function tableHandler() { $opspec = getOpspec(); switch ($opspec['action']) { case 'INSERT': switch ($opspec['table']) { case 'Attribute': $realm = 'attr'; break; case 'Chapter': $realm = 'chapter'; break; case 'Dictionary': $realm = 'dict'; break; case 'TagTree': $realm = 'tag'; break; case 'VLANSwitchTemplate': $realm = 'vst'; break; default: $realm = NULL; } usePreparedInsertBlade($opspec['table'], buildOpspecColumns($opspec, 'arglist')); if (isset($realm)) { lastCreated($realm, lastInsertID()); } $retcode = 48; break; case 'DELETE': usePreparedDeleteBlade($opspec['table'], buildOpspecColumns($opspec, 'arglist'), array_fetch($opspec, 'conjunction', 'AND')); $retcode = 49; break; case 'UPDATE': usePreparedUpdateBlade($opspec['table'], buildOpspecColumns($opspec, 'set_arglist'), buildOpspecColumns($opspec, 'where_arglist'), array_fetch($opspec, 'conjunction', 'AND')); $retcode = 51; break; default: throw new InvalidArgException('opspec/action', $opspec['action']); } showOneLiner($retcode); }
function setPortVLAN() { assertUIntArg('portcount'); try { $data = getSwitchVLANs($_REQUEST['object_id']); } catch (RTGatewayError $re) { return showFuncMessage(__FUNCTION__, 'ERR', array($re->getMessage())); } list($vlanlist, $portlist) = $data; // Here we just build up 1 set command for the gateway with all of the ports // included. The gateway is expected to filter unnecessary changes silently // and to provide a list of responses with either error or success message // for each of the rest. $nports = $_REQUEST['portcount']; $prefix = 'set '; $setcmd = ''; for ($i = 0; $i < $nports; $i++) { genericAssertion('portname_' . $i, 'string'); genericAssertion('vlanid_' . $i, 'string'); if ($_REQUEST['portname_' . $i] != $portlist[$i]['portname']) { throw new InvalidRequestArgException('portname_' . $i, $_REQUEST['portname_' . $i], 'expected to be ' . $portlist[$i]['portname']); } if ($_REQUEST['vlanid_' . $i] == $portlist[$i]['vlanid'] || $portlist[$i]['vlanid'] == 'TRUNK') { continue; } $portname = $_REQUEST['portname_' . $i]; $oldvlanid = $portlist[$i]['vlanid']; $newvlanid = $_REQUEST['vlanid_' . $i]; if (!permitted(NULL, NULL, NULL, array(array('tag' => '$fromvlan_' . $oldvlanid), array('tag' => '$vlan_' . $oldvlanid))) or !permitted(NULL, NULL, NULL, array(array('tag' => '$tovlan_' . $newvlanid), array('tag' => '$vlan_' . $newvlanid)))) { showOneLiner(159, array($portname, $oldvlanid, $newvlanid)); continue; } $setcmd .= $prefix . $portname . '=' . $newvlanid; $prefix = ';'; } // Feed the gateway and interpret its (non)response. if ($setcmd == '') { showOneLiner(201); } else { try { setSwitchVLANs($_REQUEST['object_id'], $setcmd); // shows messages by itself } catch (RTGatewayError $e) { showFuncMessage(__FUNCTION__, 'ERR', array($e->getMessage())); } } }
function tableHandler() { $opspec = getOpspec(); switch ($opspec['action']) { case 'INSERT': usePreparedInsertBlade($opspec['table'], buildOpspecColumns($opspec, 'arglist')); $retcode = 48; break; case 'DELETE': $conjunction = array_key_exists('conjunction', $opspec) ? $opspec['conjunction'] : 'AND'; usePreparedDeleteBlade($opspec['table'], buildOpspecColumns($opspec, 'arglist'), $conjunction); $retcode = 49; break; case 'UPDATE': usePreparedUpdateBlade($opspec['table'], buildOpspecColumns($opspec, 'set_arglist'), buildOpspecColumns($opspec, 'where_arglist'), array_key_exists('conjunction', $opspec) ? $opspec['conjunction'] : 'AND'); $retcode = 51; break; default: throw new InvalidArgException('opspec/action', $opspec['action']); } showOneLiner($retcode); }
function handlePopupPortLink() { assertPermission('depot', 'default'); assertUIntArg('port'); assertUIntArg('remote_port'); assertStringArg('cable', TRUE); $port_info = getPortInfo($_REQUEST['port']); $remote_port_info = getPortInfo($_REQUEST['remote_port']); $POIFC = getPortOIFCompat(); if (isset($_REQUEST['port_type']) and isset($_REQUEST['remote_port_type'])) { $type_local = $_REQUEST['port_type']; $type_remote = $_REQUEST['remote_port_type']; } else { $type_local = $port_info['oif_id']; $type_remote = $remote_port_info['oif_id']; } $matches = FALSE; $js_table = ''; foreach ($POIFC as $pair) { if ($pair['type1'] == $type_local && $pair['type2'] == $type_remote) { $matches = TRUE; break; } else { $js_table .= "POIFC['{$pair['type1']}-{$pair['type2']}'] = 1;\n"; } } if ($matches) { if ($port_info['oif_id'] != $type_local) { commitUpdatePortOIF($port_info['id'], $type_local); } if ($remote_port_info['oif_id'] != $type_remote) { commitUpdatePortOIF($remote_port_info['id'], $type_remote); } linkPorts($port_info['id'], $remote_port_info['id'], $_REQUEST['cable']); // patch cable? if (array_key_exists('heap_id', $_REQUEST)) { // Leave the compatibility constraints check up to the foreign keys. if (0 != ($heap_id = genericAssertion('heap_id', 'uint0'))) { $heaps = getPatchCableHeapSummary(); if (commitModifyPatchCableAmount($heap_id, -1)) { showSuccess('consumed a patch cable from ' . formatPatchCableHeapAsPlainText($heaps[$heap_id])); } else { showError('failed to consume a patch cable'); } } } showOneLiner(8, array(formatPortLink($port_info['object_id'], NULL, $port_info['id'], $port_info['name']), formatPort($remote_port_info))); addJS(<<<END window.opener.location.reload(true); window.close(); END , TRUE); backupLogMessages(); } else { // JS code to display port compatibility hint addJS(<<<END POIFC = {}; {$js_table} \$(document).ready(function () { \t\$('select.porttype').change(onPortTypeChange);\t \tonPortTypeChange(); }); function onPortTypeChange() { \tvar key = \$('*[name=port_type]')[0].value + '-' + \$('*[name=remote_port_type]')[0].value; \tif (POIFC[key] == 1) \t{ \t\t\$('#hint-not-compat').hide(); \t\t\$('#hint-compat').show(); \t} \telse \t{ \t\t\$('#hint-compat').hide(); \t\t\$('#hint-not-compat').show(); \t} } END , TRUE); addCSS(<<<END .compat-hint { \tdisplay: none; \tfont-size: 125%; } .compat-hint#hint-compat { \tcolor: green; } .compat-hint#hint-not-compat { \tcolor: #804040; } END , TRUE); // render port type editor form echo '<form method=GET>'; echo '<input type=hidden name="module" value="popup">'; echo '<input type=hidden name="helper" value="portlist">'; echo '<input type=hidden name="port" value="' . $port_info['id'] . '">'; echo '<input type=hidden name="remote_port" value="' . $remote_port_info['id'] . '">'; echo '<input type=hidden name="cable" value="' . htmlspecialchars($_REQUEST['cable'], ENT_QUOTES) . '">'; echo '<p>The ports you have selected are not compatible. Please select a compatible transceiver pair.'; echo '<p>'; echo formatPort($port_info) . ' '; if ($port_info['iif_id'] == 1) { echo formatPortIIFOIF($port_info); echo '<input type=hidden name="port_type" value="' . $port_info['oif_id'] . '">'; } else { echo '<label>' . $port_info['iif_name'] . ' '; printSelect(getExistingPortTypeOptions($port_info), array('class' => 'porttype', 'name' => 'port_type'), $type_local); echo '</label>'; } echo ' — '; if ($remote_port_info['iif_id'] == 1) { echo formatPortIIFOIF($remote_port_info); echo '<input type=hidden name="remote_port_type" value="' . $remote_port_info['oif_id'] . '">'; } else { echo '<label>' . $remote_port_info['iif_name'] . ' '; printSelect(getExistingPortTypeOptions($remote_port_info), array('class' => 'porttype', 'name' => 'remote_port_type'), $type_remote); echo '</label>'; } echo ' ' . formatPort($remote_port_info); echo '<p class="compat-hint" id="hint-not-compat">✕ Not compatible port types</p>'; echo '<p class="compat-hint" id="hint-compat">✔ Compatible port types</p>'; echo '<p><input type=submit name="do_link" value="Link">'; } }
function showFuncMessage($callfunc, $status, $log_args = array()) { global $msgcode; if (isset($msgcode[$callfunc][$status])) { showOneLiner($msgcode[$callfunc][$status], $log_args); } else { showWarning("Message '{$status}' is lost in {$callfunc}"); } }