Ignore:
Timestamp:
12/10/13 17:47:44 (11 years ago)
Author:
Kris Deugau
Message:

/branches/stable

Merge reverse DNS and location work; 2 of mumble

Numerous conflicts due to hand-copy or partial merges

Location:
branches/stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/stable

  • branches/stable/dns-rpc.cgi

    r263 r545  
    33##
    44# $Id$
    5 # Copyright 2011 Kris Deugau <kdeugau@deepnet.cx>
     5# Copyright 2012 Kris Deugau <kdeugau@deepnet.cx>
    66#
    77#    This program is free software: you can redistribute it and/or modify
     
    3939#package main;
    4040
    41 loadConfig();
     41DNSDB::loadConfig(rpcflag => 1);
    4242
    4343# need to create a DNSDB object too
     
    4949my $methods = {
    5050        'dnsdb.addDomain'       => \&addDomain,
    51         'dnsdb.delDomain'       => \&delDomain,
     51        '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
     
    7173
    7274# "Can't do that" errors
    73 ##fixme:  this MUST be loaded from a config file!  Also must support multiple IPs
    74 if ($ENV{REMOTE_ADDR} ne '192.168.2.116') {
    75   print "Content-type: text/xml\n\n".$res->{_decode}->encode_fault(5, "Access denied");
    76   exit;
    77 }
    7875if (!$dbh) {
    7976  print "Content-type: text/xml\n\n".$res->{_decode}->encode_fault(5, $msg);
     
    8986## Subs below here
    9087##
     88
     89# Utility subs
     90sub _aclcheck {
     91  my $subsys = shift;
     92  return 1 if grep /$ENV{REMOTE_ADDR}/, @{$DNSDB::config{rpcacl}{$subsys}};
     93  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  }
     109}
    91110
    92111#sub connectDB {
     
    103122  my %args = @_;
    104123
    105   # Make sure we've got all the local bits we need
    106   die "Missing remote username" if !$args{rpcuser};             # for logging
    107   die "Missing remote system name" if !$args{rpcsystem};        # for logging
     124  _commoncheck(\%args, 'y');
    108125
    109126  my ($code, $msg) = DNSDB::addDomain($dbh, $args{domain}, $args{group}, $args{state});
     
    112129}
    113130
    114 sub delDomain {
    115   my %args = @_;
    116 
    117   # Make sure we've got all the local bits we need
    118   die "Missing remote username" if !$args{rpcuser};             # for logging
    119   die "Missing remote system name" if !$args{rpcsystem};        # for logging
     131sub delZone {
     132  my %args = @_;
     133
     134  _commoncheck(\%args, 'y');
     135  die "Need forward/reverse zone flag\n" if !$args{revrec};
    120136
    121137  my ($code,$msg);
    122   # Let's be nice;  delete based on domid OR domain name.  Saves an RPC call round-trip, maybe.
    123   if ($args{domain} =~ /^\d+$/) {
    124     ($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});
    125141  } else {
    126     my $domid = DNSDB::domainID($dbh, $args{domain});
    127     die "Can't find domain" if !$domid;
    128     ($code,$msg) = DNSDB::delDomain($dbh, $domid);
    129   }
    130   die $msg if $code eq 'FAIL';
    131 }
    132 
    133 #sub domainName {
    134 #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 {}
    135170
    136171sub addGroup {
    137172  my %args = @_;
    138173
    139   # Make sure we've got all the local bits we need
    140   die "Missing remote username" if !$args{rpcuser};             # for logging
    141   die "Missing remote system name" if !$args{rpcsystem};        # for logging
    142 
    143 # not sure how to usefully represent permissions from any further out from DNSDB.pm :/
     174  _commoncheck(\%args, 'y');
     175  die "Missing new group name\n" if !$args{groupname};
     176  die "Missing parent group ID\n" if !$args{parent_id};
     177
     178# not sure how to usefully represent permissions via RPC. :/
    144179# not to mention, permissions are checked at the UI layer, not the DB layer.
    145180  my $perms = {domain_edit => 1, domain_create => 1, domain_delete => 1,
     
    155190  my %args = @_;
    156191
    157   # Make sure we've got all the local bits we need
    158   die "Missing remote username" if !$args{rpcuser};             # for logging
    159   die "Missing remote system name" if !$args{rpcsystem};        # for logging
     192  _commoncheck(\%args, 'y');
     193  die "Missing group ID or name to remove\n" if !$args{group};
    160194
    161195  my ($code,$msg);
     
    165199  } else {
    166200    my $grpid = DNSDB::groupID($dbh, $args{group});
    167     die "Can't find group" if !$grpid;
     201    die "Can't find group\n" if !$grpid;
    168202    ($code,$msg) = DNSDB::delGroup($dbh, $grpid);
    169203  }
    170204  die $msg if $code eq 'FAIL';
    171 }
    172 
    173 #sub getChildren {
    174 #sub groupName {
    175 #sub groupID {
     205  return $msg;
     206}
     207
     208#sub getChildren {}
     209#sub groupName {}
     210#sub getGroupCount {}
     211#sub getGroupList {}
     212#sub groupID {}
    176213
    177214sub addUser {
    178215  my %args = @_;
    179216
    180   # Make sure we've got all the local bits we need
    181   die "Missing remote username" if !$args{rpcuser};             # for logging
    182   die "Missing remote system name" if !$args{rpcsystem};        # for logging
    183 
    184 # not sure how to usefully represent permissions from any further out from DNSDB.pm :/
     217  _commoncheck(\%args, 'y');
     218
     219# not sure how to usefully represent permissions via RPC.  :/
    185220# not to mention, permissions are checked at the UI layer, not the DB layer.
    186   my $perms = {domain_edit => 1, domain_create => 1, domain_delete => 1,
    187         record_edit => 1, record_create => 1, record_delete => 1
    188         };
    189221  # bend and twist;  get those arguments in in the right order!
    190222  $args{type} = 'u' if !$args{type};
     
    200232}
    201233
    202 #sub checkUser {
     234#sub getUserCount {}
     235#sub getUserList {}
     236#sub getUserDropdown {}
     237#sub checkUser {}
    203238
    204239sub updateUser {
    205240  my %args = @_;
    206241
    207   # Make sure we've got all the local bits we need
    208   die "Missing remote username" if !$args{rpcuser};             # for logging
    209   die "Missing remote system name" if !$args{rpcsystem};        # for logging
    210 
    211   die "Missing UID" if !$args{uid};
    212 
    213 # not sure how to usefully represent permissions from any further out from DNSDB.pm :/
    214 # not to mention, permissions are checked at the UI layer, not the DB layer.
    215   my $perms = {domain_edit => 1, domain_create => 1, domain_delete => 1,
    216         record_edit => 1, record_create => 1, record_delete => 1
    217         };
     242  _commoncheck(\%args, 'y');
     243
     244  die "Missing UID\n" if !$args{uid};
     245
    218246  # bend and twist;  get those arguments in in the right order!
     247  $args{type} = 'u' if !$args{type};
    219248  my @userargs = ($args{uid}, $args{username}, $args{group}, $args{pass}, $args{state}, $args{type});
    220249  for my $argname ('fname','lname','phone') {
     
    224253##fixme:  also underlying in DNSDB::updateUser():  no way to just update this or that attribute;
    225254#         have to pass them all in to be overwritten
    226   my ($code,$msg) = DNSDB::addUser($dbh, @userargs);
    227   die $msg if $code eq 'FAIL';
     255  my ($code,$msg) = DNSDB::updateUser($dbh, @userargs);
     256  die $msg if $code eq 'FAIL';
     257  return $msg;
    228258}
    229259
     
    231261  my %args = @_;
    232262
    233   # Make sure we've got all the local bits we need
    234   die "Missing remote username" if !$args{rpcuser};             # for logging
    235   die "Missing remote system name" if !$args{rpcsystem};        # for logging
    236 
    237   die "Missing UID" if !$args{uid};
     263  _commoncheck(\%args, 'y');
     264
     265  die "Missing UID\n" if !$args{uid};
    238266  my ($code,$msg) = DNSDB::delUser($dbh, $args{uid});
    239267  die $msg if $code eq 'FAIL';
    240 }
    241 
    242 #sub userFullName {
    243 #sub userStatus {
    244 #sub getUserData {
     268  return $msg;
     269}
     270
     271#sub userFullName {}
     272#sub userStatus {}
     273#sub getUserData {}
     274
     275#sub addLoc {}
     276#sub updateLoc {}
     277#sub delLoc {}
     278#sub getLoc {}
     279#sub getLocCount {}
     280#sub getLocList {}
     281#sub getLocDropdown {}
    245282
    246283sub getSOA {
    247284  my %args = @_;
    248285
    249   # Make sure we've got all the local bits we need
    250   die "Missing remote username" if !$args{rpcuser};             # for logging
    251   die "Missing remote system name" if !$args{rpcsystem};        # for logging
    252 
    253   my %ret = DNSDB::getSOA($dbh, $args{def}, $args{id});
    254   if (!$ret{recid}) {
    255     if ($args{def} eq 'y') {
    256       die "No default SOA record in group";
     286  _commoncheck(\%args);
     287
     288  my $ret = DNSDB::getSOA($dbh, $args{defrec}, $args{revrec}, $args{id});
     289  if (!$ret) {
     290    if ($args{defrec} eq 'y') {
     291      die "No default SOA record in group\n";
    257292    } else {
    258       die "No SOA record in domain";
     293      die "No SOA record in zone\n";
    259294    }
    260295  }
    261   return \%ret;
    262 }
     296  return $ret;
     297}
     298
     299#sub updateSOA {}
    263300
    264301sub getRecLine {
    265302  my %args = @_;
    266303
    267   # Make sure we've got all the local bits we need
    268   die "Missing remote username" if !$args{rpcuser};             # for logging
    269   die "Missing remote system name" if !$args{rpcsystem};        # for logging
    270 
    271   my $ret = DNSDB::getRecLine($dbh, $args{def}, $args{id});
     304  _commoncheck(\%args);
     305
     306  my $ret = DNSDB::getRecLine($dbh, $args{defrec}, $args{revrec}, $args{id});
    272307
    273308  die $DNSDB::errstr if !$ret;
     
    279314  my %args = @_;
    280315
    281   # Make sure we've got all the local bits we need
    282   die "Missing remote username" if !$args{rpcuser};             # for logging
    283   die "Missing remote system name" if !$args{rpcsystem};        # for logging
    284 
    285 #bleh
     316  _commoncheck(\%args);
     317
     318  # set some optional args
    286319  $args{nrecs} = 'all' if !$args{nrecs};
    287320  $args{nstart} = 0 if !$args{nstart};
     
    290323  $args{direction} = 'ASC' if !$args{direction};
    291324
    292   my $ret = DNSDB::getDomRecs($dbh, $args{def}, $args{id}, $args{nrecs}, $args{nstart}, $args{order}, $args{direction});
     325  my $ret = DNSDB::getDomRecs($dbh, (defrec => $args{defrec}, revrec => $args{revrec}, id => $args{id},
     326        offset => $args{offset}, sortby => $args{sortby}, sortorder => $args{sortorder},
     327        filter => $args{filter}) );
    293328
    294329  die $DNSDB::errstr if !$ret;
     
    300335  my %args = @_;
    301336
    302   # Make sure we've got all the local bits we need
    303   die "Missing remote username" if !$args{rpcuser};             # for logging
    304   die "Missing remote system name" if !$args{rpcsystem};        # for logging
    305 
    306   return DNSDB::getRecCount($dbh, $id);
     337  _commoncheck(\%args);
     338
     339  # set some optional args
     340  $args{nrecs} = 'all' if !$args{nrecs};
     341  $args{nstart} = 0 if !$args{nstart};
     342## for order, need to map input to column names
     343  $args{order} = 'host' if !$args{order};
     344  $args{direction} = 'ASC' if !$args{direction};
     345
     346  my $ret = DNSDB::getRecCount($dbh, $args{defrec}, $args{revrec}, $args{id}, $args{filter});
     347
     348  die $DNSDB::errstr if !$ret;
     349
     350  return $ret;
    307351}
    308352
     
    310354  my %args = @_;
    311355
    312   # Make sure we've got all the local bits we need
    313   die "Missing remote username" if !$args{rpcuser};             # for logging
    314   die "Missing remote system name" if !$args{rpcsystem};        # for logging
    315 
    316   # note dist, weight, port are not reequired on all types;  will be ignored if not needed.
    317   my ($code, $msg) = DNSDB::addRec($dbh, $args{def}, $args{domid}, $args{host}, $typemap{$args{type}},
     356  _commoncheck(\%args, 'y');
     357
     358  # note dist, weight, port are not required on all types;  will be ignored if not needed.
     359  my ($code, $msg) = DNSDB::addRec($dbh, $args{def}, $args{domid}, $args{host}, $DNSDB::typemap{$args{type}},
    318360        $args{val}, $args{ttl}, $args{dist}, $args{weight}, $args{port});
    319361
     
    324366  my %args = @_;
    325367
    326   # Make sure we've got all the local bits we need
    327   die "Missing remote username" if !$args{rpcuser};             # for logging
    328   die "Missing remote system name" if !$args{rpcsystem};        # for logging
    329 
    330   # note dist, weight, port are not reequired on all types;  will be ignored if not needed.
    331   my ($code, $msg) = DNSDB::updateRec($dbh, $args{def}, $args{recid}, $args{host}, $typemap{$args{type}},
     368  _commoncheck(\%args, 'y');
     369
     370  # note dist, weight, port are not required on all types;  will be ignored if not needed.
     371  my ($code, $msg) = DNSDB::updateRec($dbh, $args{def}, $args{recid}, $args{host}, $DNSDB::typemap{$args{type}},
    332372        $args{val}, $args{ttl}, $args{dist}, $args{weight}, $args{port});
    333373
     
    338378  my %args = @_;
    339379
    340   # Make sure we've got all the local bits we need
    341   die "Missing remote username" if !$args{rpcuser};             # for logging
    342   die "Missing remote system name" if !$args{rpcsystem};        # for logging
    343 
    344   # note dist, weight, port are not reequired on all types;  will be ignored if not needed.
     380  _commoncheck(\%args, 'y');
     381
    345382  my ($code, $msg) = DNSDB::delRec($dbh, $args{def}, $args{recid});
    346383
     
    348385}
    349386
    350 #sub getParents {
    351 
    352 sub domStatus {
    353   my %args = @_;
    354 
    355   # Make sure we've got all the local bits we need
    356   die "Missing remote username" if !$args{rpcuser};             # for logging
    357   die "Missing remote system name" if !$args{rpcsystem};        # for logging
    358 
    359   my @arglist = ($dbh, $args{domid});
     387#sub getLogCount {}
     388#sub getLogEntries {}
     389#sub getTypelist {}
     390#sub parentID {}
     391#sub isParent {}
     392
     393sub zoneStatus {
     394  my %args = @_;
     395
     396  _commoncheck(\%args, 'y');
     397
     398  my @arglist = ($dbh, $args{zoneid});
    360399  push @arglist, $args{status} if defined($args{status});
    361400
    362   my $status = DNSDB::domStatus(@arglist);
    363 }
    364 
    365 #sub importAXFR {
    366 #sub export {
    367 #sub __export_tiny {
     401  my $status = DNSDB::zoneStatus(@arglist);
     402}
     403
     404#sub importAXFR {}
     405#sub importBIND {}
     406#sub import_tinydns {}
     407#sub export {}
     408#sub __export_tiny {}
     409#sub _printrec_tiny {}
     410#sub mailNotify {}
    368411
    369412sub get_method_list {
Note: See TracChangeset for help on using the changeset viewer.