Commit 1f8654db authored by Medicean's avatar Medicean

Fix Proxy Authentication

parent 7de9a096
......@@ -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'])
......
......@@ -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;
......
......@@ -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
});
});
}
......
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