Changeset 16


Ignore:
Timestamp:
09/15/09 17:52:13 (15 years ago)
Author:
Kris Deugau
Message:

/trunk

checkpoint

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r15 r16  
    2424@EXPORT_OK      = qw(
    2525        &initGlobals &connectDB &finish &addDomain &delDomain &domainName &grpName &getSOA &getRecLine
    26         &getDomRecs &addRec &delRec &domStatus
     26        &getDomRecs &addRec &updateRec &delRec &domStatus
    2727        %typemap %reverse_typemap
    2828        );
     
    3131%EXPORT_TAGS    = ( ALL => [qw(
    3232                &initGlobals &connectDB &finish &addDomain &delDomain &domainName &grpName &getSOA &getRecLine
    33                 &getDomRecs &addRec &delRec &domStatus
     33                &getDomRecs &addRec &updateRec &delRec &domStatus
    3434                %typemap %reverse_typemap
    3535                )]
     
    453453
    454454
     455## DNSDB::updateRec()
     456# Update a record
     457sub updateRec {
     458  $errstr = '';
     459  my $dbh = shift;
     460  my $defrec = shift;
     461  my $id = shift;
     462
     463# all records have these
     464  my $host = shift;
     465  my $type = shift;
     466  my $val = shift;
     467  my $ttl = shift;
     468
     469  return('FAIL',"Missing standard argument(s)") if !defined($ttl);
     470
     471# only MX and SRV will use these
     472  my $dist = 0;
     473  my $weight = 0;
     474  my $port = 0;
     475
     476  if ($type == $reverse_typemap{MX} || $type == $reverse_typemap{SRV}) {
     477    $dist = shift
     478        or return ('FAIL',"MX or SRV requires distance");
     479    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");
     484    }
     485  }
     486
     487  my $sth = $dbh->prepare("UPDATE ".($defrec eq 'y' ? 'default_' : '')."records ".
     488        "SET host=?,type=?,val=?,ttl=?,distance=?,weight=?,port=? ".
     489        "WHERE record_id=?");
     490  $sth->execute($host,$type,$val,$ttl,$dist,$weight,$port,$id);
     491
     492  return ('FAIL',$sth->errstr) if $sth->err;
     493
     494  return ('OK','OK');
     495} # end updateRec()
     496
     497
    455498## DNSDB::delRec()
    456499# Delete a record. 
  • trunk/dns.cgi

    r15 r16  
    177177
    178178} elsif ($webvar{page} eq 'record') {
     179
    179180  if ($webvar{recact} eq 'new') {
     181
    180182    $page->param(todo => "Add record to");
    181183    $page->param(recact => "add");
    182     stdrecs();
     184    fill_rectypes();
     185
    183186  } elsif ($webvar{recact} eq 'add') {
    184187
     
    191194      }
    192195    }
    193   # wtf?
    194   #  push @recargs,
    195196    my ($code,$msg) = addRec(@recargs);
    196197
    197198    if ($code eq 'OK') {
    198199      changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec});
    199 #      showdomain($webvar{defrec},$webvar{parentid});
    200   # NB: should **really** redirect here, in case of reload.  >_<  eyowch.
    201200    } else {
    202       $page->param(add_failed => 1);
     201      $page->param(failed => 1);
    203202      $page->param(errmsg => $msg);
    204       stdrecs($webvar{type});   # populate the form... er, mostly.
    205       $page->param(name => $webvar{name});
    206       $page->param(address => $webvar{address});
    207       $page->param(distance => $webvar{distance})
    208         if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV});
    209       $page->param(weight => $webvar{weight}) if $webvar{type} == $reverse_typemap{SRV};
    210       $page->param(port => $webvar{port}) if $webvar{type} == $reverse_typemap{SRV};
    211     }
    212 
    213     $page->param(defrec => $webvar{defrec});
     203      fill_recdata();   # populate the form... er, mostly.
     204    }
    214205
    215206  } elsif ($webvar{recact} eq 'edit') {
    216207
    217     $page->param(todo => "Edit record in");
     208    $page->param(todo           => "Update record");
     209    $page->param(recact         => "update");
     210    $page->param(parentid       => $webvar{parentid});
     211    $page->param(defrec         => $webvar{defrec});
    218212    my $sth = $dbh->prepare("SELECT host,type,val,distance,weight,port,ttl FROM ".
    219213        ($webvar{defrec} eq 'y' ? 'default_' : '')."records WHERE record_id=?");
     
    226220    $page->param(port           => $port);
    227221    $page->param(ttl            => $ttl);
    228     stdrecs($type);
    229   }
     222    fill_rectypes($type);
     223
     224  } elsif ($webvar{recact} eq 'update') {
     225
     226    my ($code,$msg) = updateRec($dbh,$webvar{defrec},$webvar{id},
     227        $webvar{name},$webvar{type},$webvar{address},$webvar{ttl},
     228        $webvar{distance},$webvar{weight},$webvar{port});
     229
     230    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});
     240    } else {
     241      $page->param(failed       => 1);
     242      $page->param(errmsg       => $msg);
     243      $page->param(wastrying    => "updating");
     244      $page->param(todo         => "Update record");
     245      $page->param(recact       => "update");
     246      $page->param(parentid     => $webvar{parentid});
     247      $page->param(defrec       => $webvar{defrec});
     248      fill_recdata();
     249    }
     250  }
     251
    230252  if ($webvar{defrec} eq 'y') {
    231     $page->param(domain => "group ".grpName($dbh,$webvar{parentid}));
    232   } else {
    233     $page->param(domain => domainName($dbh,$webvar{parentid}));
     253    $page->param(dohere => "group ".grpName($dbh,$webvar{parentid}));
     254  } else {
     255    $page->param(dohere => domainName($dbh,$webvar{parentid}));
    234256  }
    235257
     
    464486}
    465487
    466 sub stdrecs {
     488# fill in record type list on add/update/edit record template
     489sub fill_rectypes {
    467490  my $type = shift || $reverse_typemap{A};
    468491
    469492  my $sth = $dbh->prepare("select val,name from rectypes where stdflag=1 order by listorder");
    470493  $sth->execute;
    471 
    472 push @debugbits, "DEBUG: type $type\n";
     494push @debugbits, "type $type";
    473495  my @typelist;
    474496  while (my ($rval,$rname) = $sth->fetchrow_array()) {
     
    478500  }
    479501  $page->param(typelist => \@typelist);
    480   $page->param(domain   => domainName($dbh,$webvar{domainid}));
    481   $page->param(defrec   => $webvar{defrec});
     502}
     503
     504sub fill_recdata {
     505  fill_rectypes($webvar{type});
     506
     507  $page->param(name     => $webvar{name});
     508  $page->param(address  => $webvar{address});
     509  $page->param(distance => $webvar{distance})
     510        if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV});
     511  $page->param(weight   => $webvar{weight}) if $webvar{type} == $reverse_typemap{SRV};
     512  $page->param(port     => $webvar{port}) if $webvar{type} == $reverse_typemap{SRV};
    482513  $page->param(ttl      => ($webvar{ttl} ? $webvar{ttl} : $DNSDB::def{minttl}));
    483   if ($webvar{defrec} eq 'y') {
    484     ##fixme - should be groupid
    485     $page->param(parentid => 1);
    486   } else {
    487 print "DEBUG: foobar:  parentid $webvar{parentid}<br>\n";
    488     $page->param(parentid => $webvar{parentid});
    489   }
    490514}
    491515
  • trunk/templates/record.tmpl

    r15 r16  
    55<td align="center">
    66
    7 <TMPL_IF edit_failed><span class="errmsg">Error <TMPL VAR NAME=recact> record: <TMPL_VARNAME=errmsg></span></TMPL_IF>
     7<TMPL_IF failed><div class="errmsg">Error <TMPL_VAR NAME=wastrying> record: <TMPL_VARNAME=errmsg></div></TMPL_IF>
    88<form action="dns.cgi" method="POST">
    99<input type="hidden" name="page" value="record">
     
    1717
    1818        <table border=0 width="100%">
    19         <tr class="tableheader"><td align="center" colspan=2><TMPL_VAR NAME=todo> <TMPL_VAR NAME=domain></td></tr>
     19        <tr class="tableheader"><td align="center" colspan=2><TMPL_VAR NAME=todo>: <TMPL_VAR NAME=dohere></td></tr>
    2020        <tr class="datalinelight">
    2121                <td>Hostname</td>
     
    5151        </tr>
    5252        <tr class="datalinelight">
    53                 <td colspan=2 align=center><input type="submit" value=" Add record "></td>
     53                <td colspan=2 align=center><input type="submit" value=" <TMPL_VAR NAME=todo> "></td>
    5454        </tr>
    5555        </table>
Note: See TracChangeset for help on using the changeset viewer.