mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-04-24 07:01:25 +00:00
enable global proxy depends on options.type
This commit is contained in:
parent
bdca110890
commit
c3e67ebcb1
@ -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;
|
||||
};
|
||||
|
||||
|
4
proxy.js
4
proxy.js
@ -162,7 +162,7 @@ function proxyServer(option){
|
||||
function(callback) {
|
||||
|
||||
if (option.globalProxy) {
|
||||
var result = require('./lib/proxyManager').enableGlobalProxy(ip.address(), proxyPort);
|
||||
var result = require('./lib/proxyManager').enableGlobalProxy(ip.address(), proxyPort, proxyType == T_TYPE_HTTP ? "Http" : "Https");
|
||||
|
||||
if (result.status) {
|
||||
callback(result.stdout);
|
||||
@ -184,7 +184,7 @@ function proxyServer(option){
|
||||
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(proxyType == T_TYPE_HTTP ? "Http" : "Https");
|
||||
|
||||
//error occur
|
||||
if (result.status) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user