From a496d991bae3472b1648431d4e97ea1bcedd14e0 Mon Sep 17 00:00:00 2001 From: FelisCatus Date: Fri, 30 Jan 2015 21:30:48 +0800 Subject: [PATCH] Support proxy username/password for PacProfile. Fix #190. --- omega-i18n/en/messages.json | 12 ++++++++ omega-i18n/zh_CN/messages.json | 12 ++++++++ omega-i18n/zh_HK/messages.json | 12 ++++++++ omega-i18n/zh_TW/messages.json | 12 ++++++++ .../src/proxy_auth.coffee | 16 ++++++++++- .../src/omega/controllers/pac_profile.coffee | 19 ++++++++++++- omega-web/src/partials/fixed_auth_edit.jade | 2 +- omega-web/src/partials/profile_pac.jade | 28 +++++++++++++------ 8 files changed, 102 insertions(+), 11 deletions(-) diff --git a/omega-i18n/en/messages.json b/omega-i18n/en/messages.json index 93270a3..4069ba2 100644 --- a/omega-i18n/en/messages.json +++ b/omega-i18n/en/messages.json @@ -337,6 +337,18 @@ "options_proxy_auth": { "message": "Authentication" }, + "options_proxy_authAllWarningPac": { + "message": "Warning: The username/password may be sent to unexpected servers returned by the PAC script." + }, + "options_proxy_authAllWarningPacUrl": { + "message": "Please make sure that you trust the script provided via the URL above before entering sensitive credentials." + }, + "options_proxy_authAllWarningPacScript": { + "message": "Please make sure that you trust the script below before providing sensitive credentials." + }, + "options_proxy_authReferencedWarning": { + "message": "Additionally, using this profile in other profiles (e.g. Switch Profile) may cause the username/password to be sent to proxy servers configured in other profiles." + }, "options_scheme_default": { "message": "(default)" }, diff --git a/omega-i18n/zh_CN/messages.json b/omega-i18n/zh_CN/messages.json index 50c472c..a3f9ca7 100644 --- a/omega-i18n/zh_CN/messages.json +++ b/omega-i18n/zh_CN/messages.json @@ -337,6 +337,18 @@ "options_proxy_auth": { "message": "代理登录" }, + "options_proxy_authAllWarningPac": { + "message": "警告: 用户名密码将会提供给PAC脚本返回的任何服务器,有时目标服务器会出乎您的预料。" + }, + "options_proxy_authAllWarningPacUrl": { + "message": "在提供用户名和密码时,请先确保您可以信任以上网址提供的PAC脚本。" + }, + "options_proxy_authAllWarningPacScript": { + "message": "在提供用户名和密码时,请先确保您可以信任以下输入的PAC脚本。" + }, + "options_proxy_authReferencedWarning": { + "message": "此外,在其他情景模式(如自动切换)中使用此情景时,可能会导致用户名和密码被发送至其他情景模式中设置的服务器。" + }, "options_scheme_default": { "message": "(默认)" }, diff --git a/omega-i18n/zh_HK/messages.json b/omega-i18n/zh_HK/messages.json index da5fe80..0af20a1 100644 --- a/omega-i18n/zh_HK/messages.json +++ b/omega-i18n/zh_HK/messages.json @@ -337,6 +337,18 @@ "options_proxy_auth": { "message": "代理認證" }, + "options_proxy_authAllWarningPac": { + "message": "警告: 用戶名密碼將會提供給PAC指令碼返回的任何伺服器,有時目標伺服器會出乎您的預料。" + }, + "options_proxy_authAllWarningPacUrl": { + "message": "在提供用戶名和密碼時,請先確保您可以信任以上網址提供的PAC指令碼。" + }, + "options_proxy_authAllWarningPacScript": { + "message": "在提供用戶名和密碼時,請先確保您可以信任以下輸入的PAC指令碼。" + }, + "options_proxy_authReferencedWarning": { + "message": "此外,在其他情景模式(如自動切換)中使用此情景時,可能會導致用戶名和密碼被髮送至其他情景模式中設定的伺服器。" + }, "options_scheme_default": { "message": "(默認)" }, diff --git a/omega-i18n/zh_TW/messages.json b/omega-i18n/zh_TW/messages.json index 960a387..e758213 100644 --- a/omega-i18n/zh_TW/messages.json +++ b/omega-i18n/zh_TW/messages.json @@ -337,6 +337,18 @@ "options_proxy_auth": { "message": "代理認證" }, + "options_proxy_authAllWarningPac": { + "message": "警告: 用戶名密碼將會提供給PAC指令碼返回的任何伺服器,有時目標伺服器會出乎您的預料。" + }, + "options_proxy_authAllWarningPacUrl": { + "message": "在提供用戶名和密碼時,請先確保您可以信任以上網址提供的PAC指令碼。" + }, + "options_proxy_authAllWarningPacScript": { + "message": "在提供用戶名和密碼時,請先確保您可以信任以下輸入的PAC指令碼。" + }, + "options_proxy_authReferencedWarning": { + "message": "此外,在其他情景模式(如自動切換)中使用此情景時,可能會導致用戶名和密碼被髮送至其他情景模式中設定的伺服器。" + }, "options_scheme_default": { "message": "(默認)" }, diff --git a/omega-target-chromium-extension/src/proxy_auth.coffee b/omega-target-chromium-extension/src/proxy_auth.coffee index e1e0a30..56d9255 100644 --- a/omega-target-chromium-extension/src/proxy_auth.coffee +++ b/omega-target-chromium-extension/src/proxy_auth.coffee @@ -30,6 +30,7 @@ module.exports = class ProxyAuth _keyForProxy: (proxy) -> "#{proxy.host}:#{proxy.port}" setProxies: (profiles) -> @_proxies = {} + @_fallbacks = [] processProfile = (profile) => profile = @options.profile(profile) return unless profile?.auth @@ -47,6 +48,13 @@ module.exports = class ProxyAuth name: profile.name + '.' + scheme.prop }) + fallback = profile.auth?['all'] + if fallback? + @_fallbacks.push({ + auth: fallback + name: profile.name + '.' + 'all' + }) + if Array.isArray(profiles) for profile in profiles processProfile(profile) @@ -55,6 +63,7 @@ module.exports = class ProxyAuth processProfile(profile) _proxies: {} + _fallbacks: [] _requests: {} authHandler: (details) -> return {} unless details.isProxy @@ -67,7 +76,12 @@ module.exports = class ProxyAuth port: details.challenger.port ) - proxy = @_proxies[key]?[req.authTries] + list = @_proxies[key] + listLen = if list? then list.length else 0 + if req.authTries < listLen + proxy = list[req.authTries] + else + proxy = @_fallbacks[req.authTries - listLen] @options.log.log('ProxyAuth', key, req.authTries, proxy?.name) return {} unless proxy? diff --git a/omega-web/src/omega/controllers/pac_profile.coffee b/omega-web/src/omega/controllers/pac_profile.coffee index 8ed417e..489113b 100644 --- a/omega-web/src/omega/controllers/pac_profile.coffee +++ b/omega-web/src/omega/controllers/pac_profile.coffee @@ -1,4 +1,4 @@ -angular.module('omega').controller 'PacProfileCtrl', ($scope) -> +angular.module('omega').controller 'PacProfileCtrl', ($scope, $modal) -> # coffeelint: disable=max_line_length # https://github.com/angular/angular.js/blob/master/src/ng/directive/input.js#L13 @@ -30,3 +30,20 @@ angular.module('omega').controller 'PacProfileCtrl', ($scope) -> profile.pacScript = oldPacScript $scope.pacUrlIsFile = $scope.isFileUrl(profile.pacUrl) $scope.$watch 'profile', onProfileChange, true + + $scope.editProxyAuth = (scheme) -> + prop = 'all' + auth = $scope.profile.auth?[prop] + scope = $scope.$new('isolate') + scope.auth = auth && angular.copy(auth) + $modal.open( + templateUrl: 'partials/fixed_auth_edit.html' + scope: scope + size: 'sm' + ).result.then (auth) -> + if not auth?.username + if $scope.profile.auth + $scope.profile.auth[prop] = undefined + else + $scope.profile.auth ?= {} + $scope.profile.auth[prop] = auth diff --git a/omega-web/src/partials/fixed_auth_edit.jade b/omega-web/src/partials/fixed_auth_edit.jade index a525f28..34aa132 100644 --- a/omega-web/src/partials/fixed_auth_edit.jade +++ b/omega-web/src/partials/fixed_auth_edit.jade @@ -3,7 +3,7 @@ form(ng-submit='authForm.$valid && $close(auth)' name='authForm') button.close(type='button' ng-click='$dismiss()') span(aria-hidden='true') × span.sr-only Close - h4.modal-title {{'options_modalHeader_newProfile' | tr}} + h4.modal-title {{'options_modalHeader_proxyAuth' | tr}} .modal-body(style='padding-bottom: 0;') .form-group label.sr-only {{'options_proxyAuthUsername' | tr}} diff --git a/omega-web/src/partials/profile_pac.jade b/omega-web/src/partials/profile_pac.jade index 494a339..ec75e7d 100644 --- a/omega-web/src/partials/profile_pac.jade +++ b/omega-web/src/partials/profile_pac.jade @@ -14,11 +14,23 @@ div(ng-controller='PacProfileCtrl') ladda='updatingProfile[profile.name]' data-spinner-color="#000000" ng-class='profile.pacUrl && !profile.lastUpdate ? "btn-primary" : "btn-default"') | #[span.glyphicon.glyphicon-download-alt] {{'options_downloadProfileNow' | tr}} - section.settings-group(ng-hide='pacUrlIsFile') - h3 {{'options_group_pacScript' | tr}} - p.alert.alert-success.width-limit(ng-show='profile.pacUrl && profile.lastUpdate') - | {{'options_pacScriptLastUpdate' | tr:[(profile.lastUpdate | date:'medium')]}} - p.alert.alert-danger.width-limit(ng-show='profile.pacUrl && !profile.lastUpdate') - | {{'options_pacScriptObsolete' | tr}} - textarea.monospace.form-control.width-limit(ng-model='profile.pacScript' rows=20 - ng-disabled='pacUrlCtrl.ctrl.$invalid || !!profile.pacUrl') + section.settings-group + h3 + {{'options_group_pacScript' | tr}} + = ' ' + button.btn.btn-xs.proxy-auth-toggle(ng-class='profile.auth["all"] ? "btn-success" : "btn-default"' + type='button' role='button' ng-click='editProxyAuth()' title='{{"options_proxy_auth" | tr}}') + span.glyphicon.glyphicon-lock + div.alert.alert-warning.width-limit(ng-show='profile.auth["all"]') + p {{'options_proxy_authAllWarningPac' | tr}} + p(ng-show='!!profile.pacUrl') {{'options_proxy_authAllWarningPacUrl' | tr}} + p(ng-show='!profile.pacUrl') {{'options_proxy_authAllWarningPacScript' | tr}} + p(ng-show='!!referenced') + | #[span.glyphicon.glyphicon-warning-sign] {{'options_proxy_authReferencedWarning' | tr}} + div(ng-hide='pacUrlIsFile') + p.alert.alert-success.width-limit(ng-show='profile.pacUrl && profile.lastUpdate') + | {{'options_pacScriptLastUpdate' | tr:[(profile.lastUpdate | date:'medium')]}} + p.alert.alert-danger.width-limit(ng-show='profile.pacUrl && !profile.lastUpdate') + | {{'options_pacScriptObsolete' | tr}} + textarea.monospace.form-control.width-limit(ng-model='profile.pacScript' rows=20 + ng-disabled='pacUrlCtrl.ctrl.$invalid || !!profile.pacUrl')