Changeset 405 for trunk/dns-rpc.cgi


Ignore:
Timestamp:
10/04/12 17:26:42 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Clean up some more annoyances in dns-rpc.cgi. See #43.

  • Update active and stub list of subs to match current DNSDB.pm
  • Factor out common opening errorcheck actions into a separate internal sub
  • Refresh getRecCount internals since it should be almost identical to getDomRecs
  • Fix a couple of trivial copypasted comment typos

Add support to handle adding and deleting reverse zones. See #26.

  • Complete conversion of delDomain to delZone
  • Add addRDNS
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dns-rpc.cgi

    r401 r405  
    5050        'dnsdb.addDomain'       => \&addDomain,
    5151        'dnsdb.delZone'         => \&delZone,
     52        'dnsdb.addRDNS'         => \&addRDNS,
    5253        'dnsdb.addGroup'        => \&addGroup,
    5354        'dnsdb.delGroup'        => \&delGroup,
     
    6061        'dnsdb.getRecCount'     => \&getRecCount,
    6162        'dnsdb.addRec'          => \&addRec,
     63        'dnsdb.updateRec'       => \&updateRec,
    6264        'dnsdb.delRec'          => \&delRec,
    63         'dnsdb.domStatus'       => \&domStatus,
     65        'dnsdb.zoneStatus'      => \&zoneStatus,
    6466
    6567        'dnsdb.getMethods'      => \&get_method_list
     
    9092  return 1 if grep /$ENV{REMOTE_ADDR}/, @{$DNSDB::config{rpcacl}{$subsys}};
    9193  return 0;
     94}
     95
     96# Let's see if we can factor these out of the RPC method subs
     97sub _commoncheck {
     98  my $argref = shift;
     99  my $needslog = shift;
     100
     101  die "Missing remote system name\n" if !$argref->{rpcsystem};
     102  die "Access denied\n" if !_aclcheck($argref->{rpcsystem});
     103  if ($needslog) {
     104    die "Missing remote username\n" if !$argref->{rpcuser};
     105    die "Couldn't set userdata for logging\n"
     106        unless DNSDB::initRPC($dbh, (username => $argref->{rpcuser}, rpcsys => $argref->{rpcsystem},
     107                fullname => ($argref->{fullname} ? $argref->{fullname} : $argref->{rpcuser}) ) );
     108  }
    92109}
    93110
     
    105122  my %args = @_;
    106123
    107   # Make sure we've got all the local bits we need
    108   die "Missing remote username\n" if !$args{rpcuser};           # for logging
    109   die "Missing remote system name\n" if !$args{rpcsystem};      # for logging
    110   die "Access denied\n" if !_aclcheck($args{rpcsystem});
     124  _commoncheck(\%args, 'y');
    111125
    112126  my ($code, $msg) = DNSDB::addDomain($dbh, $args{domain}, $args{group}, $args{state});
     
    118132  my %args = @_;
    119133
    120   # Make sure we've got all the local bits we need
    121   die "Missing remote username\n" if !$args{rpcuser};           # for logging
    122   die "Missing remote system name\n" if !$args{rpcsystem};      # for logging
    123   die "Access denied\n" if !_aclcheck($args{rpcsystem});
    124 
    125 # delZone takes zone id and forwrad/reverse flag
     134  _commoncheck(\%args, 'y');
     135  die "Need forward/reverse zone flag\n" if !$args{revrec};
     136
    126137  my ($code,$msg);
    127   # Let's be nice;  delete based on domid OR domain name.  Saves an RPC call round-trip, maybe.
    128   if ($args{domain} =~ /^\d+$/) {
    129     ($code,$msg) = DNSDB::delDomain($dbh, $args{domain});
     138  # Let's be nice;  delete based on zone id OR zone name.  Saves an RPC call round-trip, maybe.
     139  if ($args{zone} =~ /^\d+$/) {
     140    ($code,$msg) = DNSDB::delZone($dbh, $args{zone}, $args{revrec});
    130141  } else {
    131     my $domid = DNSDB::domainID($dbh, $args{domain});
    132     die "Can't find domain\n" if !$domid;
    133     ($code,$msg) = DNSDB::delDomain($dbh, $domid);
    134   }
    135   die $msg if $code eq 'FAIL';
    136 }
    137 
    138 #sub domainName {
    139 #sub domainID {
     142    my $zoneid;
     143    $zoneid = DNSDB::domainID($dbh, $args{zone}) if $args{revrec} eq 'n';
     144    $zoneid = DNSDB::revID($dbh, $args{zone}) if $args{revrec} eq 'y';
     145    die "Can't find zone: $DNSDB::errstr\n" if !$zoneid;
     146    ($code,$msg) = DNSDB::delZone($dbh, $zoneid, $args{revrec});
     147  }
     148  die $msg if $code eq 'FAIL';
     149  return $msg;
     150}
     151
     152#sub domainName {}
     153#sub revName {}
     154#sub domainID {}
     155#sub revID {}
     156
     157sub addRDNS {
     158  my %args = @_;
     159
     160  _commoncheck(\%args, 'y');
     161
     162  my ($code, $msg) = DNSDB::addRDNS($dbh, $args{revzone}, $args{revpatt}, $args{group}, $args{state});
     163  die $msg if $code eq 'FAIL';
     164  return $msg;  # domain ID
     165}
     166
     167#sub getZoneCount {}
     168#sub getZoneList {}
     169#sub getZoneLocation {}
    140170
    141171sub addGroup {
    142172  my %args = @_;
    143173
    144   # Make sure we've got all the local bits we need
    145   die "Missing remote username\n" if !$args{rpcuser};           # for logging
    146   die "Missing remote system name\n" if !$args{rpcsystem};      # for logging
    147   die "Access denied\n" if !_aclcheck($args{rpcsystem});
     174  _commoncheck(\%args, 'y');
    148175
    149176# not sure how to usefully represent permissions from any further out from DNSDB.pm :/
     
    161188  my %args = @_;
    162189
    163   # Make sure we've got all the local bits we need
    164   die "Missing remote username\n" if !$args{rpcuser};           # for logging
    165   die "Missing remote system name\n" if !$args{rpcsystem};      # for logging
    166   die "Access denied\n" if !_aclcheck($args{rpcsystem});
     190  _commoncheck(\%args, 'y');
    167191
    168192  my ($code,$msg);
     
    178202}
    179203
    180 #sub getChildren {
    181 #sub groupName {
    182 #sub groupID {
     204#sub getChildren {}
     205#sub groupName {}
     206#sub getGroupCount {}
     207#sub getGroupList {}
     208#sub groupID {}
    183209
    184210sub addUser {
    185211  my %args = @_;
    186212
    187   # Make sure we've got all the local bits we need
    188   die "Missing remote username\n" if !$args{rpcuser};           # for logging
    189   die "Missing remote system name\n" if !$args{rpcsystem};      # for logging
    190   die "Access denied\n" if !_aclcheck($args{rpcsystem});
     213  _commoncheck(\%args, 'y');
    191214
    192215# not sure how to usefully represent permissions from any further out from DNSDB.pm :/
     
    208231}
    209232
    210 #sub checkUser {
     233#sub getUserCount {}
     234#sub getUserList {}
     235#sub getUserDropdown {}
     236#sub checkUser {}
    211237
    212238sub updateUser {
    213239  my %args = @_;
    214240
    215   # Make sure we've got all the local bits we need
    216   die "Missing remote username\n" if !$args{rpcuser};           # for logging
    217   die "Missing remote system name\n" if !$args{rpcsystem};      # for logging
    218   die "Access denied\n" if !_aclcheck($args{rpcsystem});
     241  _commoncheck(\%args, 'y');
    219242
    220243  die "Missing UID\n" if !$args{uid};
     
    240263  my %args = @_;
    241264
    242   # Make sure we've got all the local bits we need
    243   die "Missing remote username\n" if !$args{rpcuser};           # for logging
    244   die "Missing remote system name\n" if !$args{rpcsystem};      # for logging
    245   die "Access denied\n" if !_aclcheck($args{rpcsystem});
     265  _commoncheck(\%args, 'y');
    246266
    247267  die "Missing UID\n" if !$args{uid};
     
    250270}
    251271
    252 #sub userFullName {
    253 #sub userStatus {
    254 #sub getUserData {
     272#sub userFullName {}
     273#sub userStatus {}
     274#sub getUserData {}
     275
     276#sub addLoc {}
     277#sub updateLoc {}
     278#sub delLoc {}
     279#sub getLoc {}
     280#sub getLocCount {}
     281#sub getLocList {}
     282#sub getLocDropdown {}
    255283
    256284sub getSOA {
    257285  my %args = @_;
    258286
    259   # Make sure we've got all the local bits we need
    260   die "Missing remote username\n" if !$args{rpcuser};           # for logging
    261   die "Missing remote system name\n" if !$args{rpcsystem};      # for logging
    262   die "Access denied\n" if !_aclcheck($args{rpcsystem});
     287  _commoncheck(\%args);
    263288
    264289  my %ret = DNSDB::getSOA($dbh, $args{def}, $args{id});
     
    273298}
    274299
     300#sub updateSOA {}
     301
    275302sub getRecLine {
    276303  my %args = @_;
    277304
    278   # Make sure we've got all the local bits we need
    279   die "Missing remote username\n" if !$args{rpcuser};           # for logging
    280   die "Missing remote system name\n" if !$args{rpcsystem};      # for logging
    281   die "Access denied\n" if !_aclcheck($args{rpcsystem});
     305  _commoncheck(\%args);
    282306
    283307  my $ret = DNSDB::getRecLine($dbh, $args{def}, $args{id});
     
    291315  my %args = @_;
    292316
    293   # Make sure we've got all the local bits we need
    294   die "Missing remote username\n" if !$args{rpcuser};           # for logging
    295   die "Missing remote system name\n" if !$args{rpcsystem};      # for logging
    296   die "Access denied\n" if !_aclcheck($args{rpcsystem});
    297 
    298 #bleh
     317  _commoncheck(\%args);
     318
     319  # set some optional args
    299320  $args{nrecs} = 'all' if !$args{nrecs};
    300321  $args{nstart} = 0 if !$args{nstart};
     
    315336  my %args = @_;
    316337
    317   # Make sure we've got all the local bits we need
    318   die "Missing remote username\n" if !$args{rpcuser};           # for logging
    319   die "Missing remote system name\n" if !$args{rpcsystem};      # for logging
    320   die "Access denied\n" if !_aclcheck($args{rpcsystem});
    321 
    322   return DNSDB::getRecCount($dbh, $args{id});
     338  _commoncheck(\%args);
     339
     340  # set some optional args
     341  $args{nrecs} = 'all' if !$args{nrecs};
     342  $args{nstart} = 0 if !$args{nstart};
     343## for order, need to map input to column names
     344  $args{order} = 'host' if !$args{order};
     345  $args{direction} = 'ASC' if !$args{direction};
     346
     347  my $ret = DNSDB::getRecCount($dbh, (defrec => $args{defrec}, revrec => $args{revrec}, id => $args{id},
     348        offset => $args{offset}, sortby => $args{sortby}, sortorder => $args{sortorder},
     349        filter => $args{filter}) );
     350
     351  die $DNSDB::errstr if !$ret;
     352
     353  return $ret;
    323354}
    324355
     
    326357  my %args = @_;
    327358
    328   # Make sure we've got all the local bits we need
    329   die "Missing remote username\n" if !$args{rpcuser};           # for logging
    330   die "Missing remote system name\n" if !$args{rpcsystem};      # for logging
    331   die "Access denied\n" if !_aclcheck($args{rpcsystem});
    332 
    333   # note dist, weight, port are not reequired on all types;  will be ignored if not needed.
     359  _commoncheck(\%args, 'y');
     360
     361  # note dist, weight, port are not required on all types;  will be ignored if not needed.
    334362  my ($code, $msg) = DNSDB::addRec($dbh, $args{def}, $args{domid}, $args{host}, $DNSDB::typemap{$args{type}},
    335363        $args{val}, $args{ttl}, $args{dist}, $args{weight}, $args{port});
     
    341369  my %args = @_;
    342370
    343   # Make sure we've got all the local bits we need
    344   die "Missing remote username\n" if !$args{rpcuser};           # for logging
    345   die "Missing remote system name\n" if !$args{rpcsystem};      # for logging
    346   die "Access denied\n" if !_aclcheck($args{rpcsystem});
    347 
    348   # note dist, weight, port are not reequired on all types;  will be ignored if not needed.
     371  _commoncheck(\%args, 'y');
     372
     373  # note dist, weight, port are not required on all types;  will be ignored if not needed.
    349374  my ($code, $msg) = DNSDB::updateRec($dbh, $args{def}, $args{recid}, $args{host}, $DNSDB::typemap{$args{type}},
    350375        $args{val}, $args{ttl}, $args{dist}, $args{weight}, $args{port});
     
    356381  my %args = @_;
    357382
    358   # Make sure we've got all the local bits we need
    359   die "Missing remote username\n" if !$args{rpcuser};           # for logging
    360   die "Missing remote system name\n" if !$args{rpcsystem};      # for logging
    361   die "Access denied\n" if !_aclcheck($args{rpcsystem});
    362 
    363   # note dist, weight, port are not reequired on all types;  will be ignored if not needed.
     383  _commoncheck(\%args, 'y');
     384
    364385  my ($code, $msg) = DNSDB::delRec($dbh, $args{def}, $args{recid});
    365386
     
    367388}
    368389
    369 #sub getParents {
    370 
    371 sub domStatus {
    372   my %args = @_;
    373 
    374   # Make sure we've got all the local bits we need
    375   die "Missing remote username\n" if !$args{rpcuser};           # for logging
    376   die "Missing remote system name\n" if !$args{rpcsystem};      # for logging
    377   die "Access denied\n" if !_aclcheck($args{rpcsystem});
    378 
    379   my @arglist = ($dbh, $args{domid});
     390#sub getLogCount {}
     391#sub getLogEntries {}
     392#sub getTypelist {}
     393#sub parentID {}
     394#sub isParent {}
     395
     396sub zoneStatus {
     397  my %args = @_;
     398
     399  _commoncheck(\%args, 'y');
     400
     401  my @arglist = ($dbh, $args{zoneid});
    380402  push @arglist, $args{status} if defined($args{status});
    381403
    382   my $status = DNSDB::domStatus(@arglist);
    383 }
    384 
    385 #sub importAXFR {
    386 #sub export {
    387 #sub __export_tiny {
     404  my $status = DNSDB::zoneStatus(@arglist);
     405}
     406
     407#sub importAXFR {}
     408#sub importBIND {}
     409#sub import_tinydns {}
     410#sub export {}
     411#sub __export_tiny {}
     412#sub _printrec_tiny {}
     413#sub mailNotify {}
    388414
    389415sub get_method_list {
Note: See TracChangeset for help on using the changeset viewer.