Changeset 547 for branches/stable/dns.cgi
- Timestamp:
- 12/11/13 15:45:18 (11 years ago)
- Location:
- branches/stable
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable
-
branches/stable/dns.cgi
r546 r547 45 45 use lib '.'; ##uselib## 46 46 47 use DNSDB qw(:ALL);47 use DNSDB; 48 48 49 49 my @debugbits; # temp, to be spit out near the end of processing … … 69 69 # we'll catch a bad DB connect string once we get to trying that 70 70 ##fixme: pass params to loadConfig, and use them there, to allow one codebase to support multiple sites 71 if (!loadConfig()) { 72 warn "Using default configuration; unable to load custom settings: $DNSDB::errstr"; 71 my $dnsdb = new DNSDB; 72 73 my $header = HTML::Template->new(filename => "$templatedir/header.tmpl"); 74 my $footer = HTML::Template->new(filename => "$templatedir/footer.tmpl"); 75 $footer->param(version => $DNSDB::VERSION); 76 77 if (!$dnsdb) { 78 print "Content-type: text/html\n\n"; 79 print $header->output; 80 my $errpage = HTML::Template->new(filename => "$templatedir/dberr.tmpl"); 81 $errpage->param(errmsg => $DNSDB::errstr); 82 print $errpage->output; 83 print $footer->output; 84 exit; 73 85 } 86 87 $header->param(orgname => $dnsdb->{orgname}) if $dnsdb->{orgname} ne 'Example Corp'; 74 88 75 89 # persistent stuff needed on most/all pages 76 90 my $sid = ($webvar{sid} ? $webvar{sid} : undef); 77 my $session = new CGI::Session("driver:File", $sid, {Directory => $ config{sessiondir}})91 my $session = new CGI::Session("driver:File", $sid, {Directory => $dnsdb->{sessiondir}}) 78 92 or die CGI::Session->errstr(); 79 93 #$sid = $session->id() if !$sid; … … 81 95 # init stuff. can probably axe this down to just above if'n'when user manipulation happens 82 96 $sid = $session->id(); 83 $session->expire($ config{timeout});97 $session->expire($dnsdb->{timeout}); 84 98 # need to know the "upper" group the user can deal with; may as well 85 99 # stick this in the session rather than calling out to the DB every time. … … 149 163 push @filterargs, $filter if $filter; 150 164 151 # nrgh, can't handle login here because we don't have a database handle to check the user/pass with yet152 153 my $header = HTML::Template->new(filename => "$templatedir/header.tmpl");154 my $footer = HTML::Template->new(filename => "$templatedir/footer.tmpl");155 $header->param(orgname => $config{orgname}) if $config{orgname} ne 'Example Corp';156 $footer->param(version => $DNSDB::VERSION);157 158 165 ## set up "URL to self" 159 166 # @#$%@%@#% XHTML - & in a URL must be escaped. >:( … … 179 186 # pagination 180 187 my $perpage = 15; 181 $perpage = $ config{perpage} if $config{perpage};188 $perpage = $dnsdb->{perpage} if $dnsdb->{perpage}; 182 189 my $offset = ($webvar{offset} ? $webvar{offset} : 0); 183 190 … … 186 193 my $sortorder = "ASC"; 187 194 188 ##fixme: quit throwing the database handle around, and put all the SQL and direct DB fiddling into DNSDB.pm189 # dbname, user, pass, host (optional)190 my ($dbh,$msg) = connectDB($config{dbname}, $config{dbuser}, $config{dbpass}, $config{dbhost});191 192 if (!$dbh) {193 print "Content-type: text/html\n\n";194 print $header->output;195 my $errpage = HTML::Template->new(filename => "$templatedir/dberr.tmpl");196 $errpage->param(errmsg => $msg);197 print $errpage->output;198 print $footer->output;199 exit;200 }201 202 # Load config pieces from the database. Ideally all but the DB user/pass/etc should be loaded here.203 initGlobals($dbh);204 205 195 # security check - does the user have permission to view this entity? 206 196 # this is a prep step used "many" places 207 197 my @viewablegroups; 208 getChildren($dbh,$logingroup, \@viewablegroups, 'all');198 $dnsdb->getChildren($logingroup, \@viewablegroups, 'all'); 209 199 push @viewablegroups, $logingroup; 210 200 … … 232 222 # Snag ACL/permissions here too 233 223 234 my $userdata = login($dbh,$webvar{username}, $webvar{password});224 my $userdata = $dnsdb->login($webvar{username}, $webvar{password}); 235 225 236 226 if ($userdata) { … … 293 283 # but if they keep the session active they'll continue to have access long after being disabled. :/ 294 284 # Treat it as a session expiry. 295 if ($session->param('uid') && ! userStatus($dbh,$session->param('uid')) ) {285 if ($session->param('uid') && !$dnsdb->userStatus($session->param('uid')) ) { 296 286 $sid = ''; 297 287 $session->delete; # force expiry of the session Right Away … … 301 291 302 292 # Misc Things To Do on most pages 303 initPermissions($dbh, $session->param('uid')); 304 initActionLog($dbh, $session->param('uid')); 293 my %permissions; 294 $dnsdb->getPermissions('user', $session->param('uid'), \%permissions); 295 $dnsdb->initActionLog($session->param('uid')); 305 296 306 297 $page->param(sid => $sid) unless $webvar{page} eq 'login'; # no session ID on the login page … … 322 313 my $flag = 0; 323 314 foreach (@viewablegroups) { 324 $flag = 1 if isParent($dbh,$_, 'group', $webvar{id}, 'domain');315 $flag = 1 if $dnsdb->isParent($_, 'group', $webvar{id}, 'domain'); 325 316 } 326 317 if ($flag && ($permissions{admin} || $permissions{domain_edit})) { 327 my $stat = zoneStatus($dbh,$webvar{id},'n',$webvar{zonestatus});318 my $stat = $dnsdb->zoneStatus($webvar{id}, 'n', $webvar{zonestatus}); 328 319 $page->param(resultmsg => $DNSDB::resultstr); 329 320 } else { … … 372 363 $webvar{makeactive} = 0 if !defined($webvar{makeactive}); 373 364 374 my ($code,$msg) = addDomain($dbh,$webvar{domain},$webvar{group},($webvar{makeactive} eq 'on' ? 1 : 0));365 my ($code,$msg) = $dnsdb->addDomain($webvar{domain}, $webvar{group}, ($webvar{makeactive} eq 'on' ? 1 : 0)); 375 366 376 367 if ($code eq 'OK') { 377 mailNotify($dbh,"New ".($webvar{makeactive} eq 'on' ? 'Active' : 'Inactive')." Domain Created",368 $dnsdb->mailNotify("New ".($webvar{makeactive} eq 'on' ? 'Active' : 'Inactive')." Domain Created", 378 369 ($webvar{makeactive} eq 'on' ? 'Active' : 'Inactive').qq( domain "$webvar{domain}" added by ). 379 370 $session->param("username")); … … 402 393 403 394 $page->param(del_getconf => 1); 404 $page->param(domain => domainName($dbh,$webvar{id}));395 $page->param(domain => $dnsdb->domainName($webvar{id})); 405 396 406 397 } elsif ($webvar{del} eq 'ok') { 407 my $pargroup = parentID($dbh, (id => $webvar{id}, type => 'domain', revrec => $webvar{revrec}));408 my ($code,$msg) = delZone($dbh,$webvar{id}, $webvar{revrec});398 my $pargroup = $dnsdb->parentID(id => $webvar{id}, type => 'domain', revrec => $webvar{revrec}); 399 my ($code,$msg) = $dnsdb->delZone($webvar{id}, $webvar{revrec}); 409 400 if ($code eq 'OK') { 410 401 changepage(page => "domlist", resultmsg => $msg); … … 426 417 my $flag = 0; 427 418 foreach (@viewablegroups) { 428 $flag = 1 if isParent($dbh,$_, 'group', $webvar{id}, 'revzone');419 $flag = 1 if $dnsdb->isParent($_, 'group', $webvar{id}, 'revzone'); 429 420 } 430 421 if ($flag && ($permissions{admin} || $permissions{domain_edit})) { 431 my $stat = zoneStatus($dbh,$webvar{id},'y',$webvar{zonestatus});422 my $stat = $dnsdb->zoneStatus($webvar{id}, 'y', $webvar{zonestatus}); 432 423 $page->param(resultmsg => $DNSDB::resultstr); 433 424 } else { … … 449 440 450 441 fill_grouplist("grouplist"); 442 my $loclist = $dnsdb->getLocDropdown($curgroup); 443 $page->param(loclist => $loclist); 451 444 452 445 # prepopulate revpatt with the matching default record 453 # getRecByName($dbh, (revrec => $webvar{revrec}, defrec => $webvar{defrec}, host => 'string'));446 # $dnsdb->getRecByName(revrec => $webvar{revrec}, defrec => $webvar{defrec}, host => 'string'); 454 447 455 448 if ($session->param('add_failed')) { … … 472 465 } 473 466 474 my ($code,$msg) = addRDNS($dbh,$webvar{revzone}, $webvar{revpatt}, $webvar{group},475 ($webvar{makeactive} eq 'on' ? 1 : 0) );467 my ($code,$msg) = $dnsdb->addRDNS($webvar{revzone}, $webvar{revpatt}, $webvar{group}, 468 ($webvar{makeactive} eq 'on' ? 1 : 0), $webvar{location}); 476 469 477 470 if ($code eq 'OK') { … … 500 493 501 494 $page->param(del_getconf => 1); 502 $page->param(revzone => revName($dbh,$webvar{id}));495 $page->param(revzone => $dnsdb->revName($webvar{id})); 503 496 504 497 } elsif ($webvar{del} eq 'ok') { 505 my $pargroup = parentID($dbh, (id => $webvar{id}, type => 'revzone', revrec => $webvar{revrec}));506 my $zone = revName($dbh,$webvar{id});507 my ($code,$msg) = delZone($dbh,$webvar{id}, 'y');498 my $pargroup = $dnsdb->parentID(id => $webvar{id}, type => 'revzone', revrec => $webvar{revrec}); 499 my $zone = $dnsdb->revName($webvar{id}); 500 my ($code,$msg) = $dnsdb->delZone($webvar{id}, 'y'); 508 501 if ($code eq 'OK') { 509 502 changepage(page => "revzones", resultmsg => $msg); … … 551 544 $page->param(curpage => $webvar{page}); 552 545 553 my $count = getRecCount($dbh,$webvar{defrec}, $webvar{revrec}, $webvar{id}, $filter);546 my $count = $dnsdb->getRecCount($webvar{defrec}, $webvar{revrec}, $webvar{id}, $filter); 554 547 555 548 $sortby = 'host'; … … 577 570 # fill the page-count and first-previous-next-last-all details 578 571 fill_pgcount($count,"records", 579 ($webvar{defrec} eq 'y' ? "group ". groupName($dbh,$webvar{id}) :580 ($webvar{revrec} eq 'y' ? revName($dbh,$webvar{id}) : domainName($dbh,$webvar{id}))572 ($webvar{defrec} eq 'y' ? "group ".$dnsdb->groupName($webvar{id}) : 573 ($webvar{revrec} eq 'y' ? $dnsdb->revName($webvar{id}) : $dnsdb->domainName($webvar{id})) 581 574 )); 582 575 fill_fpnla($count); # should put some params on this sub... … … 633 626 634 627 if ($webvar{defrec} eq 'n') { 635 my $defloc = getZoneLocation($dbh,$webvar{revrec}, $webvar{parentid});628 my $defloc = $dnsdb->getZoneLocation($webvar{revrec}, $webvar{parentid}); 636 629 fill_loclist($curgroup, $defloc); 637 630 } … … 643 636 644 637 # location check - if user does not have record_locchg, set $webvar{location} to default location for zone 645 my $parloc = getZoneLocation($dbh,$webvar{revrec}, $webvar{parentid});638 my $parloc = $dnsdb->getZoneLocation($webvar{revrec}, $webvar{parentid}); 646 639 $webvar{location} = $parloc unless ($permissions{admin} || $permissions{record_locchg}); 647 640 648 my @recargs = ($ dbh,$webvar{defrec},$webvar{revrec},$webvar{parentid},649 \$webvar{name}, \$webvar{type},\$webvar{address},$webvar{ttl},$webvar{location});641 my @recargs = ($webvar{defrec}, $webvar{revrec}, $webvar{parentid}, 642 \$webvar{name}, \$webvar{type}, \$webvar{address}, $webvar{ttl}, $webvar{location}); 650 643 if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV}) { 651 644 push @recargs, $webvar{distance}; … … 656 649 } 657 650 658 my ($code,$msg) = addRec(@recargs);651 my ($code,$msg) = $dnsdb->addRec(@recargs); 659 652 660 653 if ($code eq 'OK' || $code eq 'WARN') { … … 687 680 $page->param(parentid => $webvar{parentid}); 688 681 $page->param(id => $webvar{id}); 689 my $recdata = getRecLine($dbh,$webvar{defrec}, $webvar{revrec}, $webvar{id});682 my $recdata = $dnsdb->getRecLine($webvar{defrec}, $webvar{revrec}, $webvar{id}); 690 683 $page->param(name => $recdata->{host}); 691 684 $page->param(address => $recdata->{val}); … … 694 687 $page->param(port => $recdata->{port}); 695 688 $page->param(ttl => $recdata->{ttl}); 696 $page->param(typelist => getTypelist($dbh,$webvar{revrec}, $recdata->{type}));689 $page->param(typelist => $dnsdb->getTypelist($webvar{revrec}, $recdata->{type})); 697 690 698 691 if ($webvar{defrec} eq 'n') { … … 706 699 707 700 # retain old location if user doesn't have permission to fiddle locations 708 my $oldrec = getRecLine($dbh,$webvar{defrec}, $webvar{revrec}, $webvar{id});701 my $oldrec = $dnsdb->getRecLine($webvar{defrec}, $webvar{revrec}, $webvar{id}); 709 702 $webvar{location} = $oldrec->{location} unless ($permissions{admin} || $permissions{record_locchg}); 710 703 711 my ($code,$msg) = updateRec($dbh,$webvar{defrec},$webvar{revrec},$webvar{id},$webvar{parentid},712 \$webvar{name}, \$webvar{type},\$webvar{address},$webvar{ttl},$webvar{location},713 $webvar{distance}, $webvar{weight},$webvar{port});704 my ($code,$msg) = $dnsdb->updateRec($webvar{defrec}, $webvar{revrec}, $webvar{id}, $webvar{parentid}, 705 \$webvar{name}, \$webvar{type}, \$webvar{address}, $webvar{ttl}, $webvar{location}, 706 $webvar{distance}, $webvar{weight}, $webvar{port}); 714 707 715 708 if ($code eq 'OK' || $code eq 'WARN') { … … 732 725 733 726 if ($webvar{defrec} eq 'y') { 734 $page->param(dohere => "default records in group ". groupName($dbh,$webvar{parentid}));727 $page->param(dohere => "default records in group ".$dnsdb->groupName($webvar{parentid})); 735 728 } else { 736 $page->param(dohere => domainName($dbh,$webvar{parentid})) if $webvar{revrec} eq 'n';737 $page->param(dohere => revName($dbh,$webvar{parentid})) if $webvar{revrec} eq 'y';729 $page->param(dohere => $dnsdb->domainName($webvar{parentid})) if $webvar{revrec} eq 'n'; 730 $page->param(dohere => $dnsdb->revName($webvar{parentid})) if $webvar{revrec} eq 'y'; 738 731 } 739 732 … … 764 757 if (!defined($webvar{del})) { 765 758 $page->param(del_getconf => 1); 766 my $rec = getRecLine($dbh,$webvar{defrec}, $webvar{revrec}, $webvar{id});759 my $rec = $dnsdb->getRecLine($webvar{defrec}, $webvar{revrec}, $webvar{id}); 767 760 $page->param(host => $rec->{host}); 768 761 $page->param(ftype => $typemap{$rec->{type}}); 769 762 $page->param(recval => $rec->{val}); 770 763 } elsif ($webvar{del} eq 'ok') { 771 my ($code,$msg) = delRec($dbh,$webvar{defrec}, $webvar{revrec}, $webvar{id});764 my ($code,$msg) = $dnsdb->delRec($webvar{defrec}, $webvar{revrec}, $webvar{id}); 772 765 if ($code eq 'OK') { 773 766 changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}, … … 824 817 unless ($permissions{admin} || $permissions{domain_edit}); 825 818 826 my ($code, $msg) = updateSOA($dbh,$webvar{defrec}, $webvar{revrec},819 my ($code, $msg) = $dnsdb->updateSOA($webvar{defrec}, $webvar{revrec}, 827 820 (contact => $webvar{contact}, prins => $webvar{prins}, refresh => $webvar{refresh}, 828 821 retry => $webvar{retry}, expire => $webvar{expire}, minttl => $webvar{minttl}, … … 878 871 } 879 872 } 880 # not gonna provide the 4th param: template-or-clone flag, just yet 881 my ($code,$msg) = addGroup($dbh, $webvar{newgroup}, $webvar{pargroup}, \%newperms); 873 # force inheritance of parent group's default records with inherit flag, 874 # otherwise we end up with the hardcoded defaults from DNSDB.pm. See 875 # https://secure.deepnet.cx/trac/dnsadmin/ticket/8 for the UI enhancement 876 # that will make this variable. 877 my ($code,$msg) = $dnsdb->addGroup($webvar{newgroup}, $webvar{pargroup}, \%newperms, 1); 882 878 if ($code eq 'OK') { 883 879 if ($alterperms) { … … 898 894 # fill default permissions with immediate parent's current ones 899 895 my %parperms; 900 getPermissions($dbh,'group', $curgroup, \%parperms);896 $dnsdb->getPermissions('group', $curgroup, \%parperms); 901 897 fill_permissions($page, \%parperms); 902 898 } … … 922 918 923 919 } elsif ($webvar{del} eq 'ok') { 924 my ($code,$msg) = delGroup($dbh,$webvar{id});920 my ($code,$msg) = $dnsdb->delGroup($webvar{id}); 925 921 if ($code eq 'OK') { 926 922 ##fixme: need to clean up log when deleting a major container … … 934 930 changepage(page => "grpman"); 935 931 } 936 $page->param(delgroupname => groupName($dbh,$webvar{id}));932 $page->param(delgroupname => $dnsdb->groupName($webvar{id})); 937 933 938 934 } elsif ($webvar{page} eq 'edgroup') { … … 949 945 # extra safety check; make sure user can't construct a URL to bypass ACLs 950 946 my %curperms; 951 getPermissions($dbh,'group', $webvar{gid}, \%curperms);947 $dnsdb->getPermissions('group', $webvar{gid}, \%curperms); 952 948 my %chperms; 953 949 my $alterperms = 0; … … 968 964 } 969 965 } 970 my ($code,$msg) = changePermissions($dbh,'group', $webvar{gid}, \%chperms);966 my ($code,$msg) = $dnsdb->changePermissions('group', $webvar{gid}, \%chperms); 971 967 if ($code eq 'OK') { 972 968 if ($alterperms) { 973 969 changepage(page => "grpman", warnmsg => 974 970 "You can only grant permissions you hold. Default permissions in group ". 975 groupName($dbh,$webvar{gid})." updated with reduced access");971 $dnsdb->groupName($webvar{gid})." updated with reduced access"); 976 972 } else { 977 973 changepage(page => "grpman", resultmsg => $msg); … … 983 979 } 984 980 $page->param(gid => $webvar{gid}); 985 $page->param(grpmeddle => groupName($dbh,$webvar{gid}));981 $page->param(grpmeddle => $dnsdb->groupName($webvar{gid})); 986 982 my %grpperms; 987 getPermissions($dbh,'group', $webvar{gid}, \%grpperms);983 $dnsdb->getPermissions('group', $webvar{gid}, \%grpperms); 988 984 fill_permissions($page, \%grpperms); 989 985 … … 998 994 fill_grouplist("grouplist"); 999 995 1000 my $count = getZoneCount($dbh, (revrec => 'n', curgroup => $curgroup));996 my $count = $dnsdb->getZoneCount(revrec => 'n', curgroup => $curgroup); 1001 997 1002 998 $page->param(curpage => $webvar{page}); 1003 fill_pgcount($count, 'domains',groupName($dbh,$curgroup));999 fill_pgcount($count, 'domains', $dnsdb->groupName($curgroup)); 1004 1000 fill_fpnla($count); 1005 1001 $page->param(perpage => $perpage); 1006 1002 1007 my $domlist = getZoneList($dbh, (revrec => 'n', curgroup => $curgroup));1003 my $domlist = $dnsdb->getZoneList(revrec => 'n', curgroup => $curgroup); 1008 1004 my $rownum = 0; 1009 1005 foreach my $dom (@{$domlist}) { … … 1031 1027 changepage(page => "domlist", errmsg => "You are not permitted to bulk-move domains") 1032 1028 unless ($permissions{admin} || ($permissions{domain_edit} && $permissions{domain_create} && $permissions{domain_delete})); 1033 my $newgname = groupName($dbh,$webvar{destgroup});1029 my $newgname = $dnsdb->groupName($webvar{destgroup}); 1034 1030 $page->param(action => "Move to group $newgname"); 1035 1031 } elsif ($webvar{bulkaction} eq 'deactivate' || $webvar{bulkaction} eq 'activate') { … … 1061 1057 next; 1062 1058 } 1063 $row{domain} = domainName($dbh,$webvar{$_});1059 $row{domain} = $dnsdb->domainName($webvar{$_}); 1064 1060 1065 1061 # Do the $webvar{bulkaction} 1066 1062 my ($code, $msg); 1067 ($code, $msg) = changeGroup($dbh,'domain', $webvar{$_}, $webvar{destgroup})1063 ($code, $msg) = $dnsdb->changeGroup('domain', $webvar{$_}, $webvar{destgroup}) 1068 1064 if $webvar{bulkaction} eq 'move'; 1069 1065 if ($webvar{bulkaction} eq 'deactivate' || $webvar{bulkaction} eq 'activate') { 1070 my $stat = zoneStatus($dbh,$webvar{$_},'n',($webvar{bulkaction} eq 'activate' ? 'domon' : 'domoff'));1066 my $stat = $dnsdb->zoneStatus($webvar{$_}, 'n', ($webvar{bulkaction} eq 'activate' ? 'domon' : 'domoff')); 1071 1067 $code = (defined($stat) ? 'OK' : 'FAIL'); 1072 1068 $msg = (defined($stat) ? $DNSDB::resultstr : $DNSDB::errstr); 1073 1069 } 1074 ($code, $msg) = delZone($dbh,$webvar{$_}, 'n')1070 ($code, $msg) = $dnsdb->delZone($webvar{$_}, 'n') 1075 1071 if $webvar{bulkaction} eq 'delete'; 1076 1072 … … 1097 1093 my $flag = 0; 1098 1094 foreach (@viewablegroups) { 1099 $flag = 1 if isParent($dbh,$_, 'group', $webvar{id}, 'user');1095 $flag = 1 if $dnsdb->isParent($_, 'group', $webvar{id}, 'user'); 1100 1096 } 1101 1097 if ($flag && ($permissions{admin} || $permissions{user_edit} || 1102 1098 ($permissions{self_edit} && $webvar{id} == $session->param('uid')) )) { 1103 my $stat = userStatus($dbh,$webvar{id},$webvar{userstatus});1099 my $stat = $dnsdb->userStatus($webvar{id}, $webvar{userstatus}); 1104 1100 $page->param(resultmsg => $DNSDB::resultstr); 1105 1101 } else { … … 1129 1125 fill_clonemelist(); 1130 1126 my %grpperms; 1131 getPermissions($dbh,'group', $curgroup, \%grpperms);1127 $dnsdb->getPermissions('group', $curgroup, \%grpperms); 1132 1128 1133 1129 my $grppermlist = new HTML::Template(filename => "$templatedir/permlist.tmpl"); … … 1151 1147 1152 1148 my %newperms; # we're going to prefill the existing permissions, so we can change them. 1153 getPermissions($dbh,'user', $webvar{uid}, \%newperms);1149 $dnsdb->getPermissions('user', $webvar{uid}, \%newperms); 1154 1150 1155 1151 if ($webvar{pass1} ne $webvar{pass2}) { … … 1166 1162 if (!$permissions{admin}) { 1167 1163 my %grpperms; 1168 getPermissions($dbh,'group', $curgroup, \%grpperms);1164 $dnsdb->getPermissions('group', $curgroup, \%grpperms); 1169 1165 my $ret = comparePermissions(\%permissions, \%grpperms); 1170 1166 if ($ret eq '<' || $ret eq '!') { … … 1188 1184 } elsif ($permissions{admin} && $webvar{perms_type} eq 'clone') { 1189 1185 $permstring = "c:$webvar{clonesrc}"; 1190 getPermissions($dbh,'user', $webvar{clonesrc}, \%newperms);1186 $dnsdb->getPermissions('user', $webvar{clonesrc}, \%newperms); 1191 1187 $page->param(perm_clone => 1); 1192 1188 } else { … … 1204 1200 unless $permissions{admin} || $permissions{user_create}; 1205 1201 # no scope check; user is created in the current group 1206 ($code,$msg) = addUser($dbh,$webvar{uname}, $curgroup, $webvar{pass1},1202 ($code,$msg) = $dnsdb->addUser($webvar{uname}, $curgroup, $webvar{pass1}, 1207 1203 ($webvar{makeactive} eq 'on' ? 1 : 0), $webvar{accttype}, $permstring, 1208 1204 $webvar{fname}, $webvar{lname}, $webvar{phone}); … … 1219 1215 # or self-torture trying to not commit the transaction until we're really done. 1220 1216 # Allowing for changing group, but not coding web support just yet. 1221 ($code,$msg) = updateUser($dbh,$webvar{uid}, $webvar{uname}, $webvar{gid}, $webvar{pass1},1217 ($code,$msg) = $dnsdb->updateUser($webvar{uid}, $webvar{uname}, $webvar{gid}, $webvar{pass1}, 1222 1218 ($webvar{makeactive} eq 'on' ? 1 : 0), $webvar{accttype}, 1223 1219 $webvar{fname}, $webvar{lname}, $webvar{phone}); 1224 1220 if ($code eq 'OK') { 1225 1221 $newperms{admin} = 1 if $webvar{accttype} eq 'S'; 1226 ($code2,$msg2) = changePermissions($dbh,'user', $webvar{uid}, \%newperms, ($permstring eq 'i'));1222 ($code2,$msg2) = $dnsdb->changePermissions('user', $webvar{uid}, \%newperms, ($permstring eq 'i')); 1227 1223 } 1228 1224 } … … 1280 1276 fill_clonemelist(); 1281 1277 1282 my $userinfo = getUserData($dbh,$webvar{user});1278 my $userinfo = $dnsdb->getUserData($webvar{user}); 1283 1279 fill_actypelist($userinfo->{type}); 1284 1280 # not using this yet, but adding it now means we can *much* more easily do so later. … … 1286 1282 1287 1283 my %curperms; 1288 getPermissions($dbh,'user', $webvar{user}, \%curperms);1284 $dnsdb->getPermissions('user', $webvar{user}, \%curperms); 1289 1285 fill_permissions($page, \%curperms); 1290 1286 … … 1322 1318 if (!defined($webvar{del})) { 1323 1319 $page->param(del_getconf => 1); 1324 $page->param(user => userFullName($dbh,$webvar{id}));1320 $page->param(user => $dnsdb->userFullName($webvar{id})); 1325 1321 } elsif ($webvar{del} eq 'ok') { 1326 my ($code,$msg) = delUser($dbh,$webvar{id});1322 my ($code,$msg) = $dnsdb->delUser($webvar{id}); 1327 1323 if ($code eq 'OK') { 1328 1324 # success. go back to the user list, do not pass "GO" … … 1368 1364 unless ($permissions{admin} || $permissions{location_create}); 1369 1365 1370 my ($code,$msg) = addLoc($dbh,$curgroup, $webvar{locname}, $webvar{comments}, $webvar{iplist});1366 my ($code,$msg) = $dnsdb->addLoc($curgroup, $webvar{locname}, $webvar{comments}, $webvar{iplist}); 1371 1367 1372 1368 if ($code eq 'OK' || $code eq 'WARN') { … … 1392 1388 unless ($permissions{admin} || $permissions{location_edit}); 1393 1389 1394 my $loc = getLoc($dbh,$webvar{loc});1390 my $loc = $dnsdb->getLoc($webvar{loc}); 1395 1391 $page->param(wastrying => "editing"); 1396 1392 $page->param(todo => "Edit location/view"); … … 1405 1401 unless ($permissions{admin} || $permissions{location_edit}); 1406 1402 1407 my ($code,$msg) = updateLoc($dbh,$webvar{id}, $curgroup, $webvar{locname}, $webvar{comments}, $webvar{iplist});1403 my ($code,$msg) = $dnsdb->updateLoc($webvar{id}, $curgroup, $webvar{locname}, $webvar{comments}, $webvar{iplist}); 1408 1404 1409 1405 if ($code eq 'OK') { … … 1443 1439 1444 1440 $page->param(locid => $webvar{locid}); 1445 my $locdata = getLoc($dbh,$webvar{locid});1441 my $locdata = $dnsdb->getLoc($webvar{locid}); 1446 1442 $locdata->{description} = $webvar{locid} if !$locdata->{description}; 1447 1443 # first pass = confirm y/n (sorta) … … 1450 1446 $page->param(location => $locdata->{description}); 1451 1447 } elsif ($webvar{del} eq 'ok') { 1452 my ($code,$msg) = delLoc($dbh,$webvar{locid});1448 my ($code,$msg) = $dnsdb->delLoc($webvar{locid}); 1453 1449 if ($code eq 'OK') { 1454 1450 # success. go back to the user list, do not pass "GO" … … 1465 1461 1466 1462 $page->param(qfor => $webvar{qfor}) if $webvar{qfor}; 1467 $page->param(typelist => getTypelist($dbh,'l', ($webvar{type} ? $webvar{type} : undef)));1463 $page->param(typelist => $dnsdb->getTypelist('l', ($webvar{type} ? $webvar{type} : undef))); 1468 1464 $page->param(nrecurse => $webvar{nrecurse}) if $webvar{nrecurse}; 1469 1465 $page->param(resolver => $webvar{resolver}) if $webvar{resolver}; … … 1567 1563 foreach my $domain (@domlist) { 1568 1564 my %row; 1569 my ($code,$msg) = importAXFR($dbh, $webvar{ifrom}, $domain, $webvar{group}, 1570 $webvar{domstatus}, $webvar{rwsoa}, $webvar{rwns}, ($webvar{forcettl} ? $webvar{newttl} : 0), 1571 $webvar{mergematching}); 1565 my ($code,$msg) = $dnsdb->importAXFR($webvar{ifrom}, $domain, $webvar{group}, 1566 status => $webvar{domactive}, rwsoa => $webvar{rwsoa}, rwns => $webvar{rwns}, 1567 newttl => ($webvar{forcettl} ? $webvar{newttl} : 0), 1568 merge => $webvar{mergematching}); 1572 1569 $row{domok} = $msg if $code eq 'OK'; 1573 1570 if ($code eq 'WARN') { … … 1632 1629 goto DONELOG; 1633 1630 } 1634 $page->param(logfor => 'user '. userFullName($dbh,$id));1631 $page->param(logfor => 'user '.$dnsdb->userFullName($id)); 1635 1632 } elsif ($webvar{ltype} && $webvar{ltype} eq 'dom') { 1636 1633 $id = $webvar{id}; … … 1639 1636 goto DONELOG; 1640 1637 } 1641 $page->param(logfor => 'domain '. domainName($dbh,$id));1638 $page->param(logfor => 'domain '.$dnsdb->domainName($id)); 1642 1639 } elsif ($webvar{ltype} && $webvar{ltype} eq 'rdns') { 1643 1640 $id = $webvar{id}; … … 1646 1643 goto DONELOG; 1647 1644 } 1648 $page->param(logfor => 'reverse zone '. revName($dbh,$id));1645 $page->param(logfor => 'reverse zone '.$dnsdb->revName($id)); 1649 1646 } else { 1650 1647 # Default to listing curgroup log 1651 $page->param(logfor => 'group '. groupName($dbh,$id));1648 $page->param(logfor => 'group '.$dnsdb->groupName($id)); 1652 1649 # note that scope limitations are applied via the change-group check; 1653 1650 # group log is always for the "current" group 1654 1651 } 1655 1652 $webvar{ltype} = 'group' if !$webvar{ltype}; 1656 my $lcount = getLogCount($dbh, (id => $id, logtype => $webvar{ltype})) or push @debugbits, $DNSDB::errstr;1653 my $lcount = $dnsdb->getLogCount(id => $id, logtype => $webvar{ltype}) or push @debugbits, $dnsdb->errstr; 1657 1654 1658 1655 $page->param(id => $id); … … 1674 1671 # Set up the column headings with the sort info 1675 1672 my @cols = ('fname','username','entry','stamp'); 1676 my %colnames = (fname => 'Name', username => 'Username /Email', entry => 'Log Entry', stamp => 'Date/Time');1673 my %colnames = (fname => 'Name', username => 'Username', entry => 'Log Entry', stamp => 'Date/Time'); 1677 1674 fill_colheads($sortby, $sortorder, \@cols, \%colnames); 1678 1675 1679 1676 ##fixme: increase per-page limit or use separate limit for log? some ops give *lots* of entries... 1680 my $logentries = getLogEntries($dbh,(id => $id, logtype => $webvar{ltype},1681 offset => $webvar{offset}, sortby => $sortby, sortorder => $sortorder) );1677 my $logentries = $dnsdb->getLogEntries(id => $id, logtype => $webvar{ltype}, 1678 offset => $webvar{offset}, sortby => $sortby, sortorder => $sortorder); 1682 1679 $page->param(logentries => $logentries); 1683 1680 … … 1704 1701 1705 1702 $page->param(group => $curgroup); 1706 $page->param(groupname => groupName($dbh,$curgroup));1707 $page->param(logingrp => groupName($dbh,$logingroup));1703 $page->param(groupname => $dnsdb->groupName($curgroup)); 1704 $page->param(logingrp => $dnsdb->groupName($logingroup)); 1708 1705 $page->param(logingrp_num => $logingroup); 1709 1706 … … 1771 1768 1772 1769 my $grptree = HTML::Template->new(filename => 'templates/grptree.tmpl'); 1773 getChildren($dbh,$root,\@childlist,'immediate');1770 $dnsdb->getChildren($root, \@childlist, 'immediate'); 1774 1771 return if $#childlist == -1; 1775 1772 my @grouplist; 1776 1773 foreach (@childlist) { 1777 1774 my %row; 1778 $row{grpname} = groupName($dbh,$_);1775 $row{grpname} = $dnsdb->groupName($_); 1779 1776 $row{grpnum} = $_; 1780 1777 $row{whereami} = $uri_self; 1781 1778 $row{curgrp} = ($_ == $cur); 1782 $row{expanded} = isParent($dbh,$_, 'group', $cur, 'group');1779 $row{expanded} = $dnsdb->isParent($_, 'group', $cur, 'group'); 1783 1780 $row{expanded} = 1 if $_ == $cur; 1784 1781 $row{subs} = fill_grptree($_,$cur,$indent.' '); … … 1810 1807 my $newurl = "http://$ENV{HTTP_HOST}$ENV{SCRIPT_NAME}?sid=$sid"; 1811 1808 foreach (sort keys %params) { 1809 ## fixme: something is undefined here on add location 1812 1810 $newurl .= "&$_=".$q->url_encode($params{$_}); 1813 1811 } … … 1851 1849 # $page->param(group => $DNSDB::group); 1852 1850 $page->param(isgrp => 1) if $defrec eq 'y'; 1853 $page->param(parent => ($defrec eq 'y' ? groupName($dbh,$id) :1854 ($revrec eq 'n' ? domainName($dbh, $id) : revName($dbh,$id)) ) );1851 $page->param(parent => ($defrec eq 'y' ? $dnsdb->groupName($id) : 1852 ($revrec eq 'n' ? $dnsdb->domainName($id) : $dnsdb->revName($id)) ) ); 1855 1853 1856 1854 # defaults … … 1867 1865 if ($preserve eq 'd') { 1868 1866 # there are probably better ways to do this. TMTOWTDI. 1869 my $soa = getSOA($dbh,$defrec,$revrec,$id);1867 my $soa = $dnsdb->getSOA($defrec, $revrec, $id); 1870 1868 1871 1869 $page->param(prins => ($soa->{prins} ? $soa->{prins} : $DNSDB::def{prins})); … … 1893 1891 1894 1892 # get the SOA first 1895 my $soa = getSOA($dbh,$def,$rev,$id);1893 my $soa = $dnsdb->getSOA($def, $rev, $id); 1896 1894 1897 1895 $page->param(contact => $soa->{contact}); … … 1903 1901 $page->param(ttl => $soa->{ttl}); 1904 1902 1905 my $foo2 = getDomRecs($dbh,(defrec => $def, revrec => $rev, id => $id, offset => $webvar{offset},1906 sortby => $sortby, sortorder => $sortorder, filter => $filter) );1903 my $foo2 = $dnsdb->getDomRecs(defrec => $def, revrec => $rev, id => $id, offset => $webvar{offset}, 1904 sortby => $sortby, sortorder => $sortorder, filter => $filter); 1907 1905 1908 1906 foreach my $rec (@$foo2) { … … 1922 1920 1923 1921 sub fill_recdata { 1924 $page->param(typelist => getTypelist($dbh,$webvar{revrec}, $webvar{type}));1922 $page->param(typelist => $dnsdb->getTypelist($webvar{revrec}, $webvar{type})); 1925 1923 1926 1924 # le sigh. we may get called with many empty %webvar keys … … 1930 1928 # prefill <domain> or DOMAIN in "Host" space for new records 1931 1929 if ($webvar{revrec} eq 'n') { 1932 my $domroot = ($webvar{defrec} eq 'y' ? 'DOMAIN' : domainName($dbh,$webvar{parentid}));1930 my $domroot = ($webvar{defrec} eq 'y' ? 'DOMAIN' : $dnsdb->domainName($webvar{parentid})); 1933 1931 $page->param(name => ($webvar{name} ? $webvar{name} : $domroot)); 1934 1932 $page->param(address => $webvar{address}); … … 1938 1936 $page->param(port => $webvar{port}) if $webvar{type} == $reverse_typemap{SRV}; 1939 1937 } else { 1940 my $domroot = ($webvar{defrec} eq 'y' ? 'ADMINDOMAIN' : ".$ config{domain}");1938 my $domroot = ($webvar{defrec} eq 'y' ? 'ADMINDOMAIN' : ".$dnsdb->{domain}"); 1941 1939 $page->param(name => ($webvar{name} ? $webvar{name} : $domroot)); 1942 my $zname = ($webvar{defrec} eq 'y' ? 'ZONE' : revName($dbh,$webvar{parentid}));1940 my $zname = ($webvar{defrec} eq 'y' ? 'ZONE' : $dnsdb->revName($webvar{parentid})); 1943 1941 $zname =~ s|\d*/\d+$||; 1944 1942 $page->param(address => ($webvar{address} ? $webvar{address} : $zname)); 1945 1943 } 1946 1944 # retrieve the right ttl instead of falling (way) back to the hardcoded system default 1947 my $soa = getSOA($dbh,$webvar{defrec},$webvar{revrec},$webvar{parentid});1945 my $soa = $dnsdb->getSOA($webvar{defrec}, $webvar{revrec}, $webvar{parentid}); 1948 1946 $page->param(ttl => ($webvar{ttl} ? $webvar{ttl} : $soa->{minttl})); 1949 1947 } … … 1969 1967 local $webvar{clonesrc} = 0 if !defined($webvar{clonesrc}); 1970 1968 1971 my $clones = getUserDropdown($dbh,$curgroup, $webvar{clonesrc});1969 my $clones = $dnsdb->getUserDropdown($curgroup, $webvar{clonesrc}); 1972 1970 $page->param(clonesrc => $clones); 1973 1971 } … … 2036 2034 2037 2035 my @childgroups; 2038 getChildren($dbh,$curgroup, \@childgroups, 'all') if $searchsubs;2036 $dnsdb->getChildren($curgroup, \@childgroups, 'all') if $searchsubs; 2039 2037 my $childlist = join(',',@childgroups); 2040 2038 2041 my $count = getZoneCount($dbh,(childlist => $childlist, curgroup => $curgroup, revrec => $webvar{revrec},2042 filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef) ) );2039 my $count = $dnsdb->getZoneCount(childlist => $childlist, curgroup => $curgroup, revrec => $webvar{revrec}, 2040 filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef) ); 2043 2041 2044 2042 # fill page count and first-previous-next-last-all bits 2045 fill_pgcount($count,($webvar{revrec} eq 'n' ? 'domains' : 'revzones'), groupName($dbh,$curgroup));2043 fill_pgcount($count,($webvar{revrec} eq 'n' ? 'domains' : 'revzones'),$dnsdb->groupName($curgroup)); 2046 2044 fill_fpnla($count); 2047 2045 … … 2071 2069 $page->param(group => $curgroup); 2072 2070 2073 my $zonelist = getZoneList($dbh, (childlist => $childlist, curgroup => $curgroup, 2074 revrec => $webvar{revrec}, 2071 my $zonelist = $dnsdb->getZoneList(childlist => $childlist, curgroup => $curgroup, revrec => $webvar{revrec}, 2075 2072 filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef), 2076 2073 offset => $webvar{offset}, sortby => $sortby, sortorder => $sortorder 2077 ) );2074 ); 2078 2075 # probably don't need this, keeping for reference for now 2079 2076 # foreach (@$zonelist) { … … 2094 2091 2095 2092 my @childgroups; 2096 getChildren($dbh,$curgroup, \@childgroups, 'all') if $searchsubs;2093 $dnsdb->getChildren($curgroup, \@childgroups, 'all') if $searchsubs; 2097 2094 my $childlist = join(',',@childgroups); 2098 2095 2099 my ($count) = getGroupCount($dbh,(childlist => $childlist, curgroup => $curgroup,2100 filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef) ) );2096 my ($count) = $dnsdb->getGroupCount(childlist => $childlist, curgroup => $curgroup, 2097 filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef) ); 2101 2098 2102 2099 # fill page count and first-previous-next-last-all bits … … 2129 2126 $sortby = 'g2.group_name' if $sortby eq 'parent'; 2130 2127 2131 my $glist = getGroupList($dbh,(childlist => $childlist, curgroup => $curgroup,2128 my $glist = $dnsdb->getGroupList(childlist => $childlist, curgroup => $curgroup, 2132 2129 filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef), 2133 offset => $webvar{offset}, sortby => $sortby, sortorder => $sortorder) );2130 offset => $webvar{offset}, sortby => $sortby, sortorder => $sortorder); 2134 2131 2135 2132 $page->param(grouptable => $glist); … … 2149 2146 2150 2147 my @childlist; 2151 getChildren($dbh,$root,\@childlist,'immediate');2148 $dnsdb->getChildren($root, \@childlist, 'immediate'); 2152 2149 return if $#childlist == -1; 2153 2150 foreach (@childlist) { … … 2155 2152 $row{groupval} = $_; 2156 2153 $row{groupactive} = ($_ == $cur); 2157 $row{groupname} = $indent. groupName($dbh,$_);2154 $row{groupname} = $indent.$dnsdb->groupName($_); 2158 2155 push @{$grplist}, \%row; 2159 2156 getgroupdrop($_, $cur, $grplist, $indent.' '); … … 2163 2160 my @grouplist; 2164 2161 push @grouplist, { groupval => $logingroup, groupactive => $logingroup == $curgroup, 2165 groupname => groupName($dbh,$logingroup) };2162 groupname => $dnsdb->groupName($logingroup) }; 2166 2163 getgroupdrop($logingroup, $curgroup, \@grouplist); 2167 2164 … … 2179 2176 2180 2177 if ($permissions{admin} || $permissions{record_locchg}) { 2181 my $loclist = getLocDropdown($dbh,$cur, $defloc);2178 my $loclist = $dnsdb->getLocDropdown($cur, $defloc); 2182 2179 $page->param(record_locchg => 1); 2183 2180 $page->param(loclist => $loclist); 2184 2181 } else { 2185 my $loc = getLoc($dbh,$defloc);2182 my $loc = $dnsdb->getLoc($defloc); 2186 2183 $page->param(loc_name => $loc->{description}); 2187 2184 } … … 2192 2189 2193 2190 my @childgroups; 2194 getChildren($dbh,$curgroup, \@childgroups, 'all') if $searchsubs;2191 $dnsdb->getChildren($curgroup, \@childgroups, 'all') if $searchsubs; 2195 2192 my $childlist = join(',',@childgroups); 2196 2193 2197 my $count = getUserCount($dbh,(childlist => $childlist, curgroup => $curgroup,2198 filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef) ) );2194 my $count = $dnsdb->getUserCount(childlist => $childlist, curgroup => $curgroup, 2195 filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef) ); 2199 2196 2200 2197 # fill page count and first-previous-next-last-all bits … … 2221 2218 $page->param(searchsubs => $searchsubs) if $searchsubs; 2222 2219 2223 my $ulist = getUserList($dbh,(childlist => $childlist, curgroup => $curgroup,2220 my $ulist = $dnsdb->getUserList(childlist => $childlist, curgroup => $curgroup, 2224 2221 filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef), 2225 offset => $webvar{offset}, sortby => $sortby, sortorder => $sortorder) );2222 offset => $webvar{offset}, sortby => $sortby, sortorder => $sortorder); 2226 2223 # Some UI things need to be done to the list (unlike other lists) 2227 2224 foreach my $u (@{$ulist}) { … … 2239 2236 2240 2237 my @childgroups; 2241 getChildren($dbh,$curgroup, \@childgroups, 'all') if $searchsubs;2238 $dnsdb->getChildren($curgroup, \@childgroups, 'all') if $searchsubs; 2242 2239 my $childlist = join(',',@childgroups); 2243 2240 2244 my $count = getLocCount($dbh,(childlist => $childlist, curgroup => $curgroup,2245 filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef) ) );2241 my $count = $dnsdb->getLocCount(childlist => $childlist, curgroup => $curgroup, 2242 filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef) ); 2246 2243 2247 2244 # fill page count and first-previous-next-last-all bits … … 2268 2265 $page->param(searchsubs => $searchsubs) if $searchsubs; 2269 2266 2270 my $loclist = getLocList($dbh,(childlist => $childlist, curgroup => $curgroup,2267 my $loclist = $dnsdb->getLocList(childlist => $childlist, curgroup => $curgroup, 2271 2268 filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef), 2272 offset => $webvar{offset}, sortby => $sortby, sortorder => $sortorder) );2269 offset => $webvar{offset}, sortby => $sortby, sortorder => $sortorder); 2273 2270 # Some UI things need to be done to the list 2274 2271 foreach my $l (@{$loclist}) { … … 2341 2338 } else { 2342 2339 foreach (@viewablegroups) { 2343 return 1 if isParent($dbh,$_, 'group', $entity, $entype);2340 return 1 if $dnsdb->isParent($_, 'group', $entity, $entype); 2344 2341 } 2345 2342 }
Note:
See TracChangeset
for help on using the changeset viewer.