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)  

tooltips.inc.php
Go to the documentation of this file.
1 <?php
2 
4 // Function: ws_submit($input)
5 //
6 // Description:
7 // Inserts dynamic content into a tool-tip popup.
8 // $form is a string array that should look something like this:
9 // "tooltip=>location,id=>element_id,location_id=>143324"
11 function ws_tooltips_submit($window_name, $form='') {
12  global $conf, $self, $onadb, $tip_style;
14  $html = $js = '';
15 
16  // If an array in a string was provided, build the array and store it in $form
17  $form = parse_options_string($form);
18 
19  printmsg("DEBUG => Displaying tooltip: {$form['tooltip']}", 4);
20 
21  switch ($form['tooltip']) {
22  case 'sys_alert':
23  list ($html, $js) = get_sys_alert_html($form);
24  break;
25 
26  case 'loginform':
27  list ($html, $js) = get_loginform_html($form);
28  break;
29 
30  case 'start_menu':
31  list ($html, $js) = get_start_menu_html();
32  break;
33 
34  case 'local_menu':
35  list ($html, $js) = get_local_menu_html();
36  break;
37 
38  case 'location':
39  $record['location_id'] = $form['location_id'];
40  $extravars['tipstyle'] = 'style="color: #FFFFFF;background-color: #4c4c4c;border: none;"';
41  $wspl = workspace_plugin_loader('location_detail',$record,$extravars);
42  $html .= $wspl[0]; $js .= $wspl[1];
43  break;
44 
45  case 'subnet':
46  list ($html, $js) = get_subnet_html($form['subnet_ip']);
47  break;
48 
49  case 'qf_subnet':
50  list ($html, $js) = quick_subnet_search($form);
51  break;
52 
53  case 'qf_location':
54  list ($html, $js) = quick_location_search($form);
55  break;
56 
57  case 'qf_vlan':
58  list ($html, $js) = quick_vlan_search($form);
59  break;
60 
61  case 'qf_free_ip':
62  list ($html, $js) = quick_free_ip_search($form);
63  break;
64 
65  case 'qf_pool_server':
66  list ($html, $js) = quick_pool_server_search($form);
67  break;
68 
69  case 'quick_interface_menu':
70  list ($html, $js) = quick_interface_menu($form);
71  break;
72 
73  case 'quick_interface_move':
74  list ($html, $js) = quick_interface_move($form);
75  break;
76 
77  case 'quick_interface_nat':
78  list ($html, $js) = quick_interface_nat($form);
79  break;
80 
81  case 'quick_interface_share':
82  list ($html, $js) = quick_interface_share($form);
83  break;
84 
85  case 'qf_tag':
86  list ($html, $js) = quick_tag_add($form);
87  break;
88 
89  case 'host_interface_list':
90  list ($html, $js) = get_host_interface_list_html($form);
91  break;
92 
93  case 'cainfo':
94  list ($html, $js) = get_custom_attribute_info_html($form);
95  break;
96 
97  case 'interface_cluster_list':
98  list ($html, $js) = get_interface_cluster_list_html($form);
99  break;
100 
101  case 'switchport_template_select':
102  list ($html, $js) = get_switchport_template_select($form);
103  break;
104 
105  }
106 
107 
108  // Okay here's what we do:
109  // 1. Hide the tool-tip
110  // 2. Update it's content
111  // 3. Reposition it
112  // 4. Unhide it
113  $response = new xajaxResponse();
114  $response->addScript("el('{$form['id']}').style.visibility = 'hidden';");
115  $response->addAssign($form['id'], "innerHTML", $html);
116  $response->addScript("wwTT_position('{$form['id']}'); el('{$form['id']}').style.visibility = 'visible';");
117  if ($js) { $response->addScript($js); }
118  return($response->getXML());
119 }
120 
121 
123 // Function for usort to sort tag list, used by ws_tag_html
124 // Example: usort($array, 'tagsort');
126 function tagsort($a, $b) {
127  return strcmp($a["name"], $b["name"]);
128 }
129 
131 // Update HTML list of tags for specified type
132 // the tag lists will have 5 items per line
133 // The output will be placed in the innerHTML of the 'updateid' dom element
134 //
135 // Form needs to have, type, reference, updateid
137 function ws_tag_html($window_name, $form='') {
138  global $conf, $self, $base, $onadb;
139 
140  $html = $js = '';
141 
142  // If the user supplied an array in a string, build the array and store it in $form
143  $form = parse_options_string($form);
144 
145  $c=1;
146  // Gather a list of tags to display
147  list($status, $rows, $tags) = db_get_records($onadb, 'tags', "type = '{$form['type']}' and reference = {$form['reference']}");
148  usort($tags, 'tagsort');
149  foreach ( $tags as $tag ) {
150  $html .= <<<EOL
151 <span id="tagname_{$tag['name']}{$tag['id']}"
152  class="tag"
153 EOL;
154 
155  // only show delete button when you have permission
156  if (auth('host_del') or auth('subnet_del')) {
157  $html .= <<<EOL
158  onmouseover="el('tagdel_{$tag['name']}{$tag['id']}').style.display='';"
159  onmouseout="el('tagdel_{$tag['name']}{$tag['id']}').style.display='none';"
160 EOL;
161  }
162 
163  $html .= <<<EOL
164  >{$tag['name']}<span id="tagdel_{$tag['name']}{$tag['id']}"
165  class="tagdel"
166  style="display:none"
167  onClick="xajax_window_submit('edit_tag', 'id => {$tag['id']}', 'delete');el('tagname_{$tag['name']}{$tag['id']}').style.display='none';">x</span></span>
168 EOL;
169 
170  // print a new line each $c tags
171  $c++;
172  if ( $c > 5 ) { $html .= "<br>"; $c=1; }
173  }
174 
175  $response = new xajaxResponse();
176  $response->addAssign($form['updateid'], "innerHTML", $html);
177  // set extra width in the table so the delete button looks better
178  $response->addScript("tagTdWidth=el('tagname_{$tag['name']}{$tag['id']}').parentNode.parentNode.offsetWidth+8;el('tagname_{$tag['name']}{$tag['id']}').parentNode.parentNode.setAttribute('style','width:'+tagTdWidth+'px');");
179  return($response->getXML());
180 }
181 
182 
183 
184 
186 // Function: get_message_lines_html($where)
187 //
188 // Description:
189 // Builds HTML for messages
190 // Returns a two part array ($html, $js)
192 function get_message_lines_html($where) {
193  global $conf, $self, $onadb, $tip_style;
194  global $font_family, $color, $style, $images, $msgtype;
195 
196  $html = $js = '';
197  $expire_count = 0;
198 
199  list($status, $rows, $messages) = db_get_records($onadb, 'messages', $where, 'priority,mtime', 15, 0);
200 
201  // If we don't find any rows, go ahead and return
202  if (!$rows)
203  return(array($html, $js));
204 
205  $html .= <<<EOL
206  <div style="overflow: auto;max-height: 100px;">
207  <table style="cursor: pointer;" width="100%" cellspacing="0" border="0" cellpadding="0">
208  <tbody style="max-height: 100px;overflow: auto;overflow-x: hidden;">
209 EOL;
210 
211  foreach ($messages as $record) {
212  // If the message has expired, dont print it.
213  if (strtotime($record['expiration']) < time()) {
214  $expire_count++;
215  continue;
216  }
217 
218 
219  // Escape data for display in html
220  foreach(array_keys((array)$record) as $key) {$record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']);}
221 
222  // determine the priority and setup an image for it
223  switch ($record['priority']) {
224  case 0:
225  $priorityimg = "<img src=\"{$images}/silk/bullet_blue.png\" border=\"0\" />";
226  break;
227  case 1:
228  $priorityimg = "<img src=\"{$images}/silk/bullet_red.png\" border=\"0\" />";
229  break;
230  case 2:
231  $priorityimg = "<img src=\"{$images}/silk/bullet_yellow.png\" border=\"0\" />";
232  break;
233  case 3:
234  $priorityimg = "<img src=\"{$images}/silk/bullet_green.png\" border=\"0\" />";
235  break;
236  default:
237  $priorityimg = "";
238  break;
239  }
240 
241  // re format the date to something more appropriate
242  $cleandate = date("m/d-h:i a",strtotime($record['mtime']));
243  $expire = strtotime($record['expiration']) . "/" . time() ."=". $test;
244 
245  $html .= <<<EOL
246  <tr style="height: 10px;"
247  onMouseOver="this.className='row-highlight';"
248  onMouseOut="this.className='row-normal';"
249  >
250  <td nowrap="true" title="{$record['mtime']} - Priority level: {$record['priority']} - Expires: {$record['expiration']}" valign="top" style="font-size: 10px; pad
251 ding: 0px 3px;">{$cleandate} {$priorityimg}</td>
252  <td nowrap="true" valign="top" align="right" style="font-size: 10px; padding: 0px 0px;">{$record['username']} =></td>
253  <td width="200" style="font-size: 10px; padding: 0px 2px;padding-right: 20px;">{$record['message_text']}</td>
254  </tr>
255 EOL;
256  }
257 
258  if ($expire_count > 0 ) {
259  $html .= <<<EOL
260  <tr class="row-highlight" >
261  <td colspan=3 align="center" nowrap="true" valign="top" style="font-size: 10px; padding: 0px 3px;">There are {$expire_count} expired records not displayed</td>
262  </tr>
263 EOL;
264  }
265 
266  $html .= <<<EOL
267  </tbody></table></div>
268 EOL;
269 
270  return(array($html, $js));
271 
272 }
273 
274 
275 
276 
277 
278 
279 
280 
281 
283 // Function: get_sys_alert_html($form)
284 //
285 // Description:
286 // Builds HTML for changing tacacs enable passwd
287 // Returns a two part array ($html, $js)
289 function get_sys_alert_html($form) {
290  global $conf, $self, $onadb, $tip_style;
291  global $font_family, $color, $style, $images, $msgtype;
292 
293  $html = $js = '';
294 
295 
296  $style['content_box'] = <<<EOL
297  padding: 2px 4px;
298  vertical-align: top;
299 EOL;
300 
301  // WARNING: this one's different than most of them!
302  $style['label_box'] = <<<EOL
303  font-weight: bold;
304  cursor: move;
305  color: #FFFFFF;
306 EOL;
307 
308  // Display system messages
309  $html .= <<<EOL
310 
311  <!-- SYS MESSAGES -->
312  <form id="sys_alert_form" onSubmit="return(false);">
313  <input type="hidden" name="id" value="{$form['id']}">
314  <input type="hidden" name="input_id" value="{$form['input_id']}">
315  <input type="hidden" name="text_id" value="{$form['text_id']}">
316  <table style="{$style['content_box']}" cellspacing="0" border="0" cellpadding="0">
317 
318  <tr><td colspan="2" align="center" class="qf-search-line" style="{$style['label_box']}; padding-top: 0px;" onMouseDown="dragStart(event, '{$form['id']}', 'savePosition'
319 , 0);">
320  System Messages
321  </td></tr>
322 
323  <tr>
324  <td colspan="2" align="left" class="qf-search-line">
325  <div
326  id="sys_alert_items"
327  style="
328  background-color: #FFFFFF;
329  overflow: auto;"
330  >
331 EOL;
332  // Get a list of messages that have a table name of SYS_*
333  list($lineshtml, $linesjs) = get_message_lines_html("`table_name_ref` LIKE 'SYS_%'");
334  $html .= $lineshtml;
335 
336  $html .= <<<EOL
337  </div>
338  </td>
339  </tr>
340 
341  <tr>
342  <td align="right" class="qf-search-line">
343  &nbsp;
344  </td>
345  <td align="right" class="qf-search-line">
346  <input class="button" type="button" name="close" value="Close" onClick="removeElement('{$form['id']}');">
347  </td>
348  </tr>
349 
350  </table>
351  </form>
352 EOL;
353 
354 
355  return(array($html, $js));
356 }
357 
358 
359 
361 // Function: switch_context (string $context_name)
362 //
363 // $context_name = The name of the context to switch to
364 //
365 // Switches the current context cookie and reloads the interface
366 // This is meant to be called by the GUI only and not by DCM etc
367 //
369 function ws_switch_context($window_name, $form='') {
370  global $conf, $self, $ona_contexts, $baseURL;
371 
372  $html = $js = '';
373  $form = parse_options_string($form);
374 
375  // If the context passed in is in our array, switch
376  if (isset($ona_contexts[$form['context_select']])) {
377  printmsg("INFO => Switching to context: {$form['context_select']}",0);
378  setcookie("ona_context_name", $form['context_select']);
379  $js = "window.location='{$baseURL}';";
380  }
381  // Otherwise, complain
382  else {
383  printmsg("DEBUG => There was an error switching to context: {$form['context_select']}",1);
384  $js = "alert('The context \'{$form['context_select']}\' is not valid.');";
385  }
386 
387  $response = new xajaxResponse();
388  $response->addScript($js);
389  return($response->getXML());
390 }
391 
392 
393 
394 
396 // Function: get_loginform_html($form)
397 //
398 // Description:
399 // Builds HTML for logging in as a new user
400 // Returns a two part array ($html, $js)
402 function get_loginform_html($form) {
403  global $conf, $self, $onadb, $tip_style;
404  global $font_family, $color, $style, $images;
405 
406  $html = $js = '';
407 
408 
409  $style['content_box'] = <<<EOL
410  padding: 2px 4px;
411 
412 EOL;
413 
414  // WARNING: this one's different than most of them!
415  $style['label_box'] = <<<EOL
416  font-weight: bold;
417  cursor: move;
418  color: #FFFFFF;
419 EOL;
420 
421  // Display system messages
422  $html .= <<<EOL
423 
424  <!-- LOGIN PROMPT -->
425  <form id="loginform_form" onSubmit="return false;">
426  <input id="onapassword" type="hidden" name="onapassword">
427  <table style="{$style['content_box']}" cellspacing="0" border="0">
428 
429  <tr >
430  <td nowrap="true" align="right">
431  <b>Username</b>&nbsp;
432  </td>
433  <td>
434  <input id="onausername" class="edit" autocomplete="off" name="onausername" type="edit" size="12" onkeypress="if (event.keyCode == 13) { el('getpass').focus(); }">
435  </td>
436  </tr>
437  <tr>
438  <td nowrap="true" align="right">
439  <b>Password</b>&nbsp;
440  </td>
441  <td>
442  <input id="getpass" class="edit" autocomplete="off" name="getpass" type="password" size="12" onkeypress="if (event.keyCode == 13) { el('loginbutton').click(); }">
443  </td>
444  </tr>
445  <tr><td></td>
446  <td nowrap="true">
447  <input class="button"
448  type="button"
449  name="cancel"
450  value="Cancel"
451  onClick="removeElement('{$form['id']}');"
452  >
453  <input class="button"
454  id="loginbutton"
455  type="button"
456  name="login"
457  value="Login"
458  onClick="el('onapassword').value = el('getpass').value;
459  xajax_window_submit('tooltips', xajax.getFormValues('loginform_form'), 'logingo');"
460  >
461  </td>
462  </tr>
463  <tr>
464  <td colspan="2" align="center">
465  <span id="loginmsg" style="color: red;font-size: x-small;"></span>
466  </td>
467  </tr>
468 
469  </table>
470  </form>
471 EOL;
472 
473  $js = "el('onausername').focus();";
474 
475 
476  return(array($html, $js));
477 }
478 
479 
480 
482 // Function: ws_logingo($window_name, $form)
483 //
484 // Description:
485 // Runs the actual login switch after hitting the login button in the tooltip
487 function ws_logingo($window_name, $form='') {
488  global $conf, $self, $onadb, $baseURL;
489  global $font_family, $color, $style, $images;
490 
491  $html = $js = '';
492  $form = parse_options_string($form);
493  $type='Desktop';
494 
495  if ($form['standalone']) $type='Standalone';
496 
497  printmsg("INFO => [{$type}] Attempting login as " . $form['onausername'], 4);
498 
499  list($status, $js) = get_authentication($form['onausername'],$form['onapassword']);
500 
501  if ($status==0) {
502  get_perms($form['onausername']);
503  if ($form['standalone'] == 'standalone') $js .= "window.location='{$http}{$baseURL}/';";
504  $js .= "el('loggedin_user').innerHTML = '{$_SESSION['ona']['auth']['user']['username']}';";
505  printmsg("INFO => [{$type}] {$_SESSION['ona']['auth']['user']['username']} has logged in via authtype: {$conf['authtype']}",0);
506  }
507 
508  $response = new xajaxResponse();
509  $response->addScript($js);
510  return($response->getXML());
511 
512 }
513 
514 
515 
516 
517 
518 
519 
521 // Function: get_subnet_html($subnet_ip)
522 //
523 // Description:
524 // Builds HTML for displaying a little info about a subnet for a TT popup
525 // Returns a two part array ($html, $js)
526 // If $subnet_ip isn't a valid subnet, a "add subnet" link is displayed
528 function get_subnet_html($subnet_ip) {
529  global $conf, $self, $onadb;
530  global $font_family, $color, $style, $images;
531 
532  $html = $js = '';
533 
534  $font_color = '#FFFFFF';
535 
536  $style['content_box'] = <<<EOL
537  margin: 10px 20px;
538  padding: 2px 4px;
539  background-color: #FFFFFF;
540  vertical-align: top;
541 EOL;
542 
543  $style['label_box'] = <<<EOL
544  font-weight: bold;
545  padding: 2px 4px;
546  border: solid 1px {$color['border']};
547  background-color: {$color['window_content_bg']};
548 EOL;
549 
550  // Load the subnet record
551  list($status, $rows, $subnet) = ona_find_subnet($subnet_ip);
552 
553  // If we didn't get one, tell them to add a record here
554  if ($rows == 0 or $status) {
555  // Calculate what the end of this block is so we can reccomend the max subnet size
556 
557  // GD: add IPv6 functionnality by imposing GMP use when not ipv4 subnet
558 
559  list($status, $rows, $subnets) = db_get_records($onadb, "subnets", "ip_addr > " . ip_mangle($subnet_ip, 'numeric'), "ip_addr", 1);
560  if (!is_ipv4($subnet_ip)) {
561  if ($rows >= 1) {
562  $subnet_ip_end = gmp_sub(gmp_init($subnets[0]['ip_addr']), 1);
563  $size = gmp_add(gmp_sub($subnet_ip_end, $subnet_ip), 1);
564  if (gmp_mod($size,2) == 1) gmp_sub($size,1);
565  // GD: very bad way to get the mask ... but gmp_log() does not exist !
566  for ($mask=65;$mask > 48;$mask--) {
567  if (gmp_cmp($size,gmp_pow("2",$mask)) > 0) {
568  $mask++;
569  break;
570  }
571  }
572  $subnet['ip_addr'] = ip_mangle(gmp_strval($subnet_ip), 'dotted');
573  $subnet['ip_addr_end'] = ip_mangle(gmp_strval($subnet_ip_end), 'dotted');
574  $str_subnet_ip = gmp_strval($subnet_ip);
575  $size=gmp_strval($size);
576  }
577  else {
578  $subnet_ip_end = -1;
579  $size=0;
580  }
581  }
582  else {
583  if ($rows >= 1) {
584  $subnet_ip_end = $subnets[0]['ip_addr'] - 1;
585  $size = $subnet_ip_end - $subnet_ip + 1;
586  if (($size % 2) == 1) $size--;
587  $mask = ceil(32 - (log($size) / log(2)));
588  $subnet['ip_addr'] = ip_mangle($subnet_ip, 'dotted');
589  $subnet['ip_addr_end'] = ip_mangle($subnet_ip_end, 'dotted');
590  $str_subnet_ip = $subnet_ip;
591  }
592  else {
593  $subnet_ip_end=-1;
594  $size=0;
595  }
596  }
597  $html .= <<<EOL
598  <!-- NO SUBNET -->
599  <table cellspacing="0" border="0" cellpadding="0">
600 
601  <!-- LABEL -->
602  <tr><td width=100% colspan="2" nowrap="true" style="{$style['label_box']}">
603  <a title="Add a new subnet here"
604  class="act"
605  onClick="xajax_window_submit('edit_subnet', 'ip_addr=>{$str_subnet_ip}', 'editor');"
606  >Add a subnet here</a>
607  </td></tr>
608 
609  <tr>
610  <td align="right" nowrap="true" style="color: {$font_color};"><b>IP Range</b>&nbsp;</td>
611  <td class="padding" nowrap="true" align="left" style="color: {$font_color};">{$subnet['ip_addr']}&nbsp;-&nbsp;{$subnet['ip_addr_end']}&nbsp({$size} addresses)</td>
612  </tr>
613 
614 EOL;
615  $largest_subnet = array(0, 0, 0);
616  // -- IPv4
617  if (is_ipv4($subnet_ip)) {
618  $ip = $subnet_ip;
619  while ($ip < $subnet_ip_end) {
620 
621  // find the largest mask for the specified ip
622  $myip = ip_mangle($ip, 'dotted');
623  $mymask = $mask;
624  while ($mymask <= 30) {
625  $ip1 = ip_mangle($ip, 'binary');
626  $ip2 = str_pad(substr($ip1, 0, $mymask), 32, '0');
627  $mysize = pow(2, 32-$mymask);
628  $myhosts = $mysize - 2;
629 
630  $ip1 = ip_mangle($ip1, 'dotted');
631  $ip2 = ip_mangle($ip2, 'dotted');
632  if ( $ip1 == $ip2 and (($ip + $mysize - 1) <= $subnet_ip_end) ) {
633  break;
634  }
635  $mymask++;
636  }
637  if ($mymask == 31) break;
638  if ($mysize > $largest_subnet[2]) $largest_subnet = array(ip_mangle($ip, 'dotted'), $mymask, $mysize);
639 
640 
641  $html .= <<<EOL
642  <!--
643  <tr>
644  <td align="right" nowrap="true" style="color: {$font_color};">&nbsp;</td>
645  <td class="padding" align="left" style="color: {$font_color};">{$myip} /{$mymask}&nbsp;({$myhosts} hosts)</td>
646  </tr>
647  -->
648 EOL;
649 
650  // Increment $ip
651  $ip += $mysize;
652 
653 
654  }
655  // remove 2 for gateway and broadcast
656  $largest_subnet[2] = $largest_subnet[2] - 2;
657  }
658  // -- IPV6
659  else {
660 
661  $ip = gmp_init($subnet_ip);
662  // GD: trying to avoid falling into time/memory-trap
663  // Won't enter in the loop if difference between IP and next subnet IP is too big
664  // (more than 5 x /64)
665  if (gmp_cmp(gmp_sub($subnet_ip_end,$ip),gmp_mul("18446744073709551616","5")) > 0) {
666 
667  $html .= <<<EOL
668  <tr>
669  <td align="right" nowrap="true" style="color: {$font_color};">&nbsp;</td>
670  <td align="right" nowrap="true" style="color: {$font_color};">Next Subnet too far away</td>
671  <tr>
672 EOL;
673  return(array($html, $js));
674  }
675 
676  while (gmp_cmp($ip, $subnet_ip_end) < 0) {
677 
678  // find the largest mask for the specified ip
679  $myip = ip_mangle(gmp_strval($ip), 'dotted');
680  $mymask = $mask;
681  while ($mymask <= 64) {
682  $ip1 = ip_mangle(gmp_strval($ip), 'bin128');
683  $ip2 = str_pad(substr($ip1, 0, $mymask), 128, '0');
684  $mysize = gmp_pow("2", 128-$mymask);
685  $myhosts = gmp_strval(gmp_sub($mysize,2));
686 
687  $ip1 = ip_mangle($ip1, 'dotted');
688  $ip2 = ip_mangle($ip2, 'dotted');
689  if ((strcmp($ip1, $ip2) == 0) and (gmp_cmp(gmp_sub(gmp_add($ip, $mysize),1), $subnet_ip_end) <= 0 )) {
690  break;
691  }
692  $mymask++;
693  }
694  if ($mymask == 90) break;
695  if (gmp_cmp($mysize,$largest_subnet[2]) > 0) $largest_subnet = array(ip_mangle(gmp_strval($ip), 'dotted'), $mymask, $mysize);
696 
697  $html .= <<<EOL
698  <!--
699  <tr>
700  <td align="right" nowrap="true" style="color: {$font_color};">&nbsp;</td>
701  <td class="padding" align="left" style="color: {$font_color};">{$mask} {$myip} /{$mymask}&nbsp;({$myhosts} hosts)td>
702  </tr>
703  -->
704 EOL;
705 
706  // Increment $ip
707  $ip = gmp_add($ip,$mysize);
708  }
709  // DON'T remove 2 for gateway and broadcast
710  $largest_subnet[2] = gmp_strval($largest_subnet[2]);
711 
712 
713  }
714  $html .= <<<EOL
715 
716  <tr>
717  <td align="right" nowrap="true" style="color: {$font_color};"><b>Largest block</b>&nbsp;</td>
718  <td class="padding" nowrap="true" align="left" style="color: {$font_color};">{$largest_subnet[0]} /{$largest_subnet[1]}&nbsp;({$largest_subnet[2]} usable hosts)</td>
719  </tr>
720 
721  </table>
722 EOL;
723  return(array($html, $js));
724  }
725 
726  // --
727  // -- FOUND SUBNET IN DB
728  // --
729 
730  // Convert IP and Netmask to a presentable format
731  $subnet['ip_addr'] = ip_mangle($subnet['ip_addr'], 'dotted');
732  $subnet['ip_mask'] = ip_mangle($subnet['ip_mask'], 'dotted');
733  $subnet['ip_mask_cidr'] = ip_mangle($subnet['ip_mask'], 'cidr');
734 
735  list($status, $rows, $type) = ona_get_subnet_type_record(array('id' => $subnet['subnet_type_id']));
736  $subnet['type'] = $type['display_name'];
737 
738 
739  // Calculate the percentage of the subnet that's used (total size - allocated hosts - dhcp pool size)
740  $usage_html = get_subnet_usage_html($subnet['id']);
741 
742  foreach(array_keys((array)$subnet) as $key) { $subnet[$key] = htmlentities($subnet[$key], ENT_QUOTES, $conf['php_charset']); }
743  foreach(array_keys((array)$location) as $key) { $location[$key] = htmlentities($location[$key], ENT_QUOTES, $conf['php_charset']); }
744 
745  $html .= <<<EOL
746 
747  <!-- SUBNET INFORMATION -->
748  <table cellspacing="0" border="0" cellpadding="0">
749 
750  <!-- LABEL -->
751  <tr><td width=100% colspan="2" nowrap="true" style="{$style['label_box']}">
752  <a title="View subnet. ID: {$subnet['id']}"
753  class="nav"
754  onClick="xajax_window_submit('work_space', 'xajax_window_submit(\'display_subnet\', \'subnet_id=>{$subnet['id']}\', \'display\')');"
755  >{$subnet['name']}</a>
756  </td></tr>
757 
758  <tr>
759  <td align="right" nowrap="true" style="color: {$font_color};"><b>IP Address</b>&nbsp;</td>
760  <td class="padding" align="left" style="color: {$font_color};">{$subnet['ip_addr']}&nbsp;/{$subnet['ip_mask_cidr']}</td>
761  </tr>
762 
763  <tr>
764  <td align="right" nowrap="true" style="color: {$font_color};"><b>Usage</b>&nbsp;</td>
765  <td class="padding" align="left" style="color: {$font_color};">{$usage_html}</td>
766  </tr>
767 
768 EOL;
769  if ($subnet['type']) {
770  $html .= <<<EOL
771  <tr>
772  <td align="right" nowrap="true" style="color: {$font_color};"><b>Type</b>&nbsp;</td>
773  <td class="padding" align="left" style="color: {$font_color};">{$subnet['type']}&nbsp;</td>
774  </tr>
775 EOL;
776  }
777 
778 
779  $html .= <<<EOL
780  </table>
781 EOL;
782 
783  return(array($html, $js));
784 }
785 
786 
787 
788 
789 
790 
791 
792 
793 
795 // Function: quick_subnet_search($form)
796 //
797 // Description:
798 // Builds HTML for displaying a quick search popup.
799 // Returns a two part array ($html, $js)
801 function quick_subnet_search($form) {
802  global $conf, $self, $onadb;
803  global $font_family, $color, $style, $images;
804  $html = $js = '';
805  $font_color = '#FFFFFF';
806 
807  // Build subnet type list
808  list($status, $rows, $records) = db_get_records($onadb, 'subnet_types', 'id >= 1', 'name');
809  $subnet_type_list = '<option value="">&nbsp;</option>\n';
810  $record['name'] = htmlentities($record['name']);
811  foreach ($records as $record) {
812  $subnet_type_list .= "<option value=\"{$record['id']}\">{$record['name']}</option>\n";
813  }
814 
815  $js .= <<<EOL
816  suggest_setup('ip_subnet_qf', 'suggest_ip_subnet_qf');
817  suggest_setup('ip_subnet_thru_qf', 'suggest_ip_subnet_thru_qf');
818  suggest_setup('subnet_qf', 'suggest_subnet_qf');
819 EOL;
820 
821  $style['content_box'] = <<<EOL
822  padding: 2px 4px;
823  vertical-align: top;
824 EOL;
825 
826  // WARNING: this one's different than most of them!
827  $style['label_box'] = <<<EOL
828  font-weight: bold;
829  cursor: move;
830  color: #FFFFFF;
831 EOL;
832 
833  $html .= <<<EOL
834 
835  <!-- SUBNET QUICK SEARCH -->
836  <form id="quick_subnet_search_form" onSubmit="return(false);">
837  <input type="hidden" name="id" value="{$form['id']}">
838  <input type="hidden" name="input_id" value="{$form['input_id']}">
839  <input type="hidden" name="content_id" value="qf_subnet_results">
840  <table id="subnet_search" style="{$style['content_box']}" cellspacing="0" border="0" cellpadding="0">
841 
842  <tr>
843  <td colspan="2" align="center" class="qf-search-line" style="{$style['label_box']}; padding-top: 0px;" onMouseDown="dragStart(event, '{$form['id']}', 'savePosition', 0);">
844  Subnet Quick Search
845  </td>
846  </tr>
847 
848  <tr>
849  <td align="right" class="qf-search-line">
850  Subnet <u>T</u>ype
851  </td>
852  <td align="left" class="qf-search-line">
853  <select id="nettype" name="nettype" class="edit" accesskey="u" accesskey="t" >
855  </select>
856  </td>
857  </tr>
858 
859  <tr>
860  <td align="right" class="qf-search-line">
861  Subnet <u>D</u>esc
862  </td>
863  <td align="left" class="qf-search-line">
864  <input id="subnet_qf" name="netdesc" type="text" class="edit" size="32" accesskey="d" />
865  <div id="suggest_subnet_qf" class="suggest"></div>
866  </td>
867  </tr>
868 
869  <tr>
870  <td align="right" class="qf-search-line">
871  <u>I</u>P Address
872  </td>
873  <td align="left" class="qf-search-line" nowrap="true">
874  <input id="ip_subnet_qf" name="ip_subnet" class="edit" type="text" size="15" accesskey="i" />
875  <div id="suggest_ip_subnet_qf" class="suggest"></div>
876  thru
877  <input id="ip_subnet_thru_qf" name="ip_subnet_thru" class="edit" type="text" size="15">
878  <div id="suggest_ip_subnet_thru_qf" class="suggest"></div>
879  </td>
880  </tr>
881 
882  <tr>
883  <td align="right" class="qf-search-line">
884  &nbsp;
885  </td>
886  <td align="right" class="qf-search-line">
887  <input class="button" type="button" name="cancel" value="Cancel" onClick="removeElement('{$form['id']}');">
888  <input class="button" type="button" name="search" value="Search" accesskey="s" onClick="xajax_window_submit('search_results_qf', xajax.getFormValues('quick_subnet_search_form'), 'subnet');">
889  </td>
890  </tr>
891 
892  <tr>
893  <td colspan="2" align="left" class="qf-search-line">
894  <div
895  id="qf_subnet_results"
896  style="
897  display: none;
898  background-color: #FFFFFF;
899  overflow: auto;
900  height: 300px;"
901  ></div>
902  </td>
903  </tr>
904 
905  </table>
906  </form>
907 EOL;
908 
909  return(array($html, $js));
910 }
911 
912 
913 
914 
915 
916 
917 
918 
919 
920 
921 
922 
923 
925 // Function: quick_location_search($form)
926 //
927 // Description:
928 // Builds HTML for displaying a quick search popup.
929 // Returns a two part array ($html, $js)
931 function quick_location_search($form) {
932  global $conf, $self, $onadb;
933  global $font_family, $color, $style, $images;
934  $html = $js = '';
935  $font_color = '#FFFFFF';
936 
937 
938  $js .= <<<EOL
939 EOL;
940 
941  $style['content_box'] = <<<EOL
942  padding: 2px 4px;
943  vertical-align: top;
944 EOL;
945 
946  // WARNING: this one's different than most of them!
947  $style['label_box'] = <<<EOL
948  font-weight: bold;
949  cursor: move;
950  color: #FFFFFF;
951 EOL;
952 
953  $html .= <<<EOL
954 
955  <!-- LOCATION QUICK SEARCH -->
956  <form id="quick_location_search_form" onSubmit="return(false);">
957  <input type="hidden" name="id" value="{$form['id']}">
958  <input type="hidden" name="input_id" value="{$form['input_id']}">
959  <input type="hidden" name="content_id" value="qf_location_results">
960  <table id="location_search" style="{$style['content_box']}" cellspacing="0" border="0" cellpadding="0">
961 
962  <tr>
963  <td colspan="2" align="center" class="qf-search-line" style="{$style['label_box']}; padding-top: 0px;" onMouseDown="dragStart(event, '{$form['id']}', 'savePosition', 0);">
964  Location Quick Search
965  </td>
966  </tr>
967 
968  <tr>
969  <td align="right" class="qf-search-line">
970  <u>R</u>eference
971  </td>
972  <td align="left" class="qf-search-line">
973  <input name="reference" type="text" class="edit" size="32" accesskey="r" />
974  </td>
975  </tr>
976 
977  <tr>
978  <td align="right" class="qf-search-line">
979  <u>N</u>ame
980  </td>
981  <td align="left" class="qf-search-line">
982  <input name="name" type="text" class="edit" size="32" accesskey="n" />
983  </td>
984  </tr>
985 
986  <tr>
987  <td align="right" class="qf-search-line">
988  <u>A</u>ddress
989  </td>
990  <td align="left" class="qf-search-line">
991  <input name="address" type="text" class="edit" size="32" accesskey="a" />
992  </td>
993  </tr>
994 
995  <tr>
996  <td align="right" class="qf-search-line">
997  <u>C</u>ity
998  </td>
999  <td align="left" class="qf-search-line" nowrap="true">
1000  <input name="city" class="edit" type="text" size="20" accesskey="c" />&nbsp;
1001  State: <input name="state" class="edit" type="text" size="2" maxlength="2" />
1002  </td>
1003  </tr>
1004 
1005  <tr>
1006  <td align="right" class="qf-search-line">
1007  <u>Z</u>ip
1008  </td>
1009  <td align="left" class="qf-search-line" nowrap="true">
1010  <input name="zip" class="edit" type="text" size="10" maxlength="10" accesskey="z" />
1011  </td>
1012  </tr>
1013 
1014  <tr>
1015  <td align="right" class="qf-search-line">
1016  &nbsp;
1017  </td>
1018  <td align="right" class="qf-search-line">
1019  <input class="button" type="button" name="cancel" value="Cancel" onClick="removeElement('{$form['id']}');">
1020  <input class="button" type="button" name="search" value="Search" accesskey="s" onClick="xajax_window_submit('search_results_qf', xajax.getFormValues('quick_location_search_form'), 'location');">
1021  </td>
1022  </tr>
1023 
1024  <tr>
1025  <td colspan="2" align="left" class="qf-search-line">
1026  <div
1027  id="qf_location_results"
1028  style="
1029  display: none;
1030  background-color: #FFFFFF;
1031  overflow: auto;
1032  height: 300px;"
1033  ></div>
1034  </td>
1035  </tr>
1036 
1037  </table>
1038  </form>
1039 EOL;
1040 
1041  return(array($html, $js));
1042 }
1043 
1044 
1045 
1046 
1047 
1048 
1049 
1051 // Function: quick_tag_add($form)
1052 //
1053 // Description:
1054 // Builds HTML for displaying a quick popup.
1055 // Returns a two part array ($html, $js)
1057 function quick_tag_add($form) {
1058  global $conf, $self, $onadb;
1059  global $font_family, $color, $style, $images;
1060  $html = $js = '';
1061  $font_color = '#FFFFFF';
1062 
1063  $style['content_box'] = <<<EOL
1064  padding: 2px 4px;
1065  vertical-align: top;
1066 EOL;
1067 
1068  // WARNING: this one's different than most of them!
1069  $style['label_box'] = <<<EOL
1070  font-weight: bold;
1071  cursor: move;
1072  color: #FFFFFF;
1073 EOL;
1074 
1075  $html .= <<<EOL
1076 
1077  <!-- QUICK TAG ADD -->
1078  <form id="quick_tag_add_form" onSubmit="return(false);">
1079  <input type="hidden" name="type" value="{$form['type']}">
1080  <input type="hidden" name="reference" value="{$form['reference']}">
1081  <input type="hidden" name="updateid" value="{$form['updateid']}">
1082  <table style="{$style['content_box']}" cellspacing="0" border="0" cellpadding="0">
1083 
1084  <tr><td align="center" class="qf-search-line" style="{$style['label_box']}; padding-top: 0px;" onMouseDown="dragStart(event, '{$form['id']}', 'savePosition', 0);">
1085  Add {$form['type']} tag
1086  </td></tr>
1087 
1088  <tr>
1089  <td align="left" class="qf-search-line">
1090  <input id="tag_qf" name="name" type="text" class="edit" size="25" maxlength="127"ccesskey="t" onClick="el('qf_tag_results').style.display = 'none';" onkeypress="if (event.keyCode == 13) { el('tagaddbutton').click();clearInterval(inter_exec); }" />
1091  <div id="suggest_tag_qf" class="suggest"></div>
1092 <br>
1093 <br>
1094  </td>
1095  </tr>
1096  <tr>
1097  <td align="right" class="qf-search-line">
1098  <input class="button" type="button" name="cancel" value="Cancel" onClick="removeElement('{$form['id']}');">
1099  <input id="tagaddbutton"
1100  class="button"
1101  type="button"
1102  name="add"
1103  value="Add"
1104  accesskey="a"
1105  onClick="xajax_window_submit('edit_tag', xajax.getFormValues('quick_tag_add_form'), 'save');removeElement('{$form['id']}');">
1106  </td>
1107  </tr>
1108 
1109  </table>
1110  </form>
1111 EOL;
1112 
1113  // Javascript to run after the window is built
1114  $js = <<<EOL
1115  suggest_setup('tag_qf', 'suggest_tag_qf');
1116  el('tag_qf').focus();
1117 EOL;
1118 
1119  return(array($html, $js));
1120 }
1121 
1122 
1123 
1124 
1126 // Function: quick_vlan_search($form)
1127 //
1128 // Description:
1129 // Builds HTML for displaying a quick search popup.
1130 // Returns a two part array ($html, $js)
1132 function quick_vlan_search($form) {
1133  global $conf, $self, $onadb;
1134  global $font_family, $color, $style, $images;
1135  $html = $js = '';
1136  $font_color = '#FFFFFF';
1137 
1138  $style['content_box'] = <<<EOL
1139  padding: 2px 4px;
1140  vertical-align: top;
1141 EOL;
1142 
1143  // WARNING: this one's different than most of them!
1144  $style['label_box'] = <<<EOL
1145  font-weight: bold;
1146  cursor: move;
1147  color: #FFFFFF;
1148 EOL;
1149 
1150  $html .= <<<EOL
1151 
1152  <!-- VLAN QUICK SEARCH -->
1153  <form id="quick_vlan_search_form" onSubmit="return(false);">
1154  <input type="hidden" name="id" value="{$form['id']}">
1155  <input type="hidden" name="input_id" value="{$form['input_id']}">
1156  <input type="hidden" name="text_id" value="{$form['text_id']}">
1157  <input type="hidden" name="content_id" value="qf_vlan_results">
1158  <table style="{$style['content_box']}" cellspacing="0" border="0" cellpadding="0">
1159 
1160  <tr><td colspan="2" align="center" class="qf-search-line" style="{$style['label_box']}; padding-top: 0px;" onMouseDown="dragStart(event, '{$form['id']}', 'savePosition', 0);">
1161  VLAN Quick Select
1162  </td></tr>
1163 
1164  <tr>
1165  <td align="right" class="qf-search-line">
1166  <u>C</u>ampus
1167  </td>
1168  <td align="left" class="qf-search-line">
1169  <input id="vlan_campus_qf" name="campus" type="text" class="edit" size="24" accesskey="c" onClick="el('qf_vlan_results').style.display = 'none';" />
1170  <div id="suggest_vlan_campus_qf" class="suggest"></div>
1171  </td>
1172  </tr>
1173 
1174  <tr>
1175  <td align="right" class="qf-search-line">
1176  &nbsp;
1177  </td>
1178  <td align="right" class="qf-search-line">
1179  <input class="button" type="button" name="cancel" value="Cancel" onClick="removeElement('{$form['id']}');">
1180  <input class="button" type="button" name="search" value="Search" accesskey="s" onClick="xajax_window_submit('search_results_qf', xajax.getFormValues('quick_vlan_search_form'), 'vlan');">
1181  </td>
1182  </tr>
1183 
1184  <tr>
1185  <td colspan="2" align="left" class="qf-search-line">
1186  <div
1187  id="qf_vlan_results"
1188  style="
1189  display: none;
1190  background-color: #FFFFFF;
1191  overflow: auto;
1192  height: 300px;"
1193  ></div>
1194  </td>
1195  </tr>
1196 
1197  </table>
1198  </form>
1199 EOL;
1200 
1201  // Javascript to run after the window is built
1202  $js = <<<EOL
1203  suggest_setup('vlan_campus_qf', 'suggest_vlan_campus_qf');
1204 EOL;
1205 
1206  return(array($html, $js));
1207 }
1208 
1209 
1210 
1211 
1212 
1213 
1214 
1215 
1216 
1218 // Function: quick_free_ip_search($form)
1219 //
1220 // Description:
1221 // Builds HTML for displaying a quick search popup.
1222 // Returns a two part array ($html, $js)
1224 function quick_free_ip_search($form) {
1225  global $conf, $self, $onadb;
1226  global $font_family, $color, $style, $images;
1227  $html = $js = '';
1228  $font_color = '#FFFFFF';
1229 
1230  // Build subnet type list
1231  list($status, $rows, $records) = db_get_records($onadb, 'subnet_types', 'id >= 1', 'display_name');
1232  $subnet_type_list = '<option value="">&nbsp;</option>\n';
1233  $record['display_name'] = htmlentities($record['display_name']);
1234  foreach ($records as $record) {
1235  $subnet_type_list .= "<option value=\"{$record['id']}\">{$record['display_name']}</option>\n";
1236  }
1237 
1238  $js .= <<<EOL
1239  suggest_setup('ip_subnet_qf', 'suggest_ip_subnet_qf');
1240  suggest_setup('ip_subnet_thru_qf', 'suggest_ip_subnet_thru_qf');
1241  suggest_setup('subnet_qf', 'suggest_subnet_qf');
1242 EOL;
1243 
1244  $style['content_box'] = <<<EOL
1245  padding: 2px 4px;
1246  vertical-align: top;
1247 EOL;
1248 
1249  // WARNING: this one's different than most of them!
1250  $style['label_box'] = <<<EOL
1251  font-weight: bold;
1252  cursor: move;
1253  color: #FFFFFF;
1254 EOL;
1255 
1256  foreach(array_keys((array)$form) as $key) { $form[$key] = htmlentities($form[$key], ENT_QUOTES, $conf['php_charset']); }
1257 
1258  $html .= <<<EOL
1259  <!-- FREE IP QUICK SEARCH -->
1260  <form id="quick_free_ip_search_form" onSubmit="return(false);">
1261  <input type="hidden" name="id" value="{$form['id']}">
1262  <input type="hidden" name="input_id" value="{$form['input_id']}">
1263  <input type="hidden" name="text_id" value="{$form['text_id']}">
1264  <input type="hidden" name="content_id" value="qf_free_ip_results">
1265  <input type="hidden" name="next_action" value="free_ip">
1266  <input type="hidden" name="form_id" value="quick_free_ip_search_form">
1267  <!-- The subnet_id field gets filled by clicking on a subnet result later -->
1268  <input type="hidden" id="qf_free_ip_subnet_id" name="subnet_id" value="">
1269  <table style="{$style['content_box']}" cellspacing="0" border="0" cellpadding="0">
1270 
1271  <tr><td colspan="2" align="center" class="qf-search-line" style="{$style['label_box']}; padding-top: 0px;" onMouseDown="dragStart(event, '{$form['id']}', 'savePosition', 0);">
1272  Available IP Quick Search
1273  </td></tr>
1274 
1275  <tr>
1276  <td align="right" class="qf-search-line">
1277  Subnet <u>T</u>ype
1278  </td>
1279  <td align="left" class="qf-search-line">
1280  <select id="nettype" name="nettype" class="edit" accesskey="u" accesskey="t" >
1282  </select>
1283  </td>
1284  </tr>
1285 
1286  <tr>
1287  <td align="right" class="qf-search-line">
1288  Subnet <u>D</u>esc
1289  </td>
1290  <td align="left" class="qf-search-line">
1291  <input id="subnet_qf" name="netdesc" type="text" class="edit" size="32" accesskey="d" value="{$form['text_value']}" />
1292  <div id="suggest_subnet_qf" class="suggest"></div>
1293  </td>
1294  </tr>
1295 
1296  <tr>
1297  <td align="right" class="qf-search-line">
1298  <u>I</u>P Address
1299  </td>
1300  <td align="left" class="qf-search-line" nowrap="true">
1301  <input id="ip_subnet_qf" name="ip_subnet" class="edit" type="text" size="15" accesskey="i" />
1302  <div id="suggest_ip_subnet_qf" class="suggest"></div>
1303  thru
1304  <input id="ip_subnet_thru_qf" name="ip_subnet_thru" class="edit" type="text" size="15">
1305  <div id="suggest_ip_subnet_thru_qf" class="suggest"></div>
1306  </td>
1307  </tr>
1308 
1309  <tr>
1310  <td align="right" class="qf-search-line">
1311  &nbsp;
1312  </td>
1313  <td align="right" class="qf-search-line">
1314  <input class="button" type="reset" name="reset" value="Reset">
1315  <input class="button" type="button" name="cancel" value="Cancel" onClick="removeElement('{$form['id']}');">
1316  <input class="button" type="button" name="search" value="Search" accesskey="s" onClick="xajax_window_submit('search_results_qf', xajax.getFormValues('quick_free_ip_search_form'), 'subnet');">
1317  </td>
1318  </tr>
1319 
1320  <tr>
1321  <td colspan="2" align="left" class="qf-search-line">
1322  <div
1323  id="qf_free_ip_results"
1324  style="
1325  display: none;
1326  background-color: #FFFFFF;
1327  overflow: auto;
1328  height: 300px;"
1329  ></div>
1330  </td>
1331  </tr>
1332 
1333  </table>
1334  </form>
1335 EOL;
1336 
1337  if ($form['text_value'] != "") {
1338  $js .= "xajax_window_submit('search_results_qf', xajax.getFormValues('quick_free_ip_search_form'), 'subnet');";
1339  }
1340  return(array($html, $js));
1341 }
1342 
1343 
1344 
1345 
1346 
1347 
1348 
1349 
1351 // Function: quick_pool_server_search($form)
1352 //
1353 // Description:
1354 // Builds HTML for displaying a quick search popup.
1355 // Returns a two part array ($html, $js)
1357 function quick_pool_server_search($form) {
1358  global $conf, $self, $onadb;
1359  global $font_family, $color, $style, $images;
1360  $html = $js = '';
1361  $font_color = '#FFFFFF';
1362 
1363 
1364  // Build failover group list
1365  list($status, $rows, $fg) = db_get_records($onadb, 'dhcp_failover_groups', 'id >= 1', 'id');
1366  $fg_list = '<option value="0">None</option>\n';
1367 
1368  foreach ($fg as $record) {
1369  list($status, $rows, $fail_host1) = ona_find_host($record['primary_server_id']);
1370  list($status, $rows, $fail_host2) = ona_find_host($record['secondary_server_id']);
1371 
1372  $selected = "";
1373  if ($record['id'] == $form['failover_group_id']) { $selected = "SELECTED=\"selected\""; }
1374  if ($record['id']) {
1375  $fg_list .= "<option {$selected} value=\"{$record['id']}\">{$fail_host1['fqdn']}/{$fail_host2['fqdn']}</option>\n";
1376  }
1377  }
1378 
1379  $js .= <<<EOL
1380  suggest_setup('pool_server_qf', 'suggest_pool_server_qf');
1381 
1382 EOL;
1383 
1384  $style['content_box'] = <<<EOL
1385  padding: 2px 4px;
1386  vertical-align: top;
1387 EOL;
1388 
1389  // WARNING: this one's different than most of them!
1390  $style['label_box'] = <<<EOL
1391  font-weight: bold;
1392  cursor: move;
1393  color: #FFFFFF;
1394 EOL;
1395 
1396  $html .= <<<EOL
1397 
1398  <!-- POOL SERVER QUICK SEARCH -->
1399  <form id="quick_pool_server_search_form" onSubmit="return(false);">
1400  <input type="hidden" name="id" value="{$form['id']}">
1401  <input type="hidden" name="input_id" value="{$form['input_id']}">
1402  <input type="hidden" name="content_id" value="qf_pool_server_results">
1403  <table id="pool_server_search" style="{$style['content_box']}" cellspacing="0" border="0" cellpadding="0">
1404 
1405  <tr>
1406  <td colspan="2" align="center" class="qf-search-line" style="{$style['label_box']}; padding-top: 0px;" onMouseDown="dragStart(event, '{$form['id']}', 'savePosition', 0);">
1407  DHCP Pool Failover Server Quick Select
1408  </td>
1409  </tr>
1410 
1411  <tr>
1412  <td align="right" class="qf-search-line" nowrap="true">
1413  Server <u>g</u>roup
1414  </td>
1415  <td align="left" class="qf-search-line">
1416  <select id="failover_group_qf" name="failover_group" class="edit" accesskey="f" onClick="el('pool_server_qf').value = '';">
1417  {$fg_list}
1418  </select>
1419  </td>
1420  </tr>
1421 
1422  <tr>
1423  <td align="right" class="qf-search-line">
1424  &nbsp;
1425  </td>
1426  <td align="right" class="qf-search-line">
1427  <input class="button" type="button" name="cancel" value="Cancel" onClick="removeElement('{$form['id']}');">
1428  <input class="button" type="button" name="select" value="Select" accesskey="s" onClick="el('{$form['failover_group']}').value = failover_group_qf.options[failover_group_qf.selectedIndex].value; if (failover_group_qf.options[failover_group_qf.selectedIndex].value) el('{$form['text_id']}').innerHTML = failover_group_qf.options[failover_group_qf.selectedIndex].innerHTML; removeElement('{$form['id']}');">
1429  </td>
1430  </tr>
1431 
1432 
1433  </table>
1434  </form>
1435 EOL;
1436 
1437  return(array($html, $js));
1438 }
1439 
1440 
1441 
1442 
1443 
1444 
1445 
1447 // Function: get_host_interface_list_html($form)
1448 //
1449 // Description:
1450 // Builds HTML for displaying info about multiple host interfaces
1451 // Returns a two part array ($html, $js)
1454  global $conf, $self, $onadb;
1455  global $font_family, $color, $style, $images;
1456 
1457  $html = $js = '';
1458 
1459  // Interface Record
1460  list($status, $introws, $interfaces) = db_get_records($onadb, 'interfaces', "host_id = {$form['host_id']} or id in (select interface_id from interface_clusters where host_id ={$form['host_id']})", 'ip_addr ASC');
1461 
1462  if ($introws == 0 or $status) return(array('', ''));
1463 
1464 
1465  $style['label_box'] = <<<EOL
1466  font-weight: bold;
1467  padding: 2px 4px;
1468  text-align: center;
1469  border: solid 1px {$color['border']};
1470  background-color: {$color['window_content_bg']};
1471 EOL;
1472 
1473  $html .= <<<EOL
1474  <!-- INTERFACE INFORMATION -->
1475  <table cellspacing="0" border="0" cellpadding="0">
1476 
1477  <!-- LABEL -->
1478  <tr>
1479  <td colspan=5 style="{$style['label_box']}">{$introws} interface(s)</td>
1480  </tr>
1481 EOL;
1482 
1483  $i = 0;
1484 
1485  foreach($interfaces as $interface) {
1486  list($status, $rows, $subnet) = ona_get_subnet_record(array('id'=>$interface['subnet_id']));
1487  foreach(array_keys((array)$interface) as $key) { $interface[$key] = htmlentities($interface[$key], ENT_QUOTES, $conf['php_charset']); }
1488  foreach(array_keys((array)$subnet) as $key) { $subnet[$key] = htmlentities($subnet[$key], ENT_QUOTES, $conf['php_charset']); }
1489  $ip = ip_mangle($interface['ip_addr'],'dotted');
1490 
1491  $clusticon = '';
1492  list($status, $clustrows, $clustrecord) = ona_get_record(array('interface_id' => $interface['id']), 'interface_clusters');
1493  if ($interface['host_id'] != $form['host_id'] or $clustrows>0) $clusticon = "<img title=\"This interface is shared with another host.\" src=\"{$images}/silk/sitemap.png\" border=\"0\">";
1494 
1495  $html .= <<<EOL
1496  <tr>
1497  <td align="left" style="color: #FFFFFF;" nowrap="true">{$clusticon}&nbsp;</td>
1498  <td align="left" class="padding" style="color: #FFFFFF;" nowrap="true">{$ip}</td>
1499  <td align="left" class="padding" style="color: #FFFFFF;" nowrap="true">
1500  <a title="View subnet. ID: {$subnet['id']}"
1501  style="color: #6CB3FF;"
1502  class="nav"
1503  onClick="xajax_window_submit('work_space', 'xajax_window_submit(\'display_subnet\', \'subnet_id=>{$subnet['id']}\', \'display\')'); removeElement('{$form['id']}');"
1504  >{$subnet['name']}</a>&nbsp;</td>
1505  </tr>
1506 
1507 EOL;
1508 
1509  // increment counter
1510  $i++;
1511 
1512  if ($i == 15) {
1513  $html .= <<<EOL
1514  <tr>
1515  <td align="center" class="padding" style="color: #FFFFFF;" nowrap="true" colspan=2>
1516  Only displaying first 15 interfaces on host.&nbsp;&nbsp;
1517  <a title="View host. ID: {$interface['host_id']}"
1518  style="color: #6CB3FF;"
1519  class="nav"
1520  onClick="xajax_window_submit('work_space', 'xajax_window_submit(\'display_host\', \'host_id=>{$interface['host_id']}\', \'display\')'); removeElement('{$form['id']}');"
1521  >View Host</a>&nbsp;</td>
1522  </tr>
1523 EOL;
1524  break;
1525  }
1526 
1527  }
1528  $html .= <<<EOL
1529  </table>
1530 EOL;
1531 
1532  return(array($html, $js));
1533 }
1534 
1535 
1536 
1537 
1538 
1539 
1540 
1541 
1542 
1544 // Function: get_interface_cluster_list_html($form)
1545 //
1546 // Description:
1547 // Builds HTML for displaying info about interface cluster hosts
1548 // Returns a two part array ($html, $js)
1551  global $conf, $self, $onadb;
1552  global $font_family, $color, $style, $images;
1553 
1554  $html = $js = '';
1555 
1556  // Interface Record
1557  list($status, $introws, $interfaces) = db_get_records($onadb, 'interface_clusters', "interface_id = {$form['interface_id']}");
1558  if ($introws == 0 or $status) return(array('', ''));
1559 
1560  // Get primary host info
1561  list($status, $rows, $priint) = ona_get_interface_record(array('id'=>$form['interface_id']));
1562  list($status, $rows, $prihost) = ona_get_host_record(array('id'=>$priint['host_id']));
1563 
1564  $priip = ip_mangle($priint['ip_addr'], dotted);
1565 
1566  // add one for primary host
1567  $introws=$introws+1;
1568 
1569  $style['label_box'] = <<<EOL
1570  font-weight: bold;
1571  padding: 2px 4px;
1572  text-align: center;
1573  border: solid 1px {$color['border']};
1574  background-color: {$color['window_content_bg']};
1575 EOL;
1576 
1577  $html .= <<<EOL
1578  <!-- INTERFACE CLUSTER INFORMATION -->
1579  <table cellspacing="0" border="0" cellpadding="0">
1580 
1581  <!-- LABEL -->
1582  <tr>
1583  <td colspan=3 style="{$style['label_box']}">{$introws} hosts share IP:<br>{$priip}</td>
1584  </tr>
1585  <tr>
1586  <td align="left" class="padding" style="color: #FFFFFF;" nowrap="true">
1587  <a title="View host. ID: {$prihost['id']}"
1588  style="color: #6CB3FF;"
1589  class="nav"
1590  onClick="xajax_window_submit('work_space', 'xajax_window_submit(\'display_host\', \'host_id=>{$prihost['id']}\', \'display\')'); removeElement('{$form['id']}');"
1591  >{$prihost['fqdn']}</a>&nbsp;</td>
1592  <td align="left" class="padding" style="color: #FFFFFF;" nowrap="true">{$priint['name']}</td>
1593  </tr>
1594 EOL;
1595 
1596  $i = 0;
1597 
1598  foreach($interfaces as $interface) {
1599  list($status, $rows, $host) = ona_get_host_record(array('id'=>$interface['host_id']));
1600  foreach(array_keys((array)$interface) as $key) { $interface[$key] = htmlentities($interface[$key], ENT_QUOTES, $conf['php_charset']); }
1601  foreach(array_keys((array)$host) as $key) { $host[$key] = htmlentities($host[$key], ENT_QUOTES, $conf['php_charset']); }
1602 
1603  // If there is no cluster name then use the name from the primary interface
1604  if (!$interface['name'])
1605  $interface['name'] = $priint['name'];
1606 
1607  $html .= <<<EOL
1608  <tr>
1609  <td align="left" class="padding" style="color: #FFFFFF;" nowrap="true">
1610  <form id="quick_interface_share_del_form" onSubmit="return(false);">
1611  <input type="hidden" name="ip" value="{$interface['interface_id']}">
1612  <input type="hidden" name="host" value="{$host['id']}">
1613  </form>
1614  <a title="View host. ID: {$host['id']}"
1615  style="color: #6CB3FF;"
1616  class="nav"
1617  onClick="xajax_window_submit('work_space', 'xajax_window_submit(\'display_host\', \'host_id=>{$host['id']}\', \'display\')'); removeElement('{$form['id']}');"
1618  >{$host['fqdn']}</a>&nbsp;</td>
1619  <td align="left" class="padding" style="color: #FFFFFF;" nowrap="true">{$interface['name']}</td>
1620  <td align="left" class="padding" style="color: #FFFFFF;" nowrap="true">
1621  <img src="{$images}/silk/delete.png"
1622  title="Remove interface share with {$host['fqdn']}"
1623  border="0"
1624  onClick="xajax_window_submit('tooltips', xajax.getFormValues('quick_interface_share_del_form'), 'interface_share_del');removeElement('{$form['id']}');"
1625  />
1626  </td>
1627  </tr>
1628 
1629 EOL;
1630 
1631  // increment counter
1632  $i++;
1633 
1634  if ($i == 15) {
1635  $html .= <<<EOL
1636  <tr>
1637  <td align="center" class="padding" style="color: #FFFFFF;" nowrap="true" colspan=2>
1638  Only displaying first 15 hosts in cluster.&nbsp;&nbsp;
1639  <a title="View host. ID: {$interface['host_id']}"
1640  style="color: #6CB3FF;"
1641  class="nav"
1642  onClick="xajax_window_submit('work_space', 'xajax_window_submit(\'display_host\', \'host_id=>{$interface['host_id']}\', \'display\')'); removeElement('{$form['id']}');"
1643  >View Primary Host</a>&nbsp;</td>
1644  </tr>
1645 EOL;
1646  break;
1647  }
1648 
1649  }
1650  $html .= <<<EOL
1651  </table>
1652 EOL;
1653 
1654  return(array($html, $js));
1655 }
1656 
1657 
1658 
1659 
1660 
1661 
1662 
1663 
1664 
1665 
1667 // Function: quick_interface_share($form)
1668 //
1669 // Description:
1670 // Builds HTML for displaying a quick search popup.
1671 // Returns a two part array ($html, $js)
1673 function quick_interface_share($form) {
1674  global $conf, $self, $onadb;
1675  global $font_family, $color, $style, $images;
1676  $html = $js = '';
1677  $font_color = '#FFFFFF';
1678 
1679  $style['content_box'] = <<<EOL
1680  padding: 2px 4px;
1681  vertical-align: top;
1682 EOL;
1683 
1684  // WARNING: this one's different than most of them!
1685  $style['label_box'] = <<<EOL
1686  font-weight: bold;
1687  cursor: move;
1688  color: #FFFFFF;
1689 EOL;
1690 
1691  $refresh = "xajax_window_submit('list_interfaces', xajax.getFormValues('list_interfaces_filter_form'), 'display_list');";
1692 
1693  $html .= <<<EOL
1694 
1695  <!-- QUICK INTERFACE SHARE -->
1696  <form id="quick_interface_share_form" onSubmit="return(false);">
1697  <input type="hidden" name="id" value="{$form['id']}">
1698  <input type="hidden" name="js" value="{$form['js']}">
1699  <input type="hidden" name="ip" value="{$form['interface_id']}">
1700  <table style="{$style['content_box']}" cellspacing="0" border="0" cellpadding="0">
1701 
1702  <tr><td colspan="2" align="center" class="qf-search-line" style="{$style['label_box']}; padding-top: 0px;" onMouseDown="dragStart(event, '{$form['id']}', 'savePosition', 0);">
1703  Quick interface share
1704  </td></tr>
1705 
1706  <tr>
1707  <td align="right" class="qf-search-line">
1708  Share IP
1709  </td>
1710  <td align="left" class="qf-search-line">
1711  {$form['ip_addr']}
1712  </td>
1713  </tr>
1714 
1715 
1716  <tr>
1717  <td align="right" class="qf-search-line">
1718  to <u>H</u>ost
1719  </td>
1720  <td align="left" class="qf-search-line">
1721  <input id="share_hostname" name="host" type="text" class="edit" size="24" accesskey="h" autocomplete="off"/>
1722  <div id="suggest_share_hostname" class="suggest"></div>
1723  </td>
1724  </tr>
1725 
1726  <tr>
1727  <td align="right" class="qf-search-line">
1728  Int <u>N</u>ame
1729  </td>
1730  <td align="left" class="qf-search-line">
1731  <input name="name" type="text" class="edit" size="24" accesskey="n" />
1732  </td>
1733  </tr>
1734 
1735  <tr>
1736  <td align="right" class="qf-search-line">
1737  &nbsp;
1738  </td>
1739  <td align="right" class="qf-search-line">
1740  <input class="button" type="button" name="cancel" value="Cancel" onClick="removeElement('{$form['id']}');">
1741  <input class="button" type="button" name="share" value="Share" accesskey="s" onClick="xajax_window_submit('tooltips', xajax.getFormValues('quick_interface_share_form'), 'interface_share_save');removeElement('{$form['id']}');{$refresh};">
1742  </td>
1743  </tr>
1744 
1745  </table>
1746  </form>
1747 EOL;
1748 
1749  // Javascript to run after the window is built
1750  $js .= <<<EOL
1751  el('share_hostname').focus();
1752  suggest_setup('share_hostname', 'suggest_share_hostname');
1753 EOL;
1754 
1755  return(array($html, $js));
1756 }
1757 
1758 
1759 
1760 
1761 
1763 // Function:
1764 // Save Form
1765 //
1766 // Description:
1767 // Creates/updates a interface cluster record.
1769 function ws_interface_share_save($window_name, $form='') {
1770  global $base, $include, $conf, $self, $onadb;
1771 
1772  // Check permissions
1773  if (! (auth('interface_del')) ) {
1774  $response = new xajaxResponse();
1775  $response->addScript("alert('Permission denied!');");
1776  return($response->getXML());
1777  }
1778 
1779  // Instantiate the xajaxResponse object
1780  $response = new xajaxResponse();
1781  $js = '';
1782 
1783  // Validate input
1784  if (!$form['host'] and !$form['ip']) {
1785  $response->addScript("alert('Please complete all fields to continue!');");
1786  return($response->getXML());
1787  }
1788 
1789  // Decide if we're editing or adding
1790  $module = 'interface_share';
1791 
1792  // Run the module
1793  list($status, $output) = run_module($module, $form);
1794 
1795  // If the module returned an error code display a popup warning
1796  if ($status)
1797  $js .= "alert('Save failed. ". preg_replace('/[\s\']+/', ' ', $self['error']) . "');";
1798  else {
1799  $js .= "removeElement('{$window_name}');";
1800  if ($form['js']) $js .= $form['js'];
1801  }
1802 
1803  // Insert the new table into the window
1804  $response->addScript($js);
1805  return($response->getXML());
1806 }
1807 
1808 
1809 
1810 
1811 
1812 
1814 // Function:
1815 // Save Form
1816 //
1817 // Description:
1818 // Deletes a interface cluster record.
1820 function ws_interface_share_del($window_name, $form='') {
1821  global $base, $include, $conf, $self, $onadb;
1822 
1823  // Check permissions
1824  if (! (auth('interface_del')) ) {
1825  $response = new xajaxResponse();
1826  $response->addScript("alert('Permission denied!');");
1827  return($response->getXML());
1828  }
1829 
1830  // Instantiate the xajaxResponse object
1831  $response = new xajaxResponse();
1832  $js = '';
1833 
1834  // Validate input
1835  if (!$form['host'] and !$form['ip']) {
1836  $response->addScript("alert('Please complete all fields to continue!');");
1837  return($response->getXML());
1838  }
1839 
1840  // Decide if we're editing or adding
1841  $module = 'interface_share_del';
1842 
1843  // Run the module
1844  list($status, $output) = run_module($module, $form);
1845 
1846  // If the module returned an error code display a popup warning
1847  if ($status)
1848  $js .= "alert('Delete failed. ". preg_replace('/[\s\']+/', ' ', $self['error']) . "');";
1849  else {
1850  $js .= "removeElement('{$window_name}');";
1851  if ($form['js']) $js .= $form['js'];
1852  }
1853 
1854  // Insert the new table into the window
1855  $response->addScript($js);
1856  return($response->getXML());
1857 }
1858 
1859 
1860 
1861 
1862 
1863 
1864 
1865 
1866 
1868 // Function: quick_interface_menu($form)
1869 //
1870 // Description:
1871 // Builds HTML for displaying a quick menu popup.
1872 // Returns a two part array ($html, $js)
1874 function quick_interface_menu($form) {
1875  global $conf, $self, $onadb;
1876  global $font_family, $color, $style, $images;
1877  $html = $js = '';
1878 
1879  $html .= "<div style=\"text-align: center;color: black;padding-bottom:4px;font-weight: bold;\">Interface Actions<br/> [{$form['ip_addr']}]</div>";
1880 
1881 
1882  if (auth('interface_modify') and !$form['natip']) {
1883  $html .= <<<EOL
1884  <div class="row"
1885  onMouseOver="this.className='hovered';"
1886  onMouseOut="this.className='row';"
1887  title="Add an external NAT IP"
1888  class="act"
1889  onClick="wwTT(this, event,
1890  'id', 'tt_quick_interface_nat_{$form['interface_id']}',
1891  'type', 'static',
1892  'delay', 0,
1893  'styleClass', 'wwTT_qf',
1894  'direction', 'southwest',
1895  'javascript', 'xajax_window_submit(\'tooltips\', \'tooltip=>quick_interface_nat,id=>tt_quick_interface_nat_{$form['interface_id']},interface_id=>{$form['interface_id']},ip_addr=>{$form['ip_addr']}\');'
1896  );"
1897  ><img src="{$images}/silk/world_link.png" border="0">&nbsp; Add NAT IP</div>
1898 EOL;
1899  }
1900 
1901  if (auth('interface_modify') and $form['natip']) {
1902  $html .= <<<EOL
1903  <div class="row"
1904  onMouseOver="this.className='hovered';"
1905  onMouseOut="this.className='row';"
1906  title="Delete the external NAT IP"
1907  class="act"
1908  onClick="var doit=confirm('Are you sure you want to delete this NAT address?\\nIt will remove any DNS names associated with the external IP.');
1909  if (doit == true)
1910  xajax_window_submit('tooltips', 'ip=>{$form['interface_id']},natip=>{$form['natip']},nataction=>delete,commit=>yes', 'interface_nat_save');"
1911  ><img src="{$images}/silk/world_delete.png" border="0">&nbsp; Delete NAT IP</div>
1912 EOL;
1913  }
1914 
1915 
1916  if (auth('interface_modify')) {
1917  $html .= <<<EOL
1918  <div class="row"
1919  onMouseOver="this.className='hovered';"
1920  onMouseOut="this.className='row';"
1921  title="Move IP to another host"
1922  class="act"
1923  onClick="wwTT(this, event,
1924  'id', 'tt_quick_interface_move_{$form['interface_id']}',
1925  'type', 'static',
1926  'delay', 0,
1927  'styleClass', 'wwTT_qf',
1928  'direction', 'southwest',
1929  'javascript', 'xajax_window_submit(\'tooltips\', \'tooltip=>quick_interface_move,id=>tt_quick_interface_move_{$form['interface_id']},interface_id=>{$form['interface_id']},ip_addr=>{$form['ip_addr']},orig_host=>{$form['orig_host']}\');'
1930  );"
1931  ><img src="{$images}/silk/lorry_flatbed.png" border="0">&nbsp; Move IP</div>
1932 EOL;
1933  }
1934 
1935  if (auth('interface_modify')) {
1936  $html .= <<<EOL
1937  <div class="row"
1938  onMouseOver="this.className='hovered';"
1939  onMouseOut="this.className='row';"
1940  title="Share IP with another host (hsrp,carp,vrrp)"
1941  class="act"
1942  onClick="wwTT(this, event,
1943  'id', 'tt_quick_interface_share_{$form['interface_id']}',
1944  'type', 'static',
1945  'delay', 0,
1946  'styleClass', 'wwTT_qf',
1947  'direction', 'southwest',
1948  'javascript', 'xajax_window_submit(\'tooltips\', \'tooltip=>quick_interface_share,id=>tt_quick_interface_share_{$form['interface_id']},interface_id=>{$form['interface_id']},ip_addr=>{$form['ip_addr']}\');'
1949  );"
1950  ><img src="{$images}/silk/sitemap.png" border="0">&nbsp; Share IP</div>
1951 EOL;
1952  }
1953 
1954  if (auth('interface_modify')) {
1955  $html .= <<<EOL
1956  <div class="row"
1957  onMouseOver="this.className='hovered';"
1958  onMouseOut="this.className='row';"
1959  title="Add DNS record to this interface"
1960  class="act"
1961  onClick="xajax_window_submit('edit_record', xajax.getFormValues('{$form['form_id']}'), 'editor');setTimeout('toggleBox(\'edit_record\');',500);"
1962  ><img src="{$images}/silk/font_add.png" border="0">&nbsp; Add DNS</div>
1963 EOL;
1964  }
1965 
1966 
1967 
1968  return(array($html, $js));
1969 }
1970 
1971 
1972 
1973 
1974 
1976 // Function: quick_interface_nat($form)
1977 //
1978 // Description:
1979 // Builds HTML for displaying a quick search popup.
1980 // Returns a two part array ($html, $js)
1982 function quick_interface_nat($form) {
1983  global $conf, $self, $onadb;
1984  global $font_family, $color, $style, $images;
1985  $html = $js = '';
1986  $font_color = '#FFFFFF';
1987 
1988  $style['content_box'] = <<<EOL
1989  padding: 2px 4px;
1990  vertical-align: top;
1991 EOL;
1992 
1993  // WARNING: this one's different than most of them!
1994  $style['label_box'] = <<<EOL
1995  font-weight: bold;
1996  cursor: move;
1997  color: #FFFFFF;
1998 EOL;
1999 
2000 
2001 
2002  $html .= <<<EOL
2003 
2004  <!-- QUICK INTERFACE NAT -->
2005  <form id="quick_interface_nat_form" onSubmit="return(false);">
2006  <input type="hidden" name="id" value="{$form['id']}">
2007  <input type="hidden" name="js" value="{$form['js']}">
2008  <input type="hidden" name="nataction" value="add">
2009  <input type="hidden" name="ip" value="{$form['interface_id']}">
2010  <table style="{$style['content_box']}" cellspacing="0" border="0" cellpadding="0">
2011 
2012  <tr><td colspan="2" align="center" class="qf-search-line" style="{$style['label_box']}; padding-top: 0px;" onMouseDown="dragStart(event, '{$form['id']}', 'savePosition', 0);">
2013  Quick interface NAT
2014  </td></tr>
2015 
2016  <tr>
2017  <td align="right" class="qf-search-line">
2018  Internal IP
2019  </td>
2020  <td align="left" class="qf-search-line">
2021  {$form['ip_addr']}
2022  </td>
2023  </tr>
2024 
2025 
2026  <tr>
2027  <td align="right" class="qf-search-line">
2028  <u>E</u>xternal NAT IP
2029  </td>
2030  <td align="left" class="qf-search-line">
2031  <input id="natip" name="natip" type="text" class="edit" size="24" accesskey="e" value="{$form['natip']}" />
2032  </td>
2033  </tr>
2034 
2035  <tr>
2036  <td align="right" class="qf-search-line">
2037  &nbsp;
2038  </td>
2039  <td align="right" class="qf-search-line">
2040  <input class="button" type="button" name="cancel" value="Cancel" onClick="removeElement('{$form['id']}');">
2041  <input class="button" type="button" name="save" value="Save" accesskey="m" onClick="xajax_window_submit('tooltips', xajax.getFormValues('quick_interface_nat_form'), 'interface_nat_save');removeElement('{$form['id']}');">
2042  </td>
2043  </tr>
2044 
2045  </table>
2046  </form>
2047 EOL;
2048 
2049  // Javascript to run after the window is built
2050  $js .= <<<EOL
2051  el('natip').focus();
2052 EOL;
2053 
2054  return(array($html, $js));
2055 }
2056 
2057 
2058 
2059 
2060 
2062 // Function:
2063 // Save Form
2064 //
2065 // Description:
2066 // Creates/updates an interface record.
2068 function ws_interface_nat_save($window_name, $form='') {
2069  global $base, $include, $conf, $self, $onadb;
2070 
2071  // Check permissions
2072  if (! (auth('interface_modify')) ) {
2073  $response = new xajaxResponse();
2074  $response->addScript("alert('Permission denied!');");
2075  return($response->getXML());
2076  }
2077 
2078  $form = parse_options_string($form);
2079 
2080  // Instantiate the xajaxResponse object
2081  $response = new xajaxResponse();
2082  $js = '';
2083 
2084  $refresh = "xajax_window_submit('list_interfaces', xajax.getFormValues('list_interfaces_filter_form'), 'display_list');";
2085 
2086  // Validate input
2087  if (!$form['ip'] and !$form['natip']) {
2088  $response->addScript("alert('Please complete all fields to continue!');");
2089  return($response->getXML());
2090  }
2091 
2092  // Decide if we're deleting or adding
2093  $module = 'nat_add';
2094  if ($form['nataction'] == "delete") { $module = 'nat_del'; }
2095 
2096  // Do a pre check of the ptr domain so we can prompt the user properly
2097  if ($module == 'nat_add') {
2098  $ipflip = ip_mangle($form['natip'],'flip');
2099  $octets = explode(".",$ipflip);
2100  list($status, $rows, $ptrdomain) = ona_find_domain($ipflip.".in-addr.arpa");
2101  if (!$ptrdomain['id']) {
2102  printmsg("ERROR => This operation tried to create a PTR record that is the first in the {$octets[3]}.0.0.0 class A range. You must first create at least the following DNS domain: {$octets[3]}.in-addr.arpa",3);
2103  $self['error'] = "ERROR => This operation tried to create a PTR record that is the first in the {$octets[3]}.0.0.0 class A range. You must first create at least the following DNS domain: {$octets[3]}.in-addr.arpa. You could also create domains for class B or class C level reverse zones. Click OK to open add domain dialog";
2104  $response->addScript("alert('{$self['error']}');xajax_window_submit('edit_domain', 'newptrdomainname=>{$octets[3]}.in-addr.arpa', 'editor');");
2105  return($response->getXML());
2106  }
2107  }
2108 
2109  // Run the module
2110  list($status, $output) = run_module($module, $form);
2111 
2112  // If the module returned an error code display a popup warning
2113  if ($status)
2114  $js .= "alert('Save failed. ". preg_replace('/[\s\']+/', ' ', $self['error']) . "');";
2115  else {
2116  $js .= "removeElement('{$window_name}');{$refresh}";
2117  if ($form['js']) $js .= $form['js'];
2118  }
2119 
2120 
2121  // Insert the new table into the window
2122  $response->addScript($js);
2123  return($response->getXML());
2124 }
2125 
2126 
2127 
2128 
2129 
2131 // Function: quick_interface_move($form)
2132 //
2133 // Description:
2134 // Builds HTML for displaying a quick search popup.
2135 // Returns a two part array ($html, $js)
2137 function quick_interface_move($form) {
2138  global $conf, $self, $onadb;
2139  global $font_family, $color, $style, $images;
2140  $html = $js = '';
2141  $font_color = '#FFFFFF';
2142 
2143  $style['content_box'] = <<<EOL
2144  padding: 2px 4px;
2145  vertical-align: top;
2146 EOL;
2147 
2148  // WARNING: this one's different than most of them!
2149  $style['label_box'] = <<<EOL
2150  font-weight: bold;
2151  cursor: move;
2152  color: #FFFFFF;
2153 EOL;
2154 
2155 
2156  // If this is the last interface, inform the user that the host is to be deleted
2157  list($status, $total_interfaces, $ints) = db_get_records($onadb, 'interfaces', array('host_id' => $form['orig_host']), '', 0);
2158  $lastint_js = '';
2159  if ($total_interfaces == 1) {
2160  $lastint_js = "var doit=confirm('This is the last interface on this host, the host will also be deleted once the interface is moved?'); if (doit == true) ";
2161  }
2162 
2163 
2164  $html .= <<<EOL
2165 
2166  <!-- QUICK INTERFACE MOVE -->
2167  <form id="quick_interface_move_form" onSubmit="return(false);">
2168  <input type="hidden" name="id" value="{$form['id']}">
2169  <input type="hidden" name="js" value="{$form['js']}">
2170  <input type="hidden" name="ip" value="{$form['interface_id']}">
2171  <input type="hidden" name="orig_host" value="{$form['orig_host']}">
2172  <table style="{$style['content_box']}" cellspacing="0" border="0" cellpadding="0">
2173 
2174  <tr><td colspan="2" align="center" class="qf-search-line" style="{$style['label_box']}; padding-top: 0px;" onMouseDown="dragStart(event, '{$form['id']}', 'savePosition', 0);">
2175  Quick interface move
2176  </td></tr>
2177 
2178  <tr>
2179  <td align="right" class="qf-search-line">
2180  Move IP
2181  </td>
2182  <td align="left" class="qf-search-line">
2183  {$form['ip_addr']}
2184  </td>
2185  </tr>
2186 
2187 
2188  <tr>
2189  <td align="right" class="qf-search-line">
2190  to <u>H</u>ost
2191  </td>
2192  <td align="left" class="qf-search-line">
2193  <input id="move_hostname" name="host" type="text" class="edit" size="24" accesskey="h" autocomplete="off" />
2194  <div id="suggest_move_hostname" class="suggest"></div>
2195  </td>
2196  </tr>
2197 
2198  <tr>
2199  <td align="right" class="qf-search-line">
2200  &nbsp;
2201  </td>
2202  <td align="right" class="qf-search-line">
2203  <input class="button" type="button" name="cancel" value="Cancel" onClick="removeElement('{$form['id']}');">
2204  <input class="button" type="button" name="move" value="Move" accesskey="m" onClick="{$lastint_js} xajax_window_submit('tooltips', xajax.getFormValues('quick_interface_move_form'), 'interface_move_save');removeElement('{$form['id']}');">
2205  </td>
2206  </tr>
2207 
2208  </table>
2209  </form>
2210 EOL;
2211 
2212  // Javascript to run after the window is built
2213  $js .= <<<EOL
2214  el('move_hostname').focus();
2215  suggest_setup('move_hostname', 'suggest_move_hostname');
2216 EOL;
2217 
2218  return(array($html, $js));
2219 }
2220 
2221 
2222 
2223 
2224 
2226 // Function:
2227 // Save Form
2228 //
2229 // Description:
2230 // Creates/updates an interface record.
2232 function ws_interface_move_save($window_name, $form='') {
2233  global $base, $include, $conf, $self, $onadb;
2234 
2235  // Check permissions
2236  if (! (auth('advanced')) ) {
2237  $response = new xajaxResponse();
2238  $response->addScript("alert('Permission denied!');");
2239  return($response->getXML());
2240  }
2241 
2242  // Instantiate the xajaxResponse object
2243  $response = new xajaxResponse();
2244  $js = '';
2245 
2246  $refresh = "xajax_window_submit('list_interfaces', xajax.getFormValues('list_interfaces_filter_form'), 'display_list');";
2247 
2248  // Validate input
2249  if (!$form['host'] and !$form['ip']) {
2250  $response->addScript("alert('Please complete all fields to continue!');");
2251  return($response->getXML());
2252  }
2253 
2254  list($status, $total_interfaces, $ints) = db_get_records($onadb, 'interfaces', array('host_id' => $form['orig_host']), '', 0);
2255 
2256  // Decide if we're editing or adding
2257  $module = 'interface_move_host';
2258 
2259  // Run the module
2260  list($status, $output) = run_module($module, $form);
2261 
2262  // If the module returned an error code display a popup warning
2263  if ($status)
2264  $js .= "alert('Save failed. ". preg_replace('/[\s\']+/', ' ', $self['error']) . "');";
2265  else {
2266  // Check if this is the last interface, if it is, delete the host too.
2267  if ($total_interfaces == 0) {
2268  // Run the host del module
2269  list($status, $output) = run_module('host_del', array('host' => $form['orig_host'], 'commit' => 'y'));
2270  if ($status) {
2271  // If the host del failed, move the interface back to the original host to clean things up
2272  list($status, $output) = run_module('interface_move_host', array('host' => $form['orig_host'], 'ip' => $form['ip']));
2273  $js .= "alert('Host delete failed. ". preg_replace('/[\s\']+/', ' ', $self['error']) . "');";
2274  }
2275  else {
2276  $js .= "removeElement('{$window_name}');{$refresh}";
2277  if ($form['js']) $js .= $form['js'];
2278  }
2279  }
2280  else {
2281  $js .= "removeElement('{$window_name}');{$refresh}";
2282  if ($form['js']) $js .= $form['js'];
2283  }
2284  }
2285 
2286 
2287  // Insert the new table into the window
2288  $response->addScript($js);
2289  return($response->getXML());
2290 }
2291 
2292 
2293 
2294 
2295 
2296 
2298 // Function: get_custom_attribute_info_html($form)
2299 //
2300 // Description:
2301 // Builds HTML for displaying info about custom attributes hosts
2302 // Returns a two part array ($html, $js)
2305  global $conf, $self, $onadb;
2306  global $font_family, $color, $style, $images;
2307 
2308  $html = $js = '';
2309 
2310  list($status, $rows, $ca) = ona_get_custom_attribute_record(array('id' => $form['ca_id']));
2311  if ($rows == 0 or $status) return(array('', ''));
2312 
2313 
2314  $html .= <<<EOL
2315  <!-- Custom Attribute Info -->
2316  <table cellspacing="0" border="0" cellpadding="0">
2317 
2318  <tr>
2319  <td align="left" nowrap="true" colspan="99"><b><u>Custom Attribute Info</u></b>&nbsp;</td>
2320  </tr>
2321 
2322  <tr>
2323  <td align="right" nowrap="true" style="font-weight: bold;">
2324  {$window['edit_type']}
2325  </td>
2326  <td class="padding" align="left" >
2327  {$window['edit_type_value']}
2328  </td>
2329  </tr>
2330 
2331  <tr>
2332  <td align="right" nowrap="true" style="font-weight: bold;">
2333  Type
2334  </td>
2335  <td class="padding" align="left" >
2336  {$ca['name']}
2337  </td>
2338  </tr>
2339 
2340  <tr>
2341  <td align="right" nowrap="true" style="font-weight: bold;">
2342  Value
2343  </td>
2344  <td class="padding" align="left" >
2345  <textarea
2346  name="value"
2347  alt="Value"
2348  style="font-family: inherit;background-color: white;"
2349  readonly="true"
2350  rows="6"
2351  cols="40"
2352  >{$ca['value']}</textarea>
2353  </td>
2354  </tr>
2355 
2356 EOL;
2357 
2358  $html .= <<<EOL
2359  </table>
2360 EOL;
2361 
2362  return(array($html, $js));
2363 }
2364 
2365 
2366 
2367 
2368 
2369 
2371 // Function: get_switchport_template_select($)
2372 //
2373 // Description:
2374 //
2375 // Returns a two part array ($html, $js)
2378  global $conf, $self, $onadb;
2379  global $font_family, $color, $style, $images;
2380 
2381  $html = $js = '';
2382 
2383 
2384 /* $style['content_box'] = <<<EOL
2385  margin: 10px 20px;
2386  padding: 2px 4px;
2387  background-color: #FFFFFF;
2388  vertical-align: top;
2389 EOL;
2390 
2391  $style['label_box'] = <<<EOL
2392  font-weight: bold;
2393  padding: 2px 4px;
2394  text-align: center;
2395  border: solid 1px {$color['border']};
2396  background-color: {$color['window_content_bg']};
2397 EOL; */
2398  $style['content_box'] = <<<EOL
2399  padding: 2px 4px;
2400  vertical-align: top;
2401 EOL;
2402 
2403  // WARNING: this one's different than most of them!
2404  $style['label_box'] = <<<EOL
2405  font-weight: bold;
2406  cursor: move;
2407  color: #FFFFFF;
2408 EOL;
2409 
2410  $html .= <<<EOL
2411  <!-- SWITCHPORT TEMPLATE SELECT -->
2412  <form id="switchport_template_select_form" onSubmit="return(false);">
2413  <input type="hidden" name="host" value="{$form['host']}">
2414  <input type="hidden" name="input_id" value="{$form['input_id']}">
2415  <table id="switchport_template_select" style="{$style['content_box']}" cellspacing="0" border="0" cellpadding="0">
2416  <tr>
2417  <td colspan="2" align="center" class="qf-search-line" style="{$style['label_box']}; padding-top: 0px;" onMouseDown="dragStart(event, '{$form['id']}', 'savePosition', 0);">
2418  Switchport Template Select
2419  </td>
2420  </tr>
2421  <tr>
2422  <td align="right" class="qf-search-line">Switch:&nbsp;</td>
2423  <td align="left" class="qf-search-line">{$form['host']}</td>
2424  </tr>
2425  <tr>
2426  <td align="right" class="qf-search-line">Interface:&nbsp;</td>
2427  <td align="left" class="qf-search-line">{$form['if_name']}</td>
2428  </tr>
2429  <tr>
2430  <td align="right" class="qf-search-line">Current:&nbsp;</td>
2431  <td align="left" class="qf-search-line">{$form['original_value']}</td>
2432  </tr>
2433  <tr>
2434  <td align="right" class="qf-search-line">Last Changed:&nbsp;</td>
2435  <td align="left" class="qf-search-line">{$form['time']} by {$form['user']}</td>
2436  </tr>
2437  <tr>
2438  <td colspan="2" class="qf-search-line" align="left">
2439  <div id="qf_template_list" style="overflow: auto; display: block; background-color: rgb(255, 255, 255); height: 150px;">
2440  <table style="cursor: pointer;" border="0" cellpadding="0" cellspacing="0" width="100%"><tbody>
2441 EOL;
2442  $templates=explode("|",$form['template_list']);
2443  foreach($templates as $template) {
2444  $orig_template = "orig_".$template;
2445 
2446  $html .= <<<EOL
2447  <tr onmouseover="this.className='row-highlight';"
2448  onmouseout="this.className='row-normal';"
2449  onclick="var _el1 = el('{$form['if_name']}');
2450  var _el2 = '{$form['original_value']}';
2451  _el1.value = '$template';
2452  _el1.style.backgroundColor = '#8ABBFF';
2453  if(_el1.value == _el2) { _el1.style.backgroundColor = '#FFFFFF'; }
2454  removeElement('{$form['id']}');">
2455  <td style="padding: 0px 2px; font-size: 10px;">{$template}</td>
2456  </tr>
2457 EOL;
2458  }
2459  $html .= <<<EOL
2460  </div></tbody></table>
2461  </td></tr>
2462  <td colspan="2"align="center" class="qf-search-line">
2463  <input class="button" type="button" name="cancel" value="Cancel" onClick="removeElement('{$form['id']}');">
2464  </td></tr>
2465  </table>
2466  </form>
2467 EOL;
2468 
2469  return(array($html, $js));
2470 }
2471 
2472 
2473 // Simple ping function that takes an IP in and pings it.. then shows the output in a module results window
2474 function ws_ping($window_name, $form='') {
2475 
2476  // If an array in a string was provided, build the array and store it in $form
2477  $form = parse_options_string($form);
2478 
2479  $output = shell_exec("ping -n -w 3 -c 3 {$form['ip']}");
2480 
2481  $window['title'] = 'Ping Results';
2482  $build_commit_html = 0;
2483  $commit_function = '';
2484  include(window_find_include('module_results'));
2485  return(window_open("{$window_name}_results", $window));
2486 }
2487 
2489 // Setup empty window with a progress bar in it
2490 //
2491 // usage:
2492 //
2493 // xajax_window_submit('tooltips', 'name=>edit_host', 'window_progressbar');
2494 //
2495 // Name => is the value of the window that is going to be submitted that will fill this window when done
2496 // This usually preceeds a command like xajax_window_submit('edit_host', xajax.getFormValues('form_host_{$record['id']}'), 'delete');
2498 // Setup empty window with a progress bar in it
2499 function ws_window_progressbar($window_name, $form='') {
2500  global $images;
2501 
2502  // If an array in a string was provided, build the array and store it in $form
2503  $form = parse_options_string($form);
2504 
2505  $window_name = $form['name'];
2506 
2507  $output = "<center>Working on the results, please wait<br><img src={$images}/loading.gif></center>";
2508 
2509  $window['title'] = 'Processing...';
2510  $window['js'] = "el('{$window_name}_extras').innerHTML='<br>';";
2511  $build_commit_html = 0;
2512  $commit_function = '';
2513  include(window_find_include('module_results'));
2514  return(window_open("{$window_name}_results", $window));
2515 }
2516 
2517 
2518 ?>
ona_get_host_record
ona_get_host_record($array='', $order='')
Definition: functions_db.inc.php:1106
workspace_plugin_loader
workspace_plugin_loader($modulename, $record=array(), $extravars=array())
Definition: functions_gui.inc.php:140
quick_subnet_search
quick_subnet_search($form)
Definition: tooltips.inc.php:801
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
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_get_interface_record
ona_get_interface_record($array='', $order='')
Definition: functions_db.inc.php:1126
ws_interface_share_save
ws_interface_share_save($window_name, $form='')
Definition: tooltips.inc.php:1769
ws_tag_html
ws_tag_html($window_name, $form='')
Definition: tooltips.inc.php:137
ona_find_host
ona_find_host($search="")
Definition: functions_db.inc.php:1490
window_find_include
window_find_include($window_name)
Definition: webwin.inc.php:204
$record
$record['display_name']
Definition: app_advanced_search.inc.php:12
$usage_html
$usage_html
Definition: main.inc.php:6
ws_switch_context
ws_switch_context($window_name, $form='')
Definition: tooltips.inc.php:369
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
get_perms
get_perms($login_name='')
Definition: functions_auth.inc.php:132
$window
$window['title']
Definition: install.php:26
quick_location_search
quick_location_search($form)
Definition: tooltips.inc.php:931
get_sys_alert_html
get_sys_alert_html($form)
Definition: tooltips.inc.php:289
$baseURL
$baseURL
Definition: config.inc.php:25
printmsg
if(6<=$conf['debug']) printmsg($msg="", $debugLevel=0)
Definition: functions_general.inc.php:48
get_host_interface_list_html
get_host_interface_list_html($form)
Definition: tooltips.inc.php:1453
quick_interface_share
quick_interface_share($form)
Definition: tooltips.inc.php:1673
quick_interface_nat
quick_interface_nat($form)
Definition: tooltips.inc.php:1982
$include
$include
Definition: 2-to-3.php:10
window_open
window_open($window_name, $window=array())
Definition: webwin.inc.php:59
ona_get_custom_attribute_record
ona_get_custom_attribute_record($array)
Definition: functions_db.inc.php:1183
$type
$type
Definition: dcm.php:17
ws_interface_move_save
ws_interface_move_save($window_name, $form='')
Definition: tooltips.inc.php:2232
$host
$host
Definition: collate-convert.php:19
ws_logingo
ws_logingo($window_name, $form='')
Definition: tooltips.inc.php:487
quick_tag_add
quick_tag_add($form)
Definition: tooltips.inc.php:1057
run_module
run_module($module='', $options='', $transaction=1)
Definition: functions_general.inc.php:1468
quick_interface_move
quick_interface_move($form)
Definition: tooltips.inc.php:2137
ws_interface_share_del
ws_interface_share_del($window_name, $form='')
Definition: tooltips.inc.php:1820
get_subnet_usage_html
get_subnet_usage_html($subnet_id, $width=30, $height=8)
Definition: functions_gui.inc.php:294
$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
ws_ping
ws_ping($window_name, $form='')
Definition: tooltips.inc.php:2474
tagsort
tagsort($a, $b)
Definition: tooltips.inc.php:126
get_interface_cluster_list_html
get_interface_cluster_list_html($form)
Definition: tooltips.inc.php:1550
ws_window_progressbar
ws_window_progressbar($window_name, $form='')
Definition: tooltips.inc.php:2499
get_message_lines_html
get_message_lines_html($where)
Definition: tooltips.inc.php:192
Username
</td ></td ><!-- commented out for now till LDAP stuff is usefull< tr >< td colspan="2" align="center" class="padding" style="font-weight: bold;">< u > Domain Info</u ></td ></td >< tr >< td align="right" valign="top" class="padding" style="font-weight: bold;"> Username
Definition: app_user_info.inc.php:92
$conf
global $conf
Definition: 2-to-3.php:15
xajaxResponse
Definition: xajaxResponse.inc.php:68
$subnet_type_list
$subnet_type_list
Definition: app_advanced_search.inc.php:11
$style
$style['font-family']
Definition: config.inc.php:158
$ip
$ip
Definition: main.inc.php:24
ona_get_subnet_type_record
ona_get_subnet_type_record($array)
Definition: functions_db.inc.php:1237
quick_pool_server_search
quick_pool_server_search($form)
Definition: tooltips.inc.php:1357
quick_free_ip_search
quick_free_ip_search($form)
Definition: tooltips.inc.php:1224
get_subnet_html
get_subnet_html($subnet_ip)
Definition: tooltips.inc.php:528
ws_interface_nat_save
ws_interface_nat_save($window_name, $form='')
Definition: tooltips.inc.php:2068
nbsp
& nbsp
Definition: install.php:36
get_loginform_html
get_loginform_html($form)
Definition: tooltips.inc.php:402
get_custom_attribute_info_html
get_custom_attribute_info_html($form)
Definition: tooltips.inc.php:2304
$font_family
global $font_family
Definition: app_admin_tools.inc.php:4
$output
$output
Definition: dcm.php:16
ona_get_record
ona_get_record($where="", $table="", $order="")
Definition: functions_db.inc.php:1053
$self
global $self
Definition: 2-to-3.php:15
quick_interface_menu
quick_interface_menu($form)
Definition: tooltips.inc.php:1874
get_switchport_template_select
get_switchport_template_select($form)
Definition: tooltips.inc.php:2377
$wspl
$wspl
Definition: main.inc.php:113
auth
auth($resource, $msg_level=1)
Definition: functions_general.inc.php:1330
ws_tooltips_submit
ws_tooltips_submit($window_name, $form='')
Definition: tooltips.inc.php:11
$base
$base
Definition: 2-to-3.php:8
$ona_contexts
n n $ona_contexts
Definition: install.php:354
ona_get_subnet_record
ona_get_subnet_record($array)
Definition: functions_db.inc.php:1226
cursor
_button style cursor
Definition: app_advanced_search.inc.php:49
$color
if($_SERVER['SERVER_PORT']==443) $color['bg']
Definition: config.inc.php:119
quick_vlan_search
quick_vlan_search($form)
Definition: tooltips.inc.php:1132
parse_options_string
parse_options_string($input)
Definition: xajax_setup.inc.php:88
get_authentication
get_authentication($login_name='', $login_password='')
Definition: functions_auth.inc.php:65