Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > ISPConfig 2 > Tips/Tricks/Mods

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 11th October 2005, 02:27
cstone cstone is offline
Junior Member
 
Join Date: Sep 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Post Adding domains to non-ISPConfig secondary DNS servers

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
Reply With Quote
Sponsored Links
  #2  
Old 2nd March 2006, 05:07
Switched Switched is offline
Junior Member
 
Join Date: Mar 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
Reply With Quote
  #3  
Old 2nd March 2006, 10:10
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,743 Times in 2,577 Posts
Default

Quote:
Originally Posted by Switched
Nice work!

May I suggest a small improvement?

In your dupcheck function you use this

chop($dupcheck = `grep -ic $domain /var/named/named.conf`);
In which file is it used?
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #4  
Old 18th July 2006, 23:57
Trey Hacker Trey Hacker is offline
Junior Member
 
Join Date: Jul 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
Reply With Quote
  #5  
Old 19th July 2006, 14:25
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,743 Times in 2,577 Posts
 
Default

Quote:
Originally Posted by Trey Hacker
By sub-domains I mean jimmy.forget.com rather than www.forget.com/jimmy.
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
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding sub domain to secondary dns jernis Installation/Configuration 3 22nd September 2005 18:03
Apache not adding domains adamluz Server Operation 3 16th August 2005 20:20


All times are GMT +2. The time now is 17:31.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.