Changeset 195


Ignore:
Timestamp:
12/12/11 17:52:55 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

More log behaviour tweaking

  • fix broken detail-logging of MX/SRV records on record add
  • add flag to control failure logging
  • fix broken user fullname grabber in _log

Tweak config loading with a few new options

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r193 r195  
    9898
    9999# Prepopulate a basic config.  Note some of these *will* cause errors if left unset.
     100# note:  add appropriate stanzas in loadConfig to parse these
    100101our %config = (
    101102                # Database connection info
     
    107108                # Email notice settings
    108109                mailhost        => 'smtp.example.com',
    109                 mailsender      => 'dnsdb@example.com',
     110                mailnotify      => 'dnsdb@example.com', # to
     111                mailsender      => 'dnsdb@example.com', # from
    110112                mailname        => 'DNS Administration',
     113                orgname         => 'Example Corp',
     114                domain          => 'example.com',
    111115
    112116                # Template directory
     
    116120
    117121                # Session params
    118                 timeout         => '3600'       # 1 hour default
     122                timeout         => '3600',      # 1 hour default
     123
     124                # Other miscellanea
     125                log_failures    => 1,   # log all evarthing by default
    119126        );
    120127
     
    150157        "Error opening site config file $siteconfig";
    151158      return;
     159    }
     160  }
     161
     162  # Munge log_failures.
     163  if ($config{log_failures} ne '1' && $config{log_failures} ne '0') {
     164    # true/false, on/off, yes/no all valid.
     165    if ($config{log_failures} =~ /^(?:true|false|on|off|yes|no)$/) {
     166      if ($config{log_failures} =~ /(?:true|on|yes)/) {
     167        $config{log_failures} = 1;
     168      } else {
     169        $config{log_failures} = 0;
     170      }
     171    } else {
     172      $errstr = "Bad log_failures setting $config{log_failures}";
     173      $config{log_failures} = 1;
     174      # Bad setting shouldn't be fatal.
     175      # return 2;
    152176    }
    153177  }
     
    190214      # Mail settings
    191215      $config{mailhost}         = $1 if /^mailhost\s*=\s*([a-z0-9_.-]+)/i;
     216      $config{mailnotify}       = $1 if /^mailnotify\s*=\s*([a-z0-9_.@-]+)/i;
    192217      $config{mailsender}       = $1 if /^mailsender\s*=\s*([a-z0-9_.@-]+)/i;
    193218      $config{mailname}         = $1 if /^mailname\s*=\s*([a-z0-9\s_.-]+)/i;
     219      $config{orgname}          = $1 if /^orgname\s*=\s*([a-z0-9\s_.,'-]+)/i;
     220      $config{domain}           = $1 if /^domain\s*=\s*([a-z0-9_.-]+)/i;
    194221      # session - note this is fed directly to CGI::Session
    195222      $config{timeout}  = $1 if /^[tT][iI][mM][eE][oO][uU][tT]\s*=\s*(\d+[smhdwMy]?)/;
     223      # log failed actions
     224      $config{log_failures}     = $1 if /^log_failures\s*=\s*([a-z01]+)/i;
    196225    }
    197226    close CFG;
     
    496525##fixme:  need better way(s?) to snag userinfo for log entries.  don't want to have
    497526# to pass around yet *another* constant (already passing $dbh, shouldn't need to)
     527  my $fullname;
    498528  if (!$user_id) {
    499     $user_id, $fullname) = $dbh->fetchrow_array("SELECT user_id, firstname || ' ' || lastname FROM users".
     529    ($user_id, $fullname) = $dbh->selectrow_array("SELECT user_id, firstname || ' ' || lastname FROM users".
    500530        " WHERE username=?", undef, ($username));
    501531  } elsif (!$username) {
    502     $username, $fullname) = $dbh->fetchrow_array("SELECT username, firstname || ' ' || lastname FROM users".
     532    ($username, $fullname) = $dbh->selectrow_array("SELECT username, firstname || ' ' || lastname FROM users".
     533        " WHERE user_id=?", undef, ($user_id));
     534  } else {
     535    ($fullname) = $dbh->selectrow_array("SELECT firstname || ' ' || lastname FROM users".
    503536        " WHERE user_id=?", undef, ($user_id));
    504537  }
  • trunk/dns.cgi

    r193 r195  
    350350    changepage(page => "reclist", id => $msg);
    351351  } else {
    352     logaction(0, $session->param("username"), $webvar{group}, "Failed adding domain $webvar{domain} ($msg)");
     352    logaction(0, $session->param("username"), $webvar{group}, "Failed adding domain $webvar{domain} ($msg)")
     353        if $config{log_failures};
    353354    $session->param('add_failed', 1);
    354355##fixme:  domain a security risk for XSS?
     
    383384      changepage(page => "domlist", resultmsg => "Deleted domain $dom");
    384385    } else {
    385       logaction($webvar{id}, $session->param("username"), $pargroup, "Failed to delete domain $dom ($msg)");
     386      logaction($webvar{id}, $session->param("username"), $pargroup, "Failed to delete domain $dom ($msg)")
     387        if $config{log_failures};
    386388      changepage(page => "domlist", errmsg => "Error deleting domain $dom: $msg");
    387389    }
     
    520522      if ($webvar{defrec} eq 'y') {
    521523        my $restr = "Added default record '$webvar{name} $typemap{$webvar{type}}";
    522         $restr .= " [distance $dist]" if $typemap{$webvar{type}} eq 'MX';
    523         $restr .= " [priority $dist] [weight $weight] [port $port]" if $typemap{$webvar{type}} eq 'SRV';
     524        $restr .= " [distance $webvar{distance}]" if $typemap{$webvar{type}} eq 'MX';
     525        $restr .= " [priority $webvar{distance}] [weight $webvar{weight}] [port $webvar{port}]"
     526                if $typemap{$webvar{type}} eq 'SRV';
    524527        $restr .= " $webvar{address}', TTL $webvar{ttl}";
    525528        logaction(0, $session->param("username"), $webvar{parentid}, $restr);
    526529        changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}, resultmsg => $restr);
    527530      } else {
    528         my $restr = "Added record '$webvar{name} $typemap{$webvar{type}}".
    529         $restr .= " [distance $dist]" if $typemap{$webvar{type}} eq 'MX';
    530         $restr .= " [priority $dist] [weight $weight] [port $port]" if $typemap{$webvar{type}} eq 'SRV';
     531        my $restr = "Added record '$webvar{name} $typemap{$webvar{type}}";
     532        $restr .= " [distance $webvar{dist}]" if $typemap{$webvar{type}} eq 'MX';
     533        $restr .= " [priority $webvar{dist}] [weight $webvar{weight}] [port $webvar{port}]"
     534                if $typemap{$webvar{type}} eq 'SRV';
    531535        $restr .= " $webvar{address}', TTL $webvar{ttl}";
    532536        logaction($webvar{parentid}, $session->param("username"), parentID($webvar{parentid}, 'dom', 'group'), $restr);
     
    543547      $page->param(id           => $webvar{id});
    544548      fill_recdata();   # populate the form... er, mostly.
    545       if ($webvar{defrec} eq 'y') {
    546         logaction(0, $session->param("username"), $webvar{parentid},
     549      if ($config{log_failures}) {
     550        if ($webvar{defrec} eq 'y') {
     551          logaction(0, $session->param("username"), $webvar{parentid},
    547552                "Failed adding default record '$webvar{name} $typemap{$webvar{type}} $webvar{address}', TTL $webvar{ttl} ($msg)");
    548       } else {
    549         logaction($webvar{parentid}, $session->param("username"), parentID($webvar{parentid}, 'dom', 'group'),
     553        } else {
     554          logaction($webvar{parentid}, $session->param("username"), parentID($webvar{parentid}, 'dom', 'group'),
    550555                "Failed adding record '$webvar{name} $typemap{$webvar{type}} $webvar{address}', TTL $webvar{ttl} ($msg)");
     556        }
    551557      }
    552558    }
     
    610616      $page->param(id           => $webvar{id});
    611617      fill_recdata();
    612       if ($webvar{defrec} eq 'y') {
    613         logaction(0, $session->param("username"), $webvar{parentid},
     618      if ($config{log_failures}) {
     619        if ($webvar{defrec} eq 'y') {
     620          logaction(0, $session->param("username"), $webvar{parentid},
    614621                "Failed updating default record '$typemap{$webvar{type}} $webvar{name} $webvar{address}', TTL $webvar{ttl} ($msg)");
    615       } else {
    616         logaction($webvar{parentid}, $session->param("username"), parentID($webvar{parentid}, 'dom', 'group'),
     622        } else {
     623          logaction($webvar{parentid}, $session->param("username"), parentID($webvar{parentid}, 'dom', 'group'),
    617624                "Failed updating record '$typemap{$webvar{type}} $webvar{name} $webvar{address}', TTL $webvar{ttl} ($msg)");
     625        }
    618626      }
    619627    }
     
    669677    } else {
    670678## need to find failure mode
    671       if ($webvar{defrec} eq 'y') {
    672         logaction(0, $session->param("username"), $rec->{parid},
     679      if ($config{log_failures}) {
     680        if ($webvar{defrec} eq 'y') {
     681          logaction(0, $session->param("username"), $rec->{parid},
    673682                "Failed deleting default record '$rec->{host} $typemap{$rec->{type}} $rec->{val}',".
    674683                " TTL $rec->{ttl} ($msg)");
    675       } else {
    676         logaction($rec->{parid}, $session->param("username"), parentID($rec->{parid}, 'dom', 'group'),
     684        } else {
     685          logaction($rec->{parid}, $session->param("username"), parentID($rec->{parid}, 'dom', 'group'),
    677686                "Failed deleting record '$rec->{host} $typemap{$rec->{type}} $rec->{val}', TTL $rec->{ttl} ($msg)");
     687        }
    678688      }
    679689      changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec},
     
    740750    $page->param(msg => $DBI::errstr);
    741751    fillsoa($webvar{defrec},$webvar{id});
     752##fixme: faillog
    742753  } else {
    743754
     
    820831      }
    821832    } # fallthrough else
    822     logaction(0, $session->param("username"), $webvar{pargroup}, "Failed to add group $webvar{newgroup}: $msg");
     833    logaction(0, $session->param("username"), $webvar{pargroup}, "Failed to add group $webvar{newgroup}: $msg")
     834        if $config{log_failures};
    823835    # no point in doing extra work
    824836    fill_permissions($page, \%newperms);
     
    864876    } else {
    865877# need to find failure mode
    866       logaction(0, $session->param("username"), $delparent, "Failed to delete group $deleteme: $msg");
     878      logaction(0, $session->param("username"), $delparent, "Failed to delete group $deleteme: $msg")
     879        if $config{log_failures};
    867880      changepage(page => "grpman", errmsg => "Error deleting group $deleteme: $msg");
    868881    }
     
    913926    } # fallthrough else
    914927    logaction(0, $session->param("username"), $webvar{gid}, "Failed to update default permissions in group ".
    915         groupName($dbh, $webvar{gid}).": $msg");
     928        groupName($dbh, $webvar{gid}).": $msg")
     929        if $config{log_failures};
    916930    # no point in doing extra work
    917931    fill_permissions($page, \%chperms);
     
    10021016      } else {
    10031017        logaction($webvar{$_}, $session->param("username"), parentID($webvar{$_}, 'dom', 'group'),
    1004                 "Failed to move domain ".domainName($dbh, $webvar{$_})." to group $newgname: $msg");
     1018                "Failed to move domain ".domainName($dbh, $webvar{$_})." to group $newgname: $msg")
     1019                if $config{log_failures};
    10051020      }
    10061021      $row{domerr} = $msg;
     
    10591074        $row{domok} = ($code eq 'OK');
    10601075      } else {
    1061         logaction($webvar{$_}, $session->param("username"), $pargroup, "Failed to delete domain $dom: $msg");
     1076        logaction($webvar{$_}, $session->param("username"), $pargroup, "Failed to delete domain $dom: $msg")
     1077                if $config{log_failures};
    10621078      }
    10631079      $row{domerr} = $msg;
     
    12511267      fill_clonemelist();
    12521268      logaction(0, $session->param("username"), $curgroup, "Failed to $webvar{action} user ".
    1253         "$webvar{uname}: $msg");
     1269        "$webvar{uname}: $msg")
     1270        if $config{log_failures};
    12541271    }
    12551272
     
    13301347      list_users($curgroup);
    13311348      logaction(0, $session->param("username"), $curgroup, "Failed to delete user ".
    1332         "$webvar{id}/".$userref->{username}.": $msg");
     1349        "$webvar{id}/".$userref->{username}.": $msg")
     1350        if $config{log_failures};
    13331351    }
    13341352  } else {
Note: See TracChangeset for help on using the changeset viewer.