-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
70 lines (59 loc) · 1.75 KB
/
app.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
const express = require('express');
const app = express();
const http = require('http').createServer(app);
const io = require('socket.io')(http);
const os = require('os');
const pty = require('node-pty');
const shell = os.platform() === 'win32' ? 'cmd.exe' : 'bash';
const port = process.env.PORT || 3000;
app.use(express.static(__dirname));
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
});
io.on('connection', (socket) => {
console.log('User connected');
socket.on('set-subdomain', (subdomain) => {
const term = pty.spawn(shell, ['-c', `subfinder -d ${subdomain}`], {
name: 'xterm-color',
cols: 80,
rows: 30,
cwd: process.env.PWD,
env: process.env,
});
const bannerLines = 11;
let buffer = '';
let lineNumber = 0;
term.onData((data) => {
buffer += data;
let lines = buffer.split('\n');
if (lines.length > 1) {
for (let i = 0; i < lines.length - 1; i++) {
lineNumber++;
if (lineNumber > bannerLines) {
socket.emit('output', lines[i] + '\n');
}
}
buffer = lines[lines.length - 1];
}
});
socket.on('input', (data) => {
term.write(data);
if (window.innerWidth <= 600) {
term.fit();
}
});
socket.on('output', (data) => {
term.write(data);
if (window.innerWidth <= 600) {
term.fit();
}
});
socket.on('disconnect', () => {
console.log('User disconnected');
term.kill();
});
});
});
http.listen(port, () => {
console.log(`Listening on *:${port}`);
});