-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
54 lines (44 loc) · 1.16 KB
/
server.js
File metadata and controls
54 lines (44 loc) · 1.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
'use strict';
import express from 'express';
import path from 'path';
import { fileURLToPath } from 'url';
import { exec } from 'child_process';
import { execFile } from 'child_process';
const app = express();
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
app.use(express.urlencoded({ extended: true }));
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, './'));
var output = '';
var pingoutput = '';
app.get('/', (req, res) => {
res.render('index', {
output: null,
pingoutput: null,
});
});
app.post('/', (req, res) => {
const ping = req.body.ping;
const ping1 = req.body.ping1;
if (ping) {
exec('ping -c 3 ' + req.body.ping, function (err, stdout, stderr) {
output = stdout + stderr;
res.render('index', {
output: output,
pingoutput: null,
});
});
}
if (ping1) {
execFile('/bin/ping', ['-c', '3', ping1], function (err, stdout, stderr) {
pingoutput = stdout + stderr;
res.render('index', {
pingoutput: pingoutput,
output: null,
});
});
}
});
// ping directory: /usr/bin/ping or /usr/bin/ping
app.listen(3000, () => console.log('Listening on Port:3000'));