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)  

functions_db.inc.php
Go to the documentation of this file.
1 <?php
2 /* WARNING: Don't put whitespace at the beginning or end of include files! */
3 
4 
5 
6 /* ADODB Global Variables (shouldn't need changed) */
7 
8 // You can control the associative fetch case for certain drivers which
9 // behave differently. For the sybase, oci8po, mssql, odbc and ibase
10 // drivers and all drivers derived from them, ADODB_ASSOC_CASE will by
11 // default generate recordsets where the field name keys are lower-cased.
12 // Use the constant ADODB_ASSOC_CASE to change the case of the keys.
13 // There are 3 possible values:
14 // 0 = assoc lowercase field names. $rs->fields['orderid']
15 // 1 = assoc uppercase field names. $rs->fields['ORDERID']
16 // 2 = use native-case field names. $rs->fields['OrderID'] -- this is the default since ADOdb 2.90
17 //
18 // To use it, declare it before you incldue adodb.inc.php.
19 // define('ADODB_ASSOC_CASE', 0);
20 
21 
22 // Include the database abstraction library, ADODB.
23 // http://adodb.sourceforge.net/
24 require_once($conf['inc_adodb']);
25 
26 
27 // If the database driver API does not support counting the number of
28 // records returned in a SELECT statement, the function RecordCount()
29 // is emulated when the global variable $ADODB_COUNTRECS is set to true,
30 // which is the default. We emulate this by buffering the records, which
31 // can take up large amounts of memory for big recordsets. Set this variable
32 // to false for the best performance. This variable is checked every time
33 // a query is executed, so you can selectively choose which recordsets to count.
35 
36 // If you are using recordset caching, this is the directory to save your
37 // recordsets in. Define this before you call any caching functions such
38 // as CacheExecute( ). We recommend setting register_globals=off in php.ini
39 // if you use this feature for security reasons.
40 //
41 // If you are using Unix and apache, you might need to set your cache directory
42 // permissions to something similar to the following:
43 // chown -R apache /path/to/adodb/cache
44 // chgrp -R apache /path/to/adodb/cache
46 
47 // Determines whether to right trim CHAR fields (and also VARCHAR for ibase/firebird).
48 // Set to true to trim. Default is false. Currently works for oci8po, ibase and
49 // firebird drivers. Added in ADOdb 4.01.
51 
52 // Determines the language used in MetaErrorMsg(). The default is 'en', for English.
53 // To find out what languages are supported, see the files in adodb/lang/adodb-$lang.inc.php,
54 // where $lang is the supported langauge.
55 $ADODB_LANG = 'en';
56 
57 // This is a global variable that determines how arrays are retrieved by
58 // recordsets. The recordset saves this value on creation (eg. in Execute( )
59 // or SelectLimit( )), and any subsequent changes to $ADODB_FETCH_MODE have
60 // no affect on existing recordsets, only on recordsets created in the future.
61 // The following constants are defined:
62 // define('ADODB_FETCH_DEFAULT',0);
63 // define('ADODB_FETCH_NUM',1);
64 // define('ADODB_FETCH_ASSOC',2);
65 // define('ADODB_FETCH_BOTH',3);
66 // If no fetch mode is predefined, the fetch mode defaults to ADODB_FETCH_DEFAULT.
67 // The behaviour of this default mode varies from driver to driver, so do not rely
68 // on ADODB_FETCH_DEFAULT. For portability, we recommend sticking to ADODB_FETCH_NUM
69 // or ADODB_FETCH_ASSOC. Many drivers do not support ADODB_FETCH_BOTH.
70 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
71 
72 
73 
74 
75 
76 
78 // Function: db_pconnect($context_type, $context_name)
79 //
80 // Establishes a persistent connection to the database as specified
81 // by $context_name. Uses the global DB context
82 // definitions stored in $ona_contexts().
83 // This function will try up to 5 times to get the connection working.
84 // This was a necessary function, because quite regularly we were
85 // getting Oracle errors when ADODB/PHP thought it was connected to
86 // the database when it really wasn't. Good ole Oracle ;-)
87 //
88 // Returns an ADODB database handle object
90 function db_pconnect($type, $context_name) {
91  global $conf, $base, $self, $ona_contexts;
92  global $db_context;
93 
94 
95  // Get info from old $db_context[] array if ona_contexts does not exist
96  // this is transitional, hopefully I can remove this part soon.
97  if (!is_array($ona_contexts) and is_array($db_context)) {
98  $type='mysqlt';
99  $ona_contexts[$context_name]['databases']['0']['db_type'] = $db_context[$type] [$context_name] ['primary'] ['db_type'];
100  $ona_contexts[$context_name]['databases']['0']['db_host'] = $db_context[$type] [$context_name] ['primary'] ['db_host'];
101  $ona_contexts[$context_name]['databases']['0']['db_login'] = $db_context[$type] [$context_name] ['primary'] ['db_login'];
102  $ona_contexts[$context_name]['databases']['0']['db_passwd'] = $db_context[$type] [$context_name] ['primary'] ['db_passwd'];
103  $ona_contexts[$context_name]['databases']['0']['db_database'] = $db_context[$type] [$context_name] ['primary'] ['db_database'];
104  $ona_contexts[$context_name]['databases']['0']['db_debug'] = $db_context[$type] [$context_name] ['primary'] ['db_debug'];
105  $ona_contexts[$context_name]['databases']['1']['db_type'] = $db_context[$type] [$context_name] ['secondary'] ['db_type'];
106  $ona_contexts[$context_name]['databases']['1']['db_host'] = $db_context[$type] [$context_name] ['secondary'] ['db_host'];
107  $ona_contexts[$context_name]['databases']['1']['db_login'] = $db_context[$type] [$context_name] ['secondary'] ['db_login'];
108  $ona_contexts[$context_name]['databases']['1']['db_passwd'] = $db_context[$type] [$context_name] ['secondary'] ['db_passwd'];
109  $ona_contexts[$context_name]['databases']['1']['db_database'] = $db_context[$type] [$context_name] ['secondary'] ['db_database'];
110  $ona_contexts[$context_name]['databases']['1']['db_debug'] = $db_context[$type] [$context_name] ['secondary'] ['db_debug'];
111  $ona_contexts[$context_name]['description'] = 'Default data context';
112  $ona_contexts[$context_name]['context_color'] = '#D3DBFF';
113  }
114 
115  // check if the context name passed in is in our array or not
116  if (!isset($ona_contexts[$context_name])) {
117  setcookie("ona_context_name", $conf['default_context']);
118  printmsg("ERROR => Unable to find context name '{$context_name}' in the ona_contexts configuration. Reverting back to '{$conf['default_context']}' context.",0);
119  echo "ERROR => Unable to find context name '{$context_name}' in the ona_contexts configuration. Please check {$base}/local/config/database_settings.inc.php is configured properly. Reverting back to '{$conf['default_context']}' context.";
120  return $object;
121  }
122 
123 
124  // Populate basic context info into the self storage array
125  $self['context_name'] = $context_name;
126  $self['context_desc'] = $ona_contexts[$context_name]['description'];
127  $self['context_color'] = $ona_contexts[$context_name]['context_color'];
128 
129  // loop through each context in the array and try and connect to the databases
130  // we will use the first DB we connect to for the specified context
131  // ONA will NOT connect to multiple databases at once.
132  foreach ((array)$ona_contexts[$context_name]['databases'] as $db) {
133 
134  $self['db_type'] = $db['db_type'];
135  $self['db_host'] = $db['db_host'];
136  $self['db_login'] = $db['db_login'];
137  $self['db_database'] = $db['db_database'];
138  $self['db_debug'] = $db['db_debug'];
139 
140  // Create a new ADODB connection object
141  $object = NewADOConnection($self['db_type']);
142  $object->debug = $self['db_debug'];
143  // MP: this does not seem to be a consistant setting for all adodb drivers
144  // leaving it set for those that can use it.
145  $object->charSet = $conf['charset'];
146 
147  // Try connecting to the database server
148  $connected = 0;
149  for ($a = 1; $a <= 5 and $connected == 0; $a++) {
150  $ok1 = $object->PConnect($self['db_host'], $self['db_login'], $db['db_passwd'], $self['db_database']);
151  $ok2 = $object->IsConnected();
152  $ok3 = $object->ErrorMsg();
153 
154  // If the connection didn't work, bail.
155  if (!$ok1 or !$ok2 or $ok3)
156  printmsg("ERROR => {$self['db_type']} DB connection failed: " . $object->ErrorMsg(), 0);
157  // Otherwise return the object.
158  else {
159  // MP: not sure how this behaves on other databases.. should work for mysql and postgres
160  if ($conf['set_db_charset'])
161  $object->Execute("SET names '{$conf['charset']}'");
162  return $object;
163  }
164  }
165  }
166 
167  // If it still isn't connected, return an error.
168  if ($connected == 0)
169  printmsg("ERROR => {$self['db_type']} DB connection failed after 5 tries! Maybe server is down?", 0);
170 
171  return $object;
172 }
173 
174 
175 
176 
177 
178 /* MP: Brandons functions, not currently used here.
179 
180 
181 
183 // Function: get_content(string $name)
184 //
185 // Input:
186 // $name
187 // The name of the content to load and display from the 'content'
188 // mysql table.
189 //
190 // Output:
191 // Returns the text from the 'text' field of the specified content
192 // record identified by $name.
194 function get_content($name) {
195  global $onadb;
196 
197  // Debugging
198  printmsg("DEBUG => get_content($name) called", 3);
199 
200  // Get the content to be displayed on this page
201  list($status, $rows, $content) = db_get_record($onadb, 'content', array('name' => $name));
202 
203  // Build an edit link if they're an editor
204  $edit = "";
205  if (auth('editor')) {
206  $edit = <<<EOL
207 <br/>
208 [<span onClick="xajax_window_submit('fckeditor', 'name=>{$name}', 'editor');" style="color: #4B42FF; text-decoration: underline; cursor: pointer; font-size: smaller;">edit</span>]&nbsp;&nbsp;
209 EOL;
210  }
211 
212  // If there wasn't content, tell them.
213  if ($status or !$rows)
214  return("<br/><span style=\"color: red;\"><b>Content could not be loaded, please try back soon!</b></span><br/>\n" . $edit);
215  else
216  return($content['text'] . $edit);
217 }
218 
219 
220 
221 
222 
223 
224 
225 
226 
227 
228 
229 
231 // Function: save_users_acl_in_session()
232 //
233 // Loads a user's ACL into $_SESSION['auth']['acl']...
234 // Requires that $_SESSION['auth']['user_id'] is already set.
235 // This function does not make sure they have a valid username,
236 // call securePage() first.
237 //
238 // Returns 0 on success, 1 on failure.
239 //
241 function save_users_acl_in_session() {
242  global $onadb;
243 
244  // If we've already saved their acl in the session, don't do anything.
245  if ($_SESSION['auth']['acl']['_done_'] == 1) {
246  return(0);
247  }
248 
249  // Make sure we have a user_id in the session
250  if (!$_SESSION['auth']['user']['id']) {
251  return(1);
252  }
253 
254  // Select all the user's acl's and add them to $_SESSION['auth']['acl']
255  $i = 0;
256  do {
257  // Loop through each permission the user has
258  list($status, $rows, $acl) = db_get_record($onadb, 'acl', array('user_id' => $_SESSION['auth']['user']['id']));
259  if (!$rows) { break; }
260  $i++;
261 
262  // Get the permission's name, and save it in $_SESSION['auth']['acl']
263  list($status, $rows_perm, $perm) = db_get_record($onadb, 'permissions', array('id' => $acl['perm_id']));
264  if ($rows_perm) {
265  $_SESSION['auth']['acl'][$perm['name']] = 1;
266  }
267 
268  } while ($i < $rows);
269 
270  $_SESSION['auth']['acl']['_done_'] = 1;
271 
272 }
273 
274 
275 
276 
277 
278 
279 
280 
281 
282 
283 
284 
285 
287 // Function: acl_add($user_id, $perm_name)
288 //
289 // Returns 0 on success, 1 on failure.
290 // $self['error'] has error messages
291 //
293 function acl_add($user_id, $perm_name) {
294  global $onadb;
295 
296  // Find the perm_id for the requested perm_name
297  list($status, $rows, $perm) = db_get_record($onadb, 'permissions', array('name' => $perm_name));
298  if ($status or !$perm['id']) { $self['error'] = "acl_add() ERROR => Invalid permission requested"; return(1); }
299 
300  // See if they already have that permission
301  list($status, $rows, $acl) = db_get_record($onadb, 'acl', array('perm_id' => $perm['id'], 'user_id' => $_SESSION['auth']['user']['id']));
302  if ($status or $acl['id']) { $self['error'] = "acl_add() ERROR => User already has that permission"; return(1); }
303 
304  // Add the ACL entry
305  list($status, $rows) = db_insert_record($onadb, 'acl', array('perm_id' => $perm['id'], 'user_id' => $_SESSION['auth']['user']['id']));
306  if ($status or !$rows) { $self['error'] = "acl_add() ERROR => SQL insert failed"; return(1); }
307  $_SESSION['auth']['acl'][$perm_name] = $perm['id'];
308  return(0);
309 }
310 
311 
312 
313 
314 
315 */
316 
317 
318 
319 
320 
321 
322 
323 
324 
325 
326 
327 
328 
329 
330 
331 
332 
334 // db_XXXX_record() FUNTCIONS FOLLOW //
336 
337 
338 
339 
340 
342 // Function: db_insert_record($dbh, string $table, array $insert)
343 //
344 // Input:
345 // $dbh an adodb connection object connected to a database
346 // $table the table name to insert into.
347 // $insert an associative array of KEY = VALUE pair(s) to insert
348 // into table $table. KEY is the column name, and VALUE
349 // is the value to insert into that column. Values do not
350 // need to be quoted, they will be properly quoted before
351 // being used in the SQL query.
352 //
353 // Output:
354 // Returns a two part list:
355 // 1. The exit status of the function (0 on success, non-zero on error)
356 // When a non-zero exit status is returned a textual description
357 // of the error will be stored in the global variable $self['error']
358 // 2. The number of rows that were inserted (i.e. 1 on success, 0 on
359 // error). Again, if 0 rows were inserted an error message will
360 // be stored in $self['error']
361 //
362 // Example: list($status, $rows) = db_insert_record(
363 // $mysql,
364 // "hosts",
365 // array('ID' => '12354',
366 // 'NAME' => 'test',
367 // 'CREATE_PTR' => 1,
368 // )
369 // );
370 // Exit codes:
371 // 0 :: No error
372 // 1 :: Invalid or insufficient input
373 // 2 :: SQL insert failed
375 function db_insert_record($dbh=0, $table="", $insert="") {
376  global $self;
377  @$self['db_insert_record_count']++;
378 
379  // Debugging
380  printmsg("DEBUG => db_insert_record(\$dbh, $table, \$insert) called", 3);
381 
382  // Return an error if insufficient input was received
383  if ( (!$dbh) or (!$dbh->IsConnected()) or
384  (!$table) or
385  (!$insert) ) {
386  $self['error'] = "ERROR => db_insert_record() received invalid input";
387  printmsg($self['error'], 3);
388  return(array(1, 0));
389  }
390 
391  // Build the SQL query
392  $q = "INSERT INTO {$table} ( ";
393  $first = 1;
394  foreach (array_keys($insert) as $key) {
395  if (!$first) { $q .= ', '; } $first = 0;
396  $q .= $key;
397  }
398  $q .= " ) VALUES (";
399  $first = 1;
400  foreach (array_keys($insert) as $key) {
401  if (!$first) { $q .= ', '; } $first = 0;
402  $q .= $dbh->qstr($insert[$key]);
403  }
404  $q .= " )";
405 
406  // Run the SQL
407  printmsg("DEBUG => db_insert_record() Running query: $q", 4);
408  $ok = $dbh->Execute($q);
409  $error = $dbh->ErrorMsg();
410 
411  // Report any errors
412  if ($ok === false or $error) {
413  $self['error'] = 'ERROR => SQL INSERT failed: ' . $error . "\n";
414  return(array(2, 0));
415  }
416 
417  // Otherwise return success
418  printmsg("DEBUG => db_insert_record() Insert was successful", 4);
419  return(array(0, 1));
420 }
421 
422 
423 
424 
425 
426 
427 
428 
429 
430 
431 
432 
433 
434 
435 
437 // Function: db_update_record($dbh, string $table, array/string $where, array $insert)
438 //
439 // Input:
440 // $dbh an adodb connection object connected to a database
441 // $table the table name to query from.
442 // $where an associative array of KEY = VALUE pair(s) used to
443 // locate and update the record you want. If $where is
444 // a string, that string is used as the WHERE clause of
445 // the sql query instead of generating one from an array.
446 // If you do this MAKE sure special characters are quoted
447 // properly to avoid security issues or bugs.
448 // $insert an associative array of KEY = VALUE pair(s) to update
449 // in table $table. KEY is the column name, and VALUE is
450 // the value to insert into that column. Values do not
451 // need to be quoted, they will be properly quoted before
452 // being used in the SQL query.
453 //
454 // Output:
455 // Updates a *single* record in the specified database table.
456 // Returns a two part list:
457 // 1. The exit status of the function (0 on success, non-zero on error)
458 // When a non-zero exit status is returned a textual description
459 // of the error will be stored in the global variable $self['error']
460 // 2. The number of rows that were actually updated (i.e. will
461 // always be 1 or 0.) Note that even if 0 rows are updated
462 // the exit status will still be 0 unless the SQL query fails.
463 //
464 // Example: list($status, $rows) = db_update_record(
465 // 'hosts',
466 // array('ID' => '12354'),
467 // array('IP_ADDR' => '34252522533'),
468 // );
469 // Exit codes:
470 // 0 :: No error
471 // 1 :: Invalid or insufficient input
472 // 2 :: SQL query failed
474 function db_update_record($dbh=0, $table="", $where="", $insert="") {
475  global $self;
476  @$self['db_update_record_count']++;
477 
478  // Debugging
479  printmsg("DEBUG => db_update_record(\$dbh, $table, \$where, \$insert) called", 3);
480 
481  // Return an error if insufficient input was received
482  if ( (!$dbh) or (!$dbh->IsConnected()) or
483  (!$table) or (!$where) or (!$insert) ) {
484  $self['error'] = "ERROR => db_update_record() received invalid input";
485  printmsg($self['error'], 3);
486  return(array(1, 0));
487  }
488 
489  // Build our $set variable
490  $set = '';
491  $and = '';
492  foreach (array_keys($insert) as $key) {
493  $set .= "{$and}{$key} = " . $dbh->qstr($insert[$key]);
494  if (!$and) { $and = ", "; }
495  }
496 
497  // Build the WHERE clause if $where is an array
498  if (is_array($where)) {
499  $where_str = '';
500  $and = '';
501  foreach (array_keys($where) as $key) {
502  $where_str .= $and . $key . ' = ' . $dbh->qstr($where[$key]);
503  if (!$and) { $and = " AND "; }
504  }
505  }
506  // Otherwise we just use the string in $where
507  else {
508  $where_str = $where;
509  }
510 
511  // Build the SQL query
512  $q = "UPDATE {$table} SET {$set} WHERE {$where_str}";
513 
514  // Execute the query
515  printmsg("DEBUG => db_update_record() Running query: $q", 4);
516  $rs = $dbh->Execute($q);
517 
518  // See if the query worked or not
519  if ($rs === false) {
520  $self['error'] = 'ERROR => SQL query failed: ' . $dbh->ErrorMsg();
521  printmsg($self['error'], 3);
522  return(array(2, 0));
523  }
524 
525  // How many rows were affected?
526  $rows = $dbh->Affected_Rows();
527  if ($rows === false) { $rows = 0; $self['error'] = 'Update OK, no rows effected'; }
528  $rs->Close();
529 
530  // Return Success
531  printmsg("DEBUG => db_update_record() Query updated {$rows} rows", 4);
532  return(array(0, $rows));
533 }
534 
535 
536 
537 
538 
539 
540 
541 
542 
543 
544 
545 
546 
547 
548 
550 // Function: db_delete_records($dbh, string $table, array/string $where)
551 //
552 // Input:
553 // $dbh an adodb connection object connected to a database
554 // $table the table name to delete from.
555 // $where an associative array of KEY = VALUE pair(s) used to
556 // locate and delete the record(s) you want. If $where is
557 // a string, that string is used as the WHERE clause of
558 // the sql query instead of generating one from an array.
559 // If you do this MAKE sure special characters are quoted
560 // properly to avoid security issues or bugs.
561 //
562 // Output:
563 // Deletes records from the database.
564 // Returns a two part list:
565 // 1. The exit status of the function (0 on success, non-zero on error)
566 // When a non-zero exit status is returned a textual description
567 // of the error will be stored in the global variable $self['error']
568 // 2. The number of rows that were actually deleted . Note that even
569 // if 0 rows are updated the exit status will still be 0 unless the
570 // SQL query fails.
571 //
572 // Example: list($status, $rows) = db_delete_records(
573 // 'hosts',
574 // array('ID' => '12354'),
575 // );
576 //
577 // Exit codes:
578 // 0 :: No error
579 // 1 :: Invalid or insufficient input
580 // 2 :: SQL query failed
582 function db_delete_records($dbh=0, $table="", $where="") {
583  global $self;
584  @$self['db_delete_records_count']++;
585 
586  // Debugging
587  printmsg("DEBUG => db_delete_records(\$dbh, $table, \$where) called", 3);
588 
589  // Return an error if insufficient input was received
590  if ( empty($dbh) or (!$dbh->IsConnected()) or
591  empty($table) or empty($where) ) {
592  $self['error'] = "ERROR => db_delete_records() received invalid input";
593  printmsg($self['error'], 0);
594  return(array(1, 0));
595  }
596 
597  // Build the WHERE clause if $where is an array
598  if (is_array($where)) {
599  $where_str = '';
600  $and = '';
601  foreach (array_keys($where) as $key) {
602  $where_str .= $and . $key . ' = ' . $dbh->qstr($where[$key]);
603  if (!$and) { $and = " AND "; }
604  }
605  }
606  // Otherwise we just use the string in $where
607  else {
608  $where_str = $where;
609  }
610 
611  // Build the SQL query
612  // The LIMIT 1 is only valid in MySQL, so we've removed it. db_delete_record now deletes all the records that match
613  // $q = "DELETE FROM {$table} WHERE {$where_str} LIMIT 1";
614  $q = "DELETE FROM {$table} WHERE {$where_str}";
615 
616  // Execute the query
617  $rs = $dbh->Execute($q);
618 
619  // See if the query worked or not
620  if ($rs === false) {
621  $self['error'] = 'ERROR => SQL query failed: ' . $dbh->ErrorMsg();
622  printmsg($self['error'], 3);
623  return(array(2, 0, array()));
624  }
625 
626  // How many rows were affected?
627  $rows = $dbh->Affected_Rows();
628  if ($rows === false) { $rows = 0; }
629  $rs->Close();
630 
631  // Return Success
632  printmsg("DEBUG => db_delete_records() Query deleted {$rows} row(s)", 4);
633  return(array(0, $rows));
634 }
635 
636 
637 
638 
639 
640 
641 
642 
643 
644 
645 
646 
647 
648 
649 
650 
652 // Function: db_get_record($dbh,
653 // string $table,
654 // array/string $where,
655 // string $order)
656 //
657 // Input:
658 // $dbh an adodb connection object connected to a database
659 // $table the table name to query from.
660 // $where an associative array of KEY = VALUE pair(s) used to
661 // locate and return the record you want. If $where is
662 // a string, that string is used as the WHERE clause of
663 // the sql query instead of generating one from an array.
664 // If you do this MAKE sure special characters are quoted
665 // properly to avoid security issues or bugs.
666 // $order actual SQL to use in the ORDER BY clause.
667 //
668 // Output:
669 // Returns a three part list:
670 // 1. The exit status of the function (0 on success, non-zero on error)
671 // When a non-zero exit status is returned a textual description
672 // of the error will be stored in the global variable $self['error']
673 // 2. The number of rows (n) that match values in $where, or 0 on no matches.
674 // 3. An associative array of a record from the $table table
675 // where the values in $where match. When more than one record is
676 // returned from the DB, the first record is returned on the
677 // first call. Each subsequent call with the same table and
678 // parameters will cause the function to return the next record.
679 // When 'n' records are found, and the function is called 'n+1'
680 // times, it loops and the first record is returned again.
681 //
682 // Notes:
683 // If you want to "reset" the row offset for a particular query and
684 // make sure that your next query is NOT cached, set this global
685 // variable before calling db_get_record():
686 // $self['db_get_record']['reset_cache'] = 1;
687 // These are also globally configurable, but you won't need to set
688 // these after each call to db_get_record().
689 // $self['db_get_record']['min_rows_to_cache']
690 // $self['db_get_record']['secs_to_cache']
691 //
692 //
693 // Example: list($status, $rows, $record) = db_get_record(
694 // "hosts",
695 // array('id' => '12354'),
696 // "domain_id ASC"
697 // );
698 // Example: list($status, $rows, $record) = db_get_record(
699 // "hosts",
700 // "id = '12354'",
701 // "domain_id ASC"
702 // );
703 // Exit codes:
704 // 0 :: No error
705 // 1 :: Invalid or insufficient input
706 // 2 :: SQL query failed
708 function db_get_record($dbh=0, $table="", $where="", $order="") {
709  global $self;
710  @$self['db_get_record_count']++;
711 
712  // Debugging
713  printmsg("DEBUG => db_get_record(\$dbh, \$where, $table, $order) called", 3);
714 
715  // Return an error if insufficient input was received
716  if ( (!$dbh) or (!$dbh->IsConnected()) or
717  (!$table) or (!$where) ) {
718  $self['error'] = "ERROR => db_get_record() received invalid input";
719  printmsg($self['error'], 3);
720  return(array(1, 0, array()));
721  }
722 
723  // Build the WHERE clause if $where is an array
724  if (is_array($where)) {
725  $where_str = '';
726  $and = '';
727  foreach (array_keys($where) as $key) {
728  $where_str .= $and . $key . ' = ' . $dbh->qstr($where[$key]);
729  if (!$and) { $and = " AND "; }
730  }
731  }
732  // Otherwise we just use the string in $where
733  else {
734  $where_str = $where;
735  }
736 
737  // Build the SQL query
738  $q = 'SELECT * ' .
739  "FROM {$table} " .
740  "WHERE {$where_str} ";
741  if ($order) {
742  $q .= "ORDER BY {$order}";
743  }
744 
745 
746  // Caching - our Query Cache policy is this:
747  // 1) If this is a new query for $table, don't cache
748  // 2) If this isn't a new query for $table and the recordset
749  // has more than 20 records, then cache it and use the
750  // cache for subsequent calls with the same query.
751  $use_cache = 0;
752  if (@$self['cache']["db_get_{$table}_record"]['q'] != $q) {
753  // If it's a new query, or , reset row cache and don't use cache
754  $self['cache']["db_get_{$table}_record"]['q'] = $q;
755  $self['cache']["db_get_{$table}_record"]['row'] = 0;
756 
757  printmsg("DEBUG => db_get_record() Row offset reset for table: {$table}", 5);
758  }
759  // If reset_cache == 1 we don't use cache, and go to row 0
760  else if (isset($self['db_get_record']['reset_cache']) and ($self['db_get_record']['reset_cache'])) {
761  $self['db_get_record']['reset_cache'] = 0;
762  $self['cache']["db_get_{$table}_record"]['row'] = 0;
763  }
764  // It's the same query again, decide if we should enable adodb disk cache
765  else {
766  // Set a detault unless it's already set
767  if (!$self['db_get_record']['min_rows_to_cache']) {
768  $self['db_get_record']['min_rows_to_cache'] = 20;
769  }
770 
771  // If there are enough records (or were last time we ran this query), lets cache the query this time.
772  if ($self['cache']["db_get_{$table}_record"]['rows'] >= $self['db_get_record']['min_rows_to_cache']) {
773  $use_cache = 1;
774  }
775 
776  // Increment the row offset, so we know which row to return
777  $self['cache']["db_get_{$table}_record"]['row']++;
778  }
779 
780 
781  // Select the record from the DB, don't cache results
782  if ($use_cache == 0) {
783  printmsg("DEBUG => db_get_record() running query: {$q}", 5);
784  $rs = $dbh->Execute($q);
785  }
786  // Select the record from the DB, cache results
787  else {
788  // Set a detault unless it's already set
789  if (!$self['db_get_record']['secs_to_cache']) {
790  $self['db_get_record']['secs_to_cache'] = 60;
791  }
792 
793  printmsg("DEBUG => db_get_record() running (cached) query: {$q}", 5);
794  $rs = $dbh->CacheExecute($self['db_get_record']['secs_to_cache'], $q);
795  }
796 
797 
798  // See if the query worked or not
799  if ($rs === false) {
800  $self['error'] = 'ERROR => SQL query failed: ' . $dbh->ErrorMsg();
801  printmsg($self['error'], 3);
802  return(array(2, 0, array()));
803  }
804 
805 
806  // Save the number of rows for use later
807  $rows = $self['cache']["db_get_{$table}_record"]['rows'] = $rs->RecordCount();
808 
809 
810  // If there were no rows, return 0 rows
811  if (!$rows) {
812  // Query returned no results
813  printmsg("DEBUG => db_get_record() Query returned no results", 4);
814  return(array(0, 0, array()));
815  }
816 
817  // If there's more than one record
818  else if ( ($rows > 1) and ($self['cache']["db_get_{$table}_record"]['row']) ) {
819  // If we need to loop back to row 0, lets do that
820  if ($self['cache']["db_get_{$table}_record"]['row'] >= $rows) {
821  $self['cache']["db_get_{$table}_record"]['row'] = 0;
822  }
823  // If it's the same query as last time we need to "Move" to right row
824  else {
825  $rs->Move($self['cache']["db_get_{$table}_record"]['row']);
826  }
827  }
828 
829  // Return the row
830  printmsg("DEBUG => db_get_record() Returning record " . ($self['cache']["db_get_{$table}_record"]['row'] + 1) . " of " . $rows, 4);
831  $array = $rs->FetchRow();
832  $rs->Close();
833  return(array(0, $rows, $array));
834 }
835 
836 
837 
838 
839 
840 
841 
842 
843 
845 // Function: db_get_records($dbh,
846 // string $table,
847 // array/string $where,
848 // [string $order],
849 // [int $rows=-1],
850 // [int $offset=-1]
851 // )
852 //
853 // Input:
854 // $dbh an adodb connection object connected to a database
855 // $table the table name to query from.
856 // $where an associative array of KEY = VALUE pair(s) used to
857 // locate and return the record you want. If $where is
858 // a string, that string is used as the WHERE clause of
859 // the sql query instead of generating one from an array.
860 // If you do this MAKE sure special characters are quoted
861 // properly to avoid security issues or bugs.
862 // $order actual SQL to use in the ORDER BY clause.
863 // $rows the number of rows to return. -1 = all rows.
864 // NOTE: if $rows is 0, the function will do a SELECT COUNT(*)
865 // and return the proper number of total rows.
866 // $offset retrieve rows starting with $offset. $offset is 0 based.
867 //
868 // Output:
869 // Returns a three part list:
870 // 1. The exit status of the function (0 on success, non-zero on error)
871 // When a non-zero exit status is returned a textual description
872 // of the error will be stored in the global variable $self['error']
873 // 2. The number of rows (n) that match values in $where, or 0 on no matches.
874 // 3. An array of arrays. Each sub-array is an associative array of
875 // a record from the $table table where the values in $where match.
876 //
877 // Example: list($status, $rows, $records) = db_get_record(
878 // $onadb,
879 // 'hosts',
880 // array('id' => '12354'),
881 // 'domain_id ASC',
882 // '25',
883 // '50'
884 // );
885 //
886 // Exit codes:
887 // 0 :: No error
888 // 1 :: Invalid or insufficient input
889 // 2 :: SQL query failed
891 function db_get_records($dbh=0, $table="", $where="", $order="", $rows=-1, $offset=-1) {
892  global $self;
893  @$self['db_get_records_count']++;
894 
895  // Debugging
896  printmsg("DEBUG => db_get_records(\$dbh, \$where, $table, $order, $rows, $offset) called", 3);
897 
898  // Return an error if insufficient input was received
899  if ( (!$dbh) or (!$dbh->IsConnected()) or
900  (!$table) or (!$where) ) {
901  $self['error'] = "ERROR => db_get_records() received invalid input";
902  printmsg($self['error'], 3);
903  return(array(1, 0, array()));
904  }
905 
906  // Build the WHERE clause if $where is an array
907  if (is_array($where)) {
908  $where_str = '';
909  $and = '';
910  foreach (array_keys($where) as $key) {
911  $where_str .= $and . $key . ' = ' . $dbh->qstr($where[$key]);
912  if (!$and) { $and = " AND "; }
913  }
914  }
915  // Otherwise we just use the string in $where
916  else {
917  $where_str = $where;
918  }
919 
920  // Return the 0 records, but number of total rows the query would have returned
921  // if they requested 0 rows.
922  $select = 'SELECT * ';
923  if ($rows == 0) {
924  $select = 'SELECT COUNT(*) AS COUNT ';
925  $rows = -1;
926  $offset = -1;
927  $order = '';
928  }
929 
930  // Build the SQL query
931  $q = $select .
932  "FROM {$table} " .
933  "WHERE {$where_str} ";
934  if ($order) {
935  $q .= "ORDER BY {$order}";
936  }
937 
938 
939  // Select the records from the DB
940  printmsg("DEBUG => db_get_records() running query: {$q}", 5);
941  $rs = $dbh->SelectLimit($q, $rows, $offset);
942 
943 
944  // See if the query worked or not
945  if ($rs === false) {
946  $self['error'] = 'ERROR => SQL query failed: ' . $dbh->ErrorMsg();
947  printmsg($self['error'], 3);
948  return(array(2, 0, array()));
949  }
950 
951 
952  // Save the number of rows for use later
953  $rows = $rs->RecordCount();
954  if ($select == 'SELECT COUNT(*) AS COUNT ') {
955  $record = $rs->FetchRow();
956  $rows = $record['COUNT'];
957  }
958 
959  // If there were no rows, return 0 rows
960  if (!$rows) {
961  // Query returned no results
962  printmsg("DEBUG => db_get_records() Query returned no results", 4);
963  return(array(0, 0, array()));
964  }
965 
966  // Loop and save each row to $recordset
967  $recordset = array();
968  while (!$rs->EOF) {
969  $recordset[] = $rs->FetchRow();
970  }
971 
972  // Return the row
973  printmsg("DEBUG => db_get_records() Returning records", 4);
974  $rs->Close();
975  return(array(0, $rows, $recordset));
976 }
977 
978 
979 
980 
981 
982 
983 
984 
985 
986 
987 
988 
989 
990 
991 
992 
993 
994 
995 
996 
997 
998 
999 
1000 
1002 // OTHER ONA FUNTCIONS FOLLOW //
1004 
1005 
1006 
1007 
1008 
1009 
1010 
1011 
1013 // Function: ona_insert_record(string $table, array $insert)
1014 //
1015 // See documentation for db_insert_record() in functions_db.php
1017 function ona_insert_record($table="", $insert="") {
1018  global $onadb;
1019  return(db_insert_record($onadb, $table, $insert));
1020 }
1021 
1022 
1023 
1025 // Function: ona_update_record(string $table, array/string $where, array $insert)
1026 //
1027 // See documentation for db_update_record() in functions_db.php
1029 function ona_update_record($table="", $where="", $insert="") {
1030  global $onadb;
1031  return(db_update_record($onadb, $table, $where, $insert));
1032 }
1033 
1034 
1035 
1037 // Function: ona_delete_record(string $table, array/string $where)
1038 //
1039 // See documentation for db_delete_record() in functions_db.php
1041 function ona_delete_record($table="", $where="") {
1042  global $onadb;
1043  return(db_delete_record($onadb, $table, $where));
1044 }
1045 
1046 
1047 
1049 // Function: ona_get_record(array/string $where, string $table, string $order)
1050 //
1051 // See documentation for db_get_record() in functions_db.php
1053 function ona_get_record($where="", $table="", $order="") {
1054  global $onadb;
1055  return(db_get_record($onadb, $table, $where, $order));
1056 }
1057 
1058 
1059 
1060 
1061 
1062 
1063 
1064 
1065 
1066 
1067 
1069 //
1070 // THIS IS DOCUMENTATION FOR ALL OF THE FOLLOWING
1071 // ona_get_XXX_record FUNCTIONS
1072 //
1073 // Function: ona_get_XXXXX_record(array $where)
1074 //
1075 // Input:
1076 // $where is an associative array of KEY = VALUE pair(s) used to
1077 // locate and return the host record you want.
1078 // This puts you a little close to the actual DB, but it allows
1079 // a great amount of flexability.
1080 // Example input: ona_get_host_record(array('ID' => '12354'))
1081 //
1082 // Output:
1083 // Returns a three part list:
1084 // 1. Function exit status - 0 on success, non-zero on error.
1085 // When a non-zero exit status is returned a description of the
1086 // error will be stored in the global variable $self['error']
1087 // 2. The number of rows ('n') that match values in $where, or
1088 // 0 on no matches.
1089 // 3. An associative array of a record from the DB table where the
1090 // values in $where match. When more than one record is
1091 // returned from the DB, the first record is returned on the
1092 // first call. Each subsequent call with the same parameters
1093 // will cause the function to return the next record. When 'n'
1094 // records are found, and the function is called 'n+1' times,
1095 // it loops and the first record is returned again.
1096 //
1097 // Example: list($status, $rows, $record) = ona_get_host_record(array('ID' => '12354'));
1098 //
1100 
1101 // Returns some additional fields:
1102 // name => the base hostname
1103 // fqdn => the fqdn of the host (based on it's primary_dns_id)
1104 // domain_id => domain id for the associated primary_dns_id
1105 // domain_name => domain name for the associated primary_dns_id's domain
1106 function ona_get_host_record($array='', $order='') {
1107  list($status, $rows, $record) = ona_get_record($array, 'hosts', $order);
1108  list($status_dns, $rows_dns, $dns) = ona_get_dns_record(array('id' => $record['primary_dns_id']));
1109  $record['name'] = $dns['name'];
1110  $record['fqdn'] = $dns['fqdn'];
1111  $record['primary_interface_id'] = $dns['interface_id'];
1112  $record['dns_view_id'] = $dns['dns_view_id'];
1113  $record['domain_id'] = $dns['domain_id'];
1114  $record['domain_fqdn'] = $dns['domain_fqdn'];
1115  return(array($status + $status_dns, $rows, $record));
1116 }
1117 
1118 function ona_get_block_record($array='', $order='') {
1119  return(ona_get_record($array, 'blocks', $order));
1120 }
1121 
1122 function ona_get_location_record($array='', $order='') {
1123  return(ona_get_record($array, 'locations', $order));
1124 }
1125 
1126 function ona_get_interface_record($array='', $order='') {
1127  list($status, $rows, $record) = ona_get_record($array, 'interfaces', $order);
1128  if ($rows)
1129  $record['ip_addr_text'] = ip_mangle($record['ip_addr'], 'dotted');
1130  return(array($status, $rows, $record));
1131 }
1132 
1133 // Returns an additional "fqdn" field
1134 function ona_get_domain_record($array='', $order='') {
1135  list($status, $rows, $record) = ona_get_record($array, 'domains', $order);
1136  if ($rows)
1137  $record['fqdn'] = ona_build_domain_name($record['id']);
1138  return(array($status, $rows, $record));
1139 }
1140 
1141 // Returns an additional "fqdn" field for some dns records
1142 function ona_get_dns_record($array='', $order='') {
1143  list($status, $rows, $record) = ona_get_record($array, 'dns', $order);
1144 
1145  if ($record['type'] == 'A' or $record['type'] == 'TXT') {
1146  $record['fqdn'] = $record['name'].'.'.ona_build_domain_name($record['domain_id']);
1147  $record['domain_fqdn'] = ona_build_domain_name($record['domain_id']);
1148  }
1149  if ($record['type'] == 'CNAME') {
1150  $record['fqdn'] = $record['name'].'.'.ona_build_domain_name($record['domain_id']);
1151  $record['domain_fqdn'] = ona_build_domain_name($record['domain_id']);
1152  }
1153  return(array($status, $rows, $record));
1154 }
1155 
1156 function ona_get_dns_view_record($array='', $order='') {
1157  return(ona_get_record($array, 'dns_views', $order));
1158 }
1159 
1160 function ona_get_config_record($array='', $order='ctime DESC') {
1161  list($status, $rows, $record) = ona_get_record($array, 'configurations', $order);
1162 
1163  // Lets be nice and return a little associated info
1164  list($status_tmp, $rows_tmp, $record_tmp) = ona_get_config_type_record(array('id' => $record['configuration_type_id']));
1165  $status += $status_tmp;
1166  $record['config_type_name'] = $record_tmp['name'];
1167 
1168  return(array($status, $rows, $record));
1169 }
1170 
1171 function ona_get_config_type_record($array='', $order='') {
1172  return(ona_get_record($array, 'configuration_types', $order));
1173 }
1174 
1176  return(ona_get_record($array, 'dhcp_failover_groups'));
1177 }
1178 
1180  return(ona_get_record($array, 'custom_attribute_types'));
1181 }
1182 
1184  list($status, $rows, $record) = ona_get_record($array, 'custom_attributes');
1185 
1186  // Lets be nice and return a little associated info
1187  list($status_tmp, $rows_tmp, $record_tmp) = ona_get_custom_attribute_type_record(array('id' => $record['custom_attribute_type_id']));
1188  $status += $status_tmp;
1189  $record['name'] = $record_tmp['name'];
1190  $record['field_validation_rule'] = $record_tmp['field_validation_rule'];
1191  $record['failed_rule_text'] = $record_tmp['failed_rule_text'];
1192  $record['notes'] = $record_tmp['notes'];
1193 
1194  return(array($status, $rows, $record));
1195 }
1196 
1197 function ona_get_model_record($array) {
1198  list($status, $rows, $record) = ona_get_record($array, 'models');
1199 
1200  // Lets be nice and return a little associated info
1201  list($status_tmp, $rows_tmp, $record_tmp) = ona_get_manufacturer_record(
1202  array('id' => $record['manufacturer_id'])
1203  );
1204  $status += $status_tmp;
1205  $record['manufacturer_name'] = $record_tmp['name'];
1206 
1207  return(array($status, $rows, $record));
1208 }
1209 
1211  return(ona_get_record($array, 'manufacturers'));
1212 }
1213 
1214 function ona_get_device_type_record($array) {
1215  return(ona_get_record($array, 'device_types'));
1216 }
1217 
1218 function ona_get_device_record($array) {
1219  return(ona_get_record($array, 'devices'));
1220 }
1221 
1222 function ona_get_role_record($array) {
1223  return(ona_get_record($array, 'roles'));
1224 }
1225 
1226 function ona_get_subnet_record($array) {
1227  list($status, $rows, $record) = ona_get_record($array, 'subnets');
1228 
1229  // Lets be nice and return a little associated info
1230  list($status_tmp, $rows_tmp, $record_tmp) = ona_get_subnet_type_record(array('id' => $record['subnet_type_id']));
1231  $status += $status_tmp;
1232  $record['subnet_type_name'] = $record_tmp['name'];
1233 
1234  return(array($status, $rows, $record));
1235 }
1236 
1237 function ona_get_subnet_type_record($array) {
1238  return(ona_get_record($array, 'subnet_types'));
1239 }
1240 
1241 function ona_get_vlan_record($array) {
1242  list($status, $rows, $record) = ona_get_record($array, 'vlans');
1243 
1244  // Lets be nice and return a little associated info
1245  list($status_tmp, $rows_tmp, $record_tmp) = ona_get_vlan_campus_record(
1246  array('id' => $record['vlan_campus_id'])
1247  );
1248  $status += $status_tmp;
1249  $record['vlan_campus_name'] = $record_tmp['name'];
1250 
1251  return(array($status, $rows, $record));
1252 }
1253 
1254 function ona_get_vlan_campus_record($array) {
1255  return(ona_get_record($array, 'vlan_campuses'));
1256 }
1257 
1258 function ona_get_dhcp_option_record($array) {
1259  return(ona_get_record($array, 'dhcp_options'));
1260 }
1261 
1263  list($status, $rows, $record) = ona_get_record($array, 'dhcp_option_entries');
1264 
1265  // Lets be nice and return a little associated info
1266  list($status_tmp, $rows_tmp, $record_tmp) = ona_get_dhcp_option_record(array('id' => $record['dhcp_option_id']));
1267  $status += $status_tmp;
1268  $record['number'] = $record_tmp['number'];
1269  $record['name'] = $record_tmp['name'];
1270  $record['display_name'] = $record_tmp['display_name'];
1271  $record['type'] = $record_tmp['type'];
1272 
1273  return(array($status, $rows, $record));
1274 }
1275 
1276 function ona_get_dhcp_pool_record($array) {
1277  return(ona_get_record($array, 'dhcp_pools'));
1278 }
1279 
1281  return(ona_get_record($array, 'dhcp_server_subnets'));
1282 }
1283 
1285  return(ona_get_record($array, 'dns_server_domains'));
1286 }
1287 
1288 
1289 
1290 
1291 
1292 // FIXME (MP) currently not in use.. however it does provide lookup by ID or name which is not currently working.. probably should fix this function and call it find_config_type
1293 
1294 // ///////////////////////////////////////////////////////////////////////
1295 // // Function: ona_get_configtype_deref($id or $string)
1296 // //
1297 // // Translates a config type NAME to an ID, or vice versa.
1298 // // Returns 0 on error.
1299 // //
1300 // ///////////////////////////////////////////////////////////////////////
1301 // function ona_get_configtype_deref($search='') {
1302 // global $onadb;
1303 // global $self;
1304 //
1305 // // Debugging
1306 // printmsg("DEBUG => ona_get_configtype_deref($search) called", 3);
1307 //
1308 // // Return 0 if there was no input
1309 // if (!$search) { return(0); }
1310 //
1311 // // If $q is numeric
1312 // if (preg_match('/^\d+$/', $search)) {
1313 // // Select the type name
1314 // $q = 'SELECT *
1315 // FROM IP.CONFIG_TYPE
1316 // WHERE IP.CONFIG_TYPE.CONFIG_TYPE_ID=' . $onadb->qstr($search);
1317 // $rs = $onadb->Execute($q);
1318 // if ($rs === false) {
1319 // printmsg('ERROR => SQL query failed: ' . $onadb->ErrorMsg(), 3);
1320 // return(0);
1321 // }
1322 // if ($rs->RecordCount() >= 1) {
1323 // $row = $rs->FetchRow();
1324 // return($row['CONFIG_TYPE_NAME']);
1325 // }
1326 // }
1327 //
1328 // // Otherwise lookup ID by NAME
1329 // else {
1330 // // Select the type name
1331 // $q = 'SELECT *
1332 // FROM IP.CONFIG_TYPE
1333 // WHERE IP.CONFIG_TYPE.CONFIG_TYPE_NAME=' . $onadb->qstr($search);
1334 // $rs = $onadb->Execute($q);
1335 // if ($rs === false) {
1336 // printmsg('ERROR => SQL query failed: ' . $onadb->ErrorMsg(), 3);
1337 // return(0);
1338 // }
1339 // if ($rs->RecordCount() >= 1) {
1340 // $row = $rs->FetchRow();
1341 // return($row['CONFIG_TYPE_ID']);
1342 // }
1343 // }
1344 //
1345 // // Just in case
1346 // return(0);
1347 // }
1348 
1349 
1350 
1351 
1352 
1353 
1354 
1355 
1356 
1357 
1359 // Function: ona_get_next_id($tablename)
1360 //
1361 // Returns the next ID for the specified table. It was decided
1362 // to create this function instead of using the ADODB GenID() function.
1363 // We didnt want to have sequence tables cluttering the schema so a single
1364 // table was created that stored the ID and the tablename it is for.
1365 //
1366 // Example:
1367 // $id = ona_get_next_id($tablename);
1369 function ona_get_next_id($tablename) {
1370  global $onadb, $self;
1371 
1372  // Debugging
1373  printmsg("DEBUG => ona_get_next_id() called", 3);
1374 
1375  // Find the sequence value for the specified tablename
1376  list($status, $rows, $record) = db_get_record($onadb, 'sequences', array('name' => $tablename));
1377 
1378  // Init a new sequence when the tablename is not found
1379  if (!$rows) {
1380  list($status, $rows) = db_insert_record($onadb, 'sequences', array('name' => $tablename, 'seq' => 2));
1381  return(1);
1382  }
1383  else {
1384  // if we did find something increment the sequence in the table
1385  $seq_inc = $record['seq'] + 1;
1386  list($status, $rows) = db_update_record($onadb, 'sequences', array('name' => $tablename), array('seq' => $seq_inc));
1387 
1388  if ($status) {
1389  $self['error'] = 'ERROR => ona_get_next_id() Unable to update sequence value!';
1390  printmsg($self['error'], 4);
1391  return(0);
1392  }
1393 
1394  // If we got an ID, return it.
1395  if ($record['seq'] > 0) {
1396  printmsg("DEBUG => ona_get_next_id() Returning ID: " . $record['seq'], 4);
1397  return($record['seq']);
1398  }
1399  // Just in case...
1400  else {
1401  $self['error'] = 'ERROR => ona_get_next_id() Something went wrong!';
1402  printmsg($self['error'], 4);
1403  return(0);
1404  }
1405  }
1406 }
1407 
1408 
1409 
1410 
1411 
1412 
1413 
1414 
1416 // Function: string $domain_name = ona_build_domain_name (id=NUMBER)
1417 //
1418 // Input:
1419 // $id = Row ID for a domain record
1420 //
1421 // Output:
1422 // Returns the full domain name of the specified domain record.
1423 //
1424 // Description:
1425 // Walks up the tree of domain records and returns the full
1426 // name of the domain record specified. Usually used for displaying
1427 // a full domain name over the gui.
1428 // FIXME: (bz) maybe this should allow a string to be passed too to
1429 // provide search abilities?
1430 //
1431 // Example: $name = ona_build_domain_name(18);
1433 function ona_build_domain_name($search='') {
1434  global $conf, $self, $onadb;
1435  $domain_name = '';
1436  $status = 0;
1437  while ($status == 0) {
1438  list($status, $rows, $domain) = db_get_record($onadb, 'domains', array('id' => $search));
1439  if ($domain_name == '') { // i.e. the first pass
1440  $domain_name = $domain['name'];
1441  if ($domain['parent_id'] != 0) { $search = $domain['parent_id']; }
1442  } else {
1443  $domain_name .= '.' . $domain['name'];
1444  if ($domain['parent_id'] != 0) { $search = $domain['parent_id']; }
1445  }
1446  if ($domain['parent_id'] == 0) {
1447  return($domain_name);
1448  }
1449  }
1450 }
1451 
1452 
1453 
1454 
1455 
1456 
1457 
1458 
1459 
1460 
1462 // Function: ona_find_host (string $search)
1463 //
1464 // Input:
1465 // $search = An FQDN, host ID, IP address (or other unique interface
1466 // identifier), or any substring that can uniquly identify
1467 // a host record.
1468 //
1469 // Output:
1470 // Returns a three part array: list($status, $rows, $host)
1471 //
1472 // Description:
1473 // If $search is not an FQDN:
1474 // The requested host record is identified via host ID, IP addr,
1475 // or unique dns name, etc, and the associated host record is
1476 // returned.
1477 // If $search is an FQDN:
1478 // Looks at $fqdn, determines which part of it (if any) is the
1479 // domain name and which part is the hostname. Then searches the
1480 // database for matching hostname record
1481 // * In the event that the FQDN does not contain a valid dns name
1482 // a "fake" host record is returned with only the "name" and
1483 // "fqdn" keys populated.
1484 // * In the event that a valid, existing, domain can not be found in
1485 // the FQDN, the default domain "something.com" will be returned.
1486 // I.E. A valid domain record will always be returned.
1487 //
1488 // Example: list($status, $rows, $host) = ona_find_host('myhost.domain.com');
1490 function ona_find_host($search="") {
1491  global $conf, $self, $onadb;
1492  printmsg("DEBUG => ona_find_host({$search}) called", 3);
1493 
1494  // By record ID?
1495  if (is_numeric($search)) {
1496  list($status, $rows, $host) = ona_get_host_record(array('id' => $search));
1497  if ($rows) {
1498  printmsg("DEBUG => ona_find_host({$search}) called, found: {$host['fqdn']}", 3);
1499  return(array($status, $rows, $host));
1500  }
1501  }
1502 
1503  // By Interface ID or IP address?
1504  list($status, $rows, $interface) = ona_find_interface($search);
1505  if (!$status and $rows) {
1506  // Load and return associated info
1507  list($status, $rows, $host) = ona_get_host_record(array('id' => $interface['host_id']));
1508  return(array($status, $rows, $host));
1509  }
1510 
1511  // MP: NEEDS MORE VALIDATION ON THIS PART!!
1512  // If it does not have a dot in it. append the default domain
1513  if (!strstr($search,'.')) {
1514  $search = $search.'.'.$conf['dns_defaultdomain'];
1515  }
1516 
1517  //
1518  // It's an FQDN, do a bunch of stuff!
1519  //
1520 
1521  // lets test out if it has a / in it to strip the view name portion
1522  $view['id'] = 0;
1523  if (strstr($search,'/')) {
1524  list($dnsview,$search) = explode('/', $search);
1525  list($status, $rows, $view) = db_get_record($onadb, 'dns_views', array('name' => strtoupper($dnsview)));
1526  printmsg("DEBUG => ona_find_host: DNS view [{$dnsview}] was not found, using default", 2);
1527  if(!$rows) $view['id'] = 0;
1528  }
1529 
1530 
1531  // FIXME: MP this will currently "fail" if the fqdn of the server
1532  // is the same as a valid domain name. not sure why anyone would have this but
1533  // never say never. I'll leave this issue unfixed for now
1534 
1535  // Find the 'first', domain name piece of $search
1536  list($status, $rows, $domain) = ona_find_domain($search,0);
1537  if (!isset($domain['id'])) {
1538  printmsg("ERROR => Unable to determine domain name portion of ({$search})!", 3);
1539  $self['error'] = "ERROR => Unable to determine domain name portion of ({$search})!";
1540  return(array(3, $self['error'] . "\n"));
1541  }
1542  printmsg("DEBUG => ona_find_domain({$search}) returned: {$domain['fqdn']}", 3);
1543 
1544  // Now find what the host part of $search is
1545  $hostname = str_replace(".{$domain['fqdn']}", '', $search);
1546 
1547 
1548  // Let's see if that hostname is valid or not in $domain['id']
1549  $domain_parts = explode('.', $domain['fqdn']);
1550  foreach ($domain_parts as $part) {
1551  // Loop through the parts of the domain to find host.sub domain.com type entries..
1552  list($status, $dnsrows, $dnsrecs) = db_get_records($onadb, 'dns', array('domain_id' => $domain['id'], 'name' => $hostname, 'dns_view_id' => $view['id']));
1553  // If we didnt just find a dns record.. lets move the period over and try a deeper domain/host pair.
1554  if (!$dnsrows) {
1555  $hostname = $hostname.'.'.$part;
1556  $name = str_replace("{$part}.", '', $domain['fqdn']);
1557  list($status, $rows, $domain) = ona_get_domain_record(array('name' => $name));
1558  } else {
1559  break;
1560  }
1561  }
1562 
1563 
1564  // If we found one or more dns records, lets loop through them all and find the first primary host using that name
1565  if ($dnsrows) {
1566  foreach ($dnsrecs as $entry) {
1567  list($status, $rows, $host) = ona_get_host_record(array('primary_dns_id' => $entry['id']));
1568  if ($host['id'])
1569  return(array($status, $rows, $host));
1570  }
1571  }
1572 
1573  // Otherwise, build a fake host record with only a few entries in it and return that
1574  $host = array(
1575  'id' => 0,
1576  'name' => $hostname,
1577  'fqdn' => "{$hostname}.{$domain['fqdn']}",
1578  'domain_id' => $domain['id'],
1579  'domain_fqdn' => $domain['fqdn'],
1580  );
1581 
1582  return(array(0, 0, $host));
1583 }
1584 
1585 
1586 
1587 
1588 
1589 
1590 
1591 
1592 
1594 // Function: ona_find_domain (string $fqdn)
1595 //
1596 // $fqdn = The hostname[.domain] you want to find the domain record
1597 // for.
1598 //
1599 // Looks at $fqdn, finds the best-matching domain in it, and returns
1600 // it. If $fqdn does not include a valid domain of any sort, we
1601 // assume $fqdn is a bare hostname, and return the domain record
1602 // for the user's default domain.
1603 //
1604 // You can pass a 0 as the second option to instruct it not to send back the
1605 // default domain name
1606 //
1607 // Example: list($status, $rows, $domain) = ona_find_domain('myhost.mydomain.com',1);
1609 function ona_find_domain($fqdn="", $returndefault=0) {
1610  global $conf;
1611  $status=1;
1612  $fqdn = strtolower($fqdn);
1613  printmsg("DEBUG => ona_find_domain({$fqdn}) called", 3);
1614 
1615  // lets test out if it has a / in it to strip the view name portion
1616  if (strstr($fqdn,'/')) {
1617  list($dnsview,$fqdn) = explode('/', $fqdn);
1618  }
1619 
1620  // Split it up on '.' and put it in an array backwards
1621  $parts = array_reverse(explode('.', $fqdn));
1622 
1623  // Find the domain name that best matches
1624  $name = '';
1625  $foundone = 0;
1626  $domain = array();
1627  foreach ($parts as $part) {
1628  if (!$foundone) {
1629  if (!$name) $name = $part;
1630  else $name = "{$part}.{$name}";
1631  list($status, $rowsa, $record) = ona_get_domain_record(array('name' => $name));
1632  if ($rowsa) {
1633  $domain = $record;
1634  printmsg("DEBUG => ona_find_domain({$fqdn}) Found: {$domain['fqdn']}", 3);
1635  $foundone = 1;
1636  }
1637  }
1638  else {
1639  if (!$name) $name = $part;
1640  else $name = preg_replace("/.{$domain['fqdn']}$/", '', "{$part}.{$name}");
1641  list($status, $rowsb, $record) = ona_get_domain_record(array('name' => $name, 'parent_id' => $domain['id']));
1642  if ($rowsb) {
1643  $domain = $record;
1644  printmsg("DEBUG => ona_find_domain({$fqdn}) Found with parent: {$domain['fqdn']}", 3);
1645  $foundone = 1;
1646  $name = '';
1647  } else {
1648  // try it as a fqdn not with a parent
1649  list($status, $rowsb, $record) = ona_get_domain_record(array('name' => "{$name}.{$domain['fqdn']}", 'parent_id' => 0));
1650  if ($rowsb) {
1651  $domain = $record;
1652  printmsg("DEBUG => ona_find_domain({$fqdn}) Found with parent: {$domain['fqdn']}", 3);
1653  $foundone = 1;
1654  $name = '';
1655  }
1656  }
1657 
1658  }
1659  }
1660 
1661 // FIXME: MP removed since it caused problems when passing in things like rtr.example.comasdl you would get rtrasdl.example.com back
1662 // if ($returndefault=1) {
1663 // // If we don't have a domain yet, lets assume $fqdn is a basic hostname, and return the default domain
1664 // if (!array_key_exists('id', $domain)) {
1665 // printmsg("DEBUG => ona_find_domain({$fqdn}) Using system default domain: {$conf['dns_defaultdomain']}", 3);
1666 // list($status, $rows, $record) = ona_get_domain_record(array('name' => $conf['dns_defaultdomain']));
1667 // if($rows)
1668 // $domain = $record;
1669 // }
1670 // // Set status to 0 (ok) since we are returning something
1671 // $status=0;
1672 // }
1673 
1674  // FIXME: MP rows is not right here.. need to look at fixing it.. rowsa/rowsb above doesnt translate.. do I even need that?
1675  return(array($status, $rows, $domain));
1676 }
1677 
1678 
1679 
1680 
1681 
1682 
1683 
1684 
1685 
1686 
1687 
1689 // Function: ona_find_dns_record (string $search, string $type)
1690 //
1691 // $search = The hostname[.domain], or ID you want to find the domain record
1692 // for.
1693 // $type = The type of dns record you are looking for, A, CNAME, PTR, etc
1694 // $int_id = The interface_id to use when searching for A records. helps limit to one record
1695 //
1696 // Looks at $search, finds the best-matching dns record for it, and returns
1697 // it. If $search does not include a valid domain of any sort, we
1698 // assume $search is a bare hostname, and return the dns record with
1699 // the user's default domain.
1700 //
1701 // Example: list($status, $rows, $dns) = ona_find_dns_record('myhost.mydomain.com');
1703 function ona_find_dns_record($search="",$type='',$int_id=0) {
1704  global $conf, $self, $onadb;
1705  printmsg("DEBUG => ona_find_dns_record({$search}) called", 3);
1706  $type = strtoupper($type);
1707  $search = strtolower($search);
1708 
1709  // By record ID?
1710  if (is_numeric($search)) {
1711  list($status, $rows, $dns) = ona_get_dns_record(array('id' => $search));
1712  if ($rows) {
1713  printmsg("DEBUG => ona_find_dns_record({$search}) called, found: {$dns['fqdn']}({$dns['type']})", 3);
1714  return(array($status, $rows, $dns));
1715  }
1716  }
1717 
1718 
1719  //
1720  // It's an FQDN, do a bunch of stuff!
1721  //
1722 
1723  // lets test out if it has a / in it to strip the view name portion
1724  $view['id'] = 0;
1725  if (strstr($search,'/')) {
1726  list($dnsview,$search) = explode('/', $search);
1727  list($status, $rows, $view) = db_get_record($onadb, 'dns_views', array('name' => strtoupper($dnsview)));
1728  if(!$rows) $view['id'] = 0;
1729  }
1730 
1731 
1732  // Find the domain name piece of $search
1733  list($status, $rows, $domain) = ona_find_domain($search);
1734  printmsg("DEBUG => ona_find_domain({$search}) returned: {$domain['fqdn']}", 3);
1735 
1736  // Now find what the host part of $search is
1737  $hostname = str_replace(".{$domain['fqdn']}", '', $search);
1738 
1739  // If the hostname we came up with and the domain name are the same, then assume this is
1740  // meant to be a domain specific record, like A, MX, NS type records.
1741  if ($hostname == $domain['fqdn']) $hostname = '';
1742 
1743  // Setup the search array
1744  $searcharray = array('domain_id' => $domain['id'], 'name' => $hostname, 'dns_view_id' => $view['id']);
1745 
1746  // If an interface_id was passed, add it to the array
1747  if ($int_id > 0) { $searcharray['interface_id'] = $int_id; }
1748  // If a type was passed, add it to the array
1749  if ($type) { $searcharray['type'] = $type; }
1750 
1751  // Let's see if that hostname is valid or not in $domain['id']
1752  list($status, $rows, $dns) = ona_get_dns_record($searcharray);
1753 
1754  if ($rows) {
1755  // Return good status, one row, and $dns array
1756  printmsg("DEBUG => ona_find_dns_record({$search}) called, found: {$dns['fqdn']}({$dns['type']})", 3);
1757  return(array(0, 1, $dns));
1758  }
1759 
1760  // Otherwise, build a fake dns record with only a few entries in it and return that
1761  $dns = array(
1762  'id' => 0,
1763  'name' => $hostname,
1764  'fqdn' => "{$hostname}.{$domain['fqdn']}",
1765  'domain_id' => $domain['id'],
1766  'domain_fqdn' => $domain['fqdn'],
1767  'type' => '',
1768  'dns_id' => 0
1769  );
1770 
1771  printmsg("DEBUG => ona_find_dns_record({$search}) called, Nothing found, returning fake entry: {$dns['fqdn']}({$dns['type']})", 3);
1772  return(array(0, 1, $dns));
1773 }
1774 
1775 
1776 
1777 
1778 
1779 
1780 
1781 
1782 
1783 
1784 
1785 
1786 
1787 
1789 // Function: ona_find_location(string $search)
1790 //
1791 // Input:
1792 // $search = A location ID, location number, name or substring that can
1793 // uniquly identify a location.
1794 //
1795 // Output:
1796 // Returns a three part list:
1797 // 1. The exit status of the function (0 on success, non-zero on error)
1798 // 2. The number of rows that were found - 0 or 1 (0 is returned if
1799 // a unique match couldn't be found)
1800 // 3. An associative array of a record from the LOCATIONS table
1801 // where $search matchs.
1802 //
1803 // Example: list($status, $rows, $location_record) = ona_find_location('fairview');
1804 //
1805 // Exit codes:
1806 // 0 :: No error
1807 // 1 :: Invalid or no input
1808 // 2 :: No (unique?) match found
1810 function ona_find_location($search="") {
1811  printmsg("DEBUG => ona_find_location({$search}) called", 3);
1812 
1813  // Validate input
1814  if ($search == "") {
1815  return(array(1, 0, array()));
1816  }
1817 
1818  // If it's numeric
1819  if (preg_match('/^\d+$/', $search)) {
1820  // Search for it by Location ID
1821  list($status, $rows, $record) = ona_get_location_record(array('id' => $search));
1822  // If we got it, return it
1823  if ($status == 0 and $rows == 1) {
1824  printmsg("DEBUG => ona_find_location() found location record by id", 2);
1825  return(array(0, $rows, $record));
1826  }
1827 
1828  // Search for it by zip code
1829  list($status, $rows, $record) = ona_get_location_record(array('zip_code' => $search));
1830  // If we got it, return it
1831  if ($status == 0 and $rows == 1) {
1832  printmsg("DEBUG => ona_find_location() found location record by zip code search", 2);
1833  return(array(0, $rows, $record));
1834  }
1835  }
1836 
1837  // It's a string - do several sql queries and see if we can get a unique match
1838  foreach (array('reference','name', 'address', 'city', 'state') as $field) {
1839  // First, try it as they send it
1840  list($status, $rows, $record) = ona_get_location_record(array($field => $search));
1841  // If we got it, return it
1842  if ($status == 0 and $rows == 1) {
1843  printmsg("DEBUG => ona_find_location() found location record by $field search", 2);
1844  return(array(0, $rows, $record));
1845  }
1846  }
1847 
1848  foreach (array('reference','name', 'address', 'city', 'state') as $field) {
1849  // Next, do an upper on it to try it as upper case
1850  $search = strtoupper($search);
1851  list($status, $rows, $record) = ona_get_location_record(array($field => $search));
1852  // If we got it, return it
1853  if ($status == 0 and $rows == 1) {
1854  printmsg("DEBUG => ona_find_location() found location record by UPPER($field) search", 2);
1855  return(array(0, $rows, $record));
1856  }
1857  }
1858 
1859  foreach (array('reference','name', 'address', 'city', 'state') as $field) {
1860  // Last, try it all lowercase
1861  $search = strtolower($search);
1862  list($status, $rows, $record) = ona_get_location_record(array($field => $search));
1863  // If we got it, return it
1864  if ($status == 0 and $rows == 1) {
1865  printmsg("DEBUG => ona_find_location() found location record by LOWER($field) search", 2);
1866  return(array(0, $rows, $record));
1867  }
1868  }
1869 
1870  // We didn't find it - return and error code, 0 matches, and an empty record.
1871  printmsg("DEBUG => ona_find_location() couldn't find a unique location record with specified search criteria", 2);
1872  return(array(2, 0, array()));
1873 }
1874 
1875 
1876 
1877 
1878 
1879 
1880 
1881 
1882 
1883 
1885 // Function: ona_find_interface(string $search)
1886 //
1887 // Input:
1888 // $search = An interface ID, IP address, or any substring that can
1889 // uniquly identify an interface.
1890 //
1891 // Output:
1892 // Returns a three part list:
1893 // 1. The exit status of the function (0 on success, non-zero on error)
1894 // 2. The number of rows that were found - 0 or 1 (0 is returned if
1895 // a unique match couldn't be found)
1896 // 3. An associative array of a record from the interfaces table
1897 // where $search matchs.
1898 //
1899 // Example: list($status, $rows, $interface) = ona_find_interface('10.44.10.123');
1900 //
1901 // Exit codes:
1902 // 0 :: No error
1903 // 1 :: Invalid or no input
1904 // 2 :: No (unique?) match found
1905 // 3 :: No such IP address
1906 // 4 :: More than one interface has that IP address
1907 // 5 :: No such MAC address
1908 // 6 :: More than one interface has that MAC address
1910 function ona_find_interface($search="") {
1911  printmsg("DEBUG => ona_find_interface({$search}) called", 3);
1912 
1913  // Validate input
1914  if ($search == "")
1915  return(array(1, 0, array()));
1916 
1917  // If it's numeric
1918  if (is_numeric($search)) {
1919  // It's a number - do several sql queries and see if we can get a unique match
1920  foreach (array('id', 'host_id', 'ip_addr') as $field) {
1921  list($status, $rows, $record) = ona_get_interface_record("{$field} like '{$search}'");
1922  // If we got it, return it
1923  if ($status == 0 and $rows == 1) {
1924  printmsg("DEBUG => ona_find_interface() found interface record by {$field}", 2);
1925  return(array(0, $rows, $record));
1926  }
1927  }
1928  }
1929 
1930  // If it's an IP address...
1931  $ip = ip_mangle($search, 1);
1932  if ($ip != -1) {
1933  list($status, $rows, $record) = ona_get_interface_record("ip_addr like '{$ip}'");
1934  // If we got it, return it
1935  if ($status == 0 and $rows == 1) {
1936  printmsg("DEBUG => ona_find_interface() found record by IP address", 2);
1937  return(array(0, $rows, $record));
1938  }
1939 
1940  // Otherwise return an error
1941  if ($rows == 0) {
1942  printmsg("DEBUG => No interface has the IP address: $search", 2);
1943  return(array(3, $rows, array()));
1944  }
1945  printmsg("DEBUG => More than one interface has the IP address: $search", 2);
1946  return(array(4, $rows, array()));
1947  }
1948 
1949 
1950  // If it's a MAC address
1951  $mac = mac_mangle($search, 1);
1952  if ($mac != -1) {
1953 
1954  // Search for it
1955  list($status, $rows, $record) = ona_get_interface_record(array('mac_addr' => $mac));
1956 
1957  // If we got it, return it
1958  if (!$status and $rows == 1) {
1959  printmsg("DEBUG => ona_find_interface() found record by MAC address", 2);
1960  return(array(0, $rows, $record));
1961  }
1962 
1963  // Otherwise return an error
1964  if ($rows == 0) {
1965  printmsg("ERROR => No interface has the MAC address: $search", 2);
1966  return(array(5, 0, array()));
1967  }
1968  printmsg("DEBUG => ona_find_interface() More than one interface has the MAC address: " . mac_mangle($mac, 1), 0);
1969  return(array(6, 0, array()));
1970  }
1971 
1972  // We didn't find it - return and error code, 0 matches, and an empty record.
1973  printmsg("DEBUG => ona_find_interface() couldn't find a unique interface record with specified search criteria", 1);
1974  return(array(2, 0, array()));
1975 }
1976 
1977 
1978 
1979 
1980 
1981 
1982 
1983 
1984 
1985 
1987 // Function: ona_find_subnet(string $search)
1988 //
1989 // Input:
1990 // $search = A subnet ID or IP address that can uniquly identify a subnet.
1991 //
1992 // Output:
1993 // Returns a three part list:
1994 // 1. The exit status of the function (0 on success, non-zero on error)
1995 // When a non-zero exit status is returned a textual description
1996 // of the error will be stored in the global variable $self['error']
1997 // 2. The number of rows that were found - 0 or 1 (0 is returned if
1998 // a unique match couldn't be found)
1999 // 3. An array of a record from the subnets table where $search matchs.
2000 //
2001 // Example: list($status, $rows, $subnet) = ona_find_subnet('10.44.10.123');
2003 function ona_find_subnet($search="") {
2004  global $self;
2005 
2006  // Validate input
2007  if ($search == "") {
2008  return(array(1, 0, array()));
2009  }
2010 
2011  // If it's numeric
2012  if (preg_match('/^\d+$/', $search)) {
2013  // It's a number - do several sql queries and see if we can get a unique match
2014  foreach (array('id', 'ip_addr') as $field) {
2015  // list($status, $rows, $record) = ona_get_subnet_record(array($field => $search));
2016  // GDO: don't use array() here, because it breaks ipv6 subnets
2017  list($status, $rows, $record) = ona_get_subnet_record("$field = $search");
2018  // If we got it, return it
2019  if ($status == 0 and $rows == 1) {
2020  printmsg("DEBUG => ona_find_subnet() found subnet record by $field $search", 2);
2021  return(array(0, $rows, $record));
2022  }
2023  }
2024  }
2025 
2026  // If it's an IP address
2027  $ip = ip_mangle($search, 1);
2028  if ($ip != -1) {
2029 
2030  // Do a cool SQL query to find the subnet that the given IP address is on
2031  // Basically we tell the database we want to find an IP address >= than the base
2032  // of the subnet, and less than the end of the subnet.
2033  // Description:
2034  // (2^32 - 1) == 4294967295 == a 32bit integer with all 1's.
2035  // 4294967295 - subnet_mask results in the number of hosts on that subnet.
2036  // + the base ip_addr results in the top of the subnet.
2037  if (strlen($ip) > 11) {
2038  // IPv6.. had to check that it was above ipv4 space
2039  $where = "$ip between ip_addr AND ((340282366920938463463374607431768211455 - ip_mask) + ip_addr) and ip_addr > 4294967295";
2040  } else {
2041  $where = "$ip >= ip_addr AND $ip <= ((4294967295 - ip_mask) + ip_addr)";
2042  }
2043 
2044  list($status, $rows, $record) = ona_get_subnet_record($where);
2045 
2046  // If we got it, return it
2047  if ($status == 0 and $rows == 1) {
2048  printmsg("DEBUG => ona_find_subnet() found record by IP address", 2);
2049  return(array(0, $rows, $record));
2050  }
2051 
2052  // Otherwise return an error
2053  if ($rows == 0) {
2054  $ip = ip_mangle($ip, 2);
2055  $self['error'] = "NOTICE => IP supplied, $ip, does not belong to any existing subnet!";
2056  printmsg($self['error'], 2);
2057  return(array(3, $rows, array()));
2058  }
2059  $self['error'] = "NOTICE => IP supplied, $ip, belongs to more than one subnet! Data corruption?";
2060  printmsg($self['error'], 2);
2061  return(array(4, $rows, array()));
2062  }
2063 
2064  // Try the name field
2065  // We use all upper-case subnet names
2066  list($status, $rows, $record) = ona_get_subnet_record(array('name' => strtoupper($search)));
2067  // If we got it, return it
2068  if ($status == 0 and $rows == 1) {
2069  printmsg("DEBUG => ona_find_subnet() found subnet record by its name", 2);
2070  return(array(0, $rows, $record));
2071  }
2072 
2073  // We didn't find it - return and error code, 0 matches, and an empty record.
2074  $self['error'] = "NOTICE => couldn't find a unique subnet record with specified search criteria";
2075  printmsg($self['error'], 2);
2076  return(array(2, 0, array()));
2077 }
2078 
2079 
2080 
2081 
2082 
2083 
2084 
2085 
2086 
2087 
2089 // Function: ona_find_device(string $search)
2090 //
2091 // Input:
2092 // $search = A device ID, IP address, or FQDN that can uniquely identify a device.
2093 //
2094 // Output:
2095 // Returns a three part list:
2096 // 1. The exit status of the function (0 on success, non-zero on error)
2097 // When a non-zero exit status is returned a textual description
2098 // of the error will be stored in the global variable $self['error']
2099 // 2. The number of rows that were found - 0 or 1 (0 is returned if
2100 // a unique match couldn't be found)
2101 // 3. An array of a record from the devices table where $search matches.
2102 //
2103 // Example: list($status, $rows, $device) = ona_find_device('1714');
2105 function ona_find_device($search="") {
2106  global $self;
2107 
2108  // Validate input
2109  if ($search == "") {
2110  return(array(1, 0, array()));
2111  }
2112 
2113  // If it's numeric, assume its a device ID
2114  if (preg_match('/^\d+$/', $search)) {
2115  list($status, $rows, $record) = ona_get_device_record(array('id' => $search));
2116  // If we got it, return it
2117  if ($status == 0 and $rows == 1) {
2118  printmsg("DEBUG => ona_find_device() found device record by id", 2);
2119  return(array(0, $rows, $record));
2120  }
2121  }
2122 
2123  // If it's an IP address or an FQDN:
2124 // $ip = ip_mangle($search, 'numeric');
2125 // if ($ip != -1) {
2126  // Look up the host first
2127  list($status, $rows, $host) = ona_find_host($search);
2128  if ($status == 0 and $rows == 1) {
2129  list($status, $rows, $record) = ona_get_device_record(array('id' => $host['device_id']));
2130  }
2131 
2132  // If we got it, return it
2133  if ($status == 0 and $rows == 1) {
2134  printmsg("DEBUG => ona_find_device() found record by IP address", 2);
2135  return(array(0, $rows, $record));
2136  }
2137 
2138  // Otherwise return an error
2139  if ($rows == 0) {
2140  //$ip = ip_mangle($ip, 'dotted');
2141  $self['error'] = "NOTICE => ona_find_device() was unable to locate the record by IP or fqdn";
2142  printmsg($self['error'], 2);
2143  return(array(3, $rows, array()));
2144  }
2145 // $self['error'] = "NOTICE => ona_find_device() found multiple matching records when searching by IP or fqdn. Data corruption?";
2146 // printmsg($self['error'], 2);
2147 // return(array(4, $rows, array()));
2148 // }
2149 
2150  // We didn't find it - return and error code, 0 matches, and an empty record.
2151  $self['error'] = "NOTICE => ona_find_device() couldn't find a unique device record with specified search criteria";
2152  printmsg($self['error'], 2);
2153  return(array(2, 0, array()));
2154 }
2155 
2156 
2157 
2158 
2159 
2160 
2161 
2162 
2163 
2164 
2166 // Function: ona_find_device_type(string $search)
2167 //
2168 // Input:
2169 // $search = A model name string or device_type ID that can uniquely identify
2170 // a device type from the device_types table in the database.
2171 //
2172 // Output:
2173 // Returns a three part list:
2174 // 1. The exit status of the function (0 on success, non-zero on error)
2175 // When a non-zero exit status is returned a textual description
2176 // of the error will be stored in the global variable $self['error']
2177 // 2. The number of rows that were found - 0 or 1 (0 is returned if
2178 // a unique match couldn't be found)
2179 // 3. An array of a record from the devices table where
2180 // $search matchs.
2181 //
2182 // Example: list($status, $rows, $subnet) = ona_find_device_type('something');
2184 function ona_find_device_type($search="") {
2185  global $self;
2186 
2187  // Validate input
2188  if ($search == "") {
2189  return(array(1, 0, array()));
2190  }
2191 
2192  // If it's numeric
2193  if (preg_match('/^\d+$/', $search)) {
2194  // It's a number - do several sql queries and see if we can get a unique match
2195  list($status, $rows, $record) = ona_get_device_type_record(array('id' => $search));
2196  // If we got it, return it
2197  if ($status == 0 and $rows == 1) {
2198  printmsg("DEBUG => ona_find_device_type() found device_type record by id", 2);
2199  return(array(0, $rows, $record));
2200  }
2201 /* PK: this was the original code...
2202  foreach (array('id', 'DEVICE_TYPE_ID', 'MANUFACTURER_ID') as $field) {
2203  list($status, $rows, $record) = ona_get_model_record(array($field => $search));
2204  // If we got it, return it
2205  if ($status == 0 and $rows == 1) {
2206  printmsg("DEBUG => ona_find_device() found device record by $field", 2);
2207  return(array(0, $rows, $record));
2208  }
2209  }*/
2210  }
2211 
2212  // It's a string - do several sql queries and see if we can get a unique match
2213  list($manufmodel, $role) = split("\(",$search);
2214  list($manuf, $model) = split(", ",$manufmodel);
2215  $role = preg_replace(array('/\(/','/\)/'),'',"{$role}");
2216  list($status, $rows, $manu) = ona_get_manufacturer_record(array('name' => $manuf));
2217  list($status, $rows, $rol) = ona_get_role_record(array('name' => $role));
2218  list($status, $rows, $record) = ona_get_model_record(array('name' => $model,'manufacturer_id' => $manu['id']));
2219  if ($status == 0 and $rows == 1) {
2220  list($status, $rows, $record) = ona_get_device_type_record(array('model_id' => $record['id'],'role_id' => $rol['id']));
2221  }
2222  // If we got it, return it
2223  if ($status == 0 and $rows == 1) {
2224  printmsg("DEBUG => ona_find_device_type() found device_type record by model name", 2);
2225  return(array(0, $rows, $record));
2226  }
2227 
2228 
2229  // We didn't find it - return and error code, 0 matches, and an empty record.
2230  $self['error'] = "NOTICE => couldn't find a unique device_type record with specified search criteria";
2231  printmsg($self['error'], 2);
2232  return(array(2, 0, array()));
2233 
2234 }
2235 
2236 
2237 
2238 
2239 
2240 
2241 
2242 
2243 
2245 // Function: ona_find_subnet_type(string $search)
2246 //
2247 // Input:
2248 // $search = A string or ID that can uniquly identify a subnet
2249 // type from the "subnet_types" table in the database.
2250 //
2251 // Output:
2252 // Returns a three part list:
2253 // 1. The exit status of the function (0 on success, non-zero on error)
2254 // When a non-zero exit status is returned a textual description
2255 // of the error will be stored in the global variable $self['error']
2256 // 2. The number of rows that were found - 0 or 1 (0 is returned if
2257 // a unique match couldn't be found)
2258 // 3. An array of a record from the "subnet_types" table where
2259 // $search matchs.
2260 //
2261 // Example: list($status, $rows, $net_type) = ona_find_subnet_type('VLAN (802.1Q or ISL)');
2263 function ona_find_subnet_type($search="") {
2264  global $self;
2265 
2266  // Validate input
2267  if ($search == "") {
2268  $self['error'] = "ERROR => No search string for subnet-type search";
2269  return(array(1, 0, array()));
2270  }
2271 
2272  // If it's numeric, search by record ID
2273  if (is_numeric($search)) {
2274  $field = 'id';
2275  list($status, $rows, $record) = ona_get_subnet_type_record(array($field => $search));
2276  // If we got it, return it
2277  if ($status == 0 and $rows == 1) {
2278  printmsg("DEBUG => ona_find_subnet_type() found device record by $field", 2);
2279  return(array($status, $rows, $record));
2280  }
2281  }
2282 
2283  // It's a string - do several sql queries and see if we can get a unique match
2284  list($status, $rows, $record) = ona_get_subnet_type_record(array('display_name' => $search));
2285  if ($status == 0 and $rows == 1) {
2286  printmsg("DEBUG => ona_find_subnet_type() found subnet_type record by its name", 2);
2287  return(array(0, $rows, $record));
2288  }
2289 
2290  list($status, $rows, $record) = ona_get_subnet_type_record(array('short_name' => $search));
2291  if ($status == 0 and $rows == 1) {
2292  printmsg("DEBUG => ona_find_subnet_type() found subnet_type record by its name", 2);
2293  return(array(0, $rows, $record));
2294  }
2295 
2296  // We didn't find it - return and error code, 0 matches, and an empty record.
2297  $self['error'] = "NOTICE => Subnet-type not found";
2298  printmsg($self['error'], 2);
2299  return(array(2, 0, array()));
2300 }
2301 
2302 
2303 
2304 
2305 
2307 // Function: ona_find_custom_attribute(string $search)
2308 //
2309 // Input:
2310 // $search = A string or ID that can uniquly identify a record
2311 // from the custom_attributes table in the database.
2312 //
2313 // Output:
2314 // Returns a three part list:
2315 // 1. The exit status of the function (0 on success, non-zero on error)
2316 // When a non-zero exit status is returned a textual description
2317 // of the error will be stored in the global variable $self['error']
2318 // 2. The number of rows that were found - 0 or 1 (0 is returned if
2319 // a unique match couldn't be found)
2320 // 3. An array of a record from the custom_attributes table where
2321 // $search matchs.
2322 //
2323 // Example: list($status, $rows, $net_type) = ona_find_custom_attribute('Status (Testing)');
2325 function ona_find_custom_attribute($search="") {
2326  global $self;
2327 
2328  // Validate input
2329  if ($search == "") {
2330  return(array(1, 0, array()));
2331  }
2332 
2333  // If it's numeric, search by record ID
2334  if (is_numeric($search)) {
2335  $field = 'id';
2336  list($status, $rows, $record) = ona_get_custom_attribute_record(array($field => $search));
2337  // If we got it, return it
2338  if ($status == 0 and $rows == 1) {
2339  printmsg("DEBUG => ona_find_custom_attribute() found custom attribute record by $field", 2);
2340  return(array(0, $rows, $record));
2341  }
2342  }
2343 
2344  // Split the description based on the () enclosed type
2345  list($ca_type, $ca_value) = preg_split("/\(|\)/",$search);
2346 
2347  printmsg("DEBUG => ona_find_custom_attribute(): Split is {$ca_type},{$ca_value}", 3);
2348 
2349 
2350  // It's a string - do several sql queries and see if we can get a unique match
2351  list($status, $rows, $type) = ona_get_custom_attribute_type_record(array('name' => trim($ca_type)));
2352 
2353  printmsg("DEBUG => ona_find_custom_attribute(): Found {$rows} custom attribute type record", 3);
2354 
2355  // Find the ID using the type id and value
2356  list($status, $rows, $record) = ona_get_custom_attribute_record(array('value' => $ca_value,'custom_attribute_type_id' => $type['id']));
2357  // If we got it, return it
2358  if ($status == 0 and $rows == 1) {
2359  printmsg("DEBUG => ona_find_custom_attribute(): Found custom attribute record by its full name", 2);
2360  return(array(0, $rows, $record));
2361  }
2362 
2363  // We didn't find it - return and error code, 0 matches, and an empty record.
2364  $self['error'] = "NOTICE => couldn't find a unique custom attribute record with specified search criteria";
2365  printmsg($self['error'], 2);
2366  return(array(2, 0, array()));
2367 }
2368 
2369 
2370 
2371 
2372 
2373 
2374 
2375 
2376 
2377 
2379 // Function: ona_find_dhcp_option(string $search)
2380 //
2381 // Input:
2382 // $search = A string or ID that can uniquly identify a dhcp parm type
2383 // from the dhcp_parameter_types table in the database.
2384 //
2385 // Output:
2386 // Returns a three part list:
2387 // 1. The exit status of the function (0 on success, non-zero on error)
2388 // When a non-zero exit status is returned a textual description
2389 // of the error will be stored in the global variable $self['error']
2390 // 2. The number of rows that were found - 0 or 1 (0 is returned if
2391 // a unique match couldn't be found)
2392 // 3. An array of a record from the dhcp_options table where
2393 // $search matchs.
2394 //
2395 // Example: list($status, $rows, $dhcp_type) = ona_find_dhcp_option('Default gateway(s)');
2397 function ona_find_dhcp_option($search="") {
2398  global $self;
2399 
2400  // Validate input
2401  if ($search == "") {
2402  return(array(1, 0, array()));
2403  }
2404 
2405  // If it's numeric, search by record ID
2406  if (is_numeric($search)) {
2407  $field = 'id';
2408  list($status, $rows, $record) = ona_get_dhcp_option_record(array($field => $search));
2409  // If we got it, return it
2410  if ($status == 0 and $rows == 1) {
2411  printmsg("DEBUG => ona_find_dhcp_option(): found type record by $field", 2);
2412  return(array(0, $rows, $record));
2413  }
2414  }
2415 
2416  foreach (array('name', 'display_name', 'number', 'tag') as $field) {
2417  // Do several sql queries and see if we can get a unique match
2418  list($status, $rows, $record) = ona_get_dhcp_option_record(array($field => $search));
2419 
2420  // If we got it, return it
2421  if ($status == 0 and $rows == 1) {
2422  printmsg("DEBUG => ona_find_dhcp_option(): Found type record -> {$record['display_name']}", 2);
2423  return(array(0, $rows, $record));
2424  }
2425  }
2426 
2427  // We didn't find it - return and error code, 0 matches, and an empty record.
2428  $self['error'] = "NOTICE => couldn't find a unique DHCP option record with specified search criteria";
2429  printmsg($self['error'], 2);
2430  return(array(2, 0, array()));
2431 }
2432 
2433 
2434 
2435 
2436 
2437 
2438 
2439 
2440 
2441 
2443 // Function: ona_find_vlan(string $vlan_search, [string $campus_search])
2444 //
2445 // Input:
2446 // $vlan_search =
2447 // A string or ID that can uniqely identify a vlan record from
2448 // the vlans table in the database. Often times a vlan
2449 // description is 'DEFAULT', in which case you can help narrow
2450 // down the search by also providing $campus_search.. see below.
2451 // $campus_search =
2452 // A string or ID that can uniqely identify a vlan campus record
2453 // from the vlan_campuses table. Often times a vlan itself can't
2454 // be identified by name without a campus name too.
2455 //
2456 // Output:
2457 // Returns a three part list:
2458 // 1. The exit status of the function (0 on success, non-zero on error)
2459 // When a non-zero exit status is returned a textual description
2460 // of the error will be stored in the global variable $self['error']
2461 // 2. The number of rows that were found - 0 or 1 (0 is returned if
2462 // a unique match couldn't be found)
2463 // 3. An array of a record from the vlans table where $search matchs.
2464 //
2465 // Example: list($status, $rows, $vlan) = ona_find_vlan('VLAN (802.1Q or ISL)');
2467 function ona_find_vlan($vlan_search="", $campus_search="") {
2468  global $self;
2469  if (!$vlan_search and !$campus_search) return(array(1, 0, array()));
2470 
2471  // If we got a vlan campus search string, let's look for that first.
2472  if ($campus_search) {
2473  $campus_search = strtoupper($campus_search);
2474  // Do a few sql queries and see if we can get a unique match
2475  $search = $campus_search;
2476  foreach (array('name', 'id') as $field) {
2477  list($status, $rows, $campus) = ona_get_vlan_campus_record(array($field => $search));
2478  if (!$status and $rows == 1) {
2479  printmsg("DEBUG => ona_find_vlan() found vlan campus record by $field", 2);
2480  break;
2481  }
2482  else
2483  $campus = array();
2484  }
2485  }
2486 
2487  // Search by a vlan number
2488  if (is_numeric($vlan_search)) {
2489  $where = array('number' => $vlan_search);
2490  } else {
2491  // Search for a vlan by NAME, use the campus[ID] if we have one
2492  $vlan_search = strtoupper($vlan_search);
2493  $where = array('name' => $vlan_search);
2494  }
2495 
2496  if ($campus['id']) $where['vlan_campus_id'] = $campus['id'];
2497  list($status, $rows, $vlan) = ona_get_vlan_record($where);
2498  if (!$status and $rows == 1) {
2499  return(array($status, $rows, $vlan));
2500  }
2501 
2502  // We didn't find it - return and error code, 0 matches, and an empty record.
2503  $self['error'] = "NOTICE => couldn't find a unique vlan record with specified search criteria";
2504  printmsg($self['error'], 1);
2505  return(array(2, 0, array()));
2506 }
2507 
2508 
2509 
2510 
2511 
2513 // Function: ona_find_config (array $search)
2514 //
2515 // Input Options:
2516 // $search = See functions below for how this function is used.
2517 // It's an internal function.
2518 //
2519 // Output:
2520 // Returns the data returned from ona_get_config_record()
2521 // Error messages are stored in global $self['error']
2522 //
2524 function ona_find_config($options=array()) {
2525 
2526  global $self;
2527 
2528  $status = 1;
2529  $rows = 0;
2530  $config = array();
2531 
2532  // If the user specified a config text ID
2533  if ($options['config']) {
2534  if (!preg_match('/^\d+$/', $options['config'])) {
2535  $self['error'] = "ERROR => A non-digit config ID was specified!";
2536  return(array(2, 0, array()));
2537  }
2538 
2539  list($status, $rows, $config) = ona_get_config_record(array('id' => $options['config']));
2540  }
2541 
2542  // Otherwise we're selecting a config by hostname and type
2543  else if ($options['host'] and $options['type']) {
2544  // Search for the host first
2545  list($status, $rows, $host) = ona_find_host($options['host']);
2546 
2547  // Error if the host doesn't exist
2548  if (!$host['id']) {
2549  $self['error'] = "ERROR => The host specified, {$options['host']}, does not exist!";
2550  return(array(3, 0, array()));
2551  }
2552 
2553  // Now find the ID of the config type they entered
2554  list($status, $rows, $config_type) = ona_get_config_type_record(array('name' => $options['type']));
2555  if (!$config_type['id']) {
2556  $self['error'] = "ERROR => The config type specified, {$options['type']}, is invalid!";
2557  return(array(4, 0, array()));
2558  }
2559 
2560  // Select the first config record of the specified type and host
2561  list($status, $rows, $config) = ona_get_config_record(array('host_id' => $host['id'],
2562  'configuration_type_id' => $config_type['id']));
2563 
2564  if ($status) {
2565  $self['error'] = "ERROR => The config type specified, {$options['type']}, is invalid!";
2566  return(array(5, 0, array()));
2567  }
2568 
2569  }
2570 
2571  // Return the config record we got
2572  return(array($status, $rows, $config));
2573 
2574 }
2575 
2576 
2577 
2578 
2579 
2580 
2581 
2582 
2583 // DON'T put whitespace at the beginning or end of this file!!!
2584 ?>
db_insert_record
db_insert_record($dbh=0, $table="", $insert="")
Definition: functions_db.inc.php:375
ona_get_host_record
ona_get_host_record($array='', $order='')
Definition: functions_db.inc.php:1106
ona_get_manufacturer_record
ona_get_manufacturer_record($array)
Definition: functions_db.inc.php:1210
ona_get_dhcp_option_record
ona_get_dhcp_option_record($array)
Definition: functions_db.inc.php:1258
ona_insert_record
ona_insert_record($table="", $insert="")
Definition: functions_db.inc.php:1017
ona_get_location_record
ona_get_location_record($array='', $order='')
Definition: functions_db.inc.php:1122
$ADODB_LANG
$ADODB_LANG
Definition: functions_db.inc.php:55
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
$rs
if(isset($_REQUEST['nrows'])) else $rs
Definition: server.php:94
ona_get_device_record
ona_get_device_record($array)
Definition: functions_db.inc.php:1218
ip_mangle
ip_mangle($ip="", $format="default")
Definition: functions_general.inc.php:308
$ADODB_FETCH_MODE
$ADODB_FETCH_MODE
Definition: functions_db.inc.php:70
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
ona_find_host
ona_find_host($search="")
Definition: functions_db.inc.php:1490
$record
$record['display_name']
Definition: app_advanced_search.inc.php:12
ona_get_vlan_campus_record
ona_get_vlan_campus_record($array)
Definition: functions_db.inc.php:1254
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
ona_delete_record
ona_delete_record($table="", $where="")
Definition: functions_db.inc.php:1041
mac_mangle
mac_mangle($input="", $format="default")
Definition: functions_general.inc.php:964
ona_find_device_type
ona_find_device_type($search="")
Definition: functions_db.inc.php:2184
ona_update_record
ona_update_record($table="", $where="", $insert="")
Definition: functions_db.inc.php:1029
ona_get_role_record
ona_get_role_record($array)
Definition: functions_db.inc.php:1222
ona_find_dhcp_option
ona_find_dhcp_option($search="")
Definition: functions_db.inc.php:2397
ona_get_block_record
ona_get_block_record($array='', $order='')
Definition: functions_db.inc.php:1118
ona_get_device_type_record
ona_get_device_type_record($array)
Definition: functions_db.inc.php:1214
db_pconnect
db_pconnect($type, $context_name)
Definition: functions_db.inc.php:90
db_delete_records
db_delete_records($dbh=0, $table="", $where="")
Definition: functions_db.inc.php:582
ona_get_dns_view_record
ona_get_dns_view_record($array='', $order='')
Definition: functions_db.inc.php:1156
ona_get_model_record
ona_get_model_record($array)
Definition: functions_db.inc.php:1197
printmsg
if(6<=$conf['debug']) printmsg($msg="", $debugLevel=0)
Definition: functions_general.inc.php:48
$ADODB_CACHE_DIR
$ADODB_CACHE_DIR
Definition: functions_db.inc.php:45
ona_find_interface
ona_find_interface($search="")
Definition: functions_db.inc.php:1910
ona_find_location
ona_find_location($search="")
Definition: functions_db.inc.php:1810
ona_find_config
ona_find_config($options=array())
Definition: functions_db.inc.php:2524
ona_get_custom_attribute_record
ona_get_custom_attribute_record($array)
Definition: functions_db.inc.php:1183
$type
$type
Definition: dcm.php:17
$host
$host
Definition: collate-convert.php:19
ona_find_subnet_type
ona_find_subnet_type($search="")
Definition: functions_db.inc.php:2263
db_update_record
db_update_record($dbh=0, $table="", $where="", $insert="")
Definition: functions_db.inc.php:474
ona_get_dhcp_pool_record
ona_get_dhcp_pool_record($array)
Definition: functions_db.inc.php:1276
ona_find_device
ona_find_device($search="")
Definition: functions_db.inc.php:2105
ona_get_vlan_record
ona_get_vlan_record($array)
Definition: functions_db.inc.php:1241
ona_get_dns_server_domain_record
ona_get_dns_server_domain_record($array)
Definition: functions_db.inc.php:1284
$conf
global $conf
Definition: 2-to-3.php:15
$ip
$ip
Definition: main.inc.php:24
ona_get_subnet_type_record
ona_get_subnet_type_record($array)
Definition: functions_db.inc.php:1237
ona_get_domain_record
ona_get_domain_record($array='', $order='')
Definition: functions_db.inc.php:1134
$ADODB_ANSI_PADDING_OFF
$ADODB_ANSI_PADDING_OFF
Definition: functions_db.inc.php:50
ona_find_dns_record
ona_find_dns_record($search="", $type='', $int_id=0)
Definition: functions_db.inc.php:1703
ona_find_custom_attribute
ona_find_custom_attribute($search="")
Definition: functions_db.inc.php:2325
$ADODB_COUNTRECS
$ADODB_COUNTRECS
Definition: functions_db.inc.php:34
ona_get_record
ona_get_record($where="", $table="", $order="")
Definition: functions_db.inc.php:1053
$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
db_get_record
db_get_record($dbh=0, $table="", $where="", $order="")
Definition: functions_db.inc.php:708
ona_get_custom_attribute_type_record
ona_get_custom_attribute_type_record($array)
Definition: functions_db.inc.php:1179
ona_get_dhcp_failover_group_record
ona_get_dhcp_failover_group_record($array)
Definition: functions_db.inc.php:1175
ona_get_config_type_record
ona_get_config_type_record($array='', $order='')
Definition: functions_db.inc.php:1171
$base
$base
Definition: 2-to-3.php:8
ona_get_config_record
ona_get_config_record($array='', $order='ctime DESC')
Definition: functions_db.inc.php:1160
$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
ona_get_dhcp_option_entry_record
ona_get_dhcp_option_entry_record($array)
Definition: functions_db.inc.php:1262
ona_find_vlan
ona_find_vlan($vlan_search="", $campus_search="")
Definition: functions_db.inc.php:2467
ona_build_domain_name
ona_build_domain_name($search='')
Definition: functions_db.inc.php:1433
ona_get_dns_record
ona_get_dns_record($array='', $order='')
Definition: functions_db.inc.php:1142