Show
Ignore:
Timestamp:
12/26/05 05:43:56 (7 years ago)
Author:
max-horvath
Message:

2005-12-26 Max Horvath <max.horvath@…>

  • added new headers to every source file
  • converted file to represent a tab as four (4) spaces
  • added PhpDocumentor? documentation
  • added WiFiDog skin to HTMLeditor
  • language selection in a content class now shows the language name instead of the language code
  • added caching support to content classes Langstring and TrivialLangstring?
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog-auth/wifidog/classes/Authenticator.php

    r760 r866  
    11<?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. 
     2 
     3/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 
     4 
     5// +-------------------------------------------------------------------+ 
     6// | WiFiDog Authentication Server                                     | 
     7// | =============================                                     | 
     8// |                                                                   | 
     9// | The WiFiDog Authentication Server is part of the WiFiDog captive  | 
     10// | portal suite.                                                     | 
     11// +-------------------------------------------------------------------+ 
     12// | PHP version 5 required.                                           | 
     13// +-------------------------------------------------------------------+ 
     14// | Homepage:     http://www.wifidog.org/                             | 
     15// | Source Forge: http://sourceforge.net/projects/wifidog/            | 
     16// +-------------------------------------------------------------------+ 
     17// | This program is free software; you can redistribute it and/or     | 
     18// | modify it under the terms of the GNU General Public License as    | 
     19// | published by the Free Software Foundation; either version 2 of    | 
     20// | the License, or (at your option) any later version.               | 
     21// |                                                                   | 
     22// | This program is distributed in the hope that it will be useful,   | 
     23// | but WITHOUT ANY WARRANTY; without even the implied warranty of    | 
     24// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     | 
     25// | GNU General Public License for more details.                      | 
     26// |                                                                   | 
     27// | You should have received a copy of the GNU General Public License | 
     28// | along with this program; if not, contact:                         | 
     29// |                                                                   | 
     30// | Free Software Foundation           Voice:  +1-617-542-5942        | 
     31// | 59 Temple Place - Suite 330        Fax:    +1-617-542-2652        | 
     32// | Boston, MA  02111-1307,  USA       gnu@gnu.org                    | 
     33// |                                                                   | 
     34// +-------------------------------------------------------------------+ 
     35 
     36/** 
     37 * @package    WiFiDogAuthServer 
     38 * @author     Benoit Gregoire <bock@step.polymtl.ca> 
     39 * @copyright  2005 Benoit Gregoire <bock@step.polymtl.ca> - Technologies Coeus 
     40 * inc. 
     41 * @version    CVS: $Id$ 
     42 * @link       http://sourceforge.net/projects/wifidog/ 
    2443 */ 
    2544 
     
    2948abstract class Authenticator 
    3049{ 
    31         private $mNetwork; 
    32  
    33         function __construct($network_id) 
    34         { 
    35                 $this->mNetwork = Network::getObject($network_id); 
    36         } 
    37  
    38         public function getNetwork() 
    39         { 
    40                 return $this->mNetwork; 
    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          * $conn_id:  The connection id for the connection to work on.  Optionnal. 
    50          *  If  it is not present, the behaviour depends if the network supports 
    51          * multiple logins.  If it does not, all connections associated with the 
    52          * current user will be destroyed.  If it does, only the connections 
    53          * tied to the current node will be destroyed */ 
    54         function logout($conn_id = null) 
    55         { 
    56                 global $db; 
    57                 $conn_id = $db->escapeString($conn_id); 
    58                 if (!empty ($conn_id)) 
    59                 { 
    60                         $db->ExecSqlUniqueRes("SELECT NOW(), *, CASE WHEN ((NOW() - reg_date) > networks.validation_grace_time) THEN true ELSE false END AS validation_grace_time_expired FROM connections JOIN users ON (users.user_id=connections.user_id) JOIN networks ON (users.account_origin = networks.network_id) WHERE connections.conn_id='$conn_id'", $info, false); 
    61  
    62                         $user = User :: getObject($info['user_id']); 
    63                         $network = $user->getNetwork(); 
    64                         $splash_user_id = $network->getSplashOnlyUser()->getId(); 
    65                         $this->acctStop($conn_id); 
    66                 } 
    67                 else 
    68                 { 
    69                         $user = User :: getCurrentUser(); 
    70                         $network = $user->getNetwork(); 
    71                         $splash_user_id = $network->getSplashOnlyUser()->getId(); 
    72                         if ($splash_user_id != $user->getId() && $node = Node :: getCurrentNode()) 
    73                         { 
    74                                 //Try to destroy all connections tied to the current node 
    75                                 $sql = "SELECT conn_id FROM connections WHERE user_id = '{$user->getId()}' AND node_id='{$node->getId()}' AND token_status='".TOKEN_INUSE."';\n"; 
    76                                 $conn_rows = null; 
    77                                 $db->ExecSql($sql, $conn_rows, false); 
    78                                 if ($conn_rows) 
    79                                 { 
    80                                         foreach ($conn_rows as $conn_row) 
    81                                         { 
    82                                                 $this->acctStop($conn_row['conn_id']); 
    83                                         } 
    84                                 } 
    85                         } 
    86                 } 
    87  
    88                 if ($splash_user_id != $user->getId() && $network->getMultipleLoginAllowed() == false) 
    89                 { 
    90                         /* The user isn't the splash_only user and the network config does not allow multiple logins.   
    91                          * Logging in with a new token implies that all other active tokens should expire */ 
    92                         $sql = "SELECT conn_id FROM connections WHERE user_id = '{$user->getId()}' AND token_status='".TOKEN_INUSE."';\n"; 
    93                         $conn_rows = null; 
    94                         $db->ExecSql($sql, $conn_rows, false); 
    95                         if ($conn_rows) 
    96                         { 
    97                                 foreach ($conn_rows as $conn_row) 
    98                                 { 
    99                                         $this->acctStop($conn_row['conn_id']); 
    100                                 } 
    101                         } 
    102                 } 
    103                 global $session; 
    104                 $session->destroy(); 
    105  
    106         } 
    107  
    108         /** Start accounting traffic for the user  
    109          * $conn_id:  The connection id for the connection to work on */ 
    110         function acctStart($conn_id) 
    111         { 
    112                 global $db; 
    113                 $conn_id = $db->escapeString($conn_id); 
    114                 $db->ExecSqlUniqueRes("SELECT NOW(), *, CASE WHEN ((NOW() - reg_date) > networks.validation_grace_time) THEN true ELSE false END AS validation_grace_time_expired FROM connections JOIN users ON (users.user_id=connections.user_id) JOIN networks ON (users.account_origin = networks.network_id) WHERE connections.conn_id='$conn_id'", $info, false); 
    115                 $network = Network :: getObject($info['network_id']); 
    116                 $splash_user_id = $network->getSplashOnlyUser()->getId(); 
    117                 $auth_response = $info['account_status']; 
    118                 /* Login the user */ 
    119                 $mac = $db->EscapeString($_REQUEST['mac']); 
    120                 $ip = $db->EscapeString($_REQUEST['ip']); 
    121                 $sql = "UPDATE connections SET "."token_status='".TOKEN_INUSE."',"."user_mac='$mac',"."user_ip='$ip',"."last_updated=NOW()"."WHERE conn_id='{$conn_id}';\n"; 
    122                 $db->ExecSqlUpdate($sql, false); 
    123                 if ($splash_user_id != $info['user_id'] && $network->getMultipleLoginAllowed() == false) 
    124                 { 
    125                         /* The user isn't the splash_only user and the network config does not allow multiple logins.   
    126                          * Logging in with a new token implies that all other active tokens should expire */ 
    127                         $token = $db->EscapeString($_REQUEST['token']); 
    128                         $sql = "SELECT * FROM connections WHERE user_id = '{$info['user_id']}' AND token_status='".TOKEN_INUSE."' AND token!='$token';\n"; 
    129                         $conn_rows = array (); 
    130                         $db->ExecSql($sql, $conn_rows, false); 
    131                         if (isset ($conn_rows)) 
    132                         { 
    133                                 foreach ($conn_rows as $conn_row) 
    134                                 { 
    135                                         $this->acctStop($conn_row['conn_id']); 
    136                                 } 
    137                         } 
    138                 } 
    139  
    140                 /* Delete all unused tokens for this user, so we don't fill the database with them */ 
    141                 $sql = "DELETE FROM connections "."WHERE token_status='".TOKEN_UNUSED."' AND user_id = '{$info['user_id']}';\n"; 
    142                 $db->ExecSqlUpdate($sql, false); 
    143         } 
    144  
    145         /** Update traffic counters 
    146          * $conn_id: The connection id for the connection to work on */ 
    147         function acctUpdate($conn_id, $incoming, $outgoing) 
    148         { 
    149                 // Write traffic counters to database 
    150                 global $db; 
    151                 $conn_id = $db->escapeString($conn_id); 
    152                 $db->ExecSqlUpdate("UPDATE connections SET "."incoming='$incoming',"."outgoing='$outgoing',"."last_updated=NOW() "."WHERE conn_id='{$conn_id}'"); 
    153         } 
    154  
    155         /** Final update and stop accounting 
    156          * $conn_id:  The connection id (the token id) for the connection to work on 
    157          * */ 
    158         function acctStop($conn_id) 
    159         { 
    160                 // Stop traffic counters update 
    161                 global $db; 
    162                 $conn_id = $db->escapeString($conn_id); 
    163                 $db->ExecSqlUpdate("UPDATE connections SET "."timestamp_out=NOW(),"."token_status='".TOKEN_USED."' "."WHERE conn_id='{$conn_id}';\n", false); 
    164         } 
    165  
    166         /** 
    167          * Property method that tells if the class allows registration 
    168          */ 
    169         function isRegistrationPermitted() 
    170         { 
    171                 return false; 
    172         } 
    173  
    174 } // End class 
     50    private $mNetwork; 
     51 
     52    function __construct($network_id) 
     53    { 
     54        $this->mNetwork = Network::getObject($network_id); 
     55    } 
     56 
     57    public function getNetwork() 
     58    { 
     59        return $this->mNetwork; 
     60    } 
     61 
     62    /** Attempts to login a user against the authentication source.  If successfull, returns a User object */ 
     63    function login() 
     64    { 
     65    } 
     66 
     67    /** Logs out the user 
     68     * $conn_id:  The connection id for the connection to work on.  Optionnal. 
     69     *  If  it is not present, the behaviour depends if the network supports 
     70     * multiple logins.  If it does not, all connections associated with the 
     71     * current user will be destroyed.  If it does, only the connections 
     72     * tied to the current node will be destroyed */ 
     73    function logout($conn_id = null) 
     74    { 
     75        global $db; 
     76        $conn_id = $db->escapeString($conn_id); 
     77        if (!empty ($conn_id)) 
     78        { 
     79            $db->ExecSqlUniqueRes("SELECT NOW(), *, CASE WHEN ((NOW() - reg_date) > networks.validation_grace_time) THEN true ELSE false END AS validation_grace_time_expired FROM connections JOIN users ON (users.user_id=connections.user_id) JOIN networks ON (users.account_origin = networks.network_id) WHERE connections.conn_id='$conn_id'", $info, false); 
     80 
     81            $user = User :: getObject($info['user_id']); 
     82            $network = $user->getNetwork(); 
     83            $splash_user_id = $network->getSplashOnlyUser()->getId(); 
     84            $this->acctStop($conn_id); 
     85        } 
     86        else 
     87        { 
     88            $user = User :: getCurrentUser(); 
     89            $network = $user->getNetwork(); 
     90            $splash_user_id = $network->getSplashOnlyUser()->getId(); 
     91            if ($splash_user_id != $user->getId() && $node = Node :: getCurrentNode()) 
     92            { 
     93                //Try to destroy all connections tied to the current node 
     94                $sql = "SELECT conn_id FROM connections WHERE user_id = '{$user->getId()}' AND node_id='{$node->getId()}' AND token_status='".TOKEN_INUSE."';\n"; 
     95                $conn_rows = null; 
     96                $db->ExecSql($sql, $conn_rows, false); 
     97                if ($conn_rows) 
     98                { 
     99                    foreach ($conn_rows as $conn_row) 
     100                    { 
     101                        $this->acctStop($conn_row['conn_id']); 
     102                    } 
     103                } 
     104            } 
     105        } 
     106 
     107        if ($splash_user_id != $user->getId() && $network->getMultipleLoginAllowed() == false) 
     108        { 
     109            /* The user isn't the splash_only user and the network config does not allow multiple logins. 
     110             * Logging in with a new token implies that all other active tokens should expire */ 
     111            $sql = "SELECT conn_id FROM connections WHERE user_id = '{$user->getId()}' AND token_status='".TOKEN_INUSE."';\n"; 
     112            $conn_rows = null; 
     113            $db->ExecSql($sql, $conn_rows, false); 
     114            if ($conn_rows) 
     115            { 
     116                foreach ($conn_rows as $conn_row) 
     117                { 
     118                    $this->acctStop($conn_row['conn_id']); 
     119                } 
     120            } 
     121        } 
     122        global $session; 
     123        $session->destroy(); 
     124 
     125    } 
     126 
     127    /** Start accounting traffic for the user 
     128     * $conn_id:  The connection id for the connection to work on */ 
     129    function acctStart($conn_id) 
     130    { 
     131        global $db; 
     132        $conn_id = $db->escapeString($conn_id); 
     133        $db->ExecSqlUniqueRes("SELECT NOW(), *, CASE WHEN ((NOW() - reg_date) > networks.validation_grace_time) THEN true ELSE false END AS validation_grace_time_expired FROM connections JOIN users ON (users.user_id=connections.user_id) JOIN networks ON (users.account_origin = networks.network_id) WHERE connections.conn_id='$conn_id'", $info, false); 
     134        $network = Network :: getObject($info['network_id']); 
     135        $splash_user_id = $network->getSplashOnlyUser()->getId(); 
     136        $auth_response = $info['account_status']; 
     137        /* Login the user */ 
     138        $mac = $db->EscapeString($_REQUEST['mac']); 
     139        $ip = $db->EscapeString($_REQUEST['ip']); 
     140        $sql = "UPDATE connections SET "."token_status='".TOKEN_INUSE."',"."user_mac='$mac',"."user_ip='$ip',"."last_updated=NOW()"."WHERE conn_id='{$conn_id}';\n"; 
     141        $db->ExecSqlUpdate($sql, false); 
     142        if ($splash_user_id != $info['user_id'] && $network->getMultipleLoginAllowed() == false) 
     143        { 
     144            /* The user isn't the splash_only user and the network config does not allow multiple logins. 
     145             * Logging in with a new token implies that all other active tokens should expire */ 
     146            $token = $db->EscapeString($_REQUEST['token']); 
     147            $sql = "SELECT * FROM connections WHERE user_id = '{$info['user_id']}' AND token_status='".TOKEN_INUSE."' AND token!='$token';\n"; 
     148            $conn_rows = array (); 
     149            $db->ExecSql($sql, $conn_rows, false); 
     150            if (isset ($conn_rows)) 
     151            { 
     152                foreach ($conn_rows as $conn_row) 
     153                { 
     154                    $this->acctStop($conn_row['conn_id']); 
     155                } 
     156            } 
     157        } 
     158 
     159        /* Delete all unused tokens for this user, so we don't fill the database with them */ 
     160        $sql = "DELETE FROM connections "."WHERE token_status='".TOKEN_UNUSED."' AND user_id = '{$info['user_id']}';\n"; 
     161        $db->ExecSqlUpdate($sql, false); 
     162    } 
     163 
     164    /** Update traffic counters 
     165     * $conn_id: The connection id for the connection to work on */ 
     166    function acctUpdate($conn_id, $incoming, $outgoing) 
     167    { 
     168        // Write traffic counters to database 
     169        global $db; 
     170        $conn_id = $db->escapeString($conn_id); 
     171        $db->ExecSqlUpdate("UPDATE connections SET "."incoming='$incoming',"."outgoing='$outgoing',"."last_updated=NOW() "."WHERE conn_id='{$conn_id}'"); 
     172    } 
     173 
     174    /** Final update and stop accounting 
     175     * $conn_id:  The connection id (the token id) for the connection to work on 
     176     * */ 
     177    function acctStop($conn_id) 
     178    { 
     179        // Stop traffic counters update 
     180        global $db; 
     181        $conn_id = $db->escapeString($conn_id); 
     182        $db->ExecSqlUpdate("UPDATE connections SET "."timestamp_out=NOW(),"."token_status='".TOKEN_USED."' "."WHERE conn_id='{$conn_id}';\n", false); 
     183    } 
     184 
     185    /** 
     186     * Property method that tells if the class allows registration 
     187     */ 
     188    function isRegistrationPermitted() 
     189    { 
     190        return false; 
     191    } 
     192 
     193} 
     194 
     195/* 
     196 * Local variables: 
     197 * tab-width: 4 
     198 * c-basic-offset: 4 
     199 * c-hanging-comment-ender-p: nil 
     200 * End: 
     201 */ 
     202 
    175203?>