Changeset 10 for trunk


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

/trunk

Move domain list generation into a sub; it's needed from several places
Confirm domain deletion works as expected; reenable actual deletion.
Misc comment-docs

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r7 r10  
    216216  local $dbh->{RaiseError} = 1;
    217217
    218 ##fixme
    219 return ('OK',"don't wanna!");
    220 
    221218  # Wrap all the SQL in a transaction
    222219  eval {
  • trunk/dns.cgi

    r8 r10  
    9393
    9494# hmm.  seeing problems in some possibly-not-so-corner cases.
     95# this currently only handles "domain on", "domain off"
    9596  if (defined($webvar{action})) {
    9697    domStatus($dbh,$webvar{id},$webvar{action});
    9798  }
    9899
     100  domlist();
     101
     102} elsif ($webvar{page} eq 'reclist') {
     103
     104  # Handle record list for both default records (per-group) and live domain records
     105
     106  $page->param(defrec => $webvar{defrec});
     107  $page->param(id => $webvar{id});
     108  $page->param(curpage => 'reclist');
     109
     110# select count(*) from (default_)?records where (group|domain)_id=?
     111    my $sth = $dbh->prepare("SELECT count(*) FROM ".
     112        ($webvar{defrec} eq 'y' ? 'default_' : '')."records ".
     113        "WHERE ".($webvar{defrec} eq 'y' ? 'group' : 'domain')."_id=? ".
     114        "AND NOT type=$reverse_typemap{SOA}");
     115    $sth->execute($webvar{id});
     116    my ($count) = ($sth->fetchrow_array);
     117
     118  $page->param(ntot => $count);
     119  $page->param(nfirst => 1);
     120  $page->param(nlast => 10);
     121
     122  fill_fpnla($count);  # should put some params on this sub...
     123
     124##fixme
     125  $page->param(domain => domainName($dbh,$webvar{id}));
     126  $page->param(id => $webvar{id});
     127##fixme
     128
     129  $page->param(defrec => $webvar{defrec});
     130  if ($webvar{defrec} eq 'y') {
     131    showdomain('y',1);
     132  } else {
     133    showdomain('n',$webvar{id});
     134  }
     135
     136} elsif ($webvar{page} eq 'newdomain') {
     137
     138  # weesa gonna discard parent_group_id for now
     139  my $sth = $dbh->prepare("select group_id,parent_group_id,name from groups order by group_id");
     140  $sth->execute;
     141  my @grplist;
     142  while (my ($grpid,$pargrp,$grpname) = $sth->fetchrow_array()) {
     143    my %row;
     144    $row{grpname} = $grpname;
     145    $row{grpval} = $grpid;
     146##fixme: need magic
     147#    $row{defgrp} = '';
     148    push @grplist, \%row;
     149  }
     150
     151  $page->param(grplist => \@grplist);
     152
     153} elsif ($webvar{page} eq 'newrec') {
     154  print "whee!\n";
     155
     156  # populate most fields as needed.  (eg, type list.)
     157  newrec();
     158
     159} elsif ($webvar{page} eq 'addrec') {
     160
     161  my @recargs = ($dbh,$webvar{defrec},$webvar{parentid},$webvar{name},$webvar{type},$webvar{address},$webvar{ttl});
     162  if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV}) {
     163    push @recargs, $webvar{distance};
     164    if ($webvar{type} == $reverse_typemap{SRV}) {
     165      push @recargs, $webvar{weight};
     166      push @recargs, $webvar{port};
     167    }
     168  }
     169  push @recargs,
     170  my ($code,$msg) = addRec(@recargs);
     171
     172  if ($code eq 'OK') {
     173    showdomain($webvar{defrec},$webvar{parentid});
     174# NB: should **really** redirect here, in case of reload.  >_<  eyowch.
     175  } else {
     176    $page->param(add_failed => 1);
     177    $page->param(errmsg => $msg);
     178    newrec();   # populate the form... er, mostly.
     179    $page->param(name => $webvar{name});
     180    $page->param(address => $webvar{address});
     181    $page->param(distance => $webvar{distance})
     182        if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV});
     183    $page->param(weight => $webvar{weight}) if $webvar{type} == $reverse_typemap{SRV};
     184    $page->param(port => $webvar{port}) if $webvar{type} == $reverse_typemap{SRV};
     185  }
     186
     187  $page->param(defrec => $webvar{defrec});
     188
     189} elsif ($webvar{page} eq 'conf_del') {
     190
     191  $page->param(id => $webvar{id});
     192  $page->param(defrec => $webvar{defrec});
     193
     194  my @tmp = getrecdata($dbh,$webvar{id},$webvar{defrec});
     195
     196} elsif ($webvar{page} eq 'delrec') {
     197
     198  $page->param(id => $webvar{id});
     199  $page->param(defrec => $webvar{defrec});
     200  # first pass = confirm y/n (sorta)
     201  if (!defined($webvar{del})) {
     202    $page->param(del_getconf => 1);
     203    my %rec = getRecLine($dbh,$webvar{defrec},$webvar{id});
     204    $page->param(host => $rec{host});
     205    $page->param(ftype => $typemap{$rec{type}});
     206    $page->param(recval => $rec{val});
     207  } else {
     208    my ($code,$msg) = delRec($dbh,$webvar{defrec},$webvar{id});
     209    if ($code ne 'OK') {
     210## need to find failure mode
     211      $page->param(del_failed => 1);
     212      $page->param(errmsg => $msg);
     213    }
     214##fixme:  group/parent instead of hardcoded 1
     215    showdomain('y',1);
     216  }
     217
     218} elsif ($webvar{page} eq 'deldom') {
     219
     220  $page->param(id => $webvar{id});
     221  # first pass = confirm y/n (sorta)
     222  if (!defined($webvar{del})) {
     223    $page->param(del_getconf => 1);
     224    $page->param(domain => domainName($dbh,$webvar{id}));
     225# print some neato things?
     226
     227#  } else {
     228#    #whether actually deleting or cancelling we redirect to the domain list, default format
     229
     230  } elsif ($webvar{del} eq 'ok') {
     231    my ($code,$msg) = delDomain($dbh, $webvar{id});
     232    if ($code ne 'OK') {
     233# need to find failure mode
     234      $page->param(del_failed => 1);
     235      $page->param(errmsg => $msg);
     236    } else {
     237##work
     238      domlist();
     239    }
     240  } else {
     241    # cancelled.  whee!
     242    $page->param(del_failed => 0);
     243    domlist();
     244  }
     245
     246} elsif ($webvar{page} eq 'editsoa') {
     247
     248  fillsoa($webvar{defrec},$webvar{recid});
     249
     250} elsif ($webvar{page} eq 'updatesoa') {
     251  print "ooooo!\n";
     252
     253  my $sth;
     254  my $sql = '';
     255  # no domain ID, so we're editing the default SOA for a group (we don't care which one here)
     256  # plus a bit of magic to update the appropriate table
     257  $sql = "update ".($webvar{domainid} eq '' ? "default_records" : "records").
     258        " set host='$webvar{prins}:$webvar{contact}',".
     259        " val='$webvar{refresh}:$webvar{retry}:$webvar{expire}:$webvar{minttl}',".
     260        " ttl=$webvar{ttl} where record_id=$webvar{recid}";
     261  $sth = $dbh->prepare($sql);
     262  $sth->execute;
     263
     264  if ($sth->err) {
     265    $page->param(update_failed => 1);
     266    $page->param(msg => $DBI::errstr);
     267    fillsoa($webvar{defrec},1);
     268  } else {
     269    $page->param(update_failed => 0);
     270##fixme!  need to set group ID properly here
     271    showdomain('y',1);
     272  }
     273
     274} elsif ($webvar{page} eq 'adddomain') {
     275  # Need some magic here.
     276
     277##fixme:  Group should be variable
     278  my ($code,$msg) = addDomain($dbh,$webvar{domain},1,($webvar{makeactive} eq 'on' ? 1 : 0));
     279
     280# hokay, a bit of magic to decide which page we hit.
     281  if ($code eq 'OK') {
     282    $page = HTML::Template->new(filename => "$templatedir/reclist.tmpl");
     283    showdomain(0,$msg);
     284##work
     285  } else {
     286# oooh, yeah, this is supposed to be a redirect.  er, maybe.  whee.
     287    $page = HTML::Template->new(filename => "$templatedir/newdomain.tmpl");
     288    $page->param(add_failed => 1);
     289    $page->param(domain => $webvar{domain});
     290    $page->param(errmsg => $msg);
     291  }
     292
     293
     294}
     295
     296
     297## hmm.  may want to move this so we can redirect after adding/deleting/etc
     298print "Content-type: text/html\n\n", $header->output;
     299
     300# spit it out
     301print $page->output;
     302
     303print "<div id=debug>webvar keys: <pre>\n";
     304foreach my $key (keys %webvar) {
     305  print "key: $key\tval: $webvar{$key}\n";
     306}
     307print "</pre>\nENV:\n<pre>\n";
     308foreach my $key (keys %ENV) {
     309  print "key: $key\tval: $ENV{$key}\n";
     310}
     311print "</pre></div>\n";
     312
     313print $footer->output;
     314
     315
     316exit 0;
     317
     318
     319sub fillsoa {
     320  my $def = shift;
     321  my $id = shift;
     322  my $domname;
     323
     324  if ($webvar{domain} == 0) {
     325    $domname = "DOMAIN";
     326  } else {
     327    my $sth = $dbh->prepare("select domain from domains where domain_id=$webvar{domain}");
     328    $sth->execute();
     329    ($domname) = $sth->fetchrow_array();
     330  }
     331
     332  $page->param(domain => $domname);
     333  $page->param(defrec => !$webvar{domain});
     334  $page->param(group => $DNSDB::group);
     335
     336# defaults
     337  $page->param(defcontact => $DNSDB::def{contact});
     338  $page->param(defns => $DNSDB::def{prins});
     339  $page->param(defsoattl => $DNSDB::def{soattl});
     340  $page->param(defrefresh => $DNSDB::def{refresh});
     341  $page->param(defretry => $DNSDB::def{retry});
     342  $page->param(defexpire => $DNSDB::def{expire});
     343  $page->param(defminttl => $DNSDB::def{minttl});
     344
     345  # there are probably better ways to do this.  TMTOWTDI.
     346  my %soa = getSOA($dbh,$def,$id);
     347
     348  $page->param(domainid => $webvar{domain});
     349  $page->param(recid    => $soa{recid});
     350  $page->param(prins    => ($soa{prins} ? $soa{prins} : $DNSDB::def{prins}));
     351  $page->param(contact  => ($soa{contact} ? $soa{contact} : $DNSDB::def{contact}));
     352  $page->param(refresh  => ($soa{refresh} ? $soa{refresh} : $DNSDB::def{refresh}));
     353  $page->param(retry    => ($soa{retry} ? $soa{retry} : $DNSDB::def{retry}));
     354  $page->param(expire   => ($soa{expire} ? $soa{expire} : $DNSDB::def{expire}));
     355  $page->param(minttl   => ($soa{minttl} ? $soa{minttl} : $DNSDB::def{minttl}));
     356  $page->param(ttl      => ($soa{ttl} ? $soa{ttl} : $DNSDB::def{soattl}));
     357}
     358
     359sub showdomain {
     360  my $def = shift;
     361  my $id = shift;
     362
     363  # get the SOA first
     364  my %soa = getSOA($dbh,$def,$id);
     365
     366  $page->param(recid    => $soa{recid});
     367  $page->param(contact  => $soa{contact});
     368  $page->param(prins    => $soa{prins});
     369  $page->param(refresh  => $soa{refresh});
     370  $page->param(retry    => $soa{retry});
     371  $page->param(expire   => $soa{expire});
     372  $page->param(minttl   => $soa{minttl});
     373  $page->param(ttl      => $soa{ttl});
     374
     375#  my @foo2 = getDomRecs($dbh,'def',1);
     376  my $foo2 = getDomRecs($dbh,$def,$id,$perpage,$webvar{offset});
     377
     378  my $row = 0;
     379  foreach my $rec (@$foo2) {
     380    $rec->{type} = $typemap{$rec->{type}};
     381    $rec->{row} = $row % 2;
     382    # Feh.
     383    $rec->{defrec} = $webvar{defrec};
     384    # And **FEH!!**
     385    $rec->{sid} = $webvar{sid};
     386    $row++;
     387  }
     388  $page->param(reclist => $foo2);
     389}
     390
     391sub newrec {
     392  my $sth = $dbh->prepare("select val,name from rectypes where stdflag=1 order by listorder");
     393  $sth->execute;
     394
     395  my @typelist;
     396  while (my ($rval,$rname) = $sth->fetchrow_array()) {
     397    my %row = ( recval => $rval, recname => $rname );
     398    $row{tselect} = 1 if $rval == $webvar{type};
     399    push @typelist, \%row;
     400  }
     401  $page->param(typelist => \@typelist);
     402  $page->param(domain   => domainName($dbh,$webvar{domainid}));
     403  $page->param(defrec   => $webvar{defrec});
     404  $page->param(ttl      => ($webvar{ttl} ? $webvar{ttl} : $DNSDB::def{minttl}));
     405  if ($webvar{defrec} eq 'y') {
     406    ##fixme - should be groupid
     407    $page->param(parentid => 1);
     408  } else {
     409print "DEBUG: foobar:  parentid $webvar{parentid}<br>\n";
     410    $page->param(parentid => $webvar{parentid});
     411  }
     412}
     413
     414sub fill_fpnla {
     415  my $count = shift;
     416##fixme
     417  if ($offset eq 'all') {
     418    #print "foo!  wanna see'em all\n";
     419  } else {
     420    # all these bits only have sensible behaviour if offset is numeric. err, probably.
     421    if ($count > $perpage) {
     422      # if there are more results than the default, always show the "all" link
     423      $page->param(navall => 1);
     424
     425      if ($offset > 0) {
     426        $page->param(navfirst => 1);
     427        $page->param(navprev => 1);
     428        $page->param(prevoffs => $offset-1);
     429      }
     430
     431      # show "next" and "last" links if we're not on the last page of results
     432      if ( (($offset+1) * $perpage - $count) < 0 ) {
     433        $page->param(navnext => 1);
     434        $page->param(nextoffs => $offset+1);
     435        $page->param(navlast => 1);
     436        $page->param(lastoffs => int (($count-1)/$perpage));
     437      }
     438    }
     439  }
     440} # end fill_fpnla()
     441
     442
     443sub domlist {
    99444  my $sth = $dbh->prepare("select count(*) from domains");
    100445  $sth->execute;
     
    108453        ( (($offset+1)*$perpage) > $count ? $count : (($offset+1)*$perpage) )
    109454        ));
     455
    110456##fixme - group
    111457  $page->param(id => 1);
    112458  my @domlist;
    113   $sth = $dbh->prepare("select domain_id,domain,status,groups.name from domains".
     459  my $sth = $dbh->prepare("select domain_id,domain,status,groups.name from domains".
    114460        " inner join groups on domains.group_id=groups.group_id".
    115461        " order by domain".($offset eq 'all' ? '' : " limit $perpage offset ".$offset*$perpage));
     
    131477  }
    132478  $page->param(domtable => \@domlist);
    133 
    134 } elsif ($webvar{page} eq 'reclist') {
    135 
    136   # Handle record list for both default records (per-group) and live domain records
    137 
    138   $page->param(defrec => $webvar{defrec});
    139   $page->param(id => $webvar{id});
    140   $page->param(curpage => 'reclist');
    141 
    142 # select count(*) from (default_)?records where (group|domain)_id=?
    143     my $sth = $dbh->prepare("SELECT count(*) FROM ".
    144         ($webvar{defrec} eq 'y' ? 'default_' : '')."records ".
    145         "WHERE ".($webvar{defrec} eq 'y' ? 'group' : 'domain')."_id=? ".
    146         "AND NOT type=$reverse_typemap{SOA}");
    147     $sth->execute($webvar{id});
    148     my ($count) = ($sth->fetchrow_array);
    149 
    150   $page->param(ntot => $count);
    151   $page->param(nfirst => 1);
    152   $page->param(nlast => 10);
    153 
    154   fill_fpnla($count);  # should put some params on this sub...
    155 
    156 ##fixme
    157   $page->param(domain => domainName($dbh,$webvar{id}));
    158   $page->param(id => $webvar{id});
    159 ##fixme
    160 
    161   $page->param(defrec => $webvar{defrec});
    162   if ($webvar{defrec} eq 'y') {
    163     showdomain('y',1);
    164   } else {
    165     showdomain('n',$webvar{id});
    166   }
    167 
    168 } elsif ($webvar{page} eq 'newdomain') {
    169 
    170   # weesa gonna discard parent_group_id for now
    171   my $sth = $dbh->prepare("select group_id,parent_group_id,name from groups order by group_id");
    172   $sth->execute;
    173   my @grplist;
    174   while (my ($grpid,$pargrp,$grpname) = $sth->fetchrow_array()) {
    175     my %row;
    176     $row{grpname} = $grpname;
    177     $row{grpval} = $grpid;
    178 ##fixme: need magic
    179 #    $row{defgrp} = '';
    180     push @grplist, \%row;
    181   }
    182 
    183   $page->param(grplist => \@grplist);
    184 
    185 } elsif ($webvar{page} eq 'newrec') {
    186   print "whee!\n";
    187 
    188   # populate most fields as needed.  (eg, type list.)
    189   newrec();
    190 
    191 } elsif ($webvar{page} eq 'addrec') {
    192 
    193   my @recargs = ($dbh,$webvar{defrec},$webvar{parentid},$webvar{name},$webvar{type},$webvar{address},$webvar{ttl});
    194   if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV}) {
    195     push @recargs, $webvar{distance};
    196     if ($webvar{type} == $reverse_typemap{SRV}) {
    197       push @recargs, $webvar{weight};
    198       push @recargs, $webvar{port};
    199     }
    200   }
    201   push @recargs,
    202   my ($code,$msg) = addRec(@recargs);
    203 
    204   if ($code eq 'OK') {
    205     showdomain($webvar{defrec},$webvar{parentid});
    206 # NB: should **really** redirect here, in case of reload.  >_<  eyowch.
    207   } else {
    208     $page->param(add_failed => 1);
    209     $page->param(errmsg => $msg);
    210     newrec();   # populate the form... er, mostly.
    211     $page->param(name => $webvar{name});
    212     $page->param(address => $webvar{address});
    213     $page->param(distance => $webvar{distance})
    214         if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV});
    215     $page->param(weight => $webvar{weight}) if $webvar{type} == $reverse_typemap{SRV};
    216     $page->param(port => $webvar{port}) if $webvar{type} == $reverse_typemap{SRV};
    217   }
    218 
    219   $page->param(defrec => $webvar{defrec});
    220 
    221 } elsif ($webvar{page} eq 'conf_del') {
    222 
    223   $page->param(id => $webvar{id});
    224   $page->param(defrec => $webvar{defrec});
    225 
    226   my @tmp = getrecdata($dbh,$webvar{id},$webvar{defrec});
    227 
    228 } elsif ($webvar{page} eq 'delrec') {
    229 
    230   $page->param(id => $webvar{id});
    231   $page->param(defrec => $webvar{defrec});
    232   # first pass = confirm y/n (sorta)
    233   if (!defined($webvar{del})) {
    234     $page->param(del_getconf => 1);
    235     my %rec = getRecLine($dbh,$webvar{defrec},$webvar{id});
    236     $page->param(host => $rec{host});
    237     $page->param(ftype => $typemap{$rec{type}});
    238     $page->param(recval => $rec{val});
    239   } else {
    240     my ($code,$msg) = delRec($dbh,$webvar{defrec},$webvar{id});
    241     if ($code ne 'OK') {
    242 ## need to find failure mode
    243       $page->param(del_failed => 1);
    244       $page->param(errmsg => $msg);
    245     }
    246 ##fixme:  group/parent instead of hardcoded 1
    247     showdomain('y',1);
    248   }
    249 
    250 } elsif ($webvar{page} eq 'deldom') {
    251 
    252   $page->param(id => $webvar{id});
    253   # first pass = confirm y/n (sorta)
    254   if (!defined($webvar{del})) {
    255     $page->param(del_getconf => 1);
    256     $page->param(domain => domainName($dbh,$webvar{id}));
    257 # print some neato things?
    258 
    259 #  } else {
    260 #    #whether actually deleting or cancelling we redirect to the domain list, default format
    261 
    262   } elsif ($webvar{del} eq 'ok') {
    263     my ($code,$msg) = delDomain($dbh, $webvar{id});
    264     if ($code ne 'OK') {
    265 # need to find failure mode
    266       $page->param(del_failed => 1);
    267       $page->param(errmsg => $msg);
    268     }
    269   } else {
    270     # cancelled.  whee!
    271     $page->param(del_failed => 0);
    272 # more params?
    273   }
    274 
    275 } elsif ($webvar{page} eq 'editsoa') {
    276 
    277   fillsoa($webvar{defrec},$webvar{recid});
    278 
    279 } elsif ($webvar{page} eq 'updatesoa') {
    280   print "ooooo!\n";
    281 
    282   my $sth;
    283   my $sql = '';
    284   # no domain ID, so we're editing the default SOA for a group (we don't care which one here)
    285   # plus a bit of magic to update the appropriate table
    286   $sql = "update ".($webvar{domainid} eq '' ? "default_records" : "records").
    287         " set host='$webvar{prins}:$webvar{contact}',".
    288         " val='$webvar{refresh}:$webvar{retry}:$webvar{expire}:$webvar{minttl}',".
    289         " ttl=$webvar{ttl} where record_id=$webvar{recid}";
    290   $sth = $dbh->prepare($sql);
    291   $sth->execute;
    292 
    293   if ($sth->err) {
    294     $page->param(update_failed => 1);
    295     $page->param(msg => $DBI::errstr);
    296     fillsoa($webvar{defrec},1);
    297   } else {
    298     $page->param(update_failed => 0);
    299 ##fixme!  need to set group ID properly here
    300     showdomain('y',1);
    301   }
    302 
    303 } elsif ($webvar{page} eq 'adddomain') {
    304   # Need some magic here.
    305 
    306 ##fixme:  Group should be variable
    307   my ($code,$msg) = addDomain($dbh,$webvar{domain},1,($webvar{makeactive} eq 'on' ? 1 : 0));
    308 
    309 # hokay, a bit of magic to decide which page we hit.
    310   if ($code eq 'OK') {
    311     $page = HTML::Template->new(filename => "$templatedir/reclist.tmpl");
    312     showdomain(0,$msg);
    313 ##work
    314   } else {
    315 # oooh, yeah, this is supposed to be a redirect.  er, maybe.  whee.
    316     $page = HTML::Template->new(filename => "$templatedir/newdomain.tmpl");
    317     $page->param(add_failed => 1);
    318     $page->param(domain => $webvar{domain});
    319     $page->param(errmsg => $msg);
    320   }
    321 
    322 
    323 }
    324 
    325 
    326 ## hmm.  may want to move this so we can redirect after adding/deleting/etc
    327 print "Content-type: text/html\n\n", $header->output;
    328 
    329 # spit it out
    330 print $page->output;
    331 
    332 print "<div id=debug>webvar keys: <pre>\n";
    333 foreach my $key (keys %webvar) {
    334   print "key: $key\tval: $webvar{$key}\n";
    335 }
    336 print "</pre>\nENV:\n<pre>\n";
    337 foreach my $key (keys %ENV) {
    338   print "key: $key\tval: $ENV{$key}\n";
    339 }
    340 print "</pre></div>\n";
    341 
    342 print $footer->output;
    343 
    344 
    345 exit 0;
    346 
    347 
    348 sub fillsoa {
    349   my $def = shift;
    350   my $id = shift;
    351   my $domname;
    352 
    353   if ($webvar{domain} == 0) {
    354     $domname = "DOMAIN";
    355   } else {
    356     my $sth = $dbh->prepare("select domain from domains where domain_id=$webvar{domain}");
    357     $sth->execute();
    358     ($domname) = $sth->fetchrow_array();
    359   }
    360 
    361   $page->param(domain => $domname);
    362   $page->param(defrec => !$webvar{domain});
    363   $page->param(group => $DNSDB::group);
    364 
    365 # defaults
    366   $page->param(defcontact => $DNSDB::def{contact});
    367   $page->param(defns => $DNSDB::def{prins});
    368   $page->param(defsoattl => $DNSDB::def{soattl});
    369   $page->param(defrefresh => $DNSDB::def{refresh});
    370   $page->param(defretry => $DNSDB::def{retry});
    371   $page->param(defexpire => $DNSDB::def{expire});
    372   $page->param(defminttl => $DNSDB::def{minttl});
    373 
    374   # there are probably better ways to do this.  TMTOWTDI.
    375   my %soa = getSOA($dbh,$def,$id);
    376 
    377   $page->param(domainid => $webvar{domain});
    378   $page->param(recid    => $soa{recid});
    379   $page->param(prins    => ($soa{prins} ? $soa{prins} : $DNSDB::def{prins}));
    380   $page->param(contact  => ($soa{contact} ? $soa{contact} : $DNSDB::def{contact}));
    381   $page->param(refresh  => ($soa{refresh} ? $soa{refresh} : $DNSDB::def{refresh}));
    382   $page->param(retry    => ($soa{retry} ? $soa{retry} : $DNSDB::def{retry}));
    383   $page->param(expire   => ($soa{expire} ? $soa{expire} : $DNSDB::def{expire}));
    384   $page->param(minttl   => ($soa{minttl} ? $soa{minttl} : $DNSDB::def{minttl}));
    385   $page->param(ttl      => ($soa{ttl} ? $soa{ttl} : $DNSDB::def{soattl}));
    386 }
    387 
    388 sub showdomain {
    389   my $def = shift;
    390   my $id = shift;
    391 
    392   # get the SOA first
    393   my %soa = getSOA($dbh,$def,$id);
    394 
    395   $page->param(recid    => $soa{recid});
    396   $page->param(contact  => $soa{contact});
    397   $page->param(prins    => $soa{prins});
    398   $page->param(refresh  => $soa{refresh});
    399   $page->param(retry    => $soa{retry});
    400   $page->param(expire   => $soa{expire});
    401   $page->param(minttl   => $soa{minttl});
    402   $page->param(ttl      => $soa{ttl});
    403 
    404 #  my @foo2 = getDomRecs($dbh,'def',1);
    405   my $foo2 = getDomRecs($dbh,$def,$id,$perpage,$webvar{offset});
    406 
    407   my $row = 0;
    408   foreach my $rec (@$foo2) {
    409     $rec->{type} = $typemap{$rec->{type}};
    410     $rec->{row} = $row % 2;
    411     # Feh.
    412     $rec->{defrec} = $webvar{defrec};
    413     # And **FEH!!**
    414     $rec->{sid} = $webvar{sid};
    415     $row++;
    416   }
    417   $page->param(reclist => $foo2);
    418 }
    419 
    420 sub newrec {
    421   my $sth = $dbh->prepare("select val,name from rectypes where stdflag=1 order by listorder");
    422   $sth->execute;
    423 
    424   my @typelist;
    425   while (my ($rval,$rname) = $sth->fetchrow_array()) {
    426     my %row = ( recval => $rval, recname => $rname );
    427     $row{tselect} = 1 if $rval == $webvar{type};
    428     push @typelist, \%row;
    429   }
    430   $page->param(typelist => \@typelist);
    431   $page->param(domain   => domainName($dbh,$webvar{domainid}));
    432   $page->param(defrec   => $webvar{defrec});
    433   $page->param(ttl      => ($webvar{ttl} ? $webvar{ttl} : $DNSDB::def{minttl}));
    434   if ($webvar{defrec} eq 'y') {
    435     ##fixme - should be groupid
    436     $page->param(parentid => 1);
    437   } else {
    438 print "DEBUG: foobar:  parentid $webvar{parentid}<br>\n";
    439     $page->param(parentid => $webvar{parentid});
    440   }
    441 }
    442 
    443 sub fill_fpnla {
    444   my $count = shift;
    445 ##fixme
    446   if ($offset eq 'all') {
    447     #print "foo!  wanna see'em all\n";
    448   } else {
    449     # all these bits only have sensible behaviour if offset is numeric. err, probably.
    450     if ($count > $perpage) {
    451       # if there are more results than the default, always show the "all" link
    452       $page->param(navall => 1);
    453 
    454       if ($offset > 0) {
    455         $page->param(navfirst => 1);
    456         $page->param(navprev => 1);
    457         $page->param(prevoffs => $offset-1);
    458       }
    459 
    460       # show "next" and "last" links if we're not on the last page of results
    461       if ( (($offset+1) * $perpage - $count) < 0 ) {
    462         $page->param(navnext => 1);
    463         $page->param(nextoffs => $offset+1);
    464         $page->param(navlast => 1);
    465         $page->param(lastoffs => int (($count-1)/$perpage));
    466       }
    467     }
    468   }
    469 }
     479} # end domlist()
Note: See TracChangeset for help on using the changeset viewer.