Changeset 20
- Timestamp:
- 10/15/09 13:23:51 (15 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r19 r20 23 23 @ISA = qw(Exporter); 24 24 @EXPORT_OK = qw( 25 &initGlobals &connectDB &finish &addDomain &delDomain &domainName &addGroup &getChildren &gr pName &getSOA26 &get RecLine &getDomRecs &addRec &updateRec &delRec &domStatus25 &initGlobals &connectDB &finish &addDomain &delDomain &domainName &addGroup &getChildren &groupName 26 &getSOA &getRecLine &getDomRecs &addRec &updateRec &delRec &domStatus 27 27 %typemap %reverse_typemap 28 28 ); … … 30 30 @EXPORT = (); # Export nothing by default. 31 31 %EXPORT_TAGS = ( ALL => [qw( 32 &initGlobals &connectDB &finish &addDomain &delDomain &domainName &addGroup &getChildren &grpName 33 &getSOA 34 &getRecLine &getDomRecs &addRec &updateRec &delRec &domStatus 32 &initGlobals &connectDB &finish &addDomain &delDomain &domainName &addGroup &getChildren 33 &groupName &getSOA &getRecLine &getDomRecs &addRec &updateRec &delRec &domStatus 35 34 %typemap %reverse_typemap 36 35 )] … … 264 263 $errstr = ''; 265 264 my $dbh = shift; 266 my $gr pname = shift;267 my $pargr p = shift;265 my $groupname = shift; 266 my $pargroup = shift; 268 267 269 268 # 0 indicates "template", hardcoded. … … 279 278 eval { 280 279 my $sth = $dbh->prepare("INSERT INTO groups (parent_group_id,group_name) VALUES (?,?)"); 281 $sth->execute($pargr p,$grpname);280 $sth->execute($pargroup,$groupname); 282 281 283 282 $sth = $dbh->prepare("SELECT group_id FROM groups WHERE group_name=?"); 284 $sth->execute($gr pname);285 my ($gr pid) = $sth->fetchrow_array();283 $sth->execute($groupname); 284 my ($groupid) = $sth->fetchrow_array(); 286 285 287 286 $sth = $dbh->prepare("INSERT INTO default_records (group_id,host,type,val,distance,weight,port,ttl) ". 288 "VALUES ($gr pid,?,?,?,?,?,?,?)");287 "VALUES ($groupid,?,?,?,?,?,?,?)"); 289 288 if ($torc) { 290 289 my $sth2 = $dbh->prepare("SELECT host,type,val,distance,weight,port,ttl FROM default_records WHERE group_id=?"); … … 326 325 $errstr = ''; 327 326 my $dbh = shift; 328 my $rootgr p = shift;329 my $gr pdest = shift;327 my $rootgroup = shift; 328 my $groupdest = shift; 330 329 331 330 # special break for default group; otherwise we get stuck. 332 if ($rootgr p == 1) {331 if ($rootgroup == 1) { 333 332 # by definition, group 1 is the Root Of All Groups 334 333 my $sth = $dbh->prepare("SELECT group_id FROM groups"); 335 334 $sth->execute; 336 my @gr plist;335 my @grouplist; 337 336 while (my @this = $sth->fetchrow_array) { 338 push @$gr pdest, @this;337 push @$groupdest, @this; 339 338 } 340 339 } else { 341 340 my $sth = $dbh->prepare("SELECT group_id FROM groups WHERE parent_group_id=?"); 342 $sth->execute($rootgr p);341 $sth->execute($rootgroup); 343 342 return if $sth->rows == 0; 344 my @gr plist;345 while (my ($gr p) = $sth->fetchrow_array) {346 push @$gr pdest, $grp;347 getChildren($dbh,$gr p,$grpdest);343 my @grouplist; 344 while (my ($group) = $sth->fetchrow_array) { 345 push @$groupdest, $group; 346 getChildren($dbh,$group,$groupdest); 348 347 } 349 348 } … … 351 350 352 351 353 ## DNSDB::gr pName()352 ## DNSDB::groupName() 354 353 # Return the group name based on a group ID 355 354 # Takes a database handle and the group ID 356 355 # Returns the group name or undef on failure 357 sub gr pName {358 $errstr = ''; 359 my $dbh = shift; 360 my $gr pid = shift;361 my $sth = $dbh->prepare(" select name from groups wheregroup_id=?");362 $sth->execute($gr pid);363 my ($gr pname) = $sth->fetchrow_array();364 $errstr = $DBI::errstr if !$gr pname;365 return $gr pname if $grpname;366 } # end domainName356 sub groupName { 357 $errstr = ''; 358 my $dbh = shift; 359 my $groupid = shift; 360 my $sth = $dbh->prepare("SELECT group_name FROM groups WHERE group_id=?"); 361 $sth->execute($groupid); 362 my ($groupname) = $sth->fetchrow_array(); 363 $errstr = $DBI::errstr if !$groupname; 364 return $groupname if $groupname; 365 } # end groupName 367 366 368 367 -
trunk/dns.cgi
r19 r20 59 59 } 60 60 61 if ($webvar{action} && $webvar{action} eq 'chgroup') { 62 # fiddle session-stored group data 63 # magic incantation to... uhhh... 64 $session->param('curgroup', $webvar{group}); 65 $curgroup = ($webvar{group} ? $webvar{group} : $session->param('curgroup')); 66 } 67 61 68 my $header = HTML::Template->new(filename => "$templatedir/header.tmpl"); 62 69 my $footer = HTML::Template->new(filename => "$templatedir/footer.tmpl"); … … 132 139 if ($webvar{defrec} eq 'y') { 133 140 ##fixme: hardcoded group 134 showdomain('y',$ group);141 showdomain('y',$curgroup); 135 142 } else { 136 143 showdomain('n',$webvar{id}); … … 236 243 237 244 if ($webvar{defrec} eq 'y') { 238 $page->param(dohere => "default records in group ".gr pName($dbh,$webvar{parentid}));245 $page->param(dohere => "default records in group ".groupName($dbh,$webvar{parentid})); 239 246 } else { 240 247 $page->param(dohere => domainName($dbh,$webvar{parentid})); … … 339 346 340 347 ##fixme: Group should be variable 341 my ($code,$msg) = addDomain($dbh,$webvar{domain}, 1,($webvar{makeactive} eq 'on' ? 1 : 0));348 my ($code,$msg) = addDomain($dbh,$webvar{domain},$webvar{group},($webvar{makeactive} eq 'on' ? 1 : 0)); 342 349 343 350 # hokay, a bit of magic to decide which page we hit. … … 367 374 fill_fpnla($count); 368 375 369 my @gr plist;376 my @grouplist; 370 377 $sth = $dbh->prepare("SELECT g.group_id, g.group_name, g2.group_name, ". 371 378 "count(distinct(u.email)), count(distinct(d.domain)) ". … … 381 388 while (my @data = $sth->fetchrow_array) { 382 389 my %row; 383 $row{gr pid} = $data[0];384 $row{gr pname} = $data[1];385 $row{pgr p} = $data[2];390 $row{groupid} = $data[0]; 391 $row{groupname} = $data[1]; 392 $row{pgroup} = $data[2]; 386 393 $row{nusers} = $data[3]; 387 394 $row{ndomains} = $data[4]; 388 395 $row{bg} = ($rownum++)%2; 389 396 $row{sid} = $sid; 390 push @gr plist, \%row;391 } 392 $page->param(gr ptable => \@grplist);397 push @grouplist, \%row; 398 } 399 $page->param(grouptable => \@grouplist); 393 400 394 401 $page->param(curpage => $webvar{page}); 395 402 396 403 } elsif ($webvar{page} eq 'newgrp') { 404 397 405 # do.. uhh.. stuff.. if we have no webvar{action} 398 406 if ($webvar{action} && $webvar{action} eq 'add') { … … 403 411 $page->param(errmsg => $msg); 404 412 $page->param(newgroup => $webvar{newgroup}); 405 fill_gr plist('pargroup',$webvar{pargroup});413 fill_grouplist('pargroup',$webvar{pargroup}); 406 414 } else { 407 415 # $page->param 408 fill_grplist('pargroup',$curgroup); 409 410 } 416 fill_grouplist('pargroup',$curgroup); 417 418 } 419 420 } elsif ($webvar{page} eq 'delgroup') { 421 422 $page->param(id => $webvar{id}); 423 # first pass = confirm y/n (sorta) 424 if (!defined($webvar{del})) { 425 $page->param(del_getconf => 1); 426 $page->param(groupname => groupName($dbh,$webvar{id})); 427 # print some neato things? 428 429 # } else { 430 # #whether actually deleting or cancelling we redirect to the group list, default format 431 432 } elsif ($webvar{del} eq 'ok') { 433 my ($code,$msg) = delGroup($dbh, $webvar{id}); 434 if ($code ne 'OK') { 435 # need to find failure mode 436 $page->param(del_failed => 1); 437 $page->param(errmsg => $msg); 438 } else { 439 # success. go back to the domain list, do not pass "GO" 440 changepage(page => "grpman"); 441 } 442 } else { 443 # cancelled. whee! 444 changepage(page => "grpman"); 445 } 446 411 447 } 412 448 … … 417 453 foreach (@debugbits) { print; } 418 454 419 # 455 ##common bits 420 456 if ($webvar{page} ne 'login') { 421 $page->param(grp => $group); 422 $page->param(grpname => grpName($dbh,$group)); 423 fill_grplist("grplist"); 457 $page->param(group => $curgroup); 458 $page->param(groupname => groupName($dbh,$curgroup)); 459 460 # stuff for menu group change. nb: this is icky. 461 fill_grouplist("grouplist"); 462 $page->param(whereami => $ENV{REQUEST_URI}); 424 463 } 425 464 … … 430 469 foreach my $key (keys %webvar) { 431 470 print "key: $key\tval: $webvar{$key}\n"; 471 } 472 print "</pre>\nsession:\n<pre>\n"; 473 my $sesdata = $session->dataref(); 474 foreach my $key (keys %$sesdata) { 475 print "key: $key\tval: ".$sesdata->{$key}."\n"; 432 476 } 433 477 print "</pre>\nENV:\n<pre>\n"; … … 604 648 605 649 my $sth = $dbh->prepare("SELECT count(*) FROM domains WHERE group_id=?"); 606 $sth->execute($ group);650 $sth->execute($curgroup); 607 651 my ($count) = $sth->fetchrow_array; 608 652 609 653 # fill page count and first-previous-next-last-all bits 610 654 ##fixme - hardcoded group bit 611 fill_pgcount($count,"domains", "default group");655 fill_pgcount($count,"domains",groupName($dbh,$curgroup)); 612 656 fill_fpnla($count); 613 657 614 658 ##fixme - group 615 $page->param(gr p => 1);659 $page->param(group => $curgroup); 616 660 my @domlist; 617 $sth = $dbh->prepare("select domain_id,domain,status,groups.group_name from domains". 618 " inner join groups on domains.group_id=groups.group_id". 619 " order by domain".($offset eq 'all' ? '' : " limit $perpage offset ".$offset*$perpage)); 620 $sth->execute; 661 $sth = $dbh->prepare("SELECT domain_id,domain,status,groups.group_name FROM domains". 662 " INNER JOIN groups ON domains.group_id=groups.group_id". 663 " WHERE domains.group_id=?". 664 " ORDER BY domain".($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage)); 665 $sth->execute($curgroup); 621 666 my $rownum = 0; 622 667 while (my @data = $sth->fetchrow_array) { … … 638 683 639 684 640 sub fill_gr plist {685 sub fill_grouplist { 641 686 my $template_var = shift; 642 687 my $cur = shift || $curgroup; … … 644 689 my $sth = $dbh->prepare("SELECT group_id,parent_group_id,group_name FROM groups ORDER BY group_id"); 645 690 $sth->execute; 646 my @gr plist;647 while (my ($gr pid,$pargrp,$grpname) = $sth->fetchrow_array()) {691 my @grouplist; 692 while (my ($groupid,$pargroup,$groupname) = $sth->fetchrow_array()) { 648 693 my %row; 649 $row{gr pname} = $grpname;650 $row{gr pval} = $grpid;694 $row{groupname} = $groupname; 695 $row{groupval} = $groupid; 651 696 ##fixme: need magic 652 # $row{defgr p} = '';653 $row{gr pactive} = 1 if $grpid == $cur;654 push @gr plist, \%row;655 } 656 657 $page->param("$template_var" => \@gr plist);658 659 } 697 # $row{defgroup} = ''; 698 $row{groupactive} = 1 if $groupid == $cur; 699 push @grouplist, \%row; 700 } 701 702 $page->param("$template_var" => \@grouplist); 703 704 } -
trunk/templates/grpman.tmpl
r19 r20 31 31 <td class="underline" width="1%">Delete</td> 32 32 </tr> 33 <TMPL_IF name=gr ptable>34 <TMPL_LOOP name=gr ptable>33 <TMPL_IF name=grouptable> 34 <TMPL_LOOP name=grouptable> 35 35 <tr class="row<TMPL_VAR name=bg>"> 36 <td><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=grpman&id=<TMPL_VAR NAME=gr pid>"><TMPL_VAR NAME=grpname></a></td>37 <td width="5%" nowrap><TMPL_VAR name=pgr p></td>36 <td><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=grpman&id=<TMPL_VAR NAME=groupid>"><TMPL_VAR NAME=groupname></a></td> 37 <td width="5%" nowrap><TMPL_VAR name=pgroup></td> 38 38 <td width="5%" nowrap><TMPL_VAR name=nusers></td> 39 39 <td width="5%" nowrap><TMPL_VAR name=ndomains></td> 40 <td width="1%" nowrap align=center><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=delgrp&id=<TMPL_VAR NAME=gr pid>"><img src="images/trash2.png" border=0></a></td>40 <td width="1%" nowrap align=center><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=delgrp&id=<TMPL_VAR NAME=groupid>"><img src="images/trash2.png" border=0></a></td> 41 41 </tr> 42 42 </TMPL_LOOP> -
trunk/templates/menu.tmpl
r18 r20 3 3 <a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=useradmin">Users</a><br /> 4 4 <a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=log">Log</a><br /> 5 <a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=reclist&id=<TMPL_VAR NAME=gr p>&defrec=y">Default Records</a><br />5 <a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=reclist&id=<TMPL_VAR NAME=group>&defrec=y">Default Records</a><br /> 6 6 <a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=axfr">AXFR Import</a><br /> 7 7 <hr> 8 8 Current group: 9 <form action="<TMPL_VAR NAME=whereami>" method="POST"> 9 10 <select name="group"> 10 <TMPL_LOOP NAME=gr plist><option value="<TMPL_VAR NAME=grpval>"<TMPL_IF NAME=grpactive> selected</TMPL_IF>><TMPL_VAR NAME=grpname></option>11 <TMPL_LOOP NAME=grouplist><option value="<TMPL_VAR NAME=groupval>"<TMPL_IF NAME=groupactive> selected</TMPL_IF>><TMPL_VAR NAME=groupname></option> 11 12 </TMPL_LOOP> 12 13 </select> 14 <input type=hidden name=action value="chgroup"> 15 <input type=submit value="Change group"> 16 </form> 13 17 <hr> 14 18 <a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=grpman">Manage groups</a><br /> 15 <TMPL_VAR NAME=gr pname>19 <TMPL_VAR NAME=groupname> 16 20 <hr> 17 21 <a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=dnsq">DNS Query</a><br /> -
trunk/templates/newdomain.tmpl
r2 r20 24 24 <td>Add domain to group:</td> 25 25 <td><select name=group> 26 <TMPL_LOOP name=gr plist> <option value="<TMPL_VAR NAME=grpval>" <TMPL_VAR name=defgrp>><TMPL_VAR name=grpname></option>26 <TMPL_LOOP name=grouplist> <option value="<TMPL_VAR NAME=groupval>"<TMPL_IF groupactive> selected</TMPL_IF>><TMPL_VAR name=groupname></option> 27 27 </TMPL_LOOP> 28 28 </select></td> -
trunk/templates/newgrp.tmpl
r19 r20 24 24 <td>Add as subgroup of:</td> 25 25 <td><select name=pargroup> 26 <TMPL_LOOP name=pargroup> <option value="<TMPL_VAR NAME=gr pval>"<TMPL_IF grpactive> selected</TMPL_IF>><TMPL_VAR name=grpname></option>26 <TMPL_LOOP name=pargroup> <option value="<TMPL_VAR NAME=groupval>"<TMPL_IF groupactive> selected</TMPL_IF>><TMPL_VAR name=groupname></option> 27 27 </TMPL_LOOP> 28 28 </select></td>
Note:
See TracChangeset
for help on using the changeset viewer.