Changeset 57 for trunk/dns.cgi
- Timestamp:
- 01/13/10 17:46:21 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dns.cgi
r55 r57 71 71 $session->param($webvar{page}.'filter', $webvar{filter}) if $webvar{filter}; 72 72 $webvar{searchsubs} =~ s/^n ?// if $webvar{searchsubs}; 73 $session->param($webvar{page}.'searchsubs', $webvar{searchsubs}) if $webvar{searchsubs};73 $session->param($webvar{page}.'searchsubs', $webvar{searchsubs}) if defined($webvar{searchsubs}); 74 74 75 75 my $startwith = $session->param($webvar{page}.'startwith'); … … 77 77 my $searchsubs = $session->param($webvar{page}.'searchsubs'); 78 78 79 80 81 if (0) { 82 # filter, starts with, search subgroups 83 $session->param('filter', "$webvar{page}:filter$webvar{filter}") if defined($webvar{filter}); 84 my $filter = $session->param('filter'); 85 $filter = ($filter =~ /^$webvar{page}:filter(.+)$/ ? $1 : ''); 86 87 $session->param('startwith', "$webvar{page}:startwith$webvar{startwith}") if defined($webvar{startwith}); 88 my $startwith = $session->param('startwith'); 89 $startwith = ($startwith =~ /^$webvar{page}:startwith(.+)$/ ? $1 : ''); 90 91 $webvar{searchsubs} =~ s/^n ?// if $webvar{searchsubs}; 92 $session->param('searchsubs', "$webvar{page}:searchsubs$webvar{searchsubs}") if defined($webvar{searchsubs}); 93 my $searchsubs = $session->param('searchsubs'); 94 $searchsubs = ($searchsubs =~ /^$webvar{page}:searchsubs(.+)$/ ? $1 : ''); 95 } 96 97 79 push @debugbits, "foo<br>\n" if defined($webvar{searchsubs}); 98 80 99 81 # nrgh, can't handle login here because we don't have a database handle to check the user/pass with yet 100 101 if ($webvar{action} && $webvar{action} eq 'chgroup') {102 # fiddle session-stored group data103 # magic incantation to... uhhh...104 $session->param('curgroup', $webvar{group});105 $curgroup = ($webvar{group} ? $webvar{group} : $session->param('curgroup'));106 }107 82 108 83 my $header = HTML::Template->new(filename => "$templatedir/header.tmpl"); … … 158 133 exit; 159 134 160 } 161 } 135 } elsif ($webvar{action} eq 'chgroup') { 136 # fiddle session-stored group data 137 # magic incantation to... uhhh... 138 $session->param('curgroup', $webvar{group}); 139 $curgroup = ($webvar{group} ? $webvar{group} : $session->param('curgroup')); 140 } 141 } # handle global webvar{action}s 142 162 143 163 144 ## Default page is a login page 164 145 #my $page; # to be initialized as an HTML::Template entity sooner or later 165 166 146 167 147 … … 197 177 } elsif ($webvar{page} eq 'newdomain') { 198 178 179 # hmm. nothing to do here? 180 # - group list is filled by the same bit that fills the group list in the menu 181 182 } elsif ($webvar{page} eq 'adddomain') { 183 184 my ($code,$msg) = addDomain($dbh,$webvar{domain},$webvar{group},($webvar{makeactive} eq 'on' ? 1 : 0)); 185 186 if ($code eq 'OK') { 187 logaction($msg, $session->param("username"), $webvar{group}, "Added domain $webvar{domain}"); 188 changepage(page => "reclist", id => $msg); 189 } else { 190 changepage(page => "newdomain", add_failed => 1, domain => $webvar{domain}, errmsg => $msg); 191 } 199 192 200 193 } elsif ($webvar{page} eq 'deldom') { … … 211 204 212 205 } elsif ($webvar{del} eq 'ok') { 206 my $pargroup = parentID($webvar{id}, 'dom', 'group'); 213 207 my ($code,$msg) = delDomain($dbh, $webvar{id}); 214 208 if ($code ne 'OK') { … … 218 212 listdomains($curgroup); 219 213 } else { 220 # success. go back to the domain list, do not pass "GO" 221 changepage(page => "domlist"); 214 ##fixme: need domain to put in log message 215 logaction($webvar{id}, $session->param("username"), $pargroup, "Deleted domain $webvar{domain}"); 216 changepage(page => "domlist"); 222 217 } 223 218 } else { … … 277 272 ##fixme: need more magic to get proper group - if domain was fiddled 278 273 # from search-subgroups listing, may not be "current" group 279 logaction($webvar{parentid}, $session->param("username"), $webvar{group}, 280 "Added '$typemap{$webvar{type}} $webvar{name} $webvar{address}', TTL $webvar{ttl}"); 274 275 # SELECT group_id FROM domains WHERE domain_id=?; 276 # sth->execute($webvar{parentid}); 277 ##log 278 if ($webvar{defrec} eq 'y') { 279 logaction(0, $session->param("username"), $webvar{parentid}, 280 "Added default record '$typemap{$webvar{type}} $webvar{name} $webvar{address}', TTL $webvar{ttl}"); 281 } else { 282 logaction($webvar{parentid}, $session->param("username"), parentID($webvar{parentid}, 'dom', 'group'), 283 "Added record '$typemap{$webvar{type}} $webvar{name} $webvar{address}', TTL $webvar{ttl}"); 284 } 281 285 changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}); 282 286 } else { … … 300 304 $page->param(id => $webvar{id}); 301 305 $page->param(defrec => $webvar{defrec}); 306 ##fixme: SQL does not belong! 302 307 my $sth = $dbh->prepare("SELECT host,type,val,distance,weight,port,ttl FROM ". 303 308 ($webvar{defrec} eq 'y' ? 'default_' : '')."records WHERE record_id=?"); … … 321 326 ##fixme: need more magic to get proper group - if domain was fiddled 322 327 # from search-subgroups listing, may not be "current" group 323 logaction($webvar{parentid}, $session->param("username"), $webvar{group}, 324 "Updated '$typemap{$webvar{type}} $webvar{name} $webvar{address}', TTL $webvar{ttl}"); 328 329 # SELECT d.group_id FROM domains d INNER JOIN records r ON d.domain_id=r.domain_id WHERE r.record_id=? 330 # $sth->execute($webvar{id}); 331 ##log 332 if ($webvar{defrec} eq 'y') { 333 logaction(0, $session->param("username"), $webvar{parentid}, 334 "Updated default record '$webvar{name} $typemap{$webvar{type}} $webvar{address}', TTL $webvar{ttl}"); 335 } else { 336 logaction($webvar{parentid}, $session->param("username"), parentID($webvar{id}, 'rec', 'group'), 337 "Updated record '$webvar{name} $typemap{$webvar{type}} $webvar{address}', TTL $webvar{ttl}"); 338 } 325 339 changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}); 326 340 } else { … … 345 359 } 346 360 347 } elsif ($webvar{page} eq 'newrec') {348 push @debugbits, "whee!\n";349 350 # populate most fields as needed. (eg, type list.)351 stdrecs();352 353 } elsif ($webvar{page} eq 'addrec') {354 355 my @recargs = ($dbh,$webvar{defrec},$webvar{parentid},$webvar{name},$webvar{type},$webvar{address},$webvar{ttl});356 if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV}) {357 push @recargs, $webvar{distance};358 if ($webvar{type} == $reverse_typemap{SRV}) {359 push @recargs, $webvar{weight};360 push @recargs, $webvar{port};361 }362 }363 # wtf?364 # push @recargs,365 my ($code,$msg) = addRec(@recargs);366 367 if ($code eq 'OK') {368 ##fixme: need more magic to get proper group - if domain was fiddled369 # from search-subgroups listing, may not be "current" group370 logaction($webvar{parentid}, $session->param("username"), $webvar{group},371 "Added '$typemap{$webvar{type}} $webvar{name} $webvar{address}', TTL $webvar{ttl}");372 showdomain($webvar{defrec},$webvar{parentid});373 # NB: should **really** redirect here, in case of reload. >_< eyowch.374 } else {375 $page->param(add_failed => 1);376 $page->param(errmsg => $msg);377 stdrecs($webvar{type}); # populate the form... er, mostly.378 $page->param(name => $webvar{name});379 $page->param(address => $webvar{address});380 $page->param(distance => $webvar{distance})381 if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV});382 $page->param(weight => $webvar{weight}) if $webvar{type} == $reverse_typemap{SRV};383 $page->param(port => $webvar{port}) if $webvar{type} == $reverse_typemap{SRV};384 }385 386 $page->param(defrec => $webvar{defrec});387 388 } elsif ($webvar{page} eq 'conf_del') {389 390 $page->param(id => $webvar{id});391 $page->param(defrec => $webvar{defrec});392 393 my @tmp = getrecdata($dbh,$webvar{id},$webvar{defrec});394 395 361 } elsif ($webvar{page} eq 'delrec') { 396 362 … … 406 372 $page->param(recval => $rec{val}); 407 373 } elsif ($webvar{del} eq 'ok') { 374 # get groupid of deleted record before we try to delete it 375 my $pargrp = parentID($webvar{id}, 'rec', 'group', $webvar{defrec}); 408 376 my ($code,$msg) = delRec($dbh,$webvar{defrec},$webvar{id}); 409 377 if ($code ne 'OK') { 410 378 ## need to find failure mode 379 #logaction( 411 380 $page->param(del_failed => 1); 412 381 $page->param(errmsg => $msg); 413 382 showdomain($webvar{defrec}, $webvar{parentid}); 414 383 } else { 384 ##log 415 385 changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}); 416 386 } … … 441 411 fillsoa($webvar{defrec},$webvar{id}); 442 412 } else { 413 414 ##fixme! need to set group ID properly here 415 # SELECT group_id FROM domains WHERE domain_id=? 416 # $sth->execute($webvar{id}); 417 ##log 443 418 logaction(0, $session->param("username"), $webvar{group}, 444 419 "Updated SOA (ns $webvar{prins}, contact $webvar{contact}, refresh $webvar{refresh},". 445 420 " retry $webvar{retry}, expire $webvar{expire}, minTTL $webvar{minttl}, TTL $webvar{ttl}"); 446 421 changepage(page => "reclist", id => $webvar{id}, defrec => $webvar{defrec}); 447 $page->param(update_failed => 0); 448 ##fixme! need to set group ID properly here 422 # $page->param(update_failed => 0); 449 423 # showdomain('y',1); 450 }451 452 } elsif ($webvar{page} eq 'adddomain') {453 454 my ($code,$msg) = addDomain($dbh,$webvar{domain},$webvar{group},($webvar{makeactive} eq 'on' ? 1 : 0));455 456 if ($code eq 'OK') {457 logaction($msg, $session->param("username"), $webvar{group}, "Added domain $webvar{domain}");458 changepage(page => "reclist", id => $msg);459 } else {460 # oooh, yeah, this is supposed to be a redirect. er, maybe. whee.461 ##fixme: session ID462 $page = HTML::Template->new(filename => "$templatedir/newdomain.tmpl");463 $page->param(add_failed => 1);464 $page->param(domain => $webvar{domain});465 $page->param(errmsg => $msg);466 424 } 467 425 … … 477 435 # not gonna provide the 4th param: template-or-clone flag, just yet 478 436 my ($code,$msg) = addGroup($dbh, $webvar{newgroup}, $webvar{pargroup}); 479 if $code eq 'OK'{437 if ($code eq 'OK') { 480 438 logaction(0, $session->param("username"), $webvar{pargroup}, "Added group $webvar{newgroup}"); 481 439 changepage(page => "grpman"); … … 504 462 505 463 } elsif ($webvar{del} eq 'ok') { 464 my $deleteme = groupName($dbh,$webvar{id}); # get this before we delete it... 506 465 my ($code,$msg) = delGroup($dbh, $webvar{id}); 507 push @debugbits, groupName($dbh, $webvar{id});508 466 if ($code ne 'OK') { 509 467 # need to find failure mode … … 513 471 listgroups(); 514 472 } else { 515 ##fix em: need more magic to correctly determine the group this action happens in516 logaction(0, $session->param("username"), $webvar{curgroup}, "Deleted group $ webvar{id}");473 ##fixme: need to clean up log when deleting a major container 474 logaction(0, $session->param("username"), $webvar{curgroup}, "Deleted group $deleteme"); 517 475 # success. go back to the domain list, do not pass "GO" 518 476 changepage(page => "grpman"); … … 554 512 # hokay, a bit of magic to decide which page we hit. 555 513 if ($code eq 'OK') { 514 ##log 556 515 logaction(0, $session->param("username"), $webvar{group}, 557 516 "Added user $webvar{uname} ($webvar{fname} $webvar{lname})"); … … 579 538 $page->param(user => userFullName($dbh,$webvar{id})); 580 539 } elsif ($webvar{del} eq 'ok') { 540 ##fixme: find group id user is in (for logging) *before* we delete the user 581 541 my ($code,$msg) = delUser($dbh, $webvar{id}); 582 542 if ($code ne 'OK') { … … 587 547 } else { 588 548 # success. go back to the domain list, do not pass "GO" 549 ##log 550 logaction(0, $session->param("username"), $webvar{group}, "Added domain $webvar{domain}"); 589 551 changepage(page => "useradmin"); 590 552 } … … 670 632 $page->param(dominactive => 1) if (!$webvar{domactive} && $webvar{doit}); # eww. 671 633 $page->param(importdoms => $webvar{importdoms}) if $webvar{importdoms}; 672 ##work673 634 674 635 ##fixme: check group too? … … 844 805 } 845 806 846 847 807 sub changepage { 848 808 my %params = @_; # think this works the way I want... … … 860 820 exit; 861 821 } # end changepage 862 863 822 864 823 sub fillsoa { … … 932 891 } 933 892 934 935 893 # fill in record type list on add/update/edit record template 936 894 sub fill_rectypes { … … 966 924 } 967 925 968 969 926 sub fill_actypelist { 970 927 my @actypes; … … 980 937 $page->param(actypelist => \@actypes); 981 938 } 982 983 939 984 940 sub fill_fpnla { … … 1010 966 } # end fill_fpnla() 1011 967 1012 1013 968 sub fill_pgcount { 1014 969 my $pgcount = shift; … … 1025 980 } # end fill_pgcount() 1026 981 1027 1028 982 sub listdomains { 1029 983 1030 984 ##fixme: $logingroup or $curgroup? 1031 985 my @childgroups; 1032 getChildren($dbh, $logingroup, \@childgroups, 'all') if $searchsubs;986 #getChildren($dbh, $curgroup, \@childgroups, 'all') if $searchsubs; 1033 987 my $childlist = join(',',@childgroups); 1034 988 1035 my $sql = "SELECT count(*) FROM domains WHERE group_id IN ($ logingroup".($childlist ? ",$childlist" : '').")".989 my $sql = "SELECT count(*) FROM domains WHERE group_id IN ($curgroup".($childlist ? ",$childlist" : '').")". 1036 990 ($startwith ? " AND domain ~* '^[$startwith]'" : ''). 1037 991 ($filter ? " AND domain ~* '$filter'" : ''); … … 1076 1030 $sql = "SELECT domain_id,domain,status,groups.group_name AS group FROM domains". 1077 1031 " INNER JOIN groups ON domains.group_id=groups.group_id". 1078 " WHERE domains.group_id IN ($ logingroup".($childlist ? ",$childlist" : '').")".1032 " WHERE domains.group_id IN ($curgroup".($childlist ? ",$childlist" : '').")". 1079 1033 ##fixme: don't do variable subs in SQL, use placeholders and params in ->execute() 1080 1034 ($startwith ? " AND domain ~* '^[$startwith]'" : ''). … … 1102 1056 } # end listdomains() 1103 1057 1104 1105 1058 sub listgroups { 1106 1059 … … 1175 1128 } # end listgroups() 1176 1129 1177 1178 1130 sub fill_grouplist { 1179 1131 my $template_var = shift; … … 1204 1156 } # end fill_grouplist() 1205 1157 1206 1207 1158 sub list_users { 1208 1159 … … 1278 1229 $page->param(usertable => \@userlist); 1279 1230 } # end list_users() 1280 1281 1231 1282 1232 # Generate all of the glop necessary to add or not the appropriate marker/flag for … … 1312 1262 } # end fill_colheads() 1313 1263 1314 1315 1264 sub logaction { 1316 my ($domid,$username,$groupid,$entry) ;1265 my ($domid,$username,$groupid,$entry) = shift; 1317 1266 1318 1267 my $sth = dbh->prepare("SELECT user_id, firstname || ' ' || lastname FROM users WHERE username=?"); … … 1322 1271 $sth = $dbh->prepare("INSERT INTO log (domain_id,user_id,group_id,email,name,entry) ". 1323 1272 "VALUES (?,?,?,?,?,?)"); 1324 $sth->execute($domid,$user id,$groupid,$username,$fullname,$entry);1273 $sth->execute($domid,$user_id,$groupid,$username,$fullname,$entry); 1325 1274 1326 1275 } # end logaction() 1276 1277 #sub parentID($dbh, $id, $idtype, $partype[, $defrec]) 1278 sub parentID { 1279 my $id = shift; 1280 my $idtype = shift; 1281 my $partype = shift; 1282 my $defrec = shift || ''; 1283 1284 my $sql = ''; 1285 1286 if ($idtype eq 'dom') { 1287 return $id if $defrec eq 'y'; 1288 $sql = "SELECT group_id FROM domains WHERE domain_id=?"; 1289 } elsif ($idtype eq 'rec') { 1290 if ($defrec && $defrec eq 'y') { 1291 } else { 1292 return 1293 $sql = "SELECT d.group_id FROM domains d". 1294 " INNER JOIN records r ON d.domain_id=r.domain_id". 1295 " WHERE r.record_id=?"; 1296 } 1297 } elsif ($idtype eq 'group') { 1298 $sql = "SELECT parent_group_id FROM groups WHERE group_id=?"; 1299 } elsif ($idtype eq 'user') { 1300 $sql = "SELECT group_id FROM users WHERE user_id=?"; 1301 } else { 1302 return "FOO", "BAR"; # can't get here.... we think. 1303 } 1304 }
Note:
See TracChangeset
for help on using the changeset viewer.