Show
Ignore:
Timestamp:
09/07/05 23:52:27 (8 years ago)
Author:
benoitg
Message:

2005-09-08 Benoit Gr�goire <bock@…>

  • MainUI: Move call to garbage_collect() here.
  • portal/index.php: New feature: Custom portal redirect.
  • rework much of the logout code
Files:
1 modified

Legend:

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

    r717 r722  
    11<?php 
     2 
    23/********************************************************************\ 
    34 * This program is free software; you can redistribute it and/or    * 
     
    3334                $this->mAccountOrigin = $account_orgin; 
    3435        } 
    35          
     36 
    3637        public function getAccountOrigin() 
    3738        { 
    38                 return $this->mAccountOrigin;  
     39                return $this->mAccountOrigin; 
    3940        } 
    4041 
     
    4445        } 
    4546 
    46         /** Logs out the user */ 
    47         function logout() 
     47        /** Logs out the user  
     48         * $conn_id:  The connection id for the connection to work on.  Optionnal. 
     49         *  If  it is not present, the behaviour depends if the network supports 
     50         * multiple logins.  If it does not, all connections associated with the 
     51         * current user will be destroyed.  If it does, only the connections 
     52         * tied to the current node will be destroyed */ 
     53        function logout($conn_id = null) 
    4854        { 
     55                global $db; 
     56                $conn_id = $db->escapeString($conn_id); 
     57                if (!empty ($conn_id)) 
     58                { 
     59                        $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); 
     60 
     61                        $user = User :: getObject($info['user_id']); 
     62                        $network = $user->getNetwork(); 
     63                        $splash_user_id = $network->getSplashOnlyUser()->getId(); 
     64                        $this->acctStop($conn_id); 
     65                } 
     66                else 
     67                { 
     68                        $user = User :: getCurrentUser(); 
     69                        $network = $user->getNetwork(); 
     70                        $splash_user_id = $network->getSplashOnlyUser()->getId(); 
     71                        if ($splash_user_id != $user->getId() && $node = Node :: getCurrentNode()) 
     72                        { 
     73                                //Try to destroy all connections tied to the current node 
     74                                $sql = "SELECT conn_id FROM connections WHERE user_id = '{$user->getId()}' AND node_id={$node->getId()} AND token_status='".TOKEN_INUSE."';\n"; 
     75                        $conn_rows = null; 
     76                                $db->ExecSql($sql, $conn_rows, false); 
     77                        if($conn_rows) 
     78                        { 
     79                                foreach ($conn_rows as $conn_row) 
     80                                { 
     81                                        $this->acctStop($conn_row['conn_id']); 
     82                                } 
     83                        } 
     84                        } 
     85                } 
     86 
     87                if ($splash_user_id != $user->getId() && $network->getMultipleLoginAllowed() == false) 
     88                { 
     89                        /* The user isn't the splash_only user and the network config does not allow multiple logins.   
     90                         * Logging in with a new token implies that all other active tokens should expire */ 
     91                        $sql = "SELECT conn_id FROM connections WHERE user_id = '{$user->getId()}' AND token_status='".TOKEN_INUSE."';\n"; 
     92                        $conn_rows = null; 
     93                        $db->ExecSql($sql, $conn_rows, false); 
     94                        if($conn_rows) 
     95                        { 
     96                                foreach ($conn_rows as $conn_row) 
     97                        { 
     98                                $this->acctStop($conn_row['conn_id']); 
     99                        } 
     100                        } 
     101                } 
     102                global $session; 
     103                $session->destroy(); 
     104 
    49105        } 
    50106 
     
    52108         * $conn_id:  The connection id for the connection to work on */ 
    53109        function acctStart($conn_id) 
    54         {//$info['conn_id'] 
     110        { 
     111                //$info['conn_id'] 
    55112                global $db; 
    56113                $conn_id = $db->escapeString($conn_id); 
    57114                $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); 
    58                 $network= Network::getObject($info['network_id']); 
     115                $network = Network :: getObject($info['network_id']); 
    59116                $splash_user_id = $network->getSplashOnlyUser()->getId(); 
    60117                $auth_response = $info['account_status']; 
     
    64121                $sql = "UPDATE connections SET "."token_status='".TOKEN_INUSE."',"."user_mac='$mac',"."user_ip='$ip',"."last_updated=NOW()"."WHERE conn_id='{$conn_id}';\n"; 
    65122                $db->ExecSqlUpdate($sql, false); 
    66                 if($splash_user_id != $info['user_id'] && $network->getMultipleLoginAllowed()==false) 
     123                if ($splash_user_id != $info['user_id'] && $network->getMultipleLoginAllowed() == false) 
    67124                { 
    68125                        /* The user isn't the splash_only user and the network config does not allow multiple logins.   
    69126                         * Logging in with a new token implies that all other active tokens should expire */ 
    70127                        $token = $db->EscapeString($_REQUEST['token']); 
    71                         $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"; 
    72                         $db->ExecSqlUpdate($sql, false); 
     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, true); 
     131                        foreach ($conn_rows as $conn_row) 
     132                        { 
     133                                $this->acctStop($conn_row['conn_id']); 
     134                        } 
    73135                } 
    74                  
     136 
    75137                /* Delete all unused tokens for this user, so we don't fill the database with them */ 
    76138                $sql = "DELETE FROM connections "."WHERE token_status='".TOKEN_UNUSED."' AND user_id = '{$info['user_id']}';\n"; 
     
    91153         * $conn_id:  The connection id (the token id) for the connection to work on 
    92154         * */ 
    93          function acctStop($conn_id) 
     155        function acctStop($conn_id) 
    94156        { 
    95157                // Stop traffic counters update 
     
    98160                $db->ExecSqlUpdate("UPDATE connections SET "."timestamp_out=NOW(),"."token_status='".TOKEN_USED."' "."WHERE conn_id='{$conn_id}';\n", false); 
    99161        } 
    100          
     162 
    101163        /** 
    102164         * Property method that tells if the class allows registration