root/trunk/wifidog-auth/wifidog/classes/Authenticator.php @ 523

Revision 523, 3.5 KB (checked in by benoitg, 8 years ago)

2005-03-31 Benoit Gr�goire <bock@…>

  • Remove spaces after php blocks in various files.
  • Temporarely fix single authentication source not present bug in login smarty template. All other places where we select the network will be fixed tommorow.
  • Fix initial schema errors.
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2/********************************************************************\
3 * This program is free software; you can redistribute it and/or    *
4 * modify it under the terms of the GNU General Public License as   *
5 * published by the Free Software Foundation; either version 2 of   *
6 * the License, or (at your option) any later version.              *
7 *                                                                  *
8 * This program is distributed in the hope that it will be useful,  *
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
11 * GNU General Public License for more details.                     *
12 *                                                                  *
13 * You should have received a copy of the GNU General Public License*
14 * along with this program; if not, contact:                        *
15 *                                                                  *
16 * Free Software Foundation           Voice:  +1-617-542-5942       *
17 * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
18 * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
19 *                                                                  *
20 \********************************************************************/
21/**@file Authenticator.php
22 * @author Copyright (C) 2005 Benoit Gr�goire <bock@step.polymtl.ca>,
23 * Technologies Coeus inc.
24 */
25
26/** Abstract class to represent an authentication source */
27abstract class Authenticator
28{
29        private $mAccountOrigin;
30
31        function __construct($account_orgin)
32        {
33                $this->mAccountOrigin = $account_orgin;
34        }
35       
36        public function getAccountOrigin()
37        {
38                return $this->mAccountOrigin; 
39        }
40
41        /** Attempts to login a user against the authentication source.  If successfull, returns a User object */
42        function login()
43        {
44        }
45
46        /** Logs out the user */
47        function logout()
48        {
49        }
50
51        /** Start accounting traffic for the user */
52        function acctStart($info)
53        {
54                global $db;
55                $auth_response = $info['account_status'];
56                /* Login the user */
57                $mac = $db->EscapeString($_REQUEST['mac']);
58                $ip = $db->EscapeString($_REQUEST['ip']);
59                $sql = "UPDATE connections SET "."token_status='".TOKEN_INUSE."',"."user_mac='$mac',"."user_ip='$ip',"."last_updated=NOW()"."WHERE conn_id='{$info['conn_id']}';\n";
60                $db->ExecSqlUpdate($sql, false);
61
62                /* Logging in with a new token implies that all other active tokens should expire */
63                $token = $db->EscapeString($_REQUEST['token']);
64                $sql = "UPDATE connections SET "."timestamp_out=NOW(), token_status='".TOKEN_USED."' "."WHERE user_id = '{$info['user_id']}' AND token_status='".TOKEN_INUSE."' AND token!='$token';\n";
65                $db->ExecSqlUpdate($sql, false);
66                /* Delete all unused tokens for this user, so we don't fill the database with them */
67                $sql = "DELETE FROM connections "."WHERE token_status='".TOKEN_UNUSED."' AND user_id = '{$info['user_id']}';\n";
68                $db->ExecSqlUpdate($sql, false);
69        }
70
71        /** Update traffic counters */
72        function acctUpdate($info, $incoming, $outgoing)
73        {
74                // Write traffic counters to database
75                global $db;
76                $db->ExecSqlUpdate("UPDATE connections SET "."incoming='$incoming',"."outgoing='$outgoing',"."last_updated=NOW() "."WHERE conn_id='{$info['conn_id']}'");
77        }
78
79        /** Final update and stop accounting */
80        function acctStop($info)
81        {
82                // Stop traffic counters update
83                global $db;
84                $db->ExecSqlUpdate("UPDATE connections SET "."timestamp_out=NOW(),"."token_status='".TOKEN_USED."' "."WHERE conn_id='{$info['conn_id']}';\n");
85        }
86
87} // End class
88?>
Note: See TracBrowser for help on using the browser.