diff --git a/app/assets/javascripts/app/controllers/_settings/area_proxy.coffee b/app/assets/javascripts/app/controllers/_settings/area_proxy.coffee index 841e23ffc..8d093a776 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 2886185b5..b8af3fc27 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 a6c0467f4..2634c3beb 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 @@ class AddProxySettings439 < ActiveRecord::Migration }, 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 606dd2754..9181600fa 100644 --- a/db/seeds/settings.rb +++ b/db/seeds/settings.rb @@ -479,7 +479,7 @@ Setting.create_if_not_exists( { display: '', null: false, - name: 'proxy_passowrd', + name: 'proxy_password', tag: 'input', }, ], @@ -493,6 +493,30 @@ Setting.create_if_not_exists( }, 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 1f835840a..620fb04c4 100644 --- a/lib/user_agent.rb +++ b/lib/user_agent.rb @@ -264,7 +264,10 @@ returns 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