Show
Ignore:
Timestamp:
03/16/06 18:47:35 (7 years ago)
Author:
max-horvath
Message:

"2006-03-16 Max Horvath <max.horvath@…>

  • updated language files (new german strings have already been translated)
  • added LDAP authentication
  • Dependencies class can check for an PHP extension now
  • Dependencies class can check for multiple files on a single dependency now
  • Authentication classes moved to it's own directory
  • The getAuthenticator method now uses the much safer and faster call_user_func_array function to return an authenticator object
  • the available authenticator classes are now being displayed in a select box on the network administration page
  • the link to and the Google hotspots map as is won't be shown to an unauthenticated user at a real hotspot"
Files:
1 modified

Legend:

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

    r990 r994  
    3838 * @subpackage Authenticators 
    3939 * @author     Benoit Gregoire <bock@step.polymtl.ca> 
     40 * @author     Max Horvath <max.horvath@maxspot.de> 
    4041 * @copyright  2005-2006 Benoit Gregoire, Technologies Coeus inc. 
     42 * @copyright  2006 Max Horvath, maxspot GmbH 
    4143 * @version    Subversion $Id$ 
    4244 * @link       http://www.wifidog.org/ 
     
    4749 */ 
    4850require_once('classes/Network.php'); 
     51require_once('classes/Node.php'); 
    4952require_once('classes/Session.php'); 
     53require_once('classes/User.php'); 
    5054 
    5155/** 
     
    5559 * @subpackage Authenticators 
    5660 * @author     Benoit Gregoire <bock@step.polymtl.ca> 
     61 * @author     Max Horvath <max.horvath@maxspot.de> 
    5762 * @copyright  2005-2006 Benoit Gregoire, Technologies Coeus inc. 
     63 * @copyright  2006 Max Horvath, maxspot GmbH 
    5864 */ 
    5965abstract class Authenticator 
    6066{ 
     67    /** 
     68     * Object of current network 
     69     * 
     70     * @var object 
     71     * 
     72     * @access private 
     73     */ 
    6174    private $mNetwork; 
    6275 
    63     function __construct($network_id) 
     76    /** 
     77     * Constructor 
     78     * 
     79     * @param string $network_id Id of network 
     80     * 
     81     * @return void 
     82     * 
     83     * @access public 
     84     */ 
     85    public function __construct($network_id) 
    6486    { 
    6587        $this->mNetwork = Network::getObject($network_id); 
    6688    } 
    6789 
     90    /** 
     91     * Returns object of current network 
     92     * 
     93     * @return object Object of current network 
     94     * 
     95     * @access public 
     96     */ 
    6897    public function getNetwork() 
    6998    { 
     
    71100    } 
    72101 
    73     /** Attempts to login a user against the authentication source.  If successfull, returns a User object */ 
    74     function login() 
    75     { 
    76     } 
    77  
    78     /** Logs out the user 
    79      * $conn_id:  The connection id for the connection to work on.  Optionnal. 
    80      *  If  it is not present, the behaviour depends if the network supports 
    81      * multiple logins.  If it does not, all connections associated with the 
    82      * current user will be destroyed.  If it does, only the connections 
    83      * tied to the current node will be destroyed */ 
    84     function logout($conn_id = null) 
     102    /** 
     103     * Attempts to login a user against the authentication source 
     104     * 
     105     * If successfull, returns a User object. 
     106     * 
     107     * @access public 
     108     */ 
     109    public function login() 
     110    { 
     111        // Must be defined in child class 
     112    } 
     113 
     114    /** 
     115     * Logs out the user 
     116     * 
     117     * @param string $conn_id The connection id for the connection to work on. 
     118     *                        If  it is not present, the behaviour depends if 
     119     *                        the network supports multiple logins. If it does 
     120     *                        not, all connections associated with the current 
     121     *                        user will be destroyed. If it does, only the 
     122     *                        connections tied to the current node will be 
     123     *                        destroyed. 
     124     * 
     125     * @return void 
     126     * 
     127     * @access public 
     128     */ 
     129    public function logout($conn_id = null) 
    85130    { 
    86131        // Define globals 
     
    89134 
    90135        $conn_id = $db->escapeString($conn_id); 
    91         if (!empty ($conn_id)) 
    92         { 
     136 
     137        if (!empty ($conn_id)) { 
    93138            $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); 
    94139 
    95             $user = User :: getObject($info['user_id']); 
     140            $user = User::getObject($info['user_id']); 
    96141            $network = $user->getNetwork(); 
    97142            $splash_user_id = $network->getSplashOnlyUser()->getId(); 
    98143            $this->acctStop($conn_id); 
    99         } 
    100         else 
    101         { 
    102             $user = User :: getCurrentUser(); 
     144        } else { 
     145            $user = User::getCurrentUser(); 
    103146            $network = $user->getNetwork(); 
    104147            $splash_user_id = $network->getSplashOnlyUser()->getId(); 
    105             if ($splash_user_id != $user->getId() && $node = Node :: getCurrentNode()) 
    106             { 
    107                 //Try to destroy all connections tied to the current node 
    108                 $sql = "SELECT conn_id FROM connections WHERE user_id = '{$user->getId()}' AND node_id='{$node->getId()}' AND token_status='".TOKEN_INUSE."';\n"; 
     148 
     149            if ($splash_user_id != $user->getId() && $node = Node::getCurrentNode()) { 
     150                // Try to destroy all connections tied to the current node 
     151                $sql = "SELECT conn_id FROM connections WHERE user_id = '{$user->getId()}' AND node_id='{$node->getId()}' AND token_status='".TOKEN_INUSE."';"; 
    109152                $conn_rows = null; 
    110153                $db->execSql($sql, $conn_rows, false); 
    111                 if ($conn_rows) 
    112                 { 
    113                     foreach ($conn_rows as $conn_row) 
    114                     { 
     154 
     155                if ($conn_rows) { 
     156                    foreach ($conn_rows as $conn_row) { 
    115157                        $this->acctStop($conn_row['conn_id']); 
    116158                    } 
     
    119161        } 
    120162 
    121         if ($splash_user_id != $user->getId() && $network->getMultipleLoginAllowed() == false) 
    122         { 
    123             /* The user isn't the splash_only user and the network config does not allow multiple logins. 
    124              * Logging in with a new token implies that all other active tokens should expire */ 
    125             $sql = "SELECT conn_id FROM connections WHERE user_id = '{$user->getId()}' AND token_status='".TOKEN_INUSE."';\n"; 
     163        if ($splash_user_id != $user->getId() && $network->getMultipleLoginAllowed() === false) { 
     164            /* 
     165             * The user isn't the splash_only user and the network config does 
     166             * not allow multiple logins. Logging in with a new token implies 
     167             * that all other active tokens should expire 
     168             */ 
     169            $sql = "SELECT conn_id FROM connections WHERE user_id = '{$user->getId()}' AND token_status='".TOKEN_INUSE."';"; 
    126170            $conn_rows = null; 
    127171            $db->execSql($sql, $conn_rows, false); 
    128             if ($conn_rows) 
    129             { 
    130                 foreach ($conn_rows as $conn_row) 
    131                 { 
     172 
     173            if ($conn_rows) { 
     174                foreach ($conn_rows as $conn_row) { 
    132175                    $this->acctStop($conn_row['conn_id']); 
    133176                } 
     
    141184    } 
    142185 
    143     /** Start accounting traffic for the user 
    144      * $conn_id:  The connection id for the connection to work on */ 
    145     function acctStart($conn_id) 
    146     { 
     186    /** 
     187     * Start accounting traffic for the user 
     188     * 
     189     * @param string $conn_id The connection id for the connection to work on 
     190     * 
     191     * @return void 
     192     * 
     193     * @access public 
     194     */ 
     195    public function acctStart($conn_id) 
     196    { 
     197        // Define globals 
    147198        global $db; 
     199 
    148200        $conn_id = $db->escapeString($conn_id); 
    149201        $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); 
    150         $network = Network :: getObject($info['network_id']); 
     202        $network = Network::getObject($info['network_id']); 
    151203        $splash_user_id = $network->getSplashOnlyUser()->getId(); 
    152204        $auth_response = $info['account_status']; 
    153         /* Login the user */ 
     205 
     206        // Login the user 
    154207        $mac = $db->escapeString($_REQUEST['mac']); 
    155208        $ip = $db->escapeString($_REQUEST['ip']); 
    156         $sql = "UPDATE connections SET "."token_status='".TOKEN_INUSE."',"."user_mac='$mac',"."user_ip='$ip',"."last_updated=NOW()"."WHERE conn_id='{$conn_id}';\n"; 
     209        $sql = "UPDATE connections SET "."token_status='".TOKEN_INUSE."',"."user_mac='$mac',"."user_ip='$ip',"."last_updated=NOW()"."WHERE conn_id='{$conn_id}';"; 
    157210        $db->execSqlUpdate($sql, false); 
    158         if ($splash_user_id != $info['user_id'] && $network->getMultipleLoginAllowed() == false) 
    159         { 
    160             /* The user isn't the splash_only user and the network config does not allow multiple logins. 
    161              * Logging in with a new token implies that all other active tokens should expire */ 
     211 
     212        if ($splash_user_id != $info['user_id'] && $network->getMultipleLoginAllowed() === false) { 
     213            /* 
     214             * The user isn't the splash_only user and the network config does 
     215             * not allow multiple logins. Logging in with a new token implies 
     216             * that all other active tokens should expire 
     217             */ 
    162218            $token = $db->escapeString($_REQUEST['token']); 
    163             $sql = "SELECT * FROM connections WHERE user_id = '{$info['user_id']}' AND token_status='".TOKEN_INUSE."' AND token!='$token';\n"; 
     219            $sql = "SELECT * FROM connections WHERE user_id = '{$info['user_id']}' AND token_status='".TOKEN_INUSE."' AND token!='$token';"; 
    164220            $conn_rows = array (); 
    165221            $db->execSql($sql, $conn_rows, false); 
    166             if (isset ($conn_rows)) 
    167             { 
    168                 foreach ($conn_rows as $conn_row) 
    169                 { 
     222 
     223            if (isset ($conn_rows)) { 
     224                foreach ($conn_rows as $conn_row) { 
    170225                    $this->acctStop($conn_row['conn_id']); 
    171226                } 
     
    173228        } 
    174229 
    175         /* Delete all unused tokens for this user, so we don't fill the database with them */ 
    176         $sql = "DELETE FROM connections "."WHERE token_status='".TOKEN_UNUSED."' AND user_id = '{$info['user_id']}';\n"; 
     230        /* 
     231         * Delete all unused tokens for this user, so we don't fill the database 
     232         * with them 
     233         */ 
     234        $sql = "DELETE FROM connections "."WHERE token_status='".TOKEN_UNUSED."' AND user_id = '{$info['user_id']}';"; 
    177235        $db->execSqlUpdate($sql, false); 
    178236    } 
    179237 
    180     /** Update traffic counters 
    181      * $conn_id: The connection id for the connection to work on */ 
    182     function acctUpdate($conn_id, $incoming, $outgoing) 
    183     { 
     238    /** 
     239     * Update traffic counters 
     240     * 
     241     * @param string $conn_id  The connection id for the connection to work on 
     242     * @param int    $incoming Incoming traffic in bytes 
     243     * @param int    $outgoing Outgoing traffic in bytes 
     244     * 
     245     * @return void 
     246     * 
     247     * @access public 
     248     */ 
     249    public function acctUpdate($conn_id, $incoming, $outgoing) 
     250    { 
     251        // Define globals 
     252        global $db; 
     253 
    184254        // Write traffic counters to database 
    185         global $db; 
    186255        $conn_id = $db->escapeString($conn_id); 
    187256        $db->execSqlUpdate("UPDATE connections SET "."incoming='$incoming',"."outgoing='$outgoing',"."last_updated=NOW() "."WHERE conn_id='{$conn_id}'"); 
    188257    } 
    189258 
    190     /** Final update and stop accounting 
    191      * $conn_id:  The connection id (the token id) for the connection to work on 
     259    /** 
     260     * Final update and stop accounting 
     261     * 
     262     * @param string $conn_id The connection id (the token id) for the 
     263     *                        connection to work on 
     264     * 
     265     * @return void 
     266     * 
     267     * @access public 
    192268     * */ 
    193     function acctStop($conn_id) 
    194     { 
     269    public function acctStop($conn_id) 
     270    { 
     271        // Define globals 
     272        global $db; 
     273 
    195274        // Stop traffic counters update 
    196         global $db; 
    197275        $conn_id = $db->escapeString($conn_id); 
    198276        $db->execSqlUpdate("UPDATE connections SET "."timestamp_out=NOW(),"."token_status='".TOKEN_USED."' "."WHERE conn_id='{$conn_id}';\n", false); 
     
    201279    /** 
    202280     * Property method that tells if the class allows registration 
    203      */ 
    204     function isRegistrationPermitted() 
     281     * 
     282     * @return bool Returns if the class allows registration 
     283     * 
     284     * @access public 
     285     */ 
     286    public function isRegistrationPermitted() 
    205287    { 
    206288        return false;