Hi all, I am looking for a script that will trigger the resync tool for the DNS zone files only, this would also increase the serial as well. Because of the unique way we have to update the A records in the database, the firmware on our equipment is limited, we are unable to use the built in API to update the A records in the DB. I have a script where we are able to update the DB with ease but obviously need to have the zone files updated as well. A simple php script to do a resync of the DNS zone files should suffice for this. TIA.
You can refer to mine here: https://github.com/ahrasis/IP_Updater/blob/master/ip_updater.php Though it is clearly mentioned in it, if you are not sure how and which part, you may ask further.
Thank you Ahrasis. I will. This is what I have so far, similar to yours. I can run the script fine, no errors however it is not updating the Zone File. Sooo, where have I stuffed up? PHP: <?phprequire_once('/usr/local/ispconfig/interface/lib/config.inc.php');require_once('/usr/local/ispconfig/interface/lib/app.inc.php');//* Resyncing dns zonesif(isset($_POST['resync_dns']) && $_POST['resync_dns'] == 1) { $zones = $app->db->queryAllRecords("SELECT id,origin,serial FROM dns_soa WHERE active = 'Y'"); if(is_array($zones) && !empty($zones)) { foreach($zones as $zone) { $records = $app->db->queryAllRecords("SELECT id,serial FROM dns_rr WHERE zone = ".$zone['id']." AND active = 'Y'"); if(is_array($records)) { foreach($records as $rec) { $new_serial = $app->validate_dns->increase_serial($rec["serial"]); $app->db->datalogUpdate('dns_rr', "serial = '".$new_serial."'", 'id', $rec['id']); } } $new_serial = $app->validate_dns->increase_serial($zone["serial"]); $app->db->datalogUpdate('dns_soa', "serial = '".$new_serial."'", 'id', $zone['id']); $msg .= "Zone Files Successfully Updated: ".$zone['origin'].'<br />'; } } else { $error .= "No zones found to sync.<br />"; } }?>
I think it is because you do not connect to mysql in your script after requiring config.inc.php. You should close it too when you are done.
Updated and still no change. PHP: <?phprequire_once('/usr/local/ispconfig/interface/lib/config.inc.php');require_once('/usr/local/ispconfig/interface/lib/app.inc.php');$dns_resync = mysqli_connect($conf['db_host'], $conf['db_user'], $conf['db_password'], $conf['db_database']);if (mysqli_connect_errno()) { printf("\r\nConnection to ISPConfig database failed!\r\n", mysqli_connect_error()); exit();}//* Resyncing dns zonesif(isset($_POST['resync_dns']) && $_POST['resync_dns'] == 1) { $zones = $app->db->queryAllRecords("SELECT id,origin,serial FROM dns_soa WHERE active = 'Y'"); if(is_array($zones) && !empty($zones)) { foreach($zones as $zone) { $records = $app->db->queryAllRecords("SELECT id,serial FROM dns_rr WHERE zone = ".$zone['id']." AND active = 'Y'"); if(is_array($records)) { foreach($records as $rec) { $new_serial = $app->validate_dns->increase_serial($rec["serial"]); $app->db->datalogUpdate('dns_rr', "serial = '".$new_serial."'", 'id', $rec['id']); } } $new_serial = $app->validate_dns->increase_serial($zone["serial"]); $app->db->datalogUpdate('dns_soa', "serial = '".$new_serial."'", 'id', $zone['id']); $msg .= "Resynced DNS zone: ".$zone['origin'].'<br />'; } } else { $error .= "No zones found to sync.<br />"; } }mysqli_close($dns_resync);?>
I guess you are trying to run the script remotely but it is meant to be run from within the server, thus, I am not sure if you can update dns record using it. May be you need to use the ISPConfig API instead. Anyway, if you remove the condition below and run it from terminal, the script should work just fine. Code: if(isset($_POST['resync_dns']) && $_POST['resync_dns'] == 1) {} Thus, try to remove it and test it remotely if it could work there as well.
Actually it looks like I was just impatient, appears to be working fine now. I'll just do up a cronjob and Dynamic DNS Server is running.