- Timestamp:
- 10/30/09 17:52:55 (15 years ago)
- Location:
- trunk
- Files:
-
- 4 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r23 r24 26 26 &addDomain &delDomain &domainName 27 27 &addGroup &delGroup &getChildren &groupName 28 &addUser &delUser 28 29 &getSOA &getRecLine &getDomRecs 29 30 &addRec &updateRec &delRec … … 37 38 &addDomain &delDomain &domainName 38 39 &addGroup &delGroup &getChildren &groupName 40 &addUser &delUser 39 41 &getSOA &getRecLine &getDomRecs 40 42 &addRec &updateRec &delRec … … 379 381 ## DNSDB::getChildren() 380 382 # Get a list of all groups whose parent^n is group <n> 381 # Takes a database handle, group ID, and reference to an array to put the group IDs in 383 # Takes a database handle, group ID, reference to an array to put the group IDs in, 384 # and an optional flag to return only immediate children or all children-of-children 385 # default to returning all children 382 386 # Calls itself 383 387 sub getChildren { … … 386 390 my $rootgroup = shift; 387 391 my $groupdest = shift; 392 my $immed = shift || 'all'; 388 393 389 394 # special break for default group; otherwise we get stuck. 390 395 if ($rootgroup == 1) { 391 396 # by definition, group 1 is the Root Of All Groups 392 my $sth = $dbh->prepare("SELECT group_id FROM groups"); 397 my $sth = $dbh->prepare("SELECT group_id FROM groups WHERE NOT (group_id=1)". 398 ($immed ne 'all' ? " AND parent_group_id=1" : '')); 393 399 $sth->execute; 394 my @grouplist;395 400 while (my @this = $sth->fetchrow_array) { 396 401 push @$groupdest, @this; … … 403 408 while (my ($group) = $sth->fetchrow_array) { 404 409 push @$groupdest, $group; 405 getChildren($dbh,$group,$groupdest) ;410 getChildren($dbh,$group,$groupdest) if $immed eq 'all'; 406 411 } 407 412 } … … 423 428 return $groupname if $groupname; 424 429 } # end groupName 430 431 432 ## DNSDB::addUser() 433 # 434 sub addUser { 435 $errstr = ''; 436 my $dbh = shift; 437 return ('FAIL',"Need database handle") if !$dbh; 438 my $username = shift; 439 return ('FAIL',"Missing username") if !defined($username); 440 my $group = shift; 441 return ('FAIL',"Missing group") if !defined($group); 442 my $pass = shift; 443 return ('FAIL',"Missing password") if !defined($pass); 444 445 my $state = shift; 446 return ('FAIL',"Need account status") if !defined($state); 447 my $fname = shift || ''; 448 my $lname = shift || ''; 449 450 my $user_id; 451 452 # Allow transactions, and raise an exception on errors so we can catch it later. 453 # Use local to make sure these get "reset" properly on exiting this block 454 local $dbh->{AutoCommit} = 0; 455 local $dbh->{RaiseError} = 1; 456 457 # Wrap all the SQL in a transaction 458 eval { 459 # insert the user... 460 my $sth = $dbh->prepare("INSERT INTO users (email,group_id,password,status) VALUES (?,?,?,?)"); 461 $sth->execute($username,$group,$pass,$state); 462 die "user fail\n"; 463 464 # get the ID... 465 $sth = $dbh->prepare("select user_id from users where username=?"); 466 $sth->execute($username); 467 ($user_id) = $sth->fetchrow_array(); 468 469 # once we get here, we should have suceeded. 470 $dbh->commit; 471 }; # end eval 472 473 if ($@) { 474 my $msg = $@; 475 eval { $dbh->rollback; }; 476 return ('FAIL',$msg); 477 } else { 478 return ('OK',$user_id); 479 } 480 } # end addUser 481 482 483 ## DNSDB::delUser() 484 # 485 sub delUser { 486 } # end delUser 425 487 426 488 … … 574 636 575 637 my $fields = ($defrec eq 'y' ? 'group_id' : 'domain_id').",host,type,val,ttl"; 576 my $vallist = "$id,'$host',$rectype,'$val',$ttl"; 638 my $vallen = "?,?,?,?,?"; 639 my @vallist = ($id,$host,$rectype,$val,$ttl); 577 640 578 641 my $dist; … … 581 644 return ('FAIL',"Need distance for $typemap{$rectype} record") if !defined($dist); 582 645 $fields .= ",distance"; 583 $vallist .= ",$dist"; 646 $vallen .= ",?"; 647 push @vallist, $dist; 584 648 } 585 649 my $weight; 586 650 my $port; 587 651 if ($rectype == $reverse_typemap{SRV}) { 652 # check for _service._protocol. NB: RFC2782 does not say "MUST"... nor "SHOULD"... 653 # it just says (paraphrased) "... is prepended with _ to prevent DNS collisions" 654 return ('FAIL',"SRV records must begin with _service._protocol") 655 if $host !~ /^_[A-Za-z]+\._[A-Za-z]+\.[a-z0-9-]+/; 588 656 $weight = shift; 589 657 $port = shift; 590 658 return ('FAIL',"Need weight and port for SRV record") if !defined($weight) or !defined($port); 591 659 $fields .= ",weight,port"; 592 $vallist .= ",$weight,$port"; 593 } 594 595 my $sql = "insert into ".($defrec eq 'y' ? 'default_' : '')."records ($fields) values ($vallist)"; 660 $vallen .= ",?,?"; 661 push @vallist, ($weight,$port); 662 } 663 664 my $sql = "insert into ".($defrec eq 'y' ? 'default_' : '')."records ($fields) values ($vallen)"; 665 ##fixme: use array for values, replace "vallist" with series of ?,?,? etc 596 666 # something is bugging me about this... 597 667 #warn "DEBUG: $sql"; 598 668 my $sth = $dbh->prepare($sql); 599 $sth->execute ;669 $sth->execute(@vallist); 600 670 601 671 return ('FAIL',$sth->errstr) if $sth->err; -
trunk/dns.cgi
r23 r24 198 198 changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}); 199 199 } else { 200 $page->param(failed => 1); 201 $page->param(errmsg => $msg); 200 201 $page->param(failed => 1); 202 $page->param(errmsg => $msg); 203 $page->param(wastrying => "adding"); 204 $page->param(todo => "Add record to"); 205 $page->param(recact => "add"); 206 $page->param(parentid => $webvar{parentid}); 207 $page->param(defrec => $webvar{defrec}); 208 $page->param(id => $webvar{id}); 202 209 fill_recdata(); # populate the form... er, mostly. 203 210 } … … 246 253 $page->param(dohere => "default records in group ".groupName($dbh,$webvar{parentid})); 247 254 } else { 255 $page->param(parentid => $webvar{parentid}); 256 # $page->param(id => $webvar{id}); 248 257 $page->param(dohere => domainName($dbh,$webvar{parentid})); 249 258 } … … 353 362 # redirect to dns.cgi?etc&page=reclist 354 363 changepage(page => "reclist", id => $msg); 355 $page = HTML::Template->new(filename => "$templatedir/reclist.tmpl"); 356 showdomain(0,$msg); 357 ##work 364 # $page = HTML::Template->new(filename => "$templatedir/reclist.tmpl"); 365 # showdomain(0,$msg); 358 366 } else { 359 367 # oooh, yeah, this is supposed to be a redirect. er, maybe. whee. 368 ##fixme: session ID 360 369 $page = HTML::Template->new(filename => "$templatedir/newdomain.tmpl"); 361 370 $page->param(add_failed => 1); … … 416 425 } 417 426 $page->param(delgroupname => groupName($dbh, $webvar{id})); 427 428 } elsif ($webvar{page} eq 'useradmin') { 429 430 list_users(); 431 $page->param(curpage => $webvar{page}); 432 433 } elsif ($webvar{page} eq 'newuser') { 434 435 # foo? 436 fill_actypelist(); 437 438 } elsif ($webvar{page} eq 'adduser') { 439 440 my ($code,$msg); 441 442 if ($webvar{pass1} ne $webvar{pass2}) { 443 $code = 'FAIL'; 444 $msg = "Passwords don't match"; 445 } else { 446 ($code,$msg) = addUser($dbh,$webvar{username}, $webvar{group}, $webvar{pass1}, 447 ($webvar{makeactive} eq 'on' ? 1 : 0), $webvar{fname}, $webvar{lname}); 448 } 449 450 # hokay, a bit of magic to decide which page we hit. 451 if ($code eq 'OK') { 452 # redirect to dns.cgi?etc&page=reclist 453 changepage(page => "useradmin"); 454 # $page = HTML::Template->new(filename => "$templatedir/reclist.tmpl"); 455 # showdomain(0,$msg); 456 ##work 457 } else { 458 # oooh, yeah, this is supposed to be a redirect. er, maybe. whee. 459 # $page = HTML::Template->new(filename => "$templatedir/newuser.tmpl"); 460 $page->param(add_failed => 1); 461 $page->param(username => $webvar{username}); 462 $page->param(fname => $webvar{fname}); 463 $page->param(lname => $webvar{lname}); 464 $page->param(pass1 => $webvar{pass1}); 465 $page->param(pass2 => $webvar{pass2}); 466 $page->param(errmsg => $msg); 467 fill_actypelist(); 468 } 469 470 $page->param(add_failed => 1); 418 471 } 419 472 … … 421 474 # start output here so we can redirect pages. 422 475 print "Content-type: text/html\n\n", $header->output; 423 424 foreach (@debugbits) { print; }425 476 426 477 ##common bits … … 429 480 $page->param(groupname => groupName($dbh,$curgroup)); 430 481 482 # group tree. should go elsewhere, probably 483 my $tmpgrplist = fill_grptree($logingroup,$curgroup); 484 $page->param(grptree => $tmpgrplist); 485 431 486 # stuff for menu group change. nb: this is icky. 432 487 fill_grouplist("grouplist"); 433 488 $page->param(whereami => $ENV{REQUEST_URI}); 434 489 } 490 491 foreach (@debugbits) { print; } 435 492 436 493 # spit it out … … 458 515 459 516 exit 0; 517 518 519 sub fill_grptree { 520 my $root = shift; 521 my $cur = shift; 522 523 my @childlist; 524 525 my $grptree = HTML::Template->new(filename => 'templates/grptree.tmpl'); 526 getChildren($dbh,$root,\@childlist,'immediate'); 527 return if $#childlist == -1; 528 my @grouplist; 529 foreach (@childlist) { 530 my %row; 531 $row{grpname} = groupName($dbh,$_); 532 $row{grpname} = "<b>$row{grpname}</b>" if $_ == $cur; 533 $row{subs} = fill_grptree($_,$cur); 534 push @grouplist, \%row; 535 } 536 $grptree->param(treelvl => \@grouplist); 537 return $grptree->output; 538 } 460 539 461 540 … … 575 654 $page->param(ttl => ($webvar{ttl} ? $webvar{ttl} : $DNSDB::def{minttl})); 576 655 } 656 657 658 sub fill_actypelist { 659 my @actypes; 660 661 my %row1 = (actypeval => 'u', actypename => 'user'); 662 $row1{typesel} = 1 if $webvar{accttype} eq 'u'; 663 push @actypes, \%row1; 664 665 my %row2 = (actypeval => 'S', actypename => 'superuser'); 666 $row2{typesel} = 1 if $webvar{accttype} eq 'S'; 667 push @actypes, \%row2; 668 669 $page->param(actypelist => \@actypes); 670 } 671 577 672 578 673 sub fill_fpnla { … … 713 808 $page->param("$template_var" => \@grouplist); 714 809 715 } 810 } # end fill_grouplist() 811 812 sub list_users { 813 my $sth = $dbh->prepare("select count(*) from users where group_id=?"); 814 $sth->execute($curgroup); 815 my ($count) = ($sth->fetchrow_array); 816 817 # fill page count and first-previous-next-last-all bits 818 ##fixme - hardcoded group bit 819 fill_pgcount($count,"users",''); 820 fill_fpnla($count); 821 822 my @userlist; 823 $sth = $dbh->prepare("SELECT u.user_id, u.email, u.firstname, u.lastname, u.type, g.group_name, u.status ". 824 "FROM users u ". 825 "INNER JOIN groups g ON u.group_id=g.group_id ". 826 "WHERE u.group_id=?". 827 ($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage)); 828 $sth->execute($curgroup); 829 830 my $rownum = 0; 831 while (my @data = $sth->fetchrow_array) { 832 my %row; 833 $row{userid} = $data[0]; 834 $row{username} = $data[1]; 835 $row{userfull} = "$data[2] $data[3]"; 836 $row{usertype} = ($data[4] eq 'S' ? 'superuser' : "user"); 837 $row{usergroup} = $data[5]; 838 $row{mkactive} = $data[6]; 839 $row{bg} = ($rownum++)%2; 840 $row{sid} = $sid; 841 push @userlist, \%row; 842 } 843 $page->param(usertable => \@userlist); 844 } -
trunk/templates/dns.css
r2 r24 1 1 #debug { 2 2 background-color: #990066; 3 padding: 2px; 3 4 } 4 5 … … 76 77 font-size: 10px; 77 78 } 79 ul { 80 margin-left: 10px; 81 padding: 0px; 82 list-style-type:none; 83 } 78 84 79 85 /* general classes */ -
trunk/templates/menu.tmpl
r20 r24 17 17 <hr> 18 18 <a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=grpman">Manage groups</a><br /> 19 <TMPL_VAR NAME=groupname> 19 <TMPL_VAR NAME=grptree> 20 <!-- hmm: <TMPL_VAR NAME=groupname> --> 20 21 <hr> 21 22 <a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=dnsq">DNS Query</a><br /> -
trunk/templates/newdomain.tmpl
r20 r24 3 3 <TMPL_INCLUDE NAME="menu.tmpl"> 4 4 5 <td >5 <td align="center"> 6 6 <TMPL_IF add_failed><span class="errmsg">Error adding domain <TMPL_VAR NAME=domain>: <TMPL_VAR 7 7 NAME=errmsg></span></TMPL_IF> … … 12 12 <input type="hidden" name="newdomain" value="yes"> 13 13 14 <table border=0 width=" 70%" bgcolor="white">14 <table border=0 width="450" bgcolor="white"> 15 15 <tr><td> 16 <table border=0 cellspacing= 0cellpadding=2 width="100%">16 <table border=0 cellspacing=2 cellpadding=2 width="100%"> 17 17 <tr bgcolor="#cccccc"><td colspan=2 align="center">Add Domain</td></tr> 18 18 19 19 <tr bgcolor="#eeeeee"> 20 <td >Domain Name:</td>20 <td width="50%">Domain Name:</td> 21 21 <td align="left"><input type="text" name="domain" value="<TMPL_VAR NAME=domain>"></td> 22 22 </tr> … … 29 29 </tr> 30 30 <tr bgcolor="#eeeeee"> 31 <td> </td><td><input type=checkbox name=makeactive checked>Make domain active on next DNS propagation</td>31 <td>Make domain active on next DNS propagation</td><td><input type=checkbox name=makeactive checked></td> 32 32 </tr> 33 <tr><td colspan=2 align="center"><input type="submit" value=" add"></td></tr>33 <tr><td colspan=2 align="center"><input type="submit" value="Add domain"></td></tr> 34 34 <tr><td>tmp note: radio button select "group template" vs "clone domain"?</td></tr> 35 35 </table> -
trunk/templates/newgrp.tmpl
r20 r24 28 28 </select></td> 29 29 </tr> 30 <tr><td colspan=2 align="center"><input type="submit" value=" add"></td></tr>30 <tr><td colspan=2 align="center"><input type="submit" value="Add group"></td></tr> 31 31 <tr><td colspan=2>tmp note: radio button select "group template" vs "clone group"?</td></tr> 32 32 </table>
Note:
See TracChangeset
for help on using the changeset viewer.