proper logging
This commit is contained in:
parent
96c3cf73e5
commit
694200d9f8
11 changed files with 117 additions and 21 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -26,6 +26,7 @@ ext/home
|
||||||
ext/image_hash_ban
|
ext/image_hash_ban
|
||||||
ext/ipban
|
ext/ipban
|
||||||
ext/link_image
|
ext/link_image
|
||||||
|
ext/log_db
|
||||||
ext/news
|
ext/news
|
||||||
ext/notes
|
ext/notes
|
||||||
ext/notes
|
ext/notes
|
||||||
|
|
66
contrib/log_db/main.php
Normal file
66
contrib/log_db/main.php
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Name: Logging (Database)
|
||||||
|
* Author: Shish
|
||||||
|
* Description: Keep a record of SCore events
|
||||||
|
*/
|
||||||
|
|
||||||
|
class LogDatabase extends SimpleExtension {
|
||||||
|
public function onInitExt($event) {
|
||||||
|
global $database;
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
if($config->get_int("ext_log_database_version") < 1) {
|
||||||
|
$database->create_table("score_log", "
|
||||||
|
id SCORE_AIPK,
|
||||||
|
date_sent DATETIME NOT NULL,
|
||||||
|
section VARCHAR(32) NOT NULL,
|
||||||
|
username VARCHAR(32) NOT NULL,
|
||||||
|
address SCORE_INET NOT NULL,
|
||||||
|
priority INT NOT NULL,
|
||||||
|
message TEXT NOT NULL,
|
||||||
|
INDEX(section)
|
||||||
|
");
|
||||||
|
$config->set_int("ext_log_database_version", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$config->set_default_int("log_db_priority", SCORE_LOG_INFO);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onSetupBuilding($event) {
|
||||||
|
$sb = new SetupBlock("Logging (Database)");
|
||||||
|
$sb->add_choice_option("log_db_priority", array(
|
||||||
|
"Debug" => SCORE_LOG_DEBUG,
|
||||||
|
"Info" => SCORE_LOG_INFO,
|
||||||
|
"Warning" => SCORE_LOG_WARNING,
|
||||||
|
"Error" => SCORE_LOG_ERROR,
|
||||||
|
"Critical" => SCORE_LOG_CRITICAL,
|
||||||
|
), "Debug Level: ");
|
||||||
|
$event->panel->add_block($sb);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onPageRequest($event) {
|
||||||
|
global $database, $user;
|
||||||
|
if($event->page_matches("log/view")) {
|
||||||
|
if($user->is_admin()) {
|
||||||
|
$events = $database->get_all("SELECT * FROM score_log");
|
||||||
|
$this->theme->display_events($events);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onUserBlockBuilding($event) {
|
||||||
|
$event->add_link("Event Log", make_link("log/view"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onLog($event) {
|
||||||
|
global $config, $database, $user;
|
||||||
|
if($event->priority >= $config->get_int("log_db_priority")) {
|
||||||
|
$database->execute("
|
||||||
|
INSERT INTO score_log(date_sent, section, priority, username, address, message)
|
||||||
|
VALUES(now(), ?, ?, ?, ?, ?)
|
||||||
|
", array($event->section, $event->priority, $user->name, $_SERVER['REMOTE_ADDR'], $event->message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
8
contrib/log_db/test.php
Normal file
8
contrib/log_db/test.php
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?php
|
||||||
|
class LogDatabaseTest extends SCoreWebTestCase {
|
||||||
|
function testLog() {
|
||||||
|
$this->log_in_as_admin();
|
||||||
|
$this->log_out();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
27
contrib/log_db/theme.php
Normal file
27
contrib/log_db/theme.php
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class LogDatabaseTheme extends Themelet {
|
||||||
|
public function display_events($events) {
|
||||||
|
$table = "<table class='zebra'>";
|
||||||
|
$table .= "<thead><th>Time</th><th>Module / Priority</th><th>Username / Address</th><th>Message</th></thead>";
|
||||||
|
$table .= "<tbody>";
|
||||||
|
$n = 0;
|
||||||
|
foreach($events as $event) {
|
||||||
|
$oe = ($n++ % 2 == 0) ? "even" : "odd";
|
||||||
|
$table .= "<tr class='$oe'>";
|
||||||
|
$table .= "<td>".$event['date_sent']."</td>";
|
||||||
|
$table .= "<td>".$event['section']." / ".$event['priority']."</td>";
|
||||||
|
$table .= "<td>".html_escape($event['username'])." / ".$event['address']."</td>";
|
||||||
|
$table .= "<td>".html_escape($event['message'])."</td>";
|
||||||
|
$table .= "</tr>";
|
||||||
|
}
|
||||||
|
$table .= "</tbody></table>";
|
||||||
|
|
||||||
|
global $page;
|
||||||
|
$page->set_title("Event Log");
|
||||||
|
$page->set_heading("Event Log");
|
||||||
|
$page->add_block(new NavBlock());
|
||||||
|
$page->add_block(new Block("Events", $table));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
|
@ -139,17 +139,6 @@ class LogEvent extends Event {
|
||||||
$this->priority = $priority;
|
$this->priority = $priority;
|
||||||
$this->message = $message;
|
$this->message = $message;
|
||||||
$this->time = time();
|
$this->time = time();
|
||||||
|
|
||||||
// this should be an extension
|
|
||||||
if(defined("X-HALFASSED-LOGGING")) {
|
|
||||||
global $user;
|
|
||||||
$ftime = date("Y-m-d H:i:s", $this->time);
|
|
||||||
$username = $user->name;
|
|
||||||
$ip = $_SERVER['REMOTE_ADDR'];
|
|
||||||
$fp = fopen("shimmie.log", "a");
|
|
||||||
fputs($fp, "$ftime\t$section/$priority\t$username/$ip\t$message\n");
|
|
||||||
fclose($fp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -406,12 +406,12 @@ function format_text($string) {
|
||||||
* Logging convenience *
|
* Logging convenience *
|
||||||
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
if(!defined("LOG_CRITICAL")) define("LOG_CRITICAL", 50);
|
define("SCORE_LOG_CRITICAL", 50);
|
||||||
if(!defined("LOG_ERROR")) define("LOG_ERROR", 40);
|
define("SCORE_LOG_ERROR", 40);
|
||||||
if(!defined("LOG_WARNING")) define("LOG_WARNING", 30);
|
define("SCORE_LOG_WARNING", 30);
|
||||||
if(!defined("LOG_INFO")) define("LOG_INFO", 20);
|
define("SCORE_LOG_INFO", 20);
|
||||||
if(!defined("LOG_DEBUG")) define("LOG_DEBUG", 10);
|
define("SCORE_LOG_DEBUG", 10);
|
||||||
if(!defined("LOG_NOTSET")) define("LOG_NOTSET", 0);
|
define("SCORE_LOG_NOTSET", 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A shorthand way to send a LogEvent
|
* A shorthand way to send a LogEvent
|
||||||
|
@ -424,14 +424,14 @@ function log_msg($section, $priority, $message) {
|
||||||
* A shorthand way to send a LogEvent
|
* A shorthand way to send a LogEvent
|
||||||
*/
|
*/
|
||||||
function log_info($section, $message) {
|
function log_info($section, $message) {
|
||||||
log_msg($section, LOG_INFO, $message);
|
log_msg($section, SCORE_LOG_INFO, $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A shorthand way to send a LogEvent
|
* A shorthand way to send a LogEvent
|
||||||
*/
|
*/
|
||||||
function log_error($section, $message) {
|
function log_error($section, $message) {
|
||||||
log_msg($section, LOG_ERROR, $message);
|
log_msg($section, SCORE_LOG_ERROR, $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ class AliasEditor implements Extension {
|
||||||
if($user->is_admin()) {
|
if($user->is_admin()) {
|
||||||
if(isset($_POST['oldtag'])) {
|
if(isset($_POST['oldtag'])) {
|
||||||
$database->Execute("DELETE FROM aliases WHERE oldtag=?", array($_POST['oldtag']));
|
$database->Execute("DELETE FROM aliases WHERE oldtag=?", array($_POST['oldtag']));
|
||||||
|
log_info("alias_editor", "Deleted alias for ".$_POST['oldtag']);
|
||||||
|
|
||||||
$page->set_mode("redirect");
|
$page->set_mode("redirect");
|
||||||
$page->set_redirect(make_link("alias/list"));
|
$page->set_redirect(make_link("alias/list"));
|
||||||
|
@ -102,6 +103,7 @@ class AliasEditor implements Extension {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$database->Execute("INSERT INTO aliases(oldtag, newtag) VALUES(?, ?)", $pair);
|
$database->Execute("INSERT INTO aliases(oldtag, newtag) VALUES(?, ?)", $pair);
|
||||||
|
log_info("alias_editor", "Added alias for {$event->oldtag} -> {$event->newtag}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -444,7 +444,7 @@ class CommentList extends SimpleExtension {
|
||||||
"VALUES(?, ?, ?, now(), ?)",
|
"VALUES(?, ?, ?, now(), ?)",
|
||||||
array($image_id, $user->id, $_SERVER['REMOTE_ADDR'], $comment));
|
array($image_id, $user->id, $_SERVER['REMOTE_ADDR'], $comment));
|
||||||
$cid = $database->db->Insert_ID();
|
$cid = $database->db->Insert_ID();
|
||||||
log_info("comment", "Comment #$cid added");
|
log_info("comment", "Comment #$cid added to Image #$image_id");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// }}}
|
// }}}
|
||||||
|
|
|
@ -141,12 +141,14 @@ class ExtManager extends SimpleExtension {
|
||||||
else {
|
else {
|
||||||
full_copy("contrib/$fname", "ext/$fname");
|
full_copy("contrib/$fname", "ext/$fname");
|
||||||
}
|
}
|
||||||
|
log_info("ext_manager", "Enabling $fname");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// disable if currently enabled
|
// disable if currently enabled
|
||||||
if(file_exists("ext/$fname")) {
|
if(file_exists("ext/$fname")) {
|
||||||
deltree("ext/$fname");
|
deltree("ext/$fname");
|
||||||
|
log_info("ext_manager", "Disabling $fname");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -280,6 +280,7 @@ class Setup extends SimpleExtension {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log_info("setup", "Configuration updated");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onUserBlockBuilding($event) {
|
public function onUserBlockBuilding($event) {
|
||||||
|
|
|
@ -74,7 +74,7 @@ class UserPage extends SimpleExtension {
|
||||||
}
|
}
|
||||||
else if($event->get_arg(0) == "logout") {
|
else if($event->get_arg(0) == "logout") {
|
||||||
set_prefixed_cookie("session", "", time()+60*60*24*$config->get_int('login_memory'), "/");
|
set_prefixed_cookie("session", "", time()+60*60*24*$config->get_int('login_memory'), "/");
|
||||||
log_info("user", "Logged out");
|
log_debug("user", "Logged out");
|
||||||
$page->set_mode("redirect");
|
$page->set_mode("redirect");
|
||||||
$page->set_redirect(make_link());
|
$page->set_redirect(make_link());
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue