- Timestamp:
- 10/15/09 17:50:22 (15 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r20 r22 23 23 @ISA = qw(Exporter); 24 24 @EXPORT_OK = qw( 25 &initGlobals &connectDB &finish &addDomain &delDomain &domainName &addGroup &getChildren &groupName 26 &getSOA &getRecLine &getDomRecs &addRec &updateRec &delRec &domStatus 25 &initGlobals &connectDB &finish 26 &addDomain &delDomain &domainName 27 &addGroup &delGroup &getChildren &groupName 28 &getSOA &getRecLine &getDomRecs 29 &addRec &updateRec &delRec 30 &domStatus 27 31 %typemap %reverse_typemap 28 32 ); … … 30 34 @EXPORT = (); # Export nothing by default. 31 35 %EXPORT_TAGS = ( ALL => [qw( 32 &initGlobals &connectDB &finish &addDomain &delDomain &domainName &addGroup &getChildren 33 &groupName &getSOA &getRecLine &getDomRecs &addRec &updateRec &delRec &domStatus 36 &initGlobals &connectDB &finish 37 &addDomain &delDomain &domainName 38 &addGroup &delGroup &getChildren &groupName 39 &getSOA &getRecLine &getDomRecs 40 &addRec &updateRec &delRec 41 &domStatus 34 42 %typemap %reverse_typemap 35 43 )] … … 225 233 $sth->execute($domid); 226 234 235 #die "full of fail\n"; 227 236 # once we get here, we should have suceeded. 228 $dbh->commit;237 # $dbh->commit; 229 238 }; # end eval 230 239 … … 302 311 } 303 312 304 die "epic FAIL.. hahahah, just testing!\n";305 313 # once we get here, we should have suceeded. 306 314 $dbh->commit; … … 316 324 317 325 } # end addGroup() 326 327 328 ## DNSDB::delGroup() 329 # Delete a group. 330 # Takes a group ID 331 # Returns a status code and message 332 sub delGroup { 333 my $dbh = shift; 334 my $groupid = shift; 335 336 # Allow transactions, and raise an exception on errors so we can catch it later. 337 # Use local to make sure these get "reset" properly on exiting this block 338 local $dbh->{AutoCommit} = 0; 339 local $dbh->{RaiseError} = 1; 340 341 ##fixme: locate "knowable" error conditions and deal with them before the eval 342 # -> domains still exist in group 343 # -> ... 344 345 # Wrap all the SQL in a transaction 346 eval { 347 my $sth = $dbh->prepare("delete from default_records where group_id=?"); 348 $sth->execute($groupid); 349 $sth = $dbh->prepare("delete from groups where group_id=?"); 350 $sth->execute($groupid); 351 352 die "epic group fail FTW!\n"; 353 # once we get here, we should have suceeded. 354 $dbh->commit; 355 }; # end eval 356 357 if ($@) { 358 my $msg = $@; 359 eval { $dbh->rollback; }; 360 return ('FAIL',$msg); 361 } else { 362 return ('OK','OK'); 363 } 364 } # end delGroup() 318 365 319 366 -
trunk/dns.cgi
r20 r22 165 165 $page->param(del_failed => 1); 166 166 $page->param(errmsg => $msg); 167 listdomains($curgroup); 167 168 } else { 168 169 # success. go back to the domain list, do not pass "GO" … … 365 366 } elsif ($webvar{page} eq 'grpman') { 366 367 367 my $sth = $dbh->prepare("select count(*) from groups"); 368 $sth->execute; 369 my ($count) = ($sth->fetchrow_array); 370 371 # fill page count and first-previous-next-last-all bits 372 ##fixme - hardcoded group bit 373 fill_pgcount($count,"groups",''); 374 fill_fpnla($count); 375 376 my @grouplist; 377 $sth = $dbh->prepare("SELECT g.group_id, g.group_name, g2.group_name, ". 378 "count(distinct(u.email)), count(distinct(d.domain)) ". 379 "FROM groups g ". 380 "INNER JOIN groups g2 ON g2.group_id=g.parent_group_id ". 381 "LEFT OUTER JOIN users u ON u.group_id=g.group_id ". 382 "LEFT OUTER JOIN domains d ON d.group_id=g.group_id ". 383 "GROUP BY g.group_id, g.group_name, g2.group_name ". 384 "ORDER BY g.group_id".($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage)); 385 $sth->execute; 386 387 my $rownum = 0; 388 while (my @data = $sth->fetchrow_array) { 389 my %row; 390 $row{groupid} = $data[0]; 391 $row{groupname} = $data[1]; 392 $row{pgroup} = $data[2]; 393 $row{nusers} = $data[3]; 394 $row{ndomains} = $data[4]; 395 $row{bg} = ($rownum++)%2; 396 $row{sid} = $sid; 397 push @grouplist, \%row; 398 } 399 $page->param(grouptable => \@grouplist); 400 368 listgroups(); 401 369 $page->param(curpage => $webvar{page}); 402 370 … … 418 386 } 419 387 420 } elsif ($webvar{page} eq 'delgr oup') {388 } elsif ($webvar{page} eq 'delgrp') { 421 389 422 390 $page->param(id => $webvar{id}); … … 436 404 $page->param(del_failed => 1); 437 405 $page->param(errmsg => $msg); 406 $page->param(curpage => $webvar{page}); 407 listgroups(); 438 408 } else { 439 409 # success. go back to the domain list, do not pass "GO" … … 646 616 647 617 sub listdomains { 648 649 618 my $sth = $dbh->prepare("SELECT count(*) FROM domains WHERE group_id=?"); 650 619 $sth->execute($curgroup); … … 683 652 684 653 654 sub listgroups { 655 my $sth = $dbh->prepare("select count(*) from groups"); 656 $sth->execute; 657 my ($count) = ($sth->fetchrow_array); 658 659 # fill page count and first-previous-next-last-all bits 660 ##fixme - hardcoded group bit 661 fill_pgcount($count,"groups",''); 662 fill_fpnla($count); 663 664 my @grouplist; 665 $sth = $dbh->prepare("SELECT g.group_id, g.group_name, g2.group_name, ". 666 "count(distinct(u.email)), count(distinct(d.domain)) ". 667 "FROM groups g ". 668 "INNER JOIN groups g2 ON g2.group_id=g.parent_group_id ". 669 "LEFT OUTER JOIN users u ON u.group_id=g.group_id ". 670 "LEFT OUTER JOIN domains d ON d.group_id=g.group_id ". 671 "GROUP BY g.group_id, g.group_name, g2.group_name ". 672 "ORDER BY g.group_id".($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage)); 673 $sth->execute; 674 675 my $rownum = 0; 676 while (my @data = $sth->fetchrow_array) { 677 my %row; 678 $row{groupid} = $data[0]; 679 $row{groupname} = $data[1]; 680 $row{pgroup} = $data[2]; 681 $row{nusers} = $data[3]; 682 $row{ndomains} = $data[4]; 683 $row{bg} = ($rownum++)%2; 684 $row{sid} = $sid; 685 push @grouplist, \%row; 686 } 687 $page->param(grouptable => \@grouplist); 688 } # end listgroups() 689 690 685 691 sub fill_grouplist { 686 692 my $template_var = shift; -
trunk/templates/deldom.tmpl
r7 r22 9 9 10 10 <TMPL_ELSE> 11 < TMPL_IF del_failed>11 <!-- <TMPL_IF del_failed> 12 12 <div class='errmsg'>Error deleting domain <TMPL_VAR NAME=domain>: <TMPL_VAR NAME=errmsg></div> 13 </TMPL_IF> 13 </TMPL_IF> --> 14 14 <TMPL_INCLUDE NAME="domlist.tmpl"> 15 15 </TMPL_IF> -
trunk/templates/delgrp.tmpl
r21 r22 10 10 11 11 <TMPL_ELSE> 12 < TMPL_IF del_failed>12 <!-- <TMPL_IF del_failed> 13 13 <div class='errmsg'>Error deleting group <TMPL_VAR NAME=groupname>: <TMPL_VAR NAME=errmsg></div> 14 </TMPL_IF> 14 </TMPL_IF> --> 15 15 <TMPL_INCLUDE NAME="grpman.tmpl"> 16 16 </TMPL_IF> -
trunk/templates/domlist.tmpl
r17 r22 4 4 5 5 <td align="center"> 6 7 <TMPL_IF del_failed> 8 <div class='errmsg'>Error deleting domain <TMPL_VAR NAME=domain>: <TMPL_VAR NAME=errmsg></div> 9 </TMPL_IF> 10 6 11 <table width="98%"> 7 12 <tr><td colspan=3 align=center>Domain list</td></tr> -
trunk/templates/grpman.tmpl
r20 r22 4 4 5 5 <td align="center"> 6 7 <TMPL_IF del_failed> 8 <div class='errmsg'>Error deleting group <TMPL_VAR NAME=groupname>: <TMPL_VAR NAME=errmsg></div> 9 </TMPL_IF> 10 6 11 <table width="98%"> 7 12 <tr><td colspan=3 align=center><span class="pgtitle">Manage groups</span></td></tr>
Note:
See TracChangeset
for help on using the changeset viewer.