Changeset 3 for trunk/dns.cgi


Ignore:
Timestamp:
08/18/09 18:04:14 (15 years ago)
Author:
Kris Deugau
Message:

/trunk

Checkpoint
Continued development to reach ~ VegaDNS equivalence

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dns.cgi

    r2 r3  
    77# Last update by $Author$
    88###
    9 # Copyright (C) 2008 - Kris Deugau <kdeugau@deepnet.cx>
     9# Copyright (C) 2008,2009 - Kris Deugau <kdeugau@deepnet.cx>
    1010
    1111use strict;
     
    6363
    6464# default
    65 my $perpage = 15;
     65#my $perpage = 15;
     66my $perpage = 3;
    6667my $offset = ($webvar{offset} ? $webvar{offset} : 0);
    6768
     
    8283# Default page is a login page
    8384my $page;       # to be initialized as an HTML::Template entity sooner or later
     85
     86
    8487
    8588# decide which page to spit out...
     
    9396
    9497if ($webvar{page} eq 'domlist' or $webvar{page} eq 'index') {
     98
     99# hmm.  seeing problems in some possibly-not-so-corner cases.
     100  if (defined($webvar{action})) {
     101    domStatus($dbh,$webvar{id},$webvar{action});
     102  }
     103
    95104  my $sth = $dbh->prepare("select count(*) from domains");
    96105  $sth->execute;
    97106  my ($count) = ($sth->fetchrow_array);
    98107
    99   if ($count > $perpage) {
    100     # if there are more results than the default, always show the "all" link
    101     $page->param(navall => 1);
    102 
    103     if ($offset > 0) {
    104       $page->param(navfirst => 1);
    105       $page->param(navprev => 1);
    106       $page->param(prevoffs => $offset-1);
     108##fixme
     109  if ($offset eq 'all') {
     110    print "foo!  wanna see'em all\n";
     111  } else {
     112    # all these bits only have sensible behaviour if offset is numeric. err, probably.
     113    if ($count > $perpage) {
     114      # if there are more results than the default, always show the "all" link
     115      $page->param(navall => 1);
     116
     117      if ($offset > 0) {
     118        $page->param(navfirst => 1);
     119        $page->param(navprev => 1);
     120        $page->param(prevoffs => $offset-1);
     121      }
     122
     123      # show "next" and "last" links if we're not on the last page of results
     124      if ( (($offset+1) * $perpage - $count) < 0 ) {
     125        $page->param(navnext => 1);
     126        $page->param(nextoffs => $offset+1);
     127        $page->param(navlast => 1);
     128        $page->param(lastoffs => int $count/$perpage);
     129      }
    107130    }
    108 
    109     # show "next" and "last" links if we're not on the last page of results
    110     if ( (($offset+1) * $perpage - $count) < 0 ) {
    111       $page->param(navnext => 1);
    112       $page->param(nextoffs => $offset+1);
    113       $page->param(navlast => 1);
    114       $page->param(lastoffs => int $count/$perpage);
    115     }
    116131  }
    117132
    118133  $page->param(ndomains => $count);
    119 
     134  $page->param(nstart => (($offset eq 'all' ? 0 : $offset)*$perpage+1));
     135  $page->param(npglast => ($offset eq 'all' ? $count :
     136        ( (($offset+1)*$perpage) > $count ? $count : (($offset+1)*$perpage) )
     137        ));
    120138  my @domlist;
    121139  $sth = $dbh->prepare("select domain_id,domain,status,groups.name from domains".
    122140        " inner join groups on domains.group_id=groups.group_id".
    123         " order by domain limit $perpage offset ".$offset*$perpage);
     141        " order by domain".($offset eq 'all' ? '' : " limit $perpage offset ".$offset*$perpage));
    124142  $sth->execute;
    125143  my $rownum = 0;
     
    128146    $row{domainid} = $data[0];
    129147    $row{domain} = $data[1];
    130     $row{status} = $data[2];
     148    $row{status} = ($data[2] ? 'Active' : 'Inactive');
    131149    $row{group} = $data[3];
    132150    $row{bg} = ($rownum++)%2;
    133     $row{mkactive} = ($data[2] eq 'inactive' ? 1 : 0);
     151#    $row{mkactive} = ($data[2] eq 'inactive' ? 1 : 0);
     152    $row{mkactive} = !$data[2];
    134153    $row{sid} = $sid;
     154    $row{offset} = $offset;
    135155##fixme:  need to clean up status indicator/usage/inversion
    136156    push @domlist, \%row;
     
    190210  print "whee!\n";
    191211
    192 newrec();
     212  # populate most fields as needed.  (eg, type list.)
     213  newrec();
    193214
    194215} elsif ($webvar{page} eq 'addrec') {
     
    221242  }
    222243
     244  $page->param(defrec => $webvar{defrec});
     245
    223246} elsif ($webvar{page} eq 'conf_del') {
    224247
     
    236259  if (!defined($webvar{del})) {
    237260    $page->param(del_getconf => 1);
    238   } else {
    239 #    $page->param(
    240   }
    241 ##work
     261    my %rec = getRecLine($dbh,$webvar{defrec},$webvar{id});
     262    $page->param(host => $rec{host});
     263    $page->param(ftype => $typemap{$rec{type}});
     264    $page->param(recval => $rec{val});
     265  } else {
     266    my ($code,$msg) = delRec($dbh,$webvar{defrec},$webvar{id});
     267    if ($code ne 'OK') {
     268## need to find failure mode
     269      $page->param(del_failed => 1);
     270      $page->param(errmsg => $msg);
     271    }
     272##fixme:  group/parent instead of hardcoded 1
     273    showdomain('y',1);
     274  }
    242275
    243276} elsif ($webvar{page} eq 'editsoa') {
     
    258291  $sth = $dbh->prepare($sql);
    259292  $sth->execute;
    260 print "DEBUG: $sql<br>\n";
    261 #print "DEBUG: ".$DBI::errstr;
    262293
    263294  if ($sth->err) {
     
    279310# hokay, a bit of magic to decide which page we hit.
    280311  if ($code eq 'OK') {
    281     $page = HTML::Template->new(filename => "$templatedir/domlist.tmpl");
     312    $page = HTML::Template->new(filename => "$templatedir/reclist.tmpl");
     313    showdomain(0,$msg);
     314##work
    282315  } else {
    283316# oooh, yeah, this is supposed to be a redirect.  er, maybe.  whee.
     
    288321  }
    289322
    290 #  my $sth = $dbh->prepare("insert into domains (domain,group_id,status) values (?,?,?)");
    291 #  $sth->execute($webvar{domain},1,($webvar{makeactive} ? 'active' : 'inactive')) or die $DBI::errstr;
    292 #  $sth = $dbh->prepare("select domain_id from domains where domain='$webvar{domain}'");
    293 #  $sth->execute;
    294 #  my ($dom_id) = $sth->fetchrow_array();
    295 #  $sth = $dbh->prepare("select host,type,val,distance,ttl from default_records where group_id=1");
    296 #  my $sth_in = $dbh->prepare("insert into records (domain_id,host,type,val,distance,ttl)".
    297 #       " values ($dom_id,?,?,?,?,?)");
    298 #  $sth->execute;
    299 #  while (my ($host,$type,$val,$dist,$ttl) = $sth->fetchrow_array()) {
    300 #    $host =~ s/DOMAIN/$webvar{domain}/g;
    301 #    $sth_in->execute($host,$type,$val,$dist,$ttl);
    302 #  }
    303 #  $dbh->commit or print "failed to add $webvar{domain}: ".$DBI::errstr."\n";
    304 
    305 #  $page->param(add_failed => 1);
     323
    306324}
    307325
     
    410428  $page->param(typelist => \@typelist);
    411429  $page->param(domain   => domainName($dbh,$webvar{domainid}));
    412   $page->param(parentid => $webvar{parentid});
    413430  $page->param(defrec   => $webvar{defrec});
    414431  $page->param(ttl      => ($webvar{ttl} ? $webvar{ttl} : $DNSDB::def{minttl}));
    415 }
     432  if ($webvar{defrec} eq 'y') {
     433    ##fixme - should be groupid
     434    $page->param(parentid => 1);
     435  } else {
     436    $page->param(parentid => $webvar{parentid});
     437  }
     438}
Note: See TracChangeset for help on using the changeset viewer.