-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
37 lines (30 loc) · 1.16 KB
/
server.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
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const fs = require('fs');
const shell = require('shelljs');
app.use(express.static(__dirname + '/src'));
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.set('views', __dirname + '/src');
app.get('/', (req, res) => {
res.render('src/index.html');
})
app.post('/', (req, res) => {
let IPList = req.body;
console.log(IPList);
// create iptables for DAppWall. Right now all ips are treated as malicious and banned.
let iptablesContent = `#!/bin/sh\n### first flush all the iptables Rules\niptables -F\n\n`;
for ( let i = 0; i < IPList.length; i++ ) {
iptablesContent = iptablesContent + `iptables -A INPUT -s ${IPList[i].ip} -j ${IPList[i].label}\n`
}
// fs.writeFile('ips_list', JSON.stringify(IPList), (data) => {})
fs.writeFile('dappwall_iptables.sh', iptablesContent, (data) => {});
// fs.chmodSync('./trial.sh', '755');
fs.chmodSync('./dappwall_iptables.sh', '755');
shell.exec('./trial.sh');
res.end();
})
app.listen(3000, () => {
console.log('Server is listening on port 3000');
})