Skip to content

Commit

Permalink
Fixed issue #1292 - Don't use proxy on localhost addresses.
Browse files Browse the repository at this point in the history
  • Loading branch information
martini committed Jul 27, 2017
1 parent 4ba2744 commit 1ae062f
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 13 deletions.
Expand Up @@ -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
Expand All @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions app/assets/javascripts/app/views/settings/proxy.jst.eco
Expand Up @@ -18,6 +18,12 @@
<input type="text" name="proxy_password" value="<%= @proxy_password %>" class="form-control">
</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">
<button class="btn btn js-test"><%- @T('Test Connection') %></button>
<button class="btn btn--primary js-submit hide"><%- @T('Submit') %></button>
Expand Down
@@ -1,4 +1,4 @@
class AddProxySettings439 < ActiveRecord::Migration
class SettingProxy < ActiveRecord::Migration
def up

# return if it's a new setup
Expand Down Expand Up @@ -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
26 changes: 25 additions & 1 deletion db/seeds/settings.rb
Expand Up @@ -479,7 +479,7 @@
{
display: '',
null: false,
name: 'proxy_passowrd',
name: 'proxy_password',
tag: 'input',
},
],
Expand All @@ -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',
Expand Down
5 changes: 4 additions & 1 deletion lib/user_agent.rb
Expand Up @@ -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
Expand Down

0 comments on commit 1ae062f

Please sign in to comment.