Changeset 277


Ignore:
Timestamp:
03/15/12 18:04:02 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

Checkpoint: Clean up SOA editing and extend for reverse zones.
Mostly complete; still need to finish shuffling arguments to
get logging moved into DNSDB.pm
See #26

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r276 r277  
    4343        &addGroup &delGroup &getChildren &groupName
    4444        &addUser &updateUser &delUser &userFullName &userStatus &getUserData
    45         &getSOA &getRecLine &getDomRecs &getRecCount
     45        &getSOA &updateSOA &getRecLine &getDomRecs &getRecCount
    4646        &addRec &updateRec &delRec
    4747        &getTypelist
     
    6565                &addGroup &delGroup &getChildren &groupName
    6666                &addUser &updateUser &delUser &userFullName &userStatus &getUserData
    67                 &getSOA &getRecLine &getDomRecs &getRecCount
     67                &getSOA &updateSOA &getRecLine &getDomRecs &getRecCount
    6868                &addRec &updateRec &delRec
    6969                &getTypelist
     
    21822182# Update the specified SOA record
    21832183# Takes a database handle, default/live flag, forward/reverse flag, and SOA data hash
     2184# Returns a two-element list with a result code and message
    21842185sub updateSOA {
    21852186  my $dbh = shift;
     
    21892190  my %soa = @_;
    21902191
     2192  my %oldsoa = getSOA($dbh, $defrec, $revrec, $soa{recid});
     2193
     2194  # Allow transactions, and raise an exception on errors so we can catch it later.
     2195  # Use local to make sure these get "reset" properly on exiting this block
     2196  local $dbh->{AutoCommit} = 0;
     2197  local $dbh->{RaiseError} = 1;
     2198
     2199  my $msg;
     2200
     2201  eval {
    21912202##fixme: data validation: make sure {recid} is really the SOA for {parent}
    2192   my $sql = "UPDATE "._rectable($defrec, $revrec)." SET host=?, val=?, ttl=? WHERE record_id=? AND type=6";
    2193   $dbh->do($sql, undef, ("$soa{contact}:$soa{prins}", "$soa{refresh}:$soa{retry}:$soa{expire}:$soa{minttl}",
    2194         $soa{ttl}, $soa{recid}));
    2195 
     2203    my $sql = "UPDATE "._rectable($defrec, $revrec)." SET host=?, val=?, ttl=? WHERE record_id=? AND type=6";
     2204    $dbh->do($sql, undef, ("$soa{contact}:$soa{prins}", "$soa{refresh}:$soa{retry}:$soa{expire}:$soa{minttl}",
     2205        $soa{ttl}, $soa{recid}) );
     2206
     2207    $msg = "Updated ".($defrec eq 'y' ? 'default ' : '')."SOA for ".
     2208        ($defrec eq 'y' ? groupName($dbh, $soa{recid}) :
     2209                ($revrec eq 'n' ? domainName($dbh, $soa{recid}) : revName($dbh, $soa{recid}) ) ).
     2210        ": (ns $oldsoa{prins}, contact $oldsoa{contact}, refresh $oldsoa{refresh},".
     2211        " retry $oldsoa{retry}, expire $oldsoa{expire}, minTTL $oldsoa{minttl}, TTL $oldsoa{ttl}) to ".
     2212        "(ns $soa{prins}, contact $soa{contact}, refresh $soa{refresh},".
     2213        " retry $soa{retry}, expire $soa{expire}, minTTL $soa{minttl}, TTL $soa{ttl})";
     2214
     2215#    _log($dbh, (rdns_id => $rdns_id, user_id => $userinfo{id}, group_id => $group,
     2216#       username => $userinfo{name}, entry => $msg) );
     2217
     2218    $dbh->commit;
     2219  };
     2220  if ($@) {
     2221    $msg = $@;
     2222    eval { $dbh->rollback; };
     2223    return ('FAIL',$msg);
     2224  } else {
     2225    return ('OK', $msg);
     2226  }
    21962227} # end updateSOA()
    21972228
  • trunk/dns.cgi

    r275 r277  
    908908  }
    909909
    910   fillsoa($webvar{defrec},$webvar{id});
     910  fillsoa($webvar{defrec},$webvar{revrec},$webvar{id});
    911911
    912912} elsif ($webvar{page} eq 'updatesoa') {
     
    930930
    931931  # get old SOA for log
    932   my %soa = getSOA($dbh,$webvar{defrec},$webvar{id});
    933 
    934   my $sth;
    935 ##fixme:  push SQL into DNSDB.pm
    936 ##fixme: data validation: make sure {recid} is really the SOA for {id}
    937   # no domain ID, so we're editing the default SOA for a group (we don't care which one here)
    938   # plus a bit of magic to update the appropriate table
    939   my $sql = "UPDATE ".($webvar{defrec} eq 'y' ? "default_records" : "records").
    940         " SET host=?, val=?, ttl=? WHERE record_id=?";
    941   $sth = $dbh->prepare($sql);
    942   $sth->execute("$webvar{contact}:$webvar{prins}",
    943         "$webvar{refresh}:$webvar{retry}:$webvar{expire}:$webvar{minttl}",
    944         $webvar{ttl},
    945         $webvar{recid});
    946 
    947   if ($sth->err) {
     932  my %soa = getSOA($dbh,$webvar{defrec},$webvar{revrec},$webvar{id});
     933
     934#  my $sth;
     935###fixme:  push SQL into DNSDB.pm
     936###fixme: data validation: make sure {recid} is really the SOA for {id}
     937#  # no domain ID, so we're editing the default SOA for a group (we don't care which one here)
     938#  # plus a bit of magic to update the appropriate table
     939#  my $sql = "UPDATE ".($webvar{defrec} eq 'y' ? "default_records" : "records").
     940#       " SET host=?, val=?, ttl=? WHERE record_id=?";
     941#  $sth = $dbh->prepare($sql);
     942#  $sth->execute("$webvar{contact}:$webvar{prins}",
     943#       "$webvar{refresh}:$webvar{retry}:$webvar{expire}:$webvar{minttl}",
     944#       $webvar{ttl},
     945#       $webvar{recid});
     946
     947  my ($code, $msg) = updateSOA($dbh, $webvar{defrec}, $webvar{revrec},
     948        (contact => $webvar{contact}, prins => $webvar{prins}, refresh => $webvar{refresh},
     949        retry => $webvar{retry}, expire => $webvar{expire}, minttl => $soa{minttl},
     950        ttl => $webvar{ttl}, recid => $webvar{recid}) );
     951  if ($code eq 'OK') {
     952    changepage(page => "reclist", id => $webvar{id}, defrec => $webvar{defrec}, revrec => $webvar{revrec},
     953        resultmsg => "SOA record updated");
     954  } else {
    948955    $page->param(update_failed => 1);
    949     $page->param(msg => $DBI::errstr);
    950     fillsoa($webvar{defrec},$webvar{id});
     956    $page->param(msg => $DNSDB::errstr);
     957    fillsoa($webvar{defrec},$webvar{revrec},$webvar{id});
     958  }
     959
    951960##fixme: faillog
    952   } else {
    953 
     961#  } else {
     962if (0) {
    954963    # do this in the order of "default to most common case"
    955964    my $loggroup;
     
    969978        "(ns $webvar{prins}, contact $webvar{contact}, refresh $webvar{refresh},".
    970979        " retry $webvar{retry}, expire $webvar{expire}, minTTL $webvar{minttl}, TTL $webvar{ttl})");
    971     changepage(page => "reclist", id => $webvar{id}, defrec => $webvar{defrec},
    972         resultmsg => "SOA record updated");
    973   }
     980  } # if (0)
    974981
    975982} elsif ($webvar{page} eq 'grpman') {
     
    18951902
    18961903sub fillsoa {
    1897   my $def = shift;
     1904  my $defrec = shift;
     1905  my $revrec = shift;
    18981906  my $id = shift;
    1899   my $domname = ($def eq 'y' ? '' : "DOMAIN");
    1900 
    1901   $page->param(defrec   => $def);
     1907  my $domname = ($defrec eq 'y' ? '' : "DOMAIN");
     1908
     1909  $page->param(defrec   => $defrec);
     1910  $page->param(revrec   => $revrec);
    19021911
    19031912# i had a good reason to do this when I wrote it...
    19041913#  $page->param(domain  => $domname);
    19051914#  $page->param(group   => $DNSDB::group);
    1906   $page->param(isgrp => 1) if $def eq 'y';
    1907   $page->param(parent => ($def eq 'y' ? groupName($dbh, $DNSDB::group) : domainName($dbh, $id)) );
     1915  $page->param(isgrp => 1) if $defrec eq 'y';
     1916  $page->param(parent => ($defrec eq 'y' ? groupName($dbh, $id) :
     1917        ($revrec eq 'n' ? domainName($dbh, $id) : revName($dbh, $id)) ) );
    19081918
    19091919# defaults
     
    19171927
    19181928  # there are probably better ways to do this.  TMTOWTDI.
    1919   my %soa = getSOA($dbh,$def,$id);
     1929  my %soa = getSOA($dbh,$defrec,$revrec,$id);
    19201930
    19211931  $page->param(id       => $id);
  • trunk/templates/editsoa.tmpl

    r100 r277  
    1818<input type="hidden" name="recid" value="<TMPL_VAR NAME=recid>" />
    1919<input type="hidden" name="defrec" value="<TMPL_VAR NAME=defrec>" />
     20<input type="hidden" name="revrec" value="<TMPL_VAR NAME=revrec>" />
    2021
    2122<table border="0" cellspacing="2" cellpadding="1" width="100%">
    2223<tr class="darkrowheader">
    2324        <td colspan="2" class="title"><TMPL_IF NAME=isgrp>Edit default SOA record for group <TMPL_ELSE>Edit SOA record for </TMPL_IF><TMPL_VAR NAME=parent></td>
    24         <td class="title">Defaults:</td>
     25        <td class="title">System defaults:</td>
    2526</tr>
    2627<tr class="datalinelight">
  • trunk/templates/soadata.tmpl

    r162 r277  
    33        <td align="left">SOA:</td>
    44<TMPL_IF mayeditsoa>
    5         <td align="right"><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&amp;page=editsoa&amp;id=<TMPL_VAR NAME=id>&amp;defrec=<TMPL_VAR NAME=defrec>">edit</a></td></TMPL_IF>
     5        <td align="right"><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&amp;page=editsoa&amp;id=<TMPL_VAR NAME=id>&amp;defrec=<TMPL_VAR NAME=defrec>&amp;revrec=<TMPL_VAR NAME=revrec>">edit</a></td></TMPL_IF>
    66</tr>
    77</table>
Note: See TracChangeset for help on using the changeset viewer.