Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

MASS DNS zone updater

Discussion in 'Workarounds and Optimization' started by simonas, May 10, 2013.

  1. simonas

    simonas Well-Known Member

    Apr 21, 2013
    Likes Received:
    Trophy Points:
    cPanel Access Level:
    Root Administrator

    I wanted to better organize my DNS zones, so i wrote basic program in PHP (i feel relaxed with it and letting run perl script as root could mess up original zones), which will rewrite your .db files.

    It's a tested program, but use at your own risk, always make backups!!!

    I will keep it updated, and will accept new feature requests.

    To use:
    copy all .db files from /var/named to some folder
    Create folder where you will store new zones, make it writable if on *nix
    Update variables in the script to suit your needs, change folders
    Run the script
    Check if zone files are ok, not corrupted
    Upload new zone files to /var/named/
    Do service named restart
    If it fails do named-checkconf -z /etc/named.conf
    to see which zones are bad.

    USE at your own risk!
    By default program will delete mail autodiscover / autoconfig entries, disable them in tweak settings first
    Also it will delete ftp and mail subdomains by default.

     *     Mass DNS zone update program

    // If you already changed some zones today, please increase it, keep it with leading zero!
    $revision '01';

    // Time to live, used on every record, change as you see fit
    $TTL 1800;
    // SOA serial number - consists of todays date and revision number, change as you see fit
    $SOA_serial date('Ymd') . $revision;
    // SOA refresh time, change as you see fit
    $SOA_refresh 3600;
    // SOA retry, change as you see fit
    $SOA_retry 1800;
    // SOA expire, change as you see fit
    $SOA_expire 604800;
    // Array records to remove, first words only. Lines starting with following words will be removed!
    $remove = array('mail','ftp','webdisk','autoconfig','autodiscover','_autodiscover._tcp');

    // Where you store your zone files
    $zones 'C:/Serveris/zones'// No trailing /
    // Where to write new zone files
    $write_to 'C:/Serveris/new'// No trailing /

    $files scandir($zones);

    $files as $filename) {
    $filename != '.' && $filename != '..') {
    $contents file($zones "/$filename"FILE_SKIP_EMPTY_LINES FILE_IGNORE_NEW_LINES);
    $contents as $nr => $line) {
    $line trim($line);

    $words explode("\t"$line);
    in_array($words[0], $remove)) {
    strpos($line'$TTL') === 0) {
    $contents[$nr] = '$TTL' "\t$TTL";
    preg_match("/IN\s+SOA/"$line)) {
    $contents[$nr] = preg_replace('/\d+\s+IN\s+SOA/'$TTL "\tIN\tSOA"$line);
    preg_match("/;\s*serial/i"$line)) {
    $contents[$nr] = "\t\t\t\t\t\t$SOA_serial\t; Serial Number";
    preg_match("/;\s*refresh/"$line)) {
    $contents[$nr] = "\t\t\t\t\t\t$SOA_refresh\t\t; refresh, seconds";
    preg_match("/;\s*retry/"$line)) {
    $contents[$nr] = "\t\t\t\t\t\t$SOA_retry\t\t; retry, seconds";
    preg_match("/;\s*expire/"$line)) {
    $contents[$nr] = "\t\t\t\t\t\t$SOA_expire\t\t; expire, seconds";
    preg_match("/\d+\s+\)/"$line)) {
    $contents[$nr] = "\t\t\t\t\t\t$TTL )\t\t; minimum, seconds";
    preg_match("/\d+\s+IN\s/"$line)) {
    $contents[$nr] = preg_replace("/\d+\s+IN\s+/"$TTL "\tIN "$line);
    file_put_contents($write_to "/$filename"implode("\n"$contents));
    "$filename updated<br>";
    2013-05-11 Updated: Couple fixes.
    #1 simonas, May 10, 2013
    Last edited: May 11, 2013

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice