this is blah

This commit is contained in:
Shish 2009-05-11 05:54:42 -07:00
parent 47fd679354
commit e592ee4c59
2 changed files with 0 additions and 204 deletions

View file

@ -1,121 +0,0 @@
<?php
/**
* Name: EventLog
* Author: Shish <webmaster@shishnet.org>
* License: GPLv2
* Description: A log of things that happen, for abuse tracking
*/
class EventLog implements Extension {
var $theme;
public function receive_event(Event $event) {
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if($event instanceof InitExtEvent) {
$this->setup();
}
if(($event instanceof PageRequestEvent) && $event->page_matches("event_log")) {
global $database;
if($event->user->is_admin()) {
if(isset($_POST['action'])) {
switch($_POST['action']) {
case 'clear':
$database->execute("DELETE FROM event_log");
break;
}
}
$columns = array("name", "date", "owner_ip", "event");
$orders = array("ASC", "DESC");
$sort = "date";
if(isset($_GET['sort']) && in_array($_GET['sort'], $columns)) {
$sort = $_GET['sort'];
}
$order = "DESC";
if(isset($_GET['order']) && in_array($_GET['order'], $orders)) {
$order = $_GET['order'];
}
$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";
}
$events = $database->get_all("
SELECT event_log.*,users.name FROM event_log
JOIN users ON event_log.owner_id = users.id
$filter_sql
ORDER BY $sort $order
");
$this->theme->display_page($event->page, $events);
}
else {
$this->theme->display_permission_denied($event->page);
}
}
if($event instanceof UserBlockBuildingEvent) {
if($event->user->is_admin()) {
$event->add_link("Event Log", make_link("event_log"));
}
}
global $user; // bad
if($event instanceof UploadingImageEvent) {
$this->add_to_log($event->user, 'Uploading Image', "Uploaded a new image");
}
if($event instanceof CommentPostingEvent) {
$this->add_to_log($event->user, 'Comment Posting', "Posted a comment on image #{$event->image_id}");
}
if($event instanceof WikiUpdateEvent) {
$this->add_to_log($event->user, 'Wiki Update', "Edited '{$event->wikipage->title}'");
}
if($event instanceof ConfigSaveEvent) {
$this->add_to_log($user, 'Config Save', "Updated the board config");
}
if($event instanceof ImageDeletionEvent) {
$this->add_to_log($user, 'Image Deletion', "Deleted image {$event->image->id} (tags: {$event->image->get_tag_list()})");
}
if($event instanceof SourceSetEvent) {
$this->add_to_log($user, 'Source Set', "Source for image #{$event->image->id} set to '{$event->source}'");
}
if($event instanceof TagSetEvent) {
$tags = implode($event->tags, ", ");
$this->add_to_log($user, 'Tags Set', "Tags for image #{$event->image->id} set to '$tags'");
}
}
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->create_table("event_log", "
id SCORE_AIPK,
owner_id INTEGER NOT NULL,
owner_ip SCORE_INET NOT NULL,
date DATETIME NOT NULL,
event VARCHAR(32) NOT NULL,
entry TEXT NOT NULL,
FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE
");
$config->set_int("ext_event_log_version", 1);
}
}
}
add_event_listener(new EventLog(), 99); // ignore vetoed events
?>

View file

@ -1,83 +0,0 @@
<?php
class EventLogTheme extends Themelet {
public function display_page(Page $page, $events) {
$page->set_title("Event Log");
$page->set_heading("Event Log");
$page->add_block(new NavBlock());
$this->display_table($page, $events);
$this->display_controls($page);
}
protected function display_table(Page $page, $events) {
$table = "
<style>
.event_log_table TD {
font-size: 0.75em;
}
.event_log_table TD.entry {
text-align: left;
vertical-align: middle;
}
</style>
<table border='1' class='event_log_table'>
<tr>
<th>User
<a href='".make_link("event_log", "sort=name&order=ASC")."'>+</a>
<a href='".make_link("event_log", "sort=name&order=DESC")."'>-</a>
</th>
<th style='width: 10em;'>IP
<a href='".make_link("event_log", "sort=owner_ip&order=ASC")."'>+</a>
<a href='".make_link("event_log", "sort=owner_ip&order=DESC")."'>-</a>
</th>
<th rowspan='2' class='entry'>Entry</th>
</tr>
<tr>
<th style='width: 10em;'>Date
<a href='".make_link("event_log", "sort=date&order=ASC")."'>+</a>
<a href='".make_link("event_log", "sort=date&order=DESC")."'>-</a>
</th>
<th>Event
<a href='".make_link("event_log", "sort=event&order=ASC")."'>+</a>
<a href='".make_link("event_log", "sort=event&order=DESC")."'>-</a>
</th>
</tr>
";
foreach($events as $event) {
$entry = html_escape($event['entry']);
$table .= "
<tr>
<td>
<a href='".make_link("event_log", "filter=name&where={$event['name']}")."'>{$event['name']}</a>
</td>
<td>
<a href='".make_link("event_log", "filter=owner_ip&where={$event['owner_ip']}")."'>{$event['owner_ip']}</a>
</td>
<td rowspan='2' class='entry'>{$entry}</td>
</tr>
<tr>
<td>
{$event['date']}
</td>
<td>
<a href='".make_link("event_log", "filter=event&where={$event['event']}")."'>{$event['event']}</a>
</td>
</tr>
";
}
$table .= "</table>";
$page->add_block(new Block("Log Contents", $table));
}
protected function display_controls(Page $page) {
$html = "
<form action='".make_link("event_log")."' method='POST'>
<input type='hidden' name='action' value='clear'>
<input type='submit' value='Clear Log'>
</form>
";
$page->add_block(new Block(null, $html, "main", 60));
}
}
?>