User Tools

Site Tools


dns_add_script

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
dns_add_script [2009/08/17 21:11] jtdns_add_script [2009/08/18 21:55] jt
Line 7: Line 7:
 use IO::File; use IO::File;
 use Text::Template; use Text::Template;
 +use File::Grep qw( fgrep );
  
-my $repository = "/home/jthomas/dns/master/";+ 
 +my $repository = "/home/jthomas/projects/dns/master/";
 my $dnsData = "data"; my $dnsData = "data";
  
Line 20: Line 22:
  chomp ($entry);  chomp ($entry);
  my ($hostName, $ipAddress) = split(' ', $entry);  my ($hostName, $ipAddress) = split(' ', $entry);
 +## if (  !defined($ipAddress) ) {print "$hostName has no IP Address\n"; exit 0;}
  my ($domainName, $subDomain) = findDomainName($hostName);  my ($domainName, $subDomain) = findDomainName($hostName);
  my $dbZoneFile = checkZoneExist($domainName, $subDomain, $ipAddress);  my $dbZoneFile = checkZoneExist($domainName, $subDomain, $ipAddress);
Line 69: Line 72:
  my $dbZoneFile = "db.$domainName";  my $dbZoneFile = "db.$domainName";
  my $userName = "jthomas";  my $userName = "jthomas";
- my $soa = "2009081701";+ my $soa = "2009081801";
  
  if ( -e $repository.$dbZoneFile ){  if ( -e $repository.$dbZoneFile ){
Line 76: Line 79:
   
  else{  else{
- my ($tabs) = tabLength($domainName);+ my ($tabs) = tabLength($domainName.".");
  makeZone("customArecord.tmpl", $dbZoneFile,  {soa => \$soa, userName => \$userName, domain => \"$domainName.", tabs => \$tabs, CUSTOMIP => $ipAddress });  makeZone("customArecord.tmpl", $dbZoneFile,  {soa => \$soa, userName => \$userName, domain => \"$domainName.", tabs => \$tabs, CUSTOMIP => $ipAddress });
  }  }
Line 103: Line 106:
   
  my ($dbZoneFile,  $subDomain, $ipAddress) = @_ ;   my ($dbZoneFile,  $subDomain, $ipAddress) = @_ ; 
-  +
- +
- +
  if ( defined($subDomain) &&  $subDomain ne "www"){  if ( defined($subDomain) &&  $subDomain ne "www"){
- my ($tabs) = tabLength($subDomain); +  
- open(DBFILE, ">>$repository/$dbZoneFile") , or die $! ; + if ( fgrep {/^$subDomain\t/} $repository.$dbZoneFile ){ 
- print DBFILE "$subDomain$tabs"."IN\tA\t$ipAddress\n"; +  
- close (DBFILE);+ print "Record $subDomain is already in $dbZoneFile \n"; 
 +
 +  
 + else { 
 + my ($tabs) = tabLength($subDomain); 
 + open(DBFILE, ">>$repository/$dbZoneFile") , or die $!; 
 + print DBFILE "$subDomain$tabs"."IN\tA\t$ipAddress\n"; 
 + close (DBFILE); 
 + }
  }   }
 } }
Line 118: Line 127:
  my ($word) = @_;   my ($word) = @_; 
  my $tabs = "\t" x (((32 - length($word) + 6) / 8));  my $tabs = "\t" x (((32 - length($word) + 6) / 8));
- if (length($tabs) == 0) { + if (length($tabs) == 0){ 
-    $tabs = " "; + $tabs = "\t";
-   +
  }  }
-     return $tabs;+ return $tabs;
 } }
 +
 +###########################################################################
 +# Help, info and correctional information.
 +###########################################################################
 +sub subUsage {
 +
 +    print "\nUsage: addZone.pl \[-Dn?\] <username> <hostname> <ipaddress>\n";
 +    print "       newZone.pl <username> <domain> <IP address>\n";
 +    print "addZone will create a new zone file, based on domain name. It will also add a new zone to the\n";
 +    print "list of zones governed by named-zones.conf. This file will be created and sent, if needed, by dnsPush.\n";
 +    print "Only use this to add a new zone and make sure you have the correct type (virtual, www or blank).\n\n";
 +    print "-D          Show debug information while running.\n";
 +    print "-n          Dryrun mode, make no changes, displays final zone file on screen.\n";
 +    print "-?          Help page, displays this page.\n\n";
 +    exit(0);
 +}
 +
 </code> </code>
dns_add_script.txt · Last modified: 2020/08/10 02:35 by 127.0.0.1