logging things
This commit is contained in:
parent
989fc72e5a
commit
415f6901da
11 changed files with 72 additions and 0 deletions
|
@ -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"]));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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}");
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -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 *
|
||||
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
// }}}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
Reference in a new issue