mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-04-23 15:51:25 +00:00
merge README
This commit is contained in:
commit
d7677bdf2d
@ -2,7 +2,7 @@ anyproxy
|
|||||||
==========
|
==========
|
||||||
A fully configurable proxy in NodeJS, which can handle HTTPS requests perfectly.
|
A fully configurable proxy in NodeJS, which can handle HTTPS requests perfectly.
|
||||||
|
|
||||||
(Some Chinese in this doc is nothing but translation of key points. Be relax if you dont understand.)
|
(Chinese in this doc is nothing but translation of some key points. Be relax if you dont understand.)
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@ -152,12 +152,17 @@ module.exports = {
|
|||||||
Using https features
|
Using https features
|
||||||
----------------
|
----------------
|
||||||
#### step 1 - install openssl
|
#### step 1 - install openssl
|
||||||
* install [openssl](http://wiki.openssl.org/index.php/Compilation_and_Installation) ,if you want to use HTTPS-related features. After that, the command ``openssl`` should be exposed to your shell
|
* 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.
|
||||||
|
|
||||||
#### step 2 - generate a rootCA and trust it
|
#### step 2 - generate a rootCA and trust it
|
||||||
* you should do this when it is the first time to start anyproxy
|
* you should do this when it is the first time to start anyproxy
|
||||||
* execute ``anyproxy --root`` ,follow the instructions on screen
|
* execute ``anyproxy --root`` ,follow the instructions on screen
|
||||||
|
<<<<<<< HEAD
|
||||||
* **[important!]you will see some tip like *rootCA generated at : /usr/lib...* . ``cd`` to that directory, add/trust the rootCA.crt file to your system keychain. In OSX, you may do that by open the *crt file directly**
|
* **[important!]you will see some tip like *rootCA generated at : /usr/lib...* . ``cd`` to that directory, add/trust the rootCA.crt file to your system keychain. In OSX, you may do that by open the *crt file directly**
|
||||||
|
=======
|
||||||
|
* [important!]you will see some tip like *rootCA generated at : /usr/lib...* . ``cd`` to that directory, add/trust the rootCA.crt file to your system keychain. In OSX, you may do that by open the *crt file directly
|
||||||
|
>>>>>>> 3bd519b16572cb490e7df4956de7de3e06151101
|
||||||
|
|
||||||
#### step 3 - start a https proxy
|
#### step 3 - start a https proxy
|
||||||
* ``anyproxy --type https --host my.domain.com``
|
* ``anyproxy --type https --host my.domain.com``
|
||||||
|
2
bin.js
2
bin.js
@ -32,7 +32,7 @@ if(program.clear){
|
|||||||
try{ //for abs path
|
try{ //for abs path
|
||||||
ruleModule = require(program.rule);
|
ruleModule = require(program.rule);
|
||||||
}catch(e){ //for relative path
|
}catch(e){ //for relative path
|
||||||
ruleModule = require("./" + program.rule);
|
ruleModule = require(process.cwd() + '/' + program.rule.replace(/^\.\//,''));
|
||||||
}
|
}
|
||||||
console.log(color.green("rule file loaded"));
|
console.log(color.green("rule file loaded"));
|
||||||
}else{
|
}else{
|
||||||
|
@ -5,9 +5,10 @@ var exec = require('child_process').exec,
|
|||||||
os = require("os"),
|
os = require("os"),
|
||||||
color = require('colorful'),
|
color = require('colorful'),
|
||||||
readline = require('readline'),
|
readline = require('readline'),
|
||||||
|
util = require('./util'),
|
||||||
asyncTask = require("async-task-mgr");
|
asyncTask = require("async-task-mgr");
|
||||||
|
|
||||||
var certDir = path.join(getUserHome(),"/.anyproxy_certs/"),
|
var certDir = path.join(util.getUserHome(),"/.anyproxy_certs/"),
|
||||||
cmdDir = path.join(__dirname,"..","./cert/"),
|
cmdDir = path.join(__dirname,"..","./cert/"),
|
||||||
asyncTaskMgr = new asyncTask();
|
asyncTaskMgr = new asyncTask();
|
||||||
|
|
||||||
@ -37,10 +38,6 @@ function getCertificate(hostname,cb){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUserHome() {
|
|
||||||
return process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE;
|
|
||||||
}
|
|
||||||
|
|
||||||
function createCert(hostname,callback){
|
function createCert(hostname,callback){
|
||||||
console.log(hostname);
|
console.log(hostname);
|
||||||
checkRootCA();
|
checkRootCA();
|
||||||
|
@ -171,7 +171,12 @@ function userRequestHandler(req,userRes){
|
|||||||
|
|
||||||
//send response
|
//send response
|
||||||
},function(callback){
|
},function(callback){
|
||||||
userRes.end(serverResData);
|
if(404 == statusCode){
|
||||||
|
var html404path = pathUtil.join(__dirname, '..', 'web', '404.html');
|
||||||
|
userRes.end(fs.readFileSync(html404path));
|
||||||
|
}else{
|
||||||
|
userRes.end(serverResData);
|
||||||
|
}
|
||||||
callback();
|
callback();
|
||||||
|
|
||||||
//udpate record info
|
//udpate record info
|
||||||
|
@ -18,3 +18,8 @@ module.exports.merge = function(baseObj, extendObj){
|
|||||||
return baseObj;
|
return baseObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
module.exports.getUserHome = function(){
|
||||||
|
return process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE;
|
||||||
|
}
|
||||||
|
|
||||||
|
16
proxy.js
16
proxy.js
@ -3,6 +3,7 @@ try{
|
|||||||
GLOBAL.util = require('./lib/util');
|
GLOBAL.util = require('./lib/util');
|
||||||
GLOBAL.util['iconv-lite'] = require("iconv-lite");
|
GLOBAL.util['iconv-lite'] = require("iconv-lite");
|
||||||
GLOBAL.util['colorful'] = require("colorful");
|
GLOBAL.util['colorful'] = require("colorful");
|
||||||
|
GLOBAL.util['path'] = require("path");
|
||||||
}catch(e){}
|
}catch(e){}
|
||||||
|
|
||||||
var http = require('http'),
|
var http = require('http'),
|
||||||
@ -19,6 +20,7 @@ var http = require('http'),
|
|||||||
util = require("./lib/util"),
|
util = require("./lib/util"),
|
||||||
entities = require("entities"),
|
entities = require("entities"),
|
||||||
express = require("express"),
|
express = require("express"),
|
||||||
|
path = require("path"),
|
||||||
WebSocketServer= require('ws').Server;
|
WebSocketServer= require('ws').Server;
|
||||||
|
|
||||||
GLOBAL.recorder = new Recorder();
|
GLOBAL.recorder = new Recorder();
|
||||||
@ -31,6 +33,18 @@ var T_TYPE_HTTP = 0,
|
|||||||
DEFAULT_HOST = "localhost",
|
DEFAULT_HOST = "localhost",
|
||||||
DEFAULT_TYPE = T_TYPE_HTTP;
|
DEFAULT_TYPE = T_TYPE_HTTP;
|
||||||
|
|
||||||
|
var default_rule = require('./lib/rule_default');
|
||||||
|
var anyproxyHome = path.join(util.getUserHome(),"/.anyproxy/");
|
||||||
|
if(!fs.existsSync(anyproxyHome)){
|
||||||
|
fs.mkdirSync(anyproxyHome);
|
||||||
|
}
|
||||||
|
if(fs.existsSync(path.join(anyproxyHome,"rule_default.js"))){
|
||||||
|
default_rule = require(path.join(anyproxyHome,"rule_default"));
|
||||||
|
}
|
||||||
|
if(fs.existsSync(process.cwd() + '/rule.js')){
|
||||||
|
default_rule = require(process.cwd() + '/rule');
|
||||||
|
}
|
||||||
|
|
||||||
//option
|
//option
|
||||||
//option.type : 'http'(default) or 'https'
|
//option.type : 'http'(default) or 'https'
|
||||||
//option.port : 8001(default)
|
//option.port : 8001(default)
|
||||||
@ -43,7 +57,7 @@ function proxyServer(option){
|
|||||||
proxyType = /https/i.test(option.type || DEFAULT_TYPE) ? T_TYPE_HTTPS : T_TYPE_HTTP ,
|
proxyType = /https/i.test(option.type || DEFAULT_TYPE) ? T_TYPE_HTTPS : T_TYPE_HTTP ,
|
||||||
proxyPort = option.port || DEFAULT_PORT,
|
proxyPort = option.port || DEFAULT_PORT,
|
||||||
proxyHost = option.hostname || DEFAULT_HOST,
|
proxyHost = option.hostname || DEFAULT_HOST,
|
||||||
proxyRules = option.rule || require('./lib/rule_default');
|
proxyRules = option.rule || default_rule;
|
||||||
|
|
||||||
requestHandler.setRules(proxyRules); //TODO : optimize calling for set rule
|
requestHandler.setRules(proxyRules); //TODO : optimize calling for set rule
|
||||||
self.httpProxyServer = null;
|
self.httpProxyServer = null;
|
||||||
|
28
web/404.html
Normal file
28
web/404.html
Normal file
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user