diff --git a/docs/DOCS.md b/docs/DOCS.md index 2998205..74cc4e9 100644 --- a/docs/DOCS.md +++ b/docs/DOCS.md @@ -44,6 +44,14 @@ Disable UFW. Enable UFW. > returns `Promise` +## .reload() +Reloads firewall. +> returns `Promise` + +## .reset() +Disables and resets firewall to installation defaults. **No prompt. Use this wisely.** +> returns `Promise` + ## .status(raw?: boolean) List of currently activated UFW. > returns `Promise` \ No newline at end of file diff --git a/src/Main.js b/src/Main.js index ae4e129..c834fb6 100644 --- a/src/Main.js +++ b/src/Main.js @@ -1,5 +1,3 @@ -const util = require("./Util"); - module.exports = { name: require("../package.json").name, version: require("../package.json").version, @@ -8,5 +6,7 @@ module.exports = { disable: require("./methods/disable"), enable: require("./methods/enable"), status: require("./methods/status"), - delete: require("./methods/delete") + delete: require("./methods/delete"), + reset: require("./methods/reset"), + reload: require("./methods/reload") }; \ No newline at end of file diff --git a/src/methods/reload.js b/src/methods/reload.js new file mode 100644 index 0000000..5952ba3 --- /dev/null +++ b/src/methods/reload.js @@ -0,0 +1,29 @@ +const {exec} = require("child_process"); +const {promisify} = require("util"); +const promisifiedExec = promisify(exec); +const util = require("../Util"); + +/** + * Reloads firewall. (root/sudo access is mandatory) + * @returns {Promise} Returns a boolean. +*/ +module.exports = async function() { + util.checkSudo(); + util.checkNodeVersion(); + util.checkPlatform(); + await util.checkPlatformExact(); + + try { + let res = await promisifiedExec(`sudo ufw reload`); + + if (res.stderr) throw new Error(res.stderr); + + if (res.stdout) { + return true; + } else { + return false; + }; + } catch (err) { + throw new Error(err); + }; +}; \ No newline at end of file diff --git a/src/methods/reset.js b/src/methods/reset.js new file mode 100644 index 0000000..667e717 --- /dev/null +++ b/src/methods/reset.js @@ -0,0 +1,29 @@ +const {exec} = require("child_process"); +const {promisify} = require("util"); +const promisifiedExec = promisify(exec); +const util = require("../Util"); + +/** + * Disables and resets firewall to installation defaults. No prompt. Use this wisely. (root/sudo access is mandatory) + * @returns {Promise} Returns a boolean. +*/ +module.exports = async function() { + util.checkSudo(); + util.checkNodeVersion(); + util.checkPlatform(); + await util.checkPlatformExact(); + + try { + let res = await promisifiedExec(`sudo ufw --force reset`); + + if (res.stderr) throw new Error(res.stderr); + + if (res.stdout) { + return true; + } else { + return false; + }; + } catch (err) { + throw new Error(err); + }; +}; \ No newline at end of file