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
|
<?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");
require_once("../class.templib.php");
// maximum number of outstanding IP address requests allowed - this is to prevent
// denial of service on the database as this feature is not authenticated
define("MAXREQUESTS", "100");
// disable or enable drop down menu on request page - default disabled
define("MENU", FALSE);
if (!REQUESTENABLED) {
die("IP address request system has been disabled by the administrator.");
}
// set language
isset($_COOKIE["ipplanLanguage"]) && myLanguage($_COOKIE['ipplanLanguage']);
//setdefault("window",array("bgcolor"=>"white"));
//setdefault("table",array("cellpadding"=>"0"));
//setdefault("text",array("size"=>"2"));
// explicitly cast variables as security measure against SQL injection
list($cust, $request, $user, $location, $descrip, $hname, $telno, $macaddr, $ipplanCustomer) = myRegister("I:cust S:request S:user S:location S:descrip S:hname S:telno S:macaddr I:ipplanCustomer");
$formerror="";
$title=my_("Request an IP address");
newhtml($p);
$w=myheading($p, $title, MENU);
$ds=new IPplanDbf() or myError($w,$p, my_("Could not connect to database"));
if ($_POST) {
$request=trim($request);
$descrip=trim($descrip);
if (strlen($request) == 0) {
$formerror .= my_("You need to enter request details for the ip address request")."\n";
}
if (strlen($user) == 0) {
$formerror .= my_("You need to enter user details for the request")."\n";
}
if (strlen($location) == 0) {
$formerror .= my_("You need to enter location details for the request")."\n";
}
if (strlen($descrip) == 0) {
$formerror .= my_("You need to enter description details for the request")."\n";
}
if (strlen($telno) == 0) {
$formerror .= my_("You need to enter a telephone number for the request")."\n";
}
// check if mac address is valid - all or nothing!
$newmacaddr="";
if (!empty($macaddr)) {
$newmacaddr=str_replace(array(":", "-", ".", " "), "", $macaddr);
if (strlen($newmacaddr)==12 and
preg_match("/[a-f0-9A-F]/", $newmacaddr)) {
}
else {
$formerror .= sprintf(my_("Invalid MAC address: %s"), $macaddr)."\n";
}
}
// use base template (for additional subnet information)
$template=new IPplanIPTemplate("iptemplate", $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);
if($err=$template->Verify($w)) {
$formerror .= my_("Additional information error")."\n";
}
if ($template->is_blank() == FALSE) {
$info=$template->encode();
}
}
$recs=$ds->ds->GetOne("SELECT count(*) AS cnt
FROM requestip");
if ($recs > MAXREQUESTS) {
$formerror .= my_("Maximum number of outstanding IP requests exceeded")."\n";
}
if (!$formerror) {
$ds->DbfTransactionStart();
$result=&$ds->ds->Execute("INSERT INTO requestip
(customer, requestdesc, userinf, location, descrip,
hname, telno, macaddr, info)
VALUES
($cust,
".$ds->ds->qstr($request).",
".$ds->ds->qstr($user).",
".$ds->ds->qstr($location).",
".$ds->ds->qstr($descrip).",
".$ds->ds->qstr($hname).",
".$ds->ds->qstr($telno).",
".$ds->ds->qstr($newmacaddr).",
".$ds->ds->qstr($info).")") and
$ds->AuditLog(array("event"=>200, "action"=>"request ip",
"descrip"=>$descrip, "user"=>getAuthUsername(), "userinf"=>$user,
"location"=>$location, "hname"=>$hname, "telno"=>$telno,
"macaddr"=>$macaddr));
if ($result) {
$ds->DbfTransactionEnd();
insert($w,textbr(my_("IP address request created")));
$custdescrip=$ds->GetCustomerDescrip($cust);
//Send email notification that IP Request was entered
require("../class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SetLanguage("en", "../");
$mail->Host = EMAILSERVER; // SMTP server
$mail->From = HELPDESKEMAIL;
$mail->IsHTML(false);
$mail->FromName = "IP Plan";
$mail->AddAddress(HELPDESKEMAIL);
$mail->Subject = "IP Request Submittal";
$mail->Body= "The following IP address request has been submitted and needs to be actioned.\n\n";
$mail->Body.= "IP Request Details\n\n";
$mail->Body.="Customer: $custdescrip\n";
$mail->Body.="Request Details: $request\n";
$mail->Body.="User information: $user\n";
$mail->Body.="Location: $location\n";
$mail->Body.="Description: $descrip\n";
$mail->Body.="Telephone number: $telno\n";
$mail->Body.="Host Name: $hname\n";
$mail->Body.="MAC Address: $macaddr\n\n";
$template=new IPplanIPTemplate("iptemplate", $cust);
if ($template->is_error() == FALSE) {
if (isset($userfld)) {
$template->Merge($userfld);
}
foreach ($template->userfld as $value) {
$mail->Body.=sprintf("%s: %s\n", $value["descrip"], $value["value"]);
}
}
if(!@$mail->Send()) {
$formerror .= my_("E-mail message was not sent")."\n";
$formerror .= my_("Mailer Error: ") . $mail->ErrorInfo;
}
else {
insert($w,textbr(my_("IP request E-mail message sent")));
}
}
else {
$ds->DbfTransactionRollback();
$formerror .= my_("Request could not be created - possibly a duplicate request")."\n";
}
}
}
myError($w,$p, $formerror, FALSE);
// display opening text
insert($w,heading(3, "$title."));
insert($w,textbrbr(my_("Complete the details below to request an IP address. An administrator will need to action the request before an address will be allocated.")));
// create list of customers to display based on REQUESTCUST variable
$sql = "";
$lst = split(",", REQUESTCUST);
if (REQUESTCUST != "" and !empty($lst)) {
foreach ($lst as $value) {
$i=(int)$value; // force to int
$sql.="$i,";
}
$sql=substr($sql, 0, -1);
$sql=" customer IN ($sql) ";
}
$result=$ds->GetCustomer($sql);
$lst=array();
$custset=0;
while($row = $result->FetchRow()) {
if (strtolower($row["custdescrip"])=="all")
continue;
// strip out customers user may not see due to not being member
// of customers admin group. $grps array could be empty if anonymous
// access is allowed!
if(!empty($grps)) {
if(!in_array($row["admingrp"], $grps))
continue;
}
$col=$row["customer"];
// make customer first customer in database
if (!$cust) {
$cust=$col;
$custset=1; // remember that customer was blank
}
// only make customer same as cookie if customer actually
// still exists in database, else will cause loop!
if ($custset) {
if ($col == $ipplanCustomer) {
// dont trust cookie
$cust=floor($ipplanCustomer);
}
}
$lst["$col"]=$row["custdescrip"];
}
insert($w, $f = form(array("name"=>"ENTRY",
"method"=>"post",
"action"=>$_SERVER["PHP_SELF"])));
myFocus($p, "MODIFY", "request");
insert($f,textbrbr(my_("Customer")));
insert($f,selectbox($lst,
array("name"=>"cust"),
$cust));
insert($f,textbrbr(my_("Request details")));
insert($f,span(my_("Enter full details describing the request to enable the administrators to allocate the correct IP address on the network"), array("class"=>"textSmall")));
insert($f,input_text(array("name"=>"request",
"value"=>$request,
"size"=>"80",
"maxlength"=>"80")));
insert($f, $con=container("fieldset",array("class"=>"fieldset")));
insert($con, $legend=container("legend",array("class"=>"legend")));
insert($legend, text(my_("User information")));
insert($con,textbr(my_("User")));
insert($con,input_text(array("name"=>"user",
"value"=>$user,
"size"=>"80",
"maxlength"=>"80")));
insert($con,textbrbr(my_("Location")));
insert($con,input_text(array("name"=>"location",
"value"=>$location,
"size"=>"80",
"maxlength"=>"80")));
insert($con,textbrbr(my_("Device description")));
insert($con,input_text(array("name"=>"descrip",
"value"=>$descrip,
"size"=>"80",
"maxlength"=>"80")));
insert($con,textbrbr(my_("Device hostname")));
insert($con,input_text(array("name"=>"hname",
"value"=>$hname,
"size"=>"80",
"maxlength"=>"100")));
insert($con,textbrbr(my_("Telephone number")));
insert($con,input_text(array("name"=>"telno",
"value"=>$telno,
"size"=>"15",
"maxlength"=>"15")));
insert($con,textbrbr(my_("MAC address")));
insert($con,input_text(array("name"=>"macaddr",
"value"=>$macaddr,
"size"=>"17",
"maxlength"=>"17")));
$template=new IPplanIPTemplate("iptemplate", $cust);
if ($template->is_error() == FALSE) {
//insert($f,block("<hr>"));
insert($f, $con=container("fieldset",array("class"=>"fieldset")));
insert($con, $legend=container("legend",array("class"=>"legend")));
insert($legend, text(my_("Additional information")));
//insert($f,textbr(my_("Additional information"), array("b"=>1)));
if (isset($userfld)) {
$template->Merge($userfld);
}
$template->DisplayTemplate($con);
}
insert($f,generic("br"));
insert($f,submit(array("value"=>my_("Submit"))));
insert($f,freset(array("value"=>my_("Clear"))));
printhtml($p);
?>
|