mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-05-10 14:58:27 +00:00
add support for ip-based websocket
This commit is contained in:
parent
ee5917391b
commit
59297dd85b
@ -197,7 +197,7 @@ Using https features
|
|||||||
|
|
||||||
#### to intercept(decrypt) https requests
|
#### to intercept(decrypt) https requests
|
||||||
* start your anyproxy as normal. When rootCA is generated, it will intercept all the https requests for you automatically.
|
* start your anyproxy as normal. When rootCA is generated, it will intercept all the https requests for you automatically.
|
||||||
* if you get a warning like 'unsafe connection', please check if the root CA is trusted correctly.
|
* if you get a warning like 'unsafe connection', please check if the root CA is correctly trusted .
|
||||||
|
|
||||||
#### to start an https proxy
|
#### to start an https proxy
|
||||||
* ``anyproxy --type https --host my.domain.com``
|
* ``anyproxy --type https --host my.domain.com``
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
var httpsServerMgr = require("./httpsServerMgr");
|
|
||||||
|
|
||||||
|
|
||||||
var instance = new httpsServerMgr();
|
|
||||||
|
|
||||||
instance.fetchPort("localhost",function(err,port){
|
|
||||||
console.log(port);
|
|
||||||
});
|
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "anyproxy",
|
"name": "anyproxy",
|
||||||
"version": "2.4.4",
|
"version": "2.4.6",
|
||||||
"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": {
|
||||||
@ -14,11 +14,12 @@
|
|||||||
"entities": "^1.1.1",
|
"entities": "^1.1.1",
|
||||||
"express": "^4.8.5",
|
"express": "^4.8.5",
|
||||||
"iconv-lite": "^0.4.4",
|
"iconv-lite": "^0.4.4",
|
||||||
|
"ip": "^0.3.2",
|
||||||
"juicer": "^0.6.6-stable",
|
"juicer": "^0.6.6-stable",
|
||||||
"nedb": "^0.11.0",
|
"nedb": "^0.11.0",
|
||||||
"ws": "^0.4.32",
|
|
||||||
"socks5-http-client": "^0.1.6",
|
"socks5-http-client": "^0.1.6",
|
||||||
"socks5-https-client": "^0.2.2"
|
"socks5-https-client": "^0.2.2",
|
||||||
|
"ws": "^0.4.32"
|
||||||
},
|
},
|
||||||
"devDependencies": {},
|
"devDependencies": {},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
7
proxy.js
7
proxy.js
@ -25,6 +25,7 @@ var http = require('http'),
|
|||||||
juicer = require('juicer'),
|
juicer = require('juicer'),
|
||||||
events = require("events"),
|
events = require("events"),
|
||||||
express = require("express"),
|
express = require("express"),
|
||||||
|
ip = require("ip"),
|
||||||
fork = require("child_process").fork;
|
fork = require("child_process").fork;
|
||||||
|
|
||||||
GLOBAL.recorder = new Recorder();
|
GLOBAL.recorder = new Recorder();
|
||||||
@ -108,14 +109,15 @@ function proxyServer(option){
|
|||||||
function(callback){
|
function(callback){
|
||||||
|
|
||||||
//web interface
|
//web interface
|
||||||
var child_webServer = fork(path.join(__dirname,"./webServer.js"),[proxyWebPort, socketPort , proxyConfigPort,requestHandler.getRuleSummary()]);
|
var args = [proxyWebPort, socketPort, proxyConfigPort, requestHandler.getRuleSummary(), ip.address()];
|
||||||
|
var child_webServer = fork(path.join(__dirname,"./webServer.js"),args);
|
||||||
child_webServer.on("message",function(data){
|
child_webServer.on("message",function(data){
|
||||||
if(data.type == "reqBody" && data.id){
|
if(data.type == "reqBody" && data.id){
|
||||||
child_webServer.send({
|
child_webServer.send({
|
||||||
type : "body",
|
type : "body",
|
||||||
id : data.id,
|
id : data.id,
|
||||||
body : GLOBAL.recorder.getBody(data.id)
|
body : GLOBAL.recorder.getBody(data.id)
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -243,7 +245,6 @@ function UIConfigServer(port){
|
|||||||
inherits(UIConfigServer, events.EventEmitter);
|
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;
|
@ -45,6 +45,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input type="hidden" id="socketPort" value="{{webSocketPort}}" />
|
<input type="hidden" id="socketPort" value="{{webSocketPort}}" />
|
||||||
|
<input type="hidden" id="baseUrl" value="{{ipAddress}}" />
|
||||||
|
|
||||||
<script type="text/template" id="main_table_row">
|
<script type="text/template" id="main_table_row">
|
||||||
<td class="data_id"><%= _id %></td>
|
<td class="data_id"><%= _id %></td>
|
||||||
|
@ -176,8 +176,9 @@ seajs.use(['$','Underscore' ,'Backbone'], function($, _, Backbone) {
|
|||||||
alert("WebSocket is required. Please use a modern browser.");
|
alert("WebSocket is required. Please use a modern browser.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var socketPort = $("#socketPort").val() || "8003",
|
var socketPort = $("#socketPort").val(),
|
||||||
dataSocket = new WebSocket("ws://127.0.0.1:" + socketPort);
|
baseUrl = $("#baseUrl").val(),
|
||||||
|
dataSocket = new WebSocket("ws://" + baseUrl + ":" + socketPort);
|
||||||
dataSocket.onopen = function(){}
|
dataSocket.onopen = function(){}
|
||||||
|
|
||||||
dataSocket.onmessage = function(event){
|
dataSocket.onmessage = function(event){
|
||||||
@ -196,8 +197,8 @@ seajs.use(['$','Underscore' ,'Backbone'], function($, _, Backbone) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dataSocket.onerror = function(e){
|
dataSocket.onerror = function(e){
|
||||||
alert("socket err, please refresh");
|
|
||||||
console.log(e);
|
console.log(e);
|
||||||
|
alert("socket err, please refresh");
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -8,7 +8,7 @@ var express = require("express"),
|
|||||||
entities = require("entities"),
|
entities = require("entities"),
|
||||||
WebSocketServer = require('ws').Server;
|
WebSocketServer = require('ws').Server;
|
||||||
|
|
||||||
function proxyWebServer(port,webSocketPort,proxyConfigPort,ruleSummary,recorder){
|
function proxyWebServer(port,webSocketPort,proxyConfigPort,ruleSummary,ipAddress){
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if(arguments.length < 3){
|
if(arguments.length < 3){
|
||||||
@ -52,7 +52,8 @@ function proxyWebServer(port,webSocketPort,proxyConfigPort,ruleSummary,recorder)
|
|||||||
res.end(util.simpleRender(indexHTML, {
|
res.end(util.simpleRender(indexHTML, {
|
||||||
rule : ruleSummary || "",
|
rule : ruleSummary || "",
|
||||||
webSocketPort : webSocketPort,
|
webSocketPort : webSocketPort,
|
||||||
proxyConfigPort : proxyConfigPort
|
proxyConfigPort : proxyConfigPort,
|
||||||
|
ipAddress : ipAddress || "127.0.0.1"
|
||||||
}));
|
}));
|
||||||
}else{
|
}else{
|
||||||
next();
|
next();
|
||||||
@ -60,7 +61,6 @@ function proxyWebServer(port,webSocketPort,proxyConfigPort,ruleSummary,recorder)
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.use(express.static(__dirname + '/web'));
|
app.use(express.static(__dirname + '/web'));
|
||||||
|
|
||||||
app.listen(port);
|
app.listen(port);
|
||||||
|
|
||||||
//web socket interface
|
//web socket interface
|
||||||
@ -83,9 +83,10 @@ function proxyWebServer(port,webSocketPort,proxyConfigPort,ruleSummary,recorder)
|
|||||||
inherits(proxyWebServer, events.EventEmitter);
|
inherits(proxyWebServer, events.EventEmitter);
|
||||||
|
|
||||||
var param = process.argv.slice(2),
|
var param = process.argv.slice(2),
|
||||||
server = new proxyWebServer(param[0],param[1],param[2],param[3]),
|
server = new proxyWebServer(param[0],param[1],param[2],param[3],param[4]),
|
||||||
cbMap = {}; // id body cb
|
cbMap = {}; // id body cb
|
||||||
|
|
||||||
|
|
||||||
process.on("message",function(data){
|
process.on("message",function(data){
|
||||||
|
|
||||||
if(data.type == "update"){
|
if(data.type == "update"){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user