Updating webperl classes to use Logger rather than Logging.
This commit is contained in:
parent
9462b34a02
commit
bf644e43f4
14
AppUser.pm
14
AppUser.pm
@ -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,6 +82,7 @@ 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;
|
||||
@ -90,11 +90,13 @@ sub init {
|
||||
$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();
|
||||
}
|
||||
|
@ -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,7 +187,8 @@ 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"},
|
||||
@ -189,7 +196,7 @@ sub run {
|
||||
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");
|
||||
@ -197,7 +204,7 @@ sub run {
|
||||
|
||||
# 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();
|
||||
}
|
||||
|
||||
|
||||
|
12
Auth.pm
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);
|
||||
|
||||
|
@ -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.
|
||||
|
42
Block.pm
42
Block.pm
@ -37,13 +37,6 @@ use Encode;
|
||||
use HTML::Entities;
|
||||
use strict;
|
||||
|
||||
# Globals within this and available to subclasses
|
||||
our $errstr;
|
||||
|
||||
BEGIN {
|
||||
$errstr = '';
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Constructor
|
||||
|
||||
@ -52,16 +45,17 @@ BEGIN {
|
||||
# args are optional, all the remaining arguments must be provided. The arguments should be
|
||||
# a hash of parameters, valid key names are:
|
||||
#
|
||||
# modid The module id set for the block module's entry in the database.
|
||||
# args Any arguments passed to the plugin at runtime, usually pulled from the database.
|
||||
# cgi A reference to the script's CGI object.
|
||||
# dbh A database handle to talk to the database through.
|
||||
# phpbb A phpbb3 handle object used to perform operations on a phpbb3 database.
|
||||
# template A template engine module object to load templates through.
|
||||
# settings The global configuration hashref.
|
||||
# session A reference to the current session object
|
||||
# module The module handler object, used to load other blocks on demand.
|
||||
# logtable A string containing the name of the table to use for logging. See the log() function.
|
||||
# - `modid` The module id set for the block module's entry in the database.
|
||||
# - `args` Any arguments passed to the plugin at runtime, usually pulled from the database.
|
||||
# - `cgi` A reference to the script's CGI object.
|
||||
# - `dbh` A database handle to talk to the database through.
|
||||
# - `phpbb` A phpbb3 handle object used to perform operations on a phpbb3 database.
|
||||
# - `template` A template engine module object to load templates through.
|
||||
# - `settings` The global configuration hashref.
|
||||
# - `session` A reference to the current session object
|
||||
# - `module` The module handler object, used to load other blocks on demand.
|
||||
# - `logtable` A string containing the name of the table to use for logging. See the log() function.
|
||||
# - `logger` A reference to a logger object.
|
||||
#
|
||||
# @param args A hash containing key/value pairs used to set up the module.
|
||||
# @return A newly created Block object.
|
||||
@ -395,7 +389,7 @@ sub log {
|
||||
(logtime, user_id, ipaddr, logtype, logdata)
|
||||
VALUES(UNIX_TIMESTAMP(), ?, ?, ?, ?)");
|
||||
$eventh -> execute($userid, $self -> {"cgi"} -> remote_addr(), $type, $data)
|
||||
or die_log($self -> {"cgi"} -> remote_host(), "FATAL: Unable to insert log entry for $userid ('$type', '$data')");
|
||||
or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "FATAL: Unable to insert log entry for $userid ('$type', '$data')");
|
||||
}
|
||||
|
||||
|
||||
@ -448,16 +442,4 @@ sub page_display {
|
||||
return "<p class=\"error\">".$self -> {"template"} -> replace_langvar("BLOCK_PAGE_DISPLAY")."</p>";
|
||||
}
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# Internal
|
||||
|
||||
## @fn $ set_error($errstr)
|
||||
# Set a class error string. This will always return undef, and can be used to
|
||||
# set an error message and return undef at the same time.
|
||||
#
|
||||
# @param errstr The error to store in the global errstr variable.
|
||||
# @return undef, always.
|
||||
sub set_error { $errstr = shift; return undef; }
|
||||
|
||||
1;
|
||||
|
12
Modules.pm
12
Modules.pm
@ -34,6 +34,7 @@
|
||||
# * template - The system template object.
|
||||
# * session - The session object.
|
||||
# * module - The Modules object that loaded the new module.
|
||||
# * logger - The system logger object.
|
||||
#
|
||||
# However, when calling a loaded module's new() function, this class will
|
||||
# copy the entirity of its $self variable into the argument list, so any
|
||||
@ -56,7 +57,6 @@ package Modules;
|
||||
|
||||
use DBI;
|
||||
use Module::Load;
|
||||
use Logging qw(die_log);
|
||||
use strict;
|
||||
|
||||
our $errstr;
|
||||
@ -171,7 +171,7 @@ sub new_module {
|
||||
my $sth = $self -> {"dbh"} -> prepare("SELECT * FROM ".$self -> {"settings"} -> {"database"} -> {"blocks"}."
|
||||
WHERE $mode");
|
||||
$sth -> execute($arg) or
|
||||
die_log($self -> {"cgi"} -> remote_host(), "new_module: Unable to execute query: ". $self -> {"dbh"} -> errstr);
|
||||
$self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "new_module: Unable to execute query: ". $self -> {"dbh"} -> errstr);
|
||||
|
||||
my $modrow = $sth -> fetchrow_hashref();
|
||||
|
||||
@ -198,7 +198,7 @@ sub new_module_byblockid {
|
||||
my $sth = $self -> {"dbh"} -> prepare("SELECT * FROM ".$self -> {"settings"} -> {"database"} -> {"blocks"}."
|
||||
WHERE id = ?");
|
||||
$sth -> execute($blockid) or
|
||||
die_log($self -> {"cgi"} -> remote_host(), "new_module_byblockid: Unable to execute query: ". $self -> {"dbh"} -> errstr);
|
||||
$self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "new_module_byblockid: Unable to execute query: ". $self -> {"dbh"} -> errstr);
|
||||
|
||||
my $modrow = $sth -> fetchrow_hashref();
|
||||
|
||||
@ -271,7 +271,7 @@ sub _new_module_internal {
|
||||
|
||||
my $modh = $self -> {"dbh"} -> prepare("SELECT * FROM ".$self -> {"settings"} -> {"database"} -> {"modules"}." $where");
|
||||
$modh -> execute($argument)
|
||||
or die_log($self -> {"cgi"} -> remote_host(), "Unable to execute module resolve query: ".$self -> {"dbh"} -> errstr);
|
||||
or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "Unable to execute module resolve query: ".$self -> {"dbh"} -> errstr);
|
||||
|
||||
my $modrow = $modh -> fetchrow_hashref();
|
||||
|
||||
@ -353,7 +353,7 @@ sub build_sidebar {
|
||||
WHERE TYPE = ? AND $filter
|
||||
ORDER BY position");
|
||||
$sth -> execute($side, $page) or
|
||||
die_log($self -> {"cgi"} -> remote_host(), "build_sidebar: Unable to execute query: ". $self -> {"dbh"} -> errstr);
|
||||
$self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "build_sidebar: Unable to execute query: ". $self -> {"dbh"} -> errstr);
|
||||
|
||||
my $result = "";
|
||||
while(my $row = $sth -> fetchrow_hashref()) {
|
||||
@ -386,7 +386,7 @@ sub get_block_id {
|
||||
my $blockh = $self -> {"dbh"} -> prepare("SELECT id FROM ".$self -> {"settings"} -> {"database"} -> {"blocks"}."
|
||||
WHERE name LIKE ?");
|
||||
$blockh -> execute($blockname)
|
||||
or die_log($self -> {"cgi"} -> remote_host(), "get_block_id: Unable to execute query: ". $self -> {"dbh"} -> errstr);
|
||||
or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "get_block_id: Unable to execute query: ". $self -> {"dbh"} -> errstr);
|
||||
|
||||
# Do we have the block?
|
||||
my $blockr = $blockh -> fetchrow_arrayref();
|
||||
|
@ -127,9 +127,6 @@ use MIME::Base64;
|
||||
|
||||
use Data::Dumper;
|
||||
|
||||
# Custom module imports
|
||||
use Logging qw(die_log);
|
||||
|
||||
# Globals...
|
||||
our $errstr;
|
||||
|
||||
@ -697,7 +694,7 @@ sub touch_session {
|
||||
" SET session_time = ?
|
||||
WHERE session_id = ?");
|
||||
$finger -> execute($self -> {"session_time"}, $session -> {"session_id"})
|
||||
or die_log($self -> {"cgi"} -> remote_host(), "Unable to touch session. Error was: ".$self -> {"dbh"} -> errstr);
|
||||
or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "Unable to touch session. Error was: ".$self -> {"dbh"} -> errstr);
|
||||
}
|
||||
}
|
||||
|
||||
@ -716,14 +713,14 @@ sub set_login_key {
|
||||
my $keyh = $self -> {"dbh"} -> prepare("INSERT INTO ".$self -> {"settings"} -> {"database"} -> {"keys"}.
|
||||
" VALUES(?, ?, ?, ?)");
|
||||
$keyh -> execute(md5_hex($key_id), $self -> {"sessuser"}, $ENV{REMOTE_ADDR}, time())
|
||||
or die_log($self -> {"cgi"} -> remote_host(), "Unable to create autologin key. Error was: ".$self -> {"dbh"} -> errstr);
|
||||
or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "Unable to create autologin key. Error was: ".$self -> {"dbh"} -> errstr);
|
||||
|
||||
# If we have a key, we want to overwrite it with the new stuff
|
||||
} else {
|
||||
my $keyh = $self -> {"dbh"} -> prepare("UPDATE ".$self -> {"settings"} -> {"database"} -> {"keys"}.
|
||||
" SET key_id = ?, last_ip = ?, last_login = ? WHERE user_id = ? AND key_id = ?");
|
||||
$keyh -> execute(md5_hex($key_id), $ENV{REMOTE_ADDR}, 0 + time(), 0 + $self -> {"sessuser"}, md5_hex($key))
|
||||
or die_log($self -> {"cgi"} -> remote_host(), "Unable to update autologin key. Error was: ".$self -> {"dbh"} -> errstr);
|
||||
or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "Unable to update autologin key. Error was: ".$self -> {"dbh"} -> errstr);
|
||||
}
|
||||
|
||||
$self -> {"autokey"} = $key_id;
|
||||
|
@ -99,7 +99,6 @@
|
||||
# ... href="index.cgi?block={B_[somename]}...etc...
|
||||
package Template;
|
||||
|
||||
use Logging;
|
||||
use POSIX qw(strftime);
|
||||
use Utils qw(path_join superchomp);
|
||||
use strict;
|
||||
@ -279,7 +278,7 @@ sub load_language {
|
||||
$value =~ s/\\\"/\"/go;
|
||||
|
||||
# warn if we are about to redefine a word
|
||||
warn_log("Unknown", "$key already exists in language hash!")
|
||||
$self -> {"logger"} -> warn_log("Unknown", "$key already exists in language hash!")
|
||||
if($self -> {"words"} -> {$key} && !$force_overwrite);
|
||||
|
||||
$self -> {"words"} -> {$key} = $value;
|
||||
@ -287,7 +286,7 @@ sub load_language {
|
||||
|
||||
close(WORDFILE);
|
||||
} else {
|
||||
warn_log("Unknown", "Unable to open language file $filename: $!");
|
||||
$self -> {"logger"} -> warn_log("Unknown", "Unable to open language file $filename: $!");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,10 @@ database, issue queries through this rather than creating a separate
|
||||
connection if possible.
|
||||
* `$self -> {"session"}` is a reference to the current SessionHandler object. See
|
||||
the [Sessions](@ref sessions) documentation for more about this.
|
||||
* `$self -> {"logger"}` is the global Logger object. You can use this to call
|
||||
Logger functions (note that this is distinct from the Block::log() function -
|
||||
the latter is intended to do database logging of normal user actions, while
|
||||
Logger is for recording warnings and exceptional circumstances in the system.
|
||||
|
||||
Each Block subclass also has access to a few values that can be useful:
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user