Permalink
Browse files

Updating webperl classes to use Logger rather than Logging.

  • Loading branch information...
1 parent 9462b34 commit bf644e43f48bacad22031226b70fbe04ef39d6a8 @TheWatcher committed Apr 12, 2012
Showing with 73 additions and 78 deletions.
  1. +8 −6 AppUser.pm
  2. +23 −16 Application.pm
  3. +8 −4 Auth.pm
  4. +7 −7 AuthMethods.pm
  5. +12 −30 Block.pm
  6. +6 −6 Modules.pm
  7. +3 −6 SessionHandler.pm
  8. +2 −3 Template.pm
  9. +4 −0 mdfiles/blocks.md
View
@@ -49,7 +49,6 @@
package AppUser;
use strict;
-use Logging qw(die_log);
use constant ANONYMOUS_ID => 1; # Default anonymous user id.
use constant ADMIN_TYPE => 3; # User type for admin users.
@@ -74,7 +73,7 @@ sub new {
}
-## @method $ init($cgi, $dbh, $settings)
+## @method $ init($cgi, $dbh, $settings, $logger)
# Initialise the AppUser's references to other system objects. This allows the
# setup of the object to be deferred from construction. If the cgi, dbh, and
# settings objects have been passed into new(), calling this function is not
@@ -83,18 +82,21 @@ sub new {
# @param cgi A reference to the system-wide cgi object.
# @param dbh A reference to the system DBI object.
# @param settings A reference to the global settings.
+# @param logger A reference to the logger object.
# @return undef on success, otherwise an error message
sub init {
my $self = shift;
$self -> {"cgi"} = shift;
$self -> {"dbh"} = shift;
$self -> {"settings"} = shift;
+ $self -> {"logger"} = shift;
# Check things are set.
return "cgi object not set" unless($self -> {"cgi"});
return "dbh object not set" unless($self -> {"dbh"});
return "settings object not set" unless($self -> {"settings"});
+ return "logger object not set" unless($self -> {"logger"});
# All good, return nothing...
return undef;
@@ -221,7 +223,7 @@ sub set_user_authmethod {
SET user_auth = ?
WHERE username LIKE ?");
my $result = $seth -> execute($methodid, $username)
- or die_log($self -> {"cgi"} -> remote_host(), "Unable to execute user auth update query. Error was: ".$self -> {"dbh"} -> errstr);
+ or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "Unable to execute user auth update query. Error was: ".$self -> {"dbh"} -> errstr);
$self -> {"lasterr"} .= "Unable to update user auth method, unkown user selected"
if($result != 1);
@@ -287,7 +289,7 @@ sub post_authenticate {
(username, created, last_login)
VALUES(?, UNIX_TIMESTAMP(), UNIX_TIMESTAMP())");
$newuser -> execute($username)
- or die_log($self -> {"cgi"} -> remote_host(), "FATAL: Unable to create new user record: ".$self -> {"dbh"} -> errstr);
+ or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "FATAL: Unable to create new user record: ".$self -> {"dbh"} -> errstr);
$user = $self -> get_user($username);
}
@@ -302,7 +304,7 @@ sub post_authenticate {
SET last_login = UNIX_TIMESTAMP()
WHERE user_id = ?");
$pokeh -> execute($user -> {"user_id"})
- or die_log($self -> {"cgi"} -> remote_host(), "FATAL: Unable to update user record: ".$self -> {"dbh"} -> errstr);
+ or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "FATAL: Unable to update user record: ".$self -> {"dbh"} -> errstr);
# All done...
return $user;
@@ -337,7 +339,7 @@ sub _get_user {
WHERE $field ".($uselike ? "LIKE" : "=")." ?".
($onlyreal ? " AND user_type IN (0,3)" : ""));
$userh -> execute($value)
- or die_log($self -> {"cgi"} -> remote_host(), "Unable to execute user lookup query. Error was: ".$self -> {"dbh"} -> errstr);
+ or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "Unable to execute user lookup query. Error was: ".$self -> {"dbh"} -> errstr);
return $userh -> fetchrow_hashref();
}
View
@@ -49,7 +49,7 @@ use Time::HiRes qw(time);
# Webperl modules
use Auth;
use ConfigMicro;
-use Logging qw(start_log end_log die_log);
+use Logger;
use Template;
use SessionHandler;
use Modules;
@@ -105,9 +105,12 @@ sub run {
$self -> {"starttime"} = time();
+ $self -> {"logger"} = Logger -> new()
+ or die "FATAL: Unable to create logger object";
+
# Load the system config
$self -> {"settings"} = ConfigMicro -> new($self -> {"config"})
- or die_log("Not avilable", "Application: Unable to obtain configuration file: ".$ConfigMicro::errstr);
+ or $self -> {"logger"} -> die_log("Not avilable", "Application: Unable to obtain configuration file: ".$ConfigMicro::errstr);
# Create a new CGI object to generate page content through
$self -> {"cgi"} = $self -> load_cgi($self -> {"settings"} -> {"setup"} -> {"disable_compression"});
@@ -117,54 +120,57 @@ sub run {
$self -> {"settings"} -> {"database"} -> {"username"},
$self -> {"settings"} -> {"database"} -> {"password"},
{ RaiseError => 0, AutoCommit => 1, mysql_enable_utf8 => 1 })
- or die_log($self -> {"cgi"} -> remote_host(), "Application: Unable to connect to database: ".$DBI::errstr);
+ or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "Application: Unable to connect to database: ".$DBI::errstr);
# Pull configuration data out of the database into the settings hash
$self -> {"settings"} -> load_db_config($self -> {"dbh"}, $self -> {"settings"} -> {"database"} -> {"settings"});
# Start doing logging if needed
- start_log($self -> {"settings"} -> {"config"} -> {"logfile"}) if($self -> {"settings"} -> {"config"} -> {"logfile"});
+ $self -> {"logger"} -> start_log($self -> {"settings"} -> {"config"} -> {"logfile"}) if($self -> {"settings"} -> {"config"} -> {"logfile"});
# Create the template handler object
- $self -> {"template"} = Template -> new(basedir => path_join($self -> {"settings"} -> {"config"} -> {"base"}, "templates"),
+ $self -> {"template"} = Template -> new(logger => $self -> {"logger"},
+ basedir => path_join($self -> {"settings"} -> {"config"} -> {"base"}, "templates"),
timefmt => $self -> {"settings"} -> {"config"} -> {"timefmt"},
blockname => 1,
mailcmd => '/usr/sbin/sendmail -t -f '.$self -> {"settings"} -> {"config"} -> {"Core:envelope_address"})
- or die_log($self -> {"cgi"} -> remote_host(), "Application: Unable to create template handling object: ".$Template::errstr);
+ or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "Application: Unable to create template handling object: ".$Template::errstr);
# If phpbb mode is enabled, it takes over auth.
if($self -> {"use_phpbb"}) {
load phpBB3;
- $self -> {"phpbb"} = phpBB3 -> new(prefix => $self -> {"settings"} -> {"database"} -> {"phpbb_prefix"},
+ $self -> {"phpbb"} = phpBB3 -> new(logger => $self -> {"logger"},
+ prefix => $self -> {"settings"} -> {"database"} -> {"phpbb_prefix"},
cgi => $self -> {"cgi"},
data_src => $self -> {"settings"} -> {"database"} -> {"phpbb_database"},
username => $self -> {"settings"} -> {"database"} -> {"phpbb_username"},
password => $self -> {"settings"} -> {"database"} -> {"phpbb_password"},
codepath => path_join($self -> {"settings"} -> {"config"} -> {"base"}, "templates", "default"),
url => $self -> {"settings"} -> {"config"} -> {"forumurl"})
- or die_log($self -> {"cgi"} -> remote_host(), "Unable to create phpbb object: ".$phpBB3::errstr);
+ or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "Unable to create phpbb object: ".$phpBB3::errstr);
$self -> {"auth"} = $self -> {"phpbb"};
# phpBB3 is not enabled, initialise the auth modules.
} else {
# Initialise the appuser object
- $self -> {"appuser"} -> init($self -> {"cgi"}, $self -> {"dbh"}, $self -> {"settings"});
+ $self -> {"appuser"} -> init($self -> {"cgi"}, $self -> {"dbh"}, $self -> {"settings"}, $self -> {"logger"});
# If the auth object is not set, make one
$self -> {"auth"} = Auth -> new() if(!$self -> {"auth"});
# Initialise the auth object
- $self -> {"auth"} -> init($self -> {"cgi"}, $self -> {"dbh"}, $self -> {"appuser"}, $self -> {"settings"});
+ $self -> {"auth"} -> init($self -> {"cgi"}, $self -> {"dbh"}, $self -> {"appuser"}, $self -> {"settings"}, $self -> {"logger"});
}
# Start the session engine...
- $self -> {"session"} = SessionHandler -> new(cgi => $self -> {"cgi"},
+ $self -> {"session"} = SessionHandler -> new(logger => $self -> {"logger"},
+ cgi => $self -> {"cgi"},
dbh => $self -> {"dbh"},
auth => $self -> {"auth"},
template => $self -> {"template"},
settings => $self -> {"settings"})
- or die_log($self -> {"cgi"} -> remote_host(), "Application: Unable to create session object: ".$SessionHandler::errstr);
+ or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "Application: Unable to create session object: ".$SessionHandler::errstr);
# At this point, there's potentially a real user associated with the session. If appropriate,
# update the template theme and language
@@ -181,23 +187,24 @@ sub run {
}
# And now we can make the module handler
- $self -> {"modules"} = Modules -> new(cgi => $self -> {"cgi"},
+ $self -> {"modules"} = Modules -> new(logger => $self -> {"logger"},
+ cgi => $self -> {"cgi"},
dbh => $self -> {"dbh"},
settings => $self -> {"settings"},
template => $self -> {"template"},
session => $self -> {"session"},
phpbb => $self -> {"phpbb"}, # this will handily be undef if phpbb mode is disabled
blockdir => $self -> {"settings"} -> {"paths"} -> {"blocks"} || "blocks",
logtable => $self -> {"settings"} -> {"database"} -> {"logging"})
- or die_log($self -> {"cgi"} -> remote_host(), "Application: Unable to create module handling object: ".$Modules::errstr);
+ or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "Application: Unable to create module handling object: ".$Modules::errstr);
# Obtain the page moduleid, fall back on the default if this fails
my $pageblock = $self -> {"cgi"} -> param("block");
$pageblock = $self -> {"settings"} -> {"config"} -> {"default_block"} if(!$pageblock); # This ensures $pageblock is defined and non-zero
# Obtain an instance of the page module
my $pageobj = $self -> {"modules"} -> new_module($pageblock)
- or die_log($self -> {"cgi"} -> remote_host(), "Application: Unable to load page module $pageblock: ".$self -> {"modules"} -> {"errstr"});
+ or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "Application: Unable to load page module $pageblock: ".$self -> {"modules"} -> {"errstr"});
# And call the page generation function of the page module
my $content = $pageobj -> page_display();
@@ -220,7 +227,7 @@ sub run {
$self -> {"template"} -> set_module_obj(undef);
$self -> {"dbh"} -> disconnect();
- end_log();
+ $self -> {"logger"} -> end_log();
}
View
12 Auth.pm
@@ -52,6 +52,7 @@ BEGIN {
# - dbh, a reference to the DBI object to issue database queries through.
# - settings, a reference to the global settings object.
# - app, a reference to a AppUser object to perform user-related db queries through.
+# - logger, a reference to a Logger object.
#
# @param args A hash of key, value pairs to initialise the object with.
# @return A reference to a new Auth object on success, undef on failure.
@@ -66,7 +67,7 @@ sub new {
}
-## @method $ init($cgi, $dbh, $app, $settings)
+## @method $ init($cgi, $dbh, $app, $settings, $logger)
# Initialise the Auth's references to other system objects. This allows the
# setup of the object to be deferred from construction. If the cgi, dbh, app,
# and settings objects have been passed into new(), calling this function is
@@ -84,18 +85,21 @@ sub init {
$self -> {"dbh"} = shift;
$self -> {"app"} = shift;
$self -> {"settings"} = shift;
+ $self -> {"logger"} = shift;
# Ensure that we have objects that we need
return "cgi object not set" unless($self -> {"cgi"});
return "dbh object not set" unless($self -> {"dbh"});
return "settings object not set" unless($self -> {"settings"});
return "app object not set" unless($self -> {"app"});
+ return "logger object not set" unless($self -> {"logger"});
# Create the authmethods object to handle invocation of individual methods
$self -> {"methods"} = AuthMethods -> new(cgi => $self -> {"cgi"},
dbh => $self -> {"dbh"},
settings => $self -> {"settings"},
- app => $self -> {"app"})
+ app => $self -> {"app"},
+ logger => $self -> {"logger"})
or return "Unable to create AuthMethods object: ".$AuthMethods::errstr;
$self -> {"ANONYMOUS"} = $self -> {"app"} -> anonymous_user();
@@ -141,7 +145,7 @@ sub unique_id {
# Ask urandom for some randomness to combat potential problems with the above non-atomicity
my $buffer;
open(RND, "/dev/urandom")
- or die_log($self -> {"cgi"} -> remote_host(), "Unable to open urandom: $!");
+ or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "Unable to open urandom: $!");
read(RND, $buffer, 24);
close(RND);
@@ -222,7 +226,7 @@ sub valid_user {
if(!$valid && (!$authmethod || !$methodimpl || $self -> {"settings"} -> {"Auth:enable_fallback"})) {
foreach my $trymethod (@{$methods}) {
my $methodimpl = $self -> {"methods"} -> load_method($trymethod)
- or die_log($self -> {"cgi"} -> remote_host(), "Auth implementation load failed: ".$self -> {"methods"} -> {"errstr"});
+ or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "Auth implementation load failed: ".$self -> {"methods"} -> {"errstr"});
$valid = $methodimpl -> authenticate($username, $password, $self);
View
@@ -26,7 +26,6 @@ package AuthMethods;
use strict;
use Module::Load;
-use Logging qw(die_log);
our $errstr;
@@ -51,10 +50,11 @@ sub new {
};
# Ensure that we have objects that we need
- return set_error("cgi object not set") unless($self -> {"cgi"});
- return set_error("dbh object not set") unless($self -> {"dbh"});
+ return set_error("cgi object not set") unless($self -> {"cgi"});
+ return set_error("dbh object not set") unless($self -> {"dbh"});
return set_error("settings object not set") unless($self -> {"settings"});
- return set_error("app object not set") unless($self -> {"app"});
+ return set_error("app object not set") unless($self -> {"app"});
+ return set_error("logger object not set") unless($self -> {"logger"});
return bless $self, $class;
}
@@ -80,7 +80,7 @@ sub available_methods {
($only_active ? " WHERE enabled = 1 " : " ").
"ORDER BY priority ASC");
$methodh -> execute()
- or die_log($self -> {"cgi"} -> remote_host(), "Unable to execute auth method list query: ".$self -> {"dbh"} -> errstr);
+ or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "Unable to execute auth method list query: ".$self -> {"dbh"} -> errstr);
my @methods;
while(my $method = $methodh -> fetchrow_arrayref()) {
@@ -113,7 +113,7 @@ sub load_method {
my $moduleh = $self -> {"dbh"} -> prepare("SELECT perl_module, enabled FROM ".$self -> {"settings"} -> {"database"} -> {"auth_methods"}."
WHERE id = ?");
$moduleh -> execute($method_id)
- or die_log($self -> {"cgi"} -> remote_host(), "Unable to execute auth method lookup query: ".$self -> {"dbh"} -> errstr);
+ or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "Unable to execute auth method lookup query: ".$self -> {"dbh"} -> errstr);
my $module = $moduleh -> fetchrow_hashref();
return $self -> self_error("Unknown auth method requested in load_method($method_id)") if(!$module);
@@ -125,7 +125,7 @@ sub load_method {
my $paramh = $self -> {"dbh"} -> prepare("SELECT name, value FROM ".$self -> {"settings"} -> {"database"} -> {"auth_params"}."
WHERE method_id = ?");
$paramh -> execute($method_id)
- or die_log($self -> {"cgi"} -> remote_host(), "Unable to execute auth method parameter query: ".$self -> {"dbh"} -> errstr);
+ or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "Unable to execute auth method parameter query: ".$self -> {"dbh"} -> errstr);
# Build up a settings hash using the standard objects, and settings for the
# module loaded from the database.
Oops, something went wrong.

0 comments on commit bf644e4

Please sign in to comment.