Changeset 544 for branches/stable/dns.cgi
- Timestamp:
- 12/10/13 17:15:56 (11 years ago)
- Location:
- branches/stable
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable
-
branches/stable/dns.cgi
r438 r544 62 62 63 63 # shut up some warnings, in case we arrive somewhere we forgot to set this 64 $webvar{defrec} = 'n' if !$webvar{defrec}; 64 $webvar{defrec} = 'n' if !$webvar{defrec}; # non-default records 65 $webvar{revrec} = 'n' if !$webvar{revrec}; # non-reverse (domain) records 65 66 66 67 # load some local system defaults (mainly DB connect info) … … 87 88 $session->param('domlistsortby','domain'); 88 89 $session->param('domlistorder','ASC'); 90 $session->param('revzonessortby','revnet'); 91 $session->param('revzonesorder','ASC'); 89 92 $session->param('useradminsortby','user'); 90 93 $session->param('useradminorder','ASC'); … … 204 207 my $page; 205 208 eval { 206 $page = HTML::Template->new(filename => "$templatedir/$webvar{page}.tmpl"); 209 # sigh. can't set loop_context_vars or global_vars once instantiated. 210 $page = HTML::Template->new(filename => "$templatedir/$webvar{page}.tmpl", 211 loop_context_vars => 1, global_vars => 1); 207 212 }; 208 213 if ($@) { 209 warn "Bad page $webvar{page} requested";214 my $msg = $@; 210 215 $page = HTML::Template->new(filename => "$templatedir/badpage.tmpl"); 211 $page->param(badpage => $q->escapeHTML($webvar{page})); 216 if (-e "$templatedir/$webvar{page}.tmpl") { 217 $page->param(badtemplate => $q->escapeHTML($msg)); 218 } else { 219 warn "Bad page $webvar{page} requested"; 220 $page->param(badpage => $q->escapeHTML($webvar{page})); 221 } 212 222 $webvar{page} = 'badpage'; 213 223 } … … 279 289 280 290 # I hate special cases. 291 ##fixme: probably need to handle webvar{revrec}=='y' too 281 292 if ($webvar{page} eq 'reclist' && $webvar{defrec} eq 'y') { 282 my %args = (page => $webvar{page}, id => $curgroup, defrec => $webvar{defrec} );293 my %args = (page => $webvar{page}, id => $curgroup, defrec => $webvar{defrec}, revrec => $webvar{revrec}); 283 294 $args{errmsg} = $errmsg if $errmsg; 284 295 changepage(%args); … … 300 311 301 312 } elsif ($webvar{page} eq 'domlist' or $webvar{page} eq 'index') { 313 314 $page->param(domlist => 1); 302 315 303 316 # hmm. seeing problems in some possibly-not-so-corner cases. … … 312 325 my $stat = domStatus($dbh,$webvar{id},$webvar{domstatus}); 313 326 ##fixme switch to more consise "Enabled <domain"/"Disabled <domain>" as with users? 314 logaction($webvar{id}, $session->param("username"), parentID($webvar{id}, 'dom', 'group'), 327 logaction($webvar{id}, $session->param("username"), 328 parentID($dbh, (id => $webvar{id}, type => 'domain', revrec => $webvar{revrec})), 315 329 "Changed ".domainName($dbh, $webvar{id})." state to ".($stat ? 'active' : 'inactive')); 316 330 $page->param(resultmsg => "Changed ".domainName($dbh, $webvar{id})." state to ". … … 366 380 367 381 my ($code,$msg) = addDomain($dbh,$webvar{domain},$webvar{group},($webvar{makeactive} eq 'on' ? 1 : 0), 368 ( name => $session->param("username"), id => $session->param("uid")));382 (username => $session->param("username"), id => $session->param("uid"))); 369 383 370 384 if ($code eq 'OK') { … … 401 415 402 416 } elsif ($webvar{del} eq 'ok') { 403 my $pargroup = parentID($ webvar{id}, 'dom', 'group');417 my $pargroup = parentID($dbh, (id => $webvar{id}, type => 'domain', revrec => $webvar{revrec})); 404 418 my $dom = domainName($dbh, $webvar{id}); 405 419 my ($code,$msg) = delDomain($dbh, $webvar{id}); … … 418 432 } 419 433 434 } elsif ($webvar{page} eq 'revzones') { 435 436 $webvar{revrec} = 'y'; 437 $page->param(curpage => $webvar{page}); 438 listzones(); 439 440 } elsif ($webvar{page} eq 'newrevzone') { 441 442 ## scope/access check - use domain settings? invent new (bleh) 443 changepage(page => "revzones", errmsg => "You are not permitted to add reverse zones") 444 unless ($permissions{admin} || $permissions{domain_create}); 445 446 fill_grouplist("grouplist"); 447 448 if ($webvar{add_failed}) { 449 $page->param(add_failed => 1); 450 $page->param(errmsg => $webvar{errmsg}); 451 $page->param(revzone => $webvar{revzone}); 452 $page->param(revpatt => $webvar{revpatt}); 453 } 454 455 } elsif ($webvar{page} eq 'addrevzone') { 456 457 changepage(page => "revzones", errmsg => "You are not permitted to add reverse zones") 458 unless ($permissions{admin} || $permissions{domain_create}); 459 460 # security check - does the user have permission to access this entity? 461 if (!check_scope(id => $webvar{group}, type => 'group')) { 462 changepage(page => "newrevzone", add_failed => 1, revzone => $webvar{revzone}, revpatt => $webvar{revpatt}, 463 errmsg => "You do not have permission to add a reverse zone to the requested group"); 464 } 465 466 my ($code,$msg) = addRDNS($dbh, $webvar{revzone}, $webvar{revpatt}, $webvar{group}, 467 ($webvar{makeactive} eq 'on' ? 1 : 0), 468 (username => $session->param("username"), id => $session->param("uid")) ); 469 470 if ($code eq 'OK') { 471 logaction(0, $session->param("username"), $webvar{group}, "Added reverse zone $webvar{revzone}", $msg); 472 changepage(page => "reclist", id => $msg, revrec => 'y'); 473 } else { 474 logaction(0, $session->param("username"), $webvar{group}, "Failed adding reverse zone $webvar{revzone} ($msg)"); 475 changepage(page => "newrevzone", add_failed => 1, revzone => $webvar{revzone}, revpatt => $webvar{revpatt}, 476 errmsg => $msg); 477 } 478 479 #} elsif ($webvar{page} eq 'delrevzone') { 480 420 481 } elsif ($webvar{page} eq 'reclist') { 421 482 422 483 # security check - does the user have permission to view this entity? 423 if (!check_scope(id => $webvar{id}, type => ($webvar{defrec} eq 'y' ? 'group' : 'domain'))) { 484 if (!check_scope(id => $webvar{id}, type => 485 ($webvar{defrec} eq 'y' ? 'group' : ($webvar{revrec} eq 'y' ? 'revzone' : 'domain')))) { 424 486 $page->param(errmsg => "You are not permitted to view or change the requested ". 425 ($webvar{defrec} eq 'y' ? "group's default records" : "domain's records")); 487 ($webvar{defrec} eq 'y' ? "group's default records" : 488 ($webvar{revrec} eq 'y' ? "reverse zone's records" : "domain's records"))); 426 489 $page->param(perm_err => 1); # this causes the template to skip the record listing output. 427 490 goto DONERECLIST; # and now we skip filling in the content which is not printed due to perm_err above … … 446 509 447 510 $page->param(defrec => $webvar{defrec}); 511 $page->param(revrec => $webvar{revrec}); 448 512 $page->param(id => $webvar{id}); 449 513 $page->param(curpage => $webvar{page}); 450 514 451 my $count = getRecCount($dbh, $webvar{defrec}, $webvar{ id}, $filter);515 my $count = getRecCount($dbh, $webvar{defrec}, $webvar{revrec}, $webvar{id}, $filter); 452 516 453 517 $sortby = 'host'; … … 460 524 461 525 # set up the headers 462 my @cols = ('host', 'type', 'val', 'distance', 'weight', 'port', 'ttl'); 463 my %colheads = (host => 'Name', type => 'Type', val => 'Address', 526 my @cols; 527 my %colheads; 528 if ($webvar{revrec} eq 'n') { 529 @cols = ('host', 'type', 'val', 'distance', 'weight', 'port', 'ttl'); 530 %colheads = (host => 'Name', type => 'Type', val => 'Address', 464 531 distance => 'Distance', weight => 'Weight', port => 'Port', ttl => 'TTL'); 465 my %custom = (id => $webvar{id}, defrec => $webvar{defrec}); 532 } else { 533 @cols = ('host', 'type', 'val', 'ttl'); 534 %colheads = (host => 'IP Address', type => 'Type', val => 'Hostname', ttl => 'TTL'); 535 } 536 my %custom = (id => $webvar{id}, defrec => $webvar{defrec}, revrec => $webvar{revrec}); 466 537 fill_colheads($sortby, $sortorder, \@cols, \%colheads, \%custom); 467 538 468 539 # fill the page-count and first-previous-next-last-all details 469 540 fill_pgcount($count,"records", 470 ($webvar{defrec} eq 'y' ? "group ".groupName($dbh,$webvar{id}) : domainName($dbh,$webvar{id}))); 541 ($webvar{defrec} eq 'y' ? "group ".groupName($dbh,$webvar{id}) : 542 ($webvar{revrec} eq 'y' ? revName($dbh,$webvar{id}) : domainName($dbh,$webvar{id})) 543 )); 471 544 fill_fpnla($count); # should put some params on this sub... 472 545 473 546 $page->param(defrec => $webvar{defrec}); 474 if ($webvar{defrec} eq 'y') { 475 showdomain('y',$curgroup); 476 } else { 477 showdomain('n',$webvar{id}); 547 showzone($webvar{defrec}, $webvar{revrec}, $webvar{id}); 548 if ($webvar{defrec} eq 'n') { 549 # showzone('n',$webvar{id}); 478 550 ##fixme: permission for viewing logs? 479 $page->param(logdom => 1); 551 ##fixme: determine which slice of the log we view (group, domain, revzone) 552 if ($webvar{revrec} eq 'n') { 553 $page->param(logdom => 1); 554 } else { 555 $page->param(logrdns => 1); 556 } 480 557 } 481 558 … … 484 561 $session->clear('resultmsg'); 485 562 } 563 if ($session->param('warnmsg')) { 564 $page->param(warnmsg => $session->param('warnmsg')); 565 $session->clear('warnmsg'); 566 } 486 567 if ($session->param('errmsg')) { 487 568 $page->param(errmsg => $session->param('errmsg')); … … 497 578 498 579 # security check - does the user have permission to access this entity? 499 if (!check_scope(id => $webvar{id}, type => ($webvar{defrec} eq 'y' ? 'defrec' : 'record'))) { 580 if (!check_scope(id => $webvar{id}, type => 581 ($webvar{defrec} eq 'y' ? ($webvar{revrec} eq 'y' ? 'defrevrec' : 'defrec') : 'record'))) { 500 582 $page->param(perm_err => "You are not permitted to edit the requested record"); 501 583 goto DONEREC; 502 584 } 503 585 # round 2, check the parent. 504 if (!check_scope(id => $webvar{parentid}, type => ($webvar{defrec} eq 'y' ? 'group' : 'domain'))) { 586 if (!check_scope(id => $webvar{parentid}, type => 587 ($webvar{defrec} eq 'y' ? 'group' : ($webvar{revrec} eq 'y' ? 'revzone' : 'domain')))) { 505 588 my $msg = ($webvar{defrec} eq 'y' ? 506 589 "You are not permitted to add or edit default records in the requested group" : 507 "You are not permitted to add or edit records in the requested domain ");590 "You are not permitted to add or edit records in the requested domain/zone"); 508 591 $page->param(perm_err => $msg); 509 592 goto DONEREC; 510 593 } 594 595 $page->param(defrec => $webvar{defrec}); 596 $page->param(revrec => $webvar{revrec}); 597 $page->param(fwdzone => $webvar{revrec} eq 'n'); 511 598 512 599 if ($webvar{recact} eq 'new') { … … 518 605 $page->param(recact => "add"); 519 606 $page->param(parentid => $webvar{parentid}); 520 $page->param(defrec => $webvar{defrec});521 607 522 608 fill_recdata(); … … 527 613 unless ($permissions{admin} || $permissions{record_create}); 528 614 529 ##fixme: this should probably go in DNSDB::addRec(), need to ponder what to do about PTR and friends 530 # prevent out-of-domain records from getting added by appending the domain, or DOMAIN for default records 531 my $pname = ($webvar{defrec} eq 'y' ? 'DOMAIN' : domainName($dbh,$webvar{parentid})); 532 $webvar{name} =~ s/\.*$/\.$pname/ if $webvar{name} !~ /$pname$/; 533 534 my @recargs = ($dbh,$webvar{defrec},$webvar{parentid},$webvar{name},$webvar{type},$webvar{address},$webvar{ttl}); 615 my @recargs = ($dbh,$webvar{defrec},$webvar{revrec},$webvar{parentid}, 616 \$webvar{name},\$webvar{type},\$webvar{address},$webvar{ttl}); 535 617 if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV}) { 536 618 push @recargs, $webvar{distance}; … … 543 625 my ($code,$msg) = addRec(@recargs); 544 626 545 if ($code eq 'OK') { 627 if ($code eq 'OK' || $code eq 'WARN') { 628 my $restr; 546 629 if ($webvar{defrec} eq 'y') { 547 my$restr = "Added default record '$webvar{name} $typemap{$webvar{type}}";630 $restr = "Added default record '$webvar{name} $typemap{$webvar{type}}"; 548 631 $restr .= " [distance $webvar{distance}]" if $typemap{$webvar{type}} eq 'MX'; 549 632 $restr .= " [priority $webvar{distance}] [weight $webvar{weight}] [port $webvar{port}]" … … 551 634 $restr .= " $webvar{address}', TTL $webvar{ttl}"; 552 635 logaction(0, $session->param("username"), $webvar{parentid}, $restr); 553 changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}, resultmsg => $restr);554 636 } else { 555 my$restr = "Added record '$webvar{name} $typemap{$webvar{type}}";637 $restr = "Added record '$webvar{name} $typemap{$webvar{type}}"; 556 638 $restr .= " [distance $webvar{distance}]" if $typemap{$webvar{type}} eq 'MX'; 557 639 $restr .= " [priority $webvar{distance}] [weight $webvar{weight}] [port $webvar{port}]" 558 640 if $typemap{$webvar{type}} eq 'SRV'; 559 641 $restr .= " $webvar{address}', TTL $webvar{ttl}"; 560 logaction($webvar{parentid}, $session->param("username"), parentID($webvar{parentid}, 'dom', 'group'), $restr); 561 changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}, resultmsg => $restr); 562 } 642 logaction($webvar{parentid}, $session->param("username"), 643 parentID($dbh, (id => $webvar{parentid}, type => 'domain', revrec => $webvar{revrec})), $restr); 644 } 645 my %pageparams = (page => "reclist", id => $webvar{parentid}, 646 defrec => $webvar{defrec}, revrec => $webvar{revrec}); 647 $pageparams{warnmsg} = $msg."<br><br>\n".$restr if $code eq 'WARN'; 648 $pageparams{resultmsg} = $restr if $code eq 'OK'; 649 changepage(%pageparams); 563 650 } else { 564 651 $page->param(failed => 1); … … 568 655 $page->param(recact => "add"); 569 656 $page->param(parentid => $webvar{parentid}); 570 $page->param(defrec => $webvar{defrec});571 657 $page->param(id => $webvar{id}); 572 658 fill_recdata(); # populate the form... er, mostly. 573 $page->param(name => $webvar{name});574 659 if ($config{log_failures}) { 575 660 if ($webvar{defrec} eq 'y') { … … 577 662 "Failed adding default record '$webvar{name} $typemap{$webvar{type}} $webvar{address}', TTL $webvar{ttl} ($msg)"); 578 663 } else { 579 logaction($webvar{parentid}, $session->param("username"), parentID($webvar{parentid}, 'dom', 'group'), 664 logaction($webvar{parentid}, $session->param("username"), 665 parentID($dbh, (id => $webvar{parentid}, type => 'domain', revrec => $webvar{revrec})), 580 666 "Failed adding record '$webvar{name} $typemap{$webvar{type}} $webvar{address}', TTL $webvar{ttl} ($msg)"); 581 667 } … … 592 678 $page->param(parentid => $webvar{parentid}); 593 679 $page->param(id => $webvar{id}); 594 $page->param(defrec => $webvar{defrec}); 595 my $recdata = getRecLine($dbh, $webvar{defrec}, $webvar{id}); 680 my $recdata = getRecLine($dbh, $webvar{defrec}, $webvar{revrec}, $webvar{id}); 596 681 $page->param(name => $recdata->{host}); 597 682 $page->param(address => $recdata->{val}); … … 600 685 $page->param(port => $recdata->{port}); 601 686 $page->param(ttl => $recdata->{ttl}); 602 fill_rectypes($recdata->{type});687 $page->param(typelist => getTypelist($dbh, $webvar{revrec}, $webvar{type})); 603 688 604 689 } elsif ($webvar{recact} eq 'update') { … … 613 698 614 699 # get current/previous record info so we can log "updated 'foo A 1.2.3.4' to 'foo A 2.3.4.5'" 615 my $oldrec = getRecLine($dbh, $webvar{defrec}, $webvar{ id});700 my $oldrec = getRecLine($dbh, $webvar{defrec}, $webvar{revrec}, $webvar{id}); 616 701 617 702 my ($code,$msg) = updateRec($dbh,$webvar{defrec},$webvar{id}, … … 629 714 my $restr = "Updated record from '$oldrec->{host} $typemap{$oldrec->{type}} $oldrec->{val}', TTL $oldrec->{ttl}\n". 630 715 "to '$webvar{name} $typemap{$webvar{type}} $webvar{address}', TTL $webvar{ttl}"; 631 logaction($webvar{parentid}, $session->param("username"), parentID($webvar{id}, 'rec', 'group'), $restr); 716 logaction($webvar{parentid}, $session->param("username"), 717 parentID($dbh, (id => $webvar{id}, type => 'record', defrec => $webvar{defrec}, 718 revrec => $webvar{revrec}, partype => 'group')), 719 $restr); 632 720 changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}, resultmsg => $restr); 633 721 } … … 639 727 $page->param(recact => "update"); 640 728 $page->param(parentid => $webvar{parentid}); 641 $page->param(defrec => $webvar{defrec});642 729 $page->param(id => $webvar{id}); 643 730 fill_recdata(); … … 647 734 "Failed updating default record '$typemap{$webvar{type}} $webvar{name} $webvar{address}', TTL $webvar{ttl} ($msg)"); 648 735 } else { 649 logaction($webvar{parentid}, $session->param("username"), parentID($webvar{parentid}, 'dom', 'group'), 736 logaction($webvar{parentid}, $session->param("username"), 737 parentID($dbh, (id => $webvar{parentid}, type => 'domain', revrec => $webvar{revrec})), 650 738 "Failed updating record '$typemap{$webvar{type}} $webvar{name} $webvar{address}', TTL $webvar{ttl} ($msg)"); 651 739 } … … 658 746 } else { 659 747 $page->param(parentid => $webvar{parentid}); 660 $page->param(dohere => domainName($dbh,$webvar{parentid})); 748 $page->param(dohere => domainName($dbh,$webvar{parentid})) if $webvar{revrec} eq 'n'; 749 $page->param(dohere => revName($dbh,$webvar{parentid})) if $webvar{revrec} eq 'y'; 661 750 } 662 751 … … 668 757 # This is a complete separate segment since it uses a different template from add/edit records above 669 758 670 changepage(page => "reclist", errmsg => "You are not permitted to delete records", id => $webvar{parentid}) 759 changepage(page => "reclist", errmsg => "You are not permitted to delete records", id => $webvar{parentid}, 760 defrec => $webvar{defrec}, revrec => $webvar{revrec}) 671 761 unless ($permissions{admin} || $permissions{record_delete}); 672 762 673 763 if (!check_scope(id => $webvar{id}, type => 674 764 ($webvar{defrec} eq 'y' ? ($webvar{revrec} eq 'y' ? 'defrevrec' : 'defrec') : 'record'))) { 675 changepage(page => 'domlist', errmsg => "You do not have permission to delete records in the requested ". 765 # redirect to domlist because we don't have permission for the entity requested 766 changepage(page => 'domlist', revrec => $webvar{revrec}, 767 errmsg => "You do not have permission to delete records in the requested ". 676 768 ($webvar{defrec} eq 'y' ? 'group' : 'domain')); 677 769 } … … 679 771 $page->param(id => $webvar{id}); 680 772 $page->param(defrec => $webvar{defrec}); 773 $page->param(revrec => $webvar{revrec}); 681 774 $page->param(parentid => $webvar{parentid}); 682 775 # first pass = confirm y/n (sorta) 683 776 if (!defined($webvar{del})) { 684 777 $page->param(del_getconf => 1); 685 my $rec = getRecLine($dbh, $webvar{defrec},$webvar{id});778 my $rec = getRecLine($dbh, $webvar{defrec}, $webvar{revrec}, $webvar{id}); 686 779 $page->param(host => $rec->{host}); 687 780 $page->param(ftype => $typemap{$rec->{type}}); … … 689 782 } elsif ($webvar{del} eq 'ok') { 690 783 # get rec data before we try to delete it 691 my $rec = getRecLine($dbh, $webvar{defrec},$webvar{id});692 my ($code,$msg) = delRec($dbh, $webvar{defrec},$webvar{id});784 my $rec = getRecLine($dbh, $webvar{defrec}, $webvar{revrec}, $webvar{id}); 785 my ($code,$msg) = delRec($dbh, $webvar{defrec}, $webvar{revrec}, $webvar{id}); 693 786 if ($code eq 'OK') { 694 787 if ($webvar{defrec} eq 'y') { 788 my $recclass = ($webvar{revrec} eq 'n' ? 'default record' : 'default reverse record'); 695 789 ##fixme: log distance for MX; log port/weight/distance for SRV 696 my $restr = "Deleted default record'$rec->{host} $typemap{$rec->{type}} $rec->{val}', TTL $rec->{ttl}";790 my $restr = "Deleted $recclass '$rec->{host} $typemap{$rec->{type}} $rec->{val}', TTL $rec->{ttl}"; 697 791 logaction(0, $session->param("username"), $rec->{parid}, $restr); 698 changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}, resultmsg => $restr); 792 changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}, 793 revrec => $webvar{revrec}, resultmsg => $restr); 699 794 } else { 700 my $restr = "Deleted record '$rec->{host} $typemap{$rec->{type}} $rec->{val}', TTL $rec->{ttl}"; 701 logaction($rec->{parid}, $session->param("username"), parentID($rec->{parid}, 'dom', 'group'), $restr); 702 changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}, resultmsg => $restr); 795 my $recclass = ($webvar{revrec} eq 'n' ? 'record' : 'reverse record'); 796 my $restr = "Deleted $recclass '$rec->{host} $typemap{$rec->{type}} $rec->{val}', TTL $rec->{ttl}"; 797 logaction($rec->{parid}, $session->param("username"), 798 parentID($dbh, (id => $rec->{parid}, type => 'domain', revrec => $webvar{revrec})), 799 $restr); 800 changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}, 801 revrec => $webvar{revrec}, resultmsg => $restr); 703 802 } 704 803 } else { … … 710 809 " TTL $rec->{ttl} ($msg)"); 711 810 } else { 712 logaction($rec->{parid}, $session->param("username"), parentID($rec->{parid}, 'dom', 'group'), 811 logaction($rec->{parid}, $session->param("username"), 812 parentID($dbh, (id => $rec->{parid}, type => 'domain', revrec => $webvar{revrec})), 713 813 "Failed deleting record '$rec->{host} $typemap{$rec->{type}} $rec->{val}', TTL $rec->{ttl} ($msg)"); 714 814 } 715 815 } 716 816 changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}, 717 errmsg => "Error deleting record: $msg");817 revrec => $webvar{revrec}, errmsg => "Error deleting record: $msg"); 718 818 } 719 819 } else { 720 changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec} );820 changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}, revrec => $webvar{revrec}); 721 821 } 722 822 … … 724 824 725 825 # security check - does the user have permission to view this entity? 726 if (!check_scope(id => $webvar{id}, type => ($webvar{defrec} eq 'y' ? 'group' : 'domain'))) { 826 # id is domain/revzone/group id 827 if (!check_scope(id => $webvar{id}, type => 828 ($webvar{defrec} eq 'y' ? 'group' : ($webvar{revrec} eq 'y' ? 'revzone' : 'domain')))) { 727 829 changepage(page => 'domlist', errmsg => "You do not have permission to edit the ". 728 830 ($webvar{defrec} eq 'y' ? 'default ' : '')."SOA record for the requested ". … … 744 846 # security check - does the user have permission to view this entity? 745 847 # pass 1, record ID 746 if (!check_scope(id => $webvar{recid}, type => ($webvar{defrec} eq 'y' ? 'defrec' : 'record'))) { 848 if (!check_scope(id => $webvar{recid}, type => 849 ($webvar{defrec} eq 'y' ? ($webvar{revrec} eq 'y' ? 'defrevrec' : 'defrec') : 'record'))) { 747 850 changepage(page => 'domlist', errmsg => "You do not have permission to edit the requested SOA record"); 748 851 } 749 852 # pass 2, parent (group or domain) ID 750 if (!check_scope(id => $webvar{id}, type => ($webvar{defrec} eq 'y' ? 'group' : 'domain'))) { 853 if (!check_scope(id => $webvar{id}, type => 854 ($webvar{defrec} eq 'y' ? 'group' : ($webvar{revrec} eq 'y' ? 'revzone' : 'domain')))) { 751 855 changepage(page => 'domlist', errmsg => "You do not have permission to edit the ". 752 856 ($webvar{defrec} eq 'y' ? 'default ' : '')."SOA record for the requested ". … … 787 891 $logdomain = 0; 788 892 } else { 789 $loggroup = parentID($ logdomain, 'dom', 'group', $webvar{defrec});893 $loggroup = parentID($dbh, (id => $logdomain, type => 'domain', revrec => $webvar{revrec})); 790 894 } 791 895 … … 898 1002 } elsif ($webvar{del} eq 'ok') { 899 1003 my $deleteme = groupName($dbh,$webvar{id}); # get this before we delete it... 900 my $delparent = parentID($ webvar{id}, 'group','group');1004 my $delparent = parentID($dbh, (id => $webvar{id}, type => 'group')); 901 1005 my ($code,$msg) = delGroup($dbh, $webvar{id}); 902 1006 if ($code eq 'OK') { … … 1041 1145 my ($code, $msg) = changeGroup($dbh, 'domain', $webvar{$_}, $webvar{destgroup}); 1042 1146 if ($code eq 'OK') { 1043 logaction($webvar{$_}, $session->param("username"), parentID($webvar{$_}, 'dom', 'group'), 1147 logaction($webvar{$_}, $session->param("username"), 1148 parentID($dbh, (id => $webvar{$_}, type => 'domain', revrec => $webvar{revrec})), 1044 1149 "Moved domain ".domainName($dbh, $webvar{$_})." to group $newgname"); 1045 1150 $row{domok} = ($code eq 'OK'); 1046 1151 } else { 1047 logaction($webvar{$_}, $session->param("username"), parentID($webvar{$_}, 'dom', 'group'), 1152 logaction($webvar{$_}, $session->param("username"), 1153 parentID($dbh, (id => $webvar{$_}, type => 'domain', revrec => $webvar{revrec})), 1048 1154 "Failed to move domain ".domainName($dbh, $webvar{$_})." to group $newgname: $msg") 1049 1155 if $config{log_failures}; … … 1072 1178 ##fixme: error handling on status change 1073 1179 my $stat = domStatus($dbh,$webvar{$_},($webvar{bulkaction} eq 'activate' ? 'domon' : 'domoff')); 1074 logaction($webvar{$_}, $session->param("username"), parentID($webvar{$_}, 'dom', 'group'), 1075 "Changed domain ".domainName($dbh, $webvar{$_})." state to ".($stat ? 'active' : 'inactive')); 1180 logaction($webvar{$_}, $session->param("username"), 1181 parentID($dbh, (id => $webvar{$_}, type => 'domain', revrec => $webvar{revrec})), 1182 "Changed domain ".domainName($dbh, $webvar{$_})." state to ".($stat ? 'active' : 'inactive')); 1076 1183 $row{domok} = 1; 1077 1184 # $row{domok} = ($code eq 'OK'); … … 1097 1204 } 1098 1205 $row{domain} = domainName($dbh,$webvar{$_}); 1099 my $pargroup = parentID($ webvar{$_}, 'dom', 'group');1206 my $pargroup = parentID($dbh, (id => $webvar{$_}, type => 'domain', revrec => $webvar{revrec})); 1100 1207 my $dom = domainName($dbh, $webvar{$_}); 1101 1208 my ($code, $msg) = delDomain($dbh, $webvar{$_}); … … 1130 1237 if ($flag && ($permissions{admin} || $permissions{user_edit})) { 1131 1238 my $stat = userStatus($dbh,$webvar{id},$webvar{userstatus}); 1132 logaction(0, $session->param("username"), parentID($ webvar{id}, 'user', 'group'),1239 logaction(0, $session->param("username"), parentID($dbh, (id => $webvar{id}, type => 'user')), 1133 1240 ($stat ? 'Enabled' : 'Disabled')." ".userFullName($dbh, $webvar{id}, '%u')); 1134 1241 $page->param(resultmsg => ($stat ? 'Enabled' : 'Disabled')." ".userFullName($dbh, $webvar{id}, '%u')); … … 1388 1495 1389 1496 $page->param(qfor => $webvar{qfor}) if $webvar{qfor}; 1390 fill_rectypes($webvar{type} ? $webvar{type} : '', 1);1497 $page->param(typelist => getTypelist($dbh, 'l', ($webvar{type} ? $webvar{type} : undef))); 1391 1498 $page->param(nrecurse => $webvar{nrecurse}) if $webvar{nrecurse}; 1392 1499 $page->param(resolver => $webvar{resolver}) if $webvar{resolver}; … … 1563 1670 } 1564 1671 $page->param(logfor => 'domain '.domainName($dbh,$id)); 1672 } elsif ($webvar{ltype} && $webvar{ltype} eq 'rdns') { 1673 $sql .= "rdns_id=?"; 1674 $id = $webvar{id}; 1675 if (!check_scope(id => $id, type => 'revzone')) { 1676 $page->param(errmsg => "You are not permitted to view log entries for the requested reverse zone"); 1677 goto DONELOG; 1678 } 1679 $page->param(logfor => 'reverse zone '.revName($dbh,$id)); 1565 1680 } else { 1566 1681 # Default to listing curgroup log … … 1570 1685 # group log is always for the "current" group 1571 1686 } 1687 ##fixme: 1688 # - filtering 1689 # - show reverse zone column? 1690 # - pagination/limiting number of records - put newest-first so user 1691 # doesn't always need to go to the last page for recent activity? 1572 1692 my $sth = $dbh->prepare($sql); 1573 1693 $sth->execute($id); … … 1601 1721 $page->param(logingrp => groupName($dbh,$logingroup)); 1602 1722 $page->param(logingrp_num => $logingroup); 1723 1724 ##fixme 1725 $page->param(mayrdns => 1); 1603 1726 1604 1727 $page->param(maydefrec => $permissions{admin}); … … 1696 1819 # handle user check 1697 1820 my $newurl = "http://$ENV{HTTP_HOST}$ENV{SCRIPT_NAME}?sid=$sid"; 1698 foreach ( keys %params) {1821 foreach (sort keys %params) { 1699 1822 $newurl .= "&$_=".$q->url_encode($params{$_}); 1700 1823 } … … 1743 1866 } 1744 1867 1745 sub show domain{1868 sub showzone { 1746 1869 my $def = shift; 1870 my $rev = shift; 1747 1871 my $id = shift; 1748 1872 1749 1873 # get the SOA first 1750 my %soa = getSOA($dbh,$def,$ id);1874 my %soa = getSOA($dbh,$def,$rev,$id); 1751 1875 1752 1876 $page->param(contact => $soa{contact}); … … 1758 1882 $page->param(ttl => $soa{ttl}); 1759 1883 1760 my $foo2 = getDomRecs($dbh,$def,$ id,$perpage,$webvar{offset},$sortby,$sortorder,$filter);1884 my $foo2 = getDomRecs($dbh,$def,$rev,$id,$perpage,$webvar{offset},$sortby,$sortorder,$filter); 1761 1885 1762 1886 my $row = 0; … … 1765 1889 $rec->{row} = $row % 2; 1766 1890 $rec->{defrec} = $def; 1891 $rec->{revrec} = $rev; 1767 1892 $rec->{sid} = $webvar{sid}; 1768 1893 $rec->{id} = $id; 1894 $rec->{fwdzone} = $rev eq 'n'; 1769 1895 $rec->{distance} = 'n/a' unless ($rec->{type} eq 'MX' || $rec->{type} eq 'SRV'); 1770 1896 $rec->{weight} = 'n/a' unless ($rec->{type} eq 'SRV'); … … 1778 1904 } 1779 1905 1780 # fill in record type list on add/update/edit record template1781 sub fill_rectypes {1782 my $type = shift || $reverse_typemap{A};1783 my $soaflag = shift || 0;1784 1785 my $sth = $dbh->prepare("SELECT val,name FROM rectypes WHERE stdflag=1 ORDER BY listorder");1786 $sth->execute;1787 my @typelist;1788 while (my ($rval,$rname) = $sth->fetchrow_array()) {1789 my %row = ( recval => $rval, recname => $rname );1790 $row{tselect} = 1 if $rval == $type;1791 push @typelist, \%row;1792 }1793 if ($soaflag) {1794 my %row = ( recval => $reverse_typemap{SOA}, recname => 'SOA' );1795 $row{tselect} = 1 if $reverse_typemap{SOA} == $type;1796 push @typelist, \%row;1797 }1798 $page->param(typelist => \@typelist);1799 } # fill_rectypes1800 1801 1906 sub fill_recdata { 1802 fill_rectypes($webvar{type});1907 $page->param(typelist => getTypelist($dbh, $webvar{revrec}, $webvar{type})); 1803 1908 1804 1909 # le sigh. we may get called with many empty %webvar keys … … 1807 1912 ##todo: allow BIND-style bare names, ASS-U-ME that the name is within the domain? 1808 1913 # prefill <domain> or DOMAIN in "Host" space for new records 1809 my $domroot = ($webvar{defrec} eq 'y' ? 'DOMAIN' : domainName($dbh,$webvar{parentid})); 1810 $page->param(name => $domroot); 1811 $page->param(address => $webvar{address}); 1812 $page->param(distance => $webvar{distance}) 1914 if ($webvar{revrec} eq 'n') { 1915 my $domroot = ($webvar{defrec} eq 'y' ? 'DOMAIN' : domainName($dbh,$webvar{parentid})); 1916 $page->param(name => $domroot); 1917 $page->param(address => $webvar{address}); 1918 $page->param(distance => $webvar{distance}) 1813 1919 if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV}); 1814 $page->param(weight => $webvar{weight}) if $webvar{type} == $reverse_typemap{SRV}; 1815 $page->param(port => $webvar{port}) if $webvar{type} == $reverse_typemap{SRV}; 1920 $page->param(weight => $webvar{weight}) if $webvar{type} == $reverse_typemap{SRV}; 1921 $page->param(port => $webvar{port}) if $webvar{type} == $reverse_typemap{SRV}; 1922 } else { 1923 my $domroot = ($webvar{defrec} eq 'y' ? 'ADMINDOMAIN' : ".$config{domain}"); 1924 $page->param(name => ($webvar{name} ? $webvar{name} : $domroot)); 1925 my $zname = ($webvar{defrec} eq 'y' ? 'ZONE' : revName($dbh,$webvar{parentid})); 1926 $zname =~ s|\d*/\d+$||; 1927 $page->param(address => ($webvar{address} ? $webvar{address} : $zname)); 1928 } 1816 1929 # retrieve the right ttl instead of falling (way) back to the hardcoded system default 1817 my %soa = getSOA($dbh,$webvar{defrec},$webvar{ parentid});1930 my %soa = getSOA($dbh,$webvar{defrec},$webvar{revrec},$webvar{parentid}); 1818 1931 $page->param(ttl => ($webvar{ttl} ? $webvar{ttl} : $soa{minttl})); 1819 1932 } … … 1893 2006 # on a page showing nothing. 1894 2007 # For bonus points, this reverts to the original offset on clicking the "All" link (mostly) 1895 if ($offset ne 'all') { 2008 if ($offset ne 'all') { 1896 2009 $offset-- while ($offset * $perpage) >= $pgcount; 1897 2010 } … … 1907 2020 } # end fill_pgcount() 1908 2021 1909 sub listdomains { 1910 2022 2023 sub listdomains { listzones(); } # temp 2024 2025 sub listzones { 1911 2026 # ACLs 1912 2027 $page->param(domain_create => ($permissions{admin} || $permissions{domain_create}) ); … … 1918 2033 my $childlist = join(',',@childgroups); 1919 2034 1920 my $sql = "SELECT count(*) FROM domains WHERE group_id IN ($curgroup".($childlist ? ",$childlist" : '').")". 1921 ($startwith ? " AND domain ~* ?" : ''). 1922 ($filter ? " AND domain ~* ?" : ''); 1923 my $sth = $dbh->prepare($sql); 1924 $sth->execute(@filterargs); 1925 my ($count) = $sth->fetchrow_array; 2035 my $count = getZoneCount($dbh, (childlist => $childlist, curgroup => $curgroup, revrec => $webvar{revrec}, 2036 filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef) ) ); 1926 2037 1927 2038 # fill page count and first-previous-next-last-all bits 1928 fill_pgcount($count, "domains",groupName($dbh,$curgroup));2039 fill_pgcount($count,($webvar{revrec} eq 'n' ? 'domains' : 'revzones'),groupName($dbh,$curgroup)); 1929 2040 fill_fpnla($count); 1930 2041 … … 1937 2048 1938 2049 # set up the headers 1939 my @cols = ( 'domain', 'status', 'group');1940 my %colheads = (domain => 'Domain', status => 'Status', group => 'Group');2050 my @cols = (($webvar{revrec} eq 'n' ? 'domain' : 'revnet'), 'status', 'group'); 2051 my %colheads = (domain => 'Domain', revnet => 'Reverse Zone', status => 'Status', group => 'Group'); 1941 2052 fill_colheads($sortby, $sortorder, \@cols, \%colheads); 1942 2053 … … 1946 2057 1947 2058 # waffle, waffle - keep state on these as well as sortby, sortorder? 2059 ##fixme: put this higher so the count doesn't get munched? 1948 2060 $page->param("start$startwith" => 1) if $startwith && $startwith =~ /^(?:[a-z]|0-9)$/; 1949 2061 … … 1951 2063 $page->param(searchsubs => $searchsubs) if $searchsubs; 1952 2064 1953 ##fixme1954 ##fixme push the SQL and direct database fiddling off into a sub in DNSDB.pm1955 ##fixme1956 1957 2065 $page->param(group => $curgroup); 1958 my @domlist; 1959 $sql = "SELECT domain_id,domain,status,groups.group_name AS group FROM domains". 1960 " INNER JOIN groups ON domains.group_id=groups.group_id". 1961 " WHERE domains.group_id IN ($curgroup".($childlist ? ",$childlist" : '').")". 1962 ($startwith ? " AND domain ~* ?" : ''). 1963 ($filter ? " AND domain ~* ?" : ''). 1964 " ORDER BY ".($sortby eq 'group' ? 'groups.group_name' : $sortby). 1965 " $sortorder ".($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage); 1966 $sth = $dbh->prepare($sql); 1967 $sth->execute(@filterargs); 1968 my $rownum = 0; 1969 while (my @data = $sth->fetchrow_array) { 1970 my %row; 1971 $row{domainid} = $data[0]; 1972 $row{domain} = $data[1]; 1973 $row{status} = ($data[2] ? 'Active' : 'Inactive'); 1974 $row{group} = $data[3]; 1975 $row{bg} = ($rownum++)%2; 1976 $row{mkactive} = !$data[2]; 1977 $row{sid} = $sid; 1978 $row{offset} = $offset; 1979 # ACLs 1980 $row{domain_edit} = ($permissions{admin} || $permissions{domain_edit}); 1981 $row{domain_delete} = ($permissions{admin} || $permissions{domain_delete}); 1982 push @domlist, \%row; 1983 } 1984 $page->param(domtable => \@domlist); 2066 2067 my $zonelist = getZoneList($dbh, (childlist => $childlist, curgroup => $curgroup, 2068 revrec => $webvar{revrec}, 2069 filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef), 2070 offset => $webvar{offset}, sortby => $sortby, sortorder => $sortorder 2071 ) ); 2072 # probably don't need this, keeping for reference for now 2073 # foreach (@$zonelist) { 2074 # } 2075 $page->param(domtable => $zonelist); 1985 2076 } # end listdomains() 1986 2077 … … 2221 2312 my $groupid = shift; 2222 2313 my $entry = shift; 2314 my $revid = shift || 0; 2223 2315 2224 2316 ##fixme: push SQL into DNSDB.pm … … 2228 2320 my ($user_id, $fullname) = $sth->fetchrow_array; 2229 2321 2230 $sth = $dbh->prepare("INSERT INTO log (domain_id,user_id,group_id,email,name,entry ) ".2231 "VALUES (?,?,?,?,?,? )") or warn $dbh->errstr;2232 $sth->execute($domid,$user_id,$groupid,$username,$fullname,$entry ) or warn $sth->errstr;2322 $sth = $dbh->prepare("INSERT INTO log (domain_id,user_id,group_id,email,name,entry,rdns_id) ". 2323 "VALUES (?,?,?,?,?,?,?)") or warn $dbh->errstr; 2324 $sth->execute($domid,$user_id,$groupid,$username,$fullname,$entry,$revid) or warn $sth->errstr; 2233 2325 } # end logaction() 2234 2235 2236 ##fixme: generalize to return appropriate id on all cases (ie, use $partype)2237 sub parentID {2238 my $id = shift;2239 my $idtype = shift;2240 my $partype = shift;2241 my $defrec = shift || '';2242 2243 my $sql = '';2244 2245 if ($idtype eq 'dom') {2246 return $id if $defrec eq 'y'; # "domain" + default records, we're really looking at a group.2247 $sql = "SELECT group_id FROM domains WHERE domain_id=?";2248 } elsif ($idtype eq 'rec') {2249 if ($defrec eq 'y') {2250 $sql = "SELECT group_id FROM default_records WHERE record_id=?";2251 } else {2252 $sql = "SELECT d.group_id FROM domains d".2253 " INNER JOIN records r ON d.domain_id=r.domain_id".2254 " WHERE r.record_id=?";2255 }2256 } elsif ($idtype eq 'group') {2257 $sql = "SELECT parent_group_id FROM groups WHERE group_id=?";2258 } elsif ($idtype eq 'user') {2259 $sql = "SELECT group_id FROM users WHERE user_id=?";2260 } else {2261 return "FOO", "BAR"; # can't get here.... we think.2262 }2263 my $sth = $dbh->prepare($sql);2264 $sth->execute($id);2265 my ($retid) = $sth->fetchrow_array;2266 return $retid if $retid;2267 # ahh! fall of the edge of the world if things went sideways2268 ##fixme: really need to do a little more error handling, I think2269 } # end parentID()2270 2326 2271 2327
Note:
See TracChangeset
for help on using the changeset viewer.