From 1ae062f14476a7ca821f90689b901faa6fd88132 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 27 Jul 2017 12:05:54 +0200 Subject: [PATCH] Fixed issue #1292 - Don't use proxy on localhost addresses. --- .../controllers/_settings/area_proxy.coffee | 7 +-- .../app/views/settings/proxy.jst.eco | 6 +++ ...439.rb => 20170727000001_setting_proxy.rb} | 47 +++++++++++++++---- db/seeds/settings.rb | 26 +++++++++- lib/user_agent.rb | 5 +- 5 files changed, 78 insertions(+), 13 deletions(-) rename db/migrate/{20170115000001_add_proxy_settings_439.rb => 20170727000001_setting_proxy.rb} (62%) diff --git a/app/assets/javascripts/app/controllers/_settings/area_proxy.coffee b/app/assets/javascripts/app/controllers/_settings/area_proxy.coffee index 841e23ffc16d..8d093a776777 100644 --- a/app/assets/javascripts/app/controllers/_settings/area_proxy.coffee +++ b/app/assets/javascripts/app/controllers/_settings/area_proxy.coffee @@ -2,7 +2,7 @@ class App.SettingsAreaProxy extends App.Controller events: 'submit form': 'update' 'click .js-submit': 'update' - 'click .js-test': 'test2' + 'click .js-test': 'testConnection' constructor: -> super @@ -14,20 +14,21 @@ class App.SettingsAreaProxy extends App.Controller proxy: App.Setting.get('proxy') proxy_username: App.Setting.get('proxy_username') proxy_password: App.Setting.get('proxy_password') + proxy_no: App.Setting.get('proxy_no') ) update: (e) => e.preventDefault() @formDisable(e) params = @formParam(e) - console.log('params', params) App.Setting.set('proxy', params.proxy) App.Setting.set('proxy_username', params.proxy_username) App.Setting.set('proxy_password', params.proxy_password) + App.Setting.set('proxy_no', params.proxy_no) @formEnable(e) @render() - test2: (e) => + testConnection: (e) => e.preventDefault() params = @formParam(e) @ajax( diff --git a/app/assets/javascripts/app/views/settings/proxy.jst.eco b/app/assets/javascripts/app/views/settings/proxy.jst.eco index 2886185b5988..b8af3fc2761a 100644 --- a/app/assets/javascripts/app/views/settings/proxy.jst.eco +++ b/app/assets/javascripts/app/views/settings/proxy.jst.eco @@ -18,6 +18,12 @@ +

<%- @T('No proxy for the following hosts.') %>

+
+
+ +
+
diff --git a/db/migrate/20170115000001_add_proxy_settings_439.rb b/db/migrate/20170727000001_setting_proxy.rb similarity index 62% rename from db/migrate/20170115000001_add_proxy_settings_439.rb rename to db/migrate/20170727000001_setting_proxy.rb index a6c0467f4f09..2634c3beb5e5 100644 --- a/db/migrate/20170115000001_add_proxy_settings_439.rb +++ b/db/migrate/20170727000001_setting_proxy.rb @@ -1,4 +1,4 @@ -class AddProxySettings439 < ActiveRecord::Migration +class SettingProxy < ActiveRecord::Migration def up # return if it's a new setup @@ -53,30 +53,61 @@ def up }, 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( - title: 'Proxy Password', - name: 'proxy_password', + title: 'No Proxy', + name: 'proxy_no', area: 'System::Network', - description: 'Password for proxy connection.', + description: 'No proxy for the following hosts.', options: { form: [ { display: '', null: false, - name: 'proxy_passowrd', + name: 'proxy_no', tag: 'input', }, ], }, - state: '', + state: 'localhost,127.0.0.0,::1', preferences: { disabled: true, online_service_disable: true, - prio: 3, + prio: 4, permission: ['admin.system'], }, frontend: false ) - end + end diff --git a/db/seeds/settings.rb b/db/seeds/settings.rb index 606dd2754be4..9181600fadef 100644 --- a/db/seeds/settings.rb +++ b/db/seeds/settings.rb @@ -479,7 +479,7 @@ { display: '', null: false, - name: 'proxy_passowrd', + name: 'proxy_password', tag: 'input', }, ], @@ -493,6 +493,30 @@ }, 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( title: 'Send client stats', diff --git a/lib/user_agent.rb b/lib/user_agent.rb index 1f835840ad40..620fb04c47dc 100644 --- a/lib/user_agent.rb +++ b/lib/user_agent.rb @@ -264,7 +264,10 @@ def self.request(url, options = {}) def self.get_http(uri, options) 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 =~ /^(.+?):(.+?)$/ proxy_host = $1 proxy_port = $2