From 052a75f1208b9ed72fb26e4c062fcd19d06ba77b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E8=BE=B0?= Date: Mon, 4 Apr 2016 22:42:20 +0800 Subject: [PATCH] update comments --- lib/proxyManager.js | 57 ++++++++++++++++++++++++++++++++------------- proxy.js | 10 +++++--- 2 files changed, 48 insertions(+), 19 deletions(-) diff --git a/lib/proxyManager.js b/lib/proxyManager.js index 7ddeacb..e3a3f62 100644 --- a/lib/proxyManager.js +++ b/lib/proxyManager.js @@ -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; diff --git a/proxy.js b/proxy.js index 89896e5..a80da8c 100644 --- a/proxy.js +++ b/proxy.js @@ -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();