} } } // End of template support for base // Changed - End [FE] $ds->AuditLog(sprintf(my_("User %s modified subnet details %s size %u customer cust %u"), getAuthUsername(), inet_ntoa($base), $size, $cust)); } else { // if not duplicate, fall through to here if ($size > 1) { if (TestBaseAddr(inet_aton3($ipaddr), $size)) { insert($w, text(my_("Invalid base address!"))); break; } } // use the first group user belongs to create subnet if ($baseindex = $ds->CreateSubnet($base, $size, $descrip, $cust, 0, $admingrp)) { $ds->AuditLog(sprintf(my_("User %s created new subnet %s size %u cust %u"), getAuthUsername(), inet_ntoa($base), $size, $cust)); // Changed - Begin [FE] // Start of template support for base if (!empty($info)) { // First, try to insert. $result =& $ds->ds->Execute("INSERT INTO baseadd\n (info, baseindex)\n VALUES\n (" . $ds->ds->qstr($info) . ",\n {$baseindex})"); // Second, try to update. if ($result == FALSE) { $result =& $ds->ds->Execute("UPDATE baseadd\n SET info=" . $ds->ds->qstr($info) . " \n WHERE baseindex={$baseindex}"); if ($result == FALSE) { insert($w, block("<b>" . my_("Error inserting/updating info.") . "</b>")); } } } // End of template support for base
insert($c, text($row["custdescrip"])); } while ($row = $result->FetchRow()); setdefault("cell", ""); insert($w, block("<p>")); } // 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 create a subnet for this customer as you are not a member of the customers admin group")); } $ds->DbfTransactionStart(); // use the first group user belongs to create subnet if ($id = $ds->CreateSubnet($base, $size, $descrip, $cust, $dhcp, $admingrp)) { $ds->AuditLog(array("event" => 170, "action" => "create subnet", "descrip" => $descrip, "user" => getAuthUsername(), "baseaddr" => inet_ntoa($base), "size" => $size, "cust" => $cust)); insert($w, text(sprintf(my_("Subnet %s created"), inet_ntoa($base)))); // fill new subnet with nmap if (NMAP != "" and $addnmapinfo and $size >= 4 and $size <= 1024) { if (ProcessNmap($ds, $base, $id, $size)) { insert($w, textbr()); myError($w, $p, my_("NMAP data not in XML format or XML not available"), FALSE); } } else { if ($addhostinfo and $size > 0) { // remember to skip broadcast and network addresses! for ($i_dns = 1; $i_dns < $size - 1; $i_dns++) { $hname = gethostbyaddr(inet_ntoa($base + $i_dns)); if ($hname != inet_ntoa($base + $i_dns)) { $ds->AddIP($base + $i_dns, $id, "", "", "", "", "", $hname, "");
if (!$extst) { myError($w, $p, sprintf(my_("Subnet %s not modified - out of defined authority boundary"), $baseip) . "\n"); } $restemp = $ds->GetDuplicateSubnet($base, $size, $cust); if ($restemp->FetchRow()) { $formerror .= my_("Subnet could not be created - possibly overlaps with an existing subnet on new customers network") . "\n"; } else { $ds->DbfTransactionStart(); // move the subnet to another customer, template will move with as relation // between base and baseadd is baseindex column if ($duplicatesubnet == 0) { $result =& $ds->ds->Execute("UPDATE base\n SET descrip=" . $ds->ds->qstr($descrip) . ",\n admingrp=" . $ds->ds->qstr($grp) . ",\n customer={$cust},\n lastmod=" . $ds->ds->DBTimeStamp(time()) . ",\n userid=" . $ds->ds->qstr($userid) . "\n WHERE baseindex={$baseindex}"); $ds->AuditLog(array("event" => 174, "action" => "move subnet", "user" => getAuthUsername(), "baseaddr" => inet_ntoa($base), "size" => $size, "newcust" => $cust)); } else { // use the first group user belongs to create subnet if ($id = $ds->CreateSubnet($base, $size, $descrip, $cust, 0, $grp)) { if ($duplicatesubnet == 1) { // subnet created, now move info to new subnet // cant use a temp table here as database does not // have enough rights - don't want to give it anymore // anyway, so we need to do it the hard way $result = $ds->GetSubnetDetails($baseindex); while ($row = $result->FetchRow()) { $tempipaddr = $row["ipaddr"]; $tempuser = $row["userinf"]; $templocation = $row["location"]; $temptelno = $row["telno"]; $tempdescrip = $row["descrip"]; $templastmod = $row["lastmod"]; $tempuserid = $row["userid"]; $tempresult =& $ds->ds->Execute("INSERT INTO ipaddr\n (ipaddr, userinf, location, telno,\n descrip, lastmod, userid, baseindex)\n VALUES\n (" . $ds->ds->qstr($tempipaddr) . ",\n " . $ds->ds->qstr($tempuser) . ",\n " . $ds->ds->qstr($templocation) . ",\n " . $ds->ds->qstr($temptelno) . ",\n " . $ds->ds->qstr($tempdescrip) . ",\n {$templastmod},\n " . $ds->ds->qstr($tempuserid) . ",\n {$id})");
// none found overlapping, so can extend subnet! // or overlapping subnet was already deleted $result =& $ds->ds->Execute("UPDATE base\n SET subnetsize={$size}*2,\n lastmod=" . $ds->ds->DBTimeStamp(time()) . ",\n userid=" . $ds->ds->qstr(getAuthUsername()) . "\n WHERE baseindex={$baseindex}"); $ds->AuditLog(array("event" => 173, "action" => "join subnet", "user" => getAuthUsername(), "baseaddr" => $baseip, "size" => $size * 2, "cust" => $cust)); } else { if ($action == "split") { // user may have pressed browser reload, so check size again if ($size < 2) { myError($w, $p, my_("Subnets cannot be split - host network!")); } // halve size of subnet $result =& $ds->ds->Execute("UPDATE base\n SET subnetsize={$size}/2,\n lastmod=" . $ds->ds->DBTimeStamp(time()) . ",\n userid=" . $ds->ds->qstr(getAuthUsername()) . "\n WHERE baseindex={$baseindex}"); // ... and create new subnet $timetmp = time(); // check that new decsription fits into 80 column field $basetmp = $ds->CreateSubnet($base + $size / 2, $size / 2, substr($descriptmp, 0, 80 - (strlen($timetmp) + 3)) . " - " . $timetmp, $cust, 0, $admingrp); // ... and then link half of ip records to new subnet if ($basetmp) { $ds->ds->Execute("UPDATE ipaddr\n SET baseindex={$basetmp}\n WHERE baseindex={$baseindex} AND\n ipaddr >= " . ($base + $size / 2) . " AND\n ipaddr <= " . ($base + $size - 1)); } $ds->AuditLog(array("event" => 174, "action" => "split subnet", "user" => getAuthUsername(), "baseaddr" => $baseip, "size" => $size / 2, "cust" => $cust)); } } $ds->DbfTransactionEnd(); insert($w, textbr(my_("Subnet split or joined"))); } } // set start and end address according to range if ($rangeindex) { // should only return one row here! $result = $ds->GetRange($cust, $rangeindex);