diff --git a/contrib/image_hash_ban/main.php b/contrib/image_hash_ban/main.php index 7c5736a1..e96c7d0e 100644 --- a/contrib/image_hash_ban/main.php +++ b/contrib/image_hash_ban/main.php @@ -48,6 +48,7 @@ class ImageBan implements Extension { $row = $database->db->GetRow("SELECT * FROM image_bans WHERE hash = ?", $event->hash); if($row) { + log_info("image_hash_ban", "Blocked image ({$event->hash})"); throw new UploadException("Image ".html_escape($row["hash"])." has been banned, reason: ".format_text($row["reason"])); } } diff --git a/contrib/pm/main.php b/contrib/pm/main.php index 95faa98d..4eb3618d 100644 --- a/contrib/pm/main.php +++ b/contrib/pm/main.php @@ -83,6 +83,7 @@ class PM implements Extension { } else if(($pm["to_id"] == $user->id) || $user->is_admin()) { $database->execute("DELETE FROM private_message WHERE id = ?", array($pm_id)); + log_info("pm", "Deleted PM #$pm_id"); $event->page->set_mode("redirect"); $event->page->set_redirect(make_link("user")); } @@ -112,6 +113,7 @@ class PM implements Extension { array($event->from_id, $event->from_ip, $event->to_id, $event->subject, $event->message) ); + log_info("pm", "Sent PM to User #$to_id"); } } @@ -134,6 +136,8 @@ class PM implements Extension { "); $config->set_int("pm_version", 1); } + + log_info("pm", "extension installed"); } private function get_pms(User $user) { diff --git a/core/event.class.php b/core/event.class.php index f176f4fb..ed88e2a5 100644 --- a/core/event.class.php +++ b/core/event.class.php @@ -91,4 +91,34 @@ class TextFormattingEvent extends Event { $this->stripped = $h_text; } } + + +/* + * LogEvent + * $section = a category, normally the extension name + * $priority = see python + * $message = free text + */ +class LogEvent extends Event { + var $section; + var $priority = 0; + var $message; + var $time; + + public function __construct($context, $section, $priority, $message) { + parent::__construct($context); + $this->section = $section; + $this->priority = $priority; + $this->message = $message; + $this->time = time(); + + // this should be an extension + $ftime = date("Y-m-d H:i:s", $this->time); + $username = $context->user->name; + $ip = $_SERVER['REMOTE_ADDR']; + $fp = fopen("shimmie.log", "a"); + fprintf($fp, "$ftime\t$section/$priority\t$username/$ip\t$message"); + fclose($fp); + } +} ?> diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index e1b58dae..12d83939 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -275,6 +275,7 @@ class Image { array($tag)); } + log_info("core-image", "Tags for Image #{$this->id} set to: ".implode(" ", $tags)); $this->database->cache->delete("image-{$this->id}-tags"); } @@ -285,6 +286,7 @@ class Image { public function delete() { $this->delete_tags_from_image(); $this->database->execute("DELETE FROM images WHERE id=?", array($this->id)); + log_info("core-image", "Deleted Image #{$image->id} ({$image->hash})") unlink($this->get_image_filename()); unlink($this->get_thumb_filename()); diff --git a/core/user.class.php b/core/user.class.php index ce7691a1..028347e7 100644 --- a/core/user.class.php +++ b/core/user.class.php @@ -78,11 +78,13 @@ class User { assert(is_bool($admin)); $yn = $admin ? 'Y' : 'N'; $this->database->Execute("UPDATE users SET admin=? WHERE id=?", array($yn, $this->id)); + log_info("core-user", "Made {$this->name} admin=$yn"); } public function set_password($password) { $hash = md5(strtolower($this->name) . $password); $this->database->Execute("UPDATE users SET pass=? WHERE id=?", array($hash, $this->id)); + log_info("core-user", "Set password for {$this->name}"); } } ?> diff --git a/core/util.inc.php b/core/util.inc.php index 618eea3d..351157cd 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -215,6 +215,27 @@ function format_text($string) { } +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ +* Logging convenience * +\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +define("LOG_CRITICAL", 50); +define("LOG_ERROR", 40); +define("LOG_WARNING", 30); +define("LOG_INFO", 20); +define("LOG_DEBUG", 10); +define("LOG_NOTSET", 0); + +function log_msg($section, $priority, $message) { + global $context; + send_event(new LogEvent($context, $section, $priority, $message)); +} + +function log_info($section, $message) { + log_msg($section, LOG_INFO, $message); +} + + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ * Things which should be in the core API * \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ diff --git a/ext/admin/main.php b/ext/admin/main.php index a72b7b3c..3ff685bb 100644 --- a/ext/admin/main.php +++ b/ext/admin/main.php @@ -43,6 +43,7 @@ class AdminPage implements Extension { if(($event instanceof PageRequestEvent) && $event->page_matches("admin_utils")) { if($event->user->is_admin()) { + log_info("admin", "Util: {$_POST['action']}") set_time_limit(0); $redirect = false; diff --git a/ext/comment/main.php b/ext/comment/main.php index a8b62cef..c2f6b520 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -400,17 +400,21 @@ class CommentList implements Extension { "INSERT INTO comments(image_id, owner_id, owner_ip, posted, comment) ". "VALUES(?, ?, ?, now(), ?)", array($image_id, $user->id, $_SERVER['REMOTE_ADDR'], $comment)); + $cid = $database->db->Insert_ID(); + log_info("comment", "Comment #$cid"); } } private function delete_comments($image_id) { global $database; $database->Execute("DELETE FROM comments WHERE image_id=?", array($image_id)); + log_info("comment", "Deleting all comments for Image #$image_id"); } private function delete_comment($comment_id) { global $database; $database->Execute("DELETE FROM comments WHERE id=?", array($comment_id)); + log_info("comment", "Deleting Comment #$comment_id"); } // }}} } diff --git a/ext/handle_404/main.php b/ext/handle_404/main.php index 879d20a3..b6fc0c39 100644 --- a/ext/handle_404/main.php +++ b/ext/handle_404/main.php @@ -8,6 +8,7 @@ class Handle404 implements Extension { if($page->mode == "page" && (!isset($page->blocks) || $this->count_main($page->blocks) == 0)) { $h_pagename = html_escape(implode('/', $event->args)); header("HTTP/1.0 404 Page Not Found"); + log_info("handle_404", "Hit 404: $h_pagename"); $page->set_title("404"); $page->set_heading("404 - No Handler Found"); $page->add_block(new NavBlock()); diff --git a/ext/image/main.php b/ext/image/main.php index 2277d321..2ae8eae3 100644 --- a/ext/image/main.php +++ b/ext/image/main.php @@ -193,6 +193,8 @@ class ImageIO implements Extension { $image->hash, $image->ext, $image->width, $image->height, $image->source)); $image->id = $database->db->Insert_ID(); + log_info("image", "Uploaded image {$image->id} ({$image->hash})"); + send_event(new TagSetEvent($image, $image->get_tag_array())); return null; diff --git a/ext/user/main.php b/ext/user/main.php index 224ce9fd..f6c99e25 100644 --- a/ext/user/main.php +++ b/ext/user/main.php @@ -67,6 +67,7 @@ class UserPage implements Extension { } else if($event->get_arg(0) == "logout") { setcookie("shm_session", "", time()+60*60*24*$config->get_int('login_memory'), "/"); + log_info("user", "Logged out"); $page->set_mode("redirect"); $page->set_redirect(make_link()); } @@ -201,6 +202,7 @@ class UserPage implements Extension { if(!is_null($duser)) { $user = $duser; $this->set_login_cookie($name, $pass); + log_info("user", "Logged in"); $page->set_mode("redirect"); $page->set_redirect(make_link("user")); } @@ -242,6 +244,8 @@ class UserPage implements Extension { $database->Execute( "INSERT INTO users (name, pass, joindate, email, admin) VALUES (?, ?, now(), ?, ?)", array($event->username, $hash, $email, $admin)); + $uid = $database->db->Insert_ID(); + log_info("user", "Created User #$uid ({$event->username})"); } private function set_login_cookie($name, $pass) {