1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
|
<?php
// IPplan v4.92a
// Aug 24, 2001
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
require_once("../ipplanlib.php");
require_once("../adodb/adodb.inc.php");
require_once("../class.dbflib.php");
require_once("../layout/class.layout");
require_once("../auth.php");
// Changed - Begin [FE]
require_once("../class.templib.php");
// Changed - End [FE]
$auth = new SQLAuthenticator(REALM, REALMERROR);
// And now perform the authentication
$grps=$auth->authenticate();
// set language
isset($_COOKIE["ipplanLanguage"]) && myLanguage($_COOKIE['ipplanLanguage']);
//setdefault("window",array("bgcolor"=>"white"));
//setdefault("table",array("cellpadding"=>"0"));
//setdefault("text",array("size"=>"2"));
$title=my_("Modify/Copy/Move subnet details");
newhtml($p);
insert($p, $h = wheader("IPPlan - $title"));
insert($h, script("", array("type"=>"text/javascript", "src"=>"../cookies.js")));
insert($h, script("", array("type"=>"text/javascript", "src"=>"../phpserializer.js")));
insert($h, script("", array("type"=>"text/javascript", "src"=>"../ipplanlib.js")));
$w=myheading($p, $title, true);
// explicitly cast variables as security measure against SQL injection
list($baseindex, $cust, $descrip, $grp, $origcust, $dhcp) = myRegister("I:baseindex I:cust S:descrip S:grp S:origcust I:dhcp");
// additional vars for Location: header
list($areaindex, $rangeindex, $search, $ipaddr) = myRegister("I:areaindex I:rangeindex S:search S:ipaddr");
list($userfld) = myRegister("A:userfld"); // for template fields
$formerror="";
$ds=new IPplanDbf() or myError($w,$p, my_("Could not connect to database"));
// remember original customer
if (!$origcust) {
$origcust=$cust;
}
if ($_POST) {
// 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 modify this subnet for this customer as you are not a member of the new customers admin group"));
}
$descrip=trim($descrip);
if (strlen($descrip) == 0) {
$formerror .= my_("You need to enter a description for the subnet")."\n";
}
if (!$formerror) {
$userid=getAuthUsername();
// move or duplicate the subnet to another customer
if ($origcust and $origcust!=$cust) {
// check if user belongs to customer admin group
$result=$ds->GetCustomerGrp($origcust);
// 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 move this subnet for this customer as you are not a member of the original customers admin group"));
}
// did somebody else whack the subnet in the meantime?
$result=$ds->GetBaseFromIndex($baseindex);
if (!$row = $result->FetchRow()) {
myError($w,$p, my_("Subnet cannot be found!"));
}
$size=$row["subnetsize"];
$base=$row["baseaddr"];
$baseip=inet_ntoa($row["baseaddr"]);
// test if subnet to delete is within bounds
foreach ($grps as $value) {
if ($extst = $ds->TestBounds($base, $size, $value)) {
// got an overlap, allowed to create
break;
}
}
// could not find new subnet within any of the defined bounds
// so do not create
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
SET descrip=".$ds->ds->qstr($descrip).",
admingrp=".$ds->ds->qstr($grp).",
customer=$cust,
lastmod=".$ds->ds->DBTimeStamp(time()).",
userid=".$ds->ds->qstr($userid)."
WHERE baseindex=$baseindex");
$ds->AuditLog(array("event"=>174, "action"=>"move subnet",
"user"=>getAuthUsername(), "baseaddr"=>inet_ntoa($base),
"size"=>$size, "newcust"=>$cust));
}
// duplicate the subnet to another customer
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
(ipaddr, userinf, location, telno,
descrip, lastmod, userid, baseindex)
VALUES
(".$ds->ds->qstr($tempipaddr).",
".$ds->ds->qstr($tempuser).",
".$ds->ds->qstr($templocation).",
".$ds->ds->qstr($temptelno).",
".$ds->ds->qstr($tempdescrip).",
$templastmod,
".$ds->ds->qstr($tempuserid).",
$id)");
} // end while
}
$ds->AuditLog(array("event"=>170, "action"=>"create subnet",
"descrip"=>$descrip, "user"=>getAuthUsername(), "baseaddr"=>inet_ntoa($base),
"size"=>$size, "cust"=>$cust));
}
}
}
}
// just update the description
else {
// did somebody else whack the subnet in the meantime?
$result=$ds->GetBaseFromIndex($baseindex);
if (!$row = $result->FetchRow()) {
myError($w,$p, my_("Subnet cannot be found!"));
}
$size=$row["subnetsize"];
$base=$row["baseaddr"];
$baseip=inet_ntoa($row["baseaddr"]);
// test if subnet to update is within bounds
foreach ($grps as $value) {
if ($extst = $ds->TestBounds($base, $size, $value)) {
// got an overlap, allowed to create
break;
}
}
// could not find new subnet within any of the defined bounds
// so do not create
if (!$extst) {
myError($w,$p,sprintf(my_("Subnet %s not modified - out of defined authority boundary"), $baseip)."\n");
}
$ds->DbfTransactionStart();
$result=&$ds->ds->Execute("UPDATE base
SET descrip=".$ds->ds->qstr($descrip).",
admingrp=".$ds->ds->qstr($grp).",
lastmod=".$ds->ds->DBTimeStamp(time()).",
baseopt=$dhcp,
userid=".$ds->ds->qstr($userid)."
WHERE baseindex=$baseindex") and
$ds->AuditLog(array("event"=>171, "action"=>"modify subnet",
"descrip"=>$descrip, "user"=>getAuthUsername(), "baseaddr"=>inet_ntoa($base),
"size"=>$size, "cust"=>$cust));
if ($dhcp) {
// use dhcp template (for additional subnet information)
$template=new IPplanIPTemplate("basetemplate-dhcp", $cust);
}
else {
// use base template (for additional subnet information)
$template=new IPplanIPTemplate("basetemplate", $cust);
}
$info="";
if ($template->is_error() == FALSE) {
// PROBLEM HERE: if template create suddenly returns error (template file
// permissions, xml error etc), then each submit thereafter will erase
// previous contents - this is not good
$template->Merge($userfld);
$err=$template->Verify($w);
if ($template->is_blank() == FALSE) {
$info=$template->encode();
}
}
if($ds->ds->GetRow("SELECT baseindex
FROM baseadd
WHERE baseindex=$baseindex")) { // should have FOR UPDATE here!
$result = &$ds->ds->Execute("UPDATE baseadd
SET info=".$ds->ds->qstr($info)."
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
(info, baseindex)
VALUES
(".$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($w,block("<h3>"));
insert($w,text(my_("Subnet:")." ".
inet_ntoa($baseaddr)." ".my_("Mask:")." ".
inet_ntoa(inet_aton(ALLNETS)+1 -
$size)."/".inet_bits($size)));
insert($w,textbr());
insert($w,text(my_("Description:")." ".$row["descrip"]));
insert($w,block("</h3>"));
// start form
insert($w, $f1 = form(array("name"=>"THISFORM",
"method"=>"get",
"action"=>$_SERVER["PHP_SELF"])));
$cust=myCustomerDropDown($ds, $f1, $cust, $grps) or myError($w,$p, my_("No customers"));
insert($f1,hidden(array("name"=>"descrip",
"value"=>"$descrip")));
insert($f1,hidden(array("name"=>"search",
"value"=>"$search")));
insert($f1,hidden(array("name"=>"ipaddr",
"value"=>"$ipaddr")));
insert($f1,hidden(array("name"=>"areaindex",
"value"=>"$areaindex")));
insert($f1,hidden(array("name"=>"rangeindex",
"value"=>"$rangeindex")));
insert($f1,hidden(array("name"=>"baseindex",
"value"=>"$baseindex")));
insert($f1,hidden(array("name"=>"grp",
"value"=>"$grp")));
insert($f1,hidden(array("name"=>"origcust",
"value"=>"$origcust")));
$result=$ds->GetGrps();
$lst=array();
while($row = $result->FetchRow()) {
$col=$row["grp"];
$lst["$col"]=$row["grpdescrip"];
}
if (empty($lst)) {
myError($w,$p, my_("You first need to create some groups!"));
}
// start form
insert($w, $f = form(array("name"=>"ENTRY",
"method"=>"post",
"action"=>$_SERVER["PHP_SELF"])));
if ($origcust and $origcust != $cust) {
insert($f,radio(array("name"=>"duplicatesubnet",
"value"=>"0"),
my_("Move subnet to new customer"), "checked"));
insert($f,radio(array("name"=>"duplicatesubnet",
"value"=>"1"),
my_("Duplicate subnet on new customer")));
insert($f,radio(array("name"=>"duplicatesubnet",
"value"=>"2"),
my_("Duplicate subnet on new customer without IP detail")));
insert($f,generic("br"));
}
insert($f,textbrbr(my_("Subnet description")));
insert($f,input_text(array("name"=>"descrip",
"value"=>"$descrip",
"size"=>"80",
"maxlength"=>"80")));
insert($f,generic("br"));
insert($f,checkbox(array("name"=>"dhcp",
"value"=>"1"),
my_("Is this a DHCP subnet?"), $dhcp));
insert($f,generic("br"));
insert($f,hidden(array("name"=>"baseindex",
"value"=>"$baseindex")));
insert($f,hidden(array("name"=>"cust",
"value"=>"$cust")));
insert($f,hidden(array("name"=>"search",
"value"=>"$search")));
insert($f,hidden(array("name"=>"ipaddr",
"value"=>"$ipaddr")));
insert($f,hidden(array("name"=>"areaindex",
"value"=>"$areaindex")));
insert($f,hidden(array("name"=>"rangeindex",
"value"=>"$rangeindex")));
insert($f,hidden(array("name"=>"origcust",
"value"=>"$origcust")));
insert($f,textbrbr(my_("Admin Group")));
insert($f,textbr(my_("WARNING: If you choose a group that you do not have access to, you will not be able to see or access the data")));
insert($f,selectbox($lst,
array("name"=>"grp"),
$grp));
// Changed - Begin [FE]
// Requires new default template: basetemplate.xml
// Start of template support [FE]
$result=&$ds->ds->Execute("SELECT info, infobin
FROM baseadd
WHERE baseindex=$baseindex");
$rowadd = $result->FetchRow();
$dbfinfo=$rowadd["info"];
if ($dhcp) {
// use dhcp template (for additional subnet information)
$template=new IPplanIPTemplate("basetemplate-dhcp", $cust);
}
else {
// use base template (for additional subnet information)
$template=new IPplanIPTemplate("basetemplate", $cust);
}
if ($template->is_error() == FALSE) {
insert($f, $con=container("fieldset",array("class"=>"fieldset")));
insert($con, $legend=container("legend",array("class"=>"legend")));
insert($legend, text(my_("Additional information")));
$template->Merge($template->decode($dbfinfo));
$template->DisplayTemplate($con);
}
// Changed - End [FE]
insert($f,generic("br"));
insert($f,submit(array("value"=>my_("Submit"))));
insert($f,freset(array("value"=>my_("Clear"))));
myCopyPaste($f, "ipplanCPmodsubnet", "ENTRY");
}
printhtml($p);
?>
|