update to 4.0

This commit is contained in:
Otto Mao
2017-12-01 21:30:49 +08:00
parent e392fefc64
commit 4be5aa8954
267 changed files with 27008 additions and 84482 deletions

View File

@@ -0,0 +1,47 @@
const AnyProxy = require('../proxy');
const exec = require('child_process').exec;
const AnyProxyRecorder = require('../lib/recorder');
const WebInterfaceLite = require('../lib/webInterface');
/*
-------------------------------
| ProxyServerA | ProxyServerB |
------------------------------- ----------------------------
| Common Recorder | -------(by events)------| WebInterfaceLite |
------------------------------- ----------------------------
*/
const commonRecorder = new AnyProxyRecorder();
// web interface依赖recorder
new WebInterfaceLite({ // common web interface
webPort: 8002
}, commonRecorder);
// proxy core只依赖recorder与webServer无关
const optionsA = {
port: 8001,
recorder: commonRecorder, // use common recorder
};
const optionsB = {
port: 8005,
recorder: commonRecorder, // use common recorder
};
const proxyServerA = new AnyProxy.ProxyCore(optionsA);
const proxyServerB = new AnyProxy.ProxyCore(optionsB);
proxyServerA.start();
proxyServerB.start();
// after both ready
setTimeout(() => {
exec('curl http://www.qq.com --proxy http://127.0.0.1:8001');
exec('curl http://www.sina.com.cn --proxy http://127.0.0.1:8005');
}, 1000);
// visit http://127.0.0.1 , there should be two records

View File

@@ -0,0 +1,23 @@
const AnyProxy = require('../proxy');
const exec = require('child_process').exec;
if (!AnyProxy.utils.certMgr.ifRootCAFileExists()) {
AnyProxy.utils.certMgr.generateRootCA((error, keyPath) => {
// let users to trust this CA before using proxy
if (!error) {
const certDir = require('path').dirname(keyPath);
console.log('The cert is generated at', certDir);
const isWin = /^win/.test(process.platform);
if (isWin) {
exec('start .', { cwd: certDir });
} else {
exec('open .', { cwd: certDir });
}
} else {
console.error('error when generating rootCA', error);
}
});
} else {
// clear all the certificates
// AnyProxy.utils.certMgr.clearCerts()
}

View File

@@ -0,0 +1,70 @@
const AnyProxy = require('../proxy');
const options = {
type: 'http',
port: 8001,
rule: null,
webInterface: {
enable: true,
webPort: 8002,
wsPort: 8003,
},
throttle: 10000,
forceProxyHttps: true,
silent: false
};
const proxyServer = new AnyProxy.ProxyServer(options);
proxyServer.on('ready', () => {
console.log('ready');
// set as system proxy
proxyServer.close().then(() => {
const proxyServerB = new AnyProxy.ProxyServer(options);
proxyServerB.start();
});
console.log('closed');
// setTimeout(() => {
// }, 2000);
// AnyProxy.utils.systemProxyMgr.enableGlobalProxy('127.0.0.1', '8001');
});
proxyServer.on('error', (e) => {
console.log('proxy error');
console.log(e);
});
process.on('SIGINT', () => {
// AnyProxy.utils.systemProxyMgr.disableGlobalProxy();
proxyServer.close();
process.exit();
});
proxyServer.start();
// const WebSocketServer = require('ws').Server;
// const wsServer = new WebSocketServer({ port: 8003 },function(){
// console.log('ready');
// try {
// const serverB = new WebSocketServer({ port: 8003 }, function (e, result) {
// console.log('---in B---');
// console.log(e);
// console.log(result);
// });
// } catch(e) {
// console.log(e);
// console.log('e');
// }
// // wsServer.close(function (e, result) {
// // console.log('in close');
// // console.log(e);
// // console.log(result);
// // });
// });

View File

@@ -0,0 +1,10 @@
const AnyProxy = require('../proxy');
const options = {
port: 8001,
webInterface: {
enable: true
}
};
const proxyServer = new AnyProxy.ProxyServer(options);
proxyServer.start();