Browse Source

added jsdoc

develop
ray-1337 3 years ago
parent
commit
8334e5b6b6
  1. 13
      src/methods/allow.js
  2. 13
      src/methods/deny.js
  3. 5
      src/methods/disable.js
  4. 4
      src/methods/enable.js
  5. 7
      src/methods/status.js

13
src/methods/allow.js

@ -3,6 +3,12 @@ const {promisify} = require("util");
const promisifiedExec = promisify(exec); const promisifiedExec = promisify(exec);
const util = require("../Util"); 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<Boolean>} Returns a boolean.
*/
module.exports.port = async function (port, protocol) { module.exports.port = async function (port, protocol) {
try { try {
if (!port) throw new Error("Missing port input."); 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<Boolean>} Returns a boolean.
*/
module.exports.address = async function (address, port, protocol) { module.exports.address = async function (address, port, protocol) {
try { try {
// address validation // address validation

13
src/methods/deny.js

@ -3,6 +3,12 @@ const {promisify} = require("util");
const promisifiedExec = promisify(exec); const promisifiedExec = promisify(exec);
const util = require("../Util"); 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<Boolean>} Returns a boolean.
*/
module.exports.port = async function (port, protocol) { module.exports.port = async function (port, protocol) {
try { try {
if (!port) throw new Error("Missing port input."); 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<Boolean>} Returns a boolean.
*/
module.exports.address = async function (address, port, protocol) { module.exports.address = async function (address, port, protocol) {
try { try {
// address validation // address validation

5
src/methods/disable.js

@ -2,7 +2,10 @@ const {exec} = require("child_process");
const {promisify} = require("util"); const {promisify} = require("util");
const promisifiedExec = promisify(exec); const promisifiedExec = promisify(exec);
// disable /**
* Disable ufw. (root/sudo access is mandatory)
* @returns {Promise<Boolean>} Returns a boolean.
*/
module.exports.disable = async function() { module.exports.disable = async function() {
try { try {
let res = await promisifiedExec(`echo "y" | sudo ufw disable`); let res = await promisifiedExec(`echo "y" | sudo ufw disable`);

4
src/methods/enable.js

@ -2,6 +2,10 @@ const {exec} = require("child_process");
const {promisify} = require("util"); const {promisify} = require("util");
const promisifiedExec = promisify(exec); const promisifiedExec = promisify(exec);
/**
* Enable ufw. (root/sudo access is mandatory)
* @returns {Promise<Boolean>} Returns a boolean.
*/
module.exports.enable = async function() { module.exports.enable = async function() {
try { try {
// https://serverfault.com/a/790150 // https://serverfault.com/a/790150

7
src/methods/status.js

@ -2,7 +2,12 @@ const {exec} = require("child_process");
const {promisify} = require("util"); const {promisify} = require("util");
const promisifiedExec = promisify(exec); 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<string | {to: string, action: string, from: string}[]>} 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") { if (raw && typeof raw !== "boolean") {
throw new Error("The raw must be type of boolean."); throw new Error("The raw must be type of boolean.");
}; };

Loading…
Cancel
Save