function snmpgeneric_opcreate() { $object_id = $_REQUEST['object_id']; $attr = getAttrValues($object_id); // sg_var_dump_html($_REQUEST); // sg_var_dump_html($attr); /* commitUpdateAttrValue ($object_id, $attr_id, $new_value); */ if (isset($_POST['updateattr'])) { foreach ($_POST['updateattr'] as $attr_id => $value) { // if(empty($attr[$attr_id]['value'])) if (!empty($value)) { commitUpdateAttrValue($object_id, $attr_id, $value); showSuccess("Attribute " . $attr[$attr_id]['name'] . " set to {$value}"); } } unset($attr_id); unset($value); } /* updateattr */ /* create ports */ if (isset($_POST['portcreate'])) { foreach ($_POST['portcreate'] as $if => $value) { $ifName = isset($_POST['ifName'][$if]) ? trim($_POST['ifName'][$if]) : ''; $ifPhysAddress = isset($_POST['ifPhysAddress'][$if]) ? trim($_POST['ifPhysAddress'][$if]) : ''; $ifAlias = isset($_POST['ifAlias'][$if]) ? trim($_POST['ifAlias'][$if]) : ''; $ifDescr = isset($_POST['ifDescr'][$if]) ? trim($_POST['ifDescr'][$if]) : ''; //$visible_label = (empty($ifAlias) ? '' : $ifAlias.'; ').$ifDescr; $visible_label = $ifAlias; if (empty($ifName)) { showError('Port without ifName ' . $_POST['porttypeid'][$if] . ', ' . $visible_label . ', ' . $ifPhysAddress); } else { commitAddPort($object_id, $ifName, $_POST['porttypeid'][$if], $visible_label, $ifPhysAddress); showSuccess('Port created ' . $ifName . ', ' . $_POST['porttypeid'][$if] . ', ' . $visible_label . ', ' . $ifPhysAddress); } } unset($if); unset($value); } /* portcreate */ /* net create */ if (isset($_POST['netcreate'])) { foreach ($_POST['netcreate'] as $id => $addrtype) { $range = $_POST['netprefix'][$id]; $name = $_POST['netname'][$id]; $is_reserved = isset($_POST['netreserve'][$id]); if ($addrtype == 'ipv4' || $addrtype == 'ipv4z') { createIPv4Prefix($range, $name, $is_reserved); } else { createIPv6Prefix($range, $name, $is_reserved); } showSuccess("{$range} {$name} created"); } unset($id); unset($addrtype); } /* netcreate */ /* allocate ipv6 adresses */ if (isset($_POST['ipv6addrcreate'])) { foreach ($_POST['ipv6addrcreate'] as $ipaddr => $if) { bindIPv6ToObject(ip6_parse($ipaddr), $object_id, $_POST['ifName'][$if], 1); /* connected */ showSuccess("{$ipaddr} allocated"); } unset($ipaddr); unset($if); } /* allocate ip adresses */ if (isset($_POST['ipaddrcreate'])) { foreach ($_POST['ipaddrcreate'] as $ipaddr => $if) { bindIPToObject(ip_parse($ipaddr), $object_id, $_POST['ifName'][$if], 1); /* connected */ showSuccess("{$ipaddr} allocated"); } unset($ipaddr); unset($if); } /* ipaddrecreate */ /* update label */ if (isset($_POST['updatelabel'])) { foreach ($_POST['updatelabel'] as $if => $port_id) { $ifAlias = isset($_POST['ifAlias'][$if]) ? trim($_POST['ifAlias'][$if]) : ''; sg_commitUpdatePortLabel($object_id, $port_id, $ifAlias); $ifName = isset($_POST['ifName'][$if]) ? trim($_POST['ifName'][$if]) : ''; showSuccess("label updated on {$ifName} to {$ifAlias}"); } unset($if); unset($port_id); } /* updatemac */ /* update mac addresses only */ if (isset($_POST['updatemac'])) { foreach ($_POST['updatemac'] as $if => $port_id) { $ifPhysAddress = isset($_POST['ifPhysAddress'][$if]) ? trim($_POST['ifPhysAddress'][$if]) : ''; sg_commitUpdatePortl2address($object_id, $port_id, $ifPhysAddress); $ifName = isset($_POST['ifName'][$if]) ? trim($_POST['ifName'][$if]) : ''; showSuccess("l2address updated on {$ifName} to {$ifPhysAddress}"); } unset($if); unset($port_id); } /* updatemac */ /* update port type */ if (isset($_POST['updateporttype'])) { foreach ($_POST['updateporttype'] as $if => $port_id) { $porttypeid = isset($_POST['porttypeid'][$if]) ? trim($_POST['porttypeid'][$if]) : ''; sg_commitUpdatePortType($object_id, $port_id, $porttypeid); $ifName = isset($_POST['ifName'][$if]) ? trim($_POST['ifName'][$if]) : ''; showSuccess("port type updated on {$ifName}"); } unset($if); unset($port_id); } /* updateporttype */ }
function renderIPv6NetworkAddresses($netinfo) { global $pageno, $tabno, $aac_left; echo "<table class='widetable' border=0 cellspacing=0 cellpadding=5 align='center' width='100%'>\n"; echo "<tr><th>Address</th><th>Name</th><th>Comment</th><th>Allocation</th></tr>\n"; $hl_ip = NULL; if (isset($_REQUEST['hl_ip'])) { $hl_ip = ip6_parse($_REQUEST['hl_ip']); addAutoScrollScript('ip-' . ip6_format($hl_ip)); } $addresses = $netinfo['addrlist']; ksort($addresses); markupIPAddrList($addresses); // pager $maxperpage = getConfigVar('IPV4_ADDRS_PER_PAGE'); if (count($addresses) > $maxperpage && $maxperpage > 0) { $page = isset($_REQUEST['pg']) ? $_REQUEST['pg'] : (isset($hl_ip) ? getPageNumOfIPv6($addresses, $hl_ip, $maxperpage) : 0); $numpages = ceil(count($addresses) / $maxperpage); echo "<center><h3>{$numpages} pages:</h3>"; for ($i = 0; $i < $numpages; $i++) { if ($i == $page) { echo "<b>{$i}</b> "; } else { echo "<a href='" . makeHref(array('page' => $pageno, 'tab' => $tabno, 'id' => $netinfo['id'], 'pg' => $i)) . "'>{$i}</a> "; } } echo "</center>"; } $i = 0; $interruped = FALSE; $prev_ip = ip_prev($netinfo['ip_bin']); foreach ($addresses as $ip_bin => $addr) { if (isset($page)) { ++$i; if ($i <= $maxperpage * $page) { continue; } elseif ($i > $maxperpage * ($page + 1)) { $interruped = TRUE; break; } } if ($ip_bin != ip_next($prev_ip)) { renderSeparator(ip_next($prev_ip), ip_prev($ip_bin), $hl_ip); } $prev_ip = $ip_bin; // render IP change history $title = ''; $history_class = ''; if (isset($addr['last_log'])) { $title = ' title="' . htmlspecialchars($addr['last_log']['user'] . ', ' . formatAge($addr['last_log']['time']), ENT_QUOTES) . '"'; $history_class = 'hover-history underline'; } $tr_class = $addr['class'] . ' tdleft' . ($hl_ip === $ip_bin ? ' highlight' : ''); echo "<tr class='{$tr_class}'>"; echo "<td><a class='{$history_class}' {$title} name='ip-{$addr['ip']}' href='" . makeHref(array('page' => 'ipaddress', 'ip' => $addr['ip'])) . "'>{$addr['ip']}</a></td>"; $editable = empty($addr['allocs']) || !empty($addr['name']) && permitted('ipaddress', 'properties', 'editAddress') ? 'editable' : ''; echo "<td><span class='rsvtext {$editable} id-{$addr['ip']} op-upd-ip-name'>{$addr['name']}</span></td>"; echo "<td><span class='rsvtext {$editable} id-{$addr['ip']} op-upd-ip-comment'>{$addr['comment']}</span></td><td>"; $delim = ''; if ($addr['reserved'] == 'yes') { echo "<strong>RESERVED</strong> "; $delim = '; '; } foreach ($addr['allocs'] as $ref) { echo $delim . $aac_left[$ref['type']]; echo makeIPAllocLink($ip_bin, $ref, TRUE); $delim = '; '; } if ($delim != '') { $delim = '<br>'; } foreach ($addr['vslist'] as $vs_id) { $vs = spotEntity('ipv4vs', $vs_id); echo $delim . mkA("{$vs['name']}:{$vs['vport']}/{$vs['proto']}", 'ipv4vs', $vs['id']) . '→'; $delim = '<br>'; } foreach ($addr['vsglist'] as $vs_id) { $vs = spotEntity('ipvs', $vs_id); echo $delim . mkA($vs['name'], 'ipvs', $vs['id']) . '→'; $delim = '<br>'; } foreach ($addr['rsplist'] as $rsp_id) { $rsp = spotEntity('ipv4rspool', $rsp_id); echo "{$delim}→" . mkA($rsp['name'], 'ipv4rspool', $rsp['id']); $delim = '<br>'; } echo "</td></tr>\n"; } if (!$interruped) { renderSeparator(ip_next($prev_ip), ip_last($netinfo), $hl_ip); } if (isset($page)) { // bottom pager echo "<tr><td colspan=3>"; if ($page > 0) { echo "<a href='" . makeHref(array('page' => $pageno, 'tab' => $tabno, 'id' => $netinfo['id'], 'pg' => $page - 1)) . "'><< prev</a> "; } if ($page < $numpages - 1) { echo "<a href='" . makeHref(array('page' => $pageno, 'tab' => $tabno, 'id' => $netinfo['id'], 'pg' => $page + 1)) . "'>next >></a> "; } echo "</td></tr>"; } echo "</table>"; if (permitted(NULL, NULL, 'set_reserve_comment')) { addJS('js/inplace-edit.js'); } }
function createIPv6Prefix($range = '', $name = '', $is_connected = FALSE, $taglist = array(), $vlan_ck = NULL) { // $range is in aaa0:b::c:d/x format, split into ip/mask vars $rangeArray = explode('/', $range); if (count($rangeArray) != 2) { throw new InvalidRequestArgException('range', $range, 'Invalid IPv6 prefix'); } $ip = $rangeArray[0]; $mask = $rangeArray[1]; $net = constructIPRange(ip6_parse($ip), $mask); usePreparedInsertBlade('IPv6Network', array('ip' => $net['ip_bin'], 'last_ip' => ip_last($net), 'mask' => $mask, 'name' => $name)); $network_id = lastInsertID(); # RFC3513 2.6.1 - Subnet-Router anycast if ($is_connected) { updateV6Address($net['ip_bin'], 'Subnet-Router anycast', 'yes'); } produceTagsForNewRecord('ipv6net', $taglist, $network_id); if ($vlan_ck != NULL) { $ctx = getContext(); fixContext(spotEntity('ipv6net', $network_id)); if (permitted('ipv6net', '8021q', 'bind')) { commitSupplementVLANIPv6($vlan_ck, $network_id); } restoreContext($ctx); } return $network_id; }
function ip6_checkparse($ip) { try { return ip6_parse($ip); } catch (InvalidArgException $e) { return FALSE; } }