Changeset 17 for trunk/dns.cgi


Ignore:
Timestamp:
09/30/09 16:54:10 (15 years ago)
Author:
Kris Deugau
Message:

/trunk

checkpoint
dns.cgi:

  • misc group-handling tweaks/fixme-fixes
  • misc code and SQL formatting normalizations
  • add group management list-the-groups page
  • extend common-template-parameters section

DNSDB.pm:

  • fix start point for returned records in record list
  • fix several return-on-error conditions for record add/update

templates/

  • add group management/comment to menu
  • use fpnla.tmpl in domlist.tmpl
  • misc minor fixups
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dns.cgi

    r16 r17  
    4949}
    5050
    51 my $group = ($webvar{grp} ? $webvar{grp} : 1);
     51my $group = ($webvar{group} ? $webvar{group} : 1);
    5252# handle login redirect
    5353if ($webvar{action} && $webvar{action} eq 'login') {
     
    127127  if ($webvar{defrec} eq 'y') {
    128128##fixme: hardcoded group
    129     showdomain('y',1);
     129    showdomain('y',$group);
    130130  } else {
    131131    showdomain('n',$webvar{id});
     
    209209    $page->param(recact         => "update");
    210210    $page->param(parentid       => $webvar{parentid});
     211    $page->param(id             => $webvar{id});
    211212    $page->param(defrec         => $webvar{defrec});
    212213    my $sth = $dbh->prepare("SELECT host,type,val,distance,weight,port,ttl FROM ".
     
    229230
    230231    if ($code eq 'OK') {
    231       $page->param(failed       => 1);
    232       $page->param(errmsg       => "testing");
    233       $page->param(wastrying    => "updating");
    234       $page->param(todo         => "Update record");
    235       $page->param(recact       => "update");
    236       $page->param(parentid     => $webvar{parentid});
    237       $page->param(defrec       => $webvar{defrec});
    238       fill_recdata();
    239 #      changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec});
     232      changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec});
    240233    } else {
    241234      $page->param(failed       => 1);
     
    246239      $page->param(parentid     => $webvar{parentid});
    247240      $page->param(defrec       => $webvar{defrec});
     241      $page->param(id           => $webvar{id});
    248242      fill_recdata();
    249243    }
     
    251245
    252246  if ($webvar{defrec} eq 'y') {
    253     $page->param(dohere => "group ".grpName($dbh,$webvar{parentid}));
     247    $page->param(dohere => "default records in group ".grpName($dbh,$webvar{parentid}));
    254248  } else {
    255249    $page->param(dohere => domainName($dbh,$webvar{parentid}));
     
    371365  }
    372366
    373 
    374 }
    375 
    376 
    377 ## hmm.  may want to move this so we can redirect after adding/deleting/etc
     367} elsif ($webvar{page} eq 'grpman') {
     368
     369  my $sth = $dbh->prepare("select count(*) from groups");
     370  $sth->execute;
     371  my ($count) = ($sth->fetchrow_array);
     372
     373# fill page count and first-previous-next-last-all bits
     374##fixme - hardcoded group bit
     375  fill_pgcount($count,"groups",'');
     376  fill_fpnla($count);
     377
     378  my @grplist;
     379  $sth = $dbh->prepare("SELECT g.group_id, g.group_name, g2.group_name, ".
     380        "count(distinct(u.email)), count(distinct(d.domain)) ".
     381        "FROM groups g ".
     382        "INNER JOIN groups g2 ON g2.group_id=g.parent_group_id ".
     383        "LEFT OUTER JOIN users u ON u.group_id=g.group_id ".
     384        "LEFT OUTER JOIN domains d ON d.group_id=g.group_id ".
     385        "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
     388  $sth->execute;
     389  my $rownum = 0;
     390  while (my @data = $sth->fetchrow_array) {
     391    my %row;
     392    $row{grpid} = $data[0];
     393    $row{grpname} = $data[1];
     394    $row{pgrp} = $data[2];
     395    $row{nusers} = $data[3];
     396    $row{ndomains} = $data[4];
     397    $row{bg} = ($rownum++)%2;
     398    $row{sid} = $sid;
     399    push @grplist, \%row;
     400  }
     401  $page->param(grptable => \@grplist);
     402
     403} elsif ($webvar{page} eq 'newgrp') {
     404
     405}
     406
     407
     408# start output here so we can redirect pages.
    378409print "Content-type: text/html\n\n", $header->output;
    379410
    380411foreach (@debugbits) { print; }
    381412
    382 $page->param(grp => $group) if $webvar{page} ne 'login';
     413# common bits
     414if ($webvar{page} ne 'login') {
     415  $page->param(grp => $group);
     416  $page->param(grpname => grpName($dbh,$group));
     417  $page->param(curpage => $webvar{page});
     418}
    383419
    384420# spit it out
     
    423459    $domname = "DOMAIN";
    424460  } else {
    425     my $sth = $dbh->prepare("select domain from domains where domain_id=$webvar{domain}");
    426     $sth->execute();
     461    my $sth = $dbh->prepare("SELECT domain FROM domains WHERE domain_id=?");
     462    $sth->execute($webvar{domain});
    427463    ($domname) = $sth->fetchrow_array();
    428464  }
    429465
    430   $page->param(domain => $domname);
    431   $page->param(defrec => !$webvar{domain});
    432   $page->param(group => $DNSDB::group);
     466  $page->param(domain   => $domname);
     467  $page->param(defrec   => !$webvar{domain});
     468  $page->param(group    => $DNSDB::group);
    433469
    434470# defaults
    435   $page->param(defcontact => $DNSDB::def{contact});
    436   $page->param(defns => $DNSDB::def{prins});
    437   $page->param(defsoattl => $DNSDB::def{soattl});
    438   $page->param(defrefresh => $DNSDB::def{refresh});
    439   $page->param(defretry => $DNSDB::def{retry});
    440   $page->param(defexpire => $DNSDB::def{expire});
    441   $page->param(defminttl => $DNSDB::def{minttl});
     471  $page->param(defcontact       => $DNSDB::def{contact});
     472  $page->param(defns            => $DNSDB::def{prins});
     473  $page->param(defsoattl        => $DNSDB::def{soattl});
     474  $page->param(defrefresh       => $DNSDB::def{refresh});
     475  $page->param(defretry         => $DNSDB::def{retry});
     476  $page->param(defexpire        => $DNSDB::def{expire});
     477  $page->param(defminttl        => $DNSDB::def{minttl});
    442478
    443479  # there are probably better ways to do this.  TMTOWTDI.
     
    490526  my $type = shift || $reverse_typemap{A};
    491527
    492   my $sth = $dbh->prepare("select val,name from rectypes where stdflag=1 order by listorder");
     528  my $sth = $dbh->prepare("SELECT val,name FROM rectypes WHERE stdflag=1 ORDER BY listorder");
    493529  $sth->execute;
    494 push @debugbits, "type $type";
    495530  my @typelist;
    496531  while (my ($rval,$rname) = $sth->fetchrow_array()) {
     
    518553##fixme
    519554  if ($offset eq 'all') {
    520     #print "foo!  wanna see'em all\n";
     555    push @debugbits, "foo!  wanna see'em all\n";
    521556  } else {
    522557    # all these bits only have sensible behaviour if offset is numeric. err, probably.
     
    559594
    560595sub listdomains {
    561   my $sth = $dbh->prepare("select count(*) from domains");
    562   $sth->execute;
    563   my ($count) = ($sth->fetchrow_array);
     596
     597  my $sth = $dbh->prepare("SELECT count(*) FROM domains WHERE group_id=?");
     598  $sth->execute($group);
     599  my ($count) = $sth->fetchrow_array;
    564600
    565601# fill page count and first-previous-next-last-all bits
     
    571607  $page->param(grp => 1);
    572608  my @domlist;
    573   $sth = $dbh->prepare("select domain_id,domain,status,groups.name from domains".
     609  $sth = $dbh->prepare("select domain_id,domain,status,groups.group_name from domains".
    574610        " inner join groups on domains.group_id=groups.group_id".
    575611        " order by domain".($offset eq 'all' ? '' : " limit $perpage offset ".$offset*$perpage));
Note: See TracChangeset for help on using the changeset viewer.