Further work, cleaned up some code.

This commit is contained in:
Maff 2014-02-09 10:58:03 +00:00
parent 18f595d16d
commit f2f63072ff
1 changed files with 5 additions and 5 deletions

View File

@ -10,14 +10,10 @@ package DNS::Reverse::Manager;
use feature qw(switch say);
use vars '$VERSION'; $VERSION = '1.0.0'; #Version number
use Data::Validate::Domain qw(is_domain); #for validating domains
use Data::Validate::IP qw(is_public_ipv4 is_public_ipv6); #for validating v4/v6 addresses
use Getopt::Long qw(:config posix_default bundling pass_through); #for intelligently handling cli arguments
use Net::DNS; #for doing forward and reverse lookups
use Net::DNS::ZoneFile; #for working with BIND zones
#use Net::DNS::ZoneParse; #for converting an array of RRs to a zone file
use Net::IP; #for converting IPs to their reverse zones
use POSIX qw(strftime); #for SOA serial generation
use Data::Dumper; #debugging
#conf
@ -26,6 +22,7 @@ my $def_dns = '8.8.8.8'; #Recommended default is 8.8.8.8
my $zone_dir = '/var/named/'; #for cPanel, use /var/named/.
my $zone_ext = ".db"; #Default for most environments is ".db".
my $net_type = "cpanel"; #This was originally written to support cPanel-based DNS environments, and primarily impacts how rdns-manager "syncs".
my $nsd_type = "bind9"; #I might in the future support more than just bind9.
#variables for arguments
my $verify = '';
@ -46,6 +43,7 @@ sub nicedie {
exit 1;
}
sub validate_domain {
use Data::Validate::Domain qw(is_domain);
my $domain = shift;
return 1 if is_domain $domain;
return 0;
@ -98,6 +96,7 @@ sub does_zone_exist {
return 1;
}
sub get_zone_array {
use Net::DNS::ZoneFile;
#returns 1 on record exists, 0 on record doesn't exist, -1 on zone exists but isn't writeable, -2 on file exists but isn't a zone, -3 on file doesn't exist
my $ip = shift;
my ($rec,$zone) = get_arpa $ip;
@ -118,6 +117,7 @@ sub does_record_exist {
return 0;
}
sub generate_soa_serial {
use POSIX qw(strftime);
my $cur_serial = shift;
my $yyyymmdd = strftime "%Y%m%d", localtime;
return $cur_serial+1 if $cur_serial =~ /^$yyyymmdd[0-9]{2}$/;
@ -216,7 +216,7 @@ $domain =~ s/([a-zA-Z])$/$1./ if defined $domain; #Append final period if it doe
#Main program flow
#Argument intelligence. Omitting this probably won't impact program flow much but it's important that the user know they're stupid.
nicedie "You seem to have specified both --no-sync and --force-sync. Please make your mind up." if $nosync and $fsync;
nicedie "You seem to have specified some combination of --reset, --remote-ptr and --force. Please make your mind up." if ($reset and $delptr) or (($reset or $delptr) and $force);
nicedie "You seem to have specified some combination of --reset, --remove-ptr and --force. Please make your mind up." if ($reset and $delptr) or (($reset or $delptr) and $force);
nicedie "You seem to have specified arguments that don't make sense together. Please make your mind up." if ($newzone and ($delptr or $reset or $force)) or ($verify and !defined $domain) or (defined $domain and ($newzone or $delptr or $reset));
#Simple check that the zone exists.