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
680 B

const {exec} = require("child_process");
const {promisify} = require("util");
const promisifiedExec = promisify(exec);
const util = require("../Util");
/**
* Enable ufw. (root/sudo access is mandatory)
* @returns {Promise<Boolean>} Returns a boolean.
*/
module.exports = async function() {
util.checkNodeVersion();
util.checkPlatform();
await util.checkPlatformExact();
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) {
return true;
} else {
return false;
};
} catch (err) {
throw new Error(err);
};
};