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