ona  18.1.1
About: OpenNetAdmin provides a database managed inventory of your IP network (with Web and CLI interface).
  Fossies Dox: ona-18.1.1.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

report.inc.php
Go to the documentation of this file.
1 <?php
2 
4 // Function: rpt_run()
5 //
6 // Description:
7 // Returns the output for this report.
8 // It will first get the DATA for the report by executing whatever code gathers
9 // data used by the report. This is handled by the rpt_get_data() function.
10 // It will then pass that data to the appropriate output generator.
11 //
12 // A rpt_output_XYZ() function should be written for each type of output format
13 // you want to support. The data from rpt_get_data will be used by this function.
14 //
15 // IN GENERAL, YOU SHOULD NOT NEED TO EDIT THIS FUNCTION
16 //
18 function rpt_run($form, $output_format='html') {
19 
20  $status=0;
21 
22  // See if the output function they requested even exists
23  $func_name = "rpt_output_{$output_format}";
24  if (!function_exists($func_name)) {
25  $rptoutput = "ERROR => This report does not support an '{$form['format']}' output format.";
26  return(array(1,$rptoutput));
27  }
28 
29  // if we are looking for the usage, skip gathering data. Otherwise, gather report data.
30  if (!$form['rpt_usage']) list($status, $rptdata) = rpt_get_data($form);
31 
32  if ($status) {
33  $rptoutput = "NOTICE => There was a problem getting the data. <br> {$rptdata}";
34  }
35  // Pass the data to the output type
36  else {
37  // If the rpt_usage option was passed, add it to the gathered data
38  if ($form['rpt_usage']) $rptdata['rpt_usage'] = $form['rpt_usage'];
39 
40  // Pass the data to the output generator
41  list($status, $rptoutput) = $func_name($rptdata);
42  if ($status)
43  $rptoutput = "ERROR => There was a problem getting the output: {$rptoutput}";
44  }
45 
46  return(array($status,$rptoutput));
47 }
48 
49 
50 
54 
55 
56 
58 // Function: rpt_html_form()
59 //
60 // Description:
61 // Returns the HTML form text for this report.
62 // This is used by the display report code to present an html form to
63 // the user. This simply provides a gui to gather all the input variables.
65 function rpt_html_form($report_name, $rptform='',$rptjs='') {
66  global $images, $color, $style, $conf;
67  $rpthtml = '';
68  $rptjs = '';
69 
70  // Create your input form below
71  $rpthtml .= <<<EOL
72 
73  <form id="{$report_name}_report_form" onsubmit="el('rpt_submit_button').onclick(); return false;">
74  <input type="hidden" value="{$report_name}" name="report"/>
75  Subnet: <input id="subnet" name="subnet" value="{$rptform['subnet']}" class="edit" type="text" size="15" />
76  OR Show global issues: <input id="all" name="all" class="edit" type="checkbox" />
77  <input type="submit"
78  id="rpt_submit_button"
79  title="Search"
80  value="Run Report"
81  class="act"
82  onClick="el('report_content').innerHTML='<br><center><img src={$images}/loading.gif></center><br>';xajax_window_submit('display_report', xajax.getFormValues('{$report_name}_report_form'), 'run_report');"
83  />
84  <input class="act" type="button" name="reset" value="Clear" onClick="clearElements('{$report_name}_report_form');">
85  </form>
86 
87 
88 EOL;
89 
90  // Return the html code for the form
91  return(array(0,$rpthtml,$rptjs));
92 }
93 
94 
95 
96 
97 
98 
99 
100 
101 
102 
103 
104 
105 
106 
107 function rpt_get_data($form) {
108  global $base,$onadb;
109 
110 
111 // If they want to perform a scan on an existing file
112 if ($form['subnet']) {
113  $rptdata['scansource'] = "Based on an existing scan file for '{$form['subnet']}'";
114  //$xml = shell_exec("{$nmapcommand} -sP -R -oX - {$form['subnet']}");
115 
116  list($status, $rows, $subnet) = ona_find_subnet($form['subnet']);
117  if ($rows) {
118  $netip = ip_mangle($subnet['ip_addr'],'dotted');
119  $netcidr = ip_mangle($subnet['ip_mask'],'cidr');
120  $nmapxmlfile = "{$base}/local/nmap_scans/subnets/{$netip}-{$netcidr}.xml";
121 
122  if(file_exists($nmapxmlfile)) {
123  $xml[0]=xml2ary(file_get_contents($nmapxmlfile));
124  } else {
125  $self['error'] = "ERROR => The subnet '{$form['subnet']}' does not have an nmap scan XML file on this server. {$nmapxmlfile}";
126  return(array(2, $self['error']."\n"));
127  }
128  } else {
129  $self['error'] = "ERROR => The subnet '{$form['subnet']}' does not exist.";
130  return(array(2, $self['error']."\n"));
131  }
132 }
133 
134 
135 
136 // If they want to build a report on ALL the nmap data
137 if ($form['all']) {
138  $rptdata['scansource'] = "Showing all scan data";
139 
140  $nmapdir = "{$base}/local/nmap_scans/subnets";
141  $dh = @opendir($nmapdir);
142  $c=0;
143  while (false !== ($filename = @readdir($dh))) {
144  if(strpos($filename, 'xml')) {
145  $xml[$c]=xml2ary(file_get_contents($nmapdir.'/'.$filename));
146  }
147  $c++;
148  }
149 
150 }
151 
152 // If they pass a file from the remote host via CLI
153 if ($form['file']) {
154  $rptdata['scansource'] = "Based on an uploaded XML file";
155 
156  $nmapxmlfile = $form['file'];
157  // clean up escaped characters
158  $nmapxmlfile = preg_replace('/\\\"/','"',$nmapxmlfile);
159  $nmapxmlfile = preg_replace('/\\\=/','=',$nmapxmlfile);
160  $nmapxmlfile = preg_replace('/\\\&/','&',$nmapxmlfile);
161  $xml[0]=xml2ary($nmapxmlfile);
162 }
163 
164 
165 // loop through all the xml arrays that have been built.
166 for($z=0;$z < count($xml); $z++) {
167  // Find out how many total hosts we have in the array
168  $rptdata['totalhosts'] = $xml[$z]['nmaprun']['_c']['runstats']['_c']['hosts']['_a']['total'];
169  $rptdata['runtime'] = $xml[$z]['nmaprun']['_c']['runstats']['_c']['finished']['_a']['timestr'];
170 
171  // pull args to find subnet/cidr
172  $rptdata['args'] = $xml[$z]['nmaprun']['_a']['args'];
173 
174  // process args
175  list($subnetaddr,$netcidr)=explode('/',preg_replace("/.* (.*)\/(\d+)$/","\\1/\\2",$rptdata['args']));
176  $netip = ip_mangle($subnetaddr,'dotted');
177  $netcidr = ip_mangle($netcidr,'cidr');
178 
179  // Process the array for the total amount of hosts reported
180  for($i=0;$i < $rptdata['totalhosts']; $i++) {
181  // Clear MAC each itteration of the loop
182  $macaddr = '';
183  // Gather some info from the nmap XML file
184  $netstatus = $xml[$z]['nmaprun']['_c']['host'][$i]['_c']['status']['_a']['state'];
185  $ipaddr = $xml[$z]['nmaprun']['_c']['host'][$i]['_c']['address']['_a']['addr'];
186  //$macaddr = $xml['nmaprun']['_c']['host'][$i]['_c']['address']['_a']['addr'];
187  $dnsname = $xml[$z]['nmaprun']['_c']['host'][$i]['_c']['hostnames']['_c']['hostname']['_a']['name'];
188  $dnsrows=0;
189  $dns = array();
190 
191  // Try the older nmap format if no IP found.. not sure of what differences there are in the XSL used?
192  if (!$ipaddr) {
193  $ipaddr = $xml[$z]['nmaprun']['_c']['host'][$i]['_c']['address']['0']['_a']['addr'];
194  $macaddr = $xml[$z]['nmaprun']['_c']['host'][$i]['_c']['address']['1']['_a']['addr'];
195  }
196 
197  // Lookup the IP address in the database
198  if ($ipaddr) {
199  list($status, $introws, $interface) = ona_find_interface($ipaddr);
200  if (!$introws) {
201  $interface['ip_addr_text'] = 'NOT FOUND';
202  list($status, $introws, $tmp) = ona_find_subnet($ipaddr);
203  $interface['subnet_id'] = $tmp['id'];
204  } else {
205  // Lookup the DNS name in the database
206  list($status, $dnsrows, $dnscount) = db_get_records($onadb, 'dns', "interface_id = ${interface['id']}", "", 0);
207  list($status, $dnsptrrows, $dnsptr) = ona_get_dns_record(array('interface_id' => $interface['id'], 'type' => 'PTR'));
208  list($status, $dnsprows, $dns) = ona_get_dns_record(array('id' => $dnsptr['dns_id']));
209  }
210  }
211 
212  // Find out if this IP falls inside of a pool
213  $inpool = 0;
214  $ip = ip_mangle($ipaddr,'numeric');
215  if ($ip > 0) { list($status, $poolrows, $pool) = ona_get_dhcp_pool_record("ip_addr_start <= '{$ip}' AND ip_addr_end >= '{$ip}'"); }
216  if ($poolrows) {
217  $inpool = 1;
218  }
219 
220  // some base logic
221  // if host is up in nmap but no db ip then put in $nodb
222  // if host is up and is in db then put in $noissue
223  // if host is down and not in db then skip
224  // if host is down and in db then put in $nonet
225  // if host is up an in db, does DNS match?
226  // in DNS but not DB
227  // in DB but not DNS
228  // DNS and DB dont match
229 
230  // Setup the base array element for the IP
231  $rptdata['ip'][$ipaddr]=array();
232  $rptdata['ip'][$ipaddr]['netstatus'] = $netstatus;
233  $rptdata['ip'][$ipaddr]['netip'] = $ipaddr;
234  $rptdata['ip'][$ipaddr]['netdnsname'] = strtolower($dnsname);
235  if ($macaddr != -1) $rptdata['ip'][$ipaddr]['netmacaddr'] = $macaddr;
236 
237  $rptdata['ip'][$ipaddr]['inpool'] = $inpool;
238 
239  $rptdata['ip'][$ipaddr]['dbip'] = $interface['ip_addr_text'];
240  $rptdata['ip'][$ipaddr]['dbsubnetid'] = $interface['subnet_id'];
241 
242  $rptdata['ip'][$ipaddr]['dbdnsrows'] = $dnsrows;
243 
244  if (!$dns['fqdn']) {
245  // lets see if its a PTR record
246  if ($dnsptrrows) {
247  // If we have a PTR for this interface, use it (never if built from ona?)
248  $rptdata['ip'][$ipaddr]['dbdnsname'] = $dns['fqdn'];
249  $rptdata['ip'][$ipaddr]['dbdnsptrname'] = $dnsp['fqdn'];
250  } else {
251  // find the hosts primary DNS record
252  list($status, $hostrows, $host) = ona_get_host_record(array('id' => $interface['host_id']));
253  if ($host['fqdn']) $host['fqdn'] = "(${host['fqdn']})";
254  if ($dnsrows) {
255  list($status, $dnstmprows, $dnstmp) = ona_get_dns_record(array('interface_id' => $interface['id']));
256  $rptdata['ip'][$ipaddr]['dbdnsname'] = $dnstmp['fqdn'];
257  } else {
258  $rptdata['ip'][$ipaddr]['dbdnsname'] = 'NO PTR';
259  }
260  $rptdata['ip'][$ipaddr]['dbdnsptrname'] = $host['fqdn'];
261  }
262  } else {
263  if ($dnsptrrows > 1) {
264  $rptdata['ip'][$ipaddr]['dbdnsname'] = $dns['fqdn'];
265  $rptdata['ip'][$ipaddr]['dbdnsptrname'] = $dnsp['fqdn'];
266  } else {
267  $rptdata['ip'][$ipaddr]['dbdnsname'] = $dns['fqdn'];
268  $rptdata['ip'][$ipaddr]['dbdnsptrname'] = $dnsp['fqdn'];
269  }
270  }
271  $rptdata['ip'][$ipaddr]['dbmacaddr'] = $interface['mac_addr'];
272 
273  $rptdata['netip'] = $netip;
274  $rptdata['netcidr'] = $netcidr;
275  if ($form['all']) $rptdata['all'] = 1;
276  if ($form['update_response']) $rptdata['update_response'] = 1;
277 
278  }
279 }
280 
281  return(array(0,$rptdata));
282 }
283 
284 
285 
286 
287 
288 
289 function rpt_output_html($form) {
290  global $onadb, $style, $images;
291 
292  if (!$form['scansource']) {
293  $text .= "Please fill out input form.";
294  return(array(0,$text));
295  }
296 
297  if (!$form['all']) {
298  if ($form['totalhosts']) $text .= "NMAP scan of {$form['totalhosts']} hosts done on {$form['runtime']}. {$form['scansource']} <a href=\"local/nmap_scans/subnets/{$form['netip']}-{$form['netcidr']}.xml\">Display RAW scan</a><br>";
299  } else {
300  $text .= "Displaying records for ALL nmap scans in the system. It also only shows issues, not entries that are OK.";
301  }
302 
303  if (!$form['totalhosts'] and !$form['all']) $text .= "ERROR => No hosts found in this NMAP scan, check that the XML file is not empty.<br>";
304 
305  $text .= <<<EOL
306  <table class="list-box" cellspacing="0" border="0" cellpadding="0" style="margin-bottom: 0;">
307  <!-- Table Header -->
308  <tr>
309  <td class="list-header" align="center">NMAP SCAN</td>
310  <td class="list-header" align="center">DATABASE</td>
311  <td class="list-header" align="center">&nbsp;</td>
312  <td class="list-header" align="center">Actions</td>
313  </tr>
314  </table>
315  <div id="nmap_scan_results" style="overflow: auto; width: 100%; height: 89%;border-bottom: 1px solid;">
316  <table class="list-box" cellspacing="0" border="0" cellpadding="0">
317 EOL;
318 
319  // netip netname netmac dbip dbname dbmac
320 
321  $poolhostcount = 0;
322 
323  // find out the broadcast IP for this subnet
324  $num_hosts = 0xffffffff - ip_mangle($form['netcidr'], 'numeric');
325  $broadcastip = ip_mangle((ip_mangle($form['netip'], 'numeric') + $num_hosts),'dotted');
326 
327 
328 
329  foreach ((array)$form['ip'] as $record) {
330 
331  // scans with only one row in them may show up wrong, skip them
332  if (!$record['netstatus'] and !$record['netip']) continue;
333 
334  $act_status_fail = "<img src=\"{$images}/silk/stop.png\" border=\"0\">";
335  $act_status_ok = "<img src=\"{$images}/silk/accept.png\" border=\"0\">";
336  $act_status_partial = "<img src=\"{$images}/silk/error.png\" border=\"0\">";
337 
338  $action = '';
339  $redcolor = '';
340 
341  // button info to view subnet
342  $viewsubnet = <<<EOL
343  <a onclick="xajax_window_submit('work_space', 'xajax_window_submit(\'display_subnet\', \'subnet_id=>{$record['dbsubnetid']}\', \'display\')');" title="Goto this subnet."><img src="{$images}/silk/application.png" border="0"></a>
344 EOL;
345 
346  // Check devices that are down
347  if ($record['netstatus'] == "down") {
348  // Set a red background color
349  $redcolor = "color: red;";
350  // Skip over hosts that are not in network or database
351  if ($record['dbip'] == "NOT FOUND") continue;
352  // If it is only in the database then they should validate the ip or remove from database
353  if (($record['netip'] == $record['dbip']) or ($record['netdnsname'] != $record['dbdnsname'])) {
354  $action = <<<EOL
355  {$act_status_partial}
356  <a title="Ping"
357  class="act"
358  onClick="xajax_window_submit('tooltips', 'name=>tooltips', 'window_progressbar');xajax_window_submit('tooltips', 'ip=>{$record['dbip']}', 'ping');"
359  >Ping to verify</a> then delete as desired
360 EOL;
361  }
362  }
363 
364 
365 
366  // check devices that are up
367  if ($record['netstatus'] == "up") {
368 
369 
370 
371  // If this is the subnet address or broadcast then skip it. Sometimes nmap shows them as up
372  if ($record['netip'] == $form['netip']) continue;
373  if ($record['netip'] == $broadcastip) continue;
374 
375 
376 
377  // Break out the host and domain parts of the name if we can
378  if ($record['netdnsname']) {
379  list($status, $rows, $domain) = ona_find_domain($record['netdnsname'],0);
380  // Now find what the host part of $search is
381  $hostname = str_replace(".{$domain['fqdn']}", '', $record['netdnsname']);
382  }
383 
384  // If we dont find it in the database
385  if ($record['dbip'] == "NOT FOUND") {
386  $action = <<<EOL
387  {$act_status_fail}
388  <a title="Add host."
389  class="act"
390  onClick="xajax_window_submit('edit_host', 'ip_addr=>{$record['netip']},hostname=>{$hostname},domain_id=>{$domain['id']},js=>null', 'editor');"
391  >Add as host</a> or
392  <a title="Add interface."
393  class="act"
394  onClick="xajax_window_submit('edit_interface', 'ip_addr=>{$record['netip']},js=>null', 'editor');"
395  >Add as interface</a>, check proper pool range
396 EOL;
397  }
398  // If it is in the database and network
399  if ($record['netip'] == $record['dbip']) {
400  $action = '&nbsp;'.$act_status_ok.' OK';
401  // But if the names are not the same then action is partial
402  if ($record['netdnsname'] != $record['dbdnsname']) { $action = '&nbsp;'.$act_status_partial.' Update DNS'; }
403  if (strstr($record['dbdnsname'], '(')) { $action = '&nbsp;'.$act_status_partial.' Update DNS PTR'; }
404  }
405 
406 
407  // if the database name is empty, then provide a generic "name"
408  if (!$record['dbdnsname'] and ($record['dbip'] != 'NOT FOUND') and $record['netdnsname']) $record['dbdnsname'] = 'NONE SET';
409 
410  // if the names are different, offer an edit button for the DB
411  if (($record['netdnsname']) and strtolower($record['netdnsname']) != $record['dbdnsname']) {
412  // not a lot of testing here to make sure it will find the right name.
413  list($status, $rows, $rptdnsrecord) = ona_find_dns_record($record['dbdnsname']);
414  $record['dbdnsname'] = <<<EOL
415  <a title="Edit DNS record"
416  class="act"
417  onClick="xajax_window_submit('edit_record', 'dns_record_id=>{$rptdnsrecord['id']},ip_addr=>{$record['dbip']},hostname=>{$hostname},domain_id=>{$domain['id']},js=>null', 'editor');"
418  >{$record['dbdnsname']}</a>
419 EOL;
420  }
421 
422  // If the device is in a dhcp pool range, then count it and identify it.
423  if ($record['inpool'] == 1) {
424  $poolhostcount++;
425  $record['dbip'] = 'DHCP Pooled';
426  $action = '&nbsp; DHCP Pooled device';
427  }
428 
429  }
430 
431 /*
432 TODO:
433 * more testing of mac address stuff
434 * display info about last response time.. add option to update last response form file.. flag if db has newer times than the scan
435 */
436 
437  // If we have more than 2 dns records, display info about them
438  if ($record['dbdnsrows'] > 2) {
439  $dbdnsinfo = "<span style='font-weight: bold;'>{$record['dbdnsname']}&nbsp;{$record['dbdnsptrname']}</span>";
440  } else {
441  $dbdnsinfo = "{$record['dbdnsname']}&nbsp;{$record['dbdnsptrname']}";
442  }
443 
444 
445  $txt = <<<EOL
446  <tr onMouseOver="this.className='row-highlight'" onMouseOut="this.className='row-normal'">
447  <td class="list-row" align="left" style="{$style['borderR']};{$redcolor}">{$record['netstatus']}</td>
448  <td class="list-row" align="left" style="{$redcolor}">{$record['netip']}</td>
449  <td class="list-row" align="left">{$record['netdnsname']}&nbsp;</td>
450  <td class="list-row" align="left" style="{$style['borderR']};">{$record['netmacaddr']}&nbsp;</td>
451  <td class="list-row" align="left">{$record['dbip']}&nbsp;</td>
452  <td class="list-row" align="left">{$dbdnsinfo}</td>
453  <td class="list-row" align="left" style="{$style['borderR']};">{$record['dbmacaddr']}&nbsp;</td>
454  <td class="list-row" align="left">{$viewsubnet}{$action}&nbsp;</td>
455  </tr>
456 EOL;
457 
458 
459  // if we are in all mode, print only errors.. otherwise, print it all
460  if ($form['all'] and strpos($action,'OK')) $txt = '';
461  // add the new line to the html output variable
462  $text .= $txt;
463  }
464 
465 
466  if (!$form['all']) $hostpoolinfo = "Hosts in DHCP pool range: {$poolhostcount}<br>";
467  $text .= "</table>{$hostpoolinfo}<center>END OF REPORT</center></div>";
468 
469 
470  return(array(0,$text));
471 }
472 
473 
474 
475 
476 
477 // csv wrapper function
478 function rpt_output_csv($form) {
479  $form['csv_output'] = true;
480  list($stat,$out) = rpt_output_text($form);
481  return(array($stat,$out));
482 }
483 
484 
485 
486 
487 
488 // output for text
489 function rpt_output_text($form) {
490  global $onadb, $style, $images;
491 
492  // Provide a usage message here
493  $usagemsg = <<<EOL
494 Report: nmap_scan
495  Processes the XML output of an nmap scan and compares it to data in the database.
496 
497  Required:
498  subnet=ID|IP|STRING Subnet ID, IP, or name of existing subnet with a scan
499  OR
500  file=PATH Local XML file will be sent to server for processing
501  OR
502  all Process ALL XML files on the server
503  OR
504  update_response Update the last response field for all UP IPs to time in scan
505 
506  Output Formats:
507  html
508  text
509  csv
510 
511 NOTE: When running update_response, any entry that was updated will have a ~ indication
512  at the beginning of the line.
513  DNS names with a * preceeding them indicate there are more than one name available
514  for this entry and it could have a more common name associated with it.
515 
516 EOL;
517 
518  // Provide a usage message
519  if ($form['rpt_usage']) {
520  return(array(0,$usagemsg));
521  }
522 
523  if (!$form['totalhosts'] and !$form['all']) return(array(1,"\nERROR => No hosts found, check that the XML file is not empty, or that your subnet exists in the database.\n{$usagemsg}"));
524 
525  if (!$form['all']) { $text .= "NMAP scan of {$form['totalhosts']} hosts done on {$form['runtime']}. {$form['scansource']}\n\n";
526  } else {
527  $text .= "Displaying records for ALL nmap scans in the system. It also only shows issues, not entries that are OK.\n\n";
528  }
529 
530  //$text .= sprintf("%-50s %-8s %-8s\n",'NMAP SCAN','DATABASE','Actions');
531  if ($form['csv_output'])
532  $text .= sprintf("%s,%s,%s,%s,%s,%s,%s,%s\n",'STAT','NET IP','NET NAME','NET MAC','DB IP','DB NAME','DB MAC','ACTION');
533  else
534  $text .= sprintf("%-6s %-15s %-25s %-12s %-15s %-25s %-12s %s\n",'STAT','NET IP','NET NAME','NET MAC','DB IP','DB NAME','DB MAC','ACTION');
535 
536  // netip netname netmac dbip dbname dbmac
537 
538  $poolhostcount = 0;
539 
540  // find out the broadcast IP for this subnet
541  // TODO: fix this for ipv6 stuff!
542  $num_hosts = 0xffffffff - ip_mangle($form['netcidr'], 'numeric');
543  $broadcastip = ip_mangle((ip_mangle($form['netip'], 'numeric') + $num_hosts),'dotted');
544 
545  foreach ((array)$form['ip'] as $record) {
546 
547  // scans with only one row in them may show up wrong, skip them
548  if (!$record['netstatus'] and !$record['netip']) continue;
549 
550  $action='';
551  $upresp=' ';
552 
553  // Check devices that are down
554  if ($record['netstatus'] == "down") {
555  // Skip over hosts that are not in network or database
556  if ($record['dbip'] == "NOT FOUND") continue;
557  // If it is only in the database then they should validate the ip or remove from database
558  if (($record['netip'] == $record['dbip']) or ($record['netdnsname'] != $record['dbdnsname'])) {
559  $action = "Ping to verify then delete as desired";
560  }
561  }
562 
563  // check devices that are up
564  if ($record['netstatus'] == "up") {
565 
566  // If this is the subnet address or broadcast then skip it. Sometimes nmap shows them as up
567  if ($record['netip'] == $form['netip']) continue;
568  if ($record['netip'] == $broadcastip) continue;
569 
570  // update the database last response field.
571  if ($form['update_response'] and $record['dbip'] != "NOT FOUND") {
572  //if (isset($options['dcm_output'])) { $text .= "dcm.pl -r interface_modify interface={$record['ip']} set_last_response='{$runtime}'\n"; }
573  list($updatestatus, $output) = run_module('interface_modify', array('interface' => $record['dbip'], 'set_last_response' => $form['runtime']));
574  if ($updatestatus) {
575  $self['error'] = "ERROR => Failed to update response time for '{$record['dbip']}': " . $output;
576  printmsg($self['error'], 1);
577  }
578  $upresp='~';
579  }
580 
581  // Break out the host and domain parts of the name if we can
582  if ($record['netdnsname']) {
583  list($status, $rows, $domain) = ona_find_domain($record['netdnsname'],0);
584  // Now find what the host part of $search is
585  $hostname = str_replace(".{$domain['fqdn']}", '', $record['netdnsname']);
586  }
587 
588  // If we dont find it in the database
589  if ($record['dbip'] == "NOT FOUND") $action = "Add as host or Add as interface, check proper pool range";
590 
591  // If it is in the database and network
592  if ($record['netip'] == $record['dbip']) {
593  $action = 'OK';
594  // But if the names are not the same then action is partial
595  if ($record['netdnsname'] != $record['dbdnsname']) { $action = 'Update DNS'; }
596  if (strstr($record['dbdnsname'], '(')) { $action = 'Update DNS PTR'; }
597  }
598 
599 
600  // if the database name is empty, then provide a generic "name"
601  if (!$record['dbdnsname'] and ($record['dbip'] != 'NOT FOUND') and $record['netdnsname']) $record['dbdnsname'] = 'NONE SET';
602 
603  // if the names are different, offer an edit button for the DB
604  if (($record['netdnsname']) and strtolower($record['netdnsname']) != $record['dbdnsname']) {
605  // not a lot of testing here to make sure it will find the right name.
606  list($status, $rows, $rptdnsrecord) = ona_find_dns_record($record['dbdnsname']);
607  }
608 
609  // If the device is in a dhcp pool range, then count it and identify it.
610  if ($record['inpool'] == 1) {
611  $poolhostcount++;
612  $record['dbip'] = 'DHCP Pooled';
613  $action = 'DHCP Pooled device';
614  }
615  }
616 
617  // If we have more than 2 dns records, display info about them
618  if ($record['dbdnsrows'] > 2) {
619  $record['dbdnsname'] = '*'.$record['dbdnsname'];
620  }
621 
622 /*
623 TODO:
624 * more testing of mac address stuff
625 * display info about last response time.. add option to update last response form file.. flag if db has newer times than the scan
626 */
627  if ($form['csv_output']) {
628  $txt = sprintf("%s,%s,%s,%s,%s,%s,%s,\"%s\"\n", $upresp.$record['netstatus'],$record['netip'],$record['netdnsname'],$record['netmacaddr'],$record['dbip'],$record['dbdnsname'].' '.$record['dbdnsptrname'],$record['dbmacaddr'],$action);
629  } else {
630  $txt = sprintf("%-6s %-15s %-25s %-12s %-15s %-25s %-12s %s\n",$upresp.$record['netstatus'],$record['netip'],$record['netdnsname'],$record['netmacaddr'],$record['dbip'],$record['dbdnsname'].' '.$record['dbdnsptrname'],$record['dbmacaddr'],$action);
631  }
632 
633  // if we are in all mode, print only errors.. otherwise, print it all
634  if ($form['all'] and $action == 'OK') $txt = '';
635  // add the new line to the html output variable
636  $text .= $txt;
637  }
638 
639 
640  if (!$form['all']) $hostpoolinfo = "Hosts in DHCP pool range: {$poolhostcount}\n";
641  $text .= "\n{$hostpoolinfo}END OF REPORT";
642 
643 
644  return(array(0,$text));
645 }
646 
647 
648 
649 
650 
651 
652 
653 
654 /*
655  The following functions were taken from http://mysrc.blogspot.com/2007/02/php-xml-to-array-and-backwards.html
656 */
657 /*
658  Working with XML. Usage:
659  $xml=xml2ary(file_get_contents('1.xml'));
660  $link=&$xml['ddd']['_c'];
661  $link['twomore']=$link['onemore'];
662  // ins2ary(); // dot not insert a link, and arrays with links inside!
663  echo ary2xml($xml);
664 */
665 
666 // XML to Array
667 function xml2ary(&$string) {
668  $parser = xml_parser_create();
669  xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
670  xml_parse_into_struct($parser, $string, $vals, $index);
671  xml_parser_free($parser);
672 
673  $mnary=array();
674  $ary=&$mnary;
675  foreach ($vals as $r) {
676  $t=$r['tag'];
677  if ($r['type']=='open') {
678  if (isset($ary[$t])) {
679  if (isset($ary[$t][0])) $ary[$t][]=array(); else $ary[$t]=array($ary[$t], array());
680  $cv=&$ary[$t][count($ary[$t])-1];
681  } else $cv=&$ary[$t];
682  if (isset($r['attributes'])) {foreach ($r['attributes'] as $k=>$v) $cv['_a'][$k]=$v;}
683  $cv['_c']=array();
684  $cv['_c']['_p']=&$ary;
685  $ary=&$cv['_c'];
686 
687  } elseif ($r['type']=='complete') {
688  if (isset($ary[$t])) { // same as open
689  if (isset($ary[$t][0])) $ary[$t][]=array(); else $ary[$t]=array($ary[$t], array());
690  $cv=&$ary[$t][count($ary[$t])-1];
691  } else $cv=&$ary[$t];
692  if (isset($r['attributes'])) {foreach ($r['attributes'] as $k=>$v) $cv['_a'][$k]=$v;}
693  $cv['_v']=(isset($r['value']) ? $r['value'] : '');
694 
695  } elseif ($r['type']=='close') {
696  $ary=&$ary['_p'];
697  }
698  }
699 
700  _del_p($mnary);
701  return $mnary;
702 }
703 
704 // _Internal: Remove recursion in result array
705 function _del_p(&$ary) {
706  foreach ($ary as $k=>$v) {
707  if ($k==='_p') unset($ary[$k]);
708  elseif (is_array($ary[$k])) _del_p($ary[$k]);
709  }
710 }
711 
712 // Array to XML
713 function ary2xml($cary, $d=0, $forcetag='') {
714  $res=array();
715  foreach ($cary as $tag=>$r) {
716  if (isset($r[0])) {
717  $res[]=ary2xml($r, $d, $tag);
718  } else {
719  if ($forcetag) $tag=$forcetag;
720  $sp=str_repeat("\t", $d);
721  $res[]="$sp<$tag";
722  if (isset($r['_a'])) {foreach ($r['_a'] as $at=>$av) $res[]=" $at=\"$av\"";}
723  $res[]=">".((isset($r['_c'])) ? "\n" : '');
724  if (isset($r['_c'])) $res[]=ary2xml($r['_c'], $d+1);
725  elseif (isset($r['_v'])) $res[]=$r['_v'];
726  $res[]=(isset($r['_c']) ? $sp : '')."</$tag>\n";
727  }
728 
729  }
730  return implode('', $res);
731 }
732 
733 // Insert element into array
734 function ins2ary(&$ary, $element, $pos) {
735  $ar1=array_slice($ary, 0, $pos); $ar1[]=$element;
736  $ary=array_merge($ar1, array_slice($ary, $pos));
737 }
738 
739 
740 
741 
742 
743 
744 
745 
746 
747 
748 
749 
750 
751 ?>
ona_get_host_record
ona_get_host_record($array='', $order='')
Definition: functions_db.inc.php:1106
xml2ary
xml2ary(&$string)
Definition: report.inc.php:667
onclick
_button onclick
Definition: app_advanced_search.inc.php:50
ona_find_domain
ona_find_domain($fqdn="", $returndefault=0)
Definition: functions_db.inc.php:1609
rpt_output_html
rpt_output_html($form)
Definition: report.inc.php:289
ip_mangle
ip_mangle($ip="", $format="default")
Definition: functions_general.inc.php:308
ona_find_subnet
ona_find_subnet($search="")
Definition: functions_db.inc.php:2003
$record
$record['display_name']
Definition: app_advanced_search.inc.php:12
db_get_records
db_get_records($dbh=0, $table="", $where="", $order="", $rows=-1, $offset=-1)
Definition: functions_db.inc.php:891
$status
$status
Definition: install.php:12
$onadb
global $onadb
Definition: 2-to-3.php:15
ary2xml
ary2xml($cary, $d=0, $forcetag='')
Definition: report.inc.php:713
rpt_run
rpt_run($form, $output_format='html')
Definition: report.inc.php:18
printmsg
if(6<=$conf['debug']) printmsg($msg="", $debugLevel=0)
Definition: functions_general.inc.php:48
ona_find_interface
ona_find_interface($search="")
Definition: functions_db.inc.php:1910
$stat
$stat
Definition: install.php:11
$host
$host
Definition: collate-convert.php:19
rpt_output_csv
rpt_output_csv($form)
Definition: report.inc.php:478
run_module
run_module($module='', $options='', $transaction=1)
Definition: functions_general.inc.php:1468
_del_p
_del_p(&$ary)
Definition: report.inc.php:705
ona_get_dhcp_pool_record
ona_get_dhcp_pool_record($array)
Definition: functions_db.inc.php:1276
$images
$images
Definition: config.inc.php:26
EOL
< a style="text-decoration: none;" href="/">< input class='edit' type="button" value="I don't like free stuff?" onclick=""/></a ></center ></div > EOL
Definition: install.php:40
rpt_html_form
rpt_html_form($report_name, $rptform='', $rptjs='')
Definition: report.inc.php:65
$conf
global $conf
Definition: 2-to-3.php:15
rpt_get_data
rpt_get_data($form)
Definition: report.inc.php:107
$style
$style['font-family']
Definition: config.inc.php:158
$ip
$ip
Definition: main.inc.php:24
ins2ary
ins2ary(&$ary, $element, $pos)
Definition: report.inc.php:734
nbsp
& nbsp
Definition: install.php:36
$output
$output
Definition: dcm.php:16
$z
$z
Definition: main.inc.php:27
ona_find_dns_record
ona_find_dns_record($search="", $type='', $int_id=0)
Definition: functions_db.inc.php:1703
rpt_output_text
rpt_output_text($form)
Definition: report.inc.php:489
$text
$text
Definition: install.php:11
$self
global $self
Definition: 2-to-3.php:15
$base
$base
Definition: 2-to-3.php:8
$color
if($_SERVER['SERVER_PORT']==443) $color['bg']
Definition: config.inc.php:119
ona_get_dns_record
ona_get_dns_record($array='', $order='')
Definition: functions_db.inc.php:1142