Changeset 187 for trunk


Ignore:
Timestamp:
12/06/11 15:58:51 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

Check that all major actions log both successes and failures
Make coding style more consistent (always "if $code eq 'OK'/else")
Make logged failure messages a little more consistent (always "Failed <blah>")

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dns.cgi

    r185 r187  
    373373    my $dom = domainName($dbh, $webvar{id});
    374374    my ($code,$msg) = delDomain($dbh, $webvar{id});
    375     if ($code ne 'OK') {
     375    if ($code eq 'OK') {
     376      logaction($webvar{id}, $session->param("username"), $pargroup, "Deleted domain $dom");
     377      changepage(page => "domlist", resultmsg => "Deleted domain $dom");
     378    } else {
    376379      logaction($webvar{id}, $session->param("username"), $pargroup, "Failed to delete domain $dom ($msg)");
    377380      changepage(page => "domlist", errmsg => "Error deleting domain $dom: $msg");
    378     } else {
    379       logaction($webvar{id}, $session->param("username"), $pargroup, "Deleted domain $dom");
    380       changepage(page => "domlist", resultmsg => "Deleted domain $dom");
    381381    }
    382382
     
    643643    my $rec = getRecLine($dbh,$webvar{defrec},$webvar{id});
    644644    my ($code,$msg) = delRec($dbh,$webvar{defrec},$webvar{id});
    645     if ($code ne 'OK') {
     645    if ($code eq 'OK') {
     646      if ($webvar{defrec} eq 'y') {
     647##fixme:  log distance for MX;  log port/weight/distance for SRV
     648        my $restr = "Deleted default record '$rec->{host} $typemap{$rec->{type}} $rec->{val}', TTL $rec->{ttl}";
     649        logaction(0, $session->param("username"), $rec->{parid}, $restr);
     650        changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}, resultmsg => $restr);
     651      } else {
     652        my $restr = "Deleted record '$rec->{host} $typemap{$rec->{type}} $rec->{val}', TTL $rec->{ttl}";
     653        logaction($rec->{parid}, $session->param("username"), parentID($rec->{parid}, 'dom', 'group'), $restr);
     654        changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}, resultmsg => $restr);
     655      }
     656    } else {
    646657## need to find failure mode
    647658      if ($webvar{defrec} eq 'y') {
     
    655666      changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec},
    656667                errmsg => "Error deleting record: $msg");
    657 #      $page->param(del_failed => 1);
    658 #      $page->param(errmsg => $msg);
    659 #      showdomain($webvar{defrec}, $webvar{parentid});
    660     } else {
    661       if ($webvar{defrec} eq 'y') {
    662         my $restr = "Deleted default record '$rec->{host} $typemap{$rec->{type}} $rec->{val}', TTL $rec->{ttl}";
    663         logaction(0, $session->param("username"), $rec->{parid}, $restr);
    664         changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}, resultmsg => $restr);
    665       } else {
    666         my $restr = "Deleted record '$rec->{host} $typemap{$rec->{type}} $rec->{val}', TTL $rec->{ttl}";
    667         logaction($rec->{parid}, $session->param("username"), parentID($rec->{parid}, 'dom', 'group'), $restr);
    668         changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}, resultmsg => $restr);
    669       }
    670668    }
    671669  } else {
     
    808806        changepage(page => "grpman", resultmsg => "Added group $webvar{newgroup}");
    809807      }
    810     }
     808    } # fallthrough else
     809    logaction(0, $session->param("username"), $webvar{pargroup}, "Failed to add group $webvar{newgroup}: $msg");
    811810    # no point in doing extra work
    812811    fill_permissions($page, \%newperms);
     
    842841# up along with an unchecked-by-default check box to YES DAMMIT DELETE THE WHOLE THING
    843842
    844 #    $page->param(groupname => groupName($dbh,$webvar{id}));
    845 # print some neato things?
    846 
    847 #  } else {
    848 #    #whether actually deleting or cancelling we redirect to the group list, default format
    849 
    850843  } elsif ($webvar{del} eq 'ok') {
    851844    my $deleteme = groupName($dbh,$webvar{id}); # get this before we delete it...
    852845    my $delparent = parentID($webvar{id}, 'group','group');
    853846    my ($code,$msg) = delGroup($dbh, $webvar{id});
    854     if ($code ne 'OK') {
    855 # need to find failure mode
    856       logaction(0, $session->param("username"), $delparent, "Failure deleting group $deleteme: $msg");
    857       changepage(page => "grpman", errmsg => "Error deleting group $deleteme: $msg");
    858     } else {
     847    if ($code eq 'OK') {
    859848##fixme: need to clean up log when deleting a major container
    860849      logaction(0, $session->param("username"), $delparent, "Deleted group $deleteme");
    861850      changepage(page => "grpman", resultmsg => "Deleted group $deleteme");
     851    } else {
     852# need to find failure mode
     853      logaction(0, $session->param("username"), $delparent, "Failed to delete group $deleteme: $msg");
     854      changepage(page => "grpman", errmsg => "Error deleting group $deleteme: $msg");
    862855    }
    863856  } else {
     
    905898                "Updated default permissions in group ".groupName($dbh, $webvar{gid}));
    906899      }
    907     }
     900    } # fallthrough else
     901    logaction(0, $session->param("username"), $webvar{gid}, "Failed to update default permissions in group ".
     902        groupName($dbh, $webvar{gid}).": $msg");
    908903    # no point in doing extra work
    909904    fill_permissions($page, \%chperms);
     
    994989      } else {
    995990        logaction($webvar{$_}, $session->param("username"), parentID($webvar{$_}, 'dom', 'group'),
    996                 "Failure moving domain ".domainName($dbh, $webvar{$_})." to group $newgname: $msg");
     991                "Failed to move domain ".domainName($dbh, $webvar{$_})." to group $newgname: $msg");
    997992      }
    998993      $row{domerr} = $msg;
     
    10511046        $row{domok} = ($code eq 'OK');
    10521047      } else {
    1053         logaction($webvar{$_}, $session->param("username"), $pargroup, "Failure deleting domain $dom: $msg");
     1048        logaction($webvar{$_}, $session->param("username"), $pargroup, "Failed to delete domain $dom: $msg");
    10541049      }
    10551050      $row{domerr} = $msg;
     
    12001195          $newperms{admin} = 1 if $webvar{accttype} eq 'S';
    12011196          ($code,$msg) = changePermissions($dbh, 'user', $webvar{uid}, \%newperms, ($permstring eq 'i'));
     1197          logaction(0, $session->param("username"), $curgroup,
     1198                "Updated uid $webvar{uid}, user $webvar{uname} ($webvar{fname} $webvar{lname})");
    12021199        }
    1203         logaction(0, $session->param("username"), $curgroup,
    1204                 "Updated uid $webvar{uid}, user $webvar{uname} ($webvar{fname} $webvar{lname})");
    12051200      }
    12061201    }
     
    12381233      fill_actypelist($webvar{accttype});
    12391234      fill_clonemelist();
    1240 ##fixme: log
     1235      logaction(0, $session->param("username"), $curgroup, "Failed to $webvar{action} user ".
     1236        "$webvar{uname}: $msg");
    12411237    }
    12421238
     
    13041300    my $userref = getUserData($dbh, $webvar{id});
    13051301    my ($code,$msg) = delUser($dbh, $webvar{id});
    1306     if ($code ne 'OK') {
    1307 # need to find failure mode
    1308       $page->param(del_failed => 1);
    1309       $page->param(errmsg => $msg);
    1310       list_users($curgroup);
    1311 #Error deleting user <TMPL_VAR NAME=delusername>: <TMPL_VAR NAME=errmsg>
    1312     } else {
     1302    if ($code eq 'OK') {
    13131303      # success.  go back to the user list, do not pass "GO"
    13141304      # actions on users have a domain id of 0, always
     
    13171307      changepage(page => "useradmin", resultmsg => "Deleted user ".$userref->{username}.
    13181308        " (".$userref->{lastname}.", ".$userref->{firstname}.")");
     1309    } else {
     1310# need to find failure mode
     1311      $page->param(del_failed => 1);
     1312      $page->param(errmsg => $msg);
     1313      list_users($curgroup);
     1314      logaction(0, $session->param("username"), $curgroup, "Failed to delete user ".
     1315        "$webvar{id}/".$userref->{username}.": $msg");
    13191316    }
    13201317  } else {
Note: See TracChangeset for help on using the changeset viewer.