***************************************************************************************/
/* filter input */
$_GET = filter_user_input($_GET, true, true, false);
/* must be numeric */
if (!is_numeric($_GET['subnetId'])) {
    die('<div class="alert alert-danger">' . _("Invalid ID") . '</div>');
}
if (!is_numeric($_GET['section'])) {
    die('<div class="alert alert-danger">' . _("Invalid ID") . '</div>');
}
/* get master subnet ID */
$subnetId = $_GET['subnetId'];
/* get all slaves */
$slaves = getAllSlaveSubnetsBySubnetId($subnetId);
/* get master details */
$master = getSubnetDetailsById($subnetId);
/* get section details */
$section = getSectionDetailsById($master['sectionId']);
/* divide subnets / folders */
foreach ($slaves as $s) {
    //folders
    if ($s['isFolder'] == "1") {
        $folders[] = $s;
    } else {
        $subnets[] = $s;
    }
}
/* first print belonging folders */
if (sizeof($folders) > 0) {
    /* print title */
    $slaveNum = sizeof($folders);
Example #2
0
}
/* filter input */
$_GET = filter_user_input($_GET, true, true, false);
/* must be numeric */
if (!is_numeric($_GET['subnetId'])) {
    die('<div class="alert alert-danger">' . _("Invalid ID") . '</div>');
}
if (!is_numeric($_GET['section'])) {
    die('<div class="alert alert-danger">' . _("Invalid ID") . '</div>');
}
if (!is_numeric($_GET['ipaddrid'])) {
    die('<div class="alert alert-danger">' . _("Invalid ID") . '</div>');
}
# get IP address details
$ip = getIpAddrDetailsById($_GET['ipaddrid']);
$subnet = getSubnetDetailsById($_GET['subnetId']);
$section = getSectionDetailsById($_GET['section']);
# get all selected fields for IP print
$setFieldsTemp = getSelectedIPaddrFields();
// format them to array!
$setFields = explode(";", $setFieldsTemp);
# get all custom fields
$myFields = getCustomFields('ipaddresses');
# set ping statuses
$statuses = explode(";", $settings['pingStatus']);
# permissions
$permission = checkSubnetPermission($_GET['subnetId']);
# section permissions
$permissionsSection = checkSectionPermission($_GET['section']);
# if 0 die
if ($permission == "0") {
Example #3
0
 /**
  * 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;
 }
Example #4
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);
}
# set folder flag!
$_POST['isFolder'] = true;
# failed
if ($_POST['action'] == "delete" && !isset($_POST['deleteconfirm'])) {
    # for ajax to prevent reload
    print "<div style='display:none'>alert alert-danger</div>";
    # result
    print "<div class='alert alert-warning'>";
    # print what will be deleted
    getAllSlaves($_POST['subnetId'], false);
    $removeSlaves = array_unique($removeSlaves);
    # check if folder?
    $foldercnt = 0;
    $subnetcnt = 0;
    foreach ($removeSlaves as $s) {
        $f = getSubnetDetailsById($s);
        if ($f['isFolder'] == 1) {
            $foldercnt++;
        } else {
            $subnetcnt++;
        }
    }
    $ipcnt = countAllSlaveIPAddresses($_POST['subnetId']);
    print "<strong>" . _("Warning") . "</strong>: " . _("I will delete") . ":<ul>";
    print "\t<li>{$foldercnt} " . _("folders") . "</li>";
    if ($subnetcnt > 0) {
        print "\t<li>{$subnetcnt} " . _("subnets") . "</li>";
    }
    if ($ipcnt > 0) {
        print "\t<li>{$ipcnt} " . _("IP addresses") . "</li>";
    }
Example #6
0
<?php

/*
 * Print resize split
 *********************/
/* required functions */
require_once '../../functions/functions.php';
/* verify that user has write permissions for subnet */
$subnetPerm = checkSubnetPermission($_REQUEST['subnetId']);
if ($subnetPerm < 3) {
    die('<div class="alert alert-danger">' . _('You do not have permissions to resize subnet') . '!</div>');
}
/* verify post */
CheckReferrer();
# get subnet details
$subnet = getSubnetDetailsById($_POST['subnetId']);
# check if it has slaves - if yes it cannot be splitted!
$slaves = getAllSlaveSubnetsBySubnetId($_POST['subnetId']);
if (sizeof($slaves) > 0) {
    die("<div class='alert alert-warning'>" . 'Only subnets that have no nested subnets can be splitted' . "!</div>");
}
# calculate max split
$type = IdentifyAddress(transform2long($subnet['subnet']));
# type for max resize
if ($type == "IPv4") {
    $maxMask = "30";
    $type = 0;
} else {
    $maxMask = "126";
    $type = 1;
}
Example #7
0
 # get VLAN details
 $subnet['VLAN'] = subnetGetVLANdetailsById($subnet['vlanId']);
 $subnet['VLAN'] = $subnet['VLAN']['number'];
 # reformat empty VLAN
 if (empty($subnet['VLAN']) || $subnet['VLAN'] == 0) {
     $subnet['VLAN'] = "";
 }
 # get section name
 $section = getSectionDetailsById($subnet['sectionId']);
 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";
Example #8
0
<?php

/**
 * Script to display IP address info and history
 ***********************************************/
/* verify that user is authenticated! */
isUserAuthenticated();
# get site settings
if (sizeof($settings) == 0) {
    $settings = getAllSettings();
}
# get IP address details
$ip = getIpAddrDetailsById($_REQUEST['ipaddrid']);
$subnet = getSubnetDetailsById($_REQUEST['subnetId']);
$section = getSectionDetailsById($_REQUEST['section']);
# get all selected fields for IP print
$setFieldsTemp = getSelectedIPaddrFields();
// format them to array!
$setFields = explode(";", $setFieldsTemp);
# get all custom fields
$myFields = getCustomFields('ipaddresses');
# set ping statuses
$statuses = explode(";", $settings['pingStatus']);
# permissions
$permission = checkSubnetPermission($_REQUEST['subnetId']);
# section permissions
$permissionsSection = checkSectionPermission($_REQUEST['section']);
# if 0 die
if ($permission == "0") {
    die("<div class='alert alert-danger'>" . _('You do not have permission to access this network') . "!</div>");
}
        print '<div class="alert alert-success">' . _('Range') . ' ' . $ip['start'] . ' - ' . $ip['stop'] . ' ' . _('updated successfully') . '!</div>';
        updateLogTable('Range ' . $ip['start'] . ' - ' . $ip['stop'] . ' ' . $ip['action'] . ' successfull!', 'Range ' . $ip['start'] . ' - ' . $ip['stop'] . ' ' . $ip['action'] . ' ' . _('successfull') . '!', 0);
    }
} else {
    /* unique */
    if (isset($_POST['unique'])) {
        if ($_POST['unique'] == "1" && strlen($_POST['dns_name']) > 0) {
            # check if unique
            if (!isHostUnique($_POST['dns_name'])) {
                die('<div class="alert alert-danger">' . _('Hostname is not unique') . '!</div>');
            }
        }
    }
    /* verify ip address */
    if ($ip['action'] == "move") {
        $subnet = getSubnetDetailsById($_REQUEST['newSubnet']);
        $subnet = transform2long($subnet['subnet']) . "/" . $subnet['mask'];
        $verify = VerifyIpAddress($ip['ip_addr'], $subnet, $nostrict);
        $ip['newSubnet'] = $_REQUEST['newSubnet'];
    } else {
        $verify = VerifyIpAddress($ip['ip_addr'], $ip['subnet'], $nostrict);
    }
    /* if errors are present print them, else execute query! */
    if ($verify) {
        die('<div class="alert alert-danger">' . _('Error') . ': ' . $verify . ' (' . $ip['ip_addr'] . ')</div>');
    } else {
        /* set update for update */
        $ip['type'] = "single";
        /* check for duplicate entry! needed only in case new IP address is added, otherwise the code is locked! */
        if ($ip['action'] == "add") {
            if (checkDuplicate($ip['ip_addr'], $ip['subnetId'])) {
Example #10
0
/**
 * Verify that new nested subnet is inside master subnet!
 *
 * $root = root subnet Id
 * $new  = new subnet that we wish to add to root subnet
 */
function verifySubnetNesting($rootId, $new)
{
    //first get details for root subnet
    $rootDetails = getSubnetDetailsById($rootId);
    $rootDetails = Transform2long($rootDetails['subnet']) . "/" . $rootDetails['mask'];
    /* IPv4 or ipv6? */
    $type1 = IdentifyAddress($rootDetails);
    $type2 = IdentifyAddress($new);
    /* both must be IPv4 or IPv6 */
    if ($type1 != $type2) {
        return false;
        die;
    }
    /* we need network and broadcast address and check for both if the exist in any network!*/
    if (isSubnetInsideSubnet($new, $rootDetails)) {
        return true;
    } else {
        return false;
    }
}
Example #11
0
/**
 * CSV import IP address
 *
 *		provided input is CSV line!
 */
function importCSVline($line, $subnetId)
{
    /* array */
    $line = explode(",", $line);
    global $db;
    # get variables from config file
    $database = new database($db['host'], $db['user'], $db['pass'], $db['name']);
    /* get subnet details by Id */
    $subnetDetails = getSubnetDetailsById($subnetId);
    $subnet = Transform2long($subnetDetails['subnet']) . "/" . $subnetDetails['mask'];
    /* verify! */
    if (VerifyIpAddress($line[0], $subnet)) {
        return _('Wrong IP address') . ' - ' . $line[0];
    }
    /* check for duplicates */
    if (checkDuplicate($line[0], $subnetId)) {
        return _('IP address already exists') . ' - ' . $line[0];
    }
    /* reformat state */
    switch ($line[5]) {
        case "Active":
            $line[5] = "1";
            break;
        case "active":
            $line[5] = "1";
            break;
        case "Reserved":
            $line[5] = "2";
            break;
        case "reserved":
            $line[5] = "2";
            break;
        case "Offline":
            $line[5] = "0";
            break;
        case "offline":
            $line[5] = "0";
            break;
    }
    /* reformat switch! */
    $switch = getSwitchDetailsByHostname($line[7]);
    /* get custom fields */
    $myFields = getCustomIPaddrFields();
    if (sizeof($myFields) > 0) {
        $import['fieldName'] = "";
        $import['fieldValue'] = "";
        $m = 9;
        foreach ($myFields as $field) {
            $import['fieldName'] .= ",`{$field['name']}`";
            $import['fieldValue'] .= ",'{$line[$m]}'";
            $m++;
        }
    }
    /* all ok, set query */
    $query = "insert into ipaddresses ";
    $query .= "(`subnetId`, `ip_addr`, `state`, `description`, `dns_name`, `mac`, `owner`, `switch`, `port`, `note` {$import['fieldName']} ) ";
    $query .= "values ";
    $query .= "('{$subnetId}','" . Transform2decimal($line[0]) . "', '{$line['1']}','{$line['2']}','{$line['3']}','{$line['4']}','{$line['5']}','{$line['6']}','{$switch['id']}','{$line['8']}' {$import['fieldValue']});";
    /* set log details */
    $log = prepareLogFromArray($line);
    /* execute */
    try {
        $database->executeQuery($query);
    } catch (Exception $e) {
        $error = $e->getMessage();
    }
    if (!isset($e)) {
        updateLogTable('CSV import of IP address ' . $line[1] . ' succeeded', $log, 0);
        return true;
    } else {
        updateLogTable('CSV import of IP address ' . $line[1] . ' failed', $log, 2);
        return $error;
    }
}
Example #12
0
 ********************************************/
/* use required functions */
require_once '../../functions/functions.php';
/* First chech referer and requested with */
CheckReferrer();
/* verify that user is authenticated! */
isUserAuthenticated(false);
/* get all site settings */
$settings = getAllSettings();
/* user details */
$userDetails = getActiveUserDetails();
/* get IP address id */
$id = $_REQUEST['id'];
/* fetch all IP address details */
$ip = getIpAddrDetailsById($id);
$subnet = getSubnetDetailsById($ip['subnetId']);
/* get VLAN details */
$subnet['VLAN'] = subnetGetVLANdetailsById($subnet['vlanId']);
$subnet['vlan'] = $subnet['VLAN']['number'];
if (!empty($subnet['VLAN']['name'])) {
    $subnet['vlan'] .= ' (' . $subnet['VLAN']['name'] . ')';
}
/* set title */
$title = _('IP address details') . ' :: ' . $ip['ip_addr'];
/* Preset content */
$content .= '&bull; ' . _('IP address') . ': ' . "\t" . $ip['ip_addr'] . '/' . $subnet['mask'] . "\n";
# desc
if (!empty($ip['description'])) {
    $content .= '&bull; ' . _('Description') . ':' . "\t" . $ip['description'] . "\n";
}
# hostname
Example #13
0
/**
 *	Send IP result mail - reject or confirm reservation
 */
function sendIPResultEmail($request)
{
    # get settings
    global $settings;
    global $mail;
    # set subject based on action
    if ($request['action'] == "accept") {
        $subject = _("IP address request") . " (" . Transform2long($request['ip_addr']) . ") " . _("{$request['action']}ed");
    } else {
        $subject = _("IP address request {$request['action']}ed");
    }
    # set additional headers
    $mail['recipients'] = $request['requester'];
    // it is sent to requester this time!
    $mail['subject'] = $subject;
    # add admins to CC
    $admins = getAllAdminUsers();
    $cc = "";
    foreach ($admins as $admin) {
        $cc .= '' . $admin['email'] . ', ';
    }
    $cc = substr($cc, 0, -2);
    $mail['headers'] .= 'Cc: ' . $cc . "\r\n";
    # get active user name */
    $sender = getActiveUserDetails();
    # get subnet details
    $subnet = getSubnetDetailsById($request['subnetId']);
    $subnet2 = Transform2long($subnet['subnet']) . "/" . $subnet['mask'];
    # get section detaiils
    $section = getSectionDetailsById($subnet['sectionId']);
    # reformat \n to breaks
    $request['comment'] = str_replace("\n", "<br>", $request['comment']);
    $request['adminComment'] = str_replace("\n", "<br>", $request['adminComment']);
    # set html content
    if ($settings['htmlMail'] == "1") {
        $mail['content'] = $mail['header'];
        $mail['content'] .= "<tr><td style='padding:5px;margin:0px;color:#333;font-size:16px;text-shadow:1px 1px 1px white;border-bottom:1px solid #eeeeee;' colspan='2'><font face='Helvetica, Verdana, Arial, sans-serif' style='font-size:16px;'>{$subject}</font></td></tr>";
        $mail['content'] .= '<tr><td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;border-top:1px solid white;padding-top:10px;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;">&bull; ' . _('Section') . '   	</font></td><td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;border-top:1px solid white;padding-top:10px;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;">' . $section['name'] . ' (' . $section['description'] . ')</font></td></tr>' . "\n";
        $mail['content'] .= '<tr><td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;">&bull; ' . _('Subnet') . '   			</font></td>	<td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;">' . $subnet2 . '</font></td></tr>' . "\n";
        if ($request['action'] == "accept") {
            $mail['content'] .= '<tr><td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;">&bull; ' . _('assigned IP address') . '	</font></td>	<td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;">' . Transform2long($request['ip_addr']) . '</font></td></tr>' . "\n";
        }
        $mail['content'] .= '<tr><td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;">&bull; ' . _('Description') . '		 	</font></td>	<td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;">' . $request['description'] . '</font></td></tr>' . "\n";
        $mail['content'] .= '<tr><td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;">&bull; ' . _('Hostname') . '			 </font></td>	<td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;">' . $request['dns_name'] . '</font></td></tr>' . "\n";
        $mail['content'] .= '<tr><td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;">&bull; ' . _('Owner') . '				</font></td>	<td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;">' . $request['owner'] . '</font></td></tr>' . "\n";
        $mail['content'] .= '<tr><td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;">&bull; ' . _('Requested from') . '		</font></td>	<td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;"><a href="mailto:' . $request['requester'] . '" style="color:#08c;">' . $request['requester'] . '</a></font></td></tr>' . "\n";
        $mail['content'] .= '<tr><td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;vertical-align:top;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;">&bull; ' . _('Comment (request)') . '	</font></td>	<td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;">' . $request['comment'] . '</font></td></tr>' . "\n";
        $mail['content'] .= '<tr><td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;vertical-align:top;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;">&bull; ' . _('Admin accept/reject comment') . '	</font></td>	<td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px; font-weight:bold;">' . $request['adminComment'] . '</font></td></tr>' . "\n";
        $mail['content'] .= "<tr><td style='padding:5px;padding-left:15px;margin:0px;font-style:italic;padding-bottom:3px;text-align:right;color:#ccc;text-shadow:1px 1px 1px white;border-top:1px solid white;' colspan='2'><font face='Helvetica, Verdana, Arial, sans-serif' style='font-size:11px;'>" . _('Sent by user') . " " . $mail['sender']['real_name'] . " at " . date('Y/m/d H:i') . "</font></td></tr>";
        $mail['content'] .= $mail['footer2'];
    } else {
        # reformat content
        $content = str_replace("<br>", "\r\n", $content);
        $content = str_replace("\t", " ", $content);
        $content = strip_tags($content);
        # reformat content
        $request['comment'] = str_replace("<br>", "\r\n", $request['comment']);
        $request['adminComment'] = str_replace("<br>", "\r\n", $request['adminComment']);
        $mail['content'] = $mail['header'];
        $mail['content'] .= "{$subject}" . "\r\n------------------------------\r\n\r\n";
        $mail['content'] .= _("Section") . ":  {$section['name']} ({$section['description']})\r\n";
        $mail['content'] .= _("Subnet") . ":  {$subnet2}\r\n";
        if ($request['action'] == "accept") {
            $mail['content'] .= _("Assigned IP address") . ":  " . Transform2long($request['ip_addr']) . "\r\n";
        }
        $mail['content'] .= _("Description") . ":  {$request['description']}\r\n";
        $mail['content'] .= _("Hostname") . ":  {$request['dns_name']}\r\n";
        $mail['content'] .= _("Owner") . ":  {$request['owner']}\r\n";
        $mail['content'] .= _("Requested by") . ":  {$request['requester']}\r\n";
        $mail['content'] .= _("Comment (request)") . ":  {$request['comment']}\r\n";
        $mail['content'] .= _("Admin accept/reject comment") . ":  {$request['adminComment']}\r\n";
        $mail['content'] .= "\r\nSent by user " . $mail['sender']['real_name'] . " at " . date('Y/m/d H:i');
        $mail['content'] .= $mail['footer'];
        # reset headers
        $mail['headers'] = 'From: ' . $mail['from'] . "\r\n";
        $mail['headers'] .= 'Reply-To: ' . $settings['siteAdminMail'] . "\r\n";
        $mail['headers'] .= 'X-Mailer: PHP/' . phpversion() . "\r\n";
        $mail['headers'] .= 'Cc: ' . $cc . "\r\n";
    }
    # send mail and update log
    if (!mail($mail['recipients'], $mail['subject'], $mail['content'], $mail['headers'])) {
        # write log
        updateLogTable("IP request response mail (confirm,reject) sending failed", "Sending notification mail to {$mail['recipients']} failed!", $severity = 2);
        return false;
    } else {
        # write log
        updateLogTable("IP request response mail (confirm,reject) sent ok", "Sending notification mail to {$mail['recipients']} succeeded!", $severity = 0);
        return true;
    }
}
            updateLogTable('Range ' . $ip['start'] . ' - ' . $ip['stop'] . ' ' . $ip['action'] . ' successfull!', 'Range ' . $ip['start'] . ' - ' . $ip['stop'] . ' ' . $ip['action'] . ' ' . _('successfull') . '!', 0);
        }
    }
} else {
    /* unique */
    if (isset($_POST['unique'])) {
        if ($_POST['unique'] == "1" && strlen($_POST['dns_name']) > 0) {
            # check if unique
            if (!isHostUnique($_POST['dns_name'])) {
                die('<div class="alert alert-danger">' . _('Hostname is not unique') . '!</div>');
            }
        }
    }
    /* verify ip address */
    if ($ip['action'] == "move") {
        $subnet = getSubnetDetailsById($_POST['newSubnet']);
        $subnet = transform2long($subnet['subnet']) . "/" . $subnet['mask'];
        $verify = VerifyIpAddress($ip['ip_addr'], $subnet, $nostrict);
        $ip['newSubnet'] = $_POST['newSubnet'];
    } else {
        $verify = VerifyIpAddress($ip['ip_addr'], $ip['subnet'], $nostrict);
    }
    /* if errors are present print them, else execute query! */
    if ($verify) {
        die('<div class="alert alert-danger">' . _('Error') . ': ' . $verify . ' (' . $ip['ip_addr'] . ')</div>');
    } else {
        /* set update for update */
        $ip['type'] = "single";
        /* check for duplicate entry! needed only in case new IP address is added, otherwise the code is locked! */
        if ($ip['action'] == "add") {
            if (checkDuplicate($ip['ip_addr'], $ip['subnetId'])) {
Example #15
0
    $subnetPerm = checkSubnetPermission($_POST['subnetId']);
    if ($subnetPerm != 3) {
        die("<div class='pHeader'>" . _('Error') . "</div><div class='pContent'><div class='alert alert-danger'>" . _('You do not have permissions to add edit/delete this folder') . "!</div></div><div class='pFooter'><button class='btn btn-sm btn-default hidePopups'>" . _('Close') . "</button>");
    }
}
/* verify post */
CheckReferrer();
/* get all site settings */
$settings = getAllSettings();
# we are editing or deleting existing subnet, get old details
if ($_POST['action'] != "add") {
    $subnetDataOld = getSubnetDetailsById($_POST['subnetId']);
} else {
    # for selecting master subnet if added from subnet details!
    if (strlen($_REQUEST['subnetId']) > 0) {
        $tempData = getSubnetDetailsById($_POST['subnetId']);
        $subnetDataOld['masterSubnetId'] = $tempData['id'];
        // same master subnet ID for nested
        $subnetDataOld['vlanId'] = $tempData['vlanId'];
        // same default vlan for nested
        $subnetDataOld['vrfId'] = $tempData['vrfId'];
        // same default vrf for nested
    }
    $sectionName = getSectionDetailsById($_POST['sectionId']);
}
/* get custom subnet fields */
$customSubnetFields = getCustomFields('subnets');
# set readonly flag
if ($_POST['action'] == "edit" || $_POST['action'] == "delete") {
    $readonly = true;
} else {
Example #16
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;
    }
}
/* format them to array! */
$setFields = explode(";", $setFields);
/**
 * Get all ip addresses in subnet and subnet details!
 */
$title = _("IP addresses in subnet ");
# prefix for multiple subnets
if (sizeof($slaves) == 0) {
    $ipaddresses = getIpAddressesBySubnetIdSort($subnetId, $sort['field'], $sort['direction']);
    $slavePing = false;
} else {
    $ipaddresses = getIpAddressesBySubnetIdSlavesSort($subnetId, $sort['field'], $sort['direction']);
    $title = _("All IP addresses belonging to ALL nested subnets");
    $slavePing = true;
}
$SubnetDetails = getSubnetDetailsById($subnetId);
/* die if empty! */
if (sizeof($SubnetDetails) == 0) {
    die('<div class="alert alert-danger">' . _('Subnet does not exist') . '!</div>');
}
/* get all selected fields */
$myFields = getCustomFields('ipaddresses');
$myFieldsSize = sizeof($myFields);
/* set size of selected fields */
$selFieldsSize = sizeof($setFields);
if (in_array('state', $setFields)) {
    $selFieldsSize--;
}
/* fix for 0 */
if ($selFieldsSize == 1 && strlen($setFields[0]) == 0) {
    $selFieldsSize = 0;
Example #18
0
 if ($permission != "0") {
     //get section details
     $section = getSectionDetailsById($line['sectionId']);
     //get vlan number
     $vlan = subnetGetVLANDetailsById($line['vlanId']);
     //format requests
     if ($line['allowRequests'] == 1) {
         $line['allowRequests'] = "enabled";
     } else {
         $line['allowRequests'] = "disabled";
     }
     //format master subnet
     if ($line['masterSubnetId'] == 0) {
         $line['masterSubnetId'] = "/";
     } else {
         $line['masterSubnetId'] = getSubnetDetailsById($line['masterSubnetId']);
         # folder?
         if ($line['isFolder'] == 1) {
             $line['masterSubnetId'] = "<i class='fa fa-folder-o fa fa-gray'></i> {$line['description']}";
         } else {
             $line['masterSubnetId'] = transform2long($line['masterSubnetId']['subnet']) . '/' . $line['masterSubnetId']['mask'];
         }
     }
     print '<tr class="subnetSearch" subnetId="' . $line['id'] . '" sectionName="' . $section['name'] . '" sectionId="' . $section['id'] . '" link="' . $section['name'] . '|' . $line['id'] . '">' . "\n";
     print '	<td>' . $section['name'] . '</td>' . "\n";
     //folder?
     if ($line['isFolder'] == 1) {
         print '	<td><a href="subnets/' . $line['sectionId'] . '/' . $line['id'] . '/"><i class="fa fa-folder-o fa fa-gray"></i> ' . $line['description'] . '</a></td>' . "\n";
     } else {
         print '	<td><a href="subnets/' . $line['sectionId'] . '/' . $line['id'] . '/">' . transform2long($line['subnet']) . '/' . $line['mask'] . '</a></td>' . "\n";
     }
Example #19
0
/**
 * CSV import IP address
 *
 *		provided input is CSV line!
 */
function importCSVline($line, $subnetId)
{
    global $database;
    /* get subnet details by Id */
    $subnetDetails = getSubnetDetailsById($subnetId);
    $subnet = Transform2long($subnetDetails['subnet']) . "/" . $subnetDetails['mask'];
    /* verify! */
    $err = VerifyIpAddress($line[0], $subnet);
    if ($err) {
        return _('Wrong IP address') . ' - ' . $err . ' - ' . $line[0];
    }
    /* check for duplicates */
    if (checkDuplicate($line[0], $subnetId)) {
        return _('IP address already exists') . ' - ' . $line[0];
    }
    /* get custom fields */
    $myFields = getCustomFields('ipaddresses');
    if (sizeof($myFields) > 0) {
        $import['fieldName'] = "";
        $import['fieldValue'] = "";
        $m = 9;
        foreach ($myFields as $field) {
            //escape chars
            $line[$m] = mysqli_real_escape_string($database, $line[$m]);
            $import['fieldName'] .= ",`{$field['name']}`";
            $import['fieldValue'] .= ",'{$line[$m]}'";
            $m++;
        }
    }
    /* escape chars */
    foreach ($line as $k => $l) {
        $line[$k] = mysqli_real_escape_string($database, $l);
    }
    /* all ok, set query */
    $query = "insert into ipaddresses ";
    $query .= "(`subnetId`, `ip_addr`, `state`, `description`, `dns_name`, `mac`, `owner`, `switch`, `port`, `note` {$import['fieldName']} ) ";
    $query .= "values ";
    $query .= "('{$subnetId}','" . Transform2decimal($line[0]) . "', '{$line['1']}','{$line['2']}','{$line['3']}','{$line['4']}','{$line['5']}','{$line['6']}','{$line['7']}','{$line['8']}' {$import['fieldValue']});";
    /*
    	print "<pre>";
    	print_r($line);
    	die('alert alert-danger');
    */
    /* set log details */
    $log = prepareLogFromArray($line);
    /* execute */
    try {
        $database->executeQuery($query);
    } catch (Exception $e) {
        $error = $e->getMessage();
    }
    if (!isset($e)) {
        updateLogTable('CSV import of IP address ' . $line[1] . ' succeeded', $log, 0);
        return true;
    } else {
        updateLogTable('CSV import of IP address ' . $line[1] . ' failed', $log, 2);
        return $error;
    }
}
Example #20
0
/**
 *	Send IP result mail - reject or confirm reservation
 */
function sendIPResultEmail($request)
{
    # get settings
    global $settings;
    global $mailsettings;
    global $mail;
    global $pmail;
    # set subject based on action
    if ($request['action'] == "accept") {
        $subject = _("IP address request") . " (" . Transform2long($request['ip_addr']) . ") " . _("{$request['action']}ed");
    } else {
        $subject = _("IP address request {$request['action']}ed");
    }
    # get active user name */
    $sender = getActiveUserDetails();
    # get subnet details
    $subnet = getSubnetDetailsById($request['subnetId']);
    $subnet2 = Transform2long($subnet['subnet']) . "/" . $subnet['mask'];
    # get section detaiils
    $section = getSectionDetailsById($subnet['sectionId']);
    # reformat \n to breaks
    $request['comment'] = str_replace("\n", "<br>", $request['comment']);
    $request['adminComment'] = str_replace("\n", "<br>", $request['adminComment']);
    # set html content
    $mail['content'] = $mail['header'];
    $mail['content'] .= "<tr><td style='padding:5px;margin:0px;color:#333;font-size:16px;text-shadow:1px 1px 1px white;border-bottom:1px solid #eeeeee;' colspan='2'><font face='Helvetica, Verdana, Arial, sans-serif' style='font-size:16px;'>{$subject}</font></td></tr>";
    $mail['content'] .= '<tr><td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;border-top:1px solid white;padding-top:10px;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;">&bull; ' . _('Section') . '   	</font></td><td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;border-top:1px solid white;padding-top:10px;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;">' . $section['name'] . ' (' . $section['description'] . ')</font></td></tr>' . "\n";
    $mail['content'] .= '<tr><td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;">&bull; ' . _('Subnet') . '   			</font></td>	<td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;">' . $subnet2 . '</font></td></tr>' . "\n";
    if ($request['action'] == "accept") {
        $mail['content'] .= '<tr><td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;">&bull; ' . _('assigned IP address') . '	</font></td>	<td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;">' . Transform2long($request['ip_addr']) . '</font></td></tr>' . "\n";
    }
    $mail['content'] .= '<tr><td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;">&bull; ' . _('Description') . '		 	</font></td>	<td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;">' . $request['description'] . '</font></td></tr>' . "\n";
    $mail['content'] .= '<tr><td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;">&bull; ' . _('Hostname') . '			 </font></td>	<td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;">' . $request['dns_name'] . '</font></td></tr>' . "\n";
    $mail['content'] .= '<tr><td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;">&bull; ' . _('Owner') . '				</font></td>	<td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;">' . $request['owner'] . '</font></td></tr>' . "\n";
    $mail['content'] .= '<tr><td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;">&bull; ' . _('Requested from') . '		</font></td>	<td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;"><a href="mailto:' . $request['requester'] . '" style="color:#08c;">' . $request['requester'] . '</a></font></td></tr>' . "\n";
    $mail['content'] .= '<tr><td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;vertical-align:top;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;">&bull; ' . _('Comment (request)') . '	</font></td>	<td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;">' . $request['comment'] . '</font></td></tr>' . "\n";
    $mail['content'] .= '<tr><td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;vertical-align:top;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px;">&bull; ' . _('Admin accept/reject comment') . '	</font></td>	<td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;"><font face="Helvetica, Verdana, Arial, sans-serif" style="font-size:13px; font-weight:bold;">' . $request['adminComment'] . '</font></td></tr>' . "\n";
    $mail['content'] .= "<tr><td style='padding:5px;padding-left:15px;margin:0px;font-style:italic;padding-bottom:3px;text-align:right;color:#ccc;text-shadow:1px 1px 1px white;border-top:1px solid white;' colspan='2'><font face='Helvetica, Verdana, Arial, sans-serif' style='font-size:11px;'>" . _('Sent by user') . " " . $mail['sender']['real_name'] . " at " . date('Y/m/d H:i') . "</font></td></tr>";
    $mail['content'] .= $mail['footer2'];
    # alt content
    $request['comment'] = str_replace("<br>", "\r\n", $request['comment']);
    $request['adminComment'] = str_replace("<br>", "\r\n", $request['adminComment']);
    $mail['contentAlt'] = $mail['headerAlt'];
    $mail['contentAlt'] .= "{$subject}" . "\r\n------------------------------\r\n\r\n";
    $mail['contentAlt'] .= _("Section") . ":  {$section['name']} ({$section['description']})\r\n";
    $mail['contentAlt'] .= _("Subnet") . ":  {$subnet2}\r\n";
    if ($request['action'] == "accept") {
        $mail['contentAlt'] .= _("Assigned IP address") . ":  " . Transform2long($request['ip_addr']) . "\r\n";
    }
    $mail['contentAlt'] .= _("Description") . ":  {$request['description']}\r\n";
    $mail['contentAlt'] .= _("Hostname") . ":  {$request['dns_name']}\r\n";
    $mail['contentAlt'] .= _("Owner") . ":  {$request['owner']}\r\n";
    $mail['contentAlt'] .= _("Requested by") . ":  {$request['requester']}\r\n";
    $mail['contentAlt'] .= _("Comment (request)") . ":  {$request['comment']}\r\n";
    $mail['contentAlt'] .= _("Admin accept/reject comment") . ":  {$request['adminComment']}\r\n";
    $mail['contentAlt'] .= "\r\nSent by user " . $mail['sender']['real_name'] . " at " . date('Y/m/d H:i');
    $mail['contentAlt'] .= $mail['footerAlt'];
    # set mail parameters
    try {
        $pmail->SetFrom($mailsettings['mAdminMail'], $mailsettings['mAdminName']);
        // send to requester
        $pmail->AddAddress($request['requester']);
        // add admins to CC
        $admins = getAllAdminUsers();
        foreach ($admins as $admin) {
            $pmail->AddCC($admin['email']);
        }
        $pmail->ClearReplyTos();
        $pmail->AddReplyTo($mailsettings['mAdminMail'], $mailsettings['mAdminName']);
        // content
        $pmail->Subject = $subject;
        $pmail->AltBody = $mail['contentAlt'];
        $pmail->MsgHTML($mail['content']);
        # poĊĦlji
        $pmail->Send();
    } catch (phpmailerException $e) {
        updateLogTable("IP request response mail (confirm,reject) sending failed", "Sending notification mail to {$mail['recipients']} failed!\n" . $e->errorMessage(), 2);
        return false;
    } catch (Exception $e) {
        updateLogTable("IP request response mail (confirm,reject) sending failed", "Sending notification mail to {$mail['recipients']} failed!\n" . $e->errorMessage(), 2);
        return false;
    }
    # write log for ok
    updateLogTable("IP request response mail (confirm,reject) sent ok", "Sending notification mail to {$mail['recipients']} succeeded!", 0);
    return true;
}
Example #21
0
/**
 *	print breadcrumbs
 */
function printBreadcrumbs($req)
{
    # subnets
    if (isset($req['ipaddrid'])) {
        if (isset($req['subnetId'])) {
            # get all parents
            $parents = getAllParents($req['subnetId']);
            print "<ul class='breadcrumb'>";
            # remove root - 0
            array_shift($parents);
            # section details
            if (is_numeric($req['section'])) {
                $section = getSectionDetailsById($req['section']);
            } else {
                $section = getSectionDetailsByName($req['section']);
            }
            # if name is provided
            print "\t<li><a href='subnets/{$section['id']}/'>{$section['name']}</a> <span class='divider'></span></li>";
            # section name
            foreach ($parents as $parent) {
                $subnet = getSubnetDetailsById($parent);
                if ($subnet['isFolder'] == 1) {
                    print "\t<li><a href='subnets/{$section['id']}/{$parent}/'><i class='icon-folder-open icon-gray'></i> {$subnet['description']}</a> <span class='divider'></span></li>";
                    # subnets in between
                } else {
                    print "\t<li><a href='subnets/{$section['id']}/{$parent}/'>{$subnet['description']} (" . Transform2long($subnet['subnet']) . '/' . $subnet['mask'] . ")</a> <span class='divider'></span></li>";
                    # subnets in between
                }
            }
            # parent subnet
            $subnet = getSubnetDetailsById($req['subnetId']);
            print "\t<li><a href='subnets/{$section['id']}/{$subnet['id']}/'>{$subnet['description']} (" . Transform2long($subnet['subnet']) . '/' . $subnet['mask'] . ")</a> <span class='divider'></span></li>";
            # active subnet
            # ip
            $ip = getIpAddrDetailsById($req['ipaddrid']);
            print "\t<li class='active'>{$ip['ip_addr']}</li>";
            # IP address
            print "</ul>";
        }
    } elseif ($req['page'] == "subnets") {
        if (isset($req['subnetId'])) {
            # get all parents
            $parents = getAllParents($req['subnetId']);
            print "<ul class='breadcrumb'>";
            # remove root - 0
            array_shift($parents);
            # section details
            if (is_numeric($req['section'])) {
                $section = getSectionDetailsById($req['section']);
            } else {
                $section = getSectionDetailsByName($req['section']);
            }
            # if name is provided
            print "\t<li><a href='subnets/{$section['id']}/'>{$section['name']}</a> <span class='divider'></span></li>";
            # section name
            foreach ($parents as $parent) {
                $subnet = getSubnetDetailsById($parent);
                if ($subnet['isFolder'] == 1) {
                    print "\t<li><a href='subnets/{$section['id']}/{$parent}/'><i class='icon-folder-open icon-gray'></i> {$subnet['description']}</a> <span class='divider'></span></li>";
                    # subnets in between
                } else {
                    print "\t<li><a href='subnets/{$section['id']}/{$parent}/'>{$subnet['description']} (" . Transform2long($subnet['subnet']) . '/' . $subnet['mask'] . ")</a> <span class='divider'></span></li>";
                    # subnets in between
                }
            }
            $subnet = getSubnetDetailsById($req['subnetId']);
            print "\t<li class='active'>{$subnet['description']} (" . Transform2long($subnet['subnet']) . '/' . $subnet['mask'] . ")</li>";
            # active subnet
            print "</ul>";
        }
    }
    # subnets
    if ($req['page'] == "folder") {
        if (isset($req['subnetId'])) {
            # get all parents
            $parents = getAllParents($req['subnetId']);
            print "<ul class='breadcrumb'>";
            # remove root - 0
            array_shift($parents);
            # section details
            if (is_numeric($req['section'])) {
                $section = getSectionDetailsById($req['section']);
            } else {
                $section = getSectionDetailsByName($req['section']);
            }
            # if name is provided
            print "\t<li><a href='subnets/{$section['id']}/'>{$section['name']}</a> <span class='divider'></span></li>";
            # section name
            foreach ($parents as $parent) {
                $subnet = getSubnetDetailsById($parent);
                print "\t<li><a href='subnets/{$section['id']}/{$parent}/'><i class='icon-folder-open icon-gray'></i> {$subnet['description']}</a> <span class='divider'></span></li>";
                # subnets in between
            }
            $subnet = getSubnetDetailsById($req['subnetId']);
            print "\t<li class='active'>{$subnet['description']}</li>";
            # active subnet
            print "</ul>";
        }
    } else {
        if ($req['page'] == "admin") {
        } else {
            if ($req['page'] == "tools") {
                if (isset($req['tpage'])) {
                    print "<ul class='breadcrumb'>";
                    print "\t<li><a href='tools/'>" . _('Tools') . "</a> <span class='divider'></span></li>";
                    print "\t<li class='active'>{$req['tpage']}></li>";
                    print "</ul>";
                }
            }
        }
    }
}
        //not empty
        if ($myField['Null'] == "NO" && strlen($_POST[$myField['name']]) == 0 && !checkAdmin(false)) {
            $errors[] = "Field \"{$myField['name']}\" cannot be empty!";
        }
    }
}
/* sanitize description */
/* $_POST['description'] = htmlentities($_POST['description'], ENT_COMPAT | ENT_HTML401, "UTF-8");	//prevent XSS */
/* Set permissions for add! */
if ($_POST['action'] == "add") {
    # root
    if ($_POST['masterSubnetId'] == 0) {
        $_POST['permissions'] = $section['permissions'];
    } else {
        # get parent
        $parent = getSubnetDetailsById($_POST['masterSubnetId']);
        $_POST['permissions'] = $parent['permissions'];
    }
}
/* If no errors are present execute request */
if (sizeof($errors) != 0) {
    print '<div class="alert alert-danger"><strong>' . _('Please fix following problems') . '</strong>:';
    foreach ($errors as $error) {
        print "<br>" . $error;
    }
    print '</div>';
    die;
} else {
    # failed
    if (!modifySubnetDetails($_POST)) {
        print '<div class="alert alert-danger">' . _('Error adding new subnet') . '!</div>';
Example #23
0
</th>
	<th><?php 
    print _('Description');
    ?>
</th>
	<th><?php 
    print _('Requested by');
    ?>
</th>
</tr>

<?php 
    # print requests
    foreach ($allActiveRequests as $request) {
        //get subnet details
        $subnet = getSubnetDetailsById($request['subnetId']);
        print '<tr>' . "\n";
        print "\t<td><button class='btn btn-xs btn-default' data-requestid='{$request['id']}'><i class='fa fa-pencil'></i></button></td>";
        print '	<td>' . Transform2long($subnet['subnet']) . '/' . $subnet['mask'] . ' (' . $subnet['description'] . ')</td>' . "\n";
        print '	<td>' . $request['dns_name'] . '</td>' . "\n";
        print '	<td>' . $request['description'] . '</td>' . "\n";
        print '	<td>' . $request['requester'] . '</td>' . "\n";
        print '</tr>' . "\n";
    }
    ?>

</table>

<?php 
}
?>
Example #24
0
        ?>
</tr>

<!-- IP addresses -->
<?php 
        /* if no result print nothing found */
        if (sizeof($result) > 0) {
            $m = 0;
            //for section change
            /* print content */
            foreach ($result as $line) {
                # check permission
                $permission = checkSubnetPermission($line['subnetId']);
                if ($permission != "0") {
                    //get the Subnet details
                    $subnet = getSubnetDetailsById($line['subnetId']);
                    //get vlan number
                    $vlan = subnetGetVLANDetailsById($subnet['vlanId']);
                    //get section
                    $section = getSectionDetailsById($subnet['sectionId']);
                    //detect section change and print headers
                    if ($result[$m]['subnetId'] != $result[$m - 1]['subnetId']) {
                        print '<tr>' . "\n";
                        print '	<th colspan="' . $colSpan . '">' . $section['name'] . ' :: <a href="' . create_link("subnets", $subnet['sectionId'], $subnet['id']) . '" style="font-weight:300">' . $subnet['description'] . ' (' . transform2long($subnet['subnet']) . '/' . $subnet['mask'] . ')</a></th>' . "\n";
                        print '</tr>';
                    }
                    $m++;
                    $stateClass = "";
                    if (in_array('state', $setFields)) {
                        if ($line['state'] == "0") {
                            $stateClass = "offline";