Changeset 545 for branches/stable/dns-rpc.cgi
- Timestamp:
- 12/10/13 17:47:44 (11 years ago)
- Location:
- branches/stable
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable
- Property svn:mergeinfo changed
/trunk merged: 264-316,318-416
- Property svn:mergeinfo changed
-
branches/stable/dns-rpc.cgi
r263 r545 3 3 ## 4 4 # $Id$ 5 # Copyright 201 1Kris Deugau <kdeugau@deepnet.cx>5 # Copyright 2012 Kris Deugau <kdeugau@deepnet.cx> 6 6 # 7 7 # This program is free software: you can redistribute it and/or modify … … 39 39 #package main; 40 40 41 loadConfig();41 DNSDB::loadConfig(rpcflag => 1); 42 42 43 43 # need to create a DNSDB object too … … 49 49 my $methods = { 50 50 'dnsdb.addDomain' => \&addDomain, 51 'dnsdb.delDomain' => \&delDomain, 51 'dnsdb.delZone' => \&delZone, 52 'dnsdb.addRDNS' => \&addRDNS, 52 53 'dnsdb.addGroup' => \&addGroup, 53 54 'dnsdb.delGroup' => \&delGroup, … … 60 61 'dnsdb.getRecCount' => \&getRecCount, 61 62 'dnsdb.addRec' => \&addRec, 63 'dnsdb.updateRec' => \&updateRec, 62 64 'dnsdb.delRec' => \&delRec, 63 'dnsdb. domStatus' => \&domStatus,65 'dnsdb.zoneStatus' => \&zoneStatus, 64 66 65 67 'dnsdb.getMethods' => \&get_method_list … … 71 73 72 74 # "Can't do that" errors 73 ##fixme: this MUST be loaded from a config file! Also must support multiple IPs74 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 }78 75 if (!$dbh) { 79 76 print "Content-type: text/xml\n\n".$res->{_decode}->encode_fault(5, $msg); … … 89 86 ## Subs below here 90 87 ## 88 89 # Utility subs 90 sub _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 97 sub _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 } 91 110 92 111 #sub connectDB { … … 103 122 my %args = @_; 104 123 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'); 108 125 109 126 my ($code, $msg) = DNSDB::addDomain($dbh, $args{domain}, $args{group}, $args{state}); … … 112 129 } 113 130 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 131 sub delZone { 132 my %args = @_; 133 134 _commoncheck(\%args, 'y'); 135 die "Need forward/reverse zone flag\n" if !$args{revrec}; 120 136 121 137 my ($code,$msg); 122 # Let's be nice; delete based on domid OR domainname. Saves an RPC call round-trip, maybe.123 if ($args{ domain} =~ /^\d+$/) {124 ($code,$msg) = DNSDB::del Domain($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}); 125 141 } 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 157 sub 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 {} 135 170 136 171 sub addGroup { 137 172 my %args = @_; 138 173 139 # Make sure we've got all the local bits we need140 die "Missing remote username" if !$args{rpcuser}; # for logging141 die "Missing remote system name" if !$args{rpcsystem}; # for logging142 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. :/ 144 179 # not to mention, permissions are checked at the UI layer, not the DB layer. 145 180 my $perms = {domain_edit => 1, domain_create => 1, domain_delete => 1, … … 155 190 my %args = @_; 156 191 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}; 160 194 161 195 my ($code,$msg); … … 165 199 } else { 166 200 my $grpid = DNSDB::groupID($dbh, $args{group}); 167 die "Can't find group " if !$grpid;201 die "Can't find group\n" if !$grpid; 168 202 ($code,$msg) = DNSDB::delGroup($dbh, $grpid); 169 203 } 170 204 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 {} 176 213 177 214 sub addUser { 178 215 my %args = @_; 179 216 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. :/ 185 220 # 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 => 1188 };189 221 # bend and twist; get those arguments in in the right order! 190 222 $args{type} = 'u' if !$args{type}; … … 200 232 } 201 233 202 #sub checkUser { 234 #sub getUserCount {} 235 #sub getUserList {} 236 #sub getUserDropdown {} 237 #sub checkUser {} 203 238 204 239 sub updateUser { 205 240 my %args = @_; 206 241 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 218 246 # bend and twist; get those arguments in in the right order! 247 $args{type} = 'u' if !$args{type}; 219 248 my @userargs = ($args{uid}, $args{username}, $args{group}, $args{pass}, $args{state}, $args{type}); 220 249 for my $argname ('fname','lname','phone') { … … 224 253 ##fixme: also underlying in DNSDB::updateUser(): no way to just update this or that attribute; 225 254 # 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; 228 258 } 229 259 … … 231 261 my %args = @_; 232 262 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}; 238 266 my ($code,$msg) = DNSDB::delUser($dbh, $args{uid}); 239 267 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 {} 245 282 246 283 sub getSOA { 247 284 my %args = @_; 248 285 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"; 257 292 } else { 258 die "No SOA record in domain";293 die "No SOA record in zone\n"; 259 294 } 260 295 } 261 return \%ret; 262 } 296 return $ret; 297 } 298 299 #sub updateSOA {} 263 300 264 301 sub getRecLine { 265 302 my %args = @_; 266 303 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}); 272 307 273 308 die $DNSDB::errstr if !$ret; … … 279 314 my %args = @_; 280 315 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 286 319 $args{nrecs} = 'all' if !$args{nrecs}; 287 320 $args{nstart} = 0 if !$args{nstart}; … … 290 323 $args{direction} = 'ASC' if !$args{direction}; 291 324 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}) ); 293 328 294 329 die $DNSDB::errstr if !$ret; … … 300 335 my %args = @_; 301 336 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; 307 351 } 308 352 … … 310 354 my %args = @_; 311 355 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}}, 318 360 $args{val}, $args{ttl}, $args{dist}, $args{weight}, $args{port}); 319 361 … … 324 366 my %args = @_; 325 367 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}}, 332 372 $args{val}, $args{ttl}, $args{dist}, $args{weight}, $args{port}); 333 373 … … 338 378 my %args = @_; 339 379 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 345 382 my ($code, $msg) = DNSDB::delRec($dbh, $args{def}, $args{recid}); 346 383 … … 348 385 } 349 386 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 393 sub zoneStatus { 394 my %args = @_; 395 396 _commoncheck(\%args, 'y'); 397 398 my @arglist = ($dbh, $args{zoneid}); 360 399 push @arglist, $args{status} if defined($args{status}); 361 400 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 {} 368 411 369 412 sub get_method_list {
Note:
See TracChangeset
for help on using the changeset viewer.