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)  

2-to-3.php
Go to the documentation of this file.
1 <?php
2 //
3 // This script is to be used when upgrading from version 08.05.14.
4 // It will help to create proper PTR zones for the subnets and DNS records you have
5 //
6 //
7 /* -------------------- COMMON HEADER ---------------------- */
8 $base = dirname(__FILE__)."/../www/";
9 while ($base and (!is_dir($base.'/include'))) $base = preg_replace('+/[^/]*$+', '', $base);
10 $include = $base . '/include';
11 if (!is_dir($include)) { print "ERROR => Couldn't find include folder {$include}!\n"; exit; }
12 require_once($base . '/config/config.inc.php');
13 /* --------------------------------------------------------- */
14 
15 global $conf, $self, $onadb;
16 
17 // Uncomment the following to get a ton o' debug
18 //$conf['debug'] = 6;
19 
20 // Get the PTR records that dont have a domain_id
21 list($status, $rows, $ptrs) = db_get_records($onadb, 'dns', "domain_id = 0 and type like 'PTR'", '');
22 echo "Found {$rows} PTR records with no domain.\n";
23 if (!$rows) echo " Everything looks OK!\n";
24 
25 foreach ($ptrs as $ptr) {
26  list($status, $rows, $interface) = ona_get_interface_record(array('id' => $ptr['interface_id']));
27 
28  // Print an error if it doesnt find an IP
29  if (!$interface['ip_addr']) {
30  echo "Possible orphan PTR record in dns table at ID: {$ptr['id']}. You should delete this record manually.\n";
31  continue;
32  }
33 
34  $ipflip = ip_mangle($interface['ip_addr'],'flip');
35  $octets = explode(".",$ipflip);
36  // Find a pointer domain for this record to associate with.
37  list($status, $rows, $ptrdomain) = ona_find_domain($ipflip.".in-addr.arpa",0);
38 
39  // CRAPPY security cludge
40  $_SESSION['ona']['auth']['user']['username'] = 'PTRFIX';
41  $_SESSION['ona']['auth']['perms']['advanced'] = 'Y';
42  $_SESSION['ona']['auth']['perms']['host_modify'] = 'Y';
43 
44  if (!$ptrdomain['id']) {
45  echo " {$interface['ip_addr_text']}: Unable to find a pointer domain for this IP! Creating the following DNS domain: {$octets[3]}.in-addr.arpa\n";
46  list($status, $output) = run_module('domain_add', array('name' => $octets[3].'.in-addr.arpa'));
47  if ($status) {
48  echo "ERROR => {$output}\n";
49  exit($status);
50  }
51  list($status, $rows, $ptrdomain) = ona_find_domain($ipflip.".in-addr.arpa",0);
52  }
53 
54  // Found a domain to put them in.
55  echo " Updating PTR for IP {$interface['ip_addr_text']} to domain {$ptrdomain['fqdn']}\n";
56 
57  // Change the actual DNS record
58  list($status, $rows) = db_update_record($onadb, 'dns', array('id' => $ptr['id']), array('domain_id' => $ptrdomain['id']));
59  if ($status or !$rows) {
60  echo "ERROR => SQL Query failed updating dns record: " . $self['error'];
61  exit(2);
62  }
63 
64 
65 }
66 
67 exit(0);
68 
69 ?>
ona_find_domain
ona_find_domain($fqdn="", $returndefault=0)
Definition: functions_db.inc.php:1609
ip_mangle
ip_mangle($ip="", $format="default")
Definition: functions_general.inc.php:308
ona_get_interface_record
ona_get_interface_record($array='', $order='')
Definition: functions_db.inc.php:1126
exit
exit
Definition: config.inc.php:186
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
$include
$include
Definition: 2-to-3.php:10
db_update_record
db_update_record($dbh=0, $table="", $where="", $insert="")
Definition: functions_db.inc.php:474
run_module
run_module($module='', $options='', $transaction=1)
Definition: functions_general.inc.php:1468
$_SESSION
$_SESSION['ona']['auth']
Definition: login.php:14
$conf
global $conf
Definition: 2-to-3.php:15
$output
$output
Definition: dcm.php:16
$self
global $self
Definition: 2-to-3.php:15
$base
$base
Definition: 2-to-3.php:8