Changeset 17


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
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r16 r17  
    257257
    258258## DNSDB::grpName()
    259 # Return the domain name based on a domain ID
    260 # Takes a database handle and the domain ID
    261 # Returns the domain name or undef on failure
     259# Return the group name based on a group ID
     260# Takes a database handle and the group ID
     261# Returns the group name or undef on failure
    262262sub grpName {
    263263  $errstr = '';
     
    388388  $sql .= " and not type=$reverse_typemap{SOA} order by $order";
    389389##fixme:  need to set nstart properly (offset is not internally multiplied with limit)
    390   $sql .= " limit $nrecs offset $nstart" if $nstart ne 'all';
     390  $sql .= " limit $nrecs offset ".($nstart*$nrecs) if $nstart ne 'all';
    391391
    392392  my $sth = $dbh->prepare($sql);
     
    457457sub updateRec {
    458458  $errstr = '';
     459
    459460  my $dbh = shift;
    460461  my $defrec = shift;
     
    475476
    476477  if ($type == $reverse_typemap{MX} || $type == $reverse_typemap{SRV}) {
    477     $dist = shift
    478         or return ('FAIL',"MX or SRV requires distance");
     478    $dist = shift;
     479    return ('FAIL',"MX or SRV requires distance") if !defined($dist);
    479480    if ($type == $reverse_typemap{SRV}) {
    480       my $weight = shift
    481         or return ('FAIL',"SRV requires weight");
    482       my $port = shift
    483         or return ('FAIL',"SRV requires port");
     481      $weight = shift;
     482      return ('FAIL',"SRV requires weight") if !defined($weight);
     483      $port = shift;
     484      return ('FAIL',"SRV requires port") if !defined($port);
    484485    }
    485486  }
     
    490491  $sth->execute($host,$type,$val,$ttl,$dist,$weight,$port,$id);
    491492
    492   return ('FAIL',$sth->errstr) if $sth->err;
     493  return ('FAIL',$sth->errstr."<br>\n$errstr<br>\n") if $sth->err;
    493494
    494495  return ('OK','OK');
  • 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));
  • trunk/templates/domlist.tmpl

    r12 r17  
    88<tr><td><TMPL_INCLUDE NAME="pgcount.tmpl"></td>
    99<td>
    10 <TMPL_IF navfirst><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=domlist&offset=0"><img src="images/frev.png" border=0>first</a><TMPL_ELSE><img src="images/frev.png" border=0>first</TMPL_IF>&nbsp;
    11 <TMPL_IF navprev><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=domlist&offset=<TMPL_VAR NAME=prevoffs>"><img src="images/rev.png" border=0>previous</a><TMPL_ELSE><img src="images/rev.png" border=0>previous</TMPL_IF>&nbsp;
    12 <TMPL_IF navnext><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=domlist&offset=<TMPL_VAR NAME=nextoffs>">next<img src="images/fwd.png" border=0></a><TMPL_ELSE>next<img src="images/fwd.png" border=0></TMPL_IF>&nbsp;
    13 <TMPL_IF navlast><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=domlist&offset=<TMPL_VAR NAME=lastoffs>">last<img src="images/ffwd.png" border=0></a><TMPL_ELSE>last<img src="images/ffwd.png" border=0></TMPL_IF>&nbsp;
    14 <TMPL_IF navall><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=domlist&offset=all">all</a><TMPL_ELSE>all</TMPL_IF>
     10<TMPL_INCLUDE NAME="fpnla.tmpl">
    1511</td><td align=right>insert search box here</td></tr>
    1612
  • trunk/templates/menu.tmpl

    r13 r17  
    11<td class="menu">
    2 <div class="menu">
     2Current group: <TMPL_VAR NAME=grpname><br />
    33<a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=domlist">Domains</a><br />
    44<a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=useradmin">Users</a><br />
     
    77<a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=axfr">AXFR Import</a><br />
    88<hr>
     9<a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=grpman">Manage groups</a><br />
     10<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>
     12        </TMPL_LOOP>
     13</select>
     14<hr>
    915<a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=dnsq">DNS Query</a><br />
    1016<a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=whoisq">WHOIS Query</a><br />
    11 </div>
    1217</td>
  • trunk/templates/pgcount.tmpl

    r12 r17  
    1 Listing <TMPL_VAR NAME=nfirst> - <TMPL_VAR NAME=npglast> of <TMPL_VAR NAME=ntot> <TMPL_VAR NAME=pgtype> in <TMPL_VAR NAME=parent>
     1Listing <TMPL_VAR NAME=nfirst> - <TMPL_VAR NAME=npglast> of <TMPL_VAR NAME=ntot> <TMPL_VAR NAME=pgtype><TMPL_IF NAME=parent> in <TMPL_VAR NAME=parent></TMPL_IF>
  • trunk/templates/record.tmpl

    r16 r17  
    1111<input type="hidden" name="sid" value="<TMPL_VAR NAME=sid>">
    1212<input type="hidden" name="parentid" value="<TMPL_VAR NAME=parentid>">
     13<input type="hidden" name="id" value="<TMPL_VAR NAME=id>">
    1314<input type="hidden" name="recact" value="<TMPL_VAR NAME=recact>">
    1415        <table border=0 bgcolor="white">
Note: See TracChangeset for help on using the changeset viewer.