Changeset 13 for trunk


Ignore:
Timestamp:
09/11/09 17:59:51 (15 years ago)
Author:
Kris Deugau
Message:

/trunk

Checkpoint
Merging record add/edit pieces into one template/code block
Added debugging array @debugbits to push strings into rather than printing,

since we haven't spit out headers before the processing (this is so we can
redirect)

Added DNSDB::grpName
Removed obsolete defrecs.tmpl

Location:
trunk
Files:
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r10 r13  
    2323@ISA            = qw(Exporter);
    2424@EXPORT_OK      = qw(
    25         &initGlobals &connectDB &finish &addDomain &delDomain &domainName &getSOA &getRecLine &getDomRecs
    26         &addRec &delRec &domStatus
     25        &initGlobals &connectDB &finish &addDomain &delDomain &domainName &grpName &getSOA &getRecLine
     26        &getDomRecs &addRec &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 &getSOA &getRecLine &getDomRecs
    33                 &addRec &delRec &domStatus
     32                &initGlobals &connectDB &finish &addDomain &delDomain &domainName &grpName &getSOA &getRecLine
     33                &getDomRecs &addRec &delRec &domStatus
    3434                %typemap %reverse_typemap
    3535                )]
     
    254254
    255255
     256## DNSDB::grpName()
     257# Return the domain name based on a domain ID
     258# Takes a database handle and the domain ID
     259# Returns the domain name or undef on failure
     260sub grpName {
     261  $errstr = '';
     262  my $dbh = shift;
     263  my $grpid = shift;
     264  my $sth = $dbh->prepare("select name from groups where group_id=?");
     265  $sth->execute($grpid);
     266  my ($grpname) = $sth->fetchrow_array();
     267  $errstr = $DBI::errstr if !$grpname;
     268  return $grpname if $grpname;
     269} # end domainName
     270
     271
    256272## DNSDB::editRecord()
    257273# Change an existing record
  • trunk/dns.cgi

    r12 r13  
    2222use DNSDB qw(:ALL);
    2323
     24my @debugbits;  # temp, to be spit out near the end of processing
     25
    2426# Let's do these templates right...
    2527my $templatedir = "templates";
     
    3436my %webvar = $q->Vars;
    3537
     38# persistent stuff needed on most/all pages
    3639my $sid = ($webvar{sid} ? $webvar{sid} : undef);
    3740my $session = new CGI::Session("driver:File", $sid, {Directory => $sessiondir});
     
    4649}
    4750
     51my $group = ($webvar{grp} ? $webvar{grp} : 1);
    4852# handle login redirect
    4953if ($webvar{action} && $webvar{action} eq 'login') {
     
    170174  }
    171175
     176} elsif ($webvar{page} eq 'record') {
     177  if ($webvar{recact} eq 'new') {
     178    $page->param(recact => "Add record to");
     179    stdrecs();
     180  } elsif ($webvar{recact} eq 'edit') {
     181    $page->param(recact => "Edit record in");
     182    my $sth = $dbh->prepare("SELECT host,type,val,distance,weight,port,ttl FROM ".
     183        ($webvar{defrec} eq 'y' ? 'default_' : '')."records WHERE record_id=?");
     184    $sth->execute($webvar{id});
     185    my ($host,$type,$val,$distance,$weight,$port,$ttl) = $sth->fetchrow_array;
     186    $page->param(name           => $host);
     187    $page->param(address        => $val);
     188    $page->param(distance       => $distance);
     189    $page->param(weight         => $weight);
     190    $page->param(port           => $port);
     191    $page->param(ttl            => $ttl);
     192    stdrecs($type);
     193  }
     194  if ($webvar{defrec} eq 'y') {
     195    $page->param(domain => "group ".grpName($dbh,$webvar{parentid}));
     196  } else {
     197    $page->param(domain => domainName($dbh,$webvar{parentid}));
     198  }
     199
    172200} elsif ($webvar{page} eq 'newrec') {
    173   print "whee!\n";
     201  push @debugbits, "whee!\n";
    174202
    175203  # populate most fields as needed.  (eg, type list.)
    176   newrec();
     204  stdrecs();
    177205
    178206} elsif ($webvar{page} eq 'addrec') {
     
    186214    }
    187215  }
    188   push @recargs,
     216# wtf?
     217#  push @recargs,
    189218  my ($code,$msg) = addRec(@recargs);
    190219
     
    195224    $page->param(add_failed => 1);
    196225    $page->param(errmsg => $msg);
    197     newrec();   # populate the form... er, mostly.
     226    stdrecs($webvar{type});     # populate the form... er, mostly.
    198227    $page->param(name => $webvar{name});
    199228    $page->param(address => $webvar{address});
     
    291320print "Content-type: text/html\n\n", $header->output;
    292321
     322foreach (@debugbits) { print; }
     323
     324$page->param(grp => $group);
     325
    293326# spit it out
    294327print $page->output;
     
    387420    $rec->{type} = $typemap{$rec->{type}};
    388421    $rec->{row} = $row % 2;
    389     # Feh.
    390422    $rec->{defrec} = $webvar{defrec};
    391     # And **FEH!!**
    392423    $rec->{sid} = $webvar{sid};
     424    $rec->{id} = $id;
    393425    $row++;
    394426  }
     
    396428}
    397429
    398 sub newrec {
     430sub stdrecs {
     431  my $type = shift || $reverse_typemap{A};
     432
    399433  my $sth = $dbh->prepare("select val,name from rectypes where stdflag=1 order by listorder");
    400434  $sth->execute;
    401435
     436push @debugbits, "DEBUG: type $type\n";
    402437  my @typelist;
    403438  while (my ($rval,$rname) = $sth->fetchrow_array()) {
    404439    my %row = ( recval => $rval, recname => $rname );
    405     $row{tselect} = 1 if $rval == $webvar{type};
     440    $row{tselect} = 1 if $rval == $type;
    406441    push @typelist, \%row;
    407442  }
     
    474509
    475510##fixme - group
    476   $page->param(id => 1);
     511  $page->param(grp => 1);
    477512  my @domlist;
    478   my $sth = $dbh->prepare("select domain_id,domain,status,groups.name from domains".
     513  $sth = $dbh->prepare("select domain_id,domain,status,groups.name from domains".
    479514        " inner join groups on domains.group_id=groups.group_id".
    480515        " order by domain".($offset eq 'all' ? '' : " limit $perpage offset ".$offset*$perpage));
  • trunk/templates/menu.tmpl

    r4 r13  
    44<a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=useradmin">Users</a><br />
    55<a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=log">Log</a><br />
    6 <a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=reclist&id=<TMPL_VAR NAME=id>&defrec=y">Default Records</a><br />
     6<a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=reclist&id=<TMPL_VAR NAME=grp>&defrec=y">Default Records</a><br />
    77<a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=axfr">AXFR Import</a><br />
    88<hr>
  • trunk/templates/reclist.tmpl

    r12 r13  
    2727<tr class="darkrowheader">
    2828        <td colspan=2>Records</td>
    29         <td align=right><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=newrec&parentid=<TMPL_VAR NAME=id>&defrec=<TMPL_VAR NAME=defrec>">Add record</a>
     29        <td align=right><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=record&parentid=<TMPL_VAR NAME=id>&defrec=<TMPL_VAR NAME=defrec>&recact=new">Add record</a>
    3030        <a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=showlog&id=<TMPL_VAR NAME=id>&defrec=<TMPL_VAR NAME=defrec>">View log</a>
    3131        </td>
     
    4242<TMPL_LOOP NAME=reclist>
    4343<tr class="row<TMPL_VAR NAME=row>">
    44 <td width="20%" nowrap><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=editrec&id=<TMPL_VAR NAME=record_id>&defrec=<TMPL_VAR NAME=defrec>"><TMPL_VAR NAME=host></a></td>
     44<td width="20%" nowrap><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=record&parentid=<TMPL_VAR NAME=id>&defrec=<TMPL_VAR NAME=defrec>&recact=edit&id=<TMPL_VAR NAME=record_id>"><TMPL_VAR NAME=host></a></td>
    4545<td width="5%" nowrap><TMPL_VAR NAME=type></td>
    4646<td nowrap><TMPL_VAR NAME=val></td>
Note: See TracChangeset for help on using the changeset viewer.