Changeset 295 for trunk/dns.cgi


Ignore:
Timestamp:
03/29/12 17:06:10 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

Move entity-relationship reference hashes up into the same area
as other (semi)globals in DNSDB.pm since I was starting to add
an accidental duplicate of %par_tbl.
Move action logging for bulk domain change to DNSDB.pm: (See #35)

  • Clean up dns.cgi to match previous changes to zoneStatus() and delZone()
  • Less not-quite-identical code in dns.cgi can now be factored down
  • Updated changeGroup() with action logging and more error handling
  • Tweak logging and messages in delZone()
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dns.cgi

    r294 r295  
    10851085  }
    10861086
     1087  # per-action scope checks
    10871088  if ($webvar{bulkaction} eq 'move') {
    10881089    changepage(page => "domlist", errmsg => "You are not permitted to bulk-move domains")
     
    10901091    my $newgname = groupName($dbh,$webvar{destgroup});
    10911092    $page->param(action => "Move to group $newgname");
    1092     my @bulkresults;
    1093     # nngh.  due to alpha-sorting on the previous page, we can't use domid-numeric
    1094     # order here, and since we don't have the domain names until we go around this
    1095     # loop, we can't alpha-sort them here.  :(
    1096     foreach (keys %webvar) {
    1097       my %row;
    1098       next unless $_ =~ /^dom_\d+$/;
    1099       # second security check - does the user have permission to meddle with this domain?
    1100       if (!check_scope(id => $webvar{$_}, type => 'domain')) {
    1101         $row{domerr} = "You are not permitted to make changes to the requested domain";
    1102         $row{domain} = $webvar{$_};
    1103         push @bulkresults, \%row;
    1104         next;
    1105       }
    1106       $row{domain} = domainName($dbh,$webvar{$_});
    1107       my ($code, $msg) = changeGroup($dbh, 'domain', $webvar{$_}, $webvar{destgroup});
    1108       if ($code eq 'OK') {
    1109         logaction($webvar{$_}, $session->param("username"),
    1110                 parentID($dbh, (id => $webvar{$_}, type => 'domain', revrec => $webvar{revrec})),
    1111                 "Moved domain ".domainName($dbh, $webvar{$_})." to group $newgname");
    1112         $row{domok} = ($code eq 'OK');
    1113       } else {
    1114         logaction($webvar{$_}, $session->param("username"),
    1115                 parentID($dbh, (id => $webvar{$_}, type => 'domain', revrec => $webvar{revrec})),
    1116                 "Failed to move domain ".domainName($dbh, $webvar{$_})." to group $newgname: $msg")
    1117                 if $config{log_failures};
    1118       }
    1119       $row{domerr} = $msg;
    1120       push @bulkresults, \%row;
    1121     }
    1122     $page->param(bulkresults => \@bulkresults);
    1123 
    11241093  } elsif ($webvar{bulkaction} eq 'deactivate' || $webvar{bulkaction} eq 'activate') {
    11251094    changepage(page => "domlist", errmsg => "You are not permitted to bulk-$webvar{bulkaction} domains")
    11261095        unless ($permissions{admin} || $permissions{domain_edit});
    11271096    $page->param(action => "$webvar{bulkaction} domains");
    1128     my @bulkresults;
    1129     foreach (keys %webvar) {
    1130       my %row;
    1131       next unless $_ =~ /^dom_\d+$/;
    1132       # second security check - does the user have permission to meddle with this domain?
    1133       if (!check_scope(id => $webvar{$_}, type => 'domain')) {
    1134         $row{domerr} = "You are not permitted to make changes to the requested domain";
    1135         $row{domain} = $webvar{$_};
    1136         push @bulkresults, \%row;
    1137         next;
    1138       }
    1139       $row{domain} = domainName($dbh,$webvar{$_});
    1140 ##fixme:  error handling on status change
    1141       my $stat = zoneStatus($dbh,$webvar{$_},($webvar{bulkaction} eq 'activate' ? 'domon' : 'domoff'));
    1142       logaction($webvar{$_}, $session->param("username"),
    1143         parentID($dbh, (id => $webvar{$_}, type => 'domain', revrec => $webvar{revrec})),
    1144         "Changed domain ".domainName($dbh, $webvar{$_})." state to ".($stat ? 'active' : 'inactive'));
    1145       $row{domok} = 1;
    1146 #      $row{domok} = ($code eq 'OK');
    1147 #      $row{domerr} = $msg;
    1148       push @bulkresults, \%row;
    1149     }
    1150     $page->param(bulkresults => \@bulkresults);
    1151 
    11521097  } elsif ($webvar{bulkaction} eq 'delete') {
    11531098    changepage(page => "domlist", errmsg => "You are not permitted to bulk-delete domains")
    11541099        unless ($permissions{admin} || $permissions{domain_delete});
    11551100    $page->param(action => "$webvar{bulkaction} domains");
    1156     my @bulkresults;
    1157     foreach (keys %webvar) {
    1158       my %row;
    1159       next unless $_ =~ /^dom_\d+$/;
    1160       # second security check - does the user have permission to meddle with this domain?
    1161       if (!check_scope(id => $webvar{$_}, type => 'domain')) {
    1162         $row{domerr} = "You are not permitted to make changes to the requested domain";
    1163         $row{domain} = $webvar{$_};
    1164         push @bulkresults, \%row;
    1165         next;
    1166       }
    1167       $row{domain} = domainName($dbh,$webvar{$_});
    1168       my $pargroup = parentID($dbh, (id => $webvar{$_}, type => 'domain', revrec => $webvar{revrec}));
    1169       my $dom = domainName($dbh, $webvar{$_});
    1170       my ($code, $msg) = delZone($dbh, $webvar{$_}, 'n');
    1171       if ($code eq 'OK') {
    1172         logaction($webvar{$_}, $session->param("username"), $pargroup, "Deleted domain $dom");
    1173         $row{domok} = ($code eq 'OK');
    1174       } else {
    1175         logaction($webvar{$_}, $session->param("username"), $pargroup, "Failed to delete domain $dom: $msg")
    1176                 if $config{log_failures};
    1177       }
     1101  } else {
     1102    # unknown action, bypass actually doing anything.  it should not be possible in
     1103    # normal operations, and anyone who meddles with the URL gets what they deserve.
     1104    goto DONEBULK;
     1105  } # move/(de)activate/delete if()
     1106
     1107  my @bulkresults;
     1108  # nngh.  due to alpha-sorting on the previous page, we can't use domid-numeric
     1109  # order here, and since we don't have the domain names until we go around this
     1110  # loop, we can't alpha-sort them here.  :(
     1111  foreach (keys %webvar) {
     1112    my %row;
     1113    next unless $_ =~ /^dom_\d+$/;
     1114    # second security check - does the user have permission to meddle with this domain?
     1115    if (!check_scope(id => $webvar{$_}, type => 'domain')) {
     1116      $row{domerr} = "You are not permitted to make changes to the requested domain";
     1117      $row{domain} = $webvar{$_};
     1118      push @bulkresults, \%row;
     1119      next;
     1120    }
     1121    $row{domain} = domainName($dbh,$webvar{$_});
     1122
     1123    # Do the $webvar{bulkaction}
     1124    my ($code, $msg);
     1125    ($code, $msg) = changeGroup($dbh, 'domain', $webvar{$_}, $webvar{destgroup})
     1126        if $webvar{bulkaction} eq 'move';
     1127    if ($webvar{bulkaction} eq 'deactivate' || $webvar{bulkaction} eq 'activate') {
     1128      my $stat = zoneStatus($dbh,$webvar{$_},'n',($webvar{bulkaction} eq 'activate' ? 'domon' : 'domoff'));
     1129      $code = (defined($stat) ? 'OK' : 'FAIL');
     1130      $msg = (defined($stat) ? $DNSDB::resultstr : $DNSDB::errstr);
     1131    }
     1132    ($code, $msg) = delZone($dbh, $webvar{$_}, 'n')
     1133        if $webvar{bulkaction} eq 'delete';
     1134
     1135    # Set the result output from the action
     1136    if ($code eq 'OK') {
     1137      $row{domok} = $msg;
     1138    } elsif ($code eq 'WARN') {
     1139      $row{domwarn} = $msg;
     1140    } else {
    11781141      $row{domerr} = $msg;
    1179       push @bulkresults, \%row;
    1180     }
    1181     $page->param(bulkresults => \@bulkresults);
    1182 
    1183   } # move/(de)activate/delete if()
    1184 
    1185   # not going to handle the unknown $webvar{action} else;  it should not be possible in normal
    1186   # operations, and anyone who meddles with the URL gets what they deserve.
     1142    }
     1143    push @bulkresults, \%row;
     1144
     1145  } # foreach (keys %webvar)
     1146  $page->param(bulkresults => \@bulkresults);
    11871147
    11881148  # Yes, this is a GOTO target.  PTHBTTT.
Note: See TracChangeset for help on using the changeset viewer.