X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fcorelogger.php;h=8d06056fe3afb9b63c9f1c95a850b5c2bf75b97c;hb=db270710fa0b3244697299d77a4a44951c0d2484;hp=96c53c646cb0e64e9135bc35e29eba9c7beca34f;hpb=42a50827dc2ac2b13ddaf77ea16c0989cd8b960d;p=platal.git diff --git a/classes/corelogger.php b/classes/corelogger.php index 96c53c6..8d06056 100644 --- a/classes/corelogger.php +++ b/classes/corelogger.php @@ -19,13 +19,19 @@ */ -class CoreLogger { +class CoreLogger +{ /** user id */ - var $uid; + public $uid; /** id of the session */ - var $session; + private $session; /** list of available actions */ - var $actions; + private $actions; + + public $ip; + public $host; + public $proxy_ip; + public $proxy_host; /** The constructor, creates a new entry in the sessions table * @@ -33,7 +39,8 @@ class CoreLogger { * @param $suid the id of the administrator who has just su'd to the user * @return VOID */ - function CoreLogger($uid, $suid='') { + public function __construct($uid, $suid = 0) + { // write the session entry $this->uid = $uid; $this->session = $this->writeSession($uid, $suid); @@ -47,19 +54,39 @@ class CoreLogger { } /** 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 */ - function writeSession($uid, $suid = null) { + 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={?}, browser={?}, suid={?}", - $uid, $host, $ip, $browser, $suid); + 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(); } @@ -68,18 +95,20 @@ class CoreLogger { /** Logs an action and its related data. * * @param $action le type d'action - * @param $data les données (id de liste, etc.) + * @param $data les données (id de liste, etc.) * @return VOID */ - function log($action, $data = null) { + public function log($action, $data = null) + { if (isset($this->actions[$action])) { XDB::execute("INSERT INTO logger.events - SET session={?}, action={?}, data={?}", + SET session={?}, action={?}, data={?}", $this->session, $this->actions[$action], $data); } else { - echo "unknown action : $action
"; + trigger_error("CoreLogger: unknown action, $action", E_USER_WARNING); } } } +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>