forked from absginc/sipsaker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
34 lines (25 loc) · 887 Bytes
/
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
const express = require('express');
const { spawn } = require('child_process');
const app = express();
app.use(express.json());
app.post('/sipsak', (req, res) => {
const { hostIp, hostPort = '5060' } = req.body;
const sipsak = spawn('sipsak', ['-O', '[email protected]', '-s', `sip:${hostIp}:${hostPort}`]);
let output = '';
sipsak.stdout.on('data', (data) => {
output += data.toString();
});
sipsak.stderr.on('data', (data) => {
console.error(`stderr: ${data}`);
});
sipsak.on('close', (code) => {
if (code === 0) {
console.log('SIP server is available');
res.status(200).send(`SIP server is AVAILABLE\n${output}`);
} else {
console.log('SIP server is not available');
res.status(502).send(`SIP server is NOT available\n${output}`);
}
});
});
app.listen(3000, () => console.log('sipsaker started on port 3000'));