Changeset 20 for trunk


Ignore:
Timestamp:
10/15/09 13:23:51 (15 years ago)
Author:
Kris Deugau
Message:

/trunk

checkpoint, group mangling almost complete
also normalized *most* group* refs to use "group*" vs "grp*"

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r19 r20  
    2323@ISA            = qw(Exporter);
    2424@EXPORT_OK      = qw(
    25         &initGlobals &connectDB &finish &addDomain &delDomain &domainName &addGroup &getChildren &grpName &getSOA
    26         &getRecLine &getDomRecs &addRec &updateRec &delRec &domStatus
     25        &initGlobals &connectDB &finish &addDomain &delDomain &domainName &addGroup &getChildren &groupName
     26        &getSOA &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 &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
    3534                %typemap %reverse_typemap
    3635                )]
     
    264263  $errstr = '';
    265264  my $dbh = shift;
    266   my $grpname = shift;
    267   my $pargrp = shift;
     265  my $groupname = shift;
     266  my $pargroup = shift;
    268267
    269268  # 0 indicates "template", hardcoded.
     
    279278  eval {
    280279    my $sth = $dbh->prepare("INSERT INTO groups (parent_group_id,group_name) VALUES (?,?)");
    281     $sth->execute($pargrp,$grpname);
     280    $sth->execute($pargroup,$groupname);
    282281
    283282    $sth = $dbh->prepare("SELECT group_id FROM groups WHERE group_name=?");
    284     $sth->execute($grpname);
    285     my ($grpid) = $sth->fetchrow_array();
     283    $sth->execute($groupname);
     284    my ($groupid) = $sth->fetchrow_array();
    286285
    287286    $sth = $dbh->prepare("INSERT INTO default_records (group_id,host,type,val,distance,weight,port,ttl) ".
    288         "VALUES ($grpid,?,?,?,?,?,?,?)");
     287        "VALUES ($groupid,?,?,?,?,?,?,?)");
    289288    if ($torc) {
    290289      my $sth2 = $dbh->prepare("SELECT host,type,val,distance,weight,port,ttl FROM default_records WHERE group_id=?");
     
    326325  $errstr = '';
    327326  my $dbh = shift;
    328   my $rootgrp = shift;
    329   my $grpdest = shift;
     327  my $rootgroup = shift;
     328  my $groupdest = shift;
    330329
    331330  # special break for default group;  otherwise we get stuck.
    332   if ($rootgrp == 1) {
     331  if ($rootgroup == 1) {
    333332    # by definition, group 1 is the Root Of All Groups
    334333    my $sth = $dbh->prepare("SELECT group_id FROM groups");
    335334    $sth->execute;
    336     my @grplist;
     335    my @grouplist;
    337336    while (my @this = $sth->fetchrow_array) {
    338       push @$grpdest, @this;
     337      push @$groupdest, @this;
    339338    }
    340339  } else {
    341340    my $sth = $dbh->prepare("SELECT group_id FROM groups WHERE parent_group_id=?");
    342     $sth->execute($rootgrp);
     341    $sth->execute($rootgroup);
    343342    return if $sth->rows == 0;
    344     my @grplist;
    345     while (my ($grp) = $sth->fetchrow_array) {
    346       push @$grpdest, $grp;
    347       getChildren($dbh,$grp,$grpdest);
     343    my @grouplist;
     344    while (my ($group) = $sth->fetchrow_array) {
     345      push @$groupdest, $group;
     346      getChildren($dbh,$group,$groupdest);
    348347    }
    349348  }
     
    351350
    352351
    353 ## DNSDB::grpName()
     352## DNSDB::groupName()
    354353# Return the group name based on a group ID
    355354# Takes a database handle and the group ID
    356355# Returns the group name or undef on failure
    357 sub grpName {
    358   $errstr = '';
    359   my $dbh = shift;
    360   my $grpid = shift;
    361   my $sth = $dbh->prepare("select name from groups where group_id=?");
    362   $sth->execute($grpid);
    363   my ($grpname) = $sth->fetchrow_array();
    364   $errstr = $DBI::errstr if !$grpname;
    365   return $grpname if $grpname;
    366 } # end domainName
     356sub 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
    367366
    368367
  • trunk/dns.cgi

    r19 r20  
    5959}
    6060
     61if ($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
    6168my $header = HTML::Template->new(filename => "$templatedir/header.tmpl");
    6269my $footer = HTML::Template->new(filename => "$templatedir/footer.tmpl");
     
    132139  if ($webvar{defrec} eq 'y') {
    133140##fixme: hardcoded group
    134     showdomain('y',$group);
     141    showdomain('y',$curgroup);
    135142  } else {
    136143    showdomain('n',$webvar{id});
     
    236243
    237244  if ($webvar{defrec} eq 'y') {
    238     $page->param(dohere => "default records in group ".grpName($dbh,$webvar{parentid}));
     245    $page->param(dohere => "default records in group ".groupName($dbh,$webvar{parentid}));
    239246  } else {
    240247    $page->param(dohere => domainName($dbh,$webvar{parentid}));
     
    339346
    340347##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));
    342349
    343350# hokay, a bit of magic to decide which page we hit.
     
    367374  fill_fpnla($count);
    368375
    369   my @grplist;
     376  my @grouplist;
    370377  $sth = $dbh->prepare("SELECT g.group_id, g.group_name, g2.group_name, ".
    371378        "count(distinct(u.email)), count(distinct(d.domain)) ".
     
    381388  while (my @data = $sth->fetchrow_array) {
    382389    my %row;
    383     $row{grpid} = $data[0];
    384     $row{grpname} = $data[1];
    385     $row{pgrp} = $data[2];
     390    $row{groupid} = $data[0];
     391    $row{groupname} = $data[1];
     392    $row{pgroup} = $data[2];
    386393    $row{nusers} = $data[3];
    387394    $row{ndomains} = $data[4];
    388395    $row{bg} = ($rownum++)%2;
    389396    $row{sid} = $sid;
    390     push @grplist, \%row;
    391   }
    392   $page->param(grptable => \@grplist);
     397    push @grouplist, \%row;
     398  }
     399  $page->param(grouptable => \@grouplist);
    393400
    394401  $page->param(curpage => $webvar{page});
    395402
    396403} elsif ($webvar{page} eq 'newgrp') {
     404
    397405  # do.. uhh.. stuff.. if we have no webvar{action}
    398406  if ($webvar{action} && $webvar{action} eq 'add') {
     
    403411    $page->param(errmsg => $msg);
    404412    $page->param(newgroup => $webvar{newgroup});
    405      fill_grplist('pargroup',$webvar{pargroup});
     413     fill_grouplist('pargroup',$webvar{pargroup});
    406414  } else {
    407415#    $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
    411447}
    412448
     
    417453foreach (@debugbits) { print; }
    418454
    419 # common bits
     455##common bits
    420456if ($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});
    424463}
    425464
     
    430469foreach my $key (keys %webvar) {
    431470  print "key: $key\tval: $webvar{$key}\n";
     471}
     472print "</pre>\nsession:\n<pre>\n";
     473my $sesdata = $session->dataref();
     474foreach my $key (keys %$sesdata) {
     475  print "key: $key\tval: ".$sesdata->{$key}."\n";
    432476}
    433477print "</pre>\nENV:\n<pre>\n";
     
    604648
    605649  my $sth = $dbh->prepare("SELECT count(*) FROM domains WHERE group_id=?");
    606   $sth->execute($group);
     650  $sth->execute($curgroup);
    607651  my ($count) = $sth->fetchrow_array;
    608652
    609653# fill page count and first-previous-next-last-all bits
    610654##fixme - hardcoded group bit
    611   fill_pgcount($count,"domains","default group");
     655  fill_pgcount($count,"domains",groupName($dbh,$curgroup));
    612656  fill_fpnla($count);
    613657
    614658##fixme - group
    615   $page->param(grp => 1);
     659  $page->param(group => $curgroup);
    616660  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);
    621666  my $rownum = 0;
    622667  while (my @data = $sth->fetchrow_array) {
     
    638683
    639684
    640 sub fill_grplist {
     685sub fill_grouplist {
    641686  my $template_var = shift;
    642687  my $cur = shift || $curgroup;
     
    644689  my $sth = $dbh->prepare("SELECT group_id,parent_group_id,group_name FROM groups ORDER BY group_id");
    645690  $sth->execute;
    646   my @grplist;
    647   while (my ($grpid,$pargrp,$grpname) = $sth->fetchrow_array()) {
     691  my @grouplist;
     692  while (my ($groupid,$pargroup,$groupname) = $sth->fetchrow_array()) {
    648693    my %row;
    649     $row{grpname} = $grpname;
    650     $row{grpval} = $grpid;
     694    $row{groupname} = $groupname;
     695    $row{groupval} = $groupid;
    651696##fixme: need magic
    652 #    $row{defgrp} = '';
    653     $row{grpactive} = 1 if $grpid == $cur;
    654     push @grplist, \%row;
    655   }
    656 
    657   $page->param("$template_var" => \@grplist);
    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  
    3131        <td class="underline" width="1%">Delete</td>
    3232</tr>
    33 <TMPL_IF name=grptable>
    34 <TMPL_LOOP name=grptable>
     33<TMPL_IF name=grouptable>
     34<TMPL_LOOP name=grouptable>
    3535<tr class="row<TMPL_VAR name=bg>">
    36         <td><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=grpman&id=<TMPL_VAR NAME=grpid>"><TMPL_VAR NAME=grpname></a></td>
    37         <td width="5%" nowrap><TMPL_VAR name=pgrp></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>
    3838        <td width="5%" nowrap><TMPL_VAR name=nusers></td>
    3939        <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=grpid>"><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>
    4141</tr>
    4242</TMPL_LOOP>
  • trunk/templates/menu.tmpl

    r18 r20  
    33<a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=useradmin">Users</a><br />
    44<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=grp>&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 />
    66<a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=axfr">AXFR Import</a><br />
    77<hr>
    88Current group:
     9<form action="<TMPL_VAR NAME=whereami>" method="POST">
    910<select name="group">
    10         <TMPL_LOOP NAME=grplist><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>
    1112        </TMPL_LOOP>
    1213</select>
     14<input type=hidden name=action value="chgroup">
     15<input type=submit value="Change group">
     16</form>
    1317<hr>
    1418<a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=grpman">Manage groups</a><br />
    15  <TMPL_VAR NAME=grpname>
     19 <TMPL_VAR NAME=groupname>
    1620<hr>
    1721<a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=dnsq">DNS Query</a><br />
  • trunk/templates/newdomain.tmpl

    r2 r20  
    2424                <td>Add domain to group:</td>
    2525                <td><select name=group>
    26 <TMPL_LOOP name=grplist>                <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>
    2727</TMPL_LOOP>
    2828                </select></td>
  • trunk/templates/newgrp.tmpl

    r19 r20  
    2424                <td>Add as subgroup of:</td>
    2525                <td><select name=pargroup>
    26 <TMPL_LOOP name=pargroup>               <option value="<TMPL_VAR NAME=grpval>"<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>
    2727</TMPL_LOOP>
    2828                </select></td>
Note: See TracChangeset for help on using the changeset viewer.