mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-04-23 15:31:26 +00:00
add anyproxy install to install node modules
This commit is contained in:
parent
2a42ff6e08
commit
bd6d4ded09
19
README.md
19
README.md
@ -34,7 +34,7 @@ Feature
|
|||||||
* a web interface for you to watch realtime request details, where html string with (almost) any charset could be shown correctly
|
* a web interface for you to watch realtime request details, where html string with (almost) any charset could be shown correctly
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
Quick Start
|
Quick Start
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ Https features
|
|||||||
After configuring rootCA, anyproxy could help to decrypt https requests, whose approach is also called Man-In-The-Middle(MITM).
|
After configuring rootCA, anyproxy could help to decrypt https requests, whose approach is also called Man-In-The-Middle(MITM).
|
||||||
|
|
||||||
#### step 1 - install openssl
|
#### step 1 - install openssl
|
||||||
* openssl is availabe here : [http://wiki.openssl.org/index.php/Compilation_and_Installation](http://wiki.openssl.org/index.php/Compilation_and_Installation)
|
* openssl is availabe here : [http://wiki.openssl.org/index.php/Compilation_and_Installation](http://wiki.openssl.org/index.php/Compilation_and_Installation)
|
||||||
* using ``openssl version -a `` to make sure it is accessible via you command line.
|
* using ``openssl version -a `` to make sure it is accessible via you command line.
|
||||||
|
|
||||||
#### step 2 - generate a rootCA and trust it
|
#### step 2 - generate a rootCA and trust it
|
||||||
@ -96,8 +96,17 @@ After configuring rootCA, anyproxy could help to decrypt https requests, whose a
|
|||||||
|
|
||||||
Others
|
Others
|
||||||
-----------------
|
-----------------
|
||||||
|
#### to install node modules
|
||||||
|
|
||||||
#### to save request data
|
* to install node modules for supporting rules development, use ``` anyproxy install ```
|
||||||
|
* for example ``` anyproxy install underscore ```
|
||||||
|
* and in rule file
|
||||||
|
```
|
||||||
|
var base = path.join(process.env.NODE_PATH,'anyproxy','node_modules');
|
||||||
|
var underscore = require(path.join(base,'underscore'));
|
||||||
|
```
|
||||||
|
|
||||||
|
#### to save request data
|
||||||
* to save request data to local file, use ``` anyproxy --file /path/to/file ```
|
* to save request data to local file, use ``` anyproxy --file /path/to/file ```
|
||||||
* anyproxy uses [nedb](https://github.com/louischatriot/nedb) to save request data. Since NeDB's persistence uses an append-only format, you may get some redundant record in local file. For those dupplicated ones with the same id, just use the lastest line of record.
|
* anyproxy uses [nedb](https://github.com/louischatriot/nedb) to save request data. Since NeDB's persistence uses an append-only format, you may get some redundant record in local file. For those dupplicated ones with the same id, just use the lastest line of record.
|
||||||
* [TrafficeRecorder](https://github.com/ottomao/TrafficRecorder) is another tool based on anyproxy to help recording all request data, including header and body. You may have a try.
|
* [TrafficeRecorder](https://github.com/ottomao/TrafficRecorder) is another tool based on anyproxy to help recording all request data, including header and body. You may have a try.
|
||||||
@ -118,7 +127,7 @@ var proxy = require("anyproxy");
|
|||||||
|
|
||||||
//create cert when you want to use https features
|
//create cert when you want to use https features
|
||||||
//please manually trust this rootCA when it is the first time you run it
|
//please manually trust this rootCA when it is the first time you run it
|
||||||
!proxy.isRootCAFileExists() && proxy.generateRootCA();
|
!proxy.isRootCAFileExists() && proxy.generateRootCA();
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
type : "http",
|
type : "http",
|
||||||
@ -129,7 +138,7 @@ var options = {
|
|||||||
webPort : 8002, // optional, port for web interface
|
webPort : 8002, // optional, port for web interface
|
||||||
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
|
||||||
webConfigPort : 8088, // optional, internal port for web config(beta), replace this when it is conflict with your own service
|
webConfigPort : 8088, // optional, internal port for web config(beta), 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
|
||||||
};
|
};
|
||||||
new proxy.proxyServer(options);
|
new proxy.proxyServer(options);
|
||||||
|
14
bin.js
14
bin.js
@ -1,10 +1,10 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
var program = require('commander'),
|
var program = require('commander'),
|
||||||
proxy = require("./proxy.js"),
|
|
||||||
color = require('colorful'),
|
color = require('colorful'),
|
||||||
fs = require("fs"),
|
fs = require("fs"),
|
||||||
path = require("path"),
|
path = require("path"),
|
||||||
|
npm = require("npm"),
|
||||||
packageInfo = require("./package.json");
|
packageInfo = require("./package.json");
|
||||||
|
|
||||||
program
|
program
|
||||||
@ -18,6 +18,7 @@ program
|
|||||||
.option('-l, --throttle [value]', 'throttle speed in kb/s (kbyte / sec)')
|
.option('-l, --throttle [value]', 'throttle speed in kb/s (kbyte / sec)')
|
||||||
.option('-i, --intercept', 'intercept(decrypt) https requests when root CA exists')
|
.option('-i, --intercept', 'intercept(decrypt) https requests when root CA exists')
|
||||||
.option('-c, --clear', 'clear all the tmp certificates')
|
.option('-c, --clear', 'clear all the tmp certificates')
|
||||||
|
.option('install', 'install node modules')
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
if(program.clear){
|
if(program.clear){
|
||||||
@ -30,7 +31,18 @@ if(program.clear){
|
|||||||
require("./lib/certMgr").generateRootCA(function(){
|
require("./lib/certMgr").generateRootCA(function(){
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
});
|
});
|
||||||
|
}else if(program.install){
|
||||||
|
npm.load({
|
||||||
|
"prefix": process.env.NODE_PATH + '/anyproxy/'
|
||||||
|
}, function (er) {
|
||||||
|
npm.commands.install(program.args || [], function (er, data) {
|
||||||
|
if(er)throw er;
|
||||||
|
})
|
||||||
|
npm.registry.log.on("log", function (message) {
|
||||||
|
})
|
||||||
|
});
|
||||||
}else{
|
}else{
|
||||||
|
var proxy = require("./proxy.js");
|
||||||
var ruleModule;
|
var ruleModule;
|
||||||
|
|
||||||
if(program.rule){
|
if(program.rule){
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "anyproxy",
|
"name": "anyproxy",
|
||||||
"version": "3.2.2",
|
"version": "3.2.3",
|
||||||
"description": "A fully configurable proxy in NodeJS, which can handle HTTPS requests perfectly.",
|
"description": "A fully configurable proxy in NodeJS, which can handle HTTPS requests perfectly.",
|
||||||
"main": "proxy.js",
|
"main": "proxy.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
@ -19,7 +19,8 @@
|
|||||||
"nedb": "^0.11.0",
|
"nedb": "^0.11.0",
|
||||||
"qrcode-npm": "0.0.3",
|
"qrcode-npm": "0.0.3",
|
||||||
"stream-throttle": "^0.1.3",
|
"stream-throttle": "^0.1.3",
|
||||||
"ws": "^0.4.32"
|
"ws": "^0.4.32",
|
||||||
|
"npm": "^2.7.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"proxy-eval": ">=1.1.1"
|
"proxy-eval": ">=1.1.1"
|
||||||
|
21
proxy.js
21
proxy.js
@ -48,7 +48,12 @@ try{
|
|||||||
if(fs.existsSync(path.join(process.cwd(),'rule.js'))){
|
if(fs.existsSync(path.join(process.cwd(),'rule.js'))){
|
||||||
default_rule = require(path.join(process.cwd(),'rule'));
|
default_rule = require(path.join(process.cwd(),'rule'));
|
||||||
}
|
}
|
||||||
}catch(e){}
|
}catch(e){
|
||||||
|
if(e){
|
||||||
|
console.log("error" + e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//option
|
//option
|
||||||
//option.type : 'http'(default) or 'https'
|
//option.type : 'http'(default) or 'https'
|
||||||
@ -59,7 +64,7 @@ try{
|
|||||||
//option.socketPort : 8003(default)
|
//option.socketPort : 8003(default)
|
||||||
//option.webConfigPort : 8088(default)
|
//option.webConfigPort : 8088(default)
|
||||||
//option.dbFile : null(default)
|
//option.dbFile : null(default)
|
||||||
//option.throttle : null(default)
|
//option.throttle : null(default)
|
||||||
//option.disableWebInterface
|
//option.disableWebInterface
|
||||||
//option.interceptHttps ,internal param for https
|
//option.interceptHttps ,internal param for https
|
||||||
function proxyServer(option){
|
function proxyServer(option){
|
||||||
@ -74,7 +79,7 @@ function proxyServer(option){
|
|||||||
socketPort = option.socketPort || DEFAULT_WEBSOCKET_PORT, //port for websocket
|
socketPort = option.socketPort || DEFAULT_WEBSOCKET_PORT, //port for websocket
|
||||||
proxyConfigPort = option.webConfigPort || DEFAULT_CONFIG_PORT, //port to ui config server
|
proxyConfigPort = option.webConfigPort || DEFAULT_CONFIG_PORT, //port to ui config server
|
||||||
disableWebInterface = !!option.disableWebInterface ;
|
disableWebInterface = !!option.disableWebInterface ;
|
||||||
|
|
||||||
if(option.dbFile){
|
if(option.dbFile){
|
||||||
GLOBAL.recorder = new Recorder({filename: option.dbFile});
|
GLOBAL.recorder = new Recorder({filename: option.dbFile});
|
||||||
}else{
|
}else{
|
||||||
@ -113,7 +118,7 @@ function proxyServer(option){
|
|||||||
}else{
|
}else{
|
||||||
self.httpProxyServer = http.createServer(requestHandler.userRequestHandler);
|
self.httpProxyServer = http.createServer(requestHandler.userRequestHandler);
|
||||||
callback(null);
|
callback(null);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
//listen CONNECT method for https over http
|
//listen CONNECT method for https over http
|
||||||
@ -197,7 +202,7 @@ function proxyServer(option){
|
|||||||
console.log('AnyProxy is about to exit with code:', code);
|
console.log('AnyProxy is about to exit with code:', code);
|
||||||
process.exit();
|
process.exit();
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on("uncaughtException",function(err){
|
process.on("uncaughtException",function(err){
|
||||||
child_webServer.kill();
|
child_webServer.kill();
|
||||||
console.log('Caught exception: ' + err);
|
console.log('Caught exception: ' + err);
|
||||||
@ -230,7 +235,7 @@ function proxyServer(option){
|
|||||||
function(err,result){
|
function(err,result){
|
||||||
if(!err){
|
if(!err){
|
||||||
var tipText = (proxyType == T_TYPE_HTTP ? "Http" : "Https") + " proxy started at " + color.bold(ip.address() + ":" + proxyPort);
|
var tipText = (proxyType == T_TYPE_HTTP ? "Http" : "Https") + " proxy started at " + color.bold(ip.address() + ":" + proxyPort);
|
||||||
console.log(color.green(tipText));
|
console.log(color.green(tipText));
|
||||||
}else{
|
}else{
|
||||||
var tipText = "err when start proxy server :(";
|
var tipText = "err when start proxy server :(";
|
||||||
console.log(color.red(tipText));
|
console.log(color.red(tipText));
|
||||||
@ -311,7 +316,7 @@ function UIConfigServer(port){
|
|||||||
res.setHeader("Content-Type", "application/json;charset=UTF-8");
|
res.setHeader("Content-Type", "application/json;charset=UTF-8");
|
||||||
res.end(JSON.stringify({success : true}));
|
res.end(JSON.stringify({success : true}));
|
||||||
|
|
||||||
requestHandler.setRules(customerRule);
|
requestHandler.setRules(customerRule);
|
||||||
self.emit("rule_changed");
|
self.emit("rule_changed");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -327,4 +332,4 @@ inherits(UIConfigServer, events.EventEmitter);
|
|||||||
|
|
||||||
module.exports.proxyServer = proxyServer;
|
module.exports.proxyServer = proxyServer;
|
||||||
module.exports.generateRootCA = certMgr.generateRootCA;
|
module.exports.generateRootCA = certMgr.generateRootCA;
|
||||||
module.exports.isRootCAFileExists = certMgr.isRootCAFileExists;
|
module.exports.isRootCAFileExists = certMgr.isRootCAFileExists;
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
||||||
replaceServerResDataAsync: function(req,res,serverResData,callback){
|
replaceServerResDataAsync: function(req,res,serverResData,callback){
|
||||||
|
|
||||||
//append "hello world" to all web pages
|
//append "hello world" to all web pages
|
||||||
if(/html/i.test(res.headers['content-type'])){
|
if(/html/i.test(res.headers['content-type'])){
|
||||||
var newDataStr = serverResData.toString();
|
var newDataStr = serverResData.toString();
|
||||||
@ -14,4 +13,4 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user