| 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 */ |
|---|
| 29 | abstract class Authenticator |
|---|
| 30 | { |
|---|
| 31 | protected $mAccountOrigin; |
|---|
| 32 | |
|---|
| 33 | function __construct($account_orgin) |
|---|
| 34 | { |
|---|
| 35 | $this->mAccountOrigin = $account_orgin; |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | /** Attempts to login a user against the authentication source. If successfull, returns a User object */ |
|---|
| 39 | function login() |
|---|
| 40 | { |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | /** Logs out the user */ |
|---|
| 44 | function logout() |
|---|
| 45 | { |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | /** Start accounting traffic for the user */ |
|---|
| 49 | function acctStart($info) |
|---|
| 50 | { |
|---|
| 51 | global $db; |
|---|
| 52 | $auth_response = $info['account_status']; |
|---|
| 53 | /* Login the user */ |
|---|
| 54 | $mac = $db->EscapeString($_REQUEST['mac']); |
|---|
| 55 | $ip = $db->EscapeString($_REQUEST['ip']); |
|---|
| 56 | $sql = "UPDATE connections SET "."token_status='".TOKEN_INUSE."',"."user_mac='$mac',"."user_ip='$ip',"."last_updated=NOW()"."WHERE conn_id='{$info['conn_id']}';\n"; |
|---|
| 57 | $db->ExecSqlUpdate($sql, false); |
|---|
| 58 | |
|---|
| 59 | /* Logging in with a new token implies that all other active tokens should expire */ |
|---|
| 60 | $token = $db->EscapeString($_REQUEST['token']); |
|---|
| 61 | $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"; |
|---|
| 62 | $db->ExecSqlUpdate($sql, false); |
|---|
| 63 | /* Delete all unused tokens for this user, so we don't fill the database with them */ |
|---|
| 64 | $sql = "DELETE FROM connections "."WHERE token_status='".TOKEN_UNUSED."' AND user_id = '{$info['user_id']}';\n"; |
|---|
| 65 | $db->ExecSqlUpdate($sql, false); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | /** Update traffic counters */ |
|---|
| 69 | function acctUpdate($info, $incoming, $outgoing) |
|---|
| 70 | { |
|---|
| 71 | // Write traffic counters to database |
|---|
| 72 | global $db; |
|---|
| 73 | $db->ExecSqlUpdate("UPDATE connections SET "."incoming='$incoming',"."outgoing='$outgoing',"."last_updated=NOW() "."WHERE conn_id='{$info['conn_id']}'"); |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | /** Final update and stop accounting */ |
|---|
| 77 | function acctStop($info) |
|---|
| 78 | { |
|---|
| 79 | // Stop traffic counters update |
|---|
| 80 | global $db; |
|---|
| 81 | $db->ExecSqlUpdate("UPDATE connections SET "."timestamp_out=NOW(),"."token_status='".TOKEN_USED."' "."WHERE conn_id='{$info['conn_id']}';\n"); |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | } // End class |
|---|
| 85 | ?> |
|---|
| 86 | |
|---|
| 87 | |
|---|