-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathcontrol.js
185 lines (167 loc) · 6.98 KB
/
control.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
//
// snarf - SMB man-in-the-middle tool
// Copyright (C) 2015 Josh Stone ([email protected])
// Victor Mata ([email protected])
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// ------------------------------------------------------------------------
var express = require("express");
var md = require("marked");
var fs = require("fs");
var out = require("./out.js");
module.exports.ControlPanel = function(broker, port, globals) {
var app = express();
app.engine(".html", require("ejs").__express);
app.set("views", __dirname + "/html");
app.set("view engine", "html");
app.use(express.static(__dirname + "/static"));
app.set("tab_active", false);
app.set("refresh_active", false);
app.set("refresh_count", 5000);
app.get('/', function(req, res){
var middlers = broker.listMiddlers();
var current = broker.getCurrentID();
var target = globals.target;
var blacklist = globals.blacklist.list();
res.render('index', { middlers: broker.listMiddlers(),
current: broker.getCurrentID(),
target: globals.targetpeek ? globals.targetpeek() : globals.target(),
targetsingle: globals.targetsingle,
blacklist: globals.blacklist.list(),
targetlist: globals.cycle.list()
});
});
app.get('/kill/:num', function(req, res) {
var n = parseInt(req.params.num);
out.blue("Control Server: Killing session #"+n);
if(n != NaN && broker.getMiddlers().length > n) {
broker.getMiddlers()[n].terminate();
broker.resetIDs();
}
res.redirect('/');
});
app.get('/choose/:num', function(req, res) {
var n = parseInt(req.params.num);
out.blue("Control Server: Received choose request for #"+n);
if(n != NaN && broker.getMiddlers().length > n) {
broker.setCurrentMiddler(n);
}
res.redirect('/');
});
app.get('/expire/:num', function(req, res) {
var n = parseInt(req.params.num);
out.blue("Control Server: Received expire request for #" + n);
if(n != NaN && broker.getMiddlers().length > n) {
broker.expire(n);
}
res.redirect('/');
});
app.get('/block/add/:addr', function(req, res) {
var addr = req.params.addr;
out.yellow("[DEBUG] Control Server: Received request to block: " + addr);
for(var i = 0; i < broker.getMiddlers().length; i++) {
if(broker.getMiddlers()[i].getClientAddr() == addr) {
broker.getMiddlers()[i].terminate();
}
}
broker.resetIDs();
if(globals.blacklist.ok(addr)) {
globals.blacklist.push(addr);
}
res.redirect('/');
});
app.get('/block/remove/:addr', function(req, res) {
var addr = req.params.addr;
out.yellow("[DEBUG] Control Server: Received request to unblock: " + addr);
globals.blacklist.pop(addr);
res.redirect('/');
});
app.patch('/set/target/:addr', function(req, res) {
var addr = req.params.addr;
if(!globals.targetpeek) {
out.blue("Setting new default IP to " + addr);
globals.target = function() { return addr };
}
res.redirect(301, "/");
});
app.get('/target/mode/cycle', function(req, res) {
out.yellow("[DEBUG] Control Server: Received request to switch mode to cycle");
if(globals.cycle.list().length > 0) {
globals.targetsingle = false;
globals.target = function() { return globals.cycle.shift() }
globals.targetpeek = function() { return globals.cycle.current() }
} else {
out.yellow("[DEBUG] Control Server: Cycle list is empty!")
}
res.redirect('/');
});
app.get('/target/mode/single/:addr', function(req, res) {
var addr = req.params.addr;
out.yellow("[DEBUG] Control Server: Received request to switch mode to single : " + addr);
if(addr) {
globals.targetsingle = true;
globals.target = function() { return addr }
// This doesnt play nice wih line 45
// globals.targetpeek = function() { return false }
globals.targetpeek = undefined;
out.yellow("[DEBUG] Control Server: Successfully entered single target mode")
} else {
// The client-side error handling should catch non-submitted data,
// but lets keep this here just in case
addr = globals.targetinit();
out.yellow("[DEBUG] Control Server: undefined detected, resetting value to initial target: " + addr);
}
res.redirect('/');
});
app.get('/target/add/:addr', function(req, res) {
var addr = req.params.addr;
out.yellow("[DEBUG] Control Server: Received request to add target to cycle list: " + addr);
globals.cycle.push(addr);
res.redirect('/');
});
app.get('/target/remove/:addr', function(req, res) {
var addr = req.params.addr;
out.yellow("[DEBUG] Control Server: Received request to remove target to cycle list: " + addr);
globals.cycle.pop(addr);
res.redirect('/');
});
app.get('/set/tab', function(req, res) {
if(!app.get("tab_active")) {
app.set("tab_active", "0");
} else {
app.set("tab_active", false);
}
out.yellow("[DEBUG] Control Server: tab_active is now set to: " + app.get("tab_active"));
res.redirect('/');
});
app.get('/refresh/:num', function(req, res) {
var n = parseInt(req.params.num);
if(n != NaN) {
if(n > 0) {
app.set("refresh_count", n);
app.enable("refresh_active");
} else {
app.disable("refresh_active");
}
} else {
app.disable("refresh_active");
}
out.yellow("[DEBUG] Control Server: refresh_active is: " + app.get("refresh_active") + " and time is: " + app.get("refresh_count"));
res.redirect('/');
});
app.listen(port, '127.0.0.1');
out.blue("Created control server, direct browser to http://localhost:" + port + "/");
}