$_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); print "<h4>{$master['description']} " . _('has') . " {$slaveNum} " . _('directly nested folders') . ":</h4><hr>"; /* print HTML list */
if (isset($_COOKIE['expandfolders'])) { if ($_COOKIE['expandfolders'] == "1") { $iconClass = 'fa-compress'; $action = 'open'; } else { $iconClass = 'fa-expand'; $action = 'close'; } } else { $iconClass = 'fa-expand'; $action = 'close'; } # Check if it has parent, and if so print back link if ($sectionName['masterSection'] != "0") { # get details $mSection = getSectionDetailsById($sectionName['masterSection']); print "<div class='subnets' style='padding-top:10px;'>"; print "\t<a href='subnets/{$mSection['id']}/'><i class='fa fa-gray fa-angle-left fa-pad-left'></i> " . _('Back to') . " {$mSection['name']}</a><hr>"; print "</div>"; } print "<h4>" . _('Available subnets') . " <span class='pull-right' style='margin-right:5px;cursor:pointer;'><i class='fa fa-gray fa-sm {$iconClass}' rel='tooltip' data-placement='bottom' title='" . _('Expand/compress all folders') . "' id='expandfolders' data-action='{$action}'></i></span></h4>"; print "<hr>"; /* print subnets table ---------- */ print "<div class='subnets'>"; # print links $subnets2 = fetchSubnets($sectionId); $menu = get_menu_html($subnets2); print $menu; print "</div>"; # end subnets overlay /* print VLANs */
foreach ($devices as $device) { //print details print '<tr>' . "\n"; print ' <td>' . $device['hostname'] . '</td>' . "\n"; print ' <td>' . $device['ip_addr'] . '</td>' . "\n"; print ' <td>' . $device['tname'] . '</td>' . "\n"; print ' <td>' . $device['vendor'] . '</td>' . "\n"; print ' <td>' . $device['model'] . '</td>' . "\n"; print ' <td>' . $device['version'] . '</td>' . "\n"; print ' <td class="description">' . $device['description'] . '</td>' . "\n"; //sections print ' <td class="sections">'; $temp = explode(";", $device['sections']); if (sizeof($temp) > 0 && !empty($temp[0])) { foreach ($temp as $line) { $section = getSectionDetailsById($line); if (!empty($section)) { print '<div class="switchSections">' . $section['name'] . '</div>' . "\n"; } } } print ' </td>' . "\n"; //custom if (sizeof($custom) > 0) { foreach ($custom as $field) { if (!in_array($field['name'], $ffields)) { print "<td class='hidden-xs hidden-sm hidden-md'>"; //booleans if ($field['type'] == "tinyint(1)") { if ($device[$field['name']] == "0") { print _("No");
/** * 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; }
# check if it is master if ($subnet['masterSubnetId'] == 0 || empty($subnet['masterSubnetId'])) { $masterSubnet = true; } else { $masterSubnet = false; } print "<tr>"; # 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
* We provide subnet and mask, all other is calculated based on it (subnet, broadcast,...) */ $SubnetParsed = parseIpAddress(transform2long($SubnetDetails['subnet']), $SubnetDetails['mask']); # set rowspan $rowSpan = 10 + $customSubnetFieldsSize; # permissions $permission = checkSubnetPermission($subnetId); # section permissions $permissionsSection = checkSectionPermission($SubnetDetails['sectionId']); # if 0 die if ($permission == "0") { die("<div class='alert alert-danger'>" . _('You do not have permission to access this folder') . "!</div>"); } # verify that is it displayed in proper section, otherwise warn! if ($SubnetDetails['sectionId'] != $_GET['section']) { $sd = getSectionDetailsById($SubnetDetails['sectionId']); print "<div class='alert alert-warning'>Folder is in section <a href='" . create_link("folder", $sd['id'], $SubnetDetails['id']) . "'>{$sd['name']}</a>!</div>"; } ?> <!-- content print! --> <!-- for adding IP address! --> <div id="subnetId" style="display:none"><?php print $subnetId; ?> </div> <!-- subnet details upper table --> <h4><?php print _('Folder details');
/** * 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; } }
/** * reformat sections for devices! * sections are separated with ; */ function reformatDeviceSections($sections) { if (sizeof($sections != 0)) { //first reformat $temp = explode(";", $sections); foreach ($temp as $section) { //we have sectionId, so get its name $out = getSectionDetailsById($section); $out = $out['name']; //format output $result[$out] = $section; } } //return result if it exists if ($result) { return $result; } else { return false; } }
/** * Get all subnets in provided sectionId */ function fetchSubnets($sectionId, $orderType = "subnet", $orderBy = "asc") { global $db; # get variables from config file /* check for sorting in settings and override */ $settings = getAllSettings(); /* get section details to check for ordering */ $section = getSectionDetailsById($sectionId); // section ordering if ($section['subnetOrdering'] != "default" && strlen($section['subnetOrdering']) > 0) { $sort = explode(",", $section['subnetOrdering']); $orderType = $sort[0]; $orderBy = $sort[1]; } elseif (isset($settings['subnetOrdering'])) { $sort = explode(",", $settings['subnetOrdering']); $orderType = $sort[0]; $orderBy = $sort[1]; } /* set query, open db connection and fetch results */ $query = "select * from `subnets` where `sectionId` = '{$sectionId}' ORDER BY `masterSubnetId`,`{$orderType}` {$orderBy};"; $database = new database($db['host'], $db['user'], $db['pass'], $db['name']); /* execute */ try { $subnets = $database->getArray($query); } catch (Exception $e) { $error = $e->getMessage(); print "<div class='alert alert-error'>" . _('Error') . ":{$error}</div>"; return false; } $database->close(); /* return subnets array */ return $subnets; }
<?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>"); }
/** * delete section */ public function deleteSection() { //verications if (!isset($this->id)) { throw new Exception('Section ID missing'); } //does it exist? if (sizeof(getSectionDetailsById($this->id)) == 0) { throw new Exception('Section does not exist'); } //create array to write new section $newSection = $this->toArray($this); //create new section $res = UpdateSection($newSection, true); //true means from API //return result (true/false) if (!$res) { throw new Exception('Invalid query'); } else { //format response return "Section deleted"; } }
if (!is_numeric($sectionId) && $sectionId != "Administration") { $sectionId = getSectionIdFromSectionName($sectionId); } /** * Admin check, otherwise load requested subnets */ if ($sectionId == 'Administration') { /* Print all Admin actions af user is admin :) */ if (!checkAdmin()) { print '<div class="alert alert-error">' . _('Sorry, must be admin') . '!</div>'; } else { include 'admin/adminMenu.php'; } } else { /* get section name */ $sectionName = getSectionDetailsById($sectionId); # verify permissions $sectionPermission = checkSectionPermission($sectionId); if ($sectionPermission == "0") { die("<div class='alert alert-error'>" . _('You do not have access to this section') . "!</div>"); } /* die if empty! */ if (sizeof($sectionName) == 0) { die('<div class="alert alert-error">' . _('Section does not exist') . '!</div>'); } # header if (isset($_COOKIE['expandfolders'])) { if ($_COOKIE['expandfolders'] == "1") { $iconClass = 'icon-resize-small'; $action = 'open'; } else {
/** * 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;">• ' . _('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;">• ' . _('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;">• ' . _('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;">• ' . _('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;">• ' . _('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;">• ' . _('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;">• ' . _('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;">• ' . _('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;">• ' . _('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; } }
$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 { $readonly = false; } ?> <!-- header --> <div class="pHeader"><?php
$allSubnets = searchSubnets($searchTerm, $searchTermEdited); $lineCount = 0; $worksheet =& $workbook->addWorksheet(_('Subnet search results')); //write headers $worksheet->write($lineCount, 0, _('Section'), $format_title); $worksheet->write($lineCount, 1, _('Subet'), $format_title); $worksheet->write($lineCount, 2, _('Mask'), $format_title); $worksheet->write($lineCount, 3, _('Description'), $format_title); $worksheet->write($lineCount, 4, _('Master subnet'), $format_title); $worksheet->write($lineCount, 5, _('VLAN'), $format_title); $worksheet->write($lineCount, 6, _('IP requests'), $format_title); //new line $lineCount++; foreach ($allSubnets as $line) { //get section details $section = getSectionDetailsById($line['sectionId']); //format master subnet if ($line['masterSubnetId'] == 0) { $line['masterSubnetId'] = "/"; } else { $line['masterSubnetId'] = getSubnetDetailsById($line['masterSubnetId']); $line['masterSubnetId'] = transform2long($line['masterSubnetId']['subnet']) . '/' . $line['masterSubnetId']['mask']; } //admin lock if ($line['adminLock'] == 1) { $line['adminLock'] = 'yes'; } else { $line['adminLock'] = ''; } //allowRequests if ($line['allowRequest'] == 1) {
} print '</tr>' . "\n"; $m = 0; foreach ($vlans as $vlan) { # new change detection if ($m > 0) { if ($vlans[$m]['number'] == $vlans[$m - 1]['number'] && $vlans[$m]['name'] == $vlans[$m - 1]['name'] && $vlans[$m]['description'] == $vlans[$m - 1]['description']) { $change = 'nochange'; } else { $change = 'change'; } } else { $change = 'change'; } /* get section details */ $section = getSectionDetailsById($vlan['sectionId']); /* check if it is master */ if (!isset($vlan['masterSubnetId'])) { $masterSubnet = true; } else { if ($vlan['masterSubnetId'] == 0 || empty($vlan['masterSubnetId'])) { $masterSubnet = true; } else { $masterSubnet = false; } } # check permission $permission = checkSubnetPermission($vlan['subnetId']); if ($permission != "0") { print "<tr class='{$change}'>"; /* print first 3 only if change happened! */
/** * 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;">• ' . _('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;">• ' . _('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;">• ' . _('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;">• ' . _('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;">• ' . _('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;">• ' . _('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;">• ' . _('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;">• ' . _('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;">• ' . _('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; }
print _('Group Permissions'); ?> </th> <th></th> </tr> <!-- existing sections --> <?php foreach ($sections as $section) { print '<tr class="' . $section['class'] . '">' . "\n"; print ' <td>' . str_replace("_", " ", $section['name']) . '</td>' . "\n"; print ' <td>' . $section['description'] . '</td>' . "\n"; # master Section if ($section['masterSection'] != "0") { # get section details $ssec = getSectionDetailsById($section['masterSection']); print "\t<td>{$ssec['name']}</td>"; } else { print "\t<td>/</td>"; } # strictMode if ($section['strictMode'] == 0) { $mode = _("No"); } else { $mode = _("Yes"); } print ' <td>' . $mode . '</td>' . "\n"; # Show VLANs print " <td>"; if (@$section['showVLAN'] == 1) { print _("Yes");
/* 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") { die("<div class='alert alert-danger'>" . _('You do not have permission to access this network') . "!</div>");
/** * 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>"; } } } } }
print "\t<th>" . _('Section') . "</th>"; print "\t<th class='small hidden-xs hidden-sm'>" . _('Hosts check') . "</th>"; print "\t<th class='hidden-xs hidden-sm'>" . _('Requests') . "</th>"; print " <th></th>"; print "</tr>"; /* print each slave */ $usedSum = 0; $allSum = 0; # for free space check $slaveSize = sizeof($slaves); $m = 0; foreach ($slaves as $slave) { # check permission $permission = checkSubnetPermission($slave['id']); if ($permission > 0) { $section = getSectionDetailsById($slave['sectionId']); print "<tr>"; print "\t<td class='small description'><a href='" . create_link("subnets", $section['id'], $slave['id']) . "'>" . transform2long($slave['subnet']) . "/{$slave['mask']}</a></td>"; print "\t<td>{$slave['description']}</td>"; # section print "\t<td><a href='" . create_link("subnets", $section['id']) . "'>" . $section['name'] . "</a></td>"; # host check if ($slave['pingSubnet'] == 1) { print '<td class="allowRequests small hidden-xs hidden-sm"><i class="fa fa-gray fa-check"></i></td>'; } else { print '<td class="allowRequests small hidden-xs hidden-sm"></td>'; } # count IP addresses $hasSlaves = getAllSlaveSubnetsBySubnetId($slave['id']); # slaves details are provided with ipaddressprintslaves script if (sizeof($hasSlaves) > 0) {