aboutsummaryrefslogtreecommitdiff
path: root/mod/logbrowser
diff options
context:
space:
mode:
Diffstat (limited to 'mod/logbrowser')
-rw-r--r--mod/logbrowser/languages/en.php30
-rw-r--r--mod/logbrowser/manifest.xml17
-rw-r--r--mod/logbrowser/start.php32
-rw-r--r--mod/logbrowser/views/default/admin/administer_utilities/logbrowser.php81
-rw-r--r--mod/logbrowser/views/default/forms/logbrowser/refine.php54
-rw-r--r--mod/logbrowser/views/default/logbrowser/refine.php40
-rw-r--r--mod/logbrowser/views/default/logbrowser/table.php90
7 files changed, 344 insertions, 0 deletions
diff --git a/mod/logbrowser/languages/en.php b/mod/logbrowser/languages/en.php
new file mode 100644
index 000000000..b1d2681dd
--- /dev/null
+++ b/mod/logbrowser/languages/en.php
@@ -0,0 +1,30 @@
+<?php
+/**
+ * Elgg log browser plugin language pack
+ *
+ * @package ElggLogBrowser
+ */
+
+$english = array(
+ 'admin:administer_utilities:logbrowser' => 'Log browser',
+ 'logbrowser' => 'Log browser',
+ 'logbrowser:browse' => 'Browse system log',
+ 'logbrowser:search' => 'Refine results',
+ 'logbrowser:user' => 'Username to search by',
+ 'logbrowser:starttime' => 'Beginning time (for example "last monday", "1 hour ago")',
+ 'logbrowser:endtime' => 'End time',
+
+ 'logbrowser:explore' => 'Explore log',
+
+ 'logbrowser:date' => 'Date and time',
+ 'logbrowser:ip_address' => 'IP address',
+ 'logbrowser:user:name' => 'User',
+ 'logbrowser:user:guid' => 'User GUID',
+ 'logbrowser:object' => 'Object type',
+ 'logbrowser:object:guid' => 'Object GUID',
+ 'logbrowser:action' => 'Action',
+
+ 'logbrowser:no_result' => 'No results',
+);
+
+add_translation("en", $english); \ No newline at end of file
diff --git a/mod/logbrowser/manifest.xml b/mod/logbrowser/manifest.xml
new file mode 100644
index 000000000..4527e2cbb
--- /dev/null
+++ b/mod/logbrowser/manifest.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plugin_manifest xmlns="http://www.elgg.org/plugin_manifest/1.8">
+ <name>Log Browser</name>
+ <author>Core developers</author>
+ <version>1.8</version>
+ <category>bundled</category>
+ <category>admin</category>
+ <description>Browse the system event log</description>
+ <website>http://www.elgg.org/</website>
+ <copyright>See COPYRIGHT.txt</copyright>
+ <license>GNU General Public License version 2</license>
+ <requires>
+ <type>elgg_release</type>
+ <version>1.8</version>
+ </requires>
+ <activate_on_install>true</activate_on_install>
+</plugin_manifest>
diff --git a/mod/logbrowser/start.php b/mod/logbrowser/start.php
new file mode 100644
index 000000000..22659877b
--- /dev/null
+++ b/mod/logbrowser/start.php
@@ -0,0 +1,32 @@
+<?php
+/**
+ * Elgg log browser.
+ *
+ * @package ElggLogBrowser
+ */
+
+elgg_register_event_handler('init', 'system', 'logbrowser_init');
+
+/**
+ * Initialize the log browser plugin.
+ */
+function logbrowser_init() {
+
+ elgg_register_plugin_hook_handler('register', 'menu:user_hover', 'logbrowser_user_hover_menu');
+
+ elgg_register_admin_menu_item('administer', 'logbrowser', 'administer_utilities');
+}
+
+/**
+ * Add to the user hover menu
+ */
+function logbrowser_user_hover_menu($hook, $type, $return, $params) {
+ $user = $params['entity'];
+
+ $url = "admin/administer_utilities/logbrowser?user_guid={$user->guid}";
+ $item = new ElggMenuItem('logbrowser', elgg_echo('logbrowser:explore'), $url);
+ $item->setSection('admin');
+ $return[] = $item;
+
+ return $return;
+}
diff --git a/mod/logbrowser/views/default/admin/administer_utilities/logbrowser.php b/mod/logbrowser/views/default/admin/administer_utilities/logbrowser.php
new file mode 100644
index 000000000..9506c9d9f
--- /dev/null
+++ b/mod/logbrowser/views/default/admin/administer_utilities/logbrowser.php
@@ -0,0 +1,81 @@
+<?php
+/**
+ * Elgg log browser admin page
+ *
+ * @note The ElggObject this creates for each entry is temporary
+ *
+ * @package ElggLogBrowser
+ */
+
+$limit = get_input('limit', 20);
+$offset = get_input('offset');
+
+$search_username = get_input('search_username');
+if ($search_username) {
+ $user = get_user_by_username($search_username);
+ if ($user) {
+ $user_guid = $user->guid;
+ } else {
+ $user_guid = null;
+ }
+} else {
+ $user_guid = get_input('user_guid', null);
+ if ($user_guid) {
+ $user_guid = (int) $user_guid;
+ $user = get_entity($user_guid);
+ if ($user) {
+ $search_username = $user->username;
+ }
+ } else {
+ $user_guid = null;
+ }
+}
+
+$timelower = get_input('timelower');
+if ($timelower) {
+ $timelower = strtotime($timelower);
+}
+
+$timeupper = get_input('timeupper');
+if ($timeupper) {
+ $timeupper = strtotime($timeupper);
+}
+
+$ip_address = get_input('ip_address');
+
+$refine = elgg_view('logbrowser/refine', array(
+ 'timeupper' => $timeupper,
+ 'timelower' => $timelower,
+ 'ip_address' => $ip_address,
+ 'username' => $search_username,
+));
+
+// Get log entries
+$log = get_system_log($user_guid, "", "", "","", $limit, $offset, false, $timeupper, $timelower,
+ 0, $ip_address);
+$count = get_system_log($user_guid, "", "", "","", $limit, $offset, true, $timeupper, $timelower,
+ 0, $ip_address);
+
+// if user does not exist, we have no results
+if ($search_username && is_null($user_guid)) {
+ $log = false;
+ $count = 0;
+}
+
+$table = elgg_view('logbrowser/table', array('log_entries' => $log));
+
+$nav = elgg_view('navigation/pagination',array(
+ 'offset' => $offset,
+ 'count' => $count,
+ 'limit' => $limit,
+));
+
+// display admin body
+$body = <<<__HTML
+$refine
+$nav
+$table
+$nav
+__HTML;
+
+echo $body;
diff --git a/mod/logbrowser/views/default/forms/logbrowser/refine.php b/mod/logbrowser/views/default/forms/logbrowser/refine.php
new file mode 100644
index 000000000..ebf7f10ed
--- /dev/null
+++ b/mod/logbrowser/views/default/forms/logbrowser/refine.php
@@ -0,0 +1,54 @@
+<?php
+/**
+ * Form body for refining the log browser search.
+ * Look for a particular person or in a time window.
+ *
+ * @uses $vars['username']
+ * @uses $vars['ip_address']
+ * @uses $vars['timelower']
+ * @uses $vars['timeupper']
+ */
+
+if (isset($vars['timelower'])) {
+ $lowerval = date('r', $vars['timelower']);
+} else {
+ $lowerval = "";
+}
+if (isset($vars['timeupper'])) {
+ $upperval = date('r', $vars['timeupper']);
+} else {
+ $upperval = "";
+}
+$ip_address = elgg_extract('ip_address', $vars);
+$username = elgg_extract('username', $vars);
+
+$form = "<div>" . elgg_echo('logbrowser:user');
+$form .= elgg_view('input/text', array(
+ 'name' => 'search_username',
+ 'value' => $username,
+)) . "</div>";
+
+$form .= "<div>" . elgg_echo('logbrowser:ip_address');
+$form .= elgg_view('input/text', array(
+ 'name' => 'ip_address',
+ 'value' => $ip_address,
+)) . "</div>";
+
+$form .= "<div>" . elgg_echo('logbrowser:starttime');
+$form .= elgg_view('input/text', array(
+ 'name' => 'timelower',
+ 'value' => $lowerval,
+)) . "</div>";
+
+$form .= "<div>" . elgg_echo('logbrowser:endtime');
+$form .= elgg_view('input/text', array(
+ 'name' => 'timeupper',
+ 'value' => $upperval,
+)) . "</div>";
+$form .= '<div class="elgg-foot">';
+$form .= elgg_view('input/submit', array(
+ 'value' => elgg_echo('search'),
+));
+$form .= '</div>';
+
+echo $form;
diff --git a/mod/logbrowser/views/default/logbrowser/refine.php b/mod/logbrowser/views/default/logbrowser/refine.php
new file mode 100644
index 000000000..86460c79e
--- /dev/null
+++ b/mod/logbrowser/views/default/logbrowser/refine.php
@@ -0,0 +1,40 @@
+<?php
+/**
+ * Log browser search form
+ *
+ * @package ElggLogBrowser
+ */
+
+$form_vars = array(
+ 'method' => 'get',
+ 'action' => 'admin/administer_utilities/logbrowser',
+ 'disable_security' => true,
+);
+$form = elgg_view_form('logbrowser/refine', $form_vars, $vars);
+
+$toggle_link = elgg_view('output/url', array(
+ 'href' => '#log-browser-search-form',
+ 'text' => elgg_echo('logbrowser:search'),
+ 'rel' => 'toggle',
+));
+
+$form_class = 'elgg-module elgg-module-inline';
+if (!isset($vars['user_guid'])) {
+ $form_class .= ' hidden';
+}
+
+?>
+
+<div id="logbrowser-search-area" class="mbm">
+ <div>
+ <?php echo $toggle_link; ?>
+ </div>
+ <div id="log-browser-search-form" class="<?php echo $form_class; ?>">
+ <div class="elgg-head">
+ <h3><?php echo elgg_echo('logbrowser:search'); ?></h3>
+ </div>
+ <div class="elgg-body">
+ <?php echo $form; ?>
+ </div>
+ </div>
+</div> \ No newline at end of file
diff --git a/mod/logbrowser/views/default/logbrowser/table.php b/mod/logbrowser/views/default/logbrowser/table.php
new file mode 100644
index 000000000..1223c1456
--- /dev/null
+++ b/mod/logbrowser/views/default/logbrowser/table.php
@@ -0,0 +1,90 @@
+<?php
+/**
+ * Log browser table
+ *
+ * @package ElggLogBrowser
+ */
+
+$log_entries = $vars['log_entries'];
+?>
+
+<table class="elgg-table">
+ <tr>
+ <th><?php echo elgg_echo('logbrowser:date'); ?></th>
+ <th><?php echo elgg_echo('logbrowser:ip_address'); ?></th>
+ <th><?php echo elgg_echo('logbrowser:user:name'); ?></th>
+ <th><?php echo elgg_echo('logbrowser:user:guid'); ?></th>
+ <th><?php echo elgg_echo('logbrowser:object'); ?></th>
+ <th><?php echo elgg_echo('logbrowser:object:guid'); ?></th>
+ <th><?php echo elgg_echo('logbrowser:action'); ?></th>
+ </tr>
+<?php
+ $alt = '';
+ foreach ($log_entries as $entry) {
+ if ($entry->ip_address) {
+ $ip_address = $entry->ip_address;
+ } else {
+ $ip_address = '&nbsp;';
+ }
+
+ $user = get_entity($entry->performed_by_guid);
+ if ($user) {
+ $user_link = elgg_view('output/url', array(
+ 'href' => $user->getURL(),
+ 'text' => $user->name,
+ 'is_trusted' => true,
+ ));
+ $user_guid_link = elgg_view('output/url', array(
+ 'href' => "admin/overview/logbrowser?user_guid=$user->guid",
+ 'text' => $user->getGUID(),
+ 'is_trusted' => true,
+ ));
+ } else {
+ $user_guid_link = $user_link = '&nbsp;';
+ }
+
+ $object = get_object_from_log_entry($entry->id);
+ if (is_callable(array($object, 'getURL'))) {
+ $object_link = elgg_view('output/url', array(
+ 'href' => $object->getURL(),
+ 'text' => $entry->object_class,
+ 'is_trusted' => true,
+ ));
+ } else {
+ $object_link = $entry->object_class;
+ }
+?>
+ <tr <?php echo $alt; ?>>
+ <td class="log-entry-time">
+ <?php echo date('r', $entry->time_created); ?>
+ </td>
+ <td class="log-entry-ip-address">
+ <?php echo $ip_address; ?>
+ </td>
+ <td class="log-entry-user">
+ <?php echo $user_link; ?>
+ </td>
+ <td class="log-entry-guid">
+ <?php echo $user_guid_link; ?>
+ </td>
+ <td class="log-entry-object">
+ <?php echo $object_link; ?>
+ </td>
+ <td class="log-entry-guid">
+ <?php echo $entry->object_id; ?>
+ </td>
+ <td class="log-entry-action">
+ <?php echo elgg_echo($entry->event); ?>
+ </td>
+ </tr>
+<?php
+
+ $alt = $alt ? '' : 'class="alt"';
+ }
+?>
+</table>
+<?php
+if (!$log_entries) {
+ echo elgg_echo('logbrowser:no_result');
+ return true;
+}