Support proxy username/password for PacProfile. Fix #190.

This commit is contained in:
FelisCatus 2015-01-30 21:30:48 +08:00
parent fa66421640
commit a496d991ba
8 changed files with 102 additions and 11 deletions

View File

@ -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)"
},

View File

@ -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": "(默认)"
},

View File

@ -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": "(默認)"
},

View File

@ -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": "(默認)"
},

View File

@ -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?

View File

@ -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

View File

@ -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}}

View File

@ -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')