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)  

domain.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 
9 // Function: domain_add (string $options='')
10 //
11 // $options = key=value pairs of options for this function.
12 // multiple sets of key=value pairs should be separated
13 // by an "&" symbol.
14 //
15 // Input Options:
16 // name=STRING
17 // server=NAME[.DOMAIN]
18 // auth=[Y|N]
19 // optional:
20 // admin=STRING
21 // ptr=Y or N
22 // primary=STRING
23 // refresh=NUMBER
24 // retry=NUMBER
25 // expiry=NUMBER
26 // minimum=NUMBER
27 // parent=DOMAIN_NAME
28 //
29 // Output:
30 // Adds a domain entry into the IP database with a name of 'name'. All
31 // other values are optional and can reley on their defaults.
32 //
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) = domain_add('name=something.com');
40 function domain_add($options="") {
41  global $conf, $self, $onadb;
42  printmsg("DEBUG => domain_add({$options}) called", 3);
43 
44  // Version - UPDATE on every edit!
45  $version = '1.07';
46 
47  // Parse incoming options string to an array
48  $options = parse_options($options);
49 
50  // Return the usage summary if we need to
51  if ($options['help'] or !(
52  ($options['name'])
53  or
54  ($options['admin'] or $options['ptr'] or $options['primary_master'])
55  )
56  )
57  {
58  // NOTE: Help message lines should not exceed 80 characters for proper display on a console
59  $self['error'] = 'ERROR => Insufficient parameters';
60  return(array(1,
61 <<<EOM
62 
64 Adds a DNS domain into the database
65 
66  Synopsis: domain_add [KEY=VALUE] ...
67 
68  Required:
69  name=STRING full name of new domain
70  (i.e. name.something.com)
71 
72  Optional:
73  admin=STRING Default ({$conf['dns_admin_email']})
74  primary_master=STRING Default ({$conf['dns_primary_master']})
75  refresh=NUMBER Default ({$conf['dns_refresh']})
76  retry=NUMBER Default ({$conf['dns_retry']})
77  expiry=NUMBER Default ({$conf['dns_expiry']})
78  minimum=NUMBER Default ({$conf['dns_minimum']})
79  parent=DOMAIN_NAME Default ({$conf['dns_parent']})
80  ttl=NUMBER Default ({$conf['dns_default_ttl']})
81 
82 
83 EOM
84 
85  ));
86  }
87 
88  // Use default if something was not passed on command line
89  if ($options['admin']) { $admin = $options['admin']; } else { $admin = $conf['dns_admin_email']; }
90  if ($options['primary_master']) { $primary = $options['primary_master'];} else { $primary = $conf['dns_primary_master']; }
91  if ($options['refresh']) { $refresh = $options['refresh'];} else { $refresh = $conf['dns_refresh']; }
92  if ($options['retry']) { $retry = $options['retry']; } else { $retry = $conf['dns_retry']; }
93  if ($options['expiry']) { $expiry = $options['expiry']; } else { $expiry = $conf['dns_expiry']; }
94  if ($options['minimum']) { $minimum = $options['minimum'];} else { $minimum = $conf['dns_minimum']; }
95  if ($options['ttl']) { $ttl = $options['ttl'];} else { $ttl = $conf['dns_default_ttl']; }
96 
97  $options['name'] = trim($options['name']);
98  $options['parent'] = trim($options['parent']);
99  $options['primary_master'] = trim($options['primary_master']);
100  $options['admin'] = trim($options['admin']);
101 
102  // Setup array for searching existing domains
103  $exist_domain = array('name' => $options['name']);
104 
105  // get parent domain info
106  if ($options['parent']) {
107  list($status, $rows, $parent_domain) = ona_find_domain($options['parent'],0);
108  if (!isset($parent_domain['id'])) {
109  printmsg("DEBUG => The parent domain specified ({$options['parent']}) does not exist!", 3);
110  $self['error'] = "ERROR => The parent domain specified, {$options['parent']}, does not exist!";
111  return(array(5, $self['error'] . "\n"));
112  }
113  // Set up the parent part of the search if there was one
114  $exist_domain['parent_id'] = $parent_domain['id'];
115  } else {
116  $parent_domain['id'] = 0;
117  }
118 
119 
120  // Validate that this domain doesnt already exist
121  list($status, $rows, $record) = ona_get_domain_record($exist_domain);
122 
123  if ($record['id']) {
124  printmsg("DEBUG => The domain specified ({$record['name']}) already exists!", 3);
125  $self['error'] = "ERROR => The domain specified, {$options['name']}, already exists!";
126  return(array(11, $self['error'] . "\n"));
127  }
128 
129 
130 
131 
132  if (is_string($options['name'])) {
133  // FIXME: not sure if its needed but this was calling sanitize_domainname, which did not exist
134  $domain_name = sanitize_hostname($options['name']);
135  if (!is_string($domain_name)) {
136  printmsg("DEBUG => The domain name ({$options['name']}) is invalid!", 3);
137  $self['error'] = "ERROR => The domain name ({$options['name']}) is invalid!";
138  return(array(4, $self['error'] . "\n"));
139  }
140  }
141 
142 
143 // FIXME: MP for now this is removed. it is a chicken/egg issue on setting this name
144 // Also it cant use find_host as the name is not always primary dns name.
145 
146 // if ($primary) {
147 // // Determine the primary master is a valid host
148 // list($status, $rows, $ohost) = ona_find_host($primary);
149 //
150 // if (!$ohost['id']) {
151 // printmsg("DEBUG => The primary master host specified ({$primary}) does not exist!", 3);
152 // $self['error'] = "ERROR => The primary master host specified ({$primary}) does not exist!";
153 // return(array(2, $self['error'] . "\n"));
154 // }
155 //
156 // }
157 
158 
159  // Check permissions
160  if (!auth('advanced')) {
161  $self['error'] = "Permission denied!";
162  printmsg($self['error'], 0);
163  return(array(10, $self['error'] . "\n"));
164  }
165 
166 
167 
168  // Get the next ID
169  $first_id = $id = ona_get_next_id('domains');
170  if (!$id) {
171  $self['error'] = "ERROR => The ona_get_next_id('domains') call failed!";
172  printmsg($self['error'], 0);
173  return(array(6, $self['error'] . "\n"));
174  }
175  printmsg("DEBUG => domain_add(): New domain ID: {$id} name: {$domain_name}.{$parent_domain['fqdn']}", 3);
176 
177 
178  // come up with a serial_number
179  // Calculate a serial based on time
180  // concatinate year,month,day,percentage of day
181  // FIXME: MP this needs more work to be more accurate. maybe not use date.. pretty limiting at 10 characters as suggested here: http://www.zytrax.com/books/dns/ch8/soa.html
182  // for now I'm going with non zero padded(zp) month,zp day, zp hour, zp minute, zp second. The only issue I can see at this point with this is when it rolls to january..
183  // will that be too much of an increment for it to properly zone xfer? i.e. 1209230515 = 12/09 23:05:15 in time format
184 
185  // MP: FOR NOW SERIAL WONT EVER GET USED... LEFT IT IN HERE FOR AWHILE THOUGH
186  $serial_number = date('njHis');
187 
188 
189  // Add the record
190  list($status, $rows) =
192  $onadb,
193  'domains',
194  array(
195  'id' => $id,
196  'name' => $domain_name,
197  'primary_master' => $primary,
198  'admin_email' => $admin,
199  'refresh' => $refresh,
200  'retry' => $retry,
201  'expiry' => $expiry,
202  'minimum' => $minimum,
203  'default_ttl' => $ttl,
204  'parent_id' => $parent_domain['id'],
205  'serial' => $serial_number
206  )
207  );
208  if ($status or !$rows) {
209  $self['error'] = "ERROR => domain_add() SQL Query failed: " . $self['error'];
210  printmsg($self['error'],0);
211  return(array(7, $self['error'] . "\n"));
212  }
213 
214 
215  // Return the success notice
216  $self['error'] = "INFO => Domain ADDED: {$domain_name}";
217  printmsg($self['error'],0);
218  return(array(0, $self['error'] . "\n"));
219 }
220 
221 
222 
223 
224 
225 
226 
227 
228 
229 
230 
231 
233 // Function: domain_del (string $options='')
234 //
235 // $options = key=value pairs of options for this function.
236 // multiple sets of key=value pairs should be separated
237 // by an "&" symbol.
238 //
239 // Input Options:
240 // domain=NAME or ID
241 //
242 // Output:
243 // Deletes a domain from the IP database.
244 // Returns a two part list:
245 // 1. The exit status of the function. 0 on success, non-zero on
246 // error. All errors messages are stored in $self['error'].
247 // 2. A textual message for display on the console or web interface.
248 //
249 // Example: list($status, $result) = domain_del('domain=test');
251 function domain_del($options="") {
252  global $conf, $self, $onadb;
253  printmsg("DEBUG => domain_del({$options}) called", 3);
254 
255  // Version - UPDATE on every edit!
256  $version = '1.02';
257 
258  // Parse incoming options string to an array
259  $options = parse_options($options);
260 
261  // Sanitize options[commit] (default is yes)
262  $options['commit'] = sanitize_YN($options['commit'], 'N');
263 
264  // Return the usage summary if we need to
265  if ($options['help'] or !$options['domain'] ) {
266  // NOTE: Help message lines should not exceed 80 characters for proper display on a console
267  $self['error'] = 'ERROR => Insufficient parameters';
268  return(array(1,
269 <<<EOM
270 
272 Deletes a DNS domain from the database
273 
274  Synopsis: domain_del [KEY=VALUE] ...
275 
276  Required:
277  domain=NAME or ID name or ID of the domain to delete
278 
279  Optional:
280  commit=[Y|N] commit db transaction (no)
281 \n
282 EOM
283 
284  ));
285  }
286 
287 
288  // Check if it is an ID or NAME
289  if (is_numeric($options['domain'])) {
290  $domainsearch = array('id' => $options['domain']);
291  } else {
292  $domainsearch = array('name' => $options['domain']);
293  }
294 
295  // Test that the domain actually exists.
296  list($status, $tmp_rows, $entry) = ona_get_domain_record($domainsearch);
297  if (!$entry['id']) {
298  printmsg("DEBUG => Unable to find a domain record using ID {$options['domain']}!",3);
299  $self['error'] = "ERROR => Unable to find a domain record using ID {$options['domain']}!";
300  return(array(4, $self['error']. "\n"));
301  }
302 
303  // Debugging
304  list($status, $tmp_rows, $tmp_parent) = ona_get_domain_record(array('id'=>$entry['parent_id']));
305  printmsg("DEBUG => Domain selected: {$entry['name']}.{$tmp_parent['name']}", 3);
306 
307 
308  // Display an error if DNS records are using this domain
309  list($status, $rows, $dns) = db_get_records($onadb, 'dns', array('domain_id' => $entry['id']));
310  if ($rows) {
311  printmsg("DEBUG => Domain ({$entry['name']}) can't be deleted, it is in use by {$rows} DNS entries!",3);
312  $self['error'] = "ERROR => Domain ({$entry['name']}) can't be deleted, it is in use by {$rows} DNS entries!";
313  return(array(5, $self['error'] . "\n"));
314  }
315 
316  // Display an error if it is a parent of other domains
317  list($status, $rows, $parent) = db_get_records($onadb, 'domains', array('parent_id' => $entry['id']));
318  if ($rows) {
319  printmsg("DEBUG => Domain ({$entry['name']}) can't be deleted, it is the parent of {$rows} other domain(s)!",3);
320  $self['error'] = "ERROR => Domain ({$entry['name']}) can't be deleted, it is the parent of {$rows} other domain(s)!";
321  return(array(7, $self['error'] . "\n"));
322  }
323 
324 
325 
326 
327 
328 
329 
330  // If "commit" is yes, delete the record
331  if ($options['commit'] == 'Y') {
332 
333  // Check permissions
334  if (!auth('advanced')) {
335  $self['error'] = "Permission denied!";
336  printmsg($self['error'], 0);
337  return(array(10, $self['error'] . "\n"));
338  }
339 
340  // Delete association with any servers
341  list($status, $rows) = db_delete_records($onadb, 'dns_server_domains', array('domain_id' => $entry['id']));
342  if ($status) {
343  $self['error'] = "ERROR => domain_del() SQL Query (dns_server_domains) failed: {$self['error']}";
344  printmsg($self['error'],0);
345  return(array(8, $self['error'] . "\n"));
346  }
347 
348  // Delete actual domain
349  list($status, $rows) = db_delete_records($onadb, 'domains', array('id' => $entry['id']));
350  if ($status) {
351  $self['error'] = "ERROR => domain_del() SQL Query failed: {$self['error']}";
352  printmsg($self['error'],0);
353  return(array(9, $self['error'] . "\n"));
354  }
355 
356 
357 
358 
359  // Return the success notice
360  $self['error'] = "INFO => Domain DELETED: {$entry['name']}";
361  printmsg($self['error'],0);
362  return(array(0, $self['error'] . "\n"));
363  }
364 
365  // Otherwise display the record that would have been deleted
366  $text = <<<EOL
367 Record(s) NOT DELETED (see "commit" option)
368 Displaying record(s) that would have been deleted:
369 
370 NAME: {$entry['name']}
371 
372 EOL;
373 
374  return(array(6, $text));
375 
376 }
377 
378 
379 
380 
381 
382 
383 
384 
385 
387 // Function: domain_modify (string $options='')
388 //
389 // $options = key=value pairs of options for this function.
390 // multiple sets of key=value pairs should be separated
391 // by an "&" symbol.
392 //
393 // Input Options:
394 // Where:
395 // domain=STRING or ID full name of domain (i.e. name.something.com)
396 
397 // Optional:
398 // set_name=STRING new domain name
399 // set_admin=STRING Default ({$conf['dns_admin_email']})
400 // set_ptr=[Y|N] Default ({$conf['dns_ptr']})
401 // set_primary=STRING Default ({$conf['dns_primary_master']})
402 // set_refresh=NUMBER Default ({$conf['dns_refresh']})
403 // set_retry=NUMBER Default ({$conf['dns_retry']})
404 // set_expiry=NUMBER Default ({$conf['dns_expir']})
405 // set_minimum=NUMBER Default ({$conf['dns_minimum']})
406 // set_parent=DOMAIN_NAME Default ({$conf['dns_parent']})
407 //
408 // Output:
409 // Updates an domain record in the IP database.
410 // Returns a two part list:
411 // 1. The exit status of the function. 0 on success, non-zero on
412 // error. All errors messages are stored in $self['error'].
413 // 2. A textual message for display on the console or web interface.
414 //
415 // Example: list($status, $result) = domain_modify('alias=test&host=q1234.something.com');
417 function domain_modify($options="") {
418  global $conf, $self, $onadb;
419  printmsg("DEBUG => domain_modify({$options}) called", 3);
420 
421  // Version - UPDATE on every edit!
422  $version = '1.05';
423 
424  // Parse incoming options string to an array
425  $options = parse_options($options);
426 
427  // Return the usage summary if we need to
428  if ($options['help'] or !(
429  ($options['domain'])
430  and
431  ($options['set_admin'] or
432  $options['set_name'] or
433  $options['set_primary_master'] or
434  $options['set_refresh'] or
435  $options['set_retry'] or
436  $options['set_expiry'] or
437  $options['set_minimum'] or
438  $options['set_ttl'] or
439  $options['set_parent'])
440  )
441  )
442  {
443  // NOTE: Help message lines should not exceed 80 characters for proper display on a console
444  $self['error'] = 'ERROR => Insufficient parameters';
445  return(array(1,
446 <<<EOM
447 
449 Modifies a DNS domain in the database
450 
451  Synopsis: domain_modify [KEY=VALUE] ...
452 
453  Where:
454  domain=STRING or ID full name of domain (i.e. name.something.com)
455 
456  Optional:
457  set_name=STRING new domain name
458  set_admin=STRING Default ({$conf['dns_admin_email']})
459  set_primary_master=STRING Default ({$conf['dns_primary_master']})
460  set_refresh=NUMBER Default ({$conf['dns_refresh']})
461  set_retry=NUMBER Default ({$conf['dns_retry']})
462  set_expiry=NUMBER Default ({$conf['dns_expiry']})
463  set_minimum=NUMBER Default ({$conf['dns_minimum']})
464  set_ttl=NUMBER Default ({$conf['dns_default_ttl']})
465  set_parent=DOMAIN_NAME Default ({$conf['dns_parent']})
466 
467 
468 EOM
469  ));
470  }
471 
472  $options['domain'] = trim($options['domain']);
473  $options['set_name'] = trim($options['set_name']);
474  $options['set_parent'] = trim($options['set_parent']);
475  $options['set_admin'] = trim($options['set_admin']);
476 
477  $domainsearch = array();
478  // setup a domain search based on name or id
479  if (is_numeric($options['domain'])) {
480  $domainsearch['id'] = $options['domain'];
481  } else {
482  $domainsearch['name'] = $options['domain'];
483  }
484 
485  // Determine the entry itself exists
486  list($status, $rows, $entry) = ona_get_domain_record($domainsearch);
487 
488  // Test to see that we were able to find the specified record
489  if (!$entry['id']) {
490  printmsg("DEBUG => Unable to find a domain record using ID {$options['domain']}!",3);
491  $self['error'] = "ERROR => Unable to find the domain record using {$options['domain']}!";
492  return(array(4, $self['error']. "\n"));
493  }
494 
495  printmsg("DEBUG => domain_modify(): Found entry, {$entry['name']}", 3);
496 
497 
498  // This variable will contain the updated info we'll insert into the DB
499  $SET = array();
500 
501 
502 
503  if (array_key_exists('set_parent',$options) and $options['set_parent']) {
504  $parentsearch = array();
505  // setup a domain search based on name or id
506  if (is_numeric($options['set_parent'])) {
507  $parentsearch['id'] = $options['set_parent'];
508  } else {
509  $parentsearch['name'] = $options['set_parent'];
510  }
511 
512  // Determine the host is valid
513  list($status, $rows, $domain) = ona_get_domain_record($parentsearch);
514 
515  if (!$domain['id']) {
516  printmsg("DEBUG => The parent domain specified ({$options['set_parent']}) does not exist!",3);
517  $self['error'] = "ERROR => The parent domain specified ({$options['set_parent']}) does not exist!";
518  return(array(2, $self['error'] . "\n"));
519  }
520 
521  if ($entry['parent_id'] != $domain['id']) $SET['parent_id'] = $domain['id'];
522  } else {
523  if ($entry['parent_id'] != 0) $SET['parent_id'] = 0;
524  }
525 
526  // FIXME: currently renaming zones may not work when using
527  // parent zones. https://github.com/opennetadmin/ona/issues/36
528  if (is_string($options['set_name'])) {
529  // trim leading and trailing whitespace from 'value'
530  if ($entry['name'] != trim($options['set_name'])) $SET['name'] = trim($options['set_name']);
531 
532  // Determine the entry itself exists
533  list($status, $rows, $domain) = ona_get_domain_record(array('name' => $options['set_name']));
534 
535  // Test to see that the new entry isnt already used
536  if ($domain['id'] and $domain['id'] != $entry['id']) {
537  printmsg("DEBUG => The domain specified ({$options['set_name']}) already exists!",3);
538  $self['error'] = "ERROR => The domain specified ({$options['set_name']}) already exists!";
539  return(array(6, $self['error']. "\n"));
540  }
541 
542  }
543 
544  // define the remaining entries
545  if ($options['set_primary_master'] and $entry['primary_master'] != $options['set_primary_master']) $SET['primary_master'] = trim($options['set_primary_master']);
546  if ($options['set_admin'] and $entry['admin_email'] != $options['set_admin']) $SET['admin_email'] = $options['set_admin'];
547  if ($options['set_refresh'] and $entry['refresh'] != $options['set_refresh']) $SET['refresh'] = $options['set_refresh'];
548  if ($options['set_retry'] and $entry['retry'] != $options['set_retry']) $SET['retry'] = $options['set_retry'];
549  if ($options['set_expiry'] and $entry['expiry'] != $options['set_expiry']) $SET['expiry'] = $options['set_expiry'];
550  if ($options['set_minimum'] and $entry['minimum'] != $options['set_minimum']) $SET['minimum'] = $options['set_minimum'];
551  if ($options['set_ttl'] and $entry['default_ttl'] != $options['set_ttl']) $SET['default_ttl'] = $options['set_ttl'];
552 
553 
554 // FIXME: MP for now this is removed. it is a chicken/egg issue on setting this name
555 // Also it cant use find_host as the name is not always primary.
556 
557 /* if ($SET['primary_master']) {
558  // Determine if the primary master is a valid host
559  list($status, $rows, $host) = ona_find_host($SET['primary_master']);
560 
561  if (!$host['id']) {
562  printmsg("DEBUG => The primary master host specified ({$SET['primary_master']}) does not exist!",3);
563  $self['error'] = "ERROR => The primary master host specified ({$SET['primary_master']}) does not exist!";
564  return(array(2, $self['error'] . "\n"));
565  }
566 
567  }
568 */
569 
570  // come up with a serial_number
571  // Calculate a serial based on time
572  // concatinate year,month,day,percentage of day
573  // FIXME: MP this needs more work to be more accurate. maybe not use date.. pretty limiting at 10 characters as suggested here: http://www.zytrax.com/books/dns/ch8/soa.html
574  // for now I'm going with non zero padded(zp) month,zp day, zp hour, zp minute, zp second. The only issue I can see at this point with this is when it rolls to january..
575  // will that be too much of an increment for it to properly zone xfer? i.e. 1209230515 = 12/09 23:05:15 in time format
576 
577  // MP: FOR NOW SERIAL WONT EVER GET USED... LEFT IT IN HERE FOR AWHILE THOUGH
578  //$SET['serial'] = date('njHis');
579 
580  // Serial numbers are now built based on the timeformat
581 
582 
583 
584 
585 
586  // Check permissions
587  if (!auth('advanced')) {
588  $self['error'] = "Permission denied!";
589  printmsg($self['error'], 0);
590  return(array(10, $self['error'] . "\n"));
591  }
592 
593  // Get the domain record before updating (logging)
594  list($status, $rows, $original_domain) = ona_get_domain_record(array('id'=>$entry['id']));
595 
596  // Update the record
597  if (count($SET) > 0) {
598  list($status, $rows) = db_update_record($onadb, 'domains', array('id' => $entry['id']), $SET);
599  if ($status or !$rows) {
600  $self['error'] = "ERROR => domain_modify() SQL Query failed: {$self['error']}";
601  printmsg($self['error'],0);
602  return(array(6, $self['error'] . "\n"));
603  }
604 }
605  // Get the entry again to display details
606  list($status, $rows, $new_domain) = ona_get_domain_record(array('id'=>$entry['id']));
607 
608 
609  // Return the success notice
610  $self['error'] = "INFO => Domain UPDATED:{$entry['id']}: {$new_domain['name']}";
611 
612  $log_msg = "INFO => Domain UPDATED:{$entry['id']}: ";
613  $more="";
614  foreach(array_keys($original_domain) as $key) {
615  if($original_domain[$key] != $new_domain[$key]) {
616  $log_msg .= $more . $key . "[" .$original_domain[$key] . "=>" . $new_domain[$key] . "]";
617  $more= ";";
618  }
619  }
620 
621 
622  // TRIGGER:Now that we have updated the domain, lets mark the domain on all the servers for a rebuild to pick up any new SOA info.
623  list($status, $rows) = db_update_record($onadb, 'dns_server_domains', array('domain_id' => $entry['id']), array('rebuild_flag' => 1));
624  if ($status) {
625  $self['error'] = "ERROR => domain_modify() Unable to update rebuild flags for domain. SQL Query failed: {$self['error']}";
626  printmsg($self['error'],0);
627  return(array(7, $self['error'] . "\n"));
628  }
629 
630  // only print to logfile if a change has been made to the record
631  if($more != '') {
632  printmsg($self['error'], 0);
633  printmsg($log_msg, 0);
634  }
635 
636  return(array(0, $self['error'] . "\n"));
637 }
638 
639 
640 
641 
642 
643 
644 
645 
647 // Function: domain_display (string $options='')
648 //
649 // Input Options:
650 // $options = key=value pairs of options for this function.
651 // multiple sets of key=value pairs should be separated
652 // by an "&" symbol.
653 //
654 // Output:
655 // Returns a two part list:
656 // 1. The exit status of the function. 0 on success, non-zero on
657 // error. All errors messages are stored in $self['error'].
658 // 2. A textual message for display on the console or web interface.
659 //
660 // Example: list($status, $result) = domain_display('domain=test');
662 function domain_display($options="") {
663 
664  // The important globals
665  global $conf, $self, $oracle;
666 
667  // Version - UPDATE on every edit!
668  $version = '1.01';
669 
670  printmsg("DEBUG => domain_display({$options}) called", 3);
671 
672  // Parse incoming options string to an array
673  $options = parse_options($options);
674 
675  // Return the usage summary if we need to
676  if ($options['help'] or (!$options['domain']) ) {
677  // NOTE: Help message lines should not exceed 80 characters for proper display on a console
678  $self['error'] = 'ERROR => Insufficient parameters';
679  return(array(1,
680 <<<EOM
681 
683 Displays an domain record from the database
684 
685  Synopsis: domain_display [KEY=VALUE] ...
686 
687  Required:
688  domain=NAME or ID domain name or ID of the domain to display
689 
690 
691 EOM
692 
693  ));
694  }
695 
696 
697 
698  $domainsearch = array();
699  // setup a domain search based on name or id
700  if (is_numeric($options['domain'])) {
701  $domainsearch['id'] = $options['domain'];
702  } else {
703  $domainsearch['name'] = $options['domain'];
704  }
705 
706  // Determine the entry itself exists
707  list($status, $rows, $domain) = ona_get_domain_record($domainsearch);
708 
709  // Test to see that we were able to find the specified record
710  if (!$domain['id']) {
711  printmsg("DEBUG => Unable to find a domain record using ID {$options['domain']}!",3);
712  $self['error'] = "ERROR => Unable to find the domain record using {$options['domain']}!";
713  return(array(4, $self['error']. "\n"));
714  }
715 
716 
717 
718 
719  // Debugging
720  printmsg("DEBUG => domain_display(): Found {$domain['name']}", 3);
721 
722 
723 
724 
725 
726 
727 
728  // Build text to return
729  $text = <<<EOL
730 DOMAIN RECORD ({$domain['name']})
731 
732  PARENT: {$domain['parent_id']}
733  PRIMARY: {$domain['primary_master']}
734  ADMIN: {$domain['admin_email']}
735  REFRESH: {$domain['refresh']}
736  RETRY: {$domain['retry']}
737  EXPIRY: {$domain['expiry']}
738  MINIMUM: {$domain['minimum']}
739 
740 EOL;
741 
742 
743  // Return the success notice
744  return(array(0, $text));
745 
746 
747 }
748 
749 
750 
751 
752 
753 
754 
755 
756 
757 
758 // DON'T put whitespace at the beginning or end of this file!!!
759 ?>
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
ona_get_next_id
ona_get_next_id($tablename)
Definition: functions_db.inc.php:1369
ona_find_domain
ona_find_domain($fqdn="", $returndefault=0)
Definition: functions_db.inc.php:1609
$record
$record['display_name']
Definition: app_advanced_search.inc.php:12
db_get_records
db_get_records($dbh=0, $table="", $where="", $order="", $rows=-1, $offset=-1)
Definition: functions_db.inc.php:891
$status
$status
Definition: install.php:12
$onadb
global $onadb
Definition: 2-to-3.php:15
db_delete_records
db_delete_records($dbh=0, $table="", $where="")
Definition: functions_db.inc.php:582
domain_display
domain_display($options="")
Definition: domain.inc.php:662
printmsg
if(6<=$conf['debug']) printmsg($msg="", $debugLevel=0)
Definition: functions_general.inc.php:48
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
sanitize_hostname
sanitize_hostname($string="")
Definition: functions_general.inc.php:900
$conf
global $conf
Definition: 2-to-3.php:15
domain_modify
domain_modify($options="")
Definition: domain.inc.php:417
ona_get_domain_record
ona_get_domain_record($array='', $order='')
Definition: functions_db.inc.php:1134
domain_add
domain_add($options="")
Definition: domain.inc.php:40
$text
$text
Definition: install.php:11
$self
global $self
Definition: 2-to-3.php:15
auth
auth($resource, $msg_level=1)
Definition: functions_general.inc.php:1330
parse_options
parse_options($options="")
Definition: functions_general.inc.php:1579
domain_del
domain_del($options="")
Definition: domain.inc.php:251
$version
$version
Definition: main.inc.php:22