From daef953ee7f8fa2427cac380a879d8c4c41c4c80 Mon Sep 17 00:00:00 2001 From: Wildan M Date: Fri, 16 Feb 2024 08:21:43 +0700 Subject: [PATCH] Fix get firewall status --- src/controllers/iptables.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/controllers/iptables.js b/src/controllers/iptables.js index d89a210..0f7b994 100644 --- a/src/controllers/iptables.js +++ b/src/controllers/iptables.js @@ -12,6 +12,14 @@ export default function () { router.get('/show', async function (req, res, next) { try { const p = await executor.getParsed(); + const user = req.body.user.toString(); + if (user) { + if (user.match(/[^\w.-]/)) { + throw new Error("invalid username"); + } + const id = shelljs.exec("id -u " + user).stdout.trim(); + return res.json(executor.getByUser(p, user, id)); + } res.json(p); } catch (error) { next(error); @@ -21,7 +29,7 @@ export default function () { try { const user = req.body.user.toString(); if (user.match(/[^\w.-]/)) { - throw new Error(); + throw new Error("invalid username"); } const id = shelljs.exec("id -u " + user).stdout.trim(); res.json(await executor.setAddUser(user, id)); @@ -33,7 +41,7 @@ export default function () { try { const user = req.body.user.toString(); if (user.match(/[^\w.-]/)) { - throw new Error(); + throw new Error("invalid username"); } const id = shelljs.exec("id -u " + user).stdout.trim(); res.json(await executor.setDelUser(user, id));