#!/usr/bin/perl # Somethings to set: #Primary zone directory /var/named/pz $pz = "/var/named/pz"; #Secondary zone directory /var/named/sz $sz = "/var/named/sz"; #Version $version = "1.0"; #root Check @pwent=getpwuid($<); if ($pwent[0] ne "root") { die "\nYou have to run this program as root, aborted"; } system("clear"); print "\e[7m Jims Domain Zone Adder ver $version \e[0m\n\n\n"; print "\nDomain Name: "; chomp($domain = ); if ($domain eq "") { print "Invalid information\n"; exit }; if ($domain eq " ") { print "Invalid information\n"; exit }; 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"; open(ZONE, ">>$pz/db.$domain"); 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 A $pmx.\n"; print ZONE "mail IN A $pmx.\n"; close(ZONE); system ("clear"); print "Now lets see about that reverse zone\n"; print "\nWhat are the last three digits of the IP Address: "; chomp($subn = ); if ($subn eq "") { print "Invalid information\n"; exit }; if ($subn eq " ") { print "Invalid information\n"; exit }; 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";