/** * Print subnets structure */ function printToolsSubnets($subnets, $custom) { $html = array(); $rootId = 0; # root is 0 # remove all not permitted! foreach ($subnets as $k => $s) { $permission = checkSubnetPermission($s['id']); if ($permission == "0") { unset($subnets[$k]); } } if (sizeof($subnets) > 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 if (isset($_GET['subnetId'])) { $allParents = getAllParents($_GET['subnetId']); } # 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 = "-"; } if (count($parent_stack) == 0) { $margin = "0px"; $padding = "0px"; } else { # padding $padding = "10px"; # margin $margin = count($parent_stack) * 10 - 10; $margin = $margin * 2; $margin = $margin . "px"; } # count levels $count = count($parent_stack) + 1; # get subnet details # get VLAN $vlan = subnetGetVLANdetailsById($option['value']['vlanId']); $vlan = $vlan['number']; if (empty($vlan) || $vlan == "0") { $vlan = ""; } # no VLAN # description if (strlen($option['value']['description']) == 0) { $description = "/"; } else { $description = $option['value']['description']; } # description # requests if ($option['value']['allowRequests'] == 1) { $requests = "<i class='fa fa-gray fa-check'></i>"; } else { $requests = ""; } # request disabled # hosts check if ($option['value']['pingSubnet'] == 1) { $pCheck = "<i class='fa fa-gray fa-check'></i>"; } else { $pCheck = ""; } # ping check disabled # print table line if (strlen($option['value']['subnet']) > 0) { $html[] = "<tr>"; # folder if ($option['value']['isFolder'] == 1) { $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-sfolder fa-folder-open'></i> <a href='" . create_link("folder", $option['value']['sectionId'], $option['value']['id']) . "'>{$description}</a></td>"; $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-sfolder fa-folder-open'></i> {$description}</td>"; } else { if ($count == 1) { $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-gray fa-folder-open-o'></i><a href='" . create_link("subnets", $option['value']['sectionId'], $option['value']['id']) . "'> " . transform2long($option['value']['subnet']) . "/" . $option['value']['mask'] . "</a></td>"; $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-gray fa-folder-open-o'></i> {$description}</td>"; } else { # last? if (!empty($children[$option['value']['id']])) { $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-folder-open-o'></i><a href='" . create_link("subnets", $option['value']['sectionId'], $option['value']['id']) . "'> " . transform2long($option['value']['subnet']) . "/" . $option['value']['mask'] . "</a></td>"; $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-folder-open-o'></i> {$description}</td>"; } else { $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-angle-right'></i><a href='" . create_link("subnets", $option['value']['sectionId'], $option['value']['id']) . "'> " . transform2long($option['value']['subnet']) . "/" . $option['value']['mask'] . "</a></td>"; $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-angle-right'></i> {$description}</td>"; } } } //vlan $html[] = "\t<td>{$vlan}</td>"; //masterSubnet if ($option['value']['masterSubnetId'] == 0 || empty($option['value']['masterSubnetId'])) { $masterSubnet = true; } else { $masterSubnet = false; } if ($masterSubnet) { $html[] = ' <td>/</td>' . "\n"; } else { $master = getSubnetDetailsById($option['value']['masterSubnetId']); if ($master['isFolder']) { $html[] = "\t<td><i class='fa fa-gray fa-folder-open-o'></i> <a href='" . create_link("subnets", $option['value']['sectionId'], $master['id']) . "'>{$master['description']}</a></td>" . "\n"; } else { $html[] = "\t<td><a href='" . create_link("folder", $option['value']['sectionId'], $master['id']) . "'>" . transform2long($master['subnet']) . '/' . $master['mask'] . '</a></td>' . "\n"; } } //used , free if ($option['value']['isFolder'] == 1) { $html[] = '<td class="hidden-xs hidden-sm"></td>' . "\n"; } elseif (!$masterSubnet || !subnetContainsSlaves($option['value']['id'])) { $ipCount = countIpAddressesBySubnetId($option['value']['id']); $calculate = calculateSubnetDetails(gmp_strval($ipCount), $option['value']['mask'], $option['value']['subnet']); $html[] = ' <td class="used hidden-xs hidden-sm">' . reformatNumber($calculate['used']) . '/' . reformatNumber($calculate['maxhosts']) . ' (' . reformatNumber($calculate['freehosts_percent']) . ' %)</td>'; } else { $html[] = '<td class="hidden-xs hidden-sm"></td>' . "\n"; } //requests $html[] = "\t<td class='hidden-xs hidden-sm'>{$requests}</td>"; $html[] = "\t<td class='hidden-xs hidden-sm'>{$pCheck}</td>"; //custom if (sizeof($custom) > 0) { foreach ($custom as $field) { $html[] = "<td class='hidden-xs hidden-sm hidden-md'>"; //booleans if ($field['type'] == "tinyint(1)") { if ($option['value'][$field['name']] == "0") { $html[] = _("No"); } elseif ($option['value'][$field['name']] == "1") { $html[] = _("Yes"); } } elseif ($field['type'] == "text") { if (strlen($option['value'][$field['name']]) > 0) { $html[] = "<i class='fa fa-gray fa-comment' rel='tooltip' data-container='body' data-html='true' title='" . str_replace("\n", "<br>", $option['value'][$field['name']]) . "'>"; } else { $html[] = ""; } } else { $html[] = $option['value'][$field['name']]; } $html[] = "</td>"; } } $html[] = "</tr>"; } 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 { } } return implode("\n", $html); }
print "\t<td>{$subnet['VLAN']}</td>"; print "\t<td>{$subnet['description']}</td>"; print "\t<td><a href='subnets/{$section['id']}/{$subnet['id']}/'>" . transform2long($subnet['subnet']) . "/{$subnet['mask']}</a></td>"; if ($masterSubnet) { print ' <td>/</td>' . "\n"; } else { $master = getSubnetDetailsById($subnet['masterSubnetId']); # orphaned if (strlen($master['subnet']) == 0) { print "\t<td><div class='alert alert-warning'>" . _('Master subnet does not exist') . "!</div></td>"; } else { print "\t<td><a href='subnets/{$subnet['sectionId']}/{$subnet['masterSubnetId']}/'>" . transform2long($master['subnet']) . "/{$master['mask']} ({$master['description']})</a></td>"; } } # details if (!$masterSubnet || !subnetContainsSlaves($subnet['id'])) { $ipCount = countIpAddressesBySubnetId($subnet['id']); $calculate = calculateSubnetDetails(gmp_strval($ipCount), $subnet['mask'], $subnet['subnet']); print ' <td class="used hidden-xs hidden-sm">' . reformatNumber($calculate['used']) . '/' . reformatNumber($calculate['maxhosts']) . '</td>' . "\n"; print ' <td class="free hidden-xs hidden-sm">' . reformatNumber($calculate['freehosts_percent']) . ' %</td>'; } else { print '<td class="hidden-xs hidden-sm"></td>' . "\n"; print '<td class="hidden-xs hidden-sm"></td>' . "\n"; } # allow requests if ($subnet['allowRequests'] == 1) { print '<td class="allowRequests requests hidden-xs hidden-sm">' . _('enabled') . '</td>'; } else { print '<td class="allowRequests hidden-xs hidden-sm"></td>'; } print '</tr>' . "\n";
/** * Build the HTML menu * * based on http://pastebin.com/GAFvSew4 */ function get_menu_html($subnets, $rootId = 0) { $html = array(); 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 if (isset($_REQUEST['subnetId'])) { $allParents = getAllParents($_REQUEST['subnetId']); } else { $allParents = array(); } # Menu start $html[] = '<ul id="subnets">'; while ($loop && (($option = each($children[$parent])) || $parent > $rootId)) { # count levels $count = count($parent_stack) + 1; # set opened or closed tag for displaying proper folders if (in_array($option['value']['id'], $allParents)) { $open = "open"; $openf = "-open"; } else { $open = "close"; $openf = ""; } # show also child's by default if ($option['value']['id'] == $_REQUEST['subnetId']) { if (subnetContainsSlaves($_REQUEST['subnetId'])) { $open = "open"; $openf = "-open"; } else { $open = "close"; $openf = ""; } } # override if cookie is set if (isset($_COOKIE['expandfolders'])) { if ($_COOKIE['expandfolders'] == "1") { $open = 'open'; $openf = "-open"; } } # for active class if (isset($_REQUEST['subnetId']) && $option['value']['id'] == $_REQUEST['subnetId']) { $active = "active"; $leafClass = ""; } else { $active = ""; $leafClass = "icon-gray"; } # override folder if ($option['value']['isFolder'] == 1 && $option['value']['id'] == $_REQUEST['subnetId']) { $open = "open"; $openf = "-open"; } # check for permissions if id is provided if ($option['value']['id'] != "") { $sp = checkSubnetPermission($option['value']['id']); } if ($option === false) { $parent = array_pop($parent_stack); # HTML for menu item containing childrens (close) $html[] = '</ul>'; $html[] = '</li>'; } elseif (!empty($children[$option['value']['id']])) { # if user has access permission if ($sp != 0) { # folder if ($option['value']['isFolder'] == 1) { $html[] = '<li class="folderF folder-' . $open . ' ' . $active . '"><i class="fa fa-gray fa-sfolder fa-folder' . $openf . '" rel="tooltip" data-placement="right" data-html="true" title="' . _('Folder contains more subnets') . '<br>' . _('Click on folder to open/close') . '"></i>'; $html[] = '<a href="folder/' . $option['value']['sectionId'] . '/' . $option['value']['id'] . '/">' . $option['value']['description'] . '</a>'; } elseif ($option['value']['showName'] == 1) { $html[] = '<li class="folder folder-' . $open . ' ' . $active . '"><i class="fa fa-gray fa-folder-' . $open . '-o" rel="tooltip" data-placement="right" data-html="true" title="' . _('Subnet contains more subnets') . '<br>' . _('Click on folder to open/close') . '"></i>'; $html[] = '<a href="subnets/' . $option['value']['sectionId'] . '/' . $option['value']['id'] . '/" rel="tooltip" data-placement="right" title="' . Transform2long($option['value']['subnet']) . '/' . $option['value']['mask'] . '">' . $option['value']['description'] . '</a>'; } else { $html[] = '<li class="folder folder-' . $open . ' ' . $active . '""><i class="fa fa-gray fa-folder-' . $open . '-o" rel="tooltip" data-placement="right" data-html="true" title="' . _('Subnet contains more subnets') . '<br>' . _('Click on folder to open/close') . '"></i>'; $html[] = '<a href="subnets/' . $option['value']['sectionId'] . '/' . $option['value']['id'] . '/" rel="tooltip" data-placement="right" title="' . $option['value']['description'] . '">' . Transform2long($option['value']['subnet']) . '/' . $option['value']['mask'] . '</a>'; } # print submenu if ($open == "open") { $html[] = '<ul class="submenu submenu-' . $open . '">'; } else { $html[] = '<ul class="submenu submenu-' . $open . '" style="display:none">'; } # hide - prevent flickering array_push($parent_stack, $option['value']['masterSubnetId']); $parent = $option['value']['id']; } } else { if ($sp != 0) { # folder - opened if ($option['value']['isFolder'] == 1) { $html[] = '<li class="leaf ' . $active . '"><i class="fa fa-gray fa-sfolder fa-folder' . $openf . '"></i>'; $html[] = '<a href="folder/' . $option['value']['sectionId'] . '/' . $option['value']['id'] . '/">' . $option['value']['description'] . '</a></li>'; } elseif ($option['value']['showName'] == 1) { $html[] = '<li class="leaf ' . $active . '""><i class="' . $leafClass . ' fa fa-gray fa-angle-right"></i>'; $html[] = '<a href="subnets/' . $option['value']['sectionId'] . '/' . $option['value']['id'] . '/" rel="tooltip" data-placement="right" title="' . Transform2long($option['value']['subnet']) . '/' . $option['value']['mask'] . '">' . $option['value']['description'] . '</a></li>'; } else { $html[] = '<li class="leaf ' . $active . '""><i class="' . $leafClass . ' fa fa-gray fa-angle-right"></i>'; $html[] = '<a href="subnets/' . $option['value']['sectionId'] . '/' . $option['value']['id'] . '/" rel="tooltip" data-placement="right" title="' . $option['value']['description'] . '">' . Transform2long($option['value']['subnet']) . '/' . $option['value']['mask'] . '</a></li>'; } } } } # Close menu $html[] = '</ul>'; return implode("\n", $html); }
if ($change == "change") { print ' <td>' . $vlan['number'] . '</td>' . "\n"; print ' <td>' . $vlan['name'] . '</td>' . "\n"; print ' <td>' . $vlan['description'] . '</td>' . "\n"; } else { print '<td></td>'; print '<td></td>'; print '<td></td>'; } if ($vlan['subnetId'] != null) { # subnet print " <td><a href='subnets/{$section['id']}/{$vlan['subnetId']}/'>" . transform2long($vlan['subnet']) . "/{$vlan['mask']}</a></td>"; # section print " <td><a href='subnets/{$section['id']}/'>{$section['name']}</a></td>"; # details if (!$masterSubnet || !subnetContainsSlaves($vlan['subnetId'])) { $ipCount = countIpAddressesBySubnetId($vlan['subnetId']); $calculate = calculateSubnetDetails(gmp_strval($ipCount), $vlan['mask'], $vlan['subnet']); print ' <td class="used hidden-xs hidden-sm">' . reformatNumber($calculate['used']) . '/' . reformatNumber($calculate['maxhosts']) . '</td>' . "\n"; print ' <td class="free hidden-xs hidden-sm">' . reformatNumber($calculate['freehosts_percent']) . ' %</td>'; } else { print ' <td class="used hidden-xs hidden-sm">---</td>' . "\n"; print ' <td class="free hidden-xs hidden-sm">---</td>' . "\n"; } } else { print '<td>---</td>' . "\n"; print '<td>---</td>' . "\n"; print '<td class="used hidden-xs hidden-sm">---</td>' . "\n"; print '<td class="free hidden-xs hidden-sm">---</td>'; } # custom
print "\t</td>"; print "</tr>"; } } else { print "<tr>"; print "\t<td colspan='2'><span class='alert alert-info'>" . _('No groups available') . "</span></td>"; print "</tr>"; } ?> </table> </form> <?php # print warning if slaves exist if (subnetContainsSlaves($_POST['subnetId'])) { print "<div class='alert alert-warning'>" . _('Permissions for all nested subnets will be overridden') . "!</div>"; } ?> </div> <!-- footer --> <div class="pFooter"> <div class="btn-group"> <button class="btn btn-sm btn-default hidePopups"><?php print _('Cancel'); ?> </button> <button class="btn btn-sm btn-default btn-success editSubnetPermissionsSubmit"><i class="fa fa-check"></i> <?php
print "\t<td><a href='" . create_link("folder", $f['sectionId']) . "'>{$f['section']}</a></td>"; if (strlen($f['vlanId']) > 0) { # get vlan info $vlan = getVlanById($f['vlanId']); print "\t<td class='hidden-xs hidden-sm'>{$vlan['number']}</td>"; } else { print "\t<td class='hidden-xs hidden-sm'>/</td>"; } # used # masterSubnet if ($f['masterSubnetId'] == 0 || empty($f['masterSubnetId'])) { $masterSubnet = true; } else { $masterSubnet = false; } if ($f['isFolder'] == 1) { print '<td class="hidden-xs hidden-sm"></td>'; } elseif (!$masterSubnet || !subnetContainsSlaves($f['subnetId'])) { $ipCount = countIpAddressesBySubnetId($f['subnetId']); $calculate = calculateSubnetDetails(gmp_strval($ipCount), $f['mask'], $f['subnet']); print ' <td class="used hidden-xs hidden-sm">' . reformatNumber($calculate['used']) . '/' . reformatNumber($calculate['maxhosts']) . ' (' . reformatNumber($calculate['freehosts_percent']) . ' %)</td>'; } else { print '<td class="hidden-xs hidden-sm"></td>' . "\n"; } # remove print "\t<td><a class='btn btn-xs btn-default editFavourite' data-subnetId='{$f['subnetId']}' data-action='remove' data-from='widget'><i class='fa fa-star favourite-{$f['subnetId']}' rel='tooltip' title='" . _('Click to remove from favourites') . "'></i></a></td>"; print "</tr>"; } } print "</table>"; }
<tr> <th><?php print _('Select subnet'); ?> *</th> <td> <select name="subnetId" id="subnetId" class="form-control"> <?php $m = 0; //needed for first IP address definition foreach ($subnets as $subnet) { /* show only subnets that allow IP exporting */ if ($subnet['allowRequests'] == 1) { /* must not have any nested subnets! */ if (!subnetContainsSlaves($subnet['id'])) { print '<option value="' . $subnet['id'] . '">' . Transform2long($subnet['subnet']) . '/' . $subnet['mask'] . ' [' . $subnet['description'] . ']</option>'; } } } ?> </select> </td> </tr> <!-- description --> <tr> <th><?php
print _('split'); ?> </td> <td> <div class="btn-toolbar" style="margin:0px;"> <div class="btn-group"> <button class="btn btn-small" id="resize" rel="tooltip" title="<?php print _('Resize subnet'); ?> " data-subnetId="<?php print $_POST['subnetId']; ?> "><i class="icon-gray icon-resize-vertical"></i></button> <?php # check if it has slaves - if yes it cannot be splitted! $slaves = subnetContainsSlaves($_POST['subnetId']); ?> <button class="btn btn-small <?php if ($slaves) { print "disabled"; } ?> " id="split" rel="tooltip" title="<?php print _('Split subnet'); ?> " data-subnetId="<?php print $_POST['subnetId']; ?> "><i class="icon-gray icon-resize-full"></i></button> <button class="btn btn-small" id="truncate" rel="tooltip" title="<?php print _('Truncate subnet');