source: trunk/dns-rpc.cgi@ 503

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

/trunk

Add a bit of error-logging on an RPC ACL failure

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