source: trunk/dns-rpc.cgi@ 490

Last change on this file since 490 was 490, checked in by Kris Deugau, 12 years ago

/trunk

Tweak RPC to run as FastCGI, and add another config option to control
the number of requests to handle before respawning

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author Id
File size: 20.9 KB
RevLine 
[216]1#!/usr/bin/perl -w -T
[262]2# XMLRPC interface to manipulate most DNS DB entities
3##
[200]4# $Id: dns-rpc.cgi 490 2013-04-09 19:18:00Z kdeugau $
[320]5# Copyright 2012 Kris Deugau <kdeugau@deepnet.cx>
[262]6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19##
[119]20
21use strict;
22use warnings;
[216]23
24# don't remove! required for GNU/FHS-ish install from tarball
25use lib '.'; ##uselib##
[490]26use DNSDB;
[216]27
[490]28use FCGI;
[119]29#use Frontier::RPC2;
30use Frontier::Responder;
31
32## We need to handle a couple of things globally, rather than pasting the same bit into *every* sub.
33## So, let's subclass Frontier::RPC2 + Frontier::Responder, so we can override the single sub in each
34## that needs kicking
35#### hmm. put this in a separate file?
36#package DNSDB::RPC;
37#our @ISA = ("Frontier::RPC2", "Frontier::Responder");
38#package main;
39
[468]40my $dnsdb = DNSDB->new();
[191]41
[119]42my $methods = {
43 'dnsdb.addDomain' => \&addDomain,
[401]44 'dnsdb.delZone' => \&delZone,
[405]45 'dnsdb.addRDNS' => \&addRDNS,
[121]46 'dnsdb.addGroup' => \&addGroup,
47 'dnsdb.delGroup' => \&delGroup,
48 'dnsdb.addUser' => \&addUser,
49 'dnsdb.updateUser' => \&updateUser,
50 'dnsdb.delUser' => \&delUser,
[447]51 'dnsdb.getLocDropdown' => \&getLocDropdown,
[121]52 'dnsdb.getSOA' => \&getSOA,
[123]53 'dnsdb.getRecLine' => \&getRecLine,
54 'dnsdb.getDomRecs' => \&getDomRecs,
55 'dnsdb.getRecCount' => \&getRecCount,
56 'dnsdb.addRec' => \&addRec,
[405]57 'dnsdb.updateRec' => \&updateRec,
[453]58 'dnsdb.addOrUpdateRevRec' => \&addOrUpdateRevRec,
[123]59 'dnsdb.delRec' => \&delRec,
[459]60 'dnsdb.delByCIDR' => \&delByCIDR,
[452]61#sub getLogCount {}
62#sub getLogEntries {}
63 'dnsdb.getRevPattern' => \&getRevPattern,
[405]64 'dnsdb.zoneStatus' => \&zoneStatus,
[452]65 'dnsdb.getZonesByCIDR' => \&getZonesByCIDR,
[121]66
[119]67 'dnsdb.getMethods' => \&get_method_list
68};
69
[490]70my $reqcnt = 0;
71
72while (FCGI::accept >= 0) {
73 my $res = Frontier::Responder->new(
[119]74 methods => $methods
75 );
76
[490]77 # "Can't do that" errors
78 if (!$dnsdb) {
79 print "Content-type: text/xml\n\n".$res->{_decode}->encode_fault(5, $dnsdb->err);
80 } else {
81 print $res->answer;
82 }
83 last if $reqcnt++ > $dnsdb->{maxfcgi};
84} # while FCGI::accept
[119]85
86
87exit;
88
89##
90## Subs below here
91##
92
[490]93# Check RPC ACL
[401]94sub _aclcheck {
95 my $subsys = shift;
[486]96 return 1 if grep /$ENV{REMOTE_ADDR}/, @{$dnsdb->{rpcacl}{$subsys}};
[401]97 return 0;
98}
99
[405]100# Let's see if we can factor these out of the RPC method subs
101sub _commoncheck {
102 my $argref = shift;
103 my $needslog = shift;
104
105 die "Missing remote system name\n" if !$argref->{rpcsystem};
106 die "Access denied\n" if !_aclcheck($argref->{rpcsystem});
107 if ($needslog) {
108 die "Missing remote username\n" if !$argref->{rpcuser};
109 die "Couldn't set userdata for logging\n"
[486]110 unless $dnsdb->initRPC(username => $argref->{rpcuser}, rpcsys => $argref->{rpcsystem},
111 fullname => ($argref->{fullname} ? $argref->{fullname} : $argref->{rpcuser}) );
[405]112 }
113}
114
[453]115# set location to the zone's default location if none is specified
116sub _loccheck {
117 my $argref = shift;
118 if (!$argref->{location} && $argref->{defrec} eq 'n') {
[477]119 $argref->{location} = $dnsdb->getZoneLocation($argref->{revrec}, $argref->{parent_id});
[453]120 }
121}
122
123# set ttl to zone defailt minttl if none is specified
124sub _ttlcheck {
125 my $argref = shift;
126 if (!$argref->{ttl}) {
[486]127 my $tmp = $dnsdb->getSOA($argref->{defrec}, $argref->{revrec}, $argref->{parent_id});
[453]128 $argref->{ttl} = $tmp->{minttl};
129 }
130}
131
[119]132#sub connectDB {
133#sub finish {
134#sub initGlobals {
135#sub initPermissions {
136#sub getPermissions {
137#sub changePermissions {
138#sub comparePermissions {
139#sub changeGroup {
140#sub _log {
141
142sub addDomain {
143 my %args = @_;
144
[405]145 _commoncheck(\%args, 'y');
[119]146
[477]147 my ($code, $msg) = $dnsdb->addDomain($args{domain}, $args{group}, $args{state});
[119]148 die $msg if $code eq 'FAIL';
149 return $msg; # domain ID
150}
151
[401]152sub delZone {
[119]153 my %args = @_;
154
[405]155 _commoncheck(\%args, 'y');
156 die "Need forward/reverse zone flag\n" if !$args{revrec};
[119]157
[121]158 my ($code,$msg);
[405]159 # Let's be nice; delete based on zone id OR zone name. Saves an RPC call round-trip, maybe.
160 if ($args{zone} =~ /^\d+$/) {
[477]161 ($code,$msg) = $dnsdb->delZone($args{zone}, $args{revrec});
[119]162 } else {
[405]163 my $zoneid;
[477]164 $zoneid = $dnsdb->domainID($args{zone}) if $args{revrec} eq 'n';
165 $zoneid = $dnsdb->revID($args{zone}) if $args{revrec} eq 'y';
166 die "Can't find zone: $dnsdb->errstr\n" if !$zoneid;
167 ($code,$msg) = $dnsdb->delZone($zoneid, $args{revrec});
[119]168 }
169 die $msg if $code eq 'FAIL';
[405]170 return $msg;
[119]171}
172
[405]173#sub domainName {}
174#sub revName {}
175#sub domainID {}
176#sub revID {}
[119]177
[405]178sub addRDNS {
179 my %args = @_;
180
181 _commoncheck(\%args, 'y');
182
[477]183 my ($code, $msg) = $dnsdb->addRDNS($args{revzone}, $args{revpatt}, $args{group}, $args{state}, $args{defloc});
[447]184 die "$msg\n" if $code eq 'FAIL';
[405]185 return $msg; # domain ID
186}
187
188#sub getZoneCount {}
189#sub getZoneList {}
190#sub getZoneLocation {}
191
[119]192sub addGroup {
193 my %args = @_;
194
[405]195 _commoncheck(\%args, 'y');
[407]196 die "Missing new group name\n" if !$args{groupname};
197 die "Missing parent group ID\n" if !$args{parent_id};
[119]198
[407]199# not sure how to usefully represent permissions via RPC. :/
[121]200# not to mention, permissions are checked at the UI layer, not the DB layer.
[119]201 my $perms = {domain_edit => 1, domain_create => 1, domain_delete => 1,
202 record_edit => 1, record_create => 1, record_delete => 1
203 };
204## optional $inhert arg?
[476]205 my ($code,$msg) = $dnsdb->addGroup($args{groupname}, $args{parent_id}, $perms);
[119]206 die $msg if $code eq 'FAIL';
207 return $msg;
208}
209
210sub delGroup {
211 my %args = @_;
212
[405]213 _commoncheck(\%args, 'y');
[407]214 die "Missing group ID or name to remove\n" if !$args{group};
[119]215
[121]216 my ($code,$msg);
[119]217 # Let's be nice; delete based on groupid OR group name. Saves an RPC call round-trip, maybe.
218 if ($args{group} =~ /^\d+$/) {
[476]219 ($code,$msg) = $dnsdb->delGroup($args{group});
[119]220 } else {
[486]221 my $grpid = $dnsdb->groupID($args{group});
[407]222 die "Can't find group\n" if !$grpid;
[476]223 ($code,$msg) = $dnsdb->delGroup($grpid);
[119]224 }
225 die $msg if $code eq 'FAIL';
[407]226 return $msg;
[119]227}
228
[405]229#sub getChildren {}
230#sub groupName {}
231#sub getGroupCount {}
232#sub getGroupList {}
233#sub groupID {}
[119]234
235sub addUser {
236 my %args = @_;
237
[405]238 _commoncheck(\%args, 'y');
[119]239
[409]240# not sure how to usefully represent permissions via RPC. :/
[121]241# not to mention, permissions are checked at the UI layer, not the DB layer.
[119]242 # bend and twist; get those arguments in in the right order!
243 $args{type} = 'u' if !$args{type};
244 $args{permstring} = 'i' if !defined($args{permstring});
245 my @userargs = ($args{username}, $args{group}, $args{pass}, $args{state}, $args{type}, $args{permstring});
246 for my $argname ('fname','lname','phone') {
247 last if !$args{$argname};
248 push @userargs, $args{$argname};
249 }
[479]250 my ($code,$msg) = $dnsdb->addUser(@userargs);
[119]251 die $msg if $code eq 'FAIL';
252 return $msg;
253}
254
[405]255#sub getUserCount {}
256#sub getUserList {}
257#sub getUserDropdown {}
258#sub checkUser {}
[119]259
260sub updateUser {
261 my %args = @_;
262
[405]263 _commoncheck(\%args, 'y');
[119]264
[401]265 die "Missing UID\n" if !$args{uid};
[121]266
[119]267 # bend and twist; get those arguments in in the right order!
[411]268 $args{type} = 'u' if !$args{type};
[119]269 my @userargs = ($args{uid}, $args{username}, $args{group}, $args{pass}, $args{state}, $args{type});
270 for my $argname ('fname','lname','phone') {
271 last if !$args{$argname};
272 push @userargs, $args{$argname};
273 }
274##fixme: also underlying in DNSDB::updateUser(): no way to just update this or that attribute;
275# have to pass them all in to be overwritten
[479]276 my ($code,$msg) = $dnsdb->updateUser(@userargs);
[119]277 die $msg if $code eq 'FAIL';
[412]278 return $msg;
[119]279}
280
281sub delUser {
282 my %args = @_;
283
[405]284 _commoncheck(\%args, 'y');
[119]285
[401]286 die "Missing UID\n" if !$args{uid};
[479]287 my ($code,$msg) = $dnsdb->delUser($args{uid});
[119]288 die $msg if $code eq 'FAIL';
[412]289 return $msg;
[119]290}
291
[405]292#sub userFullName {}
293#sub userStatus {}
294#sub getUserData {}
[119]295
[405]296#sub addLoc {}
297#sub updateLoc {}
298#sub delLoc {}
299#sub getLoc {}
300#sub getLocCount {}
301#sub getLocList {}
302
[447]303sub getLocDropdown {
304 my %args = @_;
305
306 _commoncheck(\%args);
307 $args{defloc} = '' if !$args{defloc};
308
[480]309 my $ret = $dnsdb->getLocDropdown($args{group}, $args{defloc});
[447]310 return $ret;
311}
312
[119]313sub getSOA {
314 my %args = @_;
315
[405]316 _commoncheck(\%args);
[121]317
[481]318 my $ret = $dnsdb->getSOA($args{defrec}, $args{revrec}, $args{id});
[413]319 if (!$ret) {
320 if ($args{defrec} eq 'y') {
[401]321 die "No default SOA record in group\n";
[121]322 } else {
[413]323 die "No SOA record in zone\n";
[121]324 }
325 }
[413]326 return $ret;
[119]327}
328
[405]329#sub updateSOA {}
330
[119]331sub getRecLine {
332 my %args = @_;
333
[405]334 _commoncheck(\%args);
[123]335
[481]336 my $ret = $dnsdb->getRecLine($args{defrec}, $args{revrec}, $args{id});
[123]337
[481]338 die $dnsdb->errstr if !$ret;
[123]339
340 return $ret;
[119]341}
342
343sub getDomRecs {
344 my %args = @_;
345
[405]346 _commoncheck(\%args);
[123]347
[405]348 # set some optional args
[123]349 $args{nrecs} = 'all' if !$args{nrecs};
350 $args{nstart} = 0 if !$args{nstart};
351## for order, need to map input to column names
352 $args{order} = 'host' if !$args{order};
353 $args{direction} = 'ASC' if !$args{direction};
354
[481]355 my $ret = $dnsdb->getDomRecs(defrec => $args{defrec}, revrec => $args{revrec}, id => $args{id},
[401]356 offset => $args{offset}, sortby => $args{sortby}, sortorder => $args{sortorder},
[481]357 filter => $args{filter});
[123]358
[481]359 die $dnsdb->errstr if !$ret;
[123]360
361 return $ret;
[119]362}
363
[123]364sub getRecCount {
365 my %args = @_;
[119]366
[405]367 _commoncheck(\%args);
[123]368
[405]369 # set some optional args
370 $args{nrecs} = 'all' if !$args{nrecs};
371 $args{nstart} = 0 if !$args{nstart};
372## for order, need to map input to column names
373 $args{order} = 'host' if !$args{order};
374 $args{direction} = 'ASC' if !$args{direction};
375
[481]376 my $ret = $dnsdb->getRecCount($args{defrec}, $args{revrec}, $args{id}, $args{filter});
[405]377
[481]378 die $dnsdb->errstr if !$ret;
[405]379
380 return $ret;
[123]381}
382
[119]383sub addRec {
384 my %args = @_;
385
[405]386 _commoncheck(\%args, 'y');
[123]387
[453]388 _loccheck(\%args);
389 _ttlcheck(\%args);
[123]390
[481]391 my @recargs = ($args{defrec}, $args{revrec}, $args{parent_id},
[426]392 \$args{name}, \$args{type}, \$args{address}, $args{ttl}, $args{location});
393 if ($args{type} == $DNSDB::reverse_typemap{MX} or $args{type} == $DNSDB::reverse_typemap{SRV}) {
394 push @recargs, $args{distance};
395 if ($args{type} == $DNSDB::reverse_typemap{SRV}) {
396 push @recargs, $args{weight};
397 push @recargs, $args{port};
398 }
399 }
400
[481]401 my ($code, $msg) = $dnsdb->addRec(@recargs);
[426]402
[123]403 die $msg if $code eq 'FAIL';
[426]404 return $msg;
[119]405}
406
407sub updateRec {
408 my %args = @_;
409
[405]410 _commoncheck(\%args, 'y');
[123]411
[452]412 # get old line, so we can update only the bits that the caller passed to change
413 # note we subbed address for val since it's a little more caller-friendly
[481]414 my $oldrec = $dnsdb->getRecLine($args{defrec}, $args{revrec}, $args{id});
[452]415 foreach my $field (qw(name type address ttl location distance weight port)) {
416 $args{$field} = $oldrec->{$field} if !$args{$field} && defined($oldrec->{$field});
417 }
418
[405]419 # note dist, weight, port are not required on all types; will be ignored if not needed.
[426]420 # parent_id is the "primary" zone we're updating; necessary for forward/reverse voodoo
[481]421 my ($code, $msg) = $dnsdb->updateRec($args{defrec}, $args{revrec}, $args{id}, $args{parent_id},
[426]422 \$args{name}, \$args{type}, \$args{address}, $args{ttl}, $args{location},
423 $args{distance}, $args{weight}, $args{port});
[123]424
425 die $msg if $code eq 'FAIL';
[426]426 return $msg;
[119]427}
428
[453]429# Takes a passed CIDR block and DNS pattern; adds a new record or updates the record(s) affected
430sub addOrUpdateRevRec {
431 my %args = @_;
432
433 _commoncheck(\%args, 'y');
[459]434 my $cidr = new NetAddr::IP $args{cidr};
[453]435
[477]436 my $zonelist = $dnsdb->getZonesByCIDR(%args);
[453]437 if (scalar(@$zonelist) == 0) {
438 # enhh.... WTF?
439 } elsif (scalar(@$zonelist) == 1) {
440 # check if the single zone returned is bigger than the CIDR. if so, we can just add a record
441 my $zone = new NetAddr::IP $zonelist->[0]->{revnet};
[459]442 if ($zone->contains($cidr)) {
[454]443 # We need to strip the CIDR mask on IPv4 /32 assignments, or we just add a new record all the time.
[459]444 my $filt = ($cidr->{isv6} || $cidr->masklen != 32 ? "$cidr" : $cidr->addr);
[481]445 my $reclist = $dnsdb->getDomRecs(defrec => 'n', revrec => 'y',
[454]446 id => $zonelist->[0]->{rdns_id}, filter => $filt);
[453]447 if (scalar(@$reclist) == 0) {
448 # Aren't Magic Numbers Fun? See pseudotype list in dnsadmin.
[460]449 my $type = ($cidr->{isv6} ? 65284 : ($cidr->masklen == 32 ? 65280 : 65283) );
[453]450 addRec(defrec =>'n', revrec => 'y', parent_id => $zonelist->[0]->{rdns_id}, type => $type,
[459]451 address => "$cidr", %args);
[453]452 } else {
[459]453 my $flag = 0;
[453]454 foreach my $rec (@$reclist) {
[454]455 # pure PTR plus composite types
456 next unless $rec->{type} == 12 || $rec->{type} == 65280 || $rec->{type} == 65281
457 || $rec->{type} == 65282 || $rec->{type} == 65283 || $rec->{type} == 65284;
458 next unless $rec->{val} eq $filt; # make sure we really update the record we want to update.
[481]459 $dnsdb->updateRec(defrec =>'n', revrec => 'y', id => $rec->{record_id},
[453]460 parent_id => $zonelist->[0]->{rdns_id}, %args);
[459]461 $flag = 1;
[453]462 last; # only do one record.
463 }
[459]464 unless ($flag) {
465 # Nothing was updated, so we didn't really have a match. Add as per @$reclist==0
466 # Aren't Magic Numbers Fun? See pseudotype list in dnsadmin.
467 my $type = ($cidr->{isv6} ? 65282 : ($cidr->masklen == 32 ? 65280 : 65283) );
[481]468 $dnsdb->addRec(defrec =>'n', revrec => 'y', parent_id => $zonelist->[0]->{rdns_id}, type => $type,
[459]469 address => "$cidr", %args);
470 }
[453]471 }
472 } else {
473 # ebbeh? CIDR is only partly represented in DNS. This needs manual intervention.
474 } # done single-zone-contains-$cidr
475 } else {
476 # Overlapping reverse zones shouldn't be possible, so if we're here we've got a CIDR
477 # that spans multiple reverse zones (eg, /23 CIDR -> 2 /24 rzones)
478 foreach my $zdata (@$zonelist) {
[481]479 my $reclist = $dnsdb->getDomRecs(defrec => 'n', revrec => 'y',
[453]480 id => $zdata->{rdns_id}, filter => $zdata->{revnet});
481 if (scalar(@$reclist) == 0) {
482 my $type = ($args{cidr}->{isv6} ? 65282 : ($args{cidr}->masklen == 32 ? 65280 : 65283) );
[481]483 $dnsdb->addRec(defrec =>'n', revrec => 'y', parent_id => $zdata->{rdns_id}, type => $type,
[453]484 address => "$args{cidr}", %args);
485 } else {
486 foreach my $rec (@$reclist) {
[454]487 # only the composite and/or template types; pure PTR or nontemplate composite
488 # types are nominally impossible here.
[453]489 next unless $rec->{type} == 65282 || $rec->{type} == 65283 || $rec->{type} == 65284;
[481]490 $dnsdb->updateRec(defrec =>'n', revrec => 'y', id => $rec->{record_id},
[453]491 parent_id => $zdata->{rdns_id}, %args);
492 last; # only do one record.
493 }
494 }
495 } # iterate zones within $cidr
496 } # done $cidr-contains-zones
497}
498
[119]499sub delRec {
500 my %args = @_;
501
[405]502 _commoncheck(\%args, 'y');
[123]503
[481]504 my ($code, $msg) = $dnsdb->delRec($args{defrec}, $args{recrev}, $args{id});
[123]505
506 die $msg if $code eq 'FAIL';
[426]507 return $msg;
[119]508}
509
[459]510sub delByCIDR {
511 my %args = @_;
512
513 _commoncheck(\%args, 'y');
514
515 # much like addOrUpdateRevRec()
[477]516 my $zonelist = $dnsdb->getZonesByCIDR(%args);
[459]517 my $cidr = new NetAddr::IP $args{cidr};
518
519 if (scalar(@$zonelist) == 0) {
520 # enhh.... WTF?
521 } elsif (scalar(@$zonelist) == 1) {
522
523 # check if the single zone returned is bigger than the CIDR
524 my $zone = new NetAddr::IP $zonelist->[0]->{revnet};
525 if ($zone->contains($cidr)) {
526
527 if ($args{delsubs}) {
528 # Delete ALL EVARYTHING!!one11!! in $args{cidr}
[481]529 my $reclist = $dnsdb->getDomRecs(defrec => 'n', revrec => 'y', id => $zonelist->[0]->{rdns_id});
[459]530 foreach my $rec (@$reclist) {
531 my $reccidr = new NetAddr::IP $rec->{val};
532 next unless $cidr->contains($reccidr);
[460]533 next unless $rec->{type} == 12 || $rec->{type} == 65280 || $rec->{type} == 65281 ||
534 $rec->{type} == 65282 || $rec->{type} == 65283 ||$rec->{type} == 65284;
[459]535 ##fixme: multiple records, wanna wax'em all, how to report errors?
536 if ($args{delforward} ||
537 $rec->{type} == 12 || $rec->{type} == 65282 ||
538 $rec->{type} == 65283 || $rec->{type} == 65284) {
[481]539 my ($code,$msg) = $dnsdb->delRec('n', 'y', $rec->{record_id});
[459]540 } else {
[481]541 my $ret = $dnsdb->downconvert($rec->{record_id}, $DNSDB::reverse_typemap{A});
[459]542 }
543 }
[460]544 if ($args{parpatt} && $zone == $cidr) {
545 # Edge case; we've just gone and axed all the records in the reverse zone.
546 # Re-add one to match the parent if we've been given a pattern to use.
[481]547 $dnsdb->addRec(defrec =>'n', revrec => 'y', parent_id => $zonelist->[0]->{rdns_id},
[460]548 type => ($zone->{isv6} ? 65284 : 65283), address => "$cidr", %args);
549 }
[459]550
551 } else {
552 # Selectively delete only exact matches on $args{cidr}
553
554 # We need to strip the CIDR mask on IPv4 /32 assignments, or we can't find single-IP records
555 my $filt = ($cidr->{isv6} || $cidr->masklen != 32 ? "$cidr" : $cidr->addr);
[481]556 my $reclist = $dnsdb->getDomRecs(defrec => 'n', revrec => 'y',
[459]557 id => $zonelist->[0]->{rdns_id}, filter => $filt, sortby => 'val', sortorder => 'DESC');
558 foreach my $rec (@$reclist) {
559 my $reccidr = new NetAddr::IP $rec->{val};
560 next unless $cidr == $reccidr;
[460]561 next unless $rec->{type} == 12 || $rec->{type} == 65280 || $rec->{type} == 65281 ||
562 $rec->{type} == 65282 || $rec->{type} == 65283 ||$rec->{type} == 65284;
[459]563 if ($args{delforward} || $rec->{type} == 12) {
[481]564 my ($code,$msg) = $dnsdb->delRec('n', 'y', $rec->{record_id});
[459]565 die $msg if $code eq 'FAIL';
566 return $msg;
567 } else {
[481]568 my $ret = $dnsdb->downconvert($rec->{record_id}, $DNSDB::reverse_typemap{A});
569 die $dnsdb->errstr if !$ret;
[459]570 return "A+PTR for $args{cidr} split and PTR removed";
571 }
572 } # foreach @$reclist
573 }
574
575 } else { # $cidr > $zone but we only have one zone
576 # ebbeh? CIDR is only partly represented in DNS. This needs manual intervention.
577 return "Warning: $args{cidr} is only partly represented in DNS. Check and remove DNS records manually.";
578 } # done single-zone-contains-$cidr
579
580 } else { # multiple zones nominally "contain" $cidr
581 # Overlapping reverse zones shouldn't be possible, so if we're here we've got a CIDR
582 # that spans multiple reverse zones (eg, /23 CIDR -> 2 /24 rzones)
583 foreach my $zdata (@$zonelist) {
[481]584 my $reclist = $dnsdb->getDomRecs(defrec => 'n', revrec => 'y', id => $zdata->{rdns_id});
[459]585 if (scalar(@$reclist) == 0) {
[460]586# nothing to do? or do we (re)add a record based on the parent?
587# yes, yes we do, past the close of the else
588# my $type = ($args{cidr}->{isv6} ? 65282 : ($args{cidr}->masklen == 32 ? 65280 : 65283) );
589# addRec(defrec =>'n', revrec => 'y', parent_id => $zdata->{rdns_id}, type => $type,
590# address => "$args{cidr}", %args);
[459]591 } else {
592 foreach my $rec (@$reclist) {
[460]593 next unless $rec->{type} == 12 || $rec->{type} == 65280 || $rec->{type} == 65281 ||
594 $rec->{type} == 65282 || $rec->{type} == 65283 || $rec->{type} == 65284;
595 # Template types are only useful when attached to a reverse zone.
596##fixme ..... or ARE THEY?
597 if ($args{delforward} ||
598 $rec->{type} == 12 || $rec->{type} == 65282 ||
599 $rec->{type} == 65283 || $rec->{type} == 65284) {
[481]600 my ($code,$msg) = $dnsdb->delRec('n', 'y', $rec->{record_id});
[460]601 } else {
[481]602 my $ret = $dnsdb->downconvert($rec->{record_id}, $DNSDB::reverse_typemap{A});
[460]603 }
[459]604 } # foreach @$reclist
[460]605 } # nrecs != 0
606 if ($args{parpatt}) {
607 # We've just gone and axed all the records in the reverse zone.
608 # Re-add one to match the parent if we've been given a pattern to use.
[481]609 $dnsdb->addRec(defrec =>'n', revrec => 'y', parent_id => $zdata->{rdns_id},
[460]610 type => ($cidr->{isv6} ? 65284 : 65283),
611 address => $zdata->{revnet}, name => $args{parpatt}, %args);
[459]612 }
613 } # iterate zones within $cidr
614 } # done $cidr-contains-zones
615
616} # end delByCIDR()
617
[405]618#sub getLogCount {}
619#sub getLogEntries {}
[452]620
621sub getRevPattern {
622 my %args = @_;
623
624 _commoncheck(\%args, 'y');
625
[483]626 return $dnsdb->getRevPattern($args{cidr}, $args{group});
[452]627}
628
[405]629#sub getTypelist {}
630#sub parentID {}
631#sub isParent {}
[123]632
[405]633sub zoneStatus {
[123]634 my %args = @_;
635
[405]636 _commoncheck(\%args, 'y');
[123]637
[477]638 my @arglist = ($args{zoneid});
[123]639 push @arglist, $args{status} if defined($args{status});
640
[477]641 my $status = $dnsdb->zoneStatus(@arglist);
[123]642}
643
[452]644# Get a list of hashes referencing the reverse zone(s) for a passed CIDR block
645sub getZonesByCIDR {
646 my %args = @_;
647
648 _commoncheck(\%args, 'y');
649
[477]650 return $dnsdb->getZonesByCIDR(%args);
[452]651}
652
[405]653#sub importAXFR {}
654#sub importBIND {}
655#sub import_tinydns {}
656#sub export {}
657#sub __export_tiny {}
658#sub _printrec_tiny {}
659#sub mailNotify {}
[119]660
661sub get_method_list {
662 my @methods = keys %{$methods};
663 return \@methods;
664}
Note: See TracBrowser for help on using the repository browser.