dns_add_script
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
dns_add_script [2009/08/14 20:45] – created jt | dns_add_script [2020/08/10 02:35] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
<code perl> | <code perl> | ||
- | |||
# | # | ||
##Jason Thomas | ##Jason Thomas | ||
+ | ##Last Modified 20090819 | ||
+ | |||
use strict; | use strict; | ||
+ | use lib '/ | ||
use File::Copy; | use File::Copy; | ||
use IO::File; | use IO::File; | ||
- | ##use Text:: | + | use Text:: |
+ | use File::Grep qw( fgrep ); | ||
- | my $entry; | + | |
- | my $hostName; | + | ##my $repository = "/ |
- | my $ipAddress; | + | my $repository = "/ |
- | my $domainName; | + | |
- | my $subDomain; | + | |
- | my $dbZoneFile; | + | |
- | my $repository = "/ | + | |
my $dnsData = " | my $dnsData = " | ||
+ | |||
+ | ##currently designed to read from file. however if fqdn is not before fqhn, it will not be able write | ||
+ | ##the entry until db.fqdn is created | ||
+ | |||
+ | |||
open (DATA, $dnsData), or die $!; | open (DATA, $dnsData), or die $!; | ||
my @dnsLine = < | my @dnsLine = < | ||
- | foreach $entry (@dnsLine){ | + | foreach |
+ | |||
chomp ($entry); | chomp ($entry); | ||
- | ($hostName, | + | |
- | $subDomain = findDomainName($hostName); | + | my ($hostName, $ipAddress) = split(' |
- | ## print " | + | my ($domainName, |
- | checkZoneExist($domainName); | + | checkZoneExist($domainName, |
- | + | ||
- | if ( defined($subDomain) && | + | |
- | addToZone($dbZoneFile, $subDomain, $ipAddress); | + | |
- | } | + | |
} | } | ||
close (DATA); | close (DATA); | ||
- | |||
exit (0); | exit (0); | ||
sub findDomainName{ | sub findDomainName{ | ||
- | my $hostName = shift; | + | my ($hostName) = @_; |
+ | my $domainName; | ||
my $subDomain; | my $subDomain; | ||
my $size; | my $size; | ||
Line 46: | Line 46: | ||
@tmp = split(' | @tmp = split(' | ||
$size = @tmp - 2; | $size = @tmp - 2; | ||
- | ## print "size of array: $size.\n"; | ||
- | if ( @tmp==2){ | + | if ( @tmp == 2){ |
- | $domainName = " | + | |
- | return undef; | + | return |
- | ## print " | + | |
} | } | ||
+ | |||
else{ | else{ | ||
+ | |||
$domainName = " | $domainName = " | ||
Line 59: | Line 59: | ||
if ( ! defined($subDomain) ){ | if ( ! defined($subDomain) ){ | ||
+ | |||
$subDomain=$tmp[$counter]; | $subDomain=$tmp[$counter]; | ||
+ | |||
} | } | ||
+ | |||
else{ | else{ | ||
+ | |||
$subDomain=" | $subDomain=" | ||
+ | |||
} | } | ||
} | } | ||
- | ## print " | + | |
- | return | + | return ($domainName, $subDomain); |
} | } | ||
} | } | ||
Line 72: | Line 77: | ||
sub checkZoneExist{ | sub checkZoneExist{ | ||
- | my $domainName = shift; | + | my ($domainName, $subDomain, $ipAddress) |
my $dbZoneFile = " | my $dbZoneFile = " | ||
+ | my $userName = " | ||
+ | my $soa = " | ||
if ( -e $repository.$dbZoneFile ){ | if ( -e $repository.$dbZoneFile ){ | ||
- | ## print "$dbZoneFile | + | |
+ | ## write subdomain to file if file exists; | ||
+ | addToZone($dbZoneFile, $subDomain, $ipAddress); | ||
+ | |||
} | } | ||
- | else{ | + | |
- | ## | + | elsif ( (! defined($subDomain)) || $subDomain eq "" |
+ | |||
+ | my ($tabs) = tabLength($domainName."."); | ||
+ | makeZone(" | ||
+ | |||
} | } | ||
- | + | ||
- | return $dbZoneFile; | + | |
- | + | ||
} | } | ||
sub makeZone{ | sub makeZone{ | ||
- | + | ||
- | + | my ($templateSource, | |
+ | my $template = Text:: | ||
+ | my $result = $template-> | ||
+ | |||
+ | if (! defined $result) { | ||
+ | die " | ||
+ | } | ||
+ | |||
+ | open(DBFILE, | ||
+ | print DBFILE $result; | ||
+ | close (DBFILE); | ||
+ | |||
+ | print " | ||
} | } | ||
Line 96: | Line 118: | ||
sub addToZone{ | sub addToZone{ | ||
- | $dbZoneFile = shift; | ||
- | $subDomain = shift; | ||
- | $ipAddress = shift; | ||
- | print " | + | my ($dbZoneFile, |
+ | |||
+ | if ( defined($subDomain) && | ||
+ | |||
+ | if ( fgrep {/^$subDomain\t/} $repository.$dbZoneFile ){ | ||
+ | |||
+ | print " | ||
+ | } | ||
+ | |||
+ | else { | ||
+ | |||
+ | my ($tabs) = tabLength($subDomain); | ||
+ | open(DBFILE, | ||
+ | print DBFILE " | ||
+ | close (DBFILE); | ||
+ | |||
+ | } | ||
+ | } | ||
+ | } | ||
+ | sub tabLength{ | ||
+ | |||
+ | my ($word) = @_; | ||
+ | my $tabs = " | ||
+ | if (length($tabs) == 0){ | ||
+ | $tabs = " | ||
+ | } | ||
+ | return $tabs; | ||
} | } | ||
+ | |||
+ | ########################################################################### | ||
+ | # Help, info and correctional information. | ||
+ | ########################################################################### | ||
+ | sub subUsage { | ||
+ | |||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | 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 " | ||
+ | print " | ||
+ | print " | ||
+ | exit(0); | ||
+ | } | ||
</ | </ |
dns_add_script.1250282756.txt.gz · Last modified: 2020/08/10 02:28 (external edit)