From 03d241576dfc75d7e34f49f9e93ec44c9c5f3516 Mon Sep 17 00:00:00 2001 From: ray-1337 <33544674+ray-1337@users.noreply.github.com> Date: Tue, 12 Apr 2022 04:01:22 +0200 Subject: [PATCH] check platform after calling each method --- src/Main.js | 3 --- src/methods/allow.js | 8 ++++++++ src/methods/delete.js | 5 +++++ src/methods/deny.js | 8 ++++++++ src/methods/disable.js | 5 +++++ src/methods/enable.js | 5 +++++ src/methods/status.js | 5 +++++ 7 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/Main.js b/src/Main.js index 01bb4ac..ae4e129 100644 --- a/src/Main.js +++ b/src/Main.js @@ -1,8 +1,5 @@ const util = require("./Util"); -util.checkNodeVersion(); -util.checkPlatform(); - module.exports = { name: require("../package.json").name, version: require("../package.json").version, diff --git a/src/methods/allow.js b/src/methods/allow.js index 403ba6e..e3cedca 100644 --- a/src/methods/allow.js +++ b/src/methods/allow.js @@ -10,6 +10,10 @@ const util = require("../Util"); * @returns {Promise} Returns a boolean. */ module.exports.port = async function (port, protocol) { + util.checkNodeVersion(); + util.checkPlatform(); + await util.checkPlatformExact(); + try { if (!port) throw new Error("Missing port input."); if (typeof port !== "number") throw new Error("The port must be type of number."); @@ -51,6 +55,10 @@ module.exports.port = async function (port, protocol) { * @returns {Promise} Returns a boolean. */ module.exports.address = async function (address, port, protocol) { + util.checkNodeVersion(); + util.checkPlatform(); + await util.checkPlatformExact(); + try { // address validation if (!address) throw new Error("Missing address input."); diff --git a/src/methods/delete.js b/src/methods/delete.js index 16a8bc7..67e97af 100644 --- a/src/methods/delete.js +++ b/src/methods/delete.js @@ -1,6 +1,7 @@ const {exec} = require("child_process"); const {promisify} = require("util"); const promisifiedExec = promisify(exec); +const util = require("../Util"); /** * Delete ufw rule(s). (root/sudo access is mandatory) @@ -8,6 +9,10 @@ const promisifiedExec = promisify(exec); * @returns {Promise} Returns a boolean. */ module.exports = async function(num) { + util.checkNodeVersion(); + util.checkPlatform(); + await util.checkPlatformExact(); + try { if (!num) throw new Error("Missing num input."); if (typeof num !== "number") throw new Error("The num must be type of number."); diff --git a/src/methods/deny.js b/src/methods/deny.js index 3cee983..167adce 100644 --- a/src/methods/deny.js +++ b/src/methods/deny.js @@ -10,6 +10,10 @@ const util = require("../Util"); * @returns {Promise} Returns a boolean. */ module.exports.port = async function (port, protocol) { + util.checkNodeVersion(); + util.checkPlatform(); + await util.checkPlatformExact(); + try { if (!port) throw new Error("Missing port input."); if (typeof port !== "number") throw new Error("The port must be type of number."); @@ -51,6 +55,10 @@ module.exports.port = async function (port, protocol) { * @returns {Promise} Returns a boolean. */ module.exports.address = async function (address, port, protocol) { + util.checkNodeVersion(); + util.checkPlatform(); + await util.checkPlatformExact(); + try { // address validation if (!address) throw new Error("Missing address input."); diff --git a/src/methods/disable.js b/src/methods/disable.js index 9e8a454..edc7b8b 100644 --- a/src/methods/disable.js +++ b/src/methods/disable.js @@ -1,12 +1,17 @@ const {exec} = require("child_process"); const {promisify} = require("util"); const promisifiedExec = promisify(exec); +const util = require("../Util"); /** * Disable ufw. (root/sudo access is mandatory) * @returns {Promise} Returns a boolean. */ module.exports = async function() { + util.checkNodeVersion(); + util.checkPlatform(); + await util.checkPlatformExact(); + try { let res = await promisifiedExec(`echo "y" | sudo ufw disable`); diff --git a/src/methods/enable.js b/src/methods/enable.js index 75bc884..4872351 100644 --- a/src/methods/enable.js +++ b/src/methods/enable.js @@ -1,12 +1,17 @@ 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} 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`); diff --git a/src/methods/status.js b/src/methods/status.js index 35f3d4c..8a37591 100644 --- a/src/methods/status.js +++ b/src/methods/status.js @@ -1,6 +1,7 @@ const {exec} = require("child_process"); const {promisify} = require("util"); const promisifiedExec = promisify(exec); +const util = require("../Util"); /** * List of currently activated ufw. (root/sudo access is mandatory) @@ -8,6 +9,10 @@ const promisifiedExec = promisify(exec); * @returns {Promise} Returns a string if "raw" param is included, otherwise a list of array with to/action/from. */ module.exports = async function(raw) { + util.checkNodeVersion(); + util.checkPlatform(); + await util.checkPlatformExact(); + if (raw && typeof raw !== "boolean") { throw new Error("The raw must be type of boolean."); };