From 8334e5b6b6705fbf4b591187260ce40324098715 Mon Sep 17 00:00:00 2001 From: ray-1337 <33544674+ray-1337@users.noreply.github.com> Date: Mon, 11 Apr 2022 22:36:51 +0200 Subject: [PATCH] added jsdoc --- src/methods/allow.js | 13 +++++++++++++ src/methods/deny.js | 13 +++++++++++++ src/methods/disable.js | 5 ++++- src/methods/enable.js | 4 ++++ src/methods/status.js | 7 ++++++- 5 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/methods/allow.js b/src/methods/allow.js index ba725d0..d195c24 100644 --- a/src/methods/allow.js +++ b/src/methods/allow.js @@ -3,6 +3,12 @@ const {promisify} = require("util"); const promisifiedExec = promisify(exec); const util = require("../Util"); +/** + * Allow incoming requests through specific port. (root/sudo access is mandatory) + * @param {number} port The connection pange. From range 1 - 65535. + * @param {"udp" | "tcp" | undefined} protocol The protocol. + * @returns {Promise} Returns a boolean. +*/ module.exports.port = async function (port, protocol) { try { if (!port) throw new Error("Missing port input."); @@ -37,6 +43,13 @@ module.exports.port = async function (port, protocol) { }; }; +/** + * Allow incoming requests through specific (IP) address. (root/sudo access is mandatory) + * @param {string} address IP address, supported by subnet/net mask. From range 0.0.0.0 to 255.255.255.255 + * @param {number | undefined} port The connection pange. From range 1 - 65535. + * @param {"udp" | "tcp" | undefined} protocol The protocol. + * @returns {Promise} Returns a boolean. +*/ module.exports.address = async function (address, port, protocol) { try { // address validation diff --git a/src/methods/deny.js b/src/methods/deny.js index f651923..219c61c 100644 --- a/src/methods/deny.js +++ b/src/methods/deny.js @@ -3,6 +3,12 @@ const {promisify} = require("util"); const promisifiedExec = promisify(exec); const util = require("../Util"); +/** + * Deny incoming requests through specific port. (root/sudo access is mandatory) + * @param {number} port The connection pange. From range 1 - 65535. + * @param {"udp" | "tcp" | undefined} protocol The protocol. + * @returns {Promise} Returns a boolean. +*/ module.exports.port = async function (port, protocol) { try { if (!port) throw new Error("Missing port input."); @@ -37,6 +43,13 @@ module.exports.port = async function (port, protocol) { }; }; +/** + * Deny incoming requests through specific (IP) address. (root/sudo access is mandatory) + * @param {string} address IP address, supported by subnet/net mask. From range 0.0.0.0 to 255.255.255.255 + * @param {number | undefined} port The connection pange. From range 1 - 65535. + * @param {"udp" | "tcp" | undefined} protocol The protocol. + * @returns {Promise} Returns a boolean. +*/ module.exports.address = async function (address, port, protocol) { try { // address validation diff --git a/src/methods/disable.js b/src/methods/disable.js index dd7c77b..928186e 100644 --- a/src/methods/disable.js +++ b/src/methods/disable.js @@ -2,7 +2,10 @@ const {exec} = require("child_process"); const {promisify} = require("util"); const promisifiedExec = promisify(exec); -// disable +/** + * Disable ufw. (root/sudo access is mandatory) + * @returns {Promise} Returns a boolean. +*/ module.exports.disable = async function() { try { let res = await promisifiedExec(`echo "y" | sudo ufw disable`); diff --git a/src/methods/enable.js b/src/methods/enable.js index b289728..799e91f 100644 --- a/src/methods/enable.js +++ b/src/methods/enable.js @@ -2,6 +2,10 @@ const {exec} = require("child_process"); const {promisify} = require("util"); const promisifiedExec = promisify(exec); +/** + * Enable ufw. (root/sudo access is mandatory) + * @returns {Promise} Returns a boolean. +*/ module.exports.enable = async function() { try { // https://serverfault.com/a/790150 diff --git a/src/methods/status.js b/src/methods/status.js index 816d9c9..c4cd158 100644 --- a/src/methods/status.js +++ b/src/methods/status.js @@ -2,7 +2,12 @@ const {exec} = require("child_process"); const {promisify} = require("util"); const promisifiedExec = promisify(exec); -module.exports = function(raw) { +/** + * List of currently activated ufw. (root/sudo access is mandatory) + * @param {boolean} [raw=false] A raw version of "ufw status" + * @returns {Promise} Returns a string if "raw" param is included, otherwise a list of array with to/action/from. +*/ +module.exports = async function(raw) { if (raw && typeof raw !== "boolean") { throw new Error("The raw must be type of boolean."); };