Adding domains to non-ISPConfig secondary DNS servers

Discussion in 'Tips/Tricks/Mods' started by cstone, Oct 11, 2005.

  1. cstone

    cstone New Member

    I had a need to add slave zone information to non-ISPConfig secondary bind name servers. For those that need to do this also, thought I'd post my patch and script here for everyone.

    First, you need to setup an ssh login from the ISPConfig server to your secondary DNS server such that an ssh login is done by a key rather than using a password. I also have this set between the 'primary' secondary server (the one the ISPConfig 'talks' to) and my other 2 secondary servers.

    Then, for the ispconfig_bind.lib.php file here's my patch:

    --- ispconfig_bind.lib.php.orig 2005-10-10 14:17:06.661812492 -0600
    +++ ispconfig_bind.lib.php 2005-10-09 19:43:38.139079442 -0600
    @@ -169,6 +169,9 @@
    $new_serial = date("Ymd")."01";
    }

    + // set domain name for use to setup secondary
    + $domain_name = $dns["dns_soa"];
    +
    // Variablen zuweisen
    $mod->tpl->assign( array('DNS_SOA' => $dns["dns_soa"],
    'DNS_ADMINMAIL' => str_replace("@", ".", $dns["dns_adminmail"]),
    @@ -296,6 +299,10 @@

    $server = $mod->system->server_conf;

    + // setup domain on secondaries
    + error_log(date("Y-m-d H:i:s")." Adding $domain_name to secondary server ns1.axint.net\n",3,"/var/tmp/ispconfig.log");
    + exec("ssh root@ns1.axint.net /root/scripts/webcp/add-dns-webcp.pl $domain_name");
    +
    $server_bind_user = $server["server_bind_user"];
    $server_bind_group = $server["server_bind_group"];
    exec("chown $server_bind_user:$server_bind_group $bind_file &> /dev/null");


    On the secondary, in /root/scripts/webcp directory I have the following script for add-dns-webcp.pl - note too that this script also updates 2 other secondary servers with the new domain also):

    =====================================
    #!/usr/bin/perl

    #############################
    # Check for Correct Input #
    #############################

    if (!$ARGV[0]) {
    chop ($timestamp = `/bin/date`);
    $error = "Failed user input check. Valid arguments (domain name) not passed to script!";
    $combine = $timestamp . " - " . $error;
    writelog ($combine);
    exit 0;
    }

    #############################
    # Define Needed Variables #
    #############################

    my $domain = $ARGV[0];
    my $filename = $domain . ".dns";
    my $savefilename = $filename . ".old";

    ####################################
    # Check if Domain Already Exists #
    ####################################

    dupcheck();

    sub dupcheck {
    chop($dupcheck = `grep -ic $domain /var/named/named.conf`);

    if ($dupcheck >= 1) {
    chop ($timestamp = `/bin/date`);
    $error = "Failed dupcheck. Domain, $domain, already exists in /var/named/named.conf!";
    $combine = $timestamp . " - " . $error;
    writelog ($combine);
    # refresh since apparently the 'duped' domain has been updated on master
    system("/usr/sbin/rndc reload");
    exit 0;
    }
    }

    #######################################
    # Add New Domain Name to named.conf #
    #######################################

    open(NAMEDFILE, ">>/var/named/named.conf") or die("\n");

    print NAMEDFILE <<EOF;

    zone "$domain" {
    type slave;
    file "slaves/$filename";
    masters {
    38.116.133.20;
    };
    };

    EOF

    close(NAMEDFILE);

    ###################################
    # Write confirmation to logfile #
    ###################################

    chop ($timestamp = `/bin/date`);
    open(LOG, ">>/var/log/dns-scripts.log") or die "failed on temp file open";
    print LOG ("$timestamp - $domain successfully added to /var/named/named.conf.\n");
    close(LOG);

    ###################
    # Reload Namedb #
    ###################

    system("/usr/sbin/rndc reload");

    #############################################
    # Add New Domain to Secondary Name Servers #
    #############################################

    system("/usr/bin/ssh -b 38.116.133.2 root\@ns2.axint.net /root/scripts/dns/add-dns-webcp.pl $domain $filename");
    system("/usr/bin/ssh -b 38.116.133.2 root\@ns3.axint.net /root/scripts/dns/add-dns-webcp.pl $domain $filename");

    exit 0;

    ##############################
    # Write logfile Subroutine #
    ##############################

    sub writelog {

    open(LOG, ">>/var/log/dns-scripts.log") or die "failed on temp file open";
    print LOG ("@_\n");
    close(LOG);

    };

    exit 0;
    =====================================

    All works quite well - YMMV.


    Chris
     
  2. Switched

    Switched New Member

    Nice work!

    May I suggest a small improvement?

    In your dupcheck function you use this

    chop($dupcheck = `grep -ic $domain /var/named/named.conf`);

    The problem with that is it matches too much. For example, as a webhost I find my users will often get their country specific domain, and the .com. So, if they start with foobar.com.au and later add foobar.com, your test will fail when it really shouldn't.

    Looking at the structure of a secondary zone entry, we should be able to match the first line uniquely.

    ie.

    Code:
    zone "foobar.com.au" {
            type slave;
            file "/path/to/zones/db.foobar.com.au";
            masters { www.xxx.yyy.zzz; };
    };
    should make

    chop($dupcheck = `grep -ic "zone \"$domain\" {" /var/named/named.conf`);

    Cheers! And thanks again for posting all of that. :)
     
  3. falko

    falko Super Moderator Howtoforge Staff Moderator HowtoForge Supporter ISPConfig Developer

    In which file is it used?
     
  4. Trey Hacker

    Trey Hacker New Member

    Qusetion on sub domains

    Question on sub domains. Is the type of script I would need to setup sub domains in an automated fashion. By sub-domains I mean jimmy.forget.com rather than www.forget.com/jimmy.

    I’m new to this side and can’t find a script to set these up automatically with a self replicating web site.

    Any help would be appreciated.


    Thank You,

    Trey Hacker
     
  5. falko

    falko Super Moderator Howtoforge Staff Moderator HowtoForge Supporter ISPConfig Developer

    If your ISPConfig server is authoritative for the forget.com domain, then you must set up the subdomain in ISPConfig's DNS Manager, otherwise on the name server that is authoritative for your domain. You can find out about the authoritative name servers with this command:
    Code:
    dig ns forget.com
     

Share This Page