- Timestamp:
- 10/08/09 17:29:50 (15 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r17 r18 23 23 @ISA = qw(Exporter); 24 24 @EXPORT_OK = qw( 25 &initGlobals &connectDB &finish &addDomain &delDomain &domainName & grpName &getSOA &getRecLine26 &get DomRecs &addRec &updateRec &delRec &domStatus25 &initGlobals &connectDB &finish &addDomain &delDomain &domainName &addGroup &grpName &getSOA 26 &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 & grpName &getSOA &getRecLine33 &get DomRecs &addRec &updateRec &delRec &domStatus32 &initGlobals &connectDB &finish &addDomain &delDomain &domainName &addGroup &grpName &getSOA 33 &getRecLine &getDomRecs &addRec &updateRec &delRec &domStatus 34 34 %typemap %reverse_typemap 35 35 )] … … 256 256 257 257 258 ## DNSDB::addGroup() 259 # Add a group 260 # Takes a database handle, group name, parent group, and template-vs-cloneme flag 261 # Returns a status code and message 262 sub addGroup { 263 $errstr = ''; 264 my $dbh = shift; 265 my $grpname = shift; 266 my $pargrp = shift; 267 268 # 0 indicates "template", hardcoded. 269 # Any other value clones that group's default records, if it exists. 270 my $torc = shift || 0; 271 272 # Allow transactions, and raise an exception on errors so we can catch it later. 273 # Use local to make sure these get "reset" properly on exiting this block 274 local $dbh->{AutoCommit} = 0; 275 local $dbh->{RaiseError} = 1; 276 277 # Wrap all the SQL in a transaction 278 eval { 279 my $sth = $dbh->prepare("INSERT INTO groups (parent_group_id,group_name) VALUES (?,?)"); 280 $sth->execute($pargrp,$grpname); 281 282 $sth = $dbh->prepare("SELECT group_id FROM groups WHERE group_name=?"); 283 $sth->execute($grpname); 284 my ($grpid) = $sth->fetchrow_array(); 285 286 $sth = $dbh->prepare("INSERT INTO default_records (group_id,host,type,val,distance,weight,port,ttl) ". 287 "VALUES ($grpid,?,?,?,?,?,?,?)"); 288 if ($torc) { 289 my $sth2 = $dbh->prepare("SELECT host,type,val,distance,weight,port,ttl FROM default_records WHERE group_id=?"); 290 while (my @clonedata = $sth2->fetchrow_array) { 291 $sth->execute(@clonedata); 292 } 293 } else { 294 # reasonable basic defaults for SOA, MX, NS, and minimal hosting 295 # could load from a config file, but somewhere along the line we need hardcoded bits. 296 $sth->execute('ns1.example.com:hostmaster.example.com', 6, '10800:3600:604800:10800', 0, 0, 0, 86400); 297 $sth->execute('DOMAIN', 1, '192.168.4.2', 0, 0, 0, 7200); 298 $sth->execute('DOMAIN', 15, 'mx.example.com', 10, 0, 0, 7200); 299 $sth->execute('DOMAIN', 2, 'ns1.example.com', 0, 0, 0, 7200); 300 $sth->execute('DOMAIN', 2, 'ns2.example.com', 0, 0, 0, 7200); 301 $sth->execute('www.DOMAIN', 5, 'DOMAIN', 0, 0, 0, 7200); 302 } 303 304 die "epic FAIL.. hahahah, just testing!\n"; 305 # once we get here, we should have suceeded. 306 $dbh->commit; 307 }; # end eval 308 309 if ($@) { 310 my $msg = $@; 311 eval { $dbh->rollback; }; 312 return ('FAIL',$msg); 313 } else { 314 return ('OK','OK'); 315 } 316 317 } # end addGroup() 318 319 258 320 ## DNSDB::grpName() 259 321 # Return the group name based on a group ID -
trunk/dns.cgi
r17 r18 45 45 # need to know the "upper" group the user can deal with; may as well 46 46 # stick this in the session rather than calling out to the DB every time. 47 $session->param('logingroupid',1); 48 $session->param('workinggroupid',1); # yes, we *do* need to track this too. er, probably. 49 } 50 47 $session->param('logingroup',1); 48 $session->param('curgroup',1); # yes, we *do* need to track this too. er, probably. 49 } 50 51 my $logingroup = $session->param('logingroup'); 52 my $curgroup = ($session->param('curgroup') ? $session->param('curgroup') : $session->param('logingroup')); 51 53 my $group = ($webvar{group} ? $webvar{group} : 1); 54 52 55 # handle login redirect 53 56 if ($webvar{action} && $webvar{action} eq 'login') { … … 102 105 } 103 106 107 $page->param(curpage => $webvar{page}); 108 104 109 listdomains(); 105 110 … … 110 115 $page->param(defrec => $webvar{defrec}); 111 116 $page->param(id => $webvar{id}); 112 $page->param(curpage => 'reclist');117 $page->param(curpage => $webvar{page}); 113 118 114 119 # select count(*) from (default_)?records where (group|domain)_id=? … … 134 139 } elsif ($webvar{page} eq 'newdomain') { 135 140 136 # weesa gonna discard parent_group_id for now137 my $sth = $dbh->prepare("select group_id,parent_group_id,name from groups order by group_id");138 $sth->execute;139 my @grplist;140 while (my ($grpid,$pargrp,$grpname) = $sth->fetchrow_array()) {141 my %row;142 $row{grpname} = $grpname;143 $row{grpval} = $grpid;144 ##fixme: need magic145 # $row{defgrp} = '';146 push @grplist, \%row;147 }148 149 $page->param(grplist => \@grplist);150 141 151 142 } elsif ($webvar{page} eq 'deldom') { … … 384 375 "LEFT OUTER JOIN domains d ON d.group_id=g.group_id ". 385 376 "GROUP BY g.group_id, g.group_name, g2.group_name ". 386 "ORDER BY g.group_name".($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage)); 387 377 "ORDER BY g.group_id".($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage)); 388 378 $sth->execute; 379 389 380 my $rownum = 0; 390 381 while (my @data = $sth->fetchrow_array) { … … 401 392 $page->param(grptable => \@grplist); 402 393 394 $page->param(curpage => $webvar{page}); 395 403 396 } elsif ($webvar{page} eq 'newgrp') { 404 397 # do.. uhh.. stuff.. if we have no webvar{action} 398 if ($webvar{action} && $webvar{action} eq 'add') { 399 # not gonna provide the 4th param: template-or-clone flag, just yet 400 my ($code,$msg) = addGroup($dbh, $webvar{newgroup}, $webvar{pargroup}); 401 changepage(page => "grpman") if $code eq 'OK'; 402 $page->param(add_failed => 1); 403 $page->param(errmsg => $msg); 404 $page->param(newgroup => $webvar{newgroup}); 405 } 405 406 } 406 407 … … 415 416 $page->param(grp => $group); 416 417 $page->param(grpname => grpName($dbh,$group)); 417 $page->param(curpage => $webvar{page});418 fill_grplist(); 418 419 } 419 420 … … 433 434 print $footer->output; 434 435 436 # as per the docs, Just In Case 437 $session->flush(); 435 438 436 439 exit 0; … … 628 631 $page->param(domtable => \@domlist); 629 632 } # end listdomains() 633 634 635 sub fill_grplist { 636 # weesa gonna discard parent_group_id for now 637 my $sth = $dbh->prepare("SELECT group_id,parent_group_id,group_name FROM groups ORDER BY group_id"); 638 push @debugbits, "grp list sth err: ".$sth->errstr."<br>\n"; 639 $sth->execute; 640 my @grplist; 641 while (my ($grpid,$pargrp,$grpname) = $sth->fetchrow_array()) { 642 my %row; 643 $row{grpname} = $grpname; 644 $row{grpval} = $grpid; 645 ##fixme: need magic 646 # $row{defgrp} = ''; 647 $row{grpactive} = 1 if $grpid eq $curgroup; 648 push @grplist, \%row; 649 } 650 651 $page->param(grplist => \@grplist); 652 653 } -
trunk/templates/menu.tmpl
r17 r18 1 1 <td class="menu"> 2 Current group: <TMPL_VAR NAME=grpname><br />3 2 <a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=domlist">Domains</a><br /> 4 3 <a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=useradmin">Users</a><br /> … … 7 6 <a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=axfr">AXFR Import</a><br /> 8 7 <hr> 9 <a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=grpman">Manage groups</a><br /> 8 Current group: 10 9 <select name="group"> 11 <TMPL_LOOP NAME=gr ouplist><option value="<TMPL_VAR NAME=grpval>"<TMPL_IF NAME=grplist> selected</TMPL_IF>><TMPL_VAR NAME=grpname></option>10 <TMPL_LOOP NAME=grplist><option value="<TMPL_VAR NAME=grpval>"<TMPL_IF NAME=grpactive> selected</TMPL_IF>><TMPL_VAR NAME=grpname></option> 12 11 </TMPL_LOOP> 13 12 </select> 13 <hr> 14 <a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=grpman">Manage groups</a><br /> 15 <TMPL_VAR NAME=grpname> 14 16 <hr> 15 17 <a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=dnsq">DNS Query</a><br />
Note:
See TracChangeset
for help on using the changeset viewer.