1
0
mirror of https://github.com/alibaba/anyproxy.git synced 2025-05-10 06:48:26 +00:00

update comments

This commit is contained in:
沈辰 2016-04-04 22:42:20 +08:00
parent a467f23ab0
commit 052a75f120
2 changed files with 48 additions and 19 deletions

@ -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++) {
@ -36,7 +61,7 @@ unixLikeSysProxyManager.getNetworkType = function() {
result = execSync('networksetup -getwebproxy ' + type);
if (result.status === 0) {
unixLikeSysProxyManager.networkType = type;
macProxyManager.networkType = type;
return type;
}
}
@ -44,14 +69,14 @@ unixLikeSysProxyManager.getNetworkType = function() {
throw new Error('Unknown network type');
};
unixLikeSysProxyManager.enableGlobalProxy = function(ip, port) {
macProxyManager.enableGlobalProxy = function(ip, port) {
if (!ip && !port) {
console.log('proxy server\'s ip and port is required');
return;
};
var networkType = unixLikeSysProxyManager.networkType || unixLikeSysProxyManager.getNetworkType();
var networkType = macProxyManager.networkType || macProxyManager.getNetworkType();
var result = execSync(
@ -70,8 +95,8 @@ unixLikeSysProxyManager.enableGlobalProxy = function(ip, port) {
return result;
};
unixLikeSysProxyManager.disableGlobalProxy = function() {
var networkType = unixLikeSysProxyManager.networkType || unixLikeSysProxyManager.getNetworkType();
macProxyManager.disableGlobalProxy = function() {
var networkType = macProxyManager.networkType || macProxyManager.getNetworkType();
var result = execSync(
@ -86,8 +111,8 @@ unixLikeSysProxyManager.disableGlobalProxy = function() {
return result;
};
unixLikeSysProxyManager.getProxyState = function() {
var networkType = unixLikeSysProxyManager.networkType || unixLikeSysProxyManager.getNetworkType();
macProxyManager.getProxyState = function() {
var networkType = macProxyManager.networkType || macProxyManager.getNetworkType();
var result = execSync('networksetup -getwebproxy ${networkType}'.replace('${networkType}', networkType));
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) {
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');
};
winSysProxyManager.getProxyState = function() {
winProxyManager.getProxyState = function() {
return '';
};
winSysProxyManager.getNetworkType = function() {
winProxyManager.getNetworkType = function() {
return '';
};
module.exports = /^win/.test(process.platform) ? winSysProxyManager : unixLikeSysProxyManager;
module.exports = /^win/.test(process.platform) ? winProxyManager : macProxyManager;

@ -182,10 +182,14 @@ function proxyServer(option){
process.on("exit",function(code){
logUtil.printLog('AnyProxy is about to exit with code: ' + code, logUtil.T_ERR);
var result = require('./lib/proxyManager').disableGlobalProxy();
if (result.status) {
console.log(color.red(result.stdout));
if (option.globalProxy) {
var result = require('./lib/proxyManager').disableGlobalProxy();
//error occur
if (result.status) {
console.log(color.red(result.stdout));
}
}
process.exit();