mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-04-24 16:51:29 +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
|
* file: ~/.bash_profile
|
||||||
@ -69,46 +69,50 @@ macProxyManager.getNetworkType = function() {
|
|||||||
throw new Error('Unknown network type');
|
throw new Error('Unknown network type');
|
||||||
};
|
};
|
||||||
|
|
||||||
macProxyManager.enableGlobalProxy = function(ip, port) {
|
macProxyManager.enableGlobalProxy = function(ip, port, proxyType) {
|
||||||
|
|
||||||
if (!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;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
proxyType = proxyType || 'http';
|
||||||
|
|
||||||
var networkType = macProxyManager.networkType || macProxyManager.getNetworkType();
|
var networkType = macProxyManager.networkType || macProxyManager.getNetworkType();
|
||||||
|
|
||||||
var result = execSync(
|
return /^http$/i.test(proxyType) ?
|
||||||
|
|
||||||
// set http proxy
|
// set http proxy
|
||||||
'sudo networksetup -setwebproxy ${networkType} ${ip} ${port}; '
|
execSync(
|
||||||
.replace("${networkType}", networkType)
|
'networksetup -setwebproxy ${networkType} ${ip} ${port}'
|
||||||
.replace("${ip}", ip)
|
.replace("${networkType}", networkType)
|
||||||
.replace("${port}", port) +
|
.replace("${ip}", ip)
|
||||||
|
.replace("${port}", port)) :
|
||||||
|
|
||||||
// set https proxy
|
// set https proxy
|
||||||
'sudo networksetup -setsecurewebproxy ${networkType} ${ip} ${port}'
|
execSync('networksetup -setsecurewebproxy ${networkType} ${ip} ${port}'
|
||||||
.replace("${networkType}", networkType)
|
.replace("${networkType}", networkType)
|
||||||
.replace("${ip}", ip)
|
.replace("${ip}", ip)
|
||||||
.replace("${port}", port));
|
.replace("${port}", port));
|
||||||
|
|
||||||
return result;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
macProxyManager.disableGlobalProxy = function() {
|
macProxyManager.disableGlobalProxy = function(proxyType) {
|
||||||
|
proxyType = proxyType || 'http';
|
||||||
|
|
||||||
var networkType = macProxyManager.networkType || macProxyManager.getNetworkType();
|
var networkType = macProxyManager.networkType || macProxyManager.getNetworkType();
|
||||||
|
|
||||||
var result = execSync(
|
return /^http$/i.test(proxyType) ?
|
||||||
|
|
||||||
// disable http proxy
|
// set http proxy
|
||||||
'sudo networksetup -setwebproxystate ${networkType} off; '
|
execSync(
|
||||||
.replace(/\$\{networkType\}/g, networkType) +
|
'networksetup -setwebproxystate ${networkType} off'
|
||||||
|
.replace("${networkType}", networkType)) :
|
||||||
|
|
||||||
// disable https proxy
|
// set https proxy
|
||||||
'sudo networksetup -setsecurewebproxystate ${networkType} off'
|
execSync(
|
||||||
.replace(/\$\{networkType\}/g, networkType));
|
'networksetup -setsecurewebproxystate ${networkType} off'
|
||||||
|
.replace("${networkType}", networkType));
|
||||||
return result;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
macProxyManager.getProxyState = function() {
|
macProxyManager.getProxyState = function() {
|
||||||
@ -133,7 +137,7 @@ var winProxyManager = {};
|
|||||||
winProxyManager.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 are required');
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
4
proxy.js
4
proxy.js
@ -162,7 +162,7 @@ function proxyServer(option){
|
|||||||
function(callback) {
|
function(callback) {
|
||||||
|
|
||||||
if (option.globalProxy) {
|
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) {
|
if (result.status) {
|
||||||
callback(result.stdout);
|
callback(result.stdout);
|
||||||
@ -184,7 +184,7 @@ function proxyServer(option){
|
|||||||
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) {
|
if (option.globalProxy) {
|
||||||
var result = require('./lib/proxyManager').disableGlobalProxy();
|
var result = require('./lib/proxyManager').disableGlobalProxy(proxyType == T_TYPE_HTTP ? "Http" : "Https");
|
||||||
|
|
||||||
//error occur
|
//error occur
|
||||||
if (result.status) {
|
if (result.status) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user