aboutsummaryrefslogtreecommitdiff
path: root/engine/lib
diff options
context:
space:
mode:
authorBrett Profitt <brett.profitt@gmail.com>2012-01-20 18:43:34 -0800
committerBrett Profitt <brett.profitt@gmail.com>2012-01-20 18:43:34 -0800
commit12c4a61edc0a225677c31f6d26a7a785c065c115 (patch)
treea17ceb5171ce8225f25fcb6299dd6739f9e47365 /engine/lib
parent9cca28b590a5884033c60af5a47aa3dcc383f7f0 (diff)
downloadelgg-12c4a61edc0a225677c31f6d26a7a785c065c115.tar.gz
elgg-12c4a61edc0a225677c31f6d26a7a785c065c115.tar.bz2
Fixes #2222. Added IP address to system log table and log browser. Fixed problem in log browser that would only show entries without an owner_guid.
Diffstat (limited to 'engine/lib')
-rw-r--r--engine/lib/system_log.php21
-rw-r--r--engine/lib/upgrades/2012012000-1.8.3-ip_in_syslog-87fe0f068cf62428.php12
2 files changed, 27 insertions, 6 deletions
diff --git a/engine/lib/system_log.php b/engine/lib/system_log.php
index fd5644135..28d90be56 100644
--- a/engine/lib/system_log.php
+++ b/engine/lib/system_log.php
@@ -11,6 +11,7 @@
* Retrieve the system log based on a number of parameters.
*
* @param int|array $by_user The guid(s) of the user(s) who initiated the event.
+ * Use 0 for unowned entries. Anything else falsey means anyone.
* @param string $event The event you are searching on.
* @param string $class The class of object it effects.
* @param string $type The type
@@ -21,11 +22,12 @@
* @param int $timebefore Lower time limit
* @param int $timeafter Upper time limit
* @param int $object_id GUID of an object
- *
+ * @param str $ip_address The IP address.
* @return mixed
*/
function get_system_log($by_user = "", $event = "", $class = "", $type = "", $subtype = "",
-$limit = 10, $offset = 0, $count = false, $timebefore = 0, $timeafter = 0, $object_id = 0) {
+$limit = 10, $offset = 0, $count = false, $timebefore = 0, $timeafter = 0, $object_id = 0,
+$ip_address = false) {
global $CONFIG;
@@ -37,16 +39,18 @@ $limit = 10, $offset = 0, $count = false, $timebefore = 0, $timeafter = 0, $obje
} else {
$by_user = (int)$by_user;
}
+
$event = sanitise_string($event);
$class = sanitise_string($class);
$type = sanitise_string($type);
$subtype = sanitise_string($subtype);
+ $ip_address = sanitise_string($ip_address);
$limit = (int)$limit;
$offset = (int)$offset;
$where = array();
- if ($by_user_orig !== "") {
+ if ($by_user_orig !== "" && $by_user_orig !== false && $by_user_orig !== null) {
if (is_int($by_user)) {
$where[] = "performed_by_guid=$by_user";
} else if (is_array($by_user)) {
@@ -75,6 +79,9 @@ $limit = 10, $offset = 0, $count = false, $timebefore = 0, $timeafter = 0, $obje
if ($object_id) {
$where[] = "object_id = " . ((int) $object_id);
}
+ if ($ip_address) {
+ $where[] = "ip_address = '$ip_address'";
+ }
$select = "*";
if ($count) {
@@ -91,7 +98,8 @@ $limit = 10, $offset = 0, $count = false, $timebefore = 0, $timeafter = 0, $obje
}
if ($count) {
- if ($numrows = get_data_row($query)) {
+ $numrows = get_data_row($query);
+ if ($numrows) {
return $numrows->count;
}
} else {
@@ -171,6 +179,7 @@ function system_log($object, $event) {
$object_subtype = $object->getSubtype();
$event = sanitise_string($event);
$time = time();
+ $ip_address = sanitise_string($_SERVER['REMOTE_ADDR']);
$performed_by = elgg_get_logged_in_user_guid();
if (isset($object->access_id)) {
@@ -194,10 +203,10 @@ function system_log($object, $event) {
if (!isset($log_cache[$time][$object_id][$event])) {
$query = "INSERT DELAYED into {$CONFIG->dbprefix}system_log
(object_id, object_class, object_type, object_subtype, event,
- performed_by_guid, owner_guid, access_id, enabled, time_created)
+ performed_by_guid, owner_guid, access_id, enabled, time_created, ip_address)
VALUES
('$object_id','$object_class','$object_type', '$object_subtype', '$event',
- $performed_by, $owner_guid, $access_id, '$enabled', '$time')";
+ $performed_by, $owner_guid, $access_id, '$enabled', '$time', '$ip_address')";
insert_data($query);
diff --git a/engine/lib/upgrades/2012012000-1.8.3-ip_in_syslog-87fe0f068cf62428.php b/engine/lib/upgrades/2012012000-1.8.3-ip_in_syslog-87fe0f068cf62428.php
new file mode 100644
index 000000000..b9514e156
--- /dev/null
+++ b/engine/lib/upgrades/2012012000-1.8.3-ip_in_syslog-87fe0f068cf62428.php
@@ -0,0 +1,12 @@
+<?php
+/**
+ * Elgg 1.8.3 upgrade 2012012000
+ * ip_in_syslog
+ *
+ * Adds a field for an IP address in the system log table
+ */
+
+$db_prefix = elgg_get_config('dbprefix');
+$q = "ALTER TABLE {$db_prefix}system_log ADD ip_address VARCHAR(15) NOT NULL AFTER time_created";
+
+update_data($q); \ No newline at end of file