- Timestamp:
- 10/04/12 17:26:42 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dns-rpc.cgi
r401 r405 50 50 'dnsdb.addDomain' => \&addDomain, 51 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 … … 90 92 return 1 if grep /$ENV{REMOTE_ADDR}/, @{$DNSDB::config{rpcacl}{$subsys}}; 91 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 } 92 109 } 93 110 … … 105 122 my %args = @_; 106 123 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'); 111 125 112 126 my ($code, $msg) = DNSDB::addDomain($dbh, $args{domain}, $args{group}, $args{state}); … … 118 132 my %args = @_; 119 133 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 126 137 my ($code,$msg); 127 # Let's be nice; delete based on domid OR domainname. Saves an RPC call round-trip, maybe.128 if ($args{ domain} =~ /^\d+$/) {129 ($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}); 130 141 } 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 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 {} 140 170 141 171 sub addGroup { 142 172 my %args = @_; 143 173 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'); 148 175 149 176 # not sure how to usefully represent permissions from any further out from DNSDB.pm :/ … … 161 188 my %args = @_; 162 189 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'); 167 191 168 192 my ($code,$msg); … … 178 202 } 179 203 180 #sub getChildren { 181 #sub groupName { 182 #sub groupID { 204 #sub getChildren {} 205 #sub groupName {} 206 #sub getGroupCount {} 207 #sub getGroupList {} 208 #sub groupID {} 183 209 184 210 sub addUser { 185 211 my %args = @_; 186 212 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'); 191 214 192 215 # not sure how to usefully represent permissions from any further out from DNSDB.pm :/ … … 208 231 } 209 232 210 #sub checkUser { 233 #sub getUserCount {} 234 #sub getUserList {} 235 #sub getUserDropdown {} 236 #sub checkUser {} 211 237 212 238 sub updateUser { 213 239 my %args = @_; 214 240 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'); 219 242 220 243 die "Missing UID\n" if !$args{uid}; … … 240 263 my %args = @_; 241 264 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'); 246 266 247 267 die "Missing UID\n" if !$args{uid}; … … 250 270 } 251 271 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 {} 255 283 256 284 sub getSOA { 257 285 my %args = @_; 258 286 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); 263 288 264 289 my %ret = DNSDB::getSOA($dbh, $args{def}, $args{id}); … … 273 298 } 274 299 300 #sub updateSOA {} 301 275 302 sub getRecLine { 276 303 my %args = @_; 277 304 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); 282 306 283 307 my $ret = DNSDB::getRecLine($dbh, $args{def}, $args{id}); … … 291 315 my %args = @_; 292 316 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 299 320 $args{nrecs} = 'all' if !$args{nrecs}; 300 321 $args{nstart} = 0 if !$args{nstart}; … … 315 336 my %args = @_; 316 337 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; 323 354 } 324 355 … … 326 357 my %args = @_; 327 358 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. 334 362 my ($code, $msg) = DNSDB::addRec($dbh, $args{def}, $args{domid}, $args{host}, $DNSDB::typemap{$args{type}}, 335 363 $args{val}, $args{ttl}, $args{dist}, $args{weight}, $args{port}); … … 341 369 my %args = @_; 342 370 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. 349 374 my ($code, $msg) = DNSDB::updateRec($dbh, $args{def}, $args{recid}, $args{host}, $DNSDB::typemap{$args{type}}, 350 375 $args{val}, $args{ttl}, $args{dist}, $args{weight}, $args{port}); … … 356 381 my %args = @_; 357 382 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 364 385 my ($code, $msg) = DNSDB::delRec($dbh, $args{def}, $args{recid}); 365 386 … … 367 388 } 368 389 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 396 sub zoneStatus { 397 my %args = @_; 398 399 _commoncheck(\%args, 'y'); 400 401 my @arglist = ($dbh, $args{zoneid}); 380 402 push @arglist, $args{status} if defined($args{status}); 381 403 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 {} 388 414 389 415 sub get_method_list {
Note:
See TracChangeset
for help on using the changeset viewer.