From 1f8654dbc370f449e1afe7284f82856050c5ec47 Mon Sep 17 00:00:00 2001 From: Medicean Date: Wed, 23 Mar 2016 17:10:14 +0800 Subject: [PATCH] Fix Proxy Authentication --- modules/request.js | 18 ------------------ source/app.entry.jsx | 6 +++--- source/modules/settings/aproxy.jsx | 8 ++++---- 3 files changed, 7 insertions(+), 25 deletions(-) diff --git a/modules/request.js b/modules/request.js index d026617f..ef0c756a 100644 --- a/modules/request.js +++ b/modules/request.js @@ -12,7 +12,6 @@ const logger = log4js.getLogger('Request'); var aproxymode = "noproxy"; var aproxyuri = ""; -var aproxyauth = ""; class Request { @@ -24,18 +23,11 @@ class Request { ipcMain.on('aproxytest', (event, opts) => { var _superagent = require('superagent'); var _aproxyuri = opts['aproxyuri']; - var _aproxyauth = opts['aproxyauth'] || ""; logger.debug("[aProxy] Test Proxy - " + _aproxyuri + " - Connect to " + opts['url']); require('superagent-proxy')(superagent); - if (!_aproxyauth) { - _superagent.Request.prototype.auth=function(arg) { - return this; - }; - }; _superagent .get(opts['url']) .proxy(_aproxyuri) - .auth(_aproxyauth) .timeout(5000) .end((err, ret) => { if (err) { @@ -52,22 +44,13 @@ class Request { ipcMain.on('aproxy', (event, opts) => { aproxymode = opts['aproxymode']; aproxyuri = opts['aproxyuri']; - aproxyauth = opts['aproxyauth']; logger.debug("[aProxy] Set Proxy Mode - " + (aproxymode == "manualproxy" ? aproxyuri : " noproxy")); if (aproxymode == "noproxy") { superagent.Request.prototype.proxy=function(arg) { return this; }; - superagent.Request.prototype.auth=function(arg) { - return this; - }; }else{ require('superagent-proxy')(superagent); - if (!aproxyauth) { - superagent.Request.prototype.auth=function(arg) { - return this; - }; - }; }; }); // 监听请求 @@ -78,7 +61,6 @@ class Request { .post(opts['url']) .set('User-Agent', 'antSword/1.0') .proxy(aproxyuri) - .auth(aproxyauth) .type('form') .timeout(5000) .send(opts['data']) diff --git a/source/app.entry.jsx b/source/app.entry.jsx index 098d78f1..dffdd4dd 100644 --- a/source/app.entry.jsx +++ b/source/app.entry.jsx @@ -41,17 +41,17 @@ var _aproxyusername = localStorage.getItem('aproxyusername'); var _aproxypassword = localStorage.getItem('aproxypassword'); antSword['aproxymode'] = _aproxymode; -antSword['aproxyuri'] = _aproxyprotocol + "://" + _aproxyserver + ":" + _aproxyport; + if (_aproxyusername == "" || _aproxyusername == null || _aproxypassword == "" || _aproxypassword == null) { antSword['aproxyauth'] = ""; }else{ antSword['aproxyauth'] = _aproxyusername + ":" + _aproxypassword; } +antSword['aproxyuri'] = _aproxyprotocol + "://" + antSword['aproxyauth']+ "@" + _aproxyserver + ":" + _aproxyport; ipcRenderer.send('aproxy', { aproxymode: antSword['aproxymode'], - aproxyuri: antSword['aproxyuri'], - aproxyauth: antSword['aproxyauth'] + aproxyuri: antSword['aproxyuri'] }); antSword['ipcRenderer'] = ipcRenderer; diff --git a/source/modules/settings/aproxy.jsx b/source/modules/settings/aproxy.jsx index 2d4bea1c..9eccf569 100644 --- a/source/modules/settings/aproxy.jsx +++ b/source/modules/settings/aproxy.jsx @@ -41,7 +41,7 @@ class AProxy { { type: 'combo',label: LANG['form']['proxy']['protocol'],readonly: true, name: 'protocol', options:[ { text: 'HTTP', value: 'http', selected: aproxyprotocol === 'http' }, { text: 'HTTPS', value: 'https', selected: aproxyprotocol === 'https' }, - { text: 'SOCKS5', value: 'socks5', selected: aproxyprotocol === 'socks5' }, + { text: 'SOCKS5', value: 'socks', selected: aproxyprotocol === 'socks' }, { text: 'SOCKS4', value: 'socks4', selected: aproxyprotocol === 'socks4' }, ]}, { type: 'input', label: LANG['form']['proxy']['server'], name: 'server', required: true, validate:"NotEmpty", value: aproxyserver}, @@ -99,13 +99,14 @@ class AProxy { var loadindex = layer.load(2, {time: 6*1000}); var _formvals = form.getValues(); var _server = _formvals['server'].replace(/.+:\/\//, '').replace(/:.+/, ''); - var _aproxyuri = _formvals['protocol'] + '://' + _server + ':' + _formvals['port']; var _aproxyauth = ""; if (_formvals['username'] == "" || _formvals['password'] == "" || _formvals['username'] == null || _formvals['password'] == null) { _aproxyauth = ""; }else{ _aproxyauth = _formvals['username'] + ":" + _formvals['password']; } + var _aproxyuri = _formvals['protocol'] + '://' + _aproxyauth + '@' +_server + ':' + _formvals['port']; + antSword['ipcRenderer'] .on('aproxytest-error', (event, err) => { layer.close(loadindex); @@ -117,8 +118,7 @@ class AProxy { }) .send('aproxytest',{ url: testurl || 'http://uyu.us', - aproxyuri: _aproxyuri, - aproxyauth: _aproxyauth + aproxyuri: _aproxyuri }); }); }