Example #1
0
<?php

/**
 * Display VLAN details
 ***********************************************************************/
/* verify that user is authenticated! */
isUserAuthenticated();
# get VLAN details
$vrf = getVRFDetailsById($_REQUEST['vrfId']);
# not existing
if (!$vrf) {
    die("<div class='alert alert-danger'>" . _('Invalid VRF id') . "!</div>");
}
# get all site settings
$settings = getAllSettings();
?>

<!-- content print! -->

<!-- for adding IP address! -->
<div id="subnetId" style="display:none"><?php 
print $subnetId;
?>
</div>

<!-- subnet details upper table -->
<h4><?php 
print _('VRF details');
?>
</h4>
<hr>
Example #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 = "<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
        #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 = "";
            }
        }
        # print table line
        if (strlen($option['value']['subnet']) > 0) {
            // verify permission
            $permission = checkSubnetPermission($option['value']['id']);
            // print item
            if ($permission != 0) {
                $html[] = "<tr>";
                # which level?
                if ($count == 1) {
                    # is 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-pad-right-3 fa-folder-open'></i> <a href='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-pad-right-3 fa-folder-open'></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-gray fa-pad-right-3 fa-folder-open-o'></i><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><i class='fa fa-gray fa-pad-right-3 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-gray fa-pad-right-3 fa-angle-right'></i><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><i class='fa fa-gray fa-pad-right-3 fa-angle-right'></i> {$description}</td>";
                        }
                    }
                } else {
                    # is folder?
                    if ($option['value']['isFolder'] == 1) {
                        # last?
                        $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-gray fa-pad-right-3 fa-folder-open'></i> <a href='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-gray fa-pad-right-3 fa-folder-open'></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-gray fa-pad-right-3 fa-folder-open-o'></i> <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><i class='fa fa-gray fa-pad-right-3 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-gray fa-pad-right-3 fa-angle-right'></i> <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><i class='fa fa-gray fa-pad-right-3 fa-angle-right'></i> {$description}</td>";
                        }
                    }
                }
                $html[] = "\t<td>{$vlan}</td>";
                #vrf
                if ($vrf == "1") {
                    $html[] = "\t<td class='hidden-xs hidden-sm'>{$vrfText}</td>";
                }
                $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[] = "\t<td class='hidden-xs hidden-sm'>" . $option['value'][$field['name']] . "</td>";
                    }
                }
                if ($actions) {
                    $html[] = "\t<td class='actions' style='padding:0px;'>";
                    $html[] = "\t<div class='btn-group'>";
                    if ($option['value']['isFolder'] == 1) {
                        $html[] = "\t\t<button class='btn btn-xs btn-default add_folder'     data-action='edit'   data-subnetid='" . $option['value']['id'] . "'  data-sectionid='" . $option['value']['sectionId'] . "'><i class='fa fa-gray fa-pencil'></i></button>";
                        $html[] = "\t\t<button class='btn btn-xs btn-default showSubnetPerm' data-action='show'   data-subnetid='" . $option['value']['id'] . "'  data-sectionid='" . $option['value']['sectionId'] . "'><i class='fa fa-gray fa-tasks'></i></button>";
                        $html[] = "\t\t<button class='btn btn-xs btn-default add_folder'     data-action='delete' data-subnetid='" . $option['value']['id'] . "'  data-sectionid='" . $option['value']['sectionId'] . "'><i class='fa fa-gray fa-times'></i></button>";
                    } else {
                        $html[] = "\t\t<button class='btn btn-xs btn-default editSubnet'     data-action='edit'   data-subnetid='" . $option['value']['id'] . "'  data-sectionid='" . $option['value']['sectionId'] . "'><i class='fa fa-gray fa-pencil'></i></button>";
                        $html[] = "\t\t<button class='btn btn-xs btn-default showSubnetPerm' data-action='show'   data-subnetid='" . $option['value']['id'] . "'  data-sectionid='" . $option['value']['sectionId'] . "'><i class='fa fa-gray fa-tasks'></i></button>";
                        $html[] = "\t\t<button class='btn btn-xs btn-default editSubnet'     data-action='delete' data-subnetid='" . $option['value']['id'] . "'  data-sectionid='" . $option['value']['sectionId'] . "'><i class='fa fa-gray fa-times'></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);
}
Example #3
0
<?php

/**
 *	Print all available VRFs and configurations
 ************************************************/
/* required functions */
require_once '../../functions/functions.php';
/* verify that user is admin */
checkAdmin();
/* filter input */
$_POST = filter_user_input($_POST, true, true, false);
$_POST['action'] = filter_user_input($_POST['action'], false, false, true);
/* get post */
$vrfPost = $_POST;
/* get all available VRFs */
$vrf = getVRFDetailsById($vrfPost['vrfId']);
/* disable edit on delete */
if ($_POST['action'] == "delete") {
    $readonly = "readonly";
} else {
    $readonly = "";
}
?>


<!-- header -->
<div class="pHeader"><?php 
print ucwords(_("{$_POST['action']}"));
?>
 <?php 
print _('VRF');
Example #4
0
/**
 * Write new changelog
 */
function writeChangelog($ctype, $action, $result, $old, $new)
{
    /* set query, open db connection and fetch results */
    global $database;
    # get settings
    $settings = getAllSettings();
    if ($settings['enableChangelog'] == 1) {
        # get user details
        $cuser = getActiveUserDetails();
        # unset unneeded values and format
        if ($ctype == "ip_addr") {
            unset($new['action'], $new['subnet'], $new['type']);
        } elseif ($ctype == "subnet") {
            $new['id'] = $new['subnetId'];
            unset($new['action'], $new['subnetId'], $new['location'], $new['vrfIdOld'], $new['permissions']);
            # if section does not change
            if ($new['sectionId'] == $new['sectionIdNew']) {
                unset($new['sectionIdNew']);
                unset($new['sectionId']);
                unset($old['sectionId']);
            } else {
                $old['sectionIdNew'] = $old['sectionId'];
            }
            //transform subnet
            if (strlen($new['subnet']) > 0) {
                $new['subnet'] = Transform2decimal(substr($new['subnet'], 0, strpos($new['subnet'], "/")));
            }
        } elseif ($ctype == "section") {
            unset($new['action']);
        }
        # calculate diff
        if ($action == "edit") {
            //old - checkboxes
            foreach ($old as $k => $v) {
                if (!isset($new[$k]) && $v == 1) {
                    $new[$k] = 0;
                }
            }
            foreach ($new as $k => $v) {
                //change
                if ($old[$k] != $v && $old[$k] != str_replace("\\'", "'", $v)) {
                    //empty
                    if (strlen(@$old[$k]) == 0) {
                        $old[$k] = "NULL";
                    }
                    if (strlen(@$v) == 0) {
                        $v = "NULL";
                    }
                    //state
                    if ($k == 'state') {
                        $old[$k] = reformatIPStateText($old[$k]);
                        $v = reformatIPStateText($v);
                    } elseif ($k == 'sectionIdNew') {
                        //get old and new device
                        if ($old[$k] != "NULL") {
                            $dev = getSectionDetailsById($old[$k]);
                            $old[$k] = $dev['name'];
                        }
                        if ($v != "NULL") {
                            $dev = getSectionDetailsById($v);
                            $v = $dev['name'];
                        }
                    } elseif ($k == "masterSubnetId") {
                        if ($old[$k] == 0) {
                            $old[$k] = "Root";
                        } else {
                            $dev = getSubnetDetailsById($old[$k]);
                            $old[$k] = transform2long($dev['subnet']) . "/{$dev['mask']} [{$dev['description']}]";
                        }
                        if ($v == 0) {
                            $v = "Root";
                        } else {
                            $dev = getSubnetDetailsById($v);
                            $v = transform2long($dev['subnet']) . "/{$dev['mask']} [{$dev['description']}]";
                        }
                    } elseif ($k == 'switch') {
                        if ($old[$k] == 0) {
                            $old[$k] = "None";
                        } elseif ($old[$k] != "NULL") {
                            $dev = getDeviceDetailsById($old[$k]);
                            $old[$k] = $dev['hostname'];
                        }
                        if ($v == 0) {
                            $v = "None";
                        }
                        if ($v != "NULL") {
                            $dev = getDeviceDetailsById($v);
                            $v = $dev['hostname'];
                        }
                    } elseif ($k == 'vlanId') {
                        //get old and new device
                        if ($old[$k] == 0) {
                            $old[$k] = "None";
                        } elseif ($old[$k] != "NULL") {
                            $dev = getVLANById($old[$k]);
                            $old[$k] = $dev['name'] . " [{$dev['number']}]";
                        }
                        if ($v == 0) {
                            $v = "None";
                        } elseif ($v != "NULL") {
                            $dev = getVLANById($v);
                            $v = $dev['name'] . " [{$dev['number']}]";
                        }
                    } elseif ($k == 'vrfId') {
                        //get old and new device
                        if ($old[$k] == 0) {
                            $old[$k] = "None";
                        } elseif ($old[$k] != "NULL") {
                            $dev = getVRFDetailsById($old[$k]);
                            $old[$k] = $dev['name'] . " [{$dev['description']}]";
                        }
                        if ($v == 0) {
                            $v = "None";
                        } elseif ($v != "NULL") {
                            $dev = getVRFDetailsById($v);
                            $v = $dev['name'] . " [{$dev['description']}]";
                        }
                    } elseif ($k == 'masterSection') {
                        if ($old[$k] == 0) {
                            $old[$k] = "Root";
                        } else {
                            $dev = getSectionDetailsById($old[$k]);
                            $old[$k] = "{$dev['name']}";
                        }
                        if ($v == 0) {
                            $v = "Root";
                        } else {
                            $dev = getSectionDetailsById($v);
                            $v = "{$dev['name']}";
                        }
                    } elseif ($k == "permissions") {
                        # get old and compare
                        $new['permissions'] = str_replace("\\", "", $new['permissions']);
                        //Remove /
                        # Get all groups:
                        $groups = getAllGroups();
                        $groups = rekeyGroups($groups);
                        # reformat:
                        $newp = json_decode($new['permissions']);
                        $v = '';
                        foreach ($newp as $ke => $p) {
                            $v .= "<br>" . $groups[$ke]['g_name'] . " : " . parsePermissions($p);
                        }
                        $old[$k] = "";
                    }
                    $log["[{$k}]"] = "{$old[$k]} => {$v}";
                }
            }
        } elseif ($action == "add") {
            $log['[create]'] = "{$ctype} created";
        } elseif ($action == "delete") {
            $log['[delete]'] = "{$ctype} deleted";
            $new['id'] = $old['id'];
        } elseif ($action == "truncate") {
            $log['[truncate]'] = "Subnet truncated";
        } elseif ($action == "resize") {
            $log['[resize]'] = "Subnet Resized";
            $log['[New mask]'] = "/" . $new['mask'];
        } elseif ($action == "perm_change") {
            # get old and compare
            $new['permissions_change'] = str_replace("\\", "", $new['permissions_change']);
            //Remove /
            # Get all groups:
            $groups = getAllGroups();
            $groups = rekeyGroups($groups);
            # reformat
            if ($new['permissions_change'] != "null") {
                $newp = json_decode($new['permissions_change']);
                foreach ($newp as $k => $p) {
                    $log['[Permissions]'] .= "<br>" . $groups[$k]['g_name'] . " : " . parsePermissions($p);
                }
            }
        }
        //if change happened write it!
        if (isset($log)) {
            # format change
            foreach (@$log as $k => $l) {
                $changelog .= "{$k} {$l}\n";
            }
            $changelog = $database->real_escape_string(trim($changelog));
            # set insert query
            $query = "insert into `changelog` (`ctype`,`coid`,`cuser`,`caction`,`cresult`,`cdate`,`cdiff`) values ('{$ctype}', '{$new['id']}', '{$cuser['id']}', '{$action}', '{$result}', NOW(), '{$changelog}');";
            # execute
            try {
                $database->executeQuery($query);
            } catch (Exception $e) {
                $error = $e->getMessage();
                return true;
            }
            # mail it!
            # all good
            return true;
        }
    } else {
        return true;
    }
}
Example #5
0
<?php

/**
 * Display VLAN details
 ***********************************************************************/
/* verify that user is authenticated! */
isUserAuthenticated();
# get VLAN details
$vrf = getVRFDetailsById($_GET['subnetId']);
# not existing
if (!$vrf) {
    die("<h4>" . _('Error') . "</h4><hr><div class='alert alert-danger'>" . _('Invalid VRF id') . "!</div>");
}
# get all site settings
$settings = getAllSettings();
?>

<!-- content print! -->

<!-- for adding IP address! -->
<div id="subnetId" style="display:none"><?php 
print $subnetId;
?>
</div>

<!-- subnet details upper table -->
<h4><?php 
print _('VRF details');
?>
</h4>
<hr>
Example #6
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);
}
Example #7
0
/**
 * Print subnets structure
 */
