function phorum_mod_event_logging_after_approve($data) { if (!$GLOBALS["PHORUM"]["mod_event_logging"]["do_log_mod_approve"]) { return $data; } // Check for suspended logging. if (!empty($GLOBALS["PHORUM"]["MOD_EVENT_LOGGING"]["SUSPEND"])) { return $data; } list($source, $from_module) = event_logging_find_source(1); $suffix = $data[1] == PHORUM_APPROVE_MESSAGE_TREE ? " and replies" : ""; event_logging_writelog(array("message" => "Moderation: Approved message \"{$data[0]["subject"]}\"{$suffix}.", "loglevel" => EVENTLOG_LVL_INFO, "message_id" => $data[0]["message_id"], "thread_id" => $data[0]["thread"], "forum_id" => $data[0]["forum_id"], "source" => $source, "category" => $from_module ? EVENTLOG_CAT_MODULE : EVENTLOG_CAT_APPLICATION)); return $data; }
function phorum_mod_event_logging_user_delete($userid) { if (!$GLOBALS["PHORUM"]["mod_event_logging"]["do_log_user_delete"]) { return $userid; } list($source, $from_module) = event_logging_find_source(1); $user = phorum_api_user_get($userid); event_logging_writelog(array("message" => "User deleted: {$user['username']} <{$user['email']}> ID: {$userid} .", "loglevel" => EVENTLOG_LVL_INFO, "source" => $source, "category" => EVENTLOG_CAT_SECURITY)); return $userid; }
/** * Write a new message to the event logging table. * * This function will automatically fill the log information with * user_id, ip, hostname (if hostname resolving is enabled for the log module) * datestamp and vroot information. Other log info can be provided throught * the $loginfo argument. * * @param $loginfo - An array containing logging information. This array * can contain the following fields: * * message A short log message on one line. * details Details about the log message, which can * span multiple lines. This could for example * be used for providing a debug backtrace. * source The source of the log message. This is a * free 32 char text field, which can be used * to specifiy what part of Phorum generated the * log message (e.g. "mod_smileys"). If no * source is provided, the "phorum_page" * constant will be used instead. * category A high level category for the message. * Options for this field are: * EVENTLOG_CAT_APPLICATION (default) * EVENTLOG_CAT_DATABASE * EVENTLOG_CAT_SECURITY * EVENTLOG_CAT_SYSTEM * EVENTLOG_CAT_MODULE * loglevel This indicates the severety of the message. * Options for this field are: * EVENTLOG_LVL_DEBUG * Messages that are used by programmers * for tracking low level Phorum operation. * EVENTLOG_LVL_INFO * Messages that provide logging for events * that occur during normal operation. These * messages could be harvested for usage * reporting and other types of reports. * EVENTLOG_LVL_WARNING * Warning messages do not indicate errors, * but they do report events that are not * considered to belong to normal operation * (e.g. a user which enters a wrong password * or a duplicate message being posted). * EVENTLOG_LVL_ERROR * Error messages indicate non urgent failures * in Phorum operation. These should be * relayed to administrators and/or developers * to have them solved. * EVENTLOG_LVL_ALERT * Alert messages indicate errors which should * be corrected as soon as possible (e.g. loss * of network connectivity or a full disk). * These should be relayed to the system * administrator). * * vroot vroot for which a message is generated. * forum_id forum_id for which a message is generated. * thread_id thread_id for which a message is generated * message_id message_id for which a message is generated * * user_id Filled automatically, but can be overridden * ip Filled automatically, but can be overridden * hostname Filled automatically, but can be overridden * datestamp Filled automatically, but can be overridden */ function event_logging_writelog($loginfo) { global $PHORUM; // Check the minimum log level. Only write to the log if the // log level of the event is at or above the configured minimum. $lvl = isset($loginfo["loglevel"]) ? (int) $loginfo["loglevel"] : 0; if ($lvl < $PHORUM["mod_event_logging"]["min_log_level"]) { return; } $loginfo = phorum_api_hook("event_logging_writelog", $loginfo); // The record that we will insert in the database. $record = array(); // Handle messages that exceed the maximum message length. if ($loginfo["message"] !== NULL && strlen($loginfo["message"]) > 255) { if (!isset($loginfo["details"])) { $loginfo["details"] = ''; } $loginfo["details"] = "Message:\n\n{$loginfo["message"]}\n\n" . $loginfo["details"]; $loginfo["message"] = substr($loginfo["message"], 0, 100) . "... (see event details for the full message)\n"; } elseif (isset($loginfo["details"])) { $loginfo["details"] = "Message:\n\n{$loginfo["message"]}\n\n" . $loginfo["details"]; } // Add the fields from the $loginfo argument. foreach ($loginfo as $key => $val) { switch ($key) { case "datestamp": case "user_id": case "vroot": case "forum_id": case "thread_id": case "message_id": case "category": case "loglevel": settype($val, "int"); $record[$key] = $val; break; case "message": case "details": case "source": case "ip": case "hostname": $record[$key] = "'" . $PHORUM['DB']->interact(DB_RETURN_QUOTED, $val) . "'"; break; default: phorum_api_error(PHORUM_ERRNO_DATABASE, "event_logging_log(): Illegal key " . "field \"{$key}\" in the \$loginfo argument"); } } // Add the message source. $from_module = FALSE; if (!isset($record["source"])) { list($source, $from_module) = event_logging_find_source(1); $record["source"] = "'" . $PHORUM['DB']->interact(DB_RETURN_QUOTED, $source) . "'"; } // Add the category. if (!isset($record["category"])) { $record["category"] = $from_module ? EVENTLOG_CAT_MODULE : EVENTLOG_CAT_APPLICATION; } // Add the datestamp. if (!isset($record["datestamp"])) { $record["datestamp"] = time(); } // Add the IP address for the current visitor. if (!isset($record["ip"]) && isset($_SERVER["REMOTE_ADDR"])) { $ip = $_SERVER["REMOTE_ADDR"]; $record["ip"] = "'" . $PHORUM['DB']->interact(DB_RETURN_QUOTED, $ip) . "'"; } // Add the hostname for the current visitor. if (!isset($record["hostname"]) && isset($record["ip"]) && $PHORUM["mod_event_logging"]["resolve_hostnames"]) { $hostname = gethostbyaddr($ip); if ($hostname != $ip) { $record["hostname"] = "'" . $PHORUM['DB']->interact(DB_RETURN_QUOTED, $hostname) . "'"; } } // Add the user_id in case the visitor is an authenticated user. if (!isset($record["user_id"]) && isset($PHORUM["user"]["user_id"]) && $PHORUM["user"]["user_id"]) { $record["user_id"] = $PHORUM["user"]["user_id"]; } // Add the current vroot. if (!isset($record["vroot"]) && isset($PHORUM["vroot"])) { $record["vroot"] = $PHORUM["vroot"]; } // Insert the logging record in the database. $PHORUM['DB']->interact(DB_RETURN_RES, "INSERT INTO {$PHORUM["event_logging_table"]}\n (" . implode(', ', array_keys($record)) . ")\n VALUES (" . implode(', ', $record) . ")", NULL, DB_MASTERQUERY); }