source: sandbox/newExpressoMail/header.session.inc.php @ 6801

Revision 6801, 3.7 KB checked in by cristiano, 12 years ago (diff)

Ticket #2967 - Melhoria na sessão do usuário do expresso

Line 
1<?php
2require_once(__DIR__.'/prototype/api/esecurity.php');
3$s = new ESecurity();
4$s->valid();
5
6
7                /***************************************************************************
8                * Expresso Livre                                                           *
9                * http://www.expressolivre.org                                             *
10                * --------------------------------------------                             *
11                *  This program is free software; you can redistribute it and/or modify it *
12                *  under the terms of the GNU General Public License as published by the   *
13                *  Free Software Foundation; either version 2 of the License, or (at your  *
14                *  option) any later version.                                              *
15                \**************************************************************************/
16               
17if ( isset( $_COOKIE[ 'sessionid' ] ) )
18        session_id( $_COOKIE[ 'sessionid' ] );
19
20if( !isset($_SESSION) )
21    session_start( );
22
23$sess = $_SESSION[ 'phpgw_session' ];
24$invalidSession = false;
25$user_agent = array();
26if (isset($GLOBALS['phpgw']) && !isset($_SESSION['connection_db_info'])){
27        $_SESSION['phpgw_info']['admin']['server']['sessions_checkip'] = $GLOBALS['phpgw_info']['server']['sessions_checkip'];
28        if($GLOBALS['phpgw_info']['server']['use_https'] == 1) {
29                $new_ip = (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR']."," : ""). $_SERVER['REMOTE_ADDR'];
30                $GLOBALS['phpgw']->db->query("UPDATE phpgw_access_log SET ip='$new_ip' WHERE account_id <> 0 and lo = 0 and sessionid='{$GLOBALS['sessionid']}'",__LINE__,__FILE__);
31        }
32         $GLOBALS['phpgw']->db->query("select trim(sessionid),".($_SESSION['phpgw_info']['admin']['server']['sessions_checkip'] ? "ip," : "")."browser from phpgw_access_log where account_id <> 0 and lo = 0 and sessionid='{$GLOBALS['sessionid']}' limit 1",__LINE__,__FILE__);
33        $GLOBALS['phpgw']->db->next_record();
34        if($GLOBALS['phpgw']->db->row( ))
35                $_SESSION['connection_db_info']['user_auth'] = implode("",$GLOBALS['phpgw']->db->row( ));
36}
37if($_SESSION['connection_db_info']['user_auth']){
38        $invalidSession = true;
39        $http_user_agent = substr($_SERVER[ 'HTTP_USER_AGENT' ],0,199);
40        $user_ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? array($_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_X_FORWARDED_FOR']) : array($_SERVER['REMOTE_ADDR']);
41        $user_agent[] = ($_SESSION['phpgw_info']['admin']['server']['sessions_checkip'] ? "{$sess['session_id']}{$user_ip[0]}" : "{$sess['session_id']}").$http_user_agent;
42        if(count($user_ip) == 2) {
43                $user_agent[] = "{$sess['session_id']}{$user_ip[1]}".$http_user_agent;
44                $user_agent[] = $sess['session_id'].implode(",",array_reverse($user_ip)).$http_user_agent;
45        }
46        $pconnection_id = $_SESSION['connection_db_info']['user_auth'];
47        if(array_search($pconnection_id, $user_agent)  !== FALSE) {
48                $invalidSession = false;
49        }
50}
51if (empty($_SESSION['phpgw_session']['session_id']) || $invalidSession)
52{
53        if($_SESSION['connection_db_info']['user_auth'] && !strstr($_SERVER['SCRIPT_NAME'],"/controller.php")) {
54                error_log( '[ INVALID SESSION ] >>>>' .$_SESSION['connection_db_info']['user_auth'].'<<<< - >>>>' . implode("",$user_agent), 0 );
55                $GLOBALS['phpgw']->session->phpgw_setcookie('sessionid');
56                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw_info']['server']['webserver_url'].'/login.php?cd=10');
57        }
58
59        setcookie(session_name(),"",0); // Removing session cookie.
60        unset($_SESSION);                               // Removing session values.
61        // From ExpressoAjax response "nosession"
62        if(strstr($_SERVER['SCRIPT_NAME'],"/controller.php")){
63                echo serialize(array("nosession" => true));
64                exit;
65        }
66}
67else{
68        // From ExpressoAjax update session_dla (datetime last access). 
69        if(strstr($_SERVER['SCRIPT_NAME'],"/controller.php"))
70                $_SESSION['phpgw_session']['session_dla'] = time();
71
72}
73?>
Note: See TracBrowser for help on using the repository browser.