From 27caa1c810ffdca0b6d432f1401d33c0062cf482 Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Sun, 16 Nov 2008 21:46:38 +0100 Subject: [PATCH] Implementation of the logger here. WARNING: This breaks compatibility with sessions created by previous versions of plat/al. Signed-off-by: Florent Bruneau --- classes/platallogger.php | 119 +++++++++++++++++++++++++++++++++++++++++++++++ core | 2 +- include/xnet.inc.php | 1 + include/xorg.inc.php | 1 + 4 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 classes/platallogger.php diff --git a/classes/platallogger.php b/classes/platallogger.php new file mode 100644 index 0000000..a7a8d02 --- /dev/null +++ b/classes/platallogger.php @@ -0,0 +1,119 @@ +uid = $uid; + $this->session = $this->writeSession($uid, $suid); + + // retrieve available actions + $res = XDB::iterRow("SELECT id, text FROM logger.actions"); + + while (list($action_id, $action_text) = $res->next()) { + $this->actions[$action_text] = $action_id; + } + } + + /** Creates a new session entry in database and return its ID. + * + * @param $uid the id of the logged user + * @param $suid the id of the administrator who has just su'd to the user + * @return session the session id + */ + private function writeSession($uid, $suid = 0) + { + $ip = $_SERVER['REMOTE_ADDR']; + $host = strtolower(gethostbyaddr($_SERVER['REMOTE_ADDR'])); + $browser = (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''); + + @list($forward_ip,) = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); + $forward_host = $forward_ip; + if ($forward_host) { + $forward_host = strtolower(gethostbyaddr($forward_host)); + } + $proxy = ''; + if ($forward_ip || @$_SERVER['HTTP_VIA']) { + $proxy = 'proxy'; + } + + XDB::execute("INSERT INTO logger.sessions + SET uid={?}, host={?}, ip={?}, forward_ip={?}, forward_host={?}, browser={?}, suid={?}, flags={?}", + $uid, $host, ip_to_uint($ip), ip_to_uint($forward_ip), $forward_host, $browser, $suid, $proxy); + if ($forward_ip) { + $this->proxy_ip = $ip; + $this->proxy_host = $host; + $this->ip = $forward_ip; + $this->host = $forward_host; + } else { + $this->ip = $ip; + $this->host = $host; + } + + $id = XDB::insertId(); + if ($uid and !$suid) { + XDB::execute('REPLACE INTO logger.last_sessions (uid, id) + VALUES ({?}, {?})', + $uid, $id); + } + return $id; + } + + + /** Logs an action and its related data. + * + * @param $action le type d'action + * @param $data les données (id de liste, etc.) + * @return VOID + */ + public function log($action, $data = null) + { + if (isset($this->actions[$action])) { + XDB::execute("INSERT INTO logger.events + SET session={?}, action={?}, data={?}", + $this->session, $this->actions[$action], $data); + } else { + trigger_error("PlLogger: unknown action, $action", E_USER_WARNING); + } + } +} + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: +?> diff --git a/core b/core index 7f10bc6..b9ca23a 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 7f10bc6153e899a781fb1244c6681252b16887b2 +Subproject commit b9ca23a38990f158ce74f13cc4413bb436ced541 diff --git a/include/xnet.inc.php b/include/xnet.inc.php index a8431e3..0247b26 100644 --- a/include/xnet.inc.php +++ b/include/xnet.inc.php @@ -20,6 +20,7 @@ ***************************************************************************/ define('PL_GLOBALS_CLASS', 'PlatalGlobals'); +define('PL_LOGGER_CLASS', 'PlatalLogger'); define('PL_SESSION_CLASS', 'XnetSession'); define('PL_PAGE_CLASS', 'XnetPage'); diff --git a/include/xorg.inc.php b/include/xorg.inc.php index b67126b..75f9af5 100644 --- a/include/xorg.inc.php +++ b/include/xorg.inc.php @@ -20,6 +20,7 @@ ***************************************************************************/ define('PL_GLOBALS_CLASS', 'PlatalGlobals'); +define('PL_LOGGER_CLASS', 'PlatalLogger'); define('PL_SESSION_CLASS', 'XorgSession'); define('PL_PAGE_CLASS', 'XorgPage'); -- 2.1.4