#!/usr/bin/perl # This script will add a basic zone file and place and entry in /etc/named.conf # The zone file it creates is rather bare so you may want to go back and edit it # before restarting named. This version is for 8.2 or 8.1 you must put the # version below because of the new TTL entry before the SOA 8.2 requires. # Questions Comments Concerns email me at admin@thealamo.net # # Strange things that need to be changed when I have time: # # This will use the first NS entry you place in it in the SOA and will also # place that entry as a NS for the zone. Should make it ask for this # information. (next release) # # It does not increase the revers zone serial number you have to do that # by hand before you restart named after adding a zone. # # It askes for a primary mail server this is simply for the cname entries later # in the file for mail and smtp. You have to enter it again for the MX entries. # Its hard to handle stuff like this since there are so many different ways # people setup zones. # Somethings you need to set/change: #Primary zone directory /var/named/pz $pz = "/var/named/pz"; #Secondary zone directory /var/named/sz $sz = "/var/named/sz"; #Bind version either 8.1 or 8.2 $bind = "8.2"; #############Thats it for setting things no need to go further unless you ##### #############Just want to mod it up for yourself. #Version $version = "1.2"; #root Check @pwent=getpwuid($<); if ($pwent[0] ne "root") { print "\nYou have to run this program as root, aborted\n"; sleep 2; exit; } system("clear"); START: print "\e[7m Jims Domain Zone Adder ver $version \e[0m\n\n\n"; print "\nDomain Name: "; chomp($domain = ); open(CONFFILE, "/etc/named.conf"); while() { if($_ =~ /$domain/) { $checkdomain="EXISTS"; } } close(CONFFILE); if ($checkdomain eq "EXISTS") { print "\n$domain already exists!\n\n"; exit; } if ($domain eq "") { print "\nTry typing something next time...\n\n"; sleep 2; goto START; } print "\nIP Address: "; chomp($ip = ); if ($ip eq "") { print "Invalid information\n"; exit }; if ($ip eq " ") { print "Invalid information\n"; exit }; print "\nReverse Zone file Name: "; chomp($rv = ); if ($rv eq "") { print "Invalid information\n"; exit }; if ($rv eq " ") { print "Invalid information\n"; exit }; print "Lets get some SOA information now...\n"; $c=-1; chomp; do { print "\nEnter Name Servers example: ns1.com Enter a blank when done\n"; $c++; lc(chomp($ns[$c] = )); } while ($ns[$c] ne ""); print "Enter the Primary Mail Server for this domain;\n"; chomp($pmx = ); if ($pmx eq "") { print "Invalid information\n"; exit }; if ($pmx eq " ") { print "Invalid information\n"; exit }; $c=-1; chomp; do { print "\nMail Servers including the one you entered above\nexample: 5 mail.com don't forget to increament\nthe priority number. Enter a blank when done\n"; $c++; lc(chomp($mx[$c] = )); } while ($mx[$c] ne ""); $domain = lc($domain); $ip = lc($ip); $rv = lc($rv); $pmx = lc($pmx); $clear = "\n"; system ("clear"); print $clear; print "Domain Name : $domain\n\n"; print "The Zone to create : $pz/db.$domain\n\n"; print "IP : $ip\n\n"; print "Reverse zone location : $rv\n\n"; for($c=0; $c<$#ns; $c++) { print "Name Servers : $ns[$c]\n\n"; } for($c=0; $c<$#mx; $c++) { print "Mail Exchangers : $mx[$c]\n\n"; } print "*NOTICE* All inputs are forced to lowercase.\n\n"; print "Please confirm, is this information correct?\n\n"; print "Enter this information into the server? [y/n] : "; chomp($cor = ); $cor = lc($cor); if ($cor ne "y") { print "Aborting...\n" ; exit }; print "Adding Data into named.conf file\n"; open(DATA, ">>/etc/named.conf"); print DATA "\nzone \"$domain\" {\n"; print DATA " type master;\n"; print DATA " file \"pz/db.$domain\";\n"; print DATA "};\n"; close(DATA); system ("clear"); sleep 3; sub date_serial { local $now = time(); local @tm = localtime($now); return sprintf "%4.4d%2.2d%2.2d", $tm[5]+1900, $tm[4]+1, $tm[3]; } print "Creating Zone File\n"; $serial = &date_serial()."01"; #$TTL = "\$TTL\"; open(ZONE, ">>$pz/db.$domain"); if ($bind eq "8.2") { print ZONE "\$\TTL 864000 @ IN SOA $ns[0]. root.$domain. (\n"; } else { print ZONE "@ IN SOA $ns[0]. root.$domain. (\n"; } print ZONE " $serial\n"; print ZONE " 8M\n"; print ZONE " 2M\n"; print ZONE " 1W\n"; print ZONE " 1D )\n"; for($c=0; $c<$#ns; $c++) { print ZONE " IN NS $ns[$c].\n"; } for($c=0; $c<$#mx; $c++) { print ZONE " IN MX $mx[$c].\n"; } print ZONE "localhost IN A 127.0.0.1\n"; print ZONE "$domain. IN A $ip\n"; print ZONE "www IN A $ip\n"; print ZONE "ftp IN A $ip\n"; print ZONE "smpt IN CNAME $pmx.\n"; print ZONE "mail IN CNAME $pmx.\n"; close(ZONE); system ("clear"); print "Now lets see about that reverse zone\n"; print "Would you like me to try and add the entery into the reverse zone [y/n]?\n"; chomp($ans = ); if ($ans eq "n") { print "\nOk thanks for trying the program!!!\n"; sleep 1; exit; } else { PSTART: print "\nWhat are the last three digits of the IP Address: "; chomp($subn = ); open(PTR, "$pz/$rv"); while() { if($_ =~ /$subn/) { $checkptr="EXISTS"; } } close(PTR); if ($checkptr eq "EXISTS") { print "\n$subn already exists!\n\n"; exit; } if ($subn eq "") { print "\nTry typing something next time...\n\n"; sleep 2; goto PSTART; } print "How do you want this to reverse example www.$domain ?\n"; chomp($ren = ); if ($ren eq "") { print "Invalid information\n"; exit }; if ($ren eq " ") { print "Invalid information\n"; exit }; $subn = lc($subn); $ren = lc($ren); print "\nCreating a PTR entry in $pz/$rv for $subn pointing to $ren\n"; open(REV, ">>$pz/$rv"); print REV "$subn PTR $ren.\n"; close(REV); print "\nDone"; }