2007-08-23 18:49:59 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Name: EventLog
|
|
|
|
* Author: Shish <webmaster@shishnet.org>
|
|
|
|
* License: GPLv2
|
|
|
|
* Description: A log of things that happen, for abuse tracking
|
|
|
|
*/
|
|
|
|
|
2008-08-23 12:08:19 +00:00
|
|
|
class EventLog implements Extension {
|
2007-08-23 18:49:59 +00:00
|
|
|
var $theme;
|
|
|
|
|
2008-08-23 12:08:19 +00:00
|
|
|
public function receive_event(Event $event) {
|
2008-09-06 16:59:02 +00:00
|
|
|
if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
2007-08-23 18:49:59 +00:00
|
|
|
|
2008-08-22 09:41:30 +00:00
|
|
|
if($event instanceof InitExtEvent) {
|
2007-08-23 18:49:59 +00:00
|
|
|
$this->setup();
|
|
|
|
}
|
|
|
|
|
2008-09-06 17:48:03 +00:00
|
|
|
if(($event instanceof PageRequestEvent) && $event->page_matches("event_log")) {
|
2007-08-24 13:35:48 +00:00
|
|
|
global $database;
|
2007-08-24 22:29:34 +00:00
|
|
|
if($event->user->is_admin()) {
|
2007-08-24 13:35:48 +00:00
|
|
|
if(isset($_POST['action'])) {
|
|
|
|
switch($_POST['action']) {
|
|
|
|
case 'clear':
|
|
|
|
$database->execute("DELETE FROM event_log");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-24 13:54:51 +00:00
|
|
|
$columns = array("name", "date", "owner_ip", "event");
|
|
|
|
$orders = array("ASC", "DESC");
|
|
|
|
|
2007-08-24 13:35:48 +00:00
|
|
|
$sort = "date";
|
2007-08-24 13:54:51 +00:00
|
|
|
if(isset($_GET['sort']) && in_array($_GET['sort'], $columns)) {
|
2007-08-24 13:35:48 +00:00
|
|
|
$sort = $_GET['sort'];
|
|
|
|
}
|
2007-08-24 13:41:43 +00:00
|
|
|
|
|
|
|
$order = "DESC";
|
2007-08-24 13:54:51 +00:00
|
|
|
if(isset($_GET['order']) && in_array($_GET['order'], $orders)) {
|
2007-08-24 13:41:43 +00:00
|
|
|
$order = $_GET['order'];
|
|
|
|
}
|
|
|
|
|
2007-08-24 13:54:51 +00:00
|
|
|
$filter_sql = "";
|
|
|
|
if(isset($_GET['filter']) && isset($_GET['where']) && in_array($_GET['filter'], $columns)) {
|
|
|
|
$filter = $_GET['filter'];
|
|
|
|
$where = $database->db->Quote($_GET['where']);
|
|
|
|
$filter_sql = "WHERE $filter = $where";
|
|
|
|
}
|
|
|
|
|
2008-01-05 00:22:19 +00:00
|
|
|
$events = $database->get_all("
|
2007-08-23 22:48:33 +00:00
|
|
|
SELECT event_log.*,users.name FROM event_log
|
|
|
|
JOIN users ON event_log.owner_id = users.id
|
2007-08-24 13:54:51 +00:00
|
|
|
$filter_sql
|
2007-08-24 13:41:43 +00:00
|
|
|
ORDER BY $sort $order
|
2007-08-23 22:48:33 +00:00
|
|
|
");
|
2007-08-23 18:49:59 +00:00
|
|
|
$this->theme->display_page($event->page, $events);
|
|
|
|
}
|
|
|
|
else {
|
2008-10-18 10:49:16 +00:00
|
|
|
$this->theme->display_permission_denied($event->page);
|
2007-08-23 18:49:59 +00:00
|
|
|
}
|
|
|
|
}
|
2008-08-22 09:41:30 +00:00
|
|
|
if($event instanceof UserBlockBuildingEvent) {
|
2007-08-23 18:49:59 +00:00
|
|
|
if($event->user->is_admin()) {
|
|
|
|
$event->add_link("Event Log", make_link("event_log"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
global $user; // bad
|
2008-08-22 09:41:30 +00:00
|
|
|
if($event instanceof UploadingImageEvent) {
|
2007-08-24 22:29:34 +00:00
|
|
|
$this->add_to_log($event->user, 'Uploading Image', "Uploaded a new image");
|
2007-08-24 17:17:52 +00:00
|
|
|
}
|
2008-08-22 09:41:30 +00:00
|
|
|
if($event instanceof CommentPostingEvent) {
|
2007-08-24 17:03:04 +00:00
|
|
|
$this->add_to_log($event->user, 'Comment Posting', "Posted a comment on image #{$event->image_id}");
|
|
|
|
}
|
2008-08-22 09:41:30 +00:00
|
|
|
if($event instanceof WikiUpdateEvent) {
|
2007-10-28 17:20:25 +00:00
|
|
|
$this->add_to_log($event->user, 'Wiki Update', "Edited '{$event->wikipage->title}'");
|
2007-08-23 18:49:59 +00:00
|
|
|
}
|
2008-08-22 09:41:30 +00:00
|
|
|
if($event instanceof ConfigSaveEvent) {
|
2007-08-23 18:49:59 +00:00
|
|
|
$this->add_to_log($user, 'Config Save', "Updated the board config");
|
|
|
|
}
|
2008-08-22 09:41:30 +00:00
|
|
|
if($event instanceof ImageDeletionEvent) {
|
2007-08-23 18:49:59 +00:00
|
|
|
$this->add_to_log($user, 'Image Deletion', "Deleted image {$event->image->id} (tags: {$event->image->get_tag_list()})");
|
|
|
|
}
|
2008-08-22 09:41:30 +00:00
|
|
|
if($event instanceof SourceSetEvent) {
|
2007-08-23 18:49:59 +00:00
|
|
|
$this->add_to_log($user, 'Source Set', "Source for image #{$event->image_id} set to '{$event->source}'");
|
|
|
|
}
|
2008-08-22 09:41:30 +00:00
|
|
|
if($event instanceof TagSetEvent) {
|
2007-10-21 22:06:34 +00:00
|
|
|
$tags = implode($event->tags, ", ");
|
|
|
|
$this->add_to_log($user, 'Tags Set', "Tags for image #{$event->image_id} set to '$tags'");
|
2007-08-23 18:49:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function add_to_log($user, $event, $entry) {
|
|
|
|
global $database;
|
|
|
|
|
|
|
|
$database->execute("
|
|
|
|
INSERT INTO event_log (owner_id, owner_ip, date, event, entry)
|
|
|
|
VALUES (?, ?, now(), ?, ?)",
|
|
|
|
array($user->id, $_SERVER['REMOTE_ADDR'], $event, $entry));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function setup() {
|
|
|
|
global $database;
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
if($config->get_int("ext_event_log_version", 0) < 1) {
|
|
|
|
$database->Execute("CREATE TABLE event_log (
|
|
|
|
id int(11) NOT NULL auto_increment primary key,
|
|
|
|
owner_id int(11) NOT NULL,
|
|
|
|
owner_ip char(15) NOT NULL,
|
|
|
|
date datetime NOT NULL,
|
|
|
|
event varchar(32) NOT NULL,
|
|
|
|
entry varchar(255) NOT NULL
|
|
|
|
)");
|
|
|
|
$config->set_int("ext_event_log_version", 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-08-24 17:03:04 +00:00
|
|
|
add_event_listener(new EventLog(), 99); // ignore vetoed events
|
2007-08-23 18:49:59 +00:00
|
|
|
?>
|