function clearVlan() { genericAssertion('vlan_ck', 'uint-vlan1'); list($vdom_id, $vlan_id) = decodeVLANCK($_REQUEST['vlan_ck']); $n_cleared = 0; foreach (getVLANConfiguredPorts($_REQUEST['vlan_ck']) as $object_id => $portnames) { $D = getStored8021QConfig($object_id); $changes = array(); foreach ($portnames as $pn) { $conf = $D[$pn]; $conf['allowed'] = array_diff($conf['allowed'], array($vlan_id)); if ($conf['mode'] == 'access') { $conf['mode'] = 'trunk'; } if ($conf['native'] == $vlan_id) { $conf['native'] = 0; } $changes[$pn] = $conf; } $n_cleared += apply8021qChangeRequest($object_id, $changes, FALSE); } if ($n_cleared > 0) { showSuccess("VLAN {$vlan_id} removed from {$n_cleared} ports"); } }
function save8021QPorts() { setFuncMessages(__FUNCTION__, array('OK' => 21)); global $sic; assertUIntArg('mutex_rev', TRUE); // counts from 0 assertStringArg('form_mode'); if ($sic['form_mode'] != 'save' and $sic['form_mode'] != 'duplicate') { throw new InvalidRequestArgException('form_mode', $sic['form_mode']); } $extra = array(); // prepare the $changes array $changes = array(); switch ($sic['form_mode']) { case 'save': assertUIntArg('nports'); if ($sic['nports'] == 1) { assertStringArg('pn_0'); $extra = array('port_name' => $sic['pn_0']); } for ($i = 0; $i < $sic['nports']; $i++) { assertStringArg('pn_' . $i); assertStringArg('pm_' . $i); // An access port only generates form input for its native VLAN, // which we derive allowed VLAN list from. $native = isset($sic['pnv_' . $i]) ? $sic['pnv_' . $i] : 0; switch ($sic["pm_{$i}"]) { case 'trunk': # assertArrayArg ('pav_' . $i); $allowed = isset($sic['pav_' . $i]) ? $sic['pav_' . $i] : array(); break; case 'access': if ($native == 'same') { continue 2; } assertUIntArg('pnv_' . $i); $allowed = array($native); break; default: throw new InvalidRequestArgException("pm_{$i}", $_REQUEST["pm_{$i}"], 'unknown port mode'); } $changes[$sic['pn_' . $i]] = array('mode' => $sic['pm_' . $i], 'allowed' => $allowed, 'native' => $native); } break; case 'duplicate': assertStringArg('from_port'); # assertArrayArg ('to_ports'); $before = getStored8021QConfig($sic['object_id'], 'desired'); if (!array_key_exists($sic['from_port'], $before)) { throw new InvalidArgException('from_port', $sic['from_port'], 'this port does not exist'); } foreach ($sic['to_ports'] as $tpn) { if (!array_key_exists($tpn, $before)) { throw new InvalidArgException('to_ports[]', $tpn, 'this port does not exist'); } elseif ($tpn != $sic['from_port']) { $changes[$tpn] = $before[$sic['from_port']]; } } break; } apply8021qChangeRequest($sic['object_id'], $changes, TRUE, $sic['mutex_rev']); return buildRedirectURL(NULL, NULL, $extra); }