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

Revision 517, 3.5 KB (checked in by fproulx, 8 years ago)

2005-03-30 Fran�ois Proulx <francois.proulx@…>

  • Finished RADIUS authentication and accounting
  • Accounting Unique session ID is now based on the same token we use
  • Fixed all issues with lost_username, lost_password etc...
  • User class has new static function getUsersByEmail and getUsersByUsername
  • Added translations for new features
  • Translated the validation, lost password, username e-mails
  • Tested quite a bit, this version is considered stable
  • A few examples on how set different RADIUS or local authenticators can be found in the config.php
  • 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
4/********************************************************************\
5 * This program is free software; you can redistribute it and/or    *
6 * modify it under the terms of the GNU General Public License as   *
7 * published by the Free Software Foundation; either version 2 of   *
8 * the License, or (at your option) any later version.              *
9 *                                                                  *
10 * This program is distributed in the hope that it will be useful,  *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
13 * GNU General Public License for more details.                     *
14 *                                                                  *
15 * You should have received a copy of the GNU General Public License*
16 * along with this program; if not, contact:                        *
17 *                                                                  *
18 * Free Software Foundation           Voice:  +1-617-542-5942       *
19 * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
20 * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
21 *                                                                  *
22 \********************************************************************/
23/**@file Authenticator.php
24 * @author Copyright (C) 2005 Benoit Gr�goire <bock@step.polymtl.ca>,
25 * Technologies Coeus inc.
26 */
27
28/** Abstract class to represent an authentication source */
29abstract class Authenticator
30{
31        private $mAccountOrigin;
32
33        function __construct($account_orgin)
34        {
35                $this->mAccountOrigin = $account_orgin;
36        }
37       
38        public function getAccountOrigin()
39        {
40                return $this->mAccountOrigin; 
41        }
42
43        /** Attempts to login a user against the authentication source.  If successfull, returns a User object */
44        function login()
45        {
46        }
47
48        /** Logs out the user */
49        function logout()
50        {
51        }
52
53        /** Start accounting traffic for the user */
54        function acctStart($info)
55        {
56                global $db;
57                $auth_response = $info['account_status'];
58                /* Login the user */
59                $mac = $db->EscapeString($_REQUEST['mac']);
60                $ip = $db->EscapeString($_REQUEST['ip']);
61                $sql = "UPDATE connections SET "."token_status='".TOKEN_INUSE."',"."user_mac='$mac',"."user_ip='$ip',"."last_updated=NOW()"."WHERE conn_id='{$info['conn_id']}';\n";
62                $db->ExecSqlUpdate($sql, false);
63
64                /* Logging in with a new token implies that all other active tokens should expire */
65                $token = $db->EscapeString($_REQUEST['token']);
66                $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";
67                $db->ExecSqlUpdate($sql, false);
68                /* Delete all unused tokens for this user, so we don't fill the database with them */
69                $sql = "DELETE FROM connections "."WHERE token_status='".TOKEN_UNUSED."' AND user_id = '{$info['user_id']}';\n";
70                $db->ExecSqlUpdate($sql, false);
71        }
72
73        /** Update traffic counters */
74        function acctUpdate($info, $incoming, $outgoing)
75        {
76                // Write traffic counters to database
77                global $db;
78                $db->ExecSqlUpdate("UPDATE connections SET "."incoming='$incoming',"."outgoing='$outgoing',"."last_updated=NOW() "."WHERE conn_id='{$info['conn_id']}'");
79        }
80
81        /** Final update and stop accounting */
82        function acctStop($info)
83        {
84                // Stop traffic counters update
85                global $db;
86                $db->ExecSqlUpdate("UPDATE connections SET "."timestamp_out=NOW(),"."token_status='".TOKEN_USED."' "."WHERE conn_id='{$info['conn_id']}';\n");
87        }
88
89} // End class
90?>
91
92
Note: See TracBrowser for help on using the browser.