source: trunk/dns-rpc.cgi@ 461

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

/trunk

Edge case bugfixes and fleshing-out for deleting records by CIDR. See #43

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