Пример #1
0
/**
 * 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);
}
Пример #2
0
/**
 * Print subnets structure
 */
function printSubnets($subnets, $actions = true, $vrf = "0", $custom = array())
{
    $html = array();
    $rootId = 0;
    # root is 0
    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($_REQUEST['subnetId'])) {
        $allParents = getAllParents($_REQUEST['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 = _("enabled");
        } else {
            $requests = "";
        }
        # request disabled
        # hosts check
        if ($option['value']['pingSubnet'] == 1) {
            $pCheck = _("enabled");
        } else {
            $pCheck = "";
        }
        # ping check disabled
        #vrf
        if ($vrf == "1") {
            # get VRF details
            if ($option['value']['vrfId'] != "0" && $option['value']['vrfId'] != "NULL") {
                $vrfTmp = getVRFDetailsById($option['value']['vrfId']);
                $vrfText = $vrfTmp['name'];
            } else {
                $vrfText = "";
            }
        }
        // <eNovance>
        // count the number of free and offline hosts
        $ipaddresses = getIpAddressesBySubnetId($option['value']['id']);
        $reservedHosts = 0;
        foreach ($ipaddresses as $ip) {
            if ($ip['state'] == "2") {
                $reservedHosts += 1;
            }
        }
        $subnetDetails = calculateSubnetDetails(count($ipaddresses), $option['value']['mask'], $option['value']['subnet']);
        $freeHosts = $subnetDetails['freehosts'];
        // </eNovance>
        # print table line
        if (strlen($option['value']['subnet']) > 0) {
            // verify permission
            $permission = checkSubnetPermission($option['value']['id']);
            // print item
            if ($permission != 0) {
                $html[] = "<tr>";
                $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><a href='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> {$description}</td>";
                $html[] = "\t<td>{$vlan}</td>";
                #vrf
                if ($vrf == "1") {
                    $html[] = "\t<td>{$vrfText}</td>";
                }
                // <eNovance>
                // Removed $requests and $pCheck since it was not necessary for us
                // </eNovance>
                # custom
                if (sizeof($custom) > 0) {
                    foreach ($custom as $field) {
                        $html[] = "\t<td>" . $option['value'][$field['name']] . "</td>";
                    }
                }
                // <eNovance>
                // Set the 'reserved' and 'free' hosts columns' value
                $html[] = "<td>{$reservedHosts}</td>";
                if ($subnetDetails['freehosts_percent'] <= 5) {
                    $html[] = "<td><a href=\"subnets/" . $option['value']['sectionId'] . "/" . $option['value']['id'] . "/\" class=\"SubnetFull\">{$freeHosts}</a></td>";
                } elseif ($subnetDetails['freehosts_percent'] <= 20) {
                    $html[] = "<td><a href=\"subnets/" . $option['value']['sectionId'] . "/" . $option['value']['id'] . "/\" class=\"SubnetAlmostFull\">{$freeHosts}</a></td>";
                } else {
                    $html[] = "<td><a href=\"subnets/" . $option['value']['sectionId'] . "/" . $option['value']['id'] . "/\" class=\"SubnetNotFull\">{$freeHosts}</a></td>";
                }
                // </eNovance>
                if ($actions) {
                    $html[] = "\t<td class='actions' style='padding:0px;'>";
                    $html[] = "\t<div class='btn-group'>";
                    $html[] = "\t\t<button class='btn btn-mini editSubnet'     data-action='edit'   data-subnetid='" . $option['value']['id'] . "'  data-sectionid='" . $option['value']['sectionId'] . "'><i class='icon-gray icon-pencil'></i></button>";
                    $html[] = "\t\t<button class='btn btn-mini showSubnetPerm' data-action='show'   data-subnetid='" . $option['value']['id'] . "'  data-sectionid='" . $option['value']['sectionId'] . "'><i class='icon-gray icon-tasks'></i></button>";
                    $html[] = "\t\t<button class='btn btn-mini editSubnet'     data-action='delete' data-subnetid='" . $option['value']['id'] . "'  data-sectionid='" . $option['value']['sectionId'] . "'><i class='icon-gray icon-remove'></i></button>";
                    $html[] = "\t</div>";
                    $html[] = "\t</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);
}
Пример #3
0
         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";
     }
 }
Пример #4
0
# die if empty!
if (sizeof($SubnetDetails) == 0) {
    die('<div class="alert alert-danger">' . _('Subnet does not exist') . '!</div>');
}
# reset VLAN number!
$SubnetDetails['VLAN'] = subnetGetVLANdetailsById($SubnetDetails['vlanId']);
# get all site settings
$settings = getAllSettings();
/** 
 * Parse IP addresses
 *
 * We provide subnet and mask, all other is calculated based on it (subnet, broadcast,...)
 */
$SubnetParsed = parseIpAddress(transform2long($SubnetDetails['subnet']), $SubnetDetails['mask']);
/* Calculate free / used etc */
$CalculateSubnetDetails = calculateSubnetDetails(gmp_strval(sizeof($ipaddresses)), $SubnetDetails['mask'], $SubnetDetails['subnet']);
# permissions
$permission = checkSubnetPermission($subnetId);
# section permissions
$permissionsSection = checkSectionPermission($SubnetDetails['sectionId']);
# if 0 die
if ($permission == "0") {
    die("<div class='alert alert-danger'>" . _('You do not have permission to access this network') . "!</div>");
}
?>

<!-- content print! -->

<!-- for adding IP address! -->
<div class="row">