-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirewall.js
32 lines (25 loc) · 830 Bytes
/
firewall.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
const { promisify } = require("util");
const { exec } = require("child_process");
const fs = require("node:fs");
const checkFirewallStatus = async () => {
const message = { enable: true, installed: false, active: false };
message.installed = fs.existsSync("/usr/sbin/firewalld");
try {
const firewalldPing = promisify(exec)("systemctl status firewalld");
const { stdout, stderr, error } = await firewalldPing;
if (error) {
return message;
}
if (stderr) {
return message;
}
const isFirewalldRunning = stdout.includes("Active: active");
if (isFirewalldRunning) {
message.active = true;
}
return message;
} catch (error) {
return message;
}
};
module.exports = checkFirewallStatus;