Browse Source

added reload and reset func

develop
ray-1337 3 years ago
parent
commit
bbed975969
  1. 8
      docs/DOCS.md
  2. 6
      src/Main.js
  3. 29
      src/methods/reload.js
  4. 29
      src/methods/reset.js

8
docs/DOCS.md

@ -44,6 +44,14 @@ Disable UFW.
Enable UFW.
> returns `Promise<Boolean>`
## .reload()
Reloads firewall.
> returns `Promise<Boolean>`
## .reset()
Disables and resets firewall to installation defaults. **No prompt. Use this wisely.**
> returns `Promise<Boolean>`
## .status(raw?: boolean)
List of currently activated UFW.
> returns `Promise<string | {to: string, action: string, from: string }[]>`

6
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")
};

29
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<Boolean>} 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);
};
};

29
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<Boolean>} 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);
};
};
Loading…
Cancel
Save