Release diogenes-0.9.22
[diogenes.git] / include / diogenes.webdav.logger.inc.php
CommitLineData
6855525e
JL
1<?php
2/*
3 * Copyright (C) 2003-2004 Polytechnique.org
4 * http://opensource.polytechnique.org/
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21
22require_once 'diogenes/diogenes.core.logger.inc.php';
23
24/** Class for logging WebDAV activity.
25 *
26 * The difference with DiogenesCoreLogger is that we do not have
27 * PHP sessions in WebDAV mode so we need a small hack to avoid creating
28 * a new 'session' entry for each operation.
29 */
30class DiogenesWebDAVLogger extends DiogenesCoreLogger {
31
32 /** is this a new WebDAV 'session' ? */
33 var $newsession;
34
35 /** WebDAV 'session' duration in seconds */
36 var $sessionlength = 1800;
37
38 /** The constructor, creates a new entry in the sessions table
39 *
40 * @param $uid the id of the logged user
41 * @param $auth authentication method for the logged user
42 * @param $username the username of the logged user
43 * @return VOID
44 */
45 function DiogenesWebDAVLogger($uid,$auth,$username) {
46 global $globals;
47
48 $this->DiogenesCoreLogger($uid,'',$auth,'');
49
50 if ($this->newsession) {
51 $this->log("auth_ok","{$username}@WebDAV");
52 }
53 }
54
55
56 /** Try to pickup an existing session, otherwise create a new entry
57 *
58 * @param $uid the id of the logged user
59 * @param $suid the id of the administrator who has just su'd to the user
60 * @param $auth authentication method for the logged user
61 * @param $sauth authentication method for the su'er
62 * @return session the session id
63 */
64 function writeSession($uid,$suid,$auth,$sauth) {
65 global $globals;
66
67 // we look for a session with the same user, auth and browser that is less
68 // than $sessionlength seconds old
69 $browser = (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '');
70 $stime = date("YmdHis",time()-$this->sessionlength);
71 $res = $globals->db->query("select id from {$this->table_sessions} where uid='$uid' and auth='$auth' and browser='$browser' and start > $stime");
72
73 if (list($session) = mysql_fetch_row($res)) {
74 // we have an existing session
75 $this->newsession = false;
76 } else {
77 // we do not have an existing session
78 $this->newsession = true;
79 $session = parent::writeSession($uid,$suid,$auth,$sauth);
80 }
81 mysql_free_result($res);
82 return $session;
83 }
84
85}
86
87?>