Changeset 275 for trunk


Ignore:
Timestamp:
03/15/12 15:34:38 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

Convert domStatus() and caller to zoneStatus() for reverse DNS
Add status change to revzones page handling
See #26

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r274 r275  
    4848        &parentID
    4949        &isParent
    50         &domStatus &importAXFR
     50        &zoneStatus &importAXFR
    5151        &export
    5252        &mailNotify
     
    7070                &parentID
    7171                &isParent
    72                 &domStatus &importAXFR
     72                &zoneStatus &importAXFR
    7373                &export
    7474                &mailNotify
     
    27222722
    27232723
    2724 ## DNSDB::domStatus()
    2725 # Sets and/or returns a domain's status
    2726 # Takes a database handle, domain ID and optionally a status argument
    2727 # Returns undef on errors.
    2728 sub domStatus {
     2724## DNSDB::zoneStatus()
     2725# Returns and optionally sets a zone's status
     2726# Takes a database handle, domain/revzone ID, forward/reverse flag, and optionally a status argument
     2727# Returns status, or undef on errors.
     2728sub zoneStatus {
    27292729  my $dbh = shift;
    27302730  my $id = shift;
    2731   my $newstatus = shift;
     2731  my $revrec = shift;
     2732  my $newstatus = shift || 'mu';
    27322733
    27332734  return undef if $id !~ /^\d+$/;
    27342735
    2735   my $sth;
    2736 
    27372736# ooo, fun!  let's see what we were passed for status
    2738   if ($newstatus) {
    2739     $sth = $dbh->prepare("update domains set status=? where domain_id=?");
    2740     # ass-u-me caller knows what's going on in full
    2741     if ($newstatus =~ /^[01]$/) {       # only two valid for now.
    2742       $sth->execute($newstatus,$id);
    2743     } elsif ($newstatus =~ /^domo(?:n|ff)$/) {
    2744       $sth->execute(($newstatus eq 'domon' ? 1 : 0),$id);
    2745     }
    2746   }
    2747 
    2748   $sth = $dbh->prepare("select status from domains where domain_id=?");
    2749   $sth->execute($id);
    2750   my ($status) = $sth->fetchrow_array;
     2737  if ($newstatus ne 'mu') {
     2738    $newstatus = 0 if $newstatus eq 'domoff';
     2739    $newstatus = 1 if $newstatus eq 'domon';
     2740    $dbh->do("UPDATE ".($revrec eq 'n' ? 'domains' : 'revzones')." SET status=? WHERE ".
     2741        ($revrec eq 'n' ? 'domain_id' : 'rdns_id')."=?", undef, ($newstatus,$id) );
     2742  }
     2743
     2744  my ($status) = $dbh->selectrow_array("SELECT status FROM ".
     2745        ($revrec eq 'n' ? "domains WHERE domain_id=?" : "revzones WHERE rdns_id=?"),
     2746        undef, ($id) );
    27512747  return $status;
    2752 } # end domStatus()
     2748} # end zoneStatus()
    27532749
    27542750
  • trunk/dns.cgi

    r274 r275  
    315315# hmm.  seeing problems in some possibly-not-so-corner cases.
    316316# this currently only handles "domain on", "domain off"
    317   if (defined($webvar{domstatus})) {
     317  if (defined($webvar{zonestatus})) {
    318318    # security check - does the user have permission to access this entity?
    319319    my $flag = 0;
     
    322322    }
    323323    if ($flag && ($permissions{admin} || $permissions{domain_edit})) {
    324       my $stat = domStatus($dbh,$webvar{id},$webvar{domstatus});
     324      my $stat = zoneStatus($dbh,$webvar{id},'n',$webvar{zonestatus});
    325325##fixme  switch to more consise "Enabled <domain"/"Disabled <domain>" as with users?
    326326      logaction($webvar{id}, $session->param("username"),
     
    332332      $page->param(errmsg => "You are not permitted to view or change the requested domain");
    333333    }
    334     $uri_self =~ s/\&amp;domstatus=[^&]*//g;    # clean up URL for stuffing into templates
     334    $uri_self =~ s/\&amp;zonestatus=[^&]*//g;   # clean up URL for stuffing into templates
    335335  }
    336336
     
    434434
    435435  $webvar{revrec} = 'y';
     436
     437  if (defined($webvar{zonestatus})) {
     438    # security check - does the user have permission to access this entity?
     439    my $flag = 0;
     440    foreach (@viewablegroups) {
     441      $flag = 1 if isParent($dbh, $_, 'group', $webvar{id}, 'revzone');
     442    }
     443    if ($flag && ($permissions{admin} || $permissions{domain_edit})) {
     444      my $stat = zoneStatus($dbh,$webvar{id},'y',$webvar{zonestatus});
     445##fixme  switch to more consise "Enabled <domain"/"Disabled <domain>" as with users?
     446      logaction($webvar{id}, $session->param("username"),
     447        parentID($dbh, (id => $webvar{id}, type => 'revzone', revrec => $webvar{revrec})),
     448        "Changed ".revName($dbh, $webvar{id})." state to ".($stat ? 'active' : 'inactive'));
     449      $page->param(resultmsg => "Changed ".revName($dbh, $webvar{id})." state to ".
     450        ($stat ? 'active' : 'inactive'));
     451    } else {
     452      $page->param(errmsg => "You are not permitted to view or change the requested reverse zone");
     453    }
     454    $uri_self =~ s/\&amp;zonestatus=[^&]*//g;   # clean up URL for stuffing into templates
     455  }
    436456
    437457  if ($session->param('resultmsg')) {
     
    12221242      $row{domain} = domainName($dbh,$webvar{$_});
    12231243##fixme:  error handling on status change
    1224       my $stat = domStatus($dbh,$webvar{$_},($webvar{bulkaction} eq 'activate' ? 'domon' : 'domoff'));
     1244      my $stat = zoneStatus($dbh,$webvar{$_},($webvar{bulkaction} eq 'activate' ? 'domon' : 'domoff'));
    12251245      logaction($webvar{$_}, $session->param("username"),
    12261246        parentID($dbh, (id => $webvar{$_}, type => 'domain', revrec => $webvar{revrec})),
     
    16371657      my %row;
    16381658      my ($code,$msg) = importAXFR($dbh, $webvar{ifrom}, $domain, $webvar{group},
    1639         $webvar{domstatus}, $webvar{rwsoa}, $webvar{rwns});
     1659        $webvar{zonestatus}, $webvar{rwsoa}, $webvar{rwns});
    16401660      $row{domok} = $msg if $code eq 'OK';
    16411661      if ($code eq 'WARN') {
  • trunk/templates/domlist.tmpl

    r239 r275  
    4949        <td><TMPL_IF status>Active<TMPL_ELSE>Inactive</TMPL_IF></td>
    5050        <td><TMPL_VAR name=group></td>
    51 <TMPL_IF domain_edit>   <td align="center"><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&amp;page=<TMPL_VAR NAME=curpage><TMPL_IF NAME=offset>&amp;offset=<TMPL_VAR NAME=offset></TMPL_IF>&amp;id=<TMPL_VAR NAME=domainid>&amp;domstatus=<TMPL_IF status>domoff<TMPL_ELSE>domon</TMPL_IF>"><TMPL_IF status>deactivate<TMPL_ELSE>activate</TMPL_IF></a></td></TMPL_IF>
     51<TMPL_IF domain_edit>   <td align="center"><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&amp;page=<TMPL_VAR NAME=curpage><TMPL_IF NAME=offset>&amp;offset=<TMPL_VAR NAME=offset></TMPL_IF>&amp;id=<TMPL_VAR NAME=domainid>&amp;zonestatus=<TMPL_IF status>domoff<TMPL_ELSE>domon</TMPL_IF>"><TMPL_IF status>deactivate<TMPL_ELSE>activate</TMPL_IF></a></td></TMPL_IF>
    5252<TMPL_IF domain_delete> <td align="center"><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&amp;page=<TMPL_IF domlist>deldom<TMPL_ELSE>delrevzone</TMPL_IF>&amp;id=<TMPL_VAR NAME=domainid>"><img src="images/trash2.png" alt="[ Delete ]" /></a></td></TMPL_IF>
    5353</tr>
Note: See TracChangeset for help on using the changeset viewer.