Commit 1f8654db authored by Medicean's avatar Medicean

Fix Proxy Authentication

parent 7de9a096
...@@ -12,7 +12,6 @@ const logger = log4js.getLogger('Request'); ...@@ -12,7 +12,6 @@ const logger = log4js.getLogger('Request');
var aproxymode = "noproxy"; var aproxymode = "noproxy";
var aproxyuri = ""; var aproxyuri = "";
var aproxyauth = "";
class Request { class Request {
...@@ -24,18 +23,11 @@ class Request { ...@@ -24,18 +23,11 @@ class Request {
ipcMain.on('aproxytest', (event, opts) => { ipcMain.on('aproxytest', (event, opts) => {
var _superagent = require('superagent'); var _superagent = require('superagent');
var _aproxyuri = opts['aproxyuri']; var _aproxyuri = opts['aproxyuri'];
var _aproxyauth = opts['aproxyauth'] || "";
logger.debug("[aProxy] Test Proxy - " + _aproxyuri + " - Connect to " + opts['url']); logger.debug("[aProxy] Test Proxy - " + _aproxyuri + " - Connect to " + opts['url']);
require('superagent-proxy')(superagent); require('superagent-proxy')(superagent);
if (!_aproxyauth) {
_superagent.Request.prototype.auth=function(arg) {
return this;
};
};
_superagent _superagent
.get(opts['url']) .get(opts['url'])
.proxy(_aproxyuri) .proxy(_aproxyuri)
.auth(_aproxyauth)
.timeout(5000) .timeout(5000)
.end((err, ret) => { .end((err, ret) => {
if (err) { if (err) {
...@@ -52,22 +44,13 @@ class Request { ...@@ -52,22 +44,13 @@ class Request {
ipcMain.on('aproxy', (event, opts) => { ipcMain.on('aproxy', (event, opts) => {
aproxymode = opts['aproxymode']; aproxymode = opts['aproxymode'];
aproxyuri = opts['aproxyuri']; aproxyuri = opts['aproxyuri'];
aproxyauth = opts['aproxyauth'];
logger.debug("[aProxy] Set Proxy Mode - " + (aproxymode == "manualproxy" ? aproxyuri : " noproxy")); logger.debug("[aProxy] Set Proxy Mode - " + (aproxymode == "manualproxy" ? aproxyuri : " noproxy"));
if (aproxymode == "noproxy") { if (aproxymode == "noproxy") {
superagent.Request.prototype.proxy=function(arg) { superagent.Request.prototype.proxy=function(arg) {
return this; return this;
}; };
superagent.Request.prototype.auth=function(arg) {
return this;
};
}else{ }else{
require('superagent-proxy')(superagent); require('superagent-proxy')(superagent);
if (!aproxyauth) {
superagent.Request.prototype.auth=function(arg) {
return this;
};
};
}; };
}); });
// 监听请求 // 监听请求
...@@ -78,7 +61,6 @@ class Request { ...@@ -78,7 +61,6 @@ class Request {
.post(opts['url']) .post(opts['url'])
.set('User-Agent', 'antSword/1.0') .set('User-Agent', 'antSword/1.0')
.proxy(aproxyuri) .proxy(aproxyuri)
.auth(aproxyauth)
.type('form') .type('form')
.timeout(5000) .timeout(5000)
.send(opts['data']) .send(opts['data'])
......
...@@ -41,17 +41,17 @@ var _aproxyusername = localStorage.getItem('aproxyusername'); ...@@ -41,17 +41,17 @@ var _aproxyusername = localStorage.getItem('aproxyusername');
var _aproxypassword = localStorage.getItem('aproxypassword'); var _aproxypassword = localStorage.getItem('aproxypassword');
antSword['aproxymode'] = _aproxymode; antSword['aproxymode'] = _aproxymode;
antSword['aproxyuri'] = _aproxyprotocol + "://" + _aproxyserver + ":" + _aproxyport;
if (_aproxyusername == "" || _aproxyusername == null || _aproxypassword == "" || _aproxypassword == null) { if (_aproxyusername == "" || _aproxyusername == null || _aproxypassword == "" || _aproxypassword == null) {
antSword['aproxyauth'] = ""; antSword['aproxyauth'] = "";
}else{ }else{
antSword['aproxyauth'] = _aproxyusername + ":" + _aproxypassword; antSword['aproxyauth'] = _aproxyusername + ":" + _aproxypassword;
} }
antSword['aproxyuri'] = _aproxyprotocol + "://" + antSword['aproxyauth']+ "@" + _aproxyserver + ":" + _aproxyport;
ipcRenderer.send('aproxy', { ipcRenderer.send('aproxy', {
aproxymode: antSword['aproxymode'], aproxymode: antSword['aproxymode'],
aproxyuri: antSword['aproxyuri'], aproxyuri: antSword['aproxyuri']
aproxyauth: antSword['aproxyauth']
}); });
antSword['ipcRenderer'] = ipcRenderer; antSword['ipcRenderer'] = ipcRenderer;
......
...@@ -41,7 +41,7 @@ class AProxy { ...@@ -41,7 +41,7 @@ class AProxy {
{ type: 'combo',label: LANG['form']['proxy']['protocol'],readonly: true, name: 'protocol', options:[ { type: 'combo',label: LANG['form']['proxy']['protocol'],readonly: true, name: 'protocol', options:[
{ text: 'HTTP', value: 'http', selected: aproxyprotocol === 'http' }, { text: 'HTTP', value: 'http', selected: aproxyprotocol === 'http' },
{ text: 'HTTPS', value: 'https', selected: aproxyprotocol === 'https' }, { 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' }, { text: 'SOCKS4', value: 'socks4', selected: aproxyprotocol === 'socks4' },
]}, ]},
{ type: 'input', label: LANG['form']['proxy']['server'], name: 'server', required: true, validate:"NotEmpty", value: aproxyserver}, { type: 'input', label: LANG['form']['proxy']['server'], name: 'server', required: true, validate:"NotEmpty", value: aproxyserver},
...@@ -99,13 +99,14 @@ class AProxy { ...@@ -99,13 +99,14 @@ class AProxy {
var loadindex = layer.load(2, {time: 6*1000}); var loadindex = layer.load(2, {time: 6*1000});
var _formvals = form.getValues(); var _formvals = form.getValues();
var _server = _formvals['server'].replace(/.+:\/\//, '').replace(/:.+/, ''); var _server = _formvals['server'].replace(/.+:\/\//, '').replace(/:.+/, '');
var _aproxyuri = _formvals['protocol'] + '://' + _server + ':' + _formvals['port'];
var _aproxyauth = ""; var _aproxyauth = "";
if (_formvals['username'] == "" || _formvals['password'] == "" || _formvals['username'] == null || _formvals['password'] == null) { if (_formvals['username'] == "" || _formvals['password'] == "" || _formvals['username'] == null || _formvals['password'] == null) {
_aproxyauth = ""; _aproxyauth = "";
}else{ }else{
_aproxyauth = _formvals['username'] + ":" + _formvals['password']; _aproxyauth = _formvals['username'] + ":" + _formvals['password'];
} }
var _aproxyuri = _formvals['protocol'] + '://' + _aproxyauth + '@' +_server + ':' + _formvals['port'];
antSword['ipcRenderer'] antSword['ipcRenderer']
.on('aproxytest-error', (event, err) => { .on('aproxytest-error', (event, err) => {
layer.close(loadindex); layer.close(loadindex);
...@@ -117,8 +118,7 @@ class AProxy { ...@@ -117,8 +118,7 @@ class AProxy {
}) })
.send('aproxytest',{ .send('aproxytest',{
url: testurl || 'http://uyu.us', url: testurl || 'http://uyu.us',
aproxyuri: _aproxyuri, aproxyuri: _aproxyuri
aproxyauth: _aproxyauth
}); });
}); });
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment