} } $filename = $_FILES['userfile']['tmp_name']; // basic sequence is connect, search, interpret search // result, close connection $ds = new IPplanDbf() or myError($w, $p, my_("Could not connect to database")); $rowcnt = 0; $ds->DbfTransactionStart(); if ($format == "xml") { // read entire file $input = implode("", file($filename)); $xml_parser = new xmlnmap("HOST"); if (!$xml_parser->parser) { myError($w, $p, my_("XML not available")); } $output = $xml_parser->parse($input); if (!$output) { myError($w, $p, my_("Data not in XML format")); } foreach ($output as $value) { $rowcnt++; insert($w, textbr()); insert($w, text(my_("Importing record:") . " {$rowcnt} ")); if ($value["STATUS"][0]["STATE"] == "up") { $data[0] = $value["ADDRESS"][0]["ADDR"]; $data[6] = ""; if (isset($value["ADDRESS"][1]["ADDRTYPE"]) and $value["ADDRESS"][1]["ADDRTYPE"] == "mac") { $data[6] = str_replace(array(":", "-", " "), "", $value["ADDRESS"][1]["ADDR"]); } $data[1] = ""; if (!empty($value["OSMATCH"][0]["NAME"])) {
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? if ($retval) { return 1; } else { // no error require_once "../xmllib.php"; $input = implode("", $resarr); // nmap parser always returns arrays for tags of form // [tagname][0...x][element] // array index will mostly be zero if one as most results // return 1 tag $xml_parser = new xmlnmap("HOST"); if (!$xml_parser->parser) { return 1; // XML parser failure - probably not compiled in } $output = $xml_parser->parse($input); if (!$output) { return 1; // not XML format } foreach ($output as $value) { if ($value["STATUS"][0]["STATE"] == "up") { // need to loop through ADDR array here! Check that // ["ADDRESS"][0]["ADDRTYPE"]=="ipv4" or // ["ADDRESS"][0]["ADDRTYPE"]=="mac" $newbase = inet_aton($value["ADDRESS"][0]["ADDR"]); $newmac = ""; if ($value["ADDRESS"][1]["ADDRTYPE"] == "mac") { $newmac = str_replace(array(":", "-", " "), "", $value["ADDRESS"][1]["ADDR"]); } if (empty($value["OSMATCH"][0]["NAME"])) { $newuser = ""; } else { $newuser = $value["OSMATCH"][0]["NAME"]; } $newdescrip = "active"; if (!empty($value["HOSTNAME"][0]["NAME"])) { $newhname = $value["HOSTNAME"][0]["NAME"]; } else { $newhname = ""; } // check within range of subnet before adding to ignore // broadcast and network addresses if ($newbase > $base and $newbase < $base + $size - 1) { $ds->AddIP($newbase, $id, $newuser, "", "", $newmac, $newdescrip, $newhname, ""); // address was polled? So add polled status $ds->UpdateIPPoll($id, $newbase); } } } return 0; } }