Repository navigation
Expand file tree
/
Copy pathtestLogRead.js
More file actions
71 lines (57 loc) · 2.16 KB
/
Copy pathtestLogRead.js
File metadata and controls
71 lines (57 loc) · 2.16 KB
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
var https = require('node:http');
var fs = require('fs');
var url = require('url')
var readline = require('readline');
https.createServer(function (req, res) {
const fileStream = fs.createReadStream('alerts.log');
const rl = readline.createInterface({input: fileStream});
const parsedUrl = url.parse(req.url, true);
const format = parsedUrl.query.format || 'Type';
const nextFormat = format === 'Type' ? 'Date' : 'Type';
res.writeHead(200, {'Content-Type': 'text/html'});
let allWarnTraf = [];
let httpTraf = [];
let ftpTraf = [];
let sshTraf = [];
let dhcpTraf = [];
rl.on('line', (line) => {
if (line.includes('[!]')) {
allWarnTraf.push(line);
if (line.includes('HTTP')) httpTraf.push(line);
if (line.includes('FTP')) ftpTraf.push(line);
if (line.includes('SSH')) sshTraf.push(line);
if (line.includes('DHCP')) dhcpTraf.push(line);
}
})
rl.on('close', () => {
res.write(`
<button onclick="window.location.search='format=${nextFormat}'">
Sort by ${nextFormat}
</button>
<h2>Sorting By ${format}</h2>
`);
if (format == 'Type') {
if (httpTraf.length > 0) {
res.write('HTTP Detected: <br>');
httpTraf.forEach(line => res.write(line + '<br>'));
}
if (ftpTraf.length > 0) {
res.write('<br>FTP Detected: <br>');
ftpTraf.forEach(line => res.write(line + '<br>'));
}
if (sshTraf.length > 0) {
res.write('<br>SSH Detected: <br>');
sshTraf.forEach(line => res.write(line + '<br>'));
}
if (dhcpTraf.length > 0) {
res.write('<br>DHCP Traffic or Spoofing Detected: <br>');
dhcpTraf.forEach(line => res.write(line + '<br>'));
}
}
else if (format == 'Date') {
allWarnTraf.forEach(line => res.write(line + '<br>'))
}
res.end()
});
}).listen(8080);
console.log('Server running on http://localhost:8080');