Changeset 243


Ignore:
Timestamp:
02/24/12 15:35:07 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

Fixing up delRec() and caller to handle reverse records. See #26.

  • make sure to pass $webvar{revrec} around everywhere
  • extend getRecLine to properly retrieve information for any record
  • make sure another couple of changepage() calls bounce you to the right place
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r242 r243  
    18221822## DNSDB::getRecLine()
    18231823# Return all data fields for a zone record in separate elements of a hash
    1824 # Takes a database handle, default/live flag, and record ID
     1824# Takes a database handle, default/live flag, forward/reverse flag, and record ID
    18251825sub getRecLine {
    18261826  $errstr = '';
    18271827  my $dbh = shift;
    1828   my $def = shift;
     1828  my $defrec = shift;
     1829  my $revrec = shift;
    18291830  my $id = shift;
    18301831
    1831   my $sql = "SELECT record_id,host,type,val,distance,weight,port,ttl".
    1832         (($def eq 'def' or $def eq 'y') ? ',group_id FROM default_' : ',domain_id FROM ').
    1833         "records WHERE record_id=?";
     1832  my $sql = "SELECT record_id,host,type,val,ttl".($revrec eq 'n' ? ',distance,weight,port' : '').
     1833        (($defrec eq 'y') ? ',group_id FROM ' : ',domain_id,rdns_id FROM ').
     1834        _rectable($defrec,$revrec)." WHERE record_id=?";
    18341835  my $ret = $dbh->selectrow_hashref($sql, undef, ($id) );
    18351836
     
    18441845  }
    18451846
    1846   $ret->{parid} = (($def eq 'def' or $def eq 'y') ? $ret->{group_id} : $ret->{domain_id});
     1847  # explicitly set a parent id
     1848  if ($defrec eq 'y') {
     1849    $ret->{parid} = $ret->{group_id};
     1850  } else {
     1851    $ret->{parid} = (($revrec eq 'n') ? $ret->{domain_id} : $ret->{rdns_id});
     1852    # and a secondary if we have a custom type that lives in both a forward and reverse zone
     1853    $ret->{secid} = (($revrec eq 'y') ? $ret->{domain_id} : $ret->{rdns_id}) if $ret->{type} > 65279;
     1854  }
    18471855
    18481856  return $ret;
     
    20972105  my $dbh = shift;
    20982106  my $defrec = shift;
     2107  my $revrec = shift;
    20992108  my $id = shift;
    21002109
    2101   my $sth = $dbh->prepare("DELETE FROM ".($defrec eq 'y' ? 'default_' : '')."records WHERE record_id=?");
     2110  my $sth = $dbh->prepare("DELETE FROM "._rectable($defrec,$revrec)." WHERE record_id=?");
    21022111  $sth->execute($id);
    21032112
  • trunk/dns.cgi

    r242 r243  
    619619    $page->param(id             => $webvar{id});
    620620    $page->param(defrec         => $webvar{defrec});
    621     my $recdata = getRecLine($dbh, $webvar{defrec}, $webvar{id});
     621    $page->param(revrec         => $webvar{revrec});
     622    my $recdata = getRecLine($dbh, $webvar{defrec}, $webvar{revrec}, $webvar{id});
    622623    $page->param(name           => $recdata->{host});
    623624    $page->param(address        => $recdata->{val});
     
    638639
    639640    # get current/previous record info so we can log "updated 'foo A 1.2.3.4' to 'foo A 2.3.4.5'"
    640     my $oldrec = getRecLine($dbh, $webvar{defrec}, $webvar{id});
     641    my $oldrec = getRecLine($dbh, $webvar{defrec}, $webvar{revrec}, $webvar{id});
    641642
    642643    my ($code,$msg) = updateRec($dbh,$webvar{defrec},$webvar{id},
     
    694695  # This is a complete separate segment since it uses a different template from add/edit records above
    695696
    696   changepage(page => "reclist", errmsg => "You are not permitted to delete records", id => $webvar{parentid})
     697  changepage(page => "reclist", errmsg => "You are not permitted to delete records", id => $webvar{parentid},
     698                revrec => $webvar{revrec})
    697699        unless ($permissions{admin} || $permissions{record_delete});
    698700
     
    704706  $page->param(id => $webvar{id});
    705707  $page->param(defrec => $webvar{defrec});
     708  $page->param(revrec => $webvar{revrec});
    706709  $page->param(parentid => $webvar{parentid});
    707710  # first pass = confirm y/n (sorta)
    708711  if (!defined($webvar{del})) {
    709712    $page->param(del_getconf => 1);
    710     my $rec = getRecLine($dbh,$webvar{defrec},$webvar{id});
     713    my $rec = getRecLine($dbh, $webvar{defrec}, $webvar{revrec}, $webvar{id});
    711714    $page->param(host => $rec->{host});
    712715    $page->param(ftype => $typemap{$rec->{type}});
     
    714717  } elsif ($webvar{del} eq 'ok') {
    715718# get rec data before we try to delete it
    716     my $rec = getRecLine($dbh,$webvar{defrec},$webvar{id});
    717     my ($code,$msg) = delRec($dbh,$webvar{defrec},$webvar{id});
     719    my $rec = getRecLine($dbh, $webvar{defrec}, $webvar{revrec}, $webvar{id});
     720    my ($code,$msg) = delRec($dbh, $webvar{defrec}, $webvar{revrec}, $webvar{id});
    718721    if ($code eq 'OK') {
    719722      if ($webvar{defrec} eq 'y') {
     
    725728        my $restr = "Deleted record '$rec->{host} $typemap{$rec->{type}} $rec->{val}', TTL $rec->{ttl}";
    726729        logaction($rec->{parid}, $session->param("username"), parentID($rec->{parid}, 'dom', 'group'), $restr);
    727         changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}, resultmsg => $restr);
     730        changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec},
     731                revrec => $webvar{revrec}, resultmsg => $restr);
    728732      }
    729733    } else {
     
    740744      }
    741745      changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec},
    742                 errmsg => "Error deleting record: $msg");
     746                revrec => $webvar{revrec}, errmsg => "Error deleting record: $msg");
    743747    }
    744748  } else {
  • trunk/templates/delrec.tmpl

    r100 r243  
    66<h3>Are you really sure you want to delete record:<br />
    77<TMPL_VAR NAME=host> <TMPL_VAR NAME=ftype> <TMPL_VAR NAME=recval></h3>
    8 <a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&amp;page=delrec&amp;del=cancel&amp;id=<TMPL_VAR NAME=id>&amp;defrec=<TMPL_VAR NAME=defrec>&amp;parentid=<TMPL_VAR NAME=parentid>">cancel</a> &nbsp; | &nbsp; <a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&amp;page=delrec&amp;del=ok&amp;id=<TMPL_VAR NAME=id>&amp;defrec=<TMPL_VAR NAME=defrec>&amp;parentid=<TMPL_VAR NAME=parentid>">confirm</a>
     8<a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&amp;page=delrec&amp;del=cancel&amp;id=<TMPL_VAR NAME=id>&amp;defrec=<TMPL_VAR NAME=defrec>&amp;revrec=<TMPL_VAR NAME=revrec>&amp;parentid=<TMPL_VAR NAME=parentid>">cancel</a>
     9 &nbsp; | &nbsp;
     10<a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&amp;page=delrec&amp;del=ok&amp;id=<TMPL_VAR NAME=id>&amp;defrec=<TMPL_VAR NAME=defrec>&amp;revrec=<TMPL_VAR NAME=revrec>&amp;parentid=<TMPL_VAR NAME=parentid>">confirm</a>
    911</td></tr></table>
    1012
Note: See TracChangeset for help on using the changeset viewer.