# set and check permissions $subnet_permission = $Subnets->check_permission($User->user, $subnet['id']); $subnet_permission > 1 ?: $Result->show("danger", _('Cannot edit IP address details') . '! <br>' . _('You do not have write access for this network'), true, true); # set selected address fields array $selected_ip_fields = $User->settings->IPfilter; $selected_ip_fields = explode(";", $selected_ip_fields); //format to array # get all custom fields $custom_fields = $Tools->fetch_custom_fields('ipaddresses'); # if subnet is full we cannot any more ip addresses if (($action == "add" || $action == "all-add") && $subnet['isFull'] == 1) { $Result->show("warning", _("Cannot add address as subnet is market as used"), true, true); } # if action is not add then fetch current details, otherwise fetch first available IP address if ($action == "all-add") { $address['ip_addr'] = $Subnets->transform_address($id, "dotted"); } else { if ($action == "add") { # get first available IP address $first = $Addresses->get_first_available_address($subnetId, $Subnets); $first = !$first ? "" : $Subnets->transform_address($first, "dotted"); $address['ip_addr'] = $first; } else { $address = (array) $Addresses->fetch_address(null, $id); } } # Set action and button text if ($action == "add") { $btnName = _("add"); $act = "add"; } else {
if ($l['isFolder'] == 1) { $l['ctype'] = "Folder"; } else { $l['ctype'] = "Subnet"; } break; case "section": $l['ctype'] = "Section"; break; } print "<tr>"; print "\t<td>{$l['real_name']}</td>"; print "\t<td>{$l['ctype']} / {$l['caction']} {$l['cresult']}</td>"; # subnet, section or ip address if ($l['ctype'] == "IP address") { print "\t<td><a href='" . create_link("subnets", $l['sectionId'], $l['subnetId'], "address-details", $l['tid']) . "'>" . $Subnets->transform_address($l['ip_addr'], "dotted") . "</a></td>"; } elseif ($l['ctype'] == "Subnet") { print "\t<td><a href='" . create_link("subnets", $l['sectionId'], $l['tid']) . "'>" . $Subnets->transform_address($l['ip_addr'], "dotted") . "/{$l['mask']}</a></td>"; } elseif ($l['ctype'] == "Folder") { print "\t<td><a href='" . create_link("folder", $l['sectionId'], $l['tid']) . "'>{$l['sDescription']}</a></td>"; } elseif ($l['ctype'] == "Section") { print "\t<td><a href='" . create_link("subnets", $l['tid']) . "'>{$l['sDescription']}</a></td>"; } print "\t<td>{$l['cdate']}</td>"; print "\t<td class='hidden-xs'>" . implode("<br>", $diff) . "</td>"; print "</tr>"; // next item $pc++; } } }
$User->check_user_session(); # id must be numeric is_numeric($_POST['id']) || strlen($_POST['id']) == 0 ?: $Result->show("danger", _("Invalid ID"), true); # get IP address id $id = $_POST['id']; # fetch subnet, vlan and nameservers $subnet = (array) $Subnets->fetch_subnet(null, $_POST['id']); $vlan = (array) $Tools->fetch_object("vlans", "vlanId", $subnet['vlanId']); $vrf = (array) $Tools->fetch_object("vrf", "vrfId", $subnet['vrfId']); $nameservers = (array) $Tools->fetch_object("nameservers", "id", $subnet['nameserverId']); # get all custom fields $custom_fields = $Tools->fetch_custom_fields('subnets'); # checks sizeof($subnet) > 0 ?: $Result->show("danger", _("Invalid subnet"), true); # set title $title = _('Subnet details') . ' :: ' . $Subnets->transform_address($subnet['subnet'], "dotted") . "/" . $subnet['mask']; # address $content[] = "• " . _('Subnet') . ": \t\t " . $Subnets->transform_address($subnet['subnet'], "dotted") . "/" . $subnet['mask']; # description empty($subnet['description']) ?: ($content[] = "• " . _('Description') . ":\t\t {$subnet['description']}"); # gateway $gateway = $Subnets->find_gateway($subnet['id']); if ($gateway !== false) { $content[] = "• " . _('Gateway') . ": \t\t" . $Subnets->transform_to_dotted($gateway->ip_addr); } # VLAN empty($subnet['vlanId']) ?: ($content[] = "• " . _('VLAN') . ": \t\t\t {$vlan['number']} ({$vlan['name']})"); # VLAN empty($subnet['vlanId']) ?: ($content[] = "• " . _('VRF') . ": \t\t\t {$vrf['name']} ({$vrf['description']})"); # Nameserver sets if (!empty($subnet['nameserverId'])) {
$Subnets = new Subnets($Database); $Addresses = new Addresses($Database); $Tools = new Tools($Database); $Result = new Result(); # fetch all subnets $all_subnets = $Tools->fetch_all_objects("subnets"); # loop and check usage for each, make sure it does not have any parent foreach ($all_subnets as $k => $s) { // marked as full should not be checked if ($s->isFull != 1) { // parent check if (!$Subnets->has_slaves($s->id)) { // count number of addresses $cnt = $Addresses->count_subnet_addresses($s->id); // calculate usage $usage = $Subnets->calculate_subnet_usage($cnt, $s->mask, $s->subnet, $s->isFull); // if more than $threshold report if ($usage['freehosts_percent'] < 100 - $limit) { // this subnet has high usage, save it to array $out[$k]['subnet'] = $Subnets->transform_address($s->subnet, "dotted") . "/" . $s->mask; $out[$k]['description'] = $s->description; $out[$k]['usage'] = $usage; } } } } # any fount if (isset($out)) { // do something with output print_r($out); }
print "</tr>"; print "<tbody id=device-{$deviceid}>"; foreach ($query_result as $ip) { //get bitmask foreach ($masks as $k => $n) { if ($n->netmask == $ip['mask']) { $ip['bitmask'] = $k; break; } } $overlap = false; // check for overlapping if (isset($subnet)) { if ($subnet->isFolder != "1") { // check if ($Subnets->is_subnet_inside_subnet("{$ip['subnet']}/{$ip['bitmask']}", $Subnets->transform_address($subnet->subnet, "dotted") . "/" . $subnet->mask) === false) { $overlap = true; } // same mask if ($ip['subnet'] == $Subnets->transform_address($subnet->subnet, "dotted") && $ip['bitmask'] == $subnet->mask) { $overlap = true; } } } // check overlapping if ($overlap === false) { $dc++; print "<tr id='tr-{$m}'>"; //ip print "<td>{$ip['subnet']}/{$ip['bitmask']}</td>"; //section, description, hidden
print "<table class='ipaddress_subnet table table-noborder table-condensed' style='margin-top:10px;'>"; print "<tr>"; print "\t<th>" . _('Hostname') . "</th>"; print " <td>" . $resolve['name'] . "</td>\n"; print "</tr>"; print "<tr>"; print "\t<th>" . _('Address') . "</th>"; print " <td>" . $address['ip'] . "</td>\n"; print "</tr>"; print "<tr>"; print "\t<th>" . _('Subnet Mask') . "</th>"; print " <td>" . $mask . "</td>\n"; print "</tr>"; print "<tr>"; print "\t<th>" . _('Default Gateway') . "</th>"; print " <td>" . $Subnets->transform_address($gateway->ip_addr, "dotted") . "</td>\n"; print "</tr>"; print "</table>"; ?> </div> <!-- footer --> <div class="pFooter"> <div class="btn-group"> <button class="btn btn-sm btn-default hidePopups"><?php print _('Close'); ?> </button> </div> <div class="manageSubnetEditResult"></div>
<!-- divider --> <tr> <td colspan="2"><hr></td> </tr> <tr> <td><?php print _('Select new subnet'); ?> :</td> <td> <select name="newSubnet" class="ip_addr form-control input-sm input-w-auto"> <?php foreach ($Subnets->slaves as $slave) { $slave_subnet = (array) $Subnets->fetch_subnet(null, $slave); print "<option value='{$slave_subnet['id']}'>{$slave_subnet['description']} (" . $Subnets->transform_address($slave_subnet['subnet'], "dotted") . "/{$slave_subnet['mask']})</option>"; } ?> </select> </td> </tr> </table> <!-- end edit ip address table --> </form> <!-- end IP address edit form --> </div> <!-- footer --> <div class="pFooter"> <div class="btn-group">
print "</div>"; } else { $c = 0; # for each IP in range modify while (gmp_cmp($m, $n) != 0) { # remove gateway if not 0 if ($c != 0) { unset($address['is_gateway']); } $c++; # reset IP address field $address['ip_addr'] = $m; # set multicast MAC if ($User->settings->enableMulticast == 1) { if ($Subnets->is_multicast($address['ip_addr'])) { $address['mac'] = $Subnets->create_multicast_mac($Subnets->transform_address($address['ip_addr'], "dotted")); } } # multicast check if ($User->settings->enableMulticast == 1) { if ($Subnets->is_multicast($address['ip_addr'])) { if (!$User->is_admin(false)) { $mtest = $Subnets->validate_multicast_mac($address['mac'], $subnet['sectionId'], $subnet['vlanId'], MCUNIQUE); if ($mtest !== true) { $Result->show("danger", _($mtest), true); } } } } # validate and normalize MAC address if ($action !== "delete") {
$Result = new Result(); # verify that user is logged in $User->check_user_session(); # validate csrf cookie $_POST['csrf_cookie'] == $_SESSION['csrf_cookie'] ?: $Result->show("danger", _("Invalid CSRF cookie"), true); # ID must be numeric if (!is_numeric($_POST['subnetId'])) { $Result->show("danger", _("Invalid ID"), true); } # verify that user has write permissions for subnet if ($Subnets->check_permission($User->user, $_POST['subnetId']) < 3) { $Result->show("danger", _('You do not have permissions to resize subnet') . '!', true); } # fetch old subnet details and set new $subnet_old = (array) $Subnets->fetch_subnet(null, $_POST['subnetId']); # verify resizing $Subnets->verify_subnet_resize($subnet_old['subnet'], $_POST['newMask'], $subnet_old['id'], $subnet_old['vrfId'], $subnet_old['masterSubnetId'], $subnet_old['mask'], $subnet_old['sectionId']); # we need to recalculate subnet address if needed if ($subnet_old['mask'] < $_POST['newMask']) { $subnet_new['subnet'] = $subnet_old['subnet']; } else { $new_boundaries = $Subnets->get_network_boundaries($Subnets->transform_address($subnet_old['subnet'], "dotted"), $_POST['newMask']); $subnet_new['subnet'] = $Subnets->transform_address($new_boundaries['network'], "decimal"); } # set update values $values = array("id" => $_POST['subnetId'], "subnet" => $subnet_new['subnet'], "mask" => $_POST['newMask']); if (!$Subnets->modify_subnet("resize", $values)) { $Result->show("danger", _("Error resizing subnet") . "!", true); } else { $Result->show("success", _("Subnet resized successfully") . "!", true); }
/** * Fetches all possible subnet addresses * * @access private * @param $subnet //subnet in decimal format * @param int $mask //subnet mask * @return void //array of ip addresses in decimal format */ private function get_all_possible_subnet_addresses($subnet, $mask) { # initialize classes $Subnets = new Subnets($this->Database); # make sure we have proper subnet format $subnet = $Subnets->transform_address($subnet, "decimal"); //fetch start and stop addresses $boundaries = (object) $Subnets->get_network_boundaries($subnet, $mask); //create array if ($mask == 32) { $ip[] = $Subnets->transform_to_decimal($boundaries->network); } elseif ($mask == 31) { $ip[] = $Subnets->transform_to_decimal($boundaries->network); $ip[] = $Subnets->transform_to_decimal($boundaries->broadcast); } else { //set loop limits $start = gmp_strval(gmp_add($Subnets->transform_to_decimal($boundaries->network), 1)); $stop = gmp_strval($Subnets->transform_to_decimal($boundaries->broadcast)); //loop for ($m = $start; $m < $stop; $m++) { $ip[] = $m; } } //return return $ip; }
# error - none found but not permitted if ($inactive_hosts === false) { print "<blockquote style='margin-top:20px;margin-left:20px;'>"; print "<p>" . _("No inactive hosts found") . "</p>"; print "</blockquote>"; } elseif (!isset($out)) { print "<blockquote style='margin-top:20px;margin-left:20px;'>"; print "<p>" . _("No inactive hosts found") . "</p>"; print "</blockquote>"; } else { // table print "<table class='table table-top table-threshold'>"; print "<tr>"; print " <th></th>"; print " <th>" . _("Address") . "</th>"; print " <th>" . _("Subnet") . "</th>"; print " <th>" . _("Hostname") . "</th>"; print " <th>" . _("Last seen") . "</th>"; print "</tr>"; // print foreach ($out as $s) { print "<tr>"; print " <td><span class='status status-error'></span></td>"; print " <td><a href='" . create_link("subnets", $s->sectionId, $s->subnetId, "address-details", $s->id) . "'>" . $Subnets->transform_address($s->ip_addr) . "</a></td>"; print " <td><a href='" . create_link("subnets", $s->sectionId, $s->subnetId) . "'>" . $Subnets->transform_address($s->subnet) . "/" . $s->mask . "</a></td>"; print " <td>{$s->dns_name}</td>"; print " <td>{$s->lastSeen}</td>"; print "</tr>"; } print "</table>"; }
} array_multisort($used, SORT_DESC, $out); // table print "<table class='table table-threshold table-noborder'>"; // print $m = 0; foreach ($out as $s) { if ($m < $slimit) { # set class $aclass = $s->usage->usedhosts_percent > $s->threshold ? "progress-bar-danger" : "progress-bar-info"; # limit description $s->description = strlen($s->description) > 10 ? substr($s->description, 0, 10) . "..." : $s->description; $s->description = strlen($s->description) > 0 ? " (" . $s->description . ")" : ""; # limit class $limit_class = $s->usage->until_threshold < 0 ? "progress-limit-negative" : "progress-limit"; print "<tr>"; print " <td><i class='fa fa-sfolder fa-sitemap' style='border-right: 1px solid #ccc;padding-right:4px;'></i> <a href='" . create_link("subnets", $s->sectionId, $s->id) . "'>" . $Subnets->transform_address($s->subnet) . "/" . $s->mask . "</a> " . $s->description . "</td>"; print " <td>"; print " <div class='progress'>"; print " <div class='progress-bar {$aclass}' role='progressbar' rel='tooltip' title='" . _('Current usage') . ": " . $s->usage->usedhosts_percent . "%' aria-valuenow='" . $s->usage->usedhosts_percent . "' aria-valuemin='0' style='width: " . $s->usage->usedhosts_percent . "%;'>" . $s->usage->usedhosts_percent . "%</div>"; print " <div class='{$limit_class}' rel='tooltip' title='" . _('Threshold') . ": " . $s->threshold . "%' style='margin-left:" . $s->usage->until_threshold . "%;'> </div>"; print " </div>"; print " </td>"; print "</tr>"; // next index $m++; } } print "</table>"; print "</div>"; }
# ignore folders if ($subnet['isFolder']) { continue; } # store needed subnet information $subnet_data[$section['id']][$subnet['vrfId']][$subnet['ip']][$subnet['mask']] = $subnet; $subnet_data[$section['id']][$subnet['vrfId']][$subnet['ip']][$subnet['mask']]['type'] = $Subnets->identify_address($subnet['ip']); # grab IP addresses $ipaddresses = $Addresses->fetch_subnet_addresses($subnet['id']); if (sizeof($ipaddresses) == 0) { continue; } foreach ($ipaddresses as $ip) { //cast $ip = (array) $ip; $edata[$section['id']][$subnet['vrfId']][$subnet['ip']][$subnet['mask']][$Subnets->transform_address($ip['ip_addr'], "dotted")] = $ip; } } } # Load available tags $tag_data = array(); $ip_tags = (array) $Addresses->addresses_types_fetch(); foreach ($ip_tags as $c_tag) { $tag_data[$c_tag['type']] = $c_tag; } # Load available devices $device_data = array(); $devices = $Tools->fetch_all_objects("devices", "hostname"); if ($devices !== false) { foreach ($devices as $c_dev) { $c_dev = (array) $c_dev;
$format_right =& $workbook->addFormat(); $format_right->setRight(1); $format_left =& $workbook->addFormat(); $format_left->setLeft(1); $format_top =& $workbook->addFormat(); $format_top->setTop(1); // Create a worksheet //$worksheet =& $workbook->addWorksheet($subnet['description']); $worksheet_name = $subnet['description']; $worksheet_name = strlen($worksheet_name) > 30 ? substr($worksheet_name, 0, 27) . '...' : $worksheet_name; $worksheet =& $workbook->addWorksheet($worksheet_name); $lineCount = 0; # Write title - subnet details $worksheet->write($lineCount, $rowCount, $subnet['description'], $format_header); $lineCount++; $worksheet->write($lineCount, $rowCount, $Subnets->transform_address($subnet['subnet'], "dotted") . "/" . $subnet['mask'], $format_header); $lineCount++; # write VLAN details $vlan = (array) $Tools->fetch_object("vlans", "vlanId", $subnet['vlanId']); if ($vlan != false) { $vlan_text = strlen($vlan['name']) > 0 ? "vlan: {$vlan['number']} - {$vlan['name']}" : "vlan: {$vlan['number']}"; $worksheet->write($lineCount, $rowCount, $vlan_text, $format_vlan); $lineCount++; } $lineCount++; //set row count $rowCount = 0; //write headers if (isset($_GET['ip_addr']) && $_GET['ip_addr'] == "on") { $worksheet->write($lineCount, $rowCount, _('ip address'), $format_title); $rowCount++;
print "<div style='display:none'>alert alert-danger</div>"; # result print "<div class='alert alert-warning'>"; print "<strong>" . _("Warning") . "</strong>: " . _("Are you sure you want to delete IP address") . "?"; print "<hr><div style='text-align:right'>"; print "<div class='btn-group'>"; print "\t<a class='btn btn-sm btn-danger editIPSubmitDelete' id='editIPSubmitDelete'>" . _("Confirm") . "</a>"; print "</div>"; print "</div>"; print "</div>"; } else { //fail if (!$Addresses->modify_address($address)) { $Result->show("danger", _('Error inserting IP address') . "!", false); } else { $Result->show("success", _("IP {$action} successful"), false); // try to ping if ($subnet['pingSubnet'] == "1" && $action == "add") { $Ping->ping_address($Subnets->transform_address($address['ip_addr'], "dotted")); // update status if ($pingRes == 0) { // print alive $Result->show("success", _("IP address") . " " . $Subnets->transform_address($address['ip_addr'], "dotted") . " " . _("is alive"), false); // update status @$Ping->ping_update_lastseen($Addresses->lastId); } } } } } }
$Admin = new Admin($Database, false); $Subnets = new Subnets($Database); $DNS = new DNS($Database); $Result = new Result(); # insert to database $discovered = 0; //for mailing foreach ($scan_subnets as $s) { if (sizeof(@$s->discovered) > 0) { foreach ($s->discovered as $ip) { // try to resolve hostname $tmp = new stdClass(); $tmp->ip_addr = $ip; $hostname = $DNS->resolve_address($tmp, true); //set update query $values = array("subnetId" => $s->id, "ip_addr" => $Subnets->transform_address($ip, "decimal"), "dns_name" => $hostname['name'], "description" => "-- autodiscovered --", "note" => "This host was autodiscovered on " . date("Y-m-d H:i:s"), "lastSeen" => date("Y-m-d H:i:s")); $Admin->object_modify("ipaddresses", "add", "id", $values); //set discovered $discovered++; } } } # send mail if ($discovered > 0 && $send_mail) { # check for recipients foreach ($Admin->fetch_multiple_objects("users", "role", "Administrator") as $admin) { if ($admin->mailNotify == "Yes") { $recepients[] = array("name" => $admin->real_name, "email" => $admin->email); } } # none?
} //insert to ipaddresses table $values = array("action" => "add", "ip_addr" => $Addresses->transform_address($_POST['ip_addr'], "decimal"), "subnetId" => $_POST['subnetId'], "description" => @$_POST['description'], "dns_name" => @$_POST['dns_name'], "mac" => @$_POST['mac'], "owner" => @$_POST['owner'], "state" => @$_POST['state'], "switch" => @$_POST['switch'], "port" => @$_POST['port'], "note" => @$_POST['note']); if (!$Addresses->modify_address($values)) { $Result->show("danger", _("Failed to create IP address"), true); } //accept message $values2 = array("id" => $_POST['requestId'], "processed" => 1, "accepted" => 1, "adminComment" => $comment); if (!$Admin->object_modify("requests", "edit", "id", $values2)) { $Result->show("danger", _("Cannot confirm IP address"), true); } else { $Result->show("success", _("IP request accepted/rejected"), false); } # send mail //save subnt $tmp['subnetId'] = $_POST['subnetId']; unset($_POST['subnetId']); // gateway $gateway = $Subnets->find_gateway($tmp['subnetId']); if ($gateway !== false) { $tmp['gateway'] = $Subnets->transform_address($gateway->ip_addr, "dotted"); } //set vlan $vlan = $Tools->fetch_object("vlans", "vlanId", $subnet['vlanId']); $tmp['vlan'] = $vlan == false ? "" : $vlan->number . " - " . $vlan->description; //set dns $dns = $Tools->fetch_object("nameservers", "id", $subnet['nameserverId']); $tmp['dns'] = $dns == false ? "" : $dns->description . " <br> " . str_replace(";", ", ", $dns->namesrv1); $_POST = array_merge($tmp, $_POST); $Tools->ip_request_send_mail("accept", $_POST); }
$DNS = new DNS($Database); $Scan = new Scan($Database); $Result = new Result(); # insert to database $discovered = 0; //for mailing foreach ($scan_subnets as $s) { if (sizeof(@$s->discovered) > 0) { foreach ($s->discovered as $ip) { // fetch subnet $subnet = $Subnets->fetch_subnet("id", $s->id); $nsid = $subnet === false ? false : $subnet->nameserverId; // try to resolve hostname $hostname = $DNS->resolve_address($ip, false, true, $nsid); //set update query $values = array("subnetId" => $s->id, "ip_addr" => $Subnets->transform_address($ip, "decimal"), "dns_name" => $hostname['name'], "description" => "-- autodiscovered --", "note" => "This host was autodiscovered on " . $nowdate, "lastSeen" => $nowdate, "state" => "2", "action" => "add"); //insert $Addresses->modify_address($values); //set discovered $discovered++; } } } # update scan time $Scan->ping_update_scanagent_checktime(1, $nowdate); # send mail if ($discovered > 0 && $send_mail) { # check for recipients foreach ($Admin->fetch_multiple_objects("users", "role", "Administrator") as $admin) { if ($admin->mailNotify == "Yes") { $recepients[] = array("name" => $admin->real_name, "email" => $admin->email);
<!-- header --> <div class="pHeader"><?php print _('Link IPv4 subnet to IPv6 subnet'); ?> </div> <!-- content --> <div class="pContent"> <span class='muted'><?php print _('Select IPv6 subnet to link to current subnet'); ?> <?php print $Subnets->transform_address($subnet->subnet, "botted"); ?> /<?php print $subnet->mask; ?> </span> <hr> <form id="editLinkedSubnet"> <select name="linked_subnet" class="form-control input-sm input-w-auto" style="margin-bottom: 20px;"> <option value="0"><?php print _("Not linked"); ?> </option> <?php