$settings = getAllSettings(); # title print "<h4>" . _('Available subnets') . "</h4>"; # check permission $permission = checkSectionPermission($_REQUEST['section']); if ($permission != "0") { # print table structure print "<table id='manageSubnets' class='table table-striped table-condensed table-top table-absolute'>"; # set colcount if ($settings['enableVRF'] == 1) { $colCount = 8; } else { $colCount = 7; } # get all subnets in section $subnets = fetchSubnets($_REQUEST['section']); # remove custom fields if all empty! */ foreach ($custom as $field) { $sizeMyFields[$field['name']] = 0; // default value # check against each IP address foreach ($subnets as $subn) { if (strlen($subn[$field['name']]) > 0) { $sizeMyFields[$field['name']]++; // +1 } } # unset if value == 0 if ($sizeMyFields[$field['name']] == 0) { unset($custom[$field['name']]); } else {
/** * Set Query for update section */ function setUpdateSectionQuery($update) { # add section if ($update['action'] == "add" || $update['action'] == "create") { $query = 'Insert into sections (`name`,`description`,`permissions`,`strictMode`,`subnetOrdering`,`showVLAN`,`showVRF`, `masterSection`) values ("' . $update['name'] . '", "' . $update['description'] . '", "' . $update['permissions'] . '", "' . isCheckbox($update['strictMode']) . '", "' . $update['subnetOrdering'] . '", "' . isCheckbox($update['showVLAN']) . '", "' . isCheckbox($update['showVRF']) . '", "' . $update['masterSection'] . '");'; } else { if ($update['action'] == "edit" || $update['action'] == "update") { $section_old = getSectionDetailsById($update['id']); # Get old section name for update # Update section $query = "update `sections` set `name` = '{$update['name']}', `description` = '{$update['description']}', `permissions` = '{$update['permissions']}', `strictMode`='" . isCheckbox($update['strictMode']) . "', `subnetOrdering`='{$update['subnetOrdering']}', `showVLAN`='" . isCheckbox($update['showVLAN']) . "', `showVRF`='" . isCheckbox($update['showVRF']) . "', `masterSection`='{$update['masterSection']}' where `id` = '{$update['id']}';"; # delegate permissions if set if ($update['delegate'] == 1) { $query .= "update `subnets` set `permissions` = '{$update['permissions']}' where `sectionId` = '{$update['id']}';"; } } else { if ($update['action'] == "delete") { /* we must delete many entries - section, all belonging subnets and ip addresses */ $sectionId = $update['id']; # delete sections query $query = "delete from `sections` where `id` = '{$sectionId}';" . "\n"; # delete belonging subnets $query .= "delete from `subnets` where `sectionId` = '{$sectionId}';" . "\n"; # delete IP addresses query $subnets = fetchSubnets($sectionId); if (sizeof($subnets) != 0) { foreach ($subnets as $subnet) { $query .= "delete from `ipaddresses` where `subnetId` = '{$subnet['id']}';" . "\n"; } } # if it has subsections delete all subsections and subnets/ip addresses if (sizeof($subsections = getAllSubSections($sectionId)) > 0) { foreach ($subsections as $ss) { $query .= "delete from `sections` where `id` = '{$ss['id']}';" . "\n"; $query .= "delete from `subnets` where `sectionId` = '{$ss['id']}';" . "\n"; $ssubnets = fetchSubnets($ss['id']); if (sizeof($ssubnets) != 0) { foreach ($ssubnets as $subnet) { $query .= "delete from `ipaddresses` where `subnetId` = '{$subnet['id']}';" . "\n"; } } } } } } } /* return query */ return $query; }
/** * get subnet details */ public function getSubnet() { /** * all subnets */ if ($this->all) { //get subnet by id $res = fetchAllSubnets(); } elseif ($this->sectionId) { //id must be set and numberic if (is_null($this->sectionId) || !is_numeric($this->sectionId)) { throw new Exception('Invalid section Id - ' . $this->sectionId); } //get all subnets in section $res = fetchSubnets($this->sectionId); //throw new exception if not existing if (sizeof($res) == 0) { //check if section exists if (sizeof(getSectionDetailsById($this->sectionId)) == 0) { throw new Exception('Section not existing'); } } } elseif ($this->id) { //id must be set and numberic if (is_null($this->id) || !is_numeric($this->id)) { throw new Exception('Subnet id not existing - ' . $this->id); } //get subnet by id $res = getSubnetDetailsById($this->id); //throw new exception if not existing if (sizeof($res) == 0) { throw new Exception('Subnet not existing'); } } elseif ($this->name) { //id must be set and numberic if (is_null($this->name) || strlen($this->name) == 0) { throw new Exception('Invalid subnet name - ' . $this->name); } //get subnet by id $res = getSubnetDetailsByName($this->name); //throw new exception if not existing if (sizeof($res) == 0) { throw new Exception('Subnet not existing'); } } else { throw new Exception('Selector missing'); } //create object from results foreach ($res as $key => $line) { $this->{$key} = $line; } //output format $format = $this->format; //remove input parameters from output unset($this->all); //remove from result array unset($this->format); unset($this->name); unset($this->id); unset($this->sectionId); //convert object to array $result = $this->toArray($this, $format); //return result return $result; }
$action = 'close'; } # Check if it has parent, and if so print back link if ($sectionName['masterSection'] != "0") { # get details $mSection = getSectionDetailsById($sectionName['masterSection']); print "<div class='subnets' style='padding-top:10px;'>"; print "\t<a href='subnets/{$mSection['id']}/'><i class='fa fa-gray fa-angle-left fa-pad-left'></i> " . _('Back to') . " {$mSection['name']}</a><hr>"; print "</div>"; } print "<h4>" . _('Available subnets') . " <span class='pull-right' style='margin-right:5px;cursor:pointer;'><i class='fa fa-gray fa-sm {$iconClass}' rel='tooltip' data-placement='bottom' title='" . _('Expand/compress all folders') . "' id='expandfolders' data-action='{$action}'></i></span></h4>"; print "<hr>"; /* print subnets table ---------- */ print "<div class='subnets'>"; # print links $subnets2 = fetchSubnets($sectionId); $menu = get_menu_html($subnets2); print $menu; print "</div>"; # end subnets overlay /* print VLANs */ if ($sectionName['showVLAN'] == 1) { $vlans = getAllVlansInSection($sectionId); # if some is present if ($vlans) { print "<div class='subnets'>"; # title print "<hr><h4>" . _('Available VLANs') . "</h4><hr>"; # create and print menu $menuVLAN = get_menu_vlan($vlans, $sectionId); print $menuVLAN;
/** * Print dropdown menu for subnets in section! */ function printDropdownMenuBySection($sectionId, $subnetMasterId = "0") { # get all subnets $subnets = fetchSubnets($sectionId); $folders = fetchFolders($sectionId); $html = array(); $rootId = 0; # root is 0 # must be integer if (isset($_GET['subnetId'])) { if (!is_numeric($_GET['subnetId'])) { die('<div class="alert alert-danger">' . _("Invalid ID") . '</div>'); } } # folders foreach ($folders as $item) { $childrenF[$item['masterSubnetId']][] = $item; } # subnets foreach ($subnets as $item) { $children[$item['masterSubnetId']][] = $item; } # loop will be false if the root has no children (i.e., an empty menu!) $loopF = !empty($childrenF[$rootId]); $loop = !empty($children[$rootId]); # initializing $parent as the root $parent = $rootId; $parent_stackF = array(); $parent_stack = array(); # display selected subnet as opened $allParents = getAllParents($_GET['subnetId']); # structure $html[] = "<select name='masterSubnetId' class='form-control input-sm input-w-auto input-max-200'>"; # folders if (sizeof($folders) > 0) { $html[] = "<optgroup label='" . _("Folders") . "'>"; # return table content (tr and td's) - folders while ($loopF && (($option = each($childrenF[$parent])) || $parent > $rootId)) { # repeat $repeat = str_repeat(" - ", count($parent_stackF)); # dashes if (count($parent_stackF) == 0) { $dash = ""; } else { $dash = $repeat; } # count levels $count = count($parent_stackF) + 1; # print table line if (strlen($option['value']['subnet']) > 0) { # selected if ($option['value']['id'] == $subnetMasterId) { $html[] = "<option value='" . $option['value']['id'] . "' selected='selected'>{$repeat} " . $option['value']['description'] . "</option>"; } else { $html[] = "<option value='" . $option['value']['id'] . "'>{$repeat} " . $option['value']['description'] . "</option>"; } } if ($option === false) { $parent = array_pop($parent_stackF); } elseif (!empty($childrenF[$option['value']['id']])) { array_push($parent_stackF, $option['value']['masterSubnetId']); $parent = $option['value']['id']; } else { } } $html[] = "</optgroup>"; } # subnets $html[] = "<optgroup label='" . _("Subnets") . "'>"; # root subnet if (!isset($subnetMasterId) || $subnetMasterId == 0) { $html[] = "<option value='0' selected='selected'>" . _("Root subnet") . "</option>"; } else { $html[] = "<option value='0'>" . _("Root subnet") . "</option>"; } # return table content (tr and td's) - subnets while ($loop && (($option = each($children[$parent])) || $parent > $rootId)) { # repeat $repeat = str_repeat(" - ", count($parent_stack)); # dashes if (count($parent_stack) == 0) { $dash = ""; } else { $dash = $repeat; } # count levels $count = count($parent_stack) + 1; # print table line if it exists and it is not folder if (strlen($option['value']['subnet']) > 0 && $option['value']['isFolder'] != 1) { # selected if ($option['value']['id'] == $subnetMasterId) { $html[] = "<option value='" . $option['value']['id'] . "' selected='selected'>{$repeat} " . transform2long($option['value']['subnet']) . "/" . $option['value']['mask'] . " (" . $option['value']['description'] . ")</option>"; } else { $html[] = "<option value='" . $option['value']['id'] . "'>{$repeat} " . transform2long($option['value']['subnet']) . "/" . $option['value']['mask'] . " (" . $option['value']['description'] . ")</option>"; } } if ($option === false) { $parent = array_pop($parent_stack); } elseif (!empty($children[$option['value']['id']])) { array_push($parent_stack, $option['value']['masterSubnetId']); $parent = $option['value']['id']; } else { } } $html[] = "</optgroup>"; $html[] = "</select>"; print implode("\n", $html); }
if (sizeof($subsections) > 0) { $subnets = fetchSubnets($update['id']); $subnetsc = sizeof($subnets); foreach ($subnets as $s) { $out[] = $s; } foreach ($subsections as $ss) { $subssubnet = fetchSubnets($ss['id']); foreach ($subssubnet as $sss) { $out[] = $sss; } $subnetsc = $subnetsc + sizeof($subssubnet); $ipcnt = countAllIPinSection($out); } } else { $subnets = fetchSubnets($update['id']); $subnetsc = sizeof($subnets); $ipcnt = countAllIPinSection($subnets); } print "<strong>" . _("Warning") . "</strong>: " . _("I will delete") . ":<ul>"; print "\t<li>{$subnetsc} " . _("subnets") . "</li>"; if ($ipcnt > 0) { print "\t<li>{$ipcnt} " . _("IP addresses") . "</li>"; } print "</ul>"; print "<hr><div style='text-align:right'>"; print _("Are you sure you want to delete above items?") . " "; print "<div class='btn-group'>"; print "\t<a class='btn btn-sm btn-danger editSectionSubmitDelete' id='editSectionSubmitDelete'>" . _("Confirm") . "</a>"; print "</div>"; print "</div>";
# headers print "\t<tr>"; print "\t<th>" . _('Subnet') . "</th>"; print "\t<th>" . _('Description') . "</th>"; print "\t<th>" . _('VLAN') . "</th>"; print "\t<th>" . _('Master Subnet') . "</th>"; print "\t<th class='hidden-xs hidden-sm'>" . _('Used') . "</th>"; print "\t<th class='hidden-xs hidden-sm'>" . _('Requests') . "</th>"; print "\t<th class='hidden-xs hidden-sm'>" . _('Hosts check') . "</th>"; if (sizeof($custom) > 0) { foreach ($custom as $field) { print "\t<th class='hidden-xs hidden-sm hidden-md'>{$field['name']}</th>"; } } print "</tr>"; # get all subnets in section $subnets = fetchSubnets($section['id']); # no subnets if (sizeof($subnets) == 0) { print "<tr><td colspan='{$colSpan}'><div class='alert alert-info'>" . _('Section has no subnets') . "!</div></td></tr>"; } else { $subnetPrint = printToolsSubnets($subnets, $custom); print $subnetPrint; } print '</tbody>'; } # end permission check } ?> </table>
/** * Print dropdown menu for subnets in section! */ function printDropdownMenuBySection($sectionId, $subnetMasterId = "0") { # get all subnets $subnets = fetchSubnets($sectionId); $html = array(); $rootId = 0; # root is 0 foreach ($subnets as $item) { $children[$item['masterSubnetId']][] = $item; } # loop will be false if the root has no children (i.e., an empty menu!) $loop = !empty($children[$rootId]); # initializing $parent as the root $parent = $rootId; $parent_stack = array(); # display selected subnet as opened $allParents = getAllParents($_REQUEST['subnetId']); # structure $html[] = "<select name='masterSubnetId'>"; # root $html[] = "<option disabled>" . _("Select Master subnet") . "</option>"; $html[] = "<option value='0'>" . _("Root subnet") . "</option>"; # return table content (tr and td's) while ($loop && (($option = each($children[$parent])) || $parent > $rootId)) { # repeat $repeat = str_repeat(" - ", count($parent_stack)); # dashes if (count($parent_stack) == 0) { $dash = ""; } else { $dash = $repeat; } # count levels $count = count($parent_stack) + 1; # print table line if (strlen($option['value']['subnet']) > 0) { # selected if ($option['value']['id'] == $subnetMasterId) { $html[] = "<option value='" . $option['value']['id'] . "' selected='selected'>{$repeat} " . transform2long($option['value']['subnet']) . "/" . $option['value']['mask'] . " (" . $option['value']['description'] . ")</option>"; } else { $html[] = "<option value='" . $option['value']['id'] . "'>{$repeat} " . transform2long($option['value']['subnet']) . "/" . $option['value']['mask'] . " (" . $option['value']['description'] . ")</option>"; } } if ($option === false) { $parent = array_pop($parent_stack); } elseif (!empty($children[$option['value']['id']])) { array_push($parent_stack, $option['value']['masterSubnetId']); $parent = $option['value']['id']; } else { } } $html[] = "</select>"; print implode("\n", $html); }
$colspan++; } } else { # subnets $subnets2 = printSubnets($subnets, true, $settings['enableVRF'], $custom); print $subnets2; } # subsection subnets if (sizeof($subsections) > 0) { $colspan = 6 + sizeof($custom); if ($settings['enableVRF'] == 1) { $colspan++; } # subnets foreach ($subsections as $ss) { $slavesubnets = fetchSubnets($ss['id']); if (sizeof($slavesubnets) > 0) { # headers print "<tr>"; print "\t<th colspan='{$colspan}'>" . _('Available subnets in subsection') . " {$ss['name']}:</th>"; print "</tr>"; # subnets $subnets3 = printSubnets($slavesubnets, true, $settings['enableVRF'], $custom); print $subnets3; } else { print "<tr>"; print "\t<th colspan='{$colspan}'>" . _('Available subnets in subsection') . " {$ss['name']}:</th>"; print "</tr>"; print "<tr>"; print "\t<td colspan='{$colspan}'><div class='alert alert-info'>" . _('Section has no subnets') . "!</div></td>"; print "</tr>";