function printAdminSubnets($subnets, $actions = true, $vrf = "0")
{
    $html = array();
    $rootId = 0;
    # root is 0
    if (sizeof($subnets) > 0) {
        foreach ($subnets as $item) {
            $item = (array) $item;
            $children[$item['masterSubnetId']][] = $item;
        }
    }
    /* get custom fields */
    $custom = getCustomFields('subnets');
    global $settings;
    /* set hidden fields */
    $ffields = json_decode($settings['hiddenCustomFields'], true);
    if (is_array($ffields['subnets'])) {
        $ffields = $ffields['subnets'];
    } else {
        $ffields = array();
    }
    # 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'])) {
        if (!is_numeric($_GET['subnetId'])) {
            die('<div class="alert alert-danger">' . _("Invalid ID") . '</div>');
        }
        $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 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
        #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 = "";
            }
        }
        # 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-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 {
                    # 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>";
                    }
                }
            }
            $html[] = "\t<td class='hidden-xs hidden-sm'>{$vlan}</td>";
            #vrf
            if ($vrf == "1") {
                $html[] = "\t<td class='hidden-xs hidden-sm'>{$vrfText}</td>";
            }
            $html[] = "\t<td class='hidden-xs hidden-sm hidden-md'>{$requests}</td>";
            $html[] = "\t<td class='hidden-xs hidden-sm hidden-md'>{$pCheck}</td>";
            # custom
            if (sizeof($custom) > 0) {
                foreach ($custom as $field) {
                    if (!in_array($field['name'], $ffields)) {
                        $html[] = "\t<td class='hidden-xs hidden-sm'>" . $option['value'][$field['name']] . "</td>";
                    }
                }
            }
            # actions
            if ($actions) {
                $html[] = "\t<td class='actions' style='padding:0px;'>";
                $html[] = "\t<div class='btn-group btn-group-xs'>";
                if ($option['value']['isFolder'] == 1) {
                    $html[] = "\t\t<button class='btn btn-sm btn-default add_folder'     data-action='edit'   data-subnetid='" . $option['value']['id'] . "'  data-sectionid='" . $option['value']['sectionId'] . "'><i class='fa fa-gray fa-pencil'></i></button>";
                    $html[] = "\t\t<button class='btn btn-sm btn-default showSubnetPerm' data-action='show'   data-subnetid='" . $option['value']['id'] . "'  data-sectionid='" . $option['value']['sectionId'] . "'><i class='fa fa-gray fa-tasks'></i></button>";
                    $html[] = "\t\t<button class='btn btn-sm btn-default add_folder'     data-action='delete' data-subnetid='" . $option['value']['id'] . "'  data-sectionid='" . $option['value']['sectionId'] . "'><i class='fa fa-gray fa-times'></i></button>";
                } else {
                    $html[] = "\t\t<button class='btn btn-sm btn-default editSubnet'     data-action='edit'   data-subnetid='" . $option['value']['id'] . "'  data-sectionid='" . $option['value']['sectionId'] . "'><i class='fa fa-gray fa-pencil'></i></button>";
                    $html[] = "\t\t<button class='btn btn-sm btn-default showSubnetPerm' data-action='show'   data-subnetid='" . $option['value']['id'] . "'  data-sectionid='" . $option['value']['sectionId'] . "'><i class='fa fa-gray fa-tasks'></i></button>";
                    $html[] = "\t\t<button class='btn btn-sm btn-default editSubnet'     data-action='delete' data-subnetid='" . $option['value']['id'] . "'  data-sectionid='" . $option['value']['sectionId'] . "'><i class='fa fa-gray fa-times'></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);
}