Last active
August 2, 2025 06:59
-
-
Save akansha-oi/d44f58f4140b160bc1044132a448950c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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