/** * Format IP address */ public function format_ip($result) { if (sizeof($result) > 0) { foreach ($result as $r) { # ip? if (isset($r['ip_addr'])) { $r['ip_addr'] = transform2long($r['ip_addr']); } elseif (isset($r['subnet'])) { $r['subnet'] = transform2long($r['subnet']); } $out[] = $r; } } else { $out = $result; } # formatted return $out; }
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'])) { die('<div class="alert alert-danger">' . _('IP address') . ' ' . $ip['ip_addr'] . ' ' . _('already existing in database') . '!</div>');
/** * Print subnets structure */ function printSubnets($subnets, $actions = true, $vrf = "0", $custom = array()) { $html = array(); $rootId = 0; # root is 0 if (sizeof($subnets) > 0) { foreach ($subnets as $item) { $children[$item['masterSubnetId']][] = $item; } } # loop will be false if the root has no children (i.e., an empty menu!) $loop = !empty($children[$rootId]); # initializing $parent as the root $parent = $rootId; $parent_stack = array(); # display selected subnet as opened if (isset($_REQUEST['subnetId'])) { $allParents = getAllParents($_REQUEST['subnetId']); } # return table content (tr and td's) while ($loop && (($option = each($children[$parent])) || $parent > $rootId)) { # repeat $repeat = str_repeat(" - ", count($parent_stack)); # dashes if (count($parent_stack) == 0) { $dash = ""; } else { $dash = "-"; } if (count($parent_stack) == 0) { $margin = "0px"; $padding = "0px"; } else { # padding $padding = "10px"; # margin $margin = count($parent_stack) * 10 - 10; $margin = $margin * 2; $margin = $margin . "px"; } # count levels $count = count($parent_stack) + 1; # get subnet details # get VLAN $vlan = subnetGetVLANdetailsById($option['value']['vlanId']); $vlan = $vlan['number']; if (empty($vlan) || $vlan == "0") { $vlan = ""; } # no VLAN # description if (strlen($option['value']['description']) == 0) { $description = "/"; } else { $description = $option['value']['description']; } # description # requests if ($option['value']['allowRequests'] == 1) { $requests = "<i class='fa fa-gray fa-check'></i>"; } else { $requests = ""; } # request disabled # hosts check if ($option['value']['pingSubnet'] == 1) { $pCheck = "<i class='fa fa-gray fa-check'></i>"; } else { $pCheck = ""; } # ping check disabled #vrf if ($vrf == "1") { # get VRF details if ($option['value']['vrfId'] != "0" && $option['value']['vrfId'] != "NULL") { $vrfTmp = getVRFDetailsById($option['value']['vrfId']); $vrfText = $vrfTmp['name']; } else { $vrfText = ""; } } # print table line if (strlen($option['value']['subnet']) > 0) { // verify permission $permission = checkSubnetPermission($option['value']['id']); // print item if ($permission != 0) { $html[] = "<tr>"; # which level? if ($count == 1) { # is folder? if ($option['value']['isFolder'] == 1) { $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-sfolder fa-pad-right-3 fa-folder-open'></i> <a href='folder/" . $option['value']['sectionId'] . "/" . $option['value']['id'] . "/'> {$description}</a></td>"; $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-sfolder fa-pad-right-3 fa-folder-open'></i> {$description}</td>"; } else { # last? if (!empty($children[$option['value']['id']])) { $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-gray fa-pad-right-3 fa-folder-open-o'></i><a href='subnets/" . $option['value']['sectionId'] . "/" . $option['value']['id'] . "/'> " . transform2long($option['value']['subnet']) . "/" . $option['value']['mask'] . "</a></td>"; $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-gray fa-pad-right-3 fa-folder-open-o'></i> {$description}</td>"; } else { $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-gray fa-pad-right-3 fa-angle-right'></i><a href='subnets/" . $option['value']['sectionId'] . "/" . $option['value']['id'] . "/'> " . transform2long($option['value']['subnet']) . "/" . $option['value']['mask'] . "</a></td>"; $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-gray fa-pad-right-3 fa-angle-right'></i> {$description}</td>"; } } } else { # is folder? if ($option['value']['isFolder'] == 1) { # last? $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-gray fa-pad-right-3 fa-folder-open'></i> <a href='folder/" . $option['value']['sectionId'] . "/" . $option['value']['id'] . "/'> {$description}</a></td>"; $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-gray fa-pad-right-3 fa-folder-open'></i> {$description}</td>"; } else { # last? if (!empty($children[$option['value']['id']])) { $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-gray fa-pad-right-3 fa-folder-open-o'></i> <a href='subnets/" . $option['value']['sectionId'] . "/" . $option['value']['id'] . "/'> " . transform2long($option['value']['subnet']) . "/" . $option['value']['mask'] . "</a></td>"; $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-gray fa-pad-right-3 fa-folder-open-o'></i> {$description}</td>"; } else { $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-gray fa-pad-right-3 fa-angle-right'></i> <a href='subnets/" . $option['value']['sectionId'] . "/" . $option['value']['id'] . "/'> " . transform2long($option['value']['subnet']) . "/" . $option['value']['mask'] . "</a></td>"; $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-gray fa-pad-right-3 fa-angle-right'></i> {$description}</td>"; } } } $html[] = "\t<td>{$vlan}</td>"; #vrf if ($vrf == "1") { $html[] = "\t<td class='hidden-xs hidden-sm'>{$vrfText}</td>"; } $html[] = "\t<td class='hidden-xs hidden-sm'>{$requests}</td>"; $html[] = "\t<td class='hidden-xs hidden-sm'>{$pCheck}</td>"; # custom if (sizeof($custom) > 0) { foreach ($custom as $field) { $html[] = "\t<td class='hidden-xs hidden-sm'>" . $option['value'][$field['name']] . "</td>"; } } if ($actions) { $html[] = "\t<td class='actions' style='padding:0px;'>"; $html[] = "\t<div class='btn-group'>"; if ($option['value']['isFolder'] == 1) { $html[] = "\t\t<button class='btn btn-xs btn-default add_folder' data-action='edit' data-subnetid='" . $option['value']['id'] . "' data-sectionid='" . $option['value']['sectionId'] . "'><i class='fa fa-gray fa-pencil'></i></button>"; $html[] = "\t\t<button class='btn btn-xs btn-default showSubnetPerm' data-action='show' data-subnetid='" . $option['value']['id'] . "' data-sectionid='" . $option['value']['sectionId'] . "'><i class='fa fa-gray fa-tasks'></i></button>"; $html[] = "\t\t<button class='btn btn-xs btn-default add_folder' data-action='delete' data-subnetid='" . $option['value']['id'] . "' data-sectionid='" . $option['value']['sectionId'] . "'><i class='fa fa-gray fa-times'></i></button>"; } else { $html[] = "\t\t<button class='btn btn-xs btn-default editSubnet' data-action='edit' data-subnetid='" . $option['value']['id'] . "' data-sectionid='" . $option['value']['sectionId'] . "'><i class='fa fa-gray fa-pencil'></i></button>"; $html[] = "\t\t<button class='btn btn-xs btn-default showSubnetPerm' data-action='show' data-subnetid='" . $option['value']['id'] . "' data-sectionid='" . $option['value']['sectionId'] . "'><i class='fa fa-gray fa-tasks'></i></button>"; $html[] = "\t\t<button class='btn btn-xs btn-default editSubnet' data-action='delete' data-subnetid='" . $option['value']['id'] . "' data-sectionid='" . $option['value']['sectionId'] . "'><i class='fa fa-gray fa-times'></i></button>"; } $html[] = "\t</div>"; $html[] = "\t</td>"; } $html[] = "</tr>"; } } if ($option === false) { $parent = array_pop($parent_stack); } elseif (!empty($children[$option['value']['id']])) { array_push($parent_stack, $option['value']['masterSubnetId']); $parent = $option['value']['id']; } else { } } return implode("\n", $html); }
if (!($overlap = verifySubnetNesting($subnetOld['masterSubnetId'], transform2long($subnetOld['subnet']) . "/" . $_POST['newMask'])) && $subnetOld['masterSubnetId'] != 0) { # get master details $master = getSubnetDetailsById($subnetOld['masterSubnetId']); $master = Transform2long($master['subnet']) . "/" . $master['mask'] . " - " . $master['description']; $errors[] = _("New subnet not in master subnet") . "!<br>({$master})"; } } /* * If subnet has slaves make sure all slaves are still inside! */ if ($section['strictMode'] == 1) { $slaves = getAllSlaveSubnetsBySubnetId($_POST['subnetId']); if (sizeof($slaves) > 0) { foreach ($slaves as $slave) { if (!isSubnetInsideSubnet(transform2long($slave['subnet']) . "/" . $slave['mask'], transform2long($subnetOld['subnet']) . "/" . $_POST['newMask'])) { $errors[] = _("Nested subnet out of new subnet") . "!<br>(" . transform2long($slave['subnet']) . "/{$slave['mask']} - {$slave['description']})"; } } } } /* if no errors edit! */ if (sizeof($errors) > 0) { print "<div class='alert alert-danger'><ul>"; foreach ($errors as $error) { print "<li>{$error}</li>"; } print "</ul></div>"; } else { # failed if (!modifySubnetMask($_POST['subnetId'], $_POST['newMask'])) { print '<div class="alert alert-danger">' . _('Error resizing subnet') . '!</div>';
<!-- content --> <div class="pContent"> <form id="subnetSplit"> <table class="table table-noborder table-condensed"> <!-- subnet --> <tr> <td class="middle"><?php print _('Subnet'); ?> </td> <td><?php print transform2long($subnet['subnet']) . "/{$subnet['mask']} ({$subnet['description']})"; ?> </td> </tr> <!-- number of new subnets --> <tr> <td class="middle"><?php print _('Number of subnets'); ?> </td> <td style="vertical-align:middle"> <select name="number" class="form-control input-sm input-w-auto"> <?php foreach ($opts as $line) { print "<option value='{$line['number']}'>{$line['number']}x /{$line['mask']} subnet ({$line['number']}x {$line['max']} hosts)</option>";
<form class="editipaddress" role="form" name="editipaddress"> <!-- edit IP address table --> <table id="editipaddress" class="table table-noborder table-condensed"> <!-- IP address --> <tr> <td><?php print _('IP address'); ?> *</td> <td> <div class="input-group"> <input type="text" name="ip_addr" class="ip_addr form-control input-sm" value="<?php print $details['ip_addr']; if (is_numeric($_POST['stopIP']) > 0) { print "-" . transform2long($_POST['stopIP']); } ?> " placeholder="<?php print _('IP address'); ?> "> <span class="input-group-addon"> <i class="fa fa-gray fa-info" rel="tooltip" data-html='true' data-placement="left" title="<?php print _('You can add,edit or delete multiple IP addresses<br>by specifying IP range (e.g. 10.10.0.0-10.10.0.25)'); ?> "></i> </span> </div> <input type="hidden" name="action" value="<?php
$class = $ipVisual[$m]['state']; $id = (int) $ipVisual[$m]['id']; $action = 'all-edit'; # tooltip $title = transform2long($ipVisual[$m]['ip_addr']); if (strlen($ipVisual[$m]['dns_name']) > 0) { $title .= "<br>" . $ipVisual[$m]['dns_name']; } if (strlen($ipVisual[$m]['desc']) > 0) { $title .= "<br>" . $ipVisual[$m]['desc']; } } else { # print add $class = 9; $id = $m; $action = 'all-add'; $title = ""; } # permissions $permission = checkSubnetPermission($subnetId); # print box if ($permission > 1) { print "<span class='ip-{$class} modIPaddr' data-action='{$action}' rel='tooltip' title='{$title}' data-position='top' data-html='true' data-subnetId='" . $subnetId . "' data-id='{$id}'>." . substr(strrchr(transform2long($m), "."), 1) . "</span>"; } else { print "<span class='ip-{$class} ' data-action='{$action}' data-subnetId='" . $subnetId . "' data-id='{$id}'>." . substr(strrchr(transform2long($m), "."), 1) . "</span>"; } } print "</div>"; print "<div style='clear:both;padding-bottom:20px;'></div>"; # clear float }
# only print if some hosts exist if (sizeof($subnetHost) > 0) { ?> <script type="text/javascript"> $(function () { var data = [ <?php if (sizeof($subnetHost) > 0) { $m = 0; foreach ($subnetHost as $subnet) { if ($m < $slimit) { # verify user access $sp = checkSubnetPermission($subnet['id']); if ($sp != "0") { $subnet['subnet'] = transform2long($subnet['subnet']); $subnet['descriptionLong'] = $subnet['description']; # odd/even if more than 5 items if (sizeof($subnetHost) > 5) { if ($m & 1) { print "['|<br>" . addslashes($subnet[description]) . "', {$subnet['usage']}, '" . addslashes($subnet[descriptionLong]) . " ({$subnet['subnet']}/{$subnet['mask']})'],"; } else { print "['" . addslashes($subnet[description]) . "', {$subnet['usage']}, '" . addslashes($subnet[descriptionLong]) . " ({$subnet['subnet']}/{$subnet['mask']})'],"; } } else { print "['" . addslashes($subnet[description]) . "', {$subnet['usage']}, '" . addslashes($subnet[descriptionLong]) . " ({$subnet['subnet']}/{$subnet['mask']})'],"; } # next $m++; } }
} } // first add to IP table foreach ($addresses as $k => $ip) { // try to resolve $ip['dns_name'] = ResolveDnsName($ip['ip_addr']); if ($ip['dns_name']['class'] == "resolved") { $ip['dns_name'] = $ip['dns_name']['name']; $addresses[$k]['dns_name'] = $ip['dns_name']; } else { $ip['dns_name'] = ""; $addresses[$k]['dns_name'] = _("unresolved"); } // insert if (!insert_discovered_ip($ip)) { print "Cannot add discovered IP " . transform2long($ip['ip_addr']) . "\n"; } } // all done, mail discovered? if (sizeof($addresses) > 0 && $email) { //send text array, cron will do that by default if you don't redirect output > /dev/null 2>&1 if ($emailText) { print_r($stateDiff); } else { $mail['from'] = "{$settings['siteTitle']} <ipam@{$settings['siteDomain']}>"; $mail['headers'] = 'From: ' . $mail['from'] . "\r\n"; $mail['headers'] .= "Content-type: text/html; charset=utf8" . "\r\n"; $mail['headers'] .= 'X-Mailer: PHP/' . phpversion() . "\r\n"; //subject $mail['subject'] = "phpIPAM new addresses detected " . date("Y-m-d H:i:s"); //header
print "\t<th class='small hidden-xs hidden-sm'>" . _('Requests') . "</th>"; print " <th class='actions'></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) { print "<tr>"; print "\t<td class='small description'><a href='subnets/{$_REQUEST['section']}/{$slave['id']}/'>{$slave['description']}</a></td>"; print "\t<td><a href='subnets/{$_REQUEST['section']}/{$slave['id']}/'>" . transform2long($slave['subnet']) . "/{$slave['mask']}</a></td>"; # host check if ($slave['pingSubnet'] == 1) { print '<td class="allowRequests small hidden-xs hidden-sm">' . _('enabled') . '</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) { $ipCount = sizeof(getIpAddressesBySubnetIdSlavesSort($slave['id'])); } else { $ipCount = countIpAddressesBySubnetId($slave['id']); } //ip count - direct subnet
$change = 'style="border-top:1px dashed white"'; $vlanOld = $vlanNew; } print '<tr class="link vlanSearch" ' . $change . ' sectionId="' . $section['id'] . '" subnetId="' . $subnet['id'] . '" link="' . $section['name'] . '|' . $subnet['id'] . '">' . "\n"; /* print first 3 only if change happened! */ if (strlen($change) > 0) { print ' <td><dd>' . $vlan['name'] . '</dd></td>' . "\n"; print ' <td><dd>' . $vlan['number'] . '</dd></td>' . "\n"; print ' <td><dd>' . $vlan['description'] . '</dd></td>' . "\n"; } else { print '<td></td>'; print '<td></td>'; print '<td></td>'; } if ($subnet['id'] != null) { # subnet print ' <td>' . transform2long($subnet['subnet']) . '/' . $subnet['mask'] . '</td>' . "\n"; # section print ' <td>' . $section['name'] . '</td>' . "\n"; } else { print '<td>---</td>' . "\n"; print '<td>---</td>' . "\n"; } print '</tr>' . "\n"; } } } } ?> </table>
} //admin lock if ($line['adminLock'] == 1) { $line['adminLock'] = 'yes'; } else { $line['adminLock'] = ''; } //allowRequests if ($line['allowRequest'] == 1) { $line['allowRequest'] = 'yes'; } else { $line['allowRequest'] = ''; } //print subnet $worksheet->write($lineCount, 0, $section['name'], $format_left); $worksheet->write($lineCount, 1, transform2long($line['subnet'])); $worksheet->write($lineCount, 2, $line['mask']); $worksheet->write($lineCount, 3, $line['description']); $worksheet->write($lineCount, 4, $line['masterSubnetId']); $worksheet->write($lineCount, 5, $line['VLAN']); $worksheet->write($lineCount, 6, $line['allowRequests']); //new line $lineCount++; } //top border line at bottom of IP addresses $worksheet->write($lineCount, 0, "", $format_top); $worksheet->write($lineCount, 1, "", $format_top); $worksheet->write($lineCount, 2, "", $format_top); $worksheet->write($lineCount, 3, "", $format_top); $worksheet->write($lineCount, 4, "", $format_top); $worksheet->write($lineCount, 5, "", $format_top);
case "subnet": if ($l['isFolder'] == 1) { $l['ctype'] = "Folder"; } else { $l['ctype'] = "Subnet"; } break; case "section": $l['ctype'] = "Section"; break; } print "<tr>"; print "\t<td>{$l['real_name']}</td>"; print "\t<td>{$l['ctype']}</td>"; # subnet, section or ip address if ($l['ctype'] == "IP address") { print "\t<td><a href='" . create_link("subnets", $l['sectionId'], $l['subnetId'], "ipdetails", $l['tid']) . "'>" . transform2long($l['ip_addr']) . "</a></td>"; } elseif ($l['ctype'] == "Subnet") { print "\t<td><a href='" . create_link("subnets", $l['sectionId'], $l['tid']) . "'>" . transform2long($l['ip_addr']) . "/{$l['mask']}</a></td>"; } elseif ($l['ctype'] == "Folder") { print "\t<td><a href='" . create_link("folder", $l['sectionId'], $l['tid']) . "'>{$l['sDescription']}</a></td>"; } print "\t<td>" . _("{$l['caction']}") . "</td>"; print "\t<td>" . _("{$l['cresult']}") . "</td>"; print "\t<td>{$l['cdate']}</td>"; print "\t<td>{$l['cdiff']}</td>"; print "</tr>"; } } print "</table>"; }
/** * 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; } }
print "\t<th class='hidden-xs hidden-sm'>" . _('Used') . "</th>"; print "\t<th style='width:5px;'></th>"; print "</tr>"; # logs foreach ($favs as $f) { # if subnet already removed (doesnt exist) dont print it! if (sizeof($f) > 0) { print "<tr class='favSubnet-{$f['subnetId']}'>"; if ($f['isFolder'] == 1) { print "\t<td><a href='" . create_link("folder", $f['sectionId'], $f['subnetId']) . "'><i class='fa fa-folder fa-sfolder'></i> {$f['description']}</a></td>"; } else { //master? if (sizeof(getAllSlaveSubnetsBySubnetId($f['subnetId'])) > 0) { print "\t<td><a href='" . create_link("subnets", $f['sectionId'], $f['subnetId']) . "'><i class='fa fa-sfolder fa-folder-o'></i>" . transform2long($f['subnet']) . "/{$f['mask']}</a></td>"; } else { print "\t<td><a href='" . create_link("subnets", $f['sectionId'], $f['subnetId']) . "'><i class='fa fa-sfolder fa-sitemap' ></i> " . transform2long($f['subnet']) . "/{$f['mask']}</a></td>"; } } print "\t<td>{$f['description']}</td>"; print "\t<td><a href='" . create_link("folder", $f['sectionId']) . "'>{$f['section']}</a></td>"; if (strlen($f['vlanId']) > 0) { # get vlan info $vlan = getVlanById($f['vlanId']); print "\t<td class='hidden-xs hidden-sm'>{$vlan['number']}</td>"; } else { print "\t<td class='hidden-xs hidden-sm'>/</td>"; } # used # masterSubnet if ($f['masterSubnetId'] == 0 || empty($f['masterSubnetId'])) { $masterSubnet = true;
$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='" . create_link("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='" . create_link("subnets", $subnet['sectionId'], $subnet['masterSubnetId']) . "'>" . transform2long($master['subnet']) . "/{$master['mask']} ({$master['description']})</a></td>"; } } # details if (!$masterSubnet || !subnetContainsSlaves($subnet['id'])) { $ipCount = countIpAddressesBySubnetId($subnet['id']); $calculate = calculateSubnetDetails(gmp_strval($ipCount), $subnet['mask'], $subnet['subnet']); print ' <td class="used hidden-xs hidden-sm">' . reformatNumber($calculate['used']) . '/' . reformatNumber($calculate['maxhosts']) . '</td>' . "\n"; print ' <td class="free hidden-xs hidden-sm">' . reformatNumber($calculate['freehosts_percent']) . ' %</td>'; } else { print '<td class="hidden-xs hidden-sm"></td>' . "\n"; print '<td class="hidden-xs hidden-sm"></td>' . "\n"; } # allow requests if ($subnet['allowRequests'] == 1) { print '<td class="allowRequests requests hidden-xs hidden-sm">' . _('enabled') . '</td>';
// alive $m = 0; foreach ($alive as $ip) { //resolve? if ($scanDNSresolve) { $dns = gethostbyaddr(transform2long($ip)); } else { $dns = "test"; } print "<tr class='result{$m}'>"; //ip print "<td>" . transform2long($ip) . "</td>"; //description print "<td>"; print "\t<input type='text' name='description{$m}'>"; print "\t<input type='hidden' name='ip{$m}' value=" . transform2long($ip) . ">"; print "</td>"; //hostname print "<td>"; print "\t<input type='text' name='dns_name{$m}' value='" . @$dns . "'>"; print "</td>"; //remove button print "<td><a href='' class='btn btn-mini btn-danger resultRemove' data-target='result{$m}'><i class='icon-white icon-remove'></i></a></td>"; print "</tr>"; $m++; } //result print "<tr>"; print "\t<td colspan='4'>"; print "<div id='subnetScanAddResult'></div>"; print "\t</td>";
exit; } # Get the subnetid of the provided subnet $query = $data->prepare("select `id` from `subnets` where `subnet` = ?"); $query->bind_param('s', $snet); $query->execute(); $query->bind_result($subnetId); $query->fetch(); # Exit if subnet is not in IPAM if (empty($subnetId)) { echo "Error: subnet not in IPAM\n"; mysqli_close($data); exit; } # Get the first free IP in specified subnet $first = getFirstAvailableIPAddress($subnetId); # Convert IP to long $firstfree = transform2long($first); # Build query to insert new host in DB $query = <<<EOQ INSERT INTO `ipaddresses` (`subnetId`,`description`,`ip_addr`,`dns_name`,`mac`,`owner`,`state`, `switch`,`port`,`note`,`excludePing`) VALUES ('{$subnetId}','{$desc}','{$first}','{$host}','','{$owner}','1','','','','0'); EOQ; try { $id = $database->executeQuery($query, true); print $firstfree; } catch (Exception $e) { print "Error: There was a problem adding {$host} to IPAM, please contact the administrator.\n"; return false; }
<div class="pContent editIPAddress"> <form name="requestIP" id="requestIP"> <table id="requestIP" class="table table-striped table-condensed"> <tr> <td><?php print _('IP address'); ?> *</td> <td> <?php require_once '../../functions/functions.php'; # get first IP address $first = transform2long(getFirstAvailableIPAddress($_POST['subnetId'])); # get subnet details $subnet = getSubnetDetailsById($_POST['subnetId']); ?> <input type="text" name="ip_addr" class="ip_addr form-control" size="30" value="<?php print $first; ?> "> <input type="hidden" name="subnetId" value="<?php print $subnet['id']; ?> "> </td> </tr>
print "</tr>"; } # IP addresses foreach ($ipaddresses as $ip) { # check permission $permission = checkSubnetPermission($ip['subnetId']); if ($permission != "0") { # get subnet details for belonging IP $subnet = getSubnetDetails($ip['subnetId']); # get section details $section = getSectionDetailsById($subnet['sectionId']); # print print "<tr>"; print "\t<td class='ip'><a href='" . create_link("subnets", $section['id'], $subnet['id'], "ipaddr", $ip['id']) . "'>" . transform2long($ip['ip_addr']) . "</a></td>"; print "\t<td class='port'>{$ip['port']}</td>"; print "\t<td class='subnet'><a href='" . create_link("subnets", $section['id'], $subnet['id']) . "'>" . transform2long($subnet['subnet']) . "/{$subnet['mask']}</a> <span class='text-muted'>({$subnet['description']})</span></td>"; print "\t<td class='description'>{$ip['description']}</td>"; # print info button for hover print "<td class='note'>"; if (!empty($ip['note'])) { $ip['note'] = str_replace("\n", "<br>", $ip['note']); print "\t<i class='fa fa-comment-o' rel='tooltip' title='{$ip['note']}'></i>"; } print "</td>"; print "\t<td class='dns hidden-xs'>{$ip['dns_name']}</td>"; print "\t<td class='owner hidden-xs hidden-sm'>{$ip['owner']}</td>"; print "</tr>"; } } print "</tr>"; print "</tbody>";
$permission = checkSubnetPermission($vlan['subnetId']); if ($permission != "0") { print "<tr class='{$change}'>"; /* print first 3 only if change happened! */ if ($change == "change") { print ' <td>' . $vlan['number'] . '</td>' . "\n"; print ' <td>' . $vlan['name'] . '</td>' . "\n"; print ' <td>' . $vlan['description'] . '</td>' . "\n"; } else { print '<td></td>'; print '<td></td>'; print '<td></td>'; } if ($vlan['subnetId'] != null) { # subnet print " <td><a href='subnets/{$section['id']}/{$vlan['subnetId']}/'>" . transform2long($vlan['subnet']) . "/{$vlan['mask']}</a></td>"; # section print " <td><a href='subnets/{$section['id']}/'>{$section['name']}</a></td>"; # details if (!$masterSubnet || !subnetContainsSlaves($vlan['subnetId'])) { $ipCount = countIpAddressesBySubnetId($vlan['subnetId']); $calculate = calculateSubnetDetails(gmp_strval($ipCount), $vlan['mask'], $vlan['subnet']); print ' <td class="used hidden-xs hidden-sm">' . reformatNumber($calculate['used']) . '/' . reformatNumber($calculate['maxhosts']) . '</td>' . "\n"; print ' <td class="free hidden-xs hidden-sm">' . reformatNumber($calculate['freehosts_percent']) . ' %</td>'; } else { print ' <td class="used hidden-xs hidden-sm">---</td>' . "\n"; print ' <td class="free hidden-xs hidden-sm">---</td>' . "\n"; } } else { print '<td>---</td>' . "\n"; print '<td>---</td>' . "\n";
# create new subnets and change subnetId for recalculated hosts $m = 0; foreach ($newsubnets as $subnet) { # set action and subnet - must be in long format $subnet['action'] = "add"; $subnet['description'] = $subnet['description'] . "/{$m}"; $subnet['subnet'] = transform2long($subnet['subnet']) . "/" . $subnet['mask']; # create subnet and save last id $lastId = modifySubnetDetails($subnet, true); # true returns last id # save all to array $lastIdArray[] = $lastId; # replace ID in IP addresses foreach ($ipaddresses as $ip) { if ($ip['subnetId'] == $m) { $ip['ip_addr'] = transform2long($ip['ip_addr']); if (!moveIPAddress($ip['id'], $lastId)) { $errors[] = $ip['ip_addr']; } } } # next $m++; } # if all good remove old subnet, else remove created subnets if (isset($errors) || sizeof($errors) > 0) { print "<div class='alert alert-danger'>" . _('Wrong IP addresses (subnet or broadcast)') . "<ul>"; foreach ($errors as $error) { print "<li>{$error}</li>"; } print "</ul></div>";
require_once '../../functions/functions.php'; /* format posted values! */ $tmp = explode("|", $_POST['direction']); $sort['field'] = $tmp[0]; $sort['direction'] = $tmp[1]; if ($sort['direction'] == "asc") { $sort['directionNext'] = "desc"; } else { $sort['directionNext'] = "asc"; } /** * Parse IP addresses * * We provide subnet and mask, all other is calculated based on it (subnet, broadcast,...) */ $SubnetParsed = parseIpAddress(transform2long($SubnetDetails['subnet']), $SubnetDetails['mask']); } /* verify that user is authenticated! */ isUserAuthenticated(); /* get all selected fields for IP print */ $setFields = getSelectedIPaddrFields(); /* 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;
} } } ?> </select> </td> </tr> <!-- IP address --> <tr> <th><?php print _('IP address'); ?> </th> <td> <input type="text" name="ip_addr" class="ip_addr form-control input-sm" value="<?php print transform2long(getFirstAvailableIPAddress($request['subnetId'])); ?> " size="30"> <input type="hidden" name="requestId" value="<?php print $request['id']; ?> "> <input type="hidden" name="requester" value="<?php print $request['requester']; ?> "> </td> </tr> <!-- description --> <tr> <th><?php
$subnets = getAllSubnetsForExport(); //get hosts foreach ($subnets as $s) { $ips = getIpAddressesBySubnetId($s['id']); if (sizeof($ips) > 0) { # create new array $res[] = "# {$s['s_description']} (" . transform2long($s['subnet']) . "/{$s['mask']}) - " . _('Section') . " {$s['se_description']}"; foreach ($ips as $ip) { # get lenth $diff = 17 - strlen(transform2long($ip['ip_addr'])); # ipv6 if ($diff < 0) { $diff = 3; } # write host if dns name is set! if (strlen($ip['dns_name']) > 0) { $res[] = transform2long($ip['ip_addr']) . str_repeat(" ", $diff) . "{$ip['dns_name']}"; } } # break $res[] = ""; } } /* join */ $content = implode("\n", $res); /* headers */ header("Cache-Control: private"); header("Content-Description: File Transfer"); header('Content-type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . $filename . '"'); print $content;
/** * function to return multidimensional array */ public function toArray($obj, $format) { //if object create array if (is_object($obj)) { $obj = (array) $obj; } if (is_array($obj)) { $arr = array(); foreach ($obj as $key => $val) { // proper format if ($key == "subnet" && $format == "ip") { $val = transform2long($val); } // output format $arr[$key] = $this->toArray($val, $format); } } else { $arr = $obj; } //return an array of items return $arr; }
$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"; print '<td class="hidden-xs hidden-sm"></td>' . "\n"; } # allow requests if ($subnet['allowRequests'] == 1) { print '<td class="allowRequests requests hidden-xs hidden-sm">' . _('enabled') . '</td>';
$allSum = 0; # for free space check $slaveSize = sizeof($subnets); $m = 0; foreach ($subnets as $slave) { # reformat empty VLAN if (empty($slave['VLAN']) || $slave['VLAN'] == 0 || strlen($slave['VLAN']) == 0) { $slave['VLAN'] = "/"; } # get VLAN details $slave['VLAN'] = subnetGetVLANdetailsById($slave['vlanId']); $slave['VLAN'] = $slave['VLAN']['number']; print "<tr>"; print "\t<td class='small'>{$slave['VLAN']}</td>"; print "\t<td class='small description'><a href='" . create_link("subnets", $section['id'], $slave['id']) . "'>{$slave['description']}</a></td>"; print "\t<td><a href='" . create_link("subnets", $section['id'], $slave['id']) . "'>" . transform2long($slave['subnet']) . "/{$slave['mask']}</a></td>"; # count IP addresses $hasSlaves = getAllSlaveSubnetsBySubnetId($slave['id']); # slaves details are provided with ipaddressprintslaves script if (sizeof($hasSlaves) > 0) { $ipCount = sizeof(getIpAddressesBySubnetIdSlavesSort($slave['id'])); } else { $ipCount = countIpAddressesBySubnetId($slave['id']); } //ip count - direct subnet $calculate = calculateSubnetDetails(gmp_strval($ipCount), $slave['mask'], $slave['subnet']); print ' <td class="small hidden-xs hidden-sm">' . $calculate['used'] . '/' . $calculate['maxhosts'] . '</td>' . "\n"; print ' <td class="small hidden-xs hidden-sm">' . $calculate['freehosts_percent'] . '</td>'; # add to sum if IPv4 if (IdentifyAddress($slave['subnet']) == "IPv4") { $usedSum = $usedSum + $calculate['used'];
/** * Search subnets */ function searchSubnets($searchterm, $searchTermEdited = "") { global $database; # get custom subnet fields $myFields = getCustomFields('subnets'); $custom = ''; if (sizeof($myFields) > 0) { /* set inserts for custom */ foreach ($myFields as $myField) { $custom .= ' or `' . $myField['name'] . '` like "%' . $searchterm . '%" '; } } /* set query */ if ($searchTermEdited['low'] == 0 && $searchTermEdited['high'] == 0) { $query[] = 'select * from `subnets` where `description` like "%' . $searchterm . '%" ' . $custom . ';'; } else { $query[] = 'select * from `subnets` where `description` like "%' . $searchterm . '%" or `subnet` between "' . $searchTermEdited['low'] . '" and "' . $searchTermEdited['high'] . '" ' . $custom . ';'; } /* search inside subnets even if IP does not exist! */ if ($searchTermEdited['low'] == $searchTermEdited['high']) { $allSubnets = fetchAllSubnets(); foreach ($allSubnets as $s) { // first verify address type $type = IdentifyAddress($s['subnet']); if ($type == "IPv4") { require_once 'PEAR/Net/IPv4.php'; $net = Net_IPv4::parseAddress(transform2long($s['subnet']) . '/' . $s['mask']); if ($searchTermEdited['low'] > transform2decimal($net->network) && $searchTermEdited['low'] < transform2decimal($net->broadcast)) { $query[] = "select * from `subnets` where `id` = {$s['id']}; \n"; } } } } /* execute each query */ foreach ($query as $q) { try { $search[] = $database->getArray($q); } catch (Exception $e) { $error = $e->getMessage(); } } /* filter results - remove blank */ $search = array_filter($search); /* die if errors */ if (isset($error)) { print "<div class='alert alert-danger'>" . _('Error') . ": {$error}</div>"; return false; } /* return result */ return $search; }
print "\t<th colspan='2'>" . _('Description') . "</th>"; print "\t<th>" . _('Hostname') . "</th>"; print "\t<th>" . _('Owner') . "</th>"; print "</tr>"; # IP addresses foreach ($ipaddresses as $ip) { # check permission $permission = checkSubnetPermission($ip['subnetId']); if ($permission != "0") { # get subnet details for belonging IP $subnet = getSubnetDetails($ip['subnetId']); # get section details $section = getSectionDetailsById($subnet['sectionId']); # print print "<tr>"; print "\t<td class='ip'>" . transform2long($ip['ip_addr']) . "/{$subnet['mask']}</td>"; print "\t<td class='port'>{$ip['port']}</td>"; print "\t<td class='subnet'><a href='/subnets/{$section['id']}/{$subnet['id']}/'>{$subnet['description']}</a></td>"; print "\t<td class='description'>{$ip['description']}</td>"; # print info button for hover print "<td class='note'>"; if (!empty($ip['note'])) { $ip['note'] = str_replace("\n", "<br>", $ip['note']); print "\t<i class='icon-gray icon-comment' rel='tooltip' title='{$ip['note']}'></i>"; } print "</td>"; print "\t<td class='dns'>{$ip['dns_name']}</td>"; print "\t<td class='owner'>{$ip['owner']}</td>"; print "</tr>"; } }