Node.js interface to UFW forked to allow execution of your Node process as non-root user.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

29 lines
726 B

const {exec} = require("child_process");
const {promisify} = require("util");
const promisifiedExec = promisify(exec);
/**
* Enable ufw. (root/sudo access is mandatory)
* @returns {Promise<Boolean>} Returns a boolean.
*/
module.exports.enable = async function() {
try {
// https://serverfault.com/a/790150
let res = await promisifiedExec(`echo "y" | sudo ufw enable`);
if (res.stderr) throw new Error(res.stderr);
if (res.stdout) {
if (res.stdout == "Firewall is active and enabled on system startup") {
return true;
} else {
console.log(res.stdout);
return false;
};
} else {
return false;
};
} catch (err) {
throw new Error(err);
};
};