Skip to content

Instantly share code, notes, and snippets.

@akansha-oi
Last active August 2, 2025 06:59
Show Gist options
  • Select an option

  • Save akansha-oi/d44f58f4140b160bc1044132a448950c to your computer and use it in GitHub Desktop.

Select an option

Save akansha-oi/d44f58f4140b160bc1044132a448950c to your computer and use it in GitHub Desktop.
this.app.post('/api/set_vlan_port', (req, res) => {
const { port, vlan: vlanStr, mode, action } = req.body;
const vlan = parseInt(vlanStr, 10);
if (!vports.includes(port)) {
return res.status(400).json({ error: 'Invalid port' });
}
if (!vlans.hasOwnProperty(vlan)) {
return res.status(400).json({ error: 'Invalid VLAN' });
}
if (mode === 'access' && action !== 'default') {
return res.status(403).json({ error: 'Access mode does not allow modifying VLAN memberships.' });
}
if (!portMemberships[port]) portMemberships[port] = {};
switch (action) {
case 'default':
portMemberships[port] = {};
portMemberships[port][vlan] = ['p', 'u'];
break;
case 'tag':
portMemberships[port][vlan] = ['t'];
break;
case 'untag':
portMemberships[port][vlan] = ['u'];
break;
case 'unmember':
delete portMemberships[port][vlan];
break;
default:
return res.status(400).json({ error: 'Invalid action' });
}
res.json({ message: 'Updated', members: portMemberships[port] });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment