mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-07-29 00:59:10 +00:00
enable global proxy depends on options.type
This commit is contained in:
@@ -20,7 +20,7 @@ function execSync(cmd) {
|
||||
|
||||
|
||||
/**
|
||||
* proxy for Centos
|
||||
* proxy for CentOs
|
||||
* ------------------------------------------------------------------------
|
||||
*
|
||||
* file: ~/.bash_profile
|
||||
@@ -69,46 +69,50 @@ macProxyManager.getNetworkType = function() {
|
||||
throw new Error('Unknown network type');
|
||||
};
|
||||
|
||||
macProxyManager.enableGlobalProxy = function(ip, port) {
|
||||
macProxyManager.enableGlobalProxy = function(ip, port, proxyType) {
|
||||
|
||||
if (!ip && !port) {
|
||||
console.log('proxy server\'s ip and port is required');
|
||||
if (!ip || !port) {
|
||||
console.log('proxy server\'s ip and port are required');
|
||||
return;
|
||||
};
|
||||
|
||||
proxyType = proxyType || 'http';
|
||||
|
||||
var networkType = macProxyManager.networkType || macProxyManager.getNetworkType();
|
||||
|
||||
var result = execSync(
|
||||
return /^http$/i.test(proxyType) ?
|
||||
|
||||
// set http proxy
|
||||
'sudo networksetup -setwebproxy ${networkType} ${ip} ${port}; '
|
||||
.replace("${networkType}", networkType)
|
||||
.replace("${ip}", ip)
|
||||
.replace("${port}", port) +
|
||||
execSync(
|
||||
'networksetup -setwebproxy ${networkType} ${ip} ${port}'
|
||||
.replace("${networkType}", networkType)
|
||||
.replace("${ip}", ip)
|
||||
.replace("${port}", port)) :
|
||||
|
||||
// set https proxy
|
||||
'sudo networksetup -setsecurewebproxy ${networkType} ${ip} ${port}'
|
||||
.replace("${networkType}", networkType)
|
||||
.replace("${ip}", ip)
|
||||
.replace("${port}", port));
|
||||
execSync('networksetup -setsecurewebproxy ${networkType} ${ip} ${port}'
|
||||
.replace("${networkType}", networkType)
|
||||
.replace("${ip}", ip)
|
||||
.replace("${port}", port));
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
macProxyManager.disableGlobalProxy = function() {
|
||||
macProxyManager.disableGlobalProxy = function(proxyType) {
|
||||
proxyType = proxyType || 'http';
|
||||
|
||||
var networkType = macProxyManager.networkType || macProxyManager.getNetworkType();
|
||||
|
||||
var result = execSync(
|
||||
return /^http$/i.test(proxyType) ?
|
||||
|
||||
// disable http proxy
|
||||
'sudo networksetup -setwebproxystate ${networkType} off; '
|
||||
.replace(/\$\{networkType\}/g, networkType) +
|
||||
// set http proxy
|
||||
execSync(
|
||||
'networksetup -setwebproxystate ${networkType} off'
|
||||
.replace("${networkType}", networkType)) :
|
||||
|
||||
// disable https proxy
|
||||
'sudo networksetup -setsecurewebproxystate ${networkType} off'
|
||||
.replace(/\$\{networkType\}/g, networkType));
|
||||
|
||||
return result;
|
||||
// set https proxy
|
||||
execSync(
|
||||
'networksetup -setsecurewebproxystate ${networkType} off'
|
||||
.replace("${networkType}", networkType));
|
||||
};
|
||||
|
||||
macProxyManager.getProxyState = function() {
|
||||
@@ -133,7 +137,7 @@ var winProxyManager = {};
|
||||
winProxyManager.enableGlobalProxy = function(ip, port) {
|
||||
|
||||
if (!ip && !port) {
|
||||
console.log('proxy server\'s ip and port is required');
|
||||
console.log('proxy server\'s ip and port are required');
|
||||
return;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user