mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-04-24 16:51:29 +00:00
optimized tips for global proxy
This commit is contained in:
parent
c3e67ebcb1
commit
b76610576a
@ -120,6 +120,7 @@ var options = {
|
|||||||
socketPort : 8003, // optional, internal port for web socket, replace this when it is conflict with your own service
|
socketPort : 8003, // optional, internal port for web socket, replace this when it is conflict with your own service
|
||||||
throttle : 10, // optional, speed limit in kb/s
|
throttle : 10, // optional, speed limit in kb/s
|
||||||
disableWebInterface : false, //optional, set it when you don't want to use the web interface
|
disableWebInterface : false, //optional, set it when you don't want to use the web interface
|
||||||
|
setAsGlobalProxy : false, //set anyproxy as your system proxy
|
||||||
silent : false //optional, do not print anything into terminal. do not set it when you are still debugging.
|
silent : false //optional, do not print anything into terminal. do not set it when you are still debugging.
|
||||||
};
|
};
|
||||||
new proxy.proxyServer(options);
|
new proxy.proxyServer(options);
|
||||||
|
4
bin.js
4
bin.js
@ -22,7 +22,7 @@ program
|
|||||||
.option('-i, --intercept', 'intercept(decrypt) https requests when root CA exists')
|
.option('-i, --intercept', 'intercept(decrypt) https requests when root CA exists')
|
||||||
.option('-s, --silent', 'do not print anything into terminal')
|
.option('-s, --silent', 'do not print anything into terminal')
|
||||||
.option('-c, --clear', 'clear all the tmp certificates')
|
.option('-c, --clear', 'clear all the tmp certificates')
|
||||||
.option('-o, --global', 'set as global proxy')
|
.option('-o, --global', 'set as global proxy for system')
|
||||||
.option('install', '[alpha] install node modules')
|
.option('install', '[alpha] install node modules')
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ if(program.clear){
|
|||||||
webPort : program.web,
|
webPort : program.web,
|
||||||
rule : ruleModule,
|
rule : ruleModule,
|
||||||
disableWebInterface : false,
|
disableWebInterface : false,
|
||||||
globalProxy : program.global,
|
setAsGlobalProxy : program.global,
|
||||||
interceptHttps : program.intercept,
|
interceptHttps : program.intercept,
|
||||||
silent : program.silent
|
silent : program.silent
|
||||||
});
|
});
|
||||||
|
@ -18,7 +18,6 @@ function execSync(cmd) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* proxy for CentOs
|
* proxy for CentOs
|
||||||
* ------------------------------------------------------------------------
|
* ------------------------------------------------------------------------
|
||||||
@ -72,7 +71,7 @@ macProxyManager.getNetworkType = function() {
|
|||||||
macProxyManager.enableGlobalProxy = function(ip, port, proxyType) {
|
macProxyManager.enableGlobalProxy = function(ip, port, proxyType) {
|
||||||
|
|
||||||
if (!ip || !port) {
|
if (!ip || !port) {
|
||||||
console.log('proxy server\'s ip and port are required');
|
console.log('failed to set global proxy server.\n ip and port are required.');
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -137,12 +136,11 @@ 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 are required');
|
console.log('failed to set global proxy server.\n ip and port are required.');
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
return execSync(
|
return execSync(
|
||||||
|
|
||||||
// set proxy
|
// set proxy
|
||||||
'reg add "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings" /v ProxyServer /t REG_SZ /d ${ip}:${port} /f & '
|
'reg add "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings" /v ProxyServer /t REG_SZ /d ${ip}:${port} /f & '
|
||||||
.replace("${ip}", ip)
|
.replace("${ip}", ip)
|
32
proxy.js
32
proxy.js
@ -16,6 +16,7 @@ var http = require('http'),
|
|||||||
logUtil = require("./lib/log"),
|
logUtil = require("./lib/log"),
|
||||||
wsServer = require("./lib/wsServer"),
|
wsServer = require("./lib/wsServer"),
|
||||||
webInterface = require("./lib/webInterface"),
|
webInterface = require("./lib/webInterface"),
|
||||||
|
SystemProxyMgr = require('./lib/systemProxyMgr'),
|
||||||
inherits = require("util").inherits,
|
inherits = require("util").inherits,
|
||||||
util = require("./lib/util"),
|
util = require("./lib/util"),
|
||||||
path = require("path"),
|
path = require("path"),
|
||||||
@ -69,8 +70,6 @@ function proxyServer(option){
|
|||||||
logUtil.setPrintStatus(false);
|
logUtil.setPrintStatus(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(!!option.interceptHttps){
|
if(!!option.interceptHttps){
|
||||||
default_rule.setInterceptFlag(true);
|
default_rule.setInterceptFlag(true);
|
||||||
|
|
||||||
@ -158,37 +157,42 @@ function proxyServer(option){
|
|||||||
callback(null);
|
callback(null);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
//set global proxy
|
||||||
function(callback) {
|
function(callback) {
|
||||||
|
if (option.setAsGlobalProxy) {
|
||||||
if (option.globalProxy) {
|
console.log('setting global proxy for you...');
|
||||||
var result = require('./lib/proxyManager').enableGlobalProxy(ip.address(), proxyPort, proxyType == T_TYPE_HTTP ? "Http" : "Https");
|
if(!/^win/.test(process.platform) && !process.env.SUDO_UID){
|
||||||
|
console.log('sudo password may be required.');
|
||||||
|
}
|
||||||
|
var result = SystemProxyMgr.enableGlobalProxy(ip.address(), proxyPort, proxyType == T_TYPE_HTTP ? "Http" : "Https");
|
||||||
if (result.status) {
|
if (result.status) {
|
||||||
callback(result.stdout);
|
callback(result.stdout);
|
||||||
} else {
|
} else {
|
||||||
|
if(/^win/.test(process.platform)){
|
||||||
|
console.log('AnyProxy is now the default proxy for your system. It may take up to 1min to take effect.');
|
||||||
|
} else{
|
||||||
|
console.log('AnyProxy is now the default proxy for your system.');
|
||||||
|
}
|
||||||
callback(null);
|
callback(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
callback(null);
|
callback(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
//server status manager
|
//server status manager
|
||||||
function(callback){
|
function(callback){
|
||||||
|
|
||||||
process.on("exit",function(code){
|
process.on("exit",function(code){
|
||||||
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.setAsGlobalProxy) {
|
||||||
var result = require('./lib/proxyManager').disableGlobalProxy(proxyType == T_TYPE_HTTP ? "Http" : "Https");
|
console.log('resigning global proxy...');
|
||||||
|
var result = SystemProxyMgr.disableGlobalProxy(proxyType == T_TYPE_HTTP ? "Http" : "Https");
|
||||||
|
|
||||||
//error occur
|
|
||||||
if (result.status) {
|
if (result.status) {
|
||||||
console.log(color.red(result.stdout));
|
console.log(color.red(result.stdout));
|
||||||
|
} else{
|
||||||
|
console.log('global proxy resigned.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user