Resync DNS records by script?

Discussion in 'General' started by FFH, Apr 5, 2018.

  1. FFH

    FFH Member

    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.
     
  2. ahrasis

    ahrasis Active Member

  3. FFH

    FFH Member

    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:
    <?php

    require_once('/usr/local/ispconfig/interface/lib/config.inc.php');
    require_once(
    '/usr/local/ispconfig/interface/lib/app.inc.php');

    //* Resyncing dns zones
    if(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 />";
        }
        
    }

    ?>
     
  4. ahrasis

    ahrasis Active Member

    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.
     
  5. FFH

    FFH Member

    Updated and still no change.

    PHP:
    <?php

    require_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 zones
    if(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);
    ?>
     
  6. ahrasis

    ahrasis Active Member

    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.
     
    Last edited: Apr 6, 2018
  7. FFH

    FFH Member

    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. :)
     
    Last edited: Apr 6, 2018
    ahrasis likes this.
  8. ahrasis

    ahrasis Active Member

    Glad to hear that.
     
  9. FFH

    FFH Member

    Thank you for your help. :)
     
    ahrasis likes this.

Share This Page