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)  

app_full_list.inc.php
Go to the documentation of this file.
1 <?php
2 global $conf, $self, $onadb ;
4 
5 
6 // Set the window title:
7 $window['title'] = "List by IP: {$subnet['name']}";
8 
9 // Load some html into $window['html']
10  // HOST LIST
11  $tab = 'hosts';
12  $submit_window = "list_{$tab}";
13  $form_id = "{$submit_window}_filter_form";
14  $_SESSION['ona'][$form_id]['tab'] = $tab;
15  $content_id = "{$window_name}_{$submit_window}";
16  $window['html'] .= <<<EOL
17  <!-- HOST LIST -->
18  <div style="border: 1px solid {$color['border']}; height : 700px; overflow : auto">
19 
20  <!-- Tab & Quick Filter -->
21  <table id="{$form_id}_table" cellspacing="0" border="0" cellpadding="0">
22  <tr>
23  <td id="{$form_id}_{$tab}_tab" >
24  <input id="{$form_id}_{$tab}_count" type="hidden">
25  </td>
26  </tr>
27  </table>
28  <div id='{$content_id}'>
29  {$conf['loading_icon']}
30  </div>
31  </div>
32 EOL;
33 
34 // Define javascript to run after the window is created
35 $window['js'] = <<<EOL
36  /* Tell the browser to load/display the list */
37  xajax_window_submit('app_full_list', 'subnet_id=>{$options['subnet_id']},form_id=>{$form_id},content_id=>{$content_id}', 'display_list');
38 
40 
42 // Function: ws_display()
43 //
44 // Description:
45 // Displays A list of hosts based on search criteria.
46 // Input: An array from xajaxGetFormValues() from a quick filter form.
48 function ws_display($window_name, $form='') {
49 
50 global $conf, $self, $onadb;
52 
53 // If the user supplied an array in a string, build the array and store it in $form
54 $form = parse_options_string($form);
55 printmsg("ws_display in app_full_list.inc.php called with: " . print_r($form,1), 3);
56 
57 $window['title']= "Host List by IP";
58 $window['js'] = <<<EOL
59  /* Put a minimize icon in the title bar */
60  el('{$window_name}_title_r').innerHTML =
61  '&nbsp;<a onClick="toggle_window(\'{$window_name}\');" title="Minimize window" style="cursor: pointer;"><img src="{$images}/icon_minimize.gif" border="0" /></a>' +
62  el('{$window_name}_title_r').innerHTML;
63 
64  /* Put a help icon in the title bar */
65  el('{$window_name}_title_r').innerHTML =
66  '&nbsp;<a href="{$_ENV['help_url']}{$window_name}" target="null" title="Help" style="cursor: pointer;"><img src="{$images}/silk/help.png" border="0" /></a>' +
67  el('{$window_name}_title_r').innerHTML;
68 
69 EOL;
70 
71 // Load some html into $window['html']
72  // HOST LIST
73  $tab = 'hosts_by_ip';
74  $submit_window = "list_{$tab}";
75  $form_id = "{$submit_window}_filter_form";
76  $_SESSION['ona'][$form_id]['tab'] = $tab;
77  $content_id = "{$window_name}_{$submit_window}";
78 
79  if(array_key_exists('ip',$form) && array_key_exists('ip_thru',$form) ) {
80  // Set the window title:
81  $window['subtitle'] = "Range: {$form['ip']} to {$form['ip_thru']}";
82 
83  // Define javascript to run after the window is created
84  $window['js'] .= <<<EOL
85  /* Tell the browser to load/display the list */
86  xajax_window_submit('app_full_list', 'ip=>{$form['ip']},ip_thru=>{$form['ip_thru']},form_id=>{$form_id},content_id=>{$content_id}', 'display_list');
87 
88 EOL;
89 
90  }
91  if(array_key_exists('subnet_id',$form)) {
92  list($status, $rows, $subnet) = ona_get_subnet_record(array('id' => $form['subnet_id']));
93 
94  // Set the window title:
95  $window['subtitle'] = "Subnet: {$subnet['name']}";
96 
97  // Define javascript to run after the window is created
98  $window['js'] .= <<<EOL
99  /* Tell the browser to load/display the list */
100  xajax_window_submit('app_full_list', 'subnet_id=>{$form['subnet_id']},form_id=>{$form_id},content_id=>{$content_id}', 'display_list');
101 
102 EOL;
103 
104  }
105  $window['html'] .= <<<EOL
106  <!-- HOST LIST -->
107  <div style="border: 1px solid {$color['border']}; height : 700px; overflow-y : auto;overflow-x : hidden">
108 
109  <!-- Tab & Quick Filter -->
110  <table id="{$form_id}_table" cellspacing="0" border="0" cellpadding="0">
111  <tr>
112  <td id="{$form_id}_{$tab}_tab" class="table-tab-active">
113  <b>{$window['subtitle']}</b>&nbsp;<span id="{$form_id}_{$tab}_count" />
114  </td>
115  <td>
116  &nbsp;<a onclick="toggle_table_rows('{$form_id}_full_host_list','byip_available');" class="button" ><img src="{$images}/silk/arrow_rotate_clockwise.png" border="0"> Toggle Available IPs</a>
117  </td>
118  </tr>
119  </table>
120  <div id='{$content_id}'>
121  {$conf['loading_icon']}
122  </div>
123  </div>
124 EOL;
125 
126 
127  return(window_open($window_name, $window));
128 
129 }
130 
132 // Function: ws_display_list()
133 //
134 // Description:
135 // Displays A list of hosts based on search criteria.
136 // Input: An array from xajaxGetFormValues() from a quick filter form.
138 function ws_display_list($window_name, $form='') {
139  global $conf, $self, $onadb;
140  global $images, $color, $style;
141  $html = '';
142  $js = '';
143 
144  // If the user supplied an array in a string, build the array and store it in $form
145  $form = parse_options_string($form);
146 
147  // Find the "tab" we're on
148  $tab = $_SESSION['ona'][$form['form_id']]['tab'];
149 
150  // Build js to refresh this list
151  $refresh = "xajax_window_submit('{$window_name}', xajax.getFormValues('{$form['form_id']}'), 'display_list');";
152 
153 
154  // Search results go in here
155  $results = array();
156  $count = 0;
157 
158 
159  // NETWORK ID
160  if (is_numeric($form['subnet_id'])) {
161 
162  }
163 
164  // Do the SQL Query
165  list ($status, $count, $results) =
167  $onadb,
168  'interfaces',
169  "subnet_id = " . $onadb->qstr($form['subnet_id']) ,
170  'ip_addr',
171  -1,
172  -1
173  );
174 
175  // make an array of ips from our results
176  $iplist=array();
177  foreach($results as $record) {
178  $iplist["{$record['ip_addr']}"]='used';
179  }
180 
181  list($status, $rows, $subnet) = ona_find_subnet($form['subnet_id']);
182 
183  // Create a few variables that will be handy later
184  $num_ips = 0xffffffff - $subnet['ip_mask'];
185  $last_ip = ($subnet['ip_addr'] + $num_ips) - 1;
186  $currip = $subnet['ip_addr'] + 1;
187 
188  // Get a list of blocks that touches this subnet
189  list($status, $blockrows, $blocks) = db_get_records($onadb, 'blocks', "{$subnet['ip_addr']} BETWEEN ip_addr_start AND ip_addr_end OR {$last_ip} BETWEEN ip_addr_start AND ip_addr_end OR ip_addr_start BETWEEN {$subnet['ip_addr']} and {$last_ip}");
190 
191  // Get a list of dhcp pools on the selected subnet
192  list($status, $rows, $pools) =
193  db_get_records($onadb, 'dhcp_pools', array('subnet_id' => $subnet['id']));
194 
195  // Add DHCP pool addresses into the list of used ips
196  foreach ($pools as $pool)
197  for ($ip = $pool['ip_addr_start']; $ip <= $pool['ip_addr_end']; $ip++)
198  $iplist["{$ip}"] = 'pool-'.$pool['id'];
199 
200  //
201  // *** BUILD HTML LIST ***
202  //
203  $html .= <<<EOL
204  <!-- Host Results -->
205  <table id="{$form['form_id']}_full_host_list" class="list-box" cellspacing="0" border="0" cellpadding="0">
206 
207  <!-- Table Header -->
208  <tr>
209  <td class="list-header" align="center" style="{$style['borderR']};" title="IP Block Association">B</td>
210  <td class="list-header" align="center" style="{$style['borderR']};">IP Address</td>
211  <td class="list-header" align="center" style="{$style['borderR']};">Last Response</td>
212  <td class="list-header" align="center" style="{$style['borderR']};">[Name] Desc</td>
213  <td class="list-header" align="center" style="{$style['borderR']};">Host Name</td>
214  <td class="list-header" align="center" style="{$style['borderR']};">Device Type</td>
215  <td class="list-header" align="center" style="{$style['borderR']};">Host Notes</td>
216  </tr>
217 EOL;
218  // Loop and display each ip on the subnet
219  while ($currip <= $last_ip) {
220 
221  $loc=array();
222  $host=array();
223  $interface=array();
224  $interfaces=0;
225  $record=array();
226  $interface_style = '';
227  $clusterhtml = '';
228  $rowstyle='background-color: #E9FFE1';
229  $rowid='byip_available';
230  $currip_txt = ip_mangle($currip, 'dotted');
231  $interface['desc'] = '<span style="color: #aaaaaa;">AVAILABLE</span>';
232  $nameval=<<<EOL
233  <a title="Add host"
234  class="act"
235  onClick="xajax_window_submit('edit_host', 'ip_addr=>{$currip_txt}', 'editor');"
236  ></a>&nbsp;
237 
238  <a title="Add host"
239  class="act"
240  onClick="xajax_window_submit('edit_host', 'ip_addr=>{$currip_txt}', 'editor');"
241  >Add a new host</a>&nbsp;
242 
243  <a title="Add interface"
244  class="act"
245  onClick="xajax_window_submit('edit_interface', 'ip_addr=>{$currip_txt}', 'editor');"
246  ></a>&nbsp;
247 
248  <a title="Add interface"
249  class="act"
250  onClick="xajax_window_submit('edit_interface', 'ip_addr=>{$currip_txt}', 'editor');"
251  >Add interface to an existing host</a>&nbsp;
252 
253 EOL;
254 
255  // If the current ip is one allocated on this subnet lets do some stuff
256  if (array_key_exists($currip, $iplist)) {
257  $rowid='byip_allocated';
258  $rowstyle='';
259 
260  // check if it is a pool range
261  list($pooltype,$poolid) = explode('-',$iplist[$currip]);
262  if ($pooltype == 'pool') {
263  $interface['desc'] = '<span style="color: #aaaaaa;">DHCP Pool</span>';
264  $rowstyle='background-color: #FFFBD6';
265  $nameval=<<<EOL
266  <a title="Edit Pool"
267  class="act"
268  onClick="xajax_window_submit('edit_dhcp_pool', 'subnet=>{$subnet['id']},id=>{$poolid}', 'editor');"
269  ><img src="{$images}/silk/page_add.png" border="0"></a>&nbsp;
270 
271  <a title="Edit Pool"
272  class="act"
273  onClick="xajax_window_submit('edit_dhcp_pool', 'subnet=>{$subnet['id']},id=>{$poolid}', 'editor');"
274  >Edit DHCP Pool</a>&nbsp;
275 EOL;
276 
277  } else {
278  // Get host record
279  list($status, $rows, $host) = ona_find_host($currip);
280 
281  // Get the interface info
282  list($status, $rows, $interface) = ona_find_interface($currip);
283 
284  // Count how many interface rows this host hasand assign it back to the interfaces variable
285  list($status, $interfaces, $records) = db_get_records($onadb, 'interfaces', 'host_id = '. $onadb->qstr($host['id']), "", 0);
286 
287  // get interface cluster info
288  list ($status, $intclusterrows, $intcluster) = db_get_records($onadb, 'interface_clusters', "interface_id = {$interface['id']}");
289  if ($intclusterrows>0) {
290  $clusterscript= "onMouseOver=\"wwTT(this, event,
291  'id', 'tt_interface_cluster_list_{$interface['id']}',
292  'type', 'velcro',
293  'styleClass', 'wwTT_niceTitle',
294  'direction', 'south',
295  'javascript', 'xajax_window_submit(\'tooltips\', \'tooltip=>interface_cluster_list,id=>tt_interface_cluster_list_{$interface['id']},interface_id=>{$interface['id']}\');'
296  );\"";
297  $clusterhtml .= <<<EOL
298  <img src="{$images}/silk/sitemap.png" {$clusterscript} />
299 EOL;
300  }
301 
302  // set the name value for an allocated host
303  $nameval = <<<EOL
304  <a title="View host. ID: {$host['id']}"
305  class="nav"
306  onClick="xajax_window_submit('work_space', 'xajax_window_submit(\'display_host\', \'host_id=>{$host['id']}\', \'display\')');"
307  >{$host['name']}</a
308  >.<a title="View domain. ID: {$host['domain_id']}"
309  class="domain"
310  onClick="xajax_window_submit('work_space', 'xajax_window_submit(\'display_domain\', \'domain_id=>{$host['domain_id']}\', \'display\')');"
311  >{$host['domain_fqdn']}</a>
312 EOL;
313 
314  // Make it bold if we have more than one interface on this host
315  if ($interfaces > 1) {
316  $interface_style = 'font-weight: bold;';
317  }
318 
319  // Device Description
320  list($status, $rows, $device) = ona_find_device($host['device_id']);
321  list($status, $rows, $device_type) = ona_get_device_type_record(array('id' => $device['device_type_id']));
322  list($status, $rows, $role) = ona_get_role_record(array('id' => $device_type['role_id']));
323  list($status, $rows, $model) = ona_get_model_record(array('id' => $device_type['model_id']));
324  list($status, $rows, $manufacturer) = ona_get_manufacturer_record(array('id' => $model['manufacturer_id']));
325  $record['device'] = "{$manufacturer['name']}, {$model['name']} ({$role['name']})";
326  $record['device'] = str_replace('Unknown', '?', $record['device']);
327 
328  $record['notes_short'] = truncate($host['notes'], 40);
329  $interface['description_short'] = truncate($interface['description'], 40);
330 
331  if ($interface['name'] ) $interface['name'] = "[{$interface['name']}]";
332  $interface['desc'] = "{$interface['name']} {$interface['description_short']}";
333 
334  // Format the date and colorize if its older than 2 months
335  if ($interface['last_response']) {
336  $interface['last_response'] = date($conf['date_format'],strtotime($interface['last_response']));
337  if (strtotime($interface['last_response']) < strtotime('-2 month')) {
338  $interface['last_response_fmt'] = 'style=color:red;';
339  }
340  }
341 
342  // Get location info
343  list($status, $rows, $loc) = ona_get_location_record(array('id' => $device['location_id']));
344 
345  }// end real host ifblock
346 
347  } // end while loop
348 
349  // Escape data for display in html
350  foreach(array_keys($record) as $key) { $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']); }
351 
352  $html .= <<<EOL
353  <tr {$rowid}=true style="{$rowstyle}" onMouseOver="this.className='row-highlight'" onMouseOut="this.className='row-normal'">
354 
355 EOL;
356 
357  // Print color info for any matching blocks
358  $c=0;
359  $blockcolors=array('#CD5C5C','#588C7E','#8C4646','#FFD700','#1E90F0','#8A2BE2','#32CD32','#D96459');
360  if ($blockrows) {
361  $html .= "<td class='list-row' nowrap style='padding:0'>";
362  foreach ($blocks as $block) {
363  if ($currip >= $block['ip_addr_start'] && $currip <= $block['ip_addr_end']) {
364  $html .= "<span title='{$block['name']}' style='background-color:{$blockcolors[$c]};padding-bottom:4px;float:left;'>&nbsp;&nbsp</span> ";
365  }
366  $c++;
367  }
368  } else {
369  // print an empty table cell
370  $html .= "<td class='list-row'>";
371  }
372 
373  $html .= <<<EOL
374  </td>
375  <td class="list-row" align="left">
376 EOL;
377  // if it is used, show an edit interface link
378  if ($rowid == 'byip_allocated') {
379  $html .= <<<EOL
380  <a class="nav" style="{$interface_style}" title="Edit interface ID: {$interface['id']}"
381  onClick="xajax_window_submit('edit_interface', 'interface_id=>{$interface['id']}', 'editor');"
382 EOL;
383 
384  if ($interfaces > 1) {
385  $html .= <<<EOL
386  onMouseOver="wwTT(this, event,
387  'id', 'tt_host_interface_list_{$host['id']}',
388  'type', 'velcro',
389  'styleClass', 'wwTT_niceTitle',
390  'direction', 'south',
391  'javascript', 'xajax_window_submit(\'tooltips\', \'tooltip=>host_interface_list,id=>tt_host_interface_list_{$host['id']},host_id=>{$host['id']}\');'
392  );"
393 EOL;
394  }
395  $html .= '>';
396 
397  }
398 
399 
400  //print out the IP address
401  $html .= $currip_txt;
402 
403  // close the A tag if used above
404  if ($rowid == 'byip_allocated') { $html .= '</a>';}
405 
406  // Keep on goin with the rest of the line
407  $html .= <<<EOL
408 
409  &nbsp;<span>{$clusterhtml}</span>
410  </td>
411 
412  <td class="list-row" {$interface['last_response_fmt']}>{$interface['last_response']}&nbsp;</td>
413 
414  <td class="list-row">
415  <span title="{$interface['description']}">{$interface['desc']}</span>&nbsp;
416  </td>
417 
418  <td class="list-row" style="border-left: 1px solid; border-left-color: #aaaaaa;">
419  {$nameval}
420  </td>
421 
422  <td class="list-row">{$record['device']}&nbsp;</td>
423 
424  <td class="list-row">
425  <span title="{$host['notes']}">{$record['notes_short']}</span>&nbsp;
426  </td>
427 
428  </tr>
429 EOL;
430 
431  // increment the currip
432  $currip++;
433 
434  }
435 
436 
437  $html .= <<<EOL
438  </table>
439 EOL;
440 
441 
442  $js .= <<<EOL
443  /* Make sure this table is 100% wide */
444  el('{$form['form_id']}_full_host_list').style.width = el('{$form['form_id']}_table').offsetWidth + 'px';
445 
446 function togglebyip(name) {
447  tr=document.getElementsByTagName('tr')
448  for (i=0;i<tr.length;i++){
449  if (tr[i].getAttribute(name)){
450  if (tr[i].style.display=='none'){tr[i].style.display = '';}
451  else {tr[i].style.display = 'none';}
452  }
453  }
454 }
455 EOL;
456 
457 
458 
459  // Insert the new html into the content div specified
460  // Instantiate the xajaxResponse object
461  $response = new xajaxResponse();
462  $response->addAssign("{$form['form_id']}_{$tab}_count", "innerHTML", "({$count})");
463  $response->addAssign($form['content_id'], "innerHTML", $html);
464  if ($js) { $response->addScript($js); }
465  return($response->getXML());
466 }
467 
468 
469 
470 
471 
472 
473 
474 
475 
476 
477 
478 
479 ?>
$form_id
$form_id
Definition: app_full_list.inc.php:13
ona_get_manufacturer_record
ona_get_manufacturer_record($array)
Definition: functions_db.inc.php:1210
$font_family
global $font_family
Definition: app_full_list.inc.php:3
ona_get_location_record
ona_get_location_record($array='', $order='')
Definition: functions_db.inc.php:1122
onclick
_button onclick
Definition: app_advanced_search.inc.php:50
Name
Full Name
Definition: app_user_info.inc.php:101
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
ona_find_host
ona_find_host($search="")
Definition: functions_db.inc.php:1490
$record
$record['display_name']
Definition: app_advanced_search.inc.php:12
$images
global $images
Definition: app_full_list.inc.php:3
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
$conf
global $conf
Definition: app_full_list.inc.php:2
$content_id
$content_id
Definition: app_full_list.inc.php:15
ona_get_role_record
ona_get_role_record($array)
Definition: functions_db.inc.php:1222
ona_get_device_type_record
ona_get_device_type_record($array)
Definition: functions_db.inc.php:1214
$window
$window['title']
Definition: app_full_list.inc.php:7
ws_display
ws_display($window_name, $form='')
Definition: app_full_list.inc.php:48
ona_get_model_record
ona_get_model_record($array)
Definition: functions_db.inc.php:1197
$tab
$tab
Definition: app_full_list.inc.php:11
printmsg
if(6<=$conf['debug']) printmsg($msg="", $debugLevel=0)
Definition: functions_general.inc.php:48
truncate
truncate($msg="", $length=0)
Definition: functions_general.inc.php:209
$color
global $color
Definition: app_full_list.inc.php:3
ws_display_list
ws_display_list($window_name, $form='')
Definition: app_full_list.inc.php:138
ona_find_interface
ona_find_interface($search="")
Definition: functions_db.inc.php:1910
window_open
window_open($window_name, $window=array())
Definition: webwin.inc.php:59
$self
global $self
Definition: app_full_list.inc.php:2
$host
$host
Definition: collate-convert.php:19
ona_find_device
ona_find_device($search="")
Definition: functions_db.inc.php:2105
xajaxResponse
Definition: xajaxResponse.inc.php:68
$submit_window
$submit_window
Definition: app_full_list.inc.php:12
$style
global $style
Definition: app_full_list.inc.php:3
$ip
$ip
Definition: main.inc.php:24
nbsp
& nbsp
Definition: install.php:36
EOL
EOL
Definition: app_full_list.inc.php:39
$_SESSION
$_SESSION['ona'][$form_id]['tab']
Definition: app_full_list.inc.php:14
ona_get_subnet_record
ona_get_subnet_record($array)
Definition: functions_db.inc.php:1226
parse_options_string
parse_options_string($input)
Definition: xajax_setup.inc.php:88
$onadb
global $onadb
Definition: app_full_list.inc.php:2