local.pm.ex
changeset 11 d1dd256c037a
child 13 82ecd75a4ee2
equal deleted inserted replaced
10:8f7ba479860c 11:d1dd256c037a
       
     1 # Example
       
     2 # $Id$
       
     3 # $URL$
       
     4 
       
     5 # remove the next line if you know, what you're doing
       
     6 die "Sure?  You should adapt this file to your needs!";
       
     7 
       
     8 package local;
       
     9 
       
    10 # in:	zone name
       
    11 #       src ip
       
    12 # out:  0 failure ($@ contains message)
       
    13 #      !0 ok      ($@ may contain message)
       
    14 sub addZone($$) {
       
    15     my ($zone, $src) = @_;
       
    16 
       
    17     my $txt = <<__;
       
    18 // Autoadded %time by $0
       
    19 zone "$zone" IN {
       
    20     type slave;
       
    21     file "/var/cache/bind/slave/$zone";
       
    22     masters { %masters; };
       
    23     allow-query { any; };
       
    24     allow-transfer { none; };
       
    25 };
       
    26 
       
    27 __
       
    28 
       
    29     $txt =~ s/%time/scalar localtime/eg;
       
    30     $txt =~ s/%masters/$src/g;
       
    31 
       
    32     if (-f ($_ = "/etc/bind/zones.auto/$zone")) {
       
    33 	$@ = "$_ already exists";
       
    34 	return 0;
       
    35     }
       
    36 
       
    37     open(OUT, $_ = ">$_") or die "Can't open $_: $!\n";
       
    38     print OUT $txt;
       
    39 
       
    40     open(OUT, $_ = ">>/etc/bind/zones.all") or die "Can't open $_: $!\n";
       
    41     print OUT $txt;
       
    42 
       
    43     close OUT;
       
    44 
       
    45     # return 0 == system("rndc reload");
       
    46     local @ARGV = qw(/var/run/bind/run/named.pid);
       
    47     chomp($_ = <>);
       
    48     warn "Sending HUP to $_\n";
       
    49     $@ = "Nameserver reloaded (HUP sent)";
       
    50     kill "HUP", $_ and return 1;
       
    51 
       
    52     $@ = "No process $_";
       
    53     return 0;
       
    54 }
       
    55 	
       
    56 
       
    57 1;
       
    58 # vim:sts=4 sw=4 aw ai sm: