// save the last customer used // must set path else Netscape gets confused! setcookie("ipplanCustomer", "{$cust}", time() + 10000000, "/"); // check if user belongs to customer admin group $result = $ds->GetCustomerGrp($cust); // can only be one row - does not matter if nothing is // found as array search will return false $row = $result->FetchRow(); if (!in_array($row["admingrp"], $grps)) { myError($w, $p, my_("You may not delete an area for this customer as you are not a member of the customers admin group")); } if ($rangeindex > 0) { $result = $ds->GetRange($cust, $rangeindex); $row = $result->FetchRow(); $rangeip = inet_ntoa($row["rangeaddr"]); $rangesize = $row["rangesize"]; $ds->DbfTransactionStart(); $result =& $ds->ds->Execute("DELETE FROM netrange\n WHERE rangeindex={$rangeindex}") and $ds->AuditLog(array("event" => 162, "action" => "delete range", "baseaddr" => $rangeip, "user" => getAuthUsername(), "size" => $rangesize, "cust" => $cust)); if ($result) { $ds->DbfTransactionEnd(); Header("Location: " . location_uri("modifyarearange.php?cust={$cust}")); exit; //insert($w,text(my_("Range deleted"))); } else { insert($w, text(my_("Range could not be deleted"))); } } else { insert($w, text(my_("Range index is invalid"))); } } printhtml($p);
} // first run? $ds->expr = $expr; $ds->size = $size; $result = $ds->FetchBase($cust, $areaindex, $rangeindex); if (!$result) { myError($w, $p, $ds->errstr); } // for "all" customer, $cust may have changed in class $cust = $ds->cust; // if searching for address only and not all customer and we found some data, then go directly to // modifyipform page if ($searchin and $cust > 0) { // does subnet exist? is jump set? then jump to ip record, else fall through and display subnet if ($jump and $row = $result->FetchRow()) { header("Location: " . location_uri("modifyipform.php?ip=" . inet_aton($ipaddr) . "&baseindex=" . $row["baseindex"])); exit; } } if ($areaindex == -1) { insert($w, heading(3, sprintf(my_("Search for IP subnets not part of a range for customer '%s'"), $ds->custdescrip))); } elseif ($areaindex and !$rangeindex) { insert($w, heading(3, sprintf(my_("Search for IP subnets between multiple ranges for customer '%s'"), $ds->custdescrip))); } else { insert($w, heading(3, sprintf(my_("Search for IP subnets between %s and %s %s for customer '%s'"), $ds->start, $ds->end, $ds->site, $ds->custdescrip))); } if ($ipaddr) { insert($w, textb(my_("IP address filter: "))); insert($w, textbr($ipaddr)); } if ($descrip) {
$result =& $ds->ds->Execute("UPDATE baseadd\n SET info=" . $ds->ds->qstr($info) . "\n WHERE baseindex={$baseindex}"); // this generates a "duplicate key" error if no update // should be OK under normal circumstances, but generates error under // debug mode turned on } else { if (!empty($info)) { $result =& $ds->ds->Execute("INSERT INTO baseadd\n (info, baseindex)\n VALUES\n (" . $ds->ds->qstr($info) . ", {$baseindex})"); } } } // end of modify subnet if (!$err and !$formerror and $result) { $ds->DbfTransactionEnd(); insert($w, text(my_("Subnet modified"))); // go back to modifybase table display header("Location: " . location_uri("modifybase.php?baseindex=" . $baseindex . "&areaindex=" . $areaindex . "&rangeindex=" . $rangeindex . "&cust=" . $cust . "&descrip=" . urlencode($search) . "&ipaddr=" . urlencode($ipaddr))); } else { $formerror .= my_("Subnet could not be modified") . "\n"; } } } if (!$_POST || $formerror) { myError($w, $p, $formerror, FALSE); $result = $ds->GetBaseFromIndex($baseindex); if (!($row = $result->FetchRow())) { myError($w, $p, my_("Subnet cannot be found!")); } $size = $row["subnetsize"]; $baseaddr = $row["baseaddr"]; $baseip = inet_ntoa($row["baseaddr"]); $dhcp = $row["baseopt"] & 1;
insert($f, input_text(array("name" => "num", "value" => "1", "size" => "3", "maxlength" => "3"))); insert($f, textbrbr(my_("Description"))); insert($f, span(my_("Leave blank to automatically describe"), array("class" => "textSmall"))); insert($f, input_text(array("name" => "descrip", "size" => "80", "maxlength" => "80"))); insert($f, textbrbr(my_("Subnet size/mask"))); // size maybe set from router script!!! insert($f, selectbox(array("1" => "255.255.255.255/32 - host", "2" => "255.255.255.254/31 - 2 hosts", "4" => "255.255.255.252/30 - 4 hosts", "8" => "255.255.255.248/29 - 8 hosts", "16" => "255.255.255.240/28 - 16 hosts", "32" => "255.255.255.224/27 - 32 hosts", "64" => "255.255.255.192/26 - 64 hosts", "128" => "255.255.255.128/25 - 128 hosts", "256" => "255.255.255.0/24 - 256 hosts (class C)", "512" => "255.255.254.0/23 - 512 hosts", "1024" => "255.255.252.0/22 - 1k hosts", "2048" => "255.255.248.0/21 - 2k hosts", "4096" => "255.255.240.0/20 - 4k hosts", "8192" => "255.255.224.0/19 - 8k hosts", "16384" => "255.255.192.0/18 - 16k hosts", "32768" => "255.255.128.0/17 - 32k hosts", "65536" => "255.255.0.0/16 - 64k hosts (class B)", "131072" => "255.254.0.0/15 - 128k hosts", "262144" => "255.252.0.0/14 - 256k hosts"), array("name" => "size"), $size)); insert($f, textbr()); //if (NMAP != "" and ini_get("safe_mode") == 0) { if (NMAP != "") { insert($f, checkbox(array("name" => "addnmapinfo", "value" => "1"), my_("Add active hosts using NMAP"))); insert($f, text(" | ")); } insert($f, checkbox(array("name" => "addhostinfo", "value" => "1"), my_("Add host names from DNS"))); insert($f, text(" | ")); insert($f, checkbox(array("name" => "dhcp", "value" => "1", "onclick" => "location.href='" . location_uri("createsubnetform.php?cust={$cust}&size={$size}&ipplanGroup={$ipplanGroup}&dhcp=1" . "'")), my_("Is this a DHCP subnet?"), $dhcp)); if ($dhcp) { insert($f, block("<p>")); insert($f, textb(my_("Creating a new DHCP subnet"))); } insert($f, textbr()); // if called from findfree, save find results if (isset($_SERVER['HTTP_REFERER']) and stristr($_SERVER['HTTP_REFERER'], "findfree.php")) { insert($f, hidden(array("name" => "findfree", "value" => base64_encode($_SERVER['HTTP_REFERER'])))); } // Requires new default template: basetemplate.xml // Start of template support [FE] if ($dhcp) { // use dhcp template (for additional subnet information) $template = new IPplanIPTemplate("basetemplate-dhcp", $cust); } else {
insert($w, textbr()); } else { myError($w, $p, sprintf(my_("Subnet %s could not be created"), inet_ntoa($base))); } } } // end of for loop for multiple subnet creation // add link if script was called from findfree // only if all subnets created without error or warning if (!$warn and $findfree) { // $findfree contains HTTP_REFERER which is a full URI already - OK header("Location: " . base64_decode($findfree)); exit; } if (!$warn and $num == 1) { header("Location: " . location_uri("displaybase.php?cust={$cust}&ipaddr={$ipaddr}")); exit; } printhtml($p); // $base=baseaddr of subnet, $id=baseindex function ProcessNmap($ds, $base, $id, $size) { global $addhostinfo; $resarr = array(); if ($addhostinfo) { $command = NMAP . " -sP " . escapeshellarg(inet_ntoa($base) . "/" . inet_bits($size)) . " -oX -"; } else { $command = NMAP . " -n -sP " . escapeshellarg(inet_ntoa($base) . "/" . inet_bits($size)) . " -oX -"; } exec($command, $resarr, $retval); // did NMAP fail due to safe mode or other error?