Changeset 18 for trunk


Ignore:
Timestamp:
10/08/09 17:29:50 (15 years ago)
Author:
Kris Deugau
Message:

/trunk

checkpoint

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r17 r18  
    2323@ISA            = qw(Exporter);
    2424@EXPORT_OK      = qw(
    25         &initGlobals &connectDB &finish &addDomain &delDomain &domainName &grpName &getSOA &getRecLine
    26         &getDomRecs &addRec &updateRec &delRec &domStatus
     25        &initGlobals &connectDB &finish &addDomain &delDomain &domainName &addGroup &grpName &getSOA
     26        &getRecLine &getDomRecs &addRec &updateRec &delRec &domStatus
    2727        %typemap %reverse_typemap
    2828        );
     
    3030@EXPORT         = (); # Export nothing by default.
    3131%EXPORT_TAGS    = ( ALL => [qw(
    32                 &initGlobals &connectDB &finish &addDomain &delDomain &domainName &grpName &getSOA &getRecLine
    33                 &getDomRecs &addRec &updateRec &delRec &domStatus
     32                &initGlobals &connectDB &finish &addDomain &delDomain &domainName &addGroup &grpName &getSOA
     33                &getRecLine &getDomRecs &addRec &updateRec &delRec &domStatus
    3434                %typemap %reverse_typemap
    3535                )]
     
    256256
    257257
     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
     262sub 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
     304die "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
    258320## DNSDB::grpName()
    259321# Return the group name based on a group ID
  • trunk/dns.cgi

    r17 r18  
    4545# need to know the "upper" group the user can deal with;  may as well
    4646# 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
     51my $logingroup = $session->param('logingroup');
     52my $curgroup = ($session->param('curgroup') ? $session->param('curgroup') : $session->param('logingroup'));
    5153my $group = ($webvar{group} ? $webvar{group} : 1);
     54
    5255# handle login redirect
    5356if ($webvar{action} && $webvar{action} eq 'login') {
     
    102105  }
    103106
     107  $page->param(curpage => $webvar{page});
     108
    104109  listdomains();
    105110
     
    110115  $page->param(defrec => $webvar{defrec});
    111116  $page->param(id => $webvar{id});
    112   $page->param(curpage => 'reclist');
     117  $page->param(curpage => $webvar{page});
    113118
    114119# select count(*) from (default_)?records where (group|domain)_id=?
     
    134139} elsif ($webvar{page} eq 'newdomain') {
    135140
    136   # weesa gonna discard parent_group_id for now
    137   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 magic
    145 #    $row{defgrp} = '';
    146     push @grplist, \%row;
    147   }
    148 
    149   $page->param(grplist => \@grplist);
    150141
    151142} elsif ($webvar{page} eq 'deldom') {
     
    384375        "LEFT OUTER JOIN domains d ON d.group_id=g.group_id ".
    385376        "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));
    388378  $sth->execute;
     379
    389380  my $rownum = 0;
    390381  while (my @data = $sth->fetchrow_array) {
     
    401392  $page->param(grptable => \@grplist);
    402393
     394  $page->param(curpage => $webvar{page});
     395
    403396} 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  }
    405406}
    406407
     
    415416  $page->param(grp => $group);
    416417  $page->param(grpname => grpName($dbh,$group));
    417   $page->param(curpage => $webvar{page});
     418  fill_grplist();
    418419}
    419420
     
    433434print $footer->output;
    434435
     436# as per the docs, Just In Case
     437$session->flush();
    435438
    436439exit 0;
     
    628631  $page->param(domtable => \@domlist);
    629632} # end listdomains()
     633
     634
     635sub 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");
     638push @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  
    11<td class="menu">
    2 Current group: <TMPL_VAR NAME=grpname><br />
    32<a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=domlist">Domains</a><br />
    43<a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=useradmin">Users</a><br />
     
    76<a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=axfr">AXFR Import</a><br />
    87<hr>
    9 <a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=grpman">Manage groups</a><br />
     8Current group:
    109<select name="group">
    11         <TMPL_LOOP NAME=grouplist><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>
    1211        </TMPL_LOOP>
    1312</select>
     13<hr>
     14<a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=grpman">Manage groups</a><br />
     15 <TMPL_VAR NAME=grpname>
    1416<hr>
    1517<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.