diff --git a/app/routes.js b/app/routes.js index b42d461..bec3620 100644 --- a/app/routes.js +++ b/app/routes.js @@ -6,7 +6,7 @@ const express = require("express") const router = express.Router() const handleConnection = require("./connectionHandler") const basicAuth = require("basic-auth") -const { sanitizeObject } = require("./utils") +const { sanitizeObject, validateSshTerm } = require("./utils") const validator = require("validator") function auth(req, res, next) { @@ -80,17 +80,4 @@ router.post("/force-reconnect", function (req, res) { res.status(401).send("Authentication required.") }) -/** - * Validates the SSH terminal name using validator functions. - * Allows alphanumeric characters, hyphens, and periods. - * @param {string} term - The terminal name to validate - * @returns {boolean} True if the terminal name is valid, false otherwise - */ -function validateSshTerm(term) { - return ( - validator.isLength(term, { min: 1, max: 30 }) && - validator.matches(term, /^[a-zA-Z0-9.-]+$/) - ) -} - module.exports = router diff --git a/app/utils.js b/app/utils.js index 6f2d244..e4f6ad3 100644 --- a/app/utils.js +++ b/app/utils.js @@ -1,5 +1,6 @@ // server // /app/utils.js +const validator = require("validator"); /** * Sanitizes an object by replacing sensitive properties with asterisks. @@ -33,4 +34,19 @@ function sanitizeObject( return obj } + +/** + * Validates the SSH terminal name using validator functions. + * Allows alphanumeric characters, hyphens, and periods. + * @param {string} term - The terminal name to validate + * @returns {boolean} True if the terminal name is valid, false otherwise + */ +function validateSshTerm(term) { + return ( + validator.isLength(term, { min: 1, max: 30 }) && + validator.matches(term, /^[a-zA-Z0-9.-]+$/) + ) +} + exports.sanitizeObject = sanitizeObject +exports.validateSshTerm = validateSshTerm;