X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fpllogger.php;h=87ef69baab4e9a78df61cda77b57709b67726892;hb=4d1c62e006bc896e9ddb59d15dc7a7e30f9eb48e;hp=0381926a7206cee5f698fd18b5251b377264ab50;hpb=ba63661ce2f38974002c7e4113320e9d06010853;p=platal.git diff --git a/classes/pllogger.php b/classes/pllogger.php index 0381926..87ef69b 100644 --- a/classes/pllogger.php +++ b/classes/pllogger.php @@ -1,6 +1,6 @@ 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; - } - - return XDB::insertId(); - } - + abstract public function __construct($uid, $suid = 0); /** Logs an action and its related data. * @@ -98,15 +34,19 @@ class PlLogger * @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); - } + abstract public function log($action, $data = null); + + /** Check validity of the logger. + * + * @param $uid the uid of the current session. + * @return TRUE if the logger can still be used. + */ + abstract public function isValid($uid); + + /** Return a dummy logger. + */ + public static function dummy($uid, $suid = 0) { + return new DummyLogger($uid, $suid); } }