Fixed issue #1292 - Don't use proxy on localhost addresses.

This commit is contained in:
Martin Edenhofer 2017-07-27 12:05:54 +02:00
parent 4ba2744689
commit 1ae062f144
5 changed files with 78 additions and 13 deletions

View file

@ -2,7 +2,7 @@ class App.SettingsAreaProxy extends App.Controller
events: events:
'submit form': 'update' 'submit form': 'update'
'click .js-submit': 'update' 'click .js-submit': 'update'
'click .js-test': 'test2' 'click .js-test': 'testConnection'
constructor: -> constructor: ->
super super
@ -14,20 +14,21 @@ class App.SettingsAreaProxy extends App.Controller
proxy: App.Setting.get('proxy') proxy: App.Setting.get('proxy')
proxy_username: App.Setting.get('proxy_username') proxy_username: App.Setting.get('proxy_username')
proxy_password: App.Setting.get('proxy_password') proxy_password: App.Setting.get('proxy_password')
proxy_no: App.Setting.get('proxy_no')
) )
update: (e) => update: (e) =>
e.preventDefault() e.preventDefault()
@formDisable(e) @formDisable(e)
params = @formParam(e) params = @formParam(e)
console.log('params', params)
App.Setting.set('proxy', params.proxy) App.Setting.set('proxy', params.proxy)
App.Setting.set('proxy_username', params.proxy_username) App.Setting.set('proxy_username', params.proxy_username)
App.Setting.set('proxy_password', params.proxy_password) App.Setting.set('proxy_password', params.proxy_password)
App.Setting.set('proxy_no', params.proxy_no)
@formEnable(e) @formEnable(e)
@render() @render()
test2: (e) => testConnection: (e) =>
e.preventDefault() e.preventDefault()
params = @formParam(e) params = @formParam(e)
@ajax( @ajax(

View file

@ -18,6 +18,12 @@
<input type="text" name="proxy_password" value="<%= @proxy_password %>" class="form-control"> <input type="text" name="proxy_password" value="<%= @proxy_password %>" class="form-control">
</div> </div>
</div> </div>
<p class="help-text"><%- @T('No proxy for the following hosts.') %></p>
<div class="horizontal end">
<div class="form-item flex">
<input type="text" name="proxy_no" value="<%= @proxy_no %>" placeholder="localhost,127.0.0.1" class="form-control">
</div>
</div>
<div class="horizontal justify-end form-controls"> <div class="horizontal justify-end form-controls">
<button class="btn btn js-test"><%- @T('Test Connection') %></button> <button class="btn btn js-test"><%- @T('Test Connection') %></button>
<button class="btn btn--primary js-submit hide"><%- @T('Submit') %></button> <button class="btn btn--primary js-submit hide"><%- @T('Submit') %></button>

View file

@ -1,4 +1,4 @@
class AddProxySettings439 < ActiveRecord::Migration class SettingProxy < ActiveRecord::Migration
def up def up
# return if it's a new setup # return if it's a new setup
@ -53,30 +53,61 @@ class AddProxySettings439 < ActiveRecord::Migration
}, },
frontend: false frontend: false
) )
# fix typo
setting = Setting.find_by(name: 'proxy_password')
if setting
setting.options[:form][0][:name] = 'proxy_password'
setting.save!
else
Setting.create_if_not_exists(
title: 'Proxy Password',
name: 'proxy_password',
area: 'System::Network',
description: 'Password for proxy connection.',
options: {
form: [
{
display: '',
null: false,
name: 'proxy_password',
tag: 'input',
},
],
},
state: '',
preferences: {
disabled: true,
online_service_disable: true,
prio: 3,
permission: ['admin.system'],
},
frontend: false
)
end
Setting.create_if_not_exists( Setting.create_if_not_exists(
title: 'Proxy Password', title: 'No Proxy',
name: 'proxy_password', name: 'proxy_no',
area: 'System::Network', area: 'System::Network',
description: 'Password for proxy connection.', description: 'No proxy for the following hosts.',
options: { options: {
form: [ form: [
{ {
display: '', display: '',
null: false, null: false,
name: 'proxy_passowrd', name: 'proxy_no',
tag: 'input', tag: 'input',
}, },
], ],
}, },
state: '', state: 'localhost,127.0.0.0,::1',
preferences: { preferences: {
disabled: true, disabled: true,
online_service_disable: true, online_service_disable: true,
prio: 3, prio: 4,
permission: ['admin.system'], permission: ['admin.system'],
}, },
frontend: false frontend: false
) )
end end
end end

View file

@ -479,7 +479,7 @@ Setting.create_if_not_exists(
{ {
display: '', display: '',
null: false, null: false,
name: 'proxy_passowrd', name: 'proxy_password',
tag: 'input', tag: 'input',
}, },
], ],
@ -493,6 +493,30 @@ Setting.create_if_not_exists(
}, },
frontend: false frontend: false
) )
Setting.create_if_not_exists(
title: 'No Proxy',
name: 'proxy_no',
area: 'System::Network',
description: 'No proxy for the following hosts.',
options: {
form: [
{
display: '',
null: false,
name: 'proxy_no',
tag: 'input',
},
],
},
state: 'localhost,127.0.0.0,::1',
preferences: {
disabled: true,
online_service_disable: true,
prio: 4,
permission: ['admin.system'],
},
frontend: false
)
Setting.create_if_not_exists( Setting.create_if_not_exists(
title: 'Send client stats', title: 'Send client stats',

View file

@ -264,7 +264,10 @@ returns
def self.get_http(uri, options) def self.get_http(uri, options)
proxy = options['proxy'] || Setting.get('proxy') proxy = options['proxy'] || Setting.get('proxy')
if proxy.present? proxy_no = options['proxy_no'] || Setting.get('proxy_no') || ''
proxy_no = proxy_no.split(',').map(&:strip) || []
proxy_no.push('localhost', '127.0.0.1', '::1')
if proxy.present? && !proxy_no.include?(uri.host.downcase)
if proxy =~ /^(.+?):(.+?)$/ if proxy =~ /^(.+?):(.+?)$/
proxy_host = $1 proxy_host = $1
proxy_port = $2 proxy_port = $2