function renderSLBEntityCell($cell, $highlighted = FALSE) { $class = "slbcell realm-{$cell['realm']} id-{$cell['id']}"; $a_class = $highlighted ? 'highlight' : ''; echo "<table class='{$class}'>"; switch ($cell['realm']) { case 'object': echo "<tr><td><a class='{$a_class}' href='index.php?page=object&object_id={$cell['id']}'>{$cell['dname']}</a>"; echo "</td></tr><tr><td>"; printImageHREF('LB'); echo "</td></tr>"; break; case 'ipv4vs': echo "<tr><td rowspan=3 width='5%'>"; printImageHREF('VS'); echo "</td><td>"; echo "<a class='{$a_class}' href='index.php?page=ipv4vs&vs_id={$cell['id']}'>"; echo $cell['dname'] . "</a></td></tr><tr><td>"; echo $cell['name'] . '</td></tr>'; break; case 'ipvs': echo "<tr><td rowspan=3 width='5%'>"; printImageHREF('VS'); echo "</td><td>"; echo "<a class='{$a_class}' href='index.php?page=ipvs&vs_id={$cell['id']}'>"; echo $cell['name'] . "</a></td></tr>"; break; case 'ipv4rspool': echo "<tr><td>"; echo "<a class='{$a_class}' href='index.php?page=ipv4rspool&pool_id={$cell['id']}'>"; echo !strlen($cell['name']) ? "ANONYMOUS pool [{$cell['id']}]" : niftyString($cell['name']); echo "</a></td></tr><tr><td>"; printImageHREF('RS pool'); if ($cell['rscount']) { echo ' <small>(' . $cell['rscount'] . ')</small>'; } echo "</td></tr>"; break; } echo "<tr><td>"; echo count($cell['etags']) ? "<small>" . serializeTags($cell['etags']) . "</small>" : ' '; echo "</td></tr></table>"; }
function __construct($name, $value, $reason = NULL) { $message = 'Argument \'' . niftyString($name) . '\'' . ' of value ' . niftyString(var_export($value, TRUE), 200) . ' is invalid' . (is_null($reason) ? '' : ' (' . niftyString($reason, 100) . ')') . '.'; parent::__construct($message, parent::INTERNAL); $this->name = $name; $this->value = $value; $this->reason = $reason; }
function renderSimpleTableWithOriginEditor($rows, $column) { function printNewitemTR($column) { printOpFormIntro('add'); echo '<tr>'; echo '<td> </td>'; echo '<td class=tdleft>' . getImageHREF('create', 'create new', TRUE, 200) . '</td>'; echo "<td><input type=text size={$column['width']} name={$column['value']} tabindex=100></td>"; echo '<td class=tdleft>' . getImageHREF('create', 'create new', TRUE, 200) . '</td>'; echo '</tr></form>'; } echo '<table class=widetable border=0 cellpadding=5 cellspacing=0 align=center>'; echo "<tr><th>Origin</th><th> </th><th>{$column['header']}</th><th> </th></tr>"; if (getConfigVar('ADDNEW_AT_TOP') == 'yes') { printNewitemTR($column); } foreach ($rows as $row) { echo '<tr>'; if ($row['origin'] == 'default') { echo '<td>' . getImageHREF('computer', 'default') . '</td>'; echo '<td> </td>'; echo '<td>' . niftyString($row[$column['value']], $column['width']) . '</td>'; echo '<td> </td>'; } else { printOpFormIntro('upd', array($column['key'] => $row[$column['key']])); echo '<td>' . getImageHREF('favorite', 'custom') . '</td>'; echo '<td>' . getOpLink(array('op' => 'del', $column['key'] => $row[$column['key']]), '', 'destroy', 'remove') . '</td>'; echo "<td><input type=text size={$column['width']} name={$column['value']} value='" . niftyString($row[$column['value']], $column['width']) . "'></td>"; echo '<td>' . getImageHREF('save', 'Save changes', TRUE) . '</td>'; echo '</form>'; } echo '</tr>'; } if (getConfigVar('ADDNEW_AT_TOP') != 'yes') { printNewitemTR($column); } echo '</table>'; }
function renderVSTRulesEditor($vst_id) { $vst = spotEntity('vst', $vst_id); amplifyCell($vst); if ($vst['rulec']) { $source_options = array(); } else { $source_options = array(); foreach (listCells('vst') as $vst_id => $vst_info) { if ($vst_info['rulec']) { $source_options[$vst_id] = niftyString('(' . $vst_info['rulec'] . ') ' . $vst_info['description']); } } } addJS('js/vst_editor.js'); echo '<center><h1>' . niftyString($vst['description']) . '</h1></center>'; if (count($source_options)) { startPortlet('clone another template'); printOpFormIntro('clone'); echo '<input type=hidden name="mutex_rev" value="' . $vst['mutex_rev'] . '">'; echo '<table cellspacing=0 cellpadding=5 align=center class=widetable>'; echo '<tr><td>' . getSelect($source_options, array('name' => 'from_id')) . '</td>'; echo '<td>' . getImageHREF('COPY', 'copy from selected', TRUE) . '</td></tr></table></form>'; finishPortlet(); startPortlet('add rules one by one'); } printOpFormIntro('upd'); echo '<table cellspacing=0 cellpadding=5 align=center class="widetable template-rules">'; echo '<tr><th></th><th>sequence</th><th>regexp</th><th>role</th>'; echo '<th>VLAN IDs</th><th>comment</th><th><a href="#" class="vst-add-rule initial">' . getImageHREF('add', 'Add rule') . '</a></th></tr>'; global $port_role_options; $row_html = '<td><a href="#" class="vst-del-rule">' . getImageHREF('destroy', 'delete rule') . '</a></td>'; $row_html .= '<td><input type=text name=rule_no value="%s" size=3></td>'; $row_html .= '<td><input type=text name=port_pcre value="%s"></td>'; $row_html .= '<td>%s</td>'; $row_html .= '<td><input type=text name=wrt_vlans value="%s"></td>'; $row_html .= '<td><input type=text name=description value="%s"></td>'; $row_html .= '<td><a href="#" class="vst-add-rule">' . getImageHREF('add', 'Duplicate rule') . '</a></td>'; addJS("var new_vst_row = '" . addslashes(sprintf($row_html, '', '', getSelect($port_role_options, array('name' => 'port_role'), 'anymode'), '', '')) . "';", TRUE); @session_start(); foreach (isset($_SESSION['vst_edited']) ? $_SESSION['vst_edited'] : $vst['rules'] as $item) { printf('<tr>' . $row_html . '</tr>', $item['rule_no'], htmlspecialchars($item['port_pcre'], ENT_QUOTES), getSelect($port_role_options, array('name' => 'port_role'), $item['port_role']), $item['wrt_vlans'], $item['description']); } echo '</table>'; echo '<input type=hidden name="template_json">'; echo '<input type=hidden name="mutex_rev" value="' . $vst['mutex_rev'] . '">'; echo '<center>' . getImageHref('SAVE', 'Save template', TRUE) . '</center>'; echo '</form>'; if (isset($_SESSION['vst_edited'])) { // draw current template renderVSTRules($vst['rules'], 'currently saved tamplate'); unset($_SESSION['vst_edited']); } session_commit(); if (count($source_options)) { finishPortlet(); } }
function printNewItemTR() { $all_vswitches = getVLANSwitches(); global $pageno; $hintcodes = array('prev_vdid' => 'DEFAULT_VDOM_ID', 'prev_vstid' => 'DEFAULT_VST_ID', 'prev_objid' => NULL); $focus = array(); foreach ($hintcodes as $hint_code => $option_name) { if (array_key_exists($hint_code, $_REQUEST)) { assertUIntArg($hint_code); $focus[$hint_code] = $_REQUEST[$hint_code]; } elseif ($option_name != NULL) { $focus[$hint_code] = getConfigVar($option_name); } else { $focus[$hint_code] = NULL; } } printOpFormIntro('add'); echo '<tr>'; if ($pageno != 'object') { echo '<td>'; // hide any object that is already in the table $options = array(); foreach (getNarrowObjectList('VLANSWITCH_LISTSRC') as $object_id => $object_dname) { if (!in_array($object_id, $all_vswitches)) { $ctx = getContext(); spreadContext(spotEntity('object', $object_id)); $decision = permitted(NULL, NULL, 'del'); restoreContext($ctx); if ($decision) { $options[$object_id] = $object_dname; } } } printSelect($options, array('name' => 'object_id', 'size' => getConfigVar('MAXSELSIZE')), $focus['prev_objid']); echo '</td>'; } if ($pageno != 'vlandomain') { echo '<td>' . getSelect(getVLANDomainOptions(), array('name' => 'vdom_id', 'size' => getConfigVar('MAXSELSIZE')), $focus['prev_vdid']) . '</td>'; } if ($pageno != 'vst') { $options = array(); foreach (listCells('vst') as $nominee) { $ctx = getContext(); spreadContext($nominee); $decision = permitted(NULL, NULL, 'add'); restoreContext($ctx); if ($decision) { $options[$nominee['id']] = niftyString($nominee['description'], 30, FALSE); } } echo '<td>' . getSelect($options, array('name' => 'vst_id', 'size' => getConfigVar('MAXSELSIZE')), $focus['prev_vstid']) . '</td>'; } echo '<td>' . getImageHREF('Attach', 'set', TRUE) . '</td></tr></form>'; }
function renderNetCellForAlloc($cell, $needed_mask = NULL) { if (empty($cell['spare_ranges']) and $cell['kidc'] == 0 and $cell['mask'] < 31) { $cell['spare_ranges'][$cell['mask'] + 1][] = $cell['ip_bin']; $cell['spare_ranges'][$cell['mask'] + 1][] = ip_last($cell) & ip4_mask($cell['mask'] + 1); } $ranges = array_keys($cell['spare_ranges']); sort($ranges, SORT_NUMERIC); foreach ($ranges as &$range) { $suffix = count($cell['spare_ranges'][$range]) <= 1 ? '' : '<small> x ' . count($cell['spare_ranges'][$range]) . '</small>'; $range = '<a href="' . makeHref(array('page' => 'ipv4space', 'tab' => 'newrange', 'set-prefix' => ip_format($cell['spare_ranges'][$range][0]) . '/' . $range)) . '">/' . $range . '</a>' . $suffix; } $spare_cidr = NULL; if (isset($needed_mask)) { for ($i = $needed_mask; $i > 0; $i--) { if (!empty($cell['spare_ranges'][$i])) { $spare_cidr = ip_format($cell['spare_ranges'][$i][0]) . '/' . $needed_mask; break; } } } echo "<table class='slbcell vscell'><tr><td rowspan=3 width='5%'>"; printImageHREF('NET'); echo '</td>'; echo "<td><a href='index.php?page={$cell['realm']}&id={$cell['id']}'>{$cell['ip']}/{$cell['mask']}</a>"; echo getRenderedIPNetCapacity($cell); echo '</td></tr>'; echo "<tr><td>"; if (strlen($cell['name'])) { echo "<strong>" . niftyString($cell['name']) . "</strong>"; } else { echo "<span class=sparenetwork>no name</span>"; } // render VLAN echo '<div class="vlan">' . implode(', ', $ranges) . '</div>'; renderNetVLAN($cell); echo "</td></tr>"; echo '<tr><td>'; echo count($cell['etags']) ? "<small>" . serializeTags($cell['etags']) . "</small>" : ' '; if (isset($spare_cidr)) { echo "<div class='vlan'><a href=\"" . makeHref(array('page' => 'ipv4space', 'tab' => 'newrange', 'set-prefix' => $spare_cidr)) . "\">Allocate /{$needed_mask}</a></div>"; } echo "</td></tr></table>"; }
function lm_renderObjectCell($cell) { echo "<table class='slbcell vscell'><tr><td rowspan=2 width='5%'>"; printImageHREF('OBJECT'); echo '</td><td>'; echo mkA('<strong>' . niftyString($cell['dname']) . '</strong>', 'object', $cell['id']); echo '</td></tr><tr><td>'; echo count($cell['etags']) ? "<small>" . serializeTags($cell['etags']) . "</small>" : ' '; echo "</td></tr></table>"; }
function formatVLANName($vlaninfo, $context = 'markup long') { switch ($context) { case 'option': $ret = $vlaninfo['vlan_id']; if ($vlaninfo['vlan_descr'] != '') { $ret .= ' ' . niftyString($vlaninfo['vlan_descr']); } return $ret; case 'label': $ret = $vlaninfo['vlan_id']; if ($vlaninfo['vlan_descr'] != '') { $ret .= ' <i>(' . niftyString($vlaninfo['vlan_descr']) . ')</i>'; } return $ret; case 'plain long': $ret = 'VLAN' . $vlaninfo['vlan_id']; if ($vlaninfo['vlan_descr'] != '') { $ret .= ' (' . niftyString($vlaninfo['vlan_descr'], 20, FALSE) . ')'; } return $ret; case 'hyperlink': $ret = '<a href="'; $ret .= makeHref(array('page' => 'vlan', 'vlan_ck' => $vlaninfo['domain_id'] . '-' . $vlaninfo['vlan_id'])); $ret .= '">' . formatVLANName($vlaninfo, 'markup long') . '</a>'; return $ret; case 'markup long': default: $ret = 'VLAN' . $vlaninfo['vlan_id']; $ret .= ' @' . niftyString($vlaninfo['domain_descr']); if ($vlaninfo['vlan_descr'] != '') { $ret .= ' <i>(' . niftyString($vlaninfo['vlan_descr']) . ')</i>'; } return $ret; } }
function renderMuninConfig() { $servers = getMuninServers(); startPortlet('Munin servers (' . count($servers) . ')'); echo '<table cellspacing=0 cellpadding=5 align=center class=widetable>'; echo '<tr><th>base URL</th><th>graph(s)</th></tr>'; foreach ($servers as $server) { echo '<tr align=left valign=top><td>' . niftyString($server['base_url']) . '</td>'; echo "<td class=tdright>{$server['num_graphs']}</td></tr>"; } echo '</table>'; finishPortlet(); }