mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-05-10 14:58:27 +00:00
update comments
This commit is contained in:
parent
a467f23ab0
commit
052a75f120
@ -20,14 +20,39 @@ function execSync(cmd) {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* proxy for Centos
|
||||||
* ------------------------------------------------------------------------
|
* ------------------------------------------------------------------------
|
||||||
* linux like system proxy manager
|
*
|
||||||
|
* file: ~/.bash_profile
|
||||||
|
*
|
||||||
|
* http_proxy=http://proxy_server_address:port
|
||||||
|
* export no_proxy=localhost,127.0.0.1,192.168.0.34
|
||||||
|
* export http_proxy
|
||||||
* ------------------------------------------------------------------------
|
* ------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var unixLikeSysProxyManager = {};
|
/**
|
||||||
|
* proxy for Ubuntu
|
||||||
|
* ------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* file: /etc/environment
|
||||||
|
* more info: http://askubuntu.com/questions/150210/how-do-i-set-systemwide-proxy-servers-in-xubuntu-lubuntu-or-ubuntu-studio
|
||||||
|
*
|
||||||
|
* http_proxy=http://proxy_server_address:port
|
||||||
|
* export no_proxy=localhost,127.0.0.1,192.168.0.34
|
||||||
|
* export http_proxy
|
||||||
|
* ------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
unixLikeSysProxyManager.getNetworkType = function() {
|
/**
|
||||||
|
* ------------------------------------------------------------------------
|
||||||
|
* mac proxy manager
|
||||||
|
* ------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
var macProxyManager = {};
|
||||||
|
|
||||||
|
macProxyManager.getNetworkType = function() {
|
||||||
|
|
||||||
for (var i = 0; i < networkTypes.length; i++) {
|
for (var i = 0; i < networkTypes.length; i++) {
|
||||||
|
|
||||||
@ -36,7 +61,7 @@ unixLikeSysProxyManager.getNetworkType = function() {
|
|||||||
result = execSync('networksetup -getwebproxy ' + type);
|
result = execSync('networksetup -getwebproxy ' + type);
|
||||||
|
|
||||||
if (result.status === 0) {
|
if (result.status === 0) {
|
||||||
unixLikeSysProxyManager.networkType = type;
|
macProxyManager.networkType = type;
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -44,14 +69,14 @@ unixLikeSysProxyManager.getNetworkType = function() {
|
|||||||
throw new Error('Unknown network type');
|
throw new Error('Unknown network type');
|
||||||
};
|
};
|
||||||
|
|
||||||
unixLikeSysProxyManager.enableGlobalProxy = function(ip, port) {
|
macProxyManager.enableGlobalProxy = function(ip, port) {
|
||||||
|
|
||||||
if (!ip && !port) {
|
if (!ip && !port) {
|
||||||
console.log('proxy server\'s ip and port is required');
|
console.log('proxy server\'s ip and port is required');
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
var networkType = unixLikeSysProxyManager.networkType || unixLikeSysProxyManager.getNetworkType();
|
var networkType = macProxyManager.networkType || macProxyManager.getNetworkType();
|
||||||
|
|
||||||
var result = execSync(
|
var result = execSync(
|
||||||
|
|
||||||
@ -70,8 +95,8 @@ unixLikeSysProxyManager.enableGlobalProxy = function(ip, port) {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
unixLikeSysProxyManager.disableGlobalProxy = function() {
|
macProxyManager.disableGlobalProxy = function() {
|
||||||
var networkType = unixLikeSysProxyManager.networkType || unixLikeSysProxyManager.getNetworkType();
|
var networkType = macProxyManager.networkType || macProxyManager.getNetworkType();
|
||||||
|
|
||||||
var result = execSync(
|
var result = execSync(
|
||||||
|
|
||||||
@ -86,8 +111,8 @@ unixLikeSysProxyManager.disableGlobalProxy = function() {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
unixLikeSysProxyManager.getProxyState = function() {
|
macProxyManager.getProxyState = function() {
|
||||||
var networkType = unixLikeSysProxyManager.networkType || unixLikeSysProxyManager.getNetworkType();
|
var networkType = macProxyManager.networkType || macProxyManager.getNetworkType();
|
||||||
var result = execSync('networksetup -getwebproxy ${networkType}'.replace('${networkType}', networkType));
|
var result = execSync('networksetup -getwebproxy ${networkType}'.replace('${networkType}', networkType));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -101,9 +126,9 @@ unixLikeSysProxyManager.getProxyState = function() {
|
|||||||
* ------------------------------------------------------------------------
|
* ------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var winSysProxyManager = {};
|
var winProxyManager = {};
|
||||||
|
|
||||||
winSysProxyManager.enableGlobalProxy = function(ip, port) {
|
winProxyManager.enableGlobalProxy = function(ip, port) {
|
||||||
|
|
||||||
if (!ip && !port) {
|
if (!ip && !port) {
|
||||||
console.log('proxy server\'s ip and port is required');
|
console.log('proxy server\'s ip and port is required');
|
||||||
@ -122,16 +147,16 @@ winSysProxyManager.enableGlobalProxy = function(ip, port) {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
winSysProxyManager.disableGlobalProxy = function() {
|
winProxyManager.disableGlobalProxy = function() {
|
||||||
return execSync('reg add "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f');
|
return execSync('reg add "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f');
|
||||||
};
|
};
|
||||||
|
|
||||||
winSysProxyManager.getProxyState = function() {
|
winProxyManager.getProxyState = function() {
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
|
|
||||||
winSysProxyManager.getNetworkType = function() {
|
winProxyManager.getNetworkType = function() {
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = /^win/.test(process.platform) ? winSysProxyManager : unixLikeSysProxyManager;
|
module.exports = /^win/.test(process.platform) ? winProxyManager : macProxyManager;
|
||||||
|
4
proxy.js
4
proxy.js
@ -182,11 +182,15 @@ function proxyServer(option){
|
|||||||
|
|
||||||
process.on("exit",function(code){
|
process.on("exit",function(code){
|
||||||
logUtil.printLog('AnyProxy is about to exit with code: ' + code, logUtil.T_ERR);
|
logUtil.printLog('AnyProxy is about to exit with code: ' + code, logUtil.T_ERR);
|
||||||
|
|
||||||
|
if (option.globalProxy) {
|
||||||
var result = require('./lib/proxyManager').disableGlobalProxy();
|
var result = require('./lib/proxyManager').disableGlobalProxy();
|
||||||
|
|
||||||
|
//error occur
|
||||||
if (result.status) {
|
if (result.status) {
|
||||||
console.log(color.red(result.stdout));
|
console.log(color.red(result.stdout));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
process.exit();
|
process.exit();
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user