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
|
<?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");
$auth = new SQLAuthenticator(REALM, REALMERROR);
// And now perform the authentication
$auth->authenticate();
// save the last customer used
// must set path else Netscape gets confused!
setcookie("ipplanCustomer","$cust",time() + 10000000, "/");
// 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_("Results of your search");
newhtml($p);
$w=myheading($p, $title, true);
// explicitly cast variables as security measure against SQL injection
list($cust, $areaindex, $rangeindex, $block, $field, $day, $month, $year, $search) = myRegister("I:cust I:areaindex I:rangeindex I:block S:field I:day I:month I:year S:search");
if (!$_GET) {
myError($w,$p, my_("You cannot reload or bookmark this page!"));
}
if (strlen($search) < 3) {
if ($field == "template" and $tmplfield == "any") {
myError($w,$p, my_("You need to enter a longer search criteria, or select a specific template"));
} else if ($field != "template") {
myError($w,$p, my_("You need to enter a longer search criteria."));
}
}
if ($field != "userinf" and $field != "location" and
$field != "telno" and $field != "descrip" and
$field != "hname" and $field != "macaddr" and
$field != "template" and $field != "any") {
myError($w,$p, my_("Invalid search field."));
}
if ($day == 0 or $month == 0 or $year == 0) {
$usedate=FALSE;
}
else {
if (!checkdate((int)$month, (int)$day, (int)$year)) {
myError($w,$p, my_("Invalid search date."));
}
$usedate=TRUE;
}
if ($field=="macaddr") {
$oldmacaddr=$search;
$search=str_replace(array(":", "-", " "), "", $search);
if (preg_match('/^[a-f0-9A-F]*$/', $search) and strlen($search) <= 12) {
}
else {
myError($w,$p, sprintf(my_("Invalid MAC address: %s"), $oldmacaddr)."\n");
}
}
// basic sequence is connect, search, interpret search
// result, close connection
$ds=new IPplanDbf() or myError($w,$p, my_("Could not connect to database"));
$addtables="";
if (DBF_TYPE=="mysql" or DBF_TYPE=="maxsql") {
if (preg_ispreg($search)) {
myError($w,$p, my_("Regular expression repetition-operator operand invalid"));
}
/* if ($field == "any") {
$where ="WHERE ipaddr.userinf RLIKE ".$ds->ds->qstr($search);
$where.=" OR ipaddr.location RLIKE ".$ds->ds->qstr($search);
$where.=" OR ipaddr.telno RLIKE ".$ds->ds->qstr($search);
$where.=" OR ipaddr.descrip RLIKE ".$ds->ds->qstr($search);
$where.=" OR ipaddr.hname RLIKE ".$ds->ds->qstr($search);
$where.=" OR (ipaddr.ipaddr=ipaddradd.ipaddr AND
ipaddradd.info RLIKE ".$ds->ds->qstr($search).")";
}
else */
if ($field == "userinf")
$where="WHERE ipaddr.userinf RLIKE ".$ds->ds->qstr($search);
else if ($field == "location")
$where="WHERE ipaddr.location RLIKE ".$ds->ds->qstr($search);
else if ($field == "telno")
$where="WHERE ipaddr.telno RLIKE ".$ds->ds->qstr($search);
else if ($field == "descrip")
$where="WHERE ipaddr.descrip RLIKE ".$ds->ds->qstr($search);
else if ($field == "hname")
$where="WHERE ipaddr.hname RLIKE ".$ds->ds->qstr($search);
else if ($field == "macaddr")
$where="WHERE ipaddr.macaddr RLIKE ".$ds->ds->qstr($search);
else if ($field == "template" and $tmplfield == "any") {
$addtables=", ipaddradd";
$where="WHERE ipaddr.ipaddr=ipaddradd.ipaddr AND ipaddr.baseindex = ipaddradd.baseindex AND
ipaddradd.info RLIKE ".$ds->ds->qstr($search);
} else if ($field == "template" and $tmplfield != "any") {
$addtables=", ipaddradd";
$where="WHERE ipaddr.ipaddr=ipaddradd.ipaddr AND ipaddr.baseindex = ipaddradd.baseindex AND
ipaddradd.info RLIKE ".$ds->ds->qstr(".*\:\"".$tmplfield."\"\;.*\".*".$search.".*\"\;");
}
}
else if (DBF_TYPE=="postgres7") {
if (preg_ispreg($search)) {
myError($w,$p, my_("Regular expression repetition-operator operand invalid"));
}
/*
if ($field == "any") {
$where ="WHERE ipaddr.userinf ~ ".$ds->ds->qstr($search);
$where.=" OR ipaddr.location ~ ".$ds->ds->qstr($search);
$where.=" OR ipaddr.telno ~ ".$ds->ds->qstr($search);
$where.=" OR ipaddr.descrip ~ ".$ds->ds->qstr($search);
$where.=" OR ipaddr.hname ~ ".$ds->ds->qstr($search);
$where.=" OR (ipaddr.ipaddr=ipaddradd.ipaddr AND
ipaddradd.info ~ ".$ds->ds->qstr($search).")";
}
else */
if ($field == "userinf")
$where="WHERE ipaddr.userinf ~ ".$ds->ds->qstr($search);
else if ($field == "location")
$where="WHERE ipaddr.location ~ ".$ds->ds->qstr($search);
else if ($field == "telno")
$where="WHERE ipaddr.telno ~ ".$ds->ds->qstr($search);
else if ($field == "descrip")
$where="WHERE ipaddr.descrip ~ ".$ds->ds->qstr($search);
else if ($field == "hname")
$where="WHERE ipaddr.hname ~ ".$ds->ds->qstr($search);
else if ($field == "macaddr")
$where="WHERE ipaddr.macaddr ~ ".$ds->ds->qstr($search);
else if ($field == "template" and $tmplfield == "any") {
$addtables=", ipaddradd";
$where="WHERE ipaddr.ipaddr=ipaddradd.ipaddr AND ipaddr.baseindex = ipaddradd.baseindex AND
ipaddradd.info ~ ".$ds->ds->qstr($search);
} else if ($field == "template" and $tmplfield != "any") {
$addtables=", ipaddradd";
$where="WHERE ipaddr.ipaddr=ipaddradd.ipaddr AND ipaddr.baseindex = ipaddradd.baseindex AND
ipaddradd.info ~ ".$ds->ds->qstr(".*\:\"".$tmplfield."\"\;.*\".*".$search.".*\"\;");
}
}
else {
/*
if ($field == "any") {
$where ="WHERE ipaddr.userinf LIKE ".$ds->ds->qstr("%".$search."%");
$where.=" OR ipaddr.location LIKE ".$ds->ds->qstr("%".$search."%");
$where.=" OR ipaddr.telno LIKE ".$ds->ds->qstr("%".$search."%");
$where.=" OR ipaddr.descrip LIKE ".$ds->ds->qstr("%".$search."%");
$where.=" OR ipaddr.hname LIKE ".$ds->ds->qstr("%".$search."%");
$where.=" OR (ipaddr.ipaddr=ipaddradd.ipaddr AND
ipaddradd.info LIKE ".$ds->ds->qstr("%".$search."%").")";
}
else */
if ($field == "userinf")
$where="WHERE ipaddr.userinf LIKE ".$ds->ds->qstr("%".$search."%");
else if ($field == "location")
$where="WHERE ipaddr.location LIKE ".$ds->ds->qstr("%".$search."%");
else if ($field == "telno")
$where="WHERE ipaddr.telno LIKE ".$ds->ds->qstr("%".$search."%");
else if ($field == "descrip")
$where="WHERE ipaddr.descrip LIKE ".$ds->ds->qstr("%".$search."%");
else if ($field == "hname")
$where="WHERE ipaddr.hname LIKE ".$ds->ds->qstr("%".$search."%");
else if ($field == "macaddr")
$where="WHERE ipaddr.macaddr LIKE ".$ds->ds->qstr("%".$search."%");
else if ($field == "template") {
$addtables=", ipaddradd";
$where="WHERE ipaddr.ipaddr=ipaddradd.ipaddr AND
ipaddradd.info LIKE ".$ds->ds->qstr("%".$search."%");
}
}
// add date info if user searched by date
if ($usedate) {
$where .= " AND ipaddr.lastmod >= ".$ds->ds->DBTimeStamp(mktime(0,0,0,$month,$day,$year));
}
// set start and end address according to range
$site="";
if ($rangeindex) {
// should only return one row here!
$result=$ds->GetRange($cust, $rangeindex);
$row = $result->FetchRow();
$start=inet_ntoa($row["rangeaddr"]);
$end=inet_ntoa($row["rangeaddr"]+$row["rangesize"]-1);
$site=" (".$row["descrip"].")";
}
else {
$start=DEFAULTROUTE;
$end=ALLNETS;
}
$startnum=inet_aton($start);
$endnum=inet_aton($end);
$custdescrip=$ds->GetCustomerDescrip($cust);
// handle "all" customer
if (strtolower($custdescrip) == "all") {
$cust=0;
}
else {
$where = $where." AND base.customer=$cust ";
}
$sqllastmod = $ds->ds->SQLDate("M d Y H:i:s", 'ipaddr.lastmod');
if ($areaindex and !$rangeindex) {
insert($w,heading(3, sprintf(my_("Search for IP subnets between multiple ranges for customer '%s'"), $custdescrip)));
// NOTE: ipaddr column aliased to baseaddr to make DisplayBlock work
$result=&$ds->ds->Execute("SELECT ipaddr.userinf, ipaddr.location,
ipaddr.telno, ipaddr.descrip, $sqllastmod AS lastmod,
ipaddr.ipaddr AS baseaddr, ipaddr.baseindex,
ipaddr.hname,
customer.custdescrip, customer.customer
FROM ipaddr, base, netrange, customer $addtables
$where AND
base.customer = customer.customer AND
base.baseindex = ipaddr.baseindex AND
netrange.areaindex=$areaindex AND
base.baseaddr BETWEEN netrange.rangeaddr AND
netrange.rangeaddr+netrange.rangesize-1 AND
netrange.customer=$cust");
// ORDER by
// ipaddr.ipaddr");
}
else {
insert($w,heading(3, sprintf(my_("Search for IP subnets between %s and %s %s for customer '%s'"), $start, $end, $site, $custdescrip)));
// NOTE: ipaddr column aliased to baseaddr to make DisplayBlock work
// get detail from ipaddr table - could be nothing!
$result=&$ds->ds->Execute("SELECT ipaddr.userinf, ipaddr.location,
ipaddr.telno, ipaddr.descrip, $sqllastmod AS lastmod,
ipaddr.ipaddr AS baseaddr, ipaddr.baseindex,
ipaddr.hname,
customer.custdescrip, customer.customer
FROM ipaddr, base, customer $addtables
$where AND
base.customer = customer.customer AND
base.baseindex = ipaddr.baseindex AND
base.baseaddr BETWEEN $startnum AND $endnum");
// ORDER by
// ipaddr.ipaddr");
}
insert($w,textb(sprintf(my_("Search filter on %s: "), $field)));
insert($w,textbr($search));
$totcnt=0;
$vars="";
// fastforward till first record if not first block of data
while ($block and $totcnt < $block*MAXTABLESIZE and
$row = $result->FetchRow()) {
$vars=DisplayBlock($w, $row, $totcnt,
"&cust=".$cust.
"&areaindex=".$areaindex."&rangeindex=".$rangeindex.
"&day=".$day."&month=".$month."&year=".$year.
"&tmplfield=".$tmplfield.
"&search=".urlencode($search)."&field=".$field);
$totcnt++;
}
insert($w,block("<p>"));
// create a table
insert($w,$t = table(array("cols"=>"6",
"class"=>"outputtable")));
// draw heading
setdefault("cell",array("class"=>"heading"));
insert($t,$c = cell());
if (!empty($vars))
insert($c,anchor($vars, "<<"));
insert($c,text(my_("IP address")));
insert($t,$c = cell());
insert($c,text(my_("User")));
insert($t,$c = cell());
insert($c,text(my_("Location")));
insert($t,$c = cell());
insert($c,text(my_("Device description")));
insert($t,$c = cell());
insert($c,text(my_("Telephone Number")));
insert($t,$ck = cell());
insert($ck,text(my_("Last modified")));
$cnt=0;
$prevrow="";
while($row = $result->FetchRow()) {
setdefault("cell",array("class"=>color_flip_flop()));
// customer is 0, display all customers with customer description
// on customer change
if ($cust == 0 and $row["custdescrip"] != $prevrow) {
insert($t,$c = cell(array("colspan"=>"6")));
insert($c,generic("b"));
insert($c,anchor($_SERVER["PHP_SELF"]."?cust=".$row["customer"]."&areaindex=&rangeindex=&ipaddr=&search=".urlencode($search)."&field=$field&tmplfield=$tmplfield",
$row["custdescrip"]));
$prevrow=$row["custdescrip"];
}
insert($t,$c = cell());
insert($c,anchor("modifyipform.php?ip=".$row["baseaddr"].
"&baseindex=".$row["baseindex"],
inet_ntoa($row["baseaddr"])));
insert($t,$c = cell());
// check if userinf field has an encoded linked address in format of LNKx.x.x.x
// where x.x.x.x is an ip address
$lnk="";
$userinf=$row["userinf"];
if (preg_match("/^LNK[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}/", $userinf)) {
list($lnk, $userinf) = preg_split("/[\s]+/", $userinf, 2);
$lnk=substr($lnk, 3);
}
insert($c,textbr($userinf));
if (!empty($lnk)) {
insert($c,block("<small><i>"));
insert($c,anchor("displaybase.php?ipaddr=$lnk&cust=$cust&searchin=1",
my_(sprintf("Follow link to %s", $lnk))));
insert($c,block("</i></small>"));
}
insert($t,$c = cell());
insert($c,text($row["location"]));
insert($t,$c = cell());
insert($c,text($row["descrip"]));
if (!empty($row["hname"])) {
insert($c,textbr());
insert($c,block("<small><i>"));
insert($c,text($row["hname"]));
insert($c,block("</i></small>"));
}
insert($t,$c = cell());
insert($c,text($row["telno"]));
insert($t,$c = cell());
insert($c,block("<small>"));
insert($c,block($result->UserTimeStamp($row["lastmod"], "M d Y H:i:s")));
insert($c,block("</small>"));
if ($totcnt % MAXTABLESIZE == MAXTABLESIZE-1)
break;
$cnt++;
$totcnt++;
}
insert($w,block("<p>"));
if (!$cnt) {
myError($w,$p, my_("Search found no matching entries"));
}
$vars="";
$printed=0;
while ($row = $result->FetchRow()) {
$totcnt++;
$vars=DisplayBlock($w, $row, $totcnt,
"&cust=".$cust.
"&areaindex=".$areaindex."&rangeindex=".$rangeindex.
"&day=".$day."&month=".$month."&year=".$year.
"&tmplfield=".$tmplfield.
"&search=".urlencode($search)."&field=".$field);
if (!empty($vars) and !$printed) {
insert($ck,anchor($vars, ">>"));
$printed=1;
}
}
$result->Close();
printhtml($p);
?>
|