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)  

dhcp_entry.inc.php
Go to the documentation of this file.
1 <?php
2 // DON'T put whitespace at the beginning or end of this file!!!
3 
4 // Make sure we have necessary functions & DB connectivity
5 require_once($conf['inc_functions_db']);
6 
7 
8 
9 
10 
11 
13 // Function: dhcp_entry_add (string $options='')
14 //
15 // $options = key=value pairs of options for this function.
16 // multiple sets of key=value pairs should be separated
17 // by an "&" symbol.
18 //
19 // Input Options:
20 // host=HOSTNAME[.DOMAIN] or host_id
21 // OR
22 // subnet=NAME or id
23 // OR
24 // server=NAME[.DOMAIN] or id
25 // AND
26 // type=DHCP type
27 // value=STRING
28 //
29 // Output:
30 // Adds a DHCP entry into the IP database of 'type' with a
31 // value of 'value' for the specified 'host', 'subnet', or
32 // 'server'.
33 // Returns a two part list:
34 // 1. The exit status of the function. 0 on success, non-zero on
35 // error. All errors messages are stored in $self['error'].
36 // 2. A textual message for display on the console or web interface.
37 //
38 // Example: list($status, $result) = dhcp_entry_add('host=q1234.something.com&type="Default gateway(s)"&value=10.1.1.1');
40 function dhcp_entry_add($options="") {
41 
42  // The important globals
43  global $conf, $self, $onadb;
44 
45  // Version - UPDATE on every edit!
46  $version = '1.03';
47 
48  printmsg("DEBUG => dhcp_entry_add({$options}) called", 3);
49 
50  // Parse incoming options string to an array
51  $options = parse_options($options);
52 
53  // if global is set to N then get rid of it entirely from the options array
54  $options['global'] = sanitize_YN($options['global'], 'N');
55  if ($options['global'] == 'N') { unset($options['global']); }
56 
57  // Return the usage summary if we need to
58  if ($options['help'] or !(
59  ($options['option'] and array_key_exists('value', $options))
60  and
61  (
62  ($options['server'] and !($options['host'] or $options['subnet'] or $options['global']))
63  or
64  ($options['host'] and !($options['server'] or $options['subnet'] or $options['global']))
65  or
66  ($options['subnet'] and !($options['host'] or $options['server'] or $options['global']))
67  or
68  (array_key_exists('global', $options) and !($options['host'] or $options['server'] or $options['subnet']))
69  )
70  )
71  )
72  {
73  // NOTE: Help message lines should not exceed 80 characters for proper display on a console
74  $self['error'] = 'ERROR => Insufficient parameters';
75  return(array(1,
76 <<<EOM
77 
79 Adds a dhcp entry into the database pointing to the specified identifier
80 
81  Synopsis: dhcp_entry_add [KEY=VALUE] ...
82 
83  Identifier (pick one):
84  host=HOSTNAME[.DOMAIN] or ID host identifier to add to
85  subnet=NAME or ID subnet identifier to add to
86  server=NAME[.DOMAIN] or ID server identifier to add to
87  global global entry for all subnets/hosts etc
88 
89  Options (both required):
90  option=DHCP option name DHCP option name (as identified in ONA)
91  value=STRING string value for the DHCP type
92 
93 \n
94 EOM
95 
96  ));
97  }
98 
99  // trim leading and trailing whitespace from 'value' and check that a value exists
100  $dhcp_option_value = trim($options['value']);
101  if (strlen($dhcp_option_value) == 0 ) {
102  printmsg("DEBUG => The DHCP value was blank",3);
103  $self['error'] = "ERROR => DHCP value was blank";
104  return(array(2, $self['error'] . "\n"));
105  }
106 
107  if ($options['global'] == 'Y') {
108  $anchor = 'global';
109  $desc = 'Global DHCP option';
110  $lvl = 0;
111  $subnet['id'] = 0;
112  $server['host_id'] = 0;
113  $host['id'] = 0;
114  } elseif ($options['host']) {
115  // Determine the host is valid
116  list($status, $rows, $host) = ona_find_host($options['host']);
117 
118  if (!$host['id']) {
119  printmsg("DEBUG => The host specified, {$options['host']}, does not exist!",3);
120  $self['error'] = "ERROR => The host specified, {$options['host']}, does not exist!";
121  return(array(2, $self['error'] . "\n"));
122  }
123 
124  $anchor = 'host';
125  $desc = $host['fqdn'];
126  $lvl = $host['lvl'];
127  $subnet['id'] = 0;
128  $server['host_id'] = 0;
129 
130  } elseif ($options['subnet']) {
131  // Determine the subnet is valid
132  list($status, $rows, $subnet) = ona_find_subnet($options['subnet']);
133 
134  if (!$subnet['id']) {
135  printmsg("DEBUG => The subnet specified, {$options['subnet']}, does not exist!",3);
136  $self['error'] = "ERROR => The subnet specified, {$options['subnet']}, does not exist!";
137  return(array(3, $self['error'] . "\n"));
138  }
139 
140  $anchor = 'subnet';
141  $desc = "{$subnet['name']} (". ip_mangle($subnet['ip_addr']).")";
142  $lvl = $subnet['lvl'];
143  $host['id'] = 0;
144  $server['host_id'] = 0;
145 
146  } elseif ($options['server']) {
147  // Determine the server is valid
148  list($status, $rows, $host) = ona_find_host($options['server']);
149 
150  if (!$host['id']) {
151  printmsg("DEBUG => The server specified, {$options['server']}, does not exist!",3);
152  $self['error'] = "ERROR => The server specified, {$options['server']}, does not exist!";
153  return(array(4, $self['error'] . "\n"));
154  }
155 
156  // Determine the host that was found is actually a server
157  list($status, $rows, $server) = ona_get_dhcp_server_subnet_record(array('host_id' => $host['id']));
158 
159  if (!$rows) {
160  printmsg("DEBUG => The host specified, {$host['fqdn']}, is not a DHCP server!",3);
161  $self['error'] = "ERROR => The host specified, {$host['fqdn']}, is not a DHCP server!";
162  return(array(5, $self['error'] . "\n"));
163  }
164 
165  $anchor = 'server';
166  $desc = $host['fqdn'];
167  $lvl = $host['lvl'];
168  $host['id'] = 0;
169  $subnet['id'] = 0;
170  }
171 
172  // Determine the type is valid
173  list($status, $rows, $type) = ona_find_dhcp_option($options['option']);
174 
175  if (!$type['id']) {
176  printmsg("DEBUG => The DHCP parameter type specified, {$options['option']}, does not exist!",3);
177  $self['error'] = "ERROR => The DHCP parameter type specified, {$options['option']}, does not exist!";
178  return(array(8, $self['error'] . "\n"));
179  }
180 
181  printmsg("DEBUG => dhcp_entry_add(): Found DHCP option {$type['display_name']}", 3);
182 
183 
184  // Make sure this isn't a duplicate
185  $search = array('dhcp_option_id' => $type['id'], 'host_id' => 0, 'subnet_id' => 0);
186  if ($host['id']) $search['host_id'] = $host['id'];
187  if ($subnet['id']) $search['subnet_id'] = $subnet['id'];
188  if ($server['id']) $search['server_id'] = $server['id'];
189 
190  list($status, $rows, $record) = ona_get_dhcp_option_entry_record($search);
191  if ($status or $rows) {
192  printmsg("DEBUG => That DHCP option, {$type['display_name']}, is already defined!",3);
193  $self['error'] = "ERROR => That DHCP option ({$type['display_name']}) is already defined!";
194  return(array(11, $self['error'] . "\n"));
195  }
196 
197 
198 
199  // Check permissions
200  if (!auth('advanced') or !authlvl($lvl)) {
201  $self['error'] = "Permission denied!";
202  printmsg($self['error'], 0);
203  return(array(10, $self['error'] . "\n"));
204  }
205 
206  // Get the next id
207  $id = ona_get_next_id('dhcp_option_entries');
208  if (!$id) {
209  $self['error'] = "ERROR => The ona_get_next_id() call failed!";
210  printmsg($self['error'], 0);
211  return(array(6, $self['error'] . "\n"));
212  }
213  printmsg("DEBUG => dhcp_entry_add(): New ID: $id", 3);
214 
215  // Add the record
216  list($status, $rows) =
218  $onadb,
219  'dhcp_option_entries',
220  array(
221  'id' => $id,
222  'dhcp_option_id' => $type['id'],
223  'value' => $dhcp_option_value,
224  'host_id' => $host['id'],
225  'server_id' => $server['host_id'],
226  'subnet_id' => $subnet['id']
227  )
228  );
229  if ($status or !$rows) {
230  $self['error'] = "ERROR => dhcp_entry_add() SQL Query failed: " . $self['error'];
231  printmsg($self['error'], 0);
232  return(array(7, $self['error'] . "\n"));
233  }
234 
235  // Return the success notice
236  $self['error'] = "INFO => DHCP entry ADDED: {$type['display_name']}={$dhcp_option_value} on {$desc} ";
237  printmsg($self['error'], 0);
238  return(array(0, $self['error'] . "\n"));
239 }
240 
241 
242 
243 
244 
245 
246 
247 
248 
249 
250 
251 
253 // Function: dhcp_entry_del (string $options='')
254 //
255 // $options = key=value pairs of options for this function.
256 // multiple sets of key=value pairs should be separated
257 // by an "&" symbol.
258 //
259 // Input Options:
260 // id=id
261 //
262 // Output:
263 // Deletes a dhcp entry from the IP database.
264 // Returns a two part list:
265 // 1. The exit status of the function. 0 on success, non-zero on
266 // error. All errors messages are stored in $self['error'].
267 // 2. A textual message for display on the console or web interface.
268 //
269 // Example: list($status, $result) = dhcp_entry_add('host=test');
271 function dhcp_entry_del($options="") {
272 
273  // The important globals
274  global $conf, $self, $onadb;
275 
276  // Version - UPDATE on every edit!
277  $version = '1.01';
278 
279  printmsg("DEBUG => dhcp_entry_del({$options}) called", 3);
280 
281  // Parse incoming options string to an array
282  $options = parse_options($options);
283 
284  // Sanitize options[commit] (default is yes)
285  $options['commit'] = sanitize_YN($options['commit'], 'N');
286 
287  // Return the usage summary if we need to
288  if ($options['help'] or !$options['id'] ) {
289  // NOTE: Help message lines should not exceed 80 characters for proper display on a console
290  $self['error'] = 'ERROR => Insufficient parameters';
291  return(array(1,
292 <<<EOM
293 
295 Deletes a DHCP entry from the database
296 
297  Synopsis: dhcp_entry_del [KEY=VALUE] ...
298 
299  Required:
300  id=ID ID of the dhcp entry to delete
301 
302  Optional:
303  commit=[yes|no] commit db transaction (no)
304 \n
305 EOM
306 
307  ));
308  }
309 
310 
311  // Sanitize options[commit] (default is no)
312  $options['commit'] = sanitize_YN($options['commit'], 'N');
313  $desc = 'Global level';
314 
315  // If the option provided is numeric, check to see if it exists
316  if (is_numeric($options['id'])) {
317 
318  // Debugging
319  printmsg("DEBUG => DHCP entry ID selected: {$options['id']}", 3);
320 
321  list($status, $tmp_rows, $entry) = ona_get_dhcp_option_entry_record(array('id' => $options['id']));
322 
323  // Test to see that we were able to find the specified record
324  if (!$entry['id']) {
325  printmsg("DEBUG => Unable to find the DHCP entry record using ID {$options['id']}!",3);
326  $self['error'] = "ERROR => Unable to find the DHCP entry record using ID {$options['id']}!";
327  return(array(4, $self['error']. "\n"));
328  }
329 
330  // Assign a search option based on host or server id
331  if ($entry['host_id']) $search = $entry['host_id'];
332  if ($entry['server_id']) $search = $entry['server_id'];
333 
334  if ($entry['host_id'] or $entry['server_id']) {
335  // Get some host information to display later and determine its valid
336  list($status, $rows, $host) = ona_find_host($search);
337 
338  // Bail out if you cant find a host
339  if (!$host['id']) {
340  printmsg("DEBUG => The ID specified, {$search}, does not exist!",3);
341  $self['error'] = "ERROR => The ID specified, {$search}, does not exist!";
342  return(array(3, $self['error']. "\n"));
343  }
344 
345  printmsg("DEBUG => dhcp_entry_del(): Using host: {$host['fqdn']} ID: {$host['id']}", 3);
346  $desc = $host['fqdn'];
347  $lvl = $host['lvl'];
348 
349  } elseif ($entry['subnet_id']) {
350  // Determine the subnet is valid
351  list($status, $rows, $subnet) = ona_find_subnet($entry['subnet_id']);
352 
353  if (!$subnet['id']) {
354  printmsg("DEBUG => The subnet specified, {$options['subnet']}, does not exist!", 3);
355  $self['error'] = "ERROR => The subnet specified, {$options['subnet']}, does not exist!";
356  return(array(3, $self['error'] . "\n"));
357  }
358 
359  printmsg("DEBUG => dhcp_entry_del(): Using subnet: {$subnet['name']} ID: {$subnet['id']}", 3);
360  $desc = "{$subnet['name']} (". ip_mangle($subnet['ip_addr']).")";
361  $lvl = $subnet['lvl'];
362 
363  }
364 
365  } else {
366  printmsg("DEBUG => {$options['id']} is not a numeric value", 3);
367  $self['error'] = "ERROR => {$options['id']} is not a numeric value";
368  return(array(15, $self['error'] . "\n"));
369  }
370 
371 
372  // If "commit" is yes, delte the record
373  if ($options['commit'] == 'Y') {
374 
375  // Check permissions
376  if (!auth('advanced') or !authlvl($lvl)) {
377  $self['error'] = "Permission denied!";
378  printmsg($self['error'], 0);
379  return(array(10, $self['error'] . "\n"));
380  }
381 
382  list($status, $rows) = db_delete_records($onadb, 'dhcp_option_entries', array('id' => $entry['id']));
383  if ($status or !$rows) {
384  $self['error'] = "ERROR => dhcp_entry_del() SQL Query failed: " . $self['error'];
385  printmsg($self['error'], 0);
386  return(array(4, $self['error'] . "\n"));
387  }
388 
389  // Return the success notice
390  $self['error'] = "INFO => DHCP entry DELETED: {$entry['display_name']}={$entry['value']} from {$desc} ";
391  printmsg($self['error'], 0);
392  return(array(0, $self['error'] . "\n"));
393  }
394 
395  // Otherwise display the record that would have been deleted
396  $text = <<<EOL
397 Record(s) NOT DELETED (see "commit" option)
398 Displaying record(s) that would have been deleted:
399 
400 ON: {$desc}
401 
402  Delete the following dhcp entry:
403  ENTRY: {$entry['display_name']} = {$entry['value']}
404 
405 EOL;
406 
407  return(array(6, $text));
408 
409 }
410 
411 
412 
413 
414 
415 
416 
417 
418 
420 // Function: dhcp_entry_modify (string $options='')
421 //
422 // $options = key=value pairs of options for this function.
423 // multiple sets of key=value pairs should be separated
424 // by an "&" symbol.
425 //
426 // Input Options:
427 // host=HOSTNAME[.DOMAIN] or host_id
428 // OR
429 // subnet=NAME or id
430 // OR
431 // server=NAME[.DOMAIN] or id
432 // AND
433 // type=DHCP type
434 // value=STRING
435 //
436 // Output:
437 // Updates an dhcp_entry record in the IP database.
438 // Returns a two part list:
439 // 1. The exit status of the function. 0 on success, non-zero on
440 // error. All errors messages are stored in $self['error'].
441 // 2. A textual message for display on the console or web interface.
442 //
443 // Example: list($status, $result) = dhcp_entry_modify('set_value=something');
445 function dhcp_entry_modify($options="") {
446 
447  // The important globals
448  global $conf, $self, $onadb;
449 
450  // Version - UPDATE on every edit!
451  $version = '1.04';
452 
453  printmsg("DEBUG => dhcp_entry_modify({$options}) called", 3);
454 
455  // Parse incoming options string to an array
456  $options = parse_options($options);
457 
458  // Return the usage summary if we need to
459  if ($options['help'] or
460  !(
461  ($options['id'])
462  and
463  (
464  ($options['set_option'] and array_key_exists('set_value',$options))
465  or
466  (array_key_exists('set_value',$options))
467  )
468  )
469  )
470  {
471  // NOTE: Help message lines should not exceed 80 characters for proper display on a console
472  $self['error'] = 'ERROR => Insufficient parameters';
473  return(array(1,
474 <<<EOM
475 
477 Modifies a DHCP entry in the database
478 
479  Synopsis: dhcp_entry_modify [KEY=VALUE] ...
480 
481  Where:
482  id=ID DHCP entry ID
483 
484  Options:
485  set_option=DHCP type DHCP parameter type
486  set_value=STRING string value for the DHCP type
487 
488  Notes:
489  If you specify a type, you must specify a value.
490 \n
491 EOM
492  ));
493  }
494 
495  // Determine the entry itself exists
496  list($status, $rows, $entry) = ona_get_dhcp_option_entry_record(array('id' => $options['id']));
497  if ($status or !$rows) {
498  printmsg("DEBUG => Invalid DHCP entry record ID ({$options['id']})!",3);
499  $self['error'] = "ERROR => Invalid DHCP entry record ID ({$options['id']})!";
500  return(array(2, $self['error']. "\n"));
501  }
502 
503  printmsg("DEBUG => dhcp_entry_modify(): Found entry, {$entry['display_name']} => {$entry['value']}", 3);
504  $desc='';
505  // Load associated host, subnet or server record
506  $host = $subnet = $server = array();
507  if ($entry['host_id']) {
508  list($status, $rows, $host) = ona_find_host($entry['host_id']);
509  $desc = $host['fqdn'];
510  }
511  if ($entry['subnet_id']) {
512  list($status, $rows, $subnet) = ona_find_subnet($entry['subnet_id']);
513  $desc = "{$subnet['name']} (". ip_mangle($subnet['ip_addr']).")";
514  }
515  if ($entry['server_id']) {
516  list($status, $rows, $server) = ona_find_host($entry['server_id']);
517  $desc = $server['fqdn'];
518  }
519 
520  // Check permissions on source identifier
521  $lvl = 100;
522  if ($host['id']) $lvl = $host['lvl'];
523  if ($subnet['id']) $lvl = $subnet['lvl'];
524  if (!auth('advanced') or (!authlvl($lvl))) {
525  $self['error'] = "Permission denied!";
526  printmsg($self['error'], 0);
527  return(array(10, $self['error'] . "\n"));
528  }
529 
530  // unset $host if $server is defined .. we don't need it anymore
531  if ($server['id']) $host = array();
532 
533  // This variable will contain the updated info we'll insert into the DB
534  $SET = array();
535 
536 
537  if (array_key_exists('set_value', $options)) {
538  // trim leading and trailing whitespace from 'value'
539  $SET['value'] = trim($options['set_value']);
540  // trim leading and trailing whitespace from 'value' and check that a value exists
541  $SET['value'] = trim($options['set_value']);
542  if (strlen($SET['value']) == 0 ) {
543  printmsg("DEBUG => The DHCP value was blank",3);
544  $self['error'] = "ERROR => DHCP value was blank";
545  return(array(2, $self['error'] . "\n"));
546  }
547  }
548 
549 
550 
551  if ($options['set_option']) {
552  // Make sure they specified a value
553  if (!array_key_exists('set_value', $options)) {
554  printmsg("DEBUG => No value specified for given DHCP parameter type ({$options['set_option']})!", 3);
555  $self['error'] = "ERROR => No value specified for given DHCP parameter type ({$options['set_option']})!";
556  return(array(8, $self['error'] . "\n"));
557  }
558 
559  // Determine the type is valid
560  list($status, $rows, $type) = ona_find_dhcp_option(trim($options['set_option']));
561  if ($status or !$rows) {
562  printmsg("DEBUG => Invalid DHCP parameter type specified ({$options['set_option']})!", 3);
563  $self['error'] = "ERROR => Invalid DHCP parameter type specified ({$options['set_option']})!";
564  return(array(8, $self['error'] . "\n"));
565  }
566 
567  printmsg("DEBUG => dhcp_entry_modify(): Found parameter type {$type['display_name']}", 3);
568 
569  $SET['dhcp_option_id'] = $type['id'];
570 
571  // Make sure this isn't a duplicate
572  // TODO: this code seems a bit suspect of being nasty.. possibly fix it up
573  $search = array('dhcp_option_id' => $type['id'], 'host_id' => 0, 'subnet_id' => 0);
574  if ($host['id']) $search['host_id'] = $host['id'];
575  if ($subnet['id']) $search['subnet_id'] = $subnet['id'];
576  if ($server['id']) $search['server_id'] = $server['id'];
577  list($status, $rows, $record) = ona_get_dhcp_option_entry_record($search);
578  if ($status or $rows > 1 or ($rows == 1 and $record['id'] != $entry['id']) ) {
579  printmsg("DEBUG => That DHCP parameter type is already defined ({$search})!", 3);
580  $self['error'] = "ERROR => That DHCP parameter type is already defined ({$search})!";
581  return(array(11, $self['error'] . "\n"));
582  }
583 
584  }
585 
586  // Get the dhcp entry record before updating (logging)
587  list($status, $rows, $original_entry) = ona_get_dhcp_option_entry_record(array('id' => $entry['id']));
588 
589  // Update the record
590  list($status, $rows) = db_update_record($onadb, 'dhcp_option_entries', array('id' => $entry['id']), $SET);
591  if ($status or !$rows) {
592  $self['error'] = "ERROR => dhcp_entry_modify() SQL Query failed: " . $self['error'];
593  printmsg($self['error'], 0);
594  return(array(6, $self['error'] . "\n"));
595  }
596 
597  // Get the entry again to display details
598  list($status, $tmp_rows, $entry) = ona_get_dhcp_option_entry_record(array('id' => $entry['id']));
599 
600 
601  // Return the success notice
602  $self['error'] = "INFO => DHCP entry UPDATED:{$entry['id']}: \"{$entry['display_name']}\"={$entry['value']} on {$desc} ";
603 
604  $log_msg = "INFO => DHCP entry UPDATED:{$entry['id']}: ";
605  $more="";
606  foreach(array_keys($original_entry) as $key) {
607  if($original_entry[$key] != $entry[$key]) {
608  $log_msg .= $more . $key . "[" .$original_entry[$key] . "=>" . $entry[$key] . "]";
609  $more= ";";
610  }
611  }
612 
613  // only print to logfile if a change has been made to the record
614  if($more != '') {
615  printmsg($self['error'], 0);
616  printmsg($log_msg, 0);
617  }
618 
619  return(array(0, $self['error'] . "\n"));
620 }
621 
622 
623 
624 
625 
626 
627 
628 
629 
630 
631 
632 
633 
634 
635 
636 
637 
638 
640 // Function: dhcp_entry_display (string $options='')
641 //
642 // Input Options:
643 // $options = key=value pairs of options for this function.
644 // multiple sets of key=value pairs should be separated
645 // by an "&" symbol.
646 //
647 // Output:
648 // Returns a two part list:
649 // 1. The exit status of the function. 0 on success, non-zero on
650 // error. All errors messages are stored in $self['error'].
651 // 2. A textual message for display on the console or web interface.
652 //
653 // Example: list($status, $result) = dhcp_entry_display('host=test');
655 function dhcp_entry_display($options="") {
656 
657  // The important globals
658  global $conf, $self, $onadb;
659 
660  // Version - UPDATE on every edit!
661  $version = '1.00';
662 
663  printmsg("DEBUG => dhcp_entry_display({$options}) called", 3);
664 
665  // Parse incoming options string to an array
666  $options = parse_options($options);
667 
668  // Return the usage summary if we need to
669  if ($options['help'] or (!$options['host'] and !$options['server'] and !$options['subnet']) ) {
670  // NOTE: Help message lines should not exceed 80 characters for proper display on a console
671  $self['error'] = 'ERROR => Insufficient parameters';
672  return(array(1,
673 <<<EOM
674 
676 Displays an dhcp_entry record from the database
677 
678  Synopsis: dhcp_entry_display [KEY=VALUE] ...
679 
680  Required:
681  host=NAME[.DOMAIN] or id hostname or id of the host to display
682  OR
683  subnet=NAME or id description or id of the subnet to display
684  OR
685  server=NAME[.DOMAIN] or id hostname or id of the server to display
686 
687  Notes:
688  * DOMAIN will default to {$conf['dns_defaultdomain']} if not specified
689 \n
690 EOM
691 
692  ));
693  }
694 
695  if ($options['host']) {
696  // Determine the host is valid
697  list($status, $rows, $host) = ona_find_host($options['host']);
698 
699  if (!$host['id']) {
700  printmsg("DEBUG => The host specified, {$options['host']}, does not exist!", 3);
701  $self['error'] = "ERROR => The host specified, {$options['host']}, does not exist!";
702  return(array(2, $self['error'] . "\n"));
703  }
704 
705  $anchor = 'host';
706  $desc = $host['FQDN'];
707  $where = array('HOST_id' => $host['id']);
708  } elseif ($options['subnet']) {
709  // Determine the subnet is valid
710  list($status, $rows, $subnet) = ona_find_subnet($options['subnet']);
711 
712  if (!$subnet['id']) {
713  printmsg("DEBUG => The subnet specified, {$options['subnet']}, does not exist!", 3);
714  $self['error'] = "ERROR => The subnet specified, {$options['subnet']}, does not exist!";
715  return(array(3, $self['error'] . "\n"));
716  }
717 
718  $anchor = 'subnet';
719  $desc = "{$subnet['DESCRIPTION']} (". ip_mangle($subnet['IP_ADDRESS']).")";
720  $where = array('NETWORK_id' => $subnet['id']);
721 
722  } elseif ($options['server']) {
723  // Determine the server is valid
724  list($status, $rows, $host) = ona_find_host($options['server']);
725 
726  if (!$host['id']) {
727  printmsg("DEBUG => The server specified, {$options['server']}, does not exist!", 3);
728  $self['error'] = "ERROR => The server specified, {$options['server']}, does not exist!";
729  return(array(4, $self['error'] . "\n"));
730  }
731 
732  // Determine the host that was found is actually a server
733  list($status, $rows, $server) = ona_get_server_record(array('HOST_id' => $host['id']));
734 
735  if (!$server['id']) {
736  printmsg("DEBUG => The host specified, {$host['FQDN']}, is not a server!", 3);
737  $self['error'] = "ERROR => The host specified, {$host['FQDN']}, is not a server!";
738  return(array(5, $self['error'] . "\n"));
739  }
740 
741  $anchor = 'server';
742  $desc = $host['FQDN'];
743  $where = array('SERVER_id' => $server['id']);
744 
745  }
746 
747 
748  // Debugging
749  printmsg("DEBUG => dhcp_entry_display(): Found {$anchor}: {$desc}", 3);
750 
751 
752 
753 
754 
755 
756 
757  // Build text to return
758  $text = strtoupper($anchor) . " RECORD ({$desc})\n";
759 
760  // Display the record(s)
761  $i = 0;
762  do {
763  list($status, $rows, $entry) = ona_get_dhcp_entry_record($where);
764  if ($rows == 0) {
765  $text .= "\nNO ASSOCIATED DHCP ENTRY RECORDS\n";
766  break;
767  }
768  $i++;
769  $text .= "\nASSOCIATED DHCP ENTRY RECORD ({$i} of {$rows})\n";
770  $text .= format_array($entry);
771  } while ($i < $rows);
772 
773  // Return the success notice
774  return(array(0, $text));
775 
776 
777 }
778 
779 
780 
781 
782 
783 
784 
785 
786 
787 
788 // DON'T put whitespace at the beginning or end of this file!!!
789 ?>
db_insert_record
db_insert_record($dbh=0, $table="", $insert="")
Definition: functions_db.inc.php:375
sanitize_YN
sanitize_YN($string="", $default="Y")
Definition: functions_general.inc.php:1637
dhcp_entry_modify
dhcp_entry_modify($options="")
Definition: dhcp_entry.inc.php:445
ona_get_next_id
ona_get_next_id($tablename)
Definition: functions_db.inc.php:1369
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
$status
$status
Definition: install.php:12
$onadb
global $onadb
Definition: 2-to-3.php:15
ona_find_dhcp_option
ona_find_dhcp_option($search="")
Definition: functions_db.inc.php:2397
db_delete_records
db_delete_records($dbh=0, $table="", $where="")
Definition: functions_db.inc.php:582
dhcp_entry_display
dhcp_entry_display($options="")
Definition: dhcp_entry.inc.php:655
printmsg
if(6<=$conf['debug']) printmsg($msg="", $debugLevel=0)
Definition: functions_general.inc.php:48
dhcp_entry_del
dhcp_entry_del($options="")
Definition: dhcp_entry.inc.php:271
format_array
format_array($array=array())
Definition: functions_general.inc.php:1745
dhcp_entry_add
dhcp_entry_add($options="")
Definition: dhcp_entry.inc.php:40
$type
$type
Definition: dcm.php:17
authlvl
authlvl($level)
Definition: functions_general.inc.php:1349
$host
$host
Definition: collate-convert.php:19
db_update_record
db_update_record($dbh=0, $table="", $where="", $insert="")
Definition: functions_db.inc.php:474
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
$conf
global $conf
Definition: 2-to-3.php:15
$text
$text
Definition: install.php:11
$self
global $self
Definition: 2-to-3.php:15
ona_get_dhcp_server_subnet_record
ona_get_dhcp_server_subnet_record($array)
Definition: functions_db.inc.php:1280
auth
auth($resource, $msg_level=1)
Definition: functions_general.inc.php:1330
ona_get_dhcp_option_entry_record
ona_get_dhcp_option_entry_record($array)
Definition: functions_db.inc.php:1262
parse_options
parse_options($options="")
Definition: functions_general.inc.php:1579
$version
$version
Definition: main.inc.php:22