[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cobalt-users] Perl script to move DNS domains to a cobalt server
- Subject: [cobalt-users] Perl script to move DNS domains to a cobalt server
- From: Jeff Sauricki <jsauricki@xxxxxxxx>
- Date: Tue Aug 8 15:09:50 2000
I had to move 80 domains from an NT based DNS server to a Cobalt RaQ3. Here
is the script I used if anyone wants to use it.
#!d:\perl\bin
# mkdns.pl Create the records file for a Cobalt RaQ3 from a zone file
#js @dpai 08/04/00
#Rev. 1.1
#input file passed as 1st command line argument
#output appended to records
#errors written to mkdns_er.txt
#status written to mkdns_st.txt
# zone name passed as 2nd command line argument
#SOA info
$SOAdomain = "";
$SOAns = "";
$SOAemail = "";
$SOAserial = "1"; #Not used, replaced by Cobalt CGI script on Save
$SOArefresh = "3600"; # 3 hours
$SOAretry = "600"; # 10 min.
$SOAexpire = "864000"; #10 days
$SOAttl = "3600"; #3 hours
#NS info
$NShost = "";
#host info
$Ahost = "";
$Aip = "";
#MX info
$MXperfer = "Low";
$MXhost = "";
$linecnt = 0;
$soacnt = 0;
$nscnt = 0;
$hostcnt = 0;
$mxcnt = 0;
#record type
$rectyp = "";
$comment = 1;
$soa = 2;
$ns = 3;
$mx = 4;
$host = 5;
$unknown = 6;
$pos = 0;
$linecnt = 0;
#Open output file
if ($ARGV[1] eq ""){
print ("Usage:\n");
print ("MKDNS.PL will use a DNS zone file to create the records file used
by\n");
print ("the Cobalt DNS GUI to manage the Cobalt DNS server.\n\n");
print ("You can use a NT or BIND zone file or even pull one from \n");
print ("a DNS server using nslookup or dig.\n\n");
print ("MKDNS.PL takes two arguments; zone_file and domain_name\n");
print ("Example: PERL MKDNS.PL microsoft.com.dns microsoft.com\n\n");
print ("The output is appended to a file named RECORDS.\n");
print ("You must manually copy RECORDS to the Cobalt server
\\etc\\named\\ directory.\n");
print ("You can then open the DNS GUI and click Save to create the\n");
print ("zone files. Errors are saved to the file MKDNS_ER.TXT.\n");
print ("Run time status is saved to the MKDNS_ST.TX file\n\n");
print ("NOTE: SOA times are hard coded and are NOT read from the zone
file!\n");
die ("\n");
}else {
$SOAdomain = $ARGV[1];
}
open(file_out,">>records");
open(file_err,">>mkdns_er.txt");
open(file_stat,">>mkdns_st.txt");
#open input file
if (open(file_in,$ARGV[0])){
$input = <file_in>;
while ($input ne "") {
$linecnt += 1;
@in = ("");
$line = '';
$rectyp = $unknown;
$out[$print] = $true;
#strip white space
$input =~ s/^\s+//; #before
$input =~ s/\s+$//; #after
# remove extra spaces,tabs,cr,lf
$input =~ s/\s+/ /g;
$pos = index ($input,";");
if ($pos >= 0){
$line = substr($input,0,$pos);
} else{
$line = $input;
}
if (length($line) eq 0){
$input = <file_in>;
next
}
if ($line =~ / ns /i ){
$rectype =$ns;
&do_ns;
}
if ($line =~ / mx /i){
$rectype =$mx;
&do_mx;
}
if ($line =~ / a /i){
$rectype =$host;
&do_host;
}
if ($line =~ / in /i and $line =~ / soa /i){
$rectype =$soa;
&do_soa;
}
if ( $rectype eq $unknown){
#print file_err ("$line\n");
}
$input = <file_in>;
}
close(file_in);
&print_soa;
}
else {
die "Couldn't open input file $ARGV[0]\n";
}
close(file_out);
close(file_err);
&Status;
close(file_stat);
#**********************************************************************
sub do_soa {
$soacnt += 1;
@in = split (/ +/,$line);
if ($in[0] eq "@"and $in[1] eq "IN" and $in[2] eq "SOA"){
$SOAns = $in[3];
$SOAns =~ s/\.$//;
$SOAemail = $in[4];
$SOAemail =~ s/\./@/;
$SOAemail =~ s/\.$//;
}
}
sub print_soa {
print file_out ("soa - $SOAdomain
$SOAns:$NShost:$SOAemail:$SOArefresh:$SOAretry:$SOAexpire:$SOAttl -\n");
}
sub do_ns {
$nscnt += 1;
@in = split (/ +/,$line);
if ($in[0] eq "@"){
$NShost = $in[2];
$NShost =~ s/\.$//;
if ($NShost eq $SOAns){
$NShost = "";
}
}
}
sub do_host {
$hostcnt += 1;
@in = split (/ +/,$line);
if ($in[0] eq "@"){
$Ahost = "-";
}else{
$Ahost = $in[0];
# strip off trailing period
$Ahost =~ s/\.$//;
}
$Aip = $in[2];
print file_out ("a $Ahost $SOAdomain $Aip 24\n");
}
sub do_mx {
$mxcnt += 1;
@in = split (/ +/,$line);
$MXhost = $in[3];
# strip off trailing period
$MXhost =~ s/\.$//;
print file_out ("mx - $SOAdomain Low $MXhost\n");
}
sub Status{
print ("Records processed from file $ARGV[0] for zone $SOAdomain\n");
print ("State of Authority = $soacnt\n");
print ("Hosts = $hostcnt\n");
print ("Name Servers = $nscnt\n");
print ("Mail Exchangers = $mxcnt\n");
print ("Total lines parsed = $linecnt\n\n");
print file_stat ("Records processed from file $ARGV[0] for zone
$SOAdomain\n");
print file_stat ("State of Authority = $soacnt\n");
print file_stat ("Hosts = $hostcnt\n");
print file_stat ("Name Servers = $nscnt\n");
print file_stat ("Mail Exchangers = $mxcnt\n");
print file_stat ("Total lines parsed = $linecnt\n\n");
}