Skip to content

Commit

Permalink
Fix get
Browse files Browse the repository at this point in the history
  • Loading branch information
willnode committed Feb 16, 2024
1 parent 436629c commit dfec027
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
6 changes: 1 addition & 5 deletions src/controllers/iptables.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ export default function () {
router.get('/show', async function (req, res, next) {
try {
const p = await executor.getParsed();
if (req.query.user) {
res.json(executor.getByUsers(p, ...(req.query.user.toString()).split(',')));
} else {
res.json((p));
}
res.json(p);
} catch (error) {
next(error);
}
Expand Down
12 changes: 7 additions & 5 deletions src/executor/iptables.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ const tmpFile6 = path.join(process.cwd(), '/.tmp/ip6tables')
class IptablesExecutor {
/**
* @param {any} parsed
* @param {string[]} users
*/
getByUsers(parsed, ...users) {
return users.map(u => (
parsed.filter?.rules.find(x => x["--uid-owner"] === u)
))
getByUser(parsed, userName, userID = "") {
const setRules = [
`-A OUTPUT -m owner --uid-owner ${userID} -j REJECT -m comment --comment "${userName}"`,
`-A OUTPUT -m owner --uid-owner ${userName} -j REJECT`,
]

return parsed.filter.some((x) => setRules.includes(x));
}
/**
*
Expand Down
2 changes: 1 addition & 1 deletion src/executor/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export default async function runConfig(config, domain, writer, sandbox = false)
let firewallStatusCache = undefined;
let firewallStatus = async () => {
if (firewallStatusCache === undefined)
firewallStatusCache = !!iptablesExec.getByUsers(await iptablesExec.getParsed(), domaindata['Username'])[0];
firewallStatusCache = !!iptablesExec.getByUser(await iptablesExec.getParsed(), domaindata['Username'], domaindata['User ID']);
return firewallStatusCache;
};
if (Array.isArray(config.features)) {
Expand Down

0 comments on commit dfec027

Please sign in to comment.