EGroupware /
egroupware
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * EGroupware API loader |
||
| 4 | * |
||
| 5 | * Rewritten by [email protected] to store the eGW enviroment |
||
| 6 | * (egw-object and egw_info-array) in a php-session and restore it from |
||
| 7 | * there instead of creating it completly new on each page-request. |
||
| 8 | * The enviroment gets now created by the egw-class |
||
| 9 | * |
||
| 10 | * This file was originaly written by Dan Kuykendall and Joseph Engo |
||
| 11 | * Copyright (C) 2000, 2001 Dan Kuykendall |
||
| 12 | * |
||
| 13 | * @link http://www.egroupware.org |
||
| 14 | * @author Ralf Becker <RalfBecker-AT-outdoor-training.de> |
||
| 15 | * @package api |
||
| 16 | * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License |
||
| 17 | */ |
||
| 18 | |||
| 19 | use EGroupware\Api\Session; |
||
| 20 | use EGroupware\Api\Egw; |
||
| 21 | |||
| 22 | // E_STRICT in PHP 5.4 gives various strict warnings in working code, which can NOT be easy fixed in all use-cases :-( |
||
| 23 | // Only variables should be assigned by reference, eg. soetemplate::tree_walk() |
||
| 24 | // Declaration of <extended method> should be compatible with <parent method>, varios places where method parameters change |
||
| 25 | // --> switching it off for now, as it makes error-log unusable |
||
| 26 | error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED); |
||
| 27 | if (function_exists('get_magic_quotes_runtime') && get_magic_quotes_runtime()) |
||
| 28 | { |
||
| 29 | set_magic_quotes_runtime(false); |
||
|
0 ignored issues
–
show
|
|||
| 30 | } |
||
| 31 | |||
| 32 | $egw_min_php_version = '7.1'; |
||
| 33 | if (!function_exists('version_compare') || version_compare(PHP_VERSION,$egw_min_php_version) < 0) |
||
| 34 | { |
||
| 35 | die("EGroupware requires PHP $egw_min_php_version or greater.<br />Please contact your System Administrator to upgrade PHP!"); |
||
| 36 | } |
||
| 37 | |||
| 38 | if (!defined('EGW_API_INC')) define('EGW_API_INC',PHPGW_API_INC); // this is to support the header upgrade |
||
|
0 ignored issues
–
show
|
|||
| 39 | |||
| 40 | /* Make sure the header.inc.php is current. */ |
||
| 41 | if (!isset($GLOBALS['egw_domain']) || $GLOBALS['egw_info']['server']['versions']['header'] < $GLOBALS['egw_info']['server']['versions']['current_header']) |
||
| 42 | { |
||
| 43 | echo '<center><b>You need to update your header.inc.php file to version '. |
||
| 44 | $GLOBALS['egw_info']['server']['versions']['current_header']. |
||
| 45 | ' by running <a href="setup/manageheader.php">setup/headeradmin</a>.</b></center>'; |
||
| 46 | exit; |
||
| 47 | } |
||
| 48 | |||
| 49 | /* Make sure the developer is following the rules. */ |
||
| 50 | if (!isset($GLOBALS['egw_info']['flags']['currentapp'])) |
||
| 51 | { |
||
| 52 | echo "<p><b>!!! YOU DO NOT HAVE YOUR \$GLOBALS['egw_info']['flags']['currentapp'] SET !!!<br>\n"; |
||
| 53 | echo '!!! PLEASE CORRECT THIS SITUATION !!!</b></p>'; |
||
| 54 | } |
||
| 55 | |||
| 56 | require_once(__DIR__.'/loader/common.php'); |
||
| 57 | |||
| 58 | // init eGW's sessions-handler and check if we can restore the eGW enviroment from the php-session |
||
| 59 | if (Session::init_handler()) |
||
| 60 | { |
||
| 61 | if ($GLOBALS['egw_info']['flags']['currentapp'] != 'login' && $GLOBALS['egw_info']['flags']['currentapp'] != 'logout') |
||
| 62 | { |
||
| 63 | if (is_array($_SESSION[Session::EGW_INFO_CACHE]) && $_SESSION[Session::EGW_OBJECT_CACHE] && $_SESSION[Session::EGW_REQUIRED_FILES]) |
||
| 64 | { |
||
| 65 | // marking the context as restored from the session, used by session->verify to not read the data from the db again |
||
| 66 | $GLOBALS['egw_info']['flags']['restored_from_session'] = true; |
||
| 67 | |||
| 68 | // restoring the egw_info-array |
||
| 69 | $GLOBALS['egw_info'] = array_merge($_SESSION[Session::EGW_INFO_CACHE],array('flags' => $GLOBALS['egw_info']['flags'])); |
||
| 70 | |||
| 71 | // include required class-definitions |
||
| 72 | if (is_array($_SESSION[Session::EGW_REQUIRED_FILES])) // all classes, which can not be autoloaded |
||
| 73 | { |
||
| 74 | foreach($_SESSION[Session::EGW_REQUIRED_FILES] as $file) |
||
| 75 | { |
||
| 76 | require_once($file); |
||
| 77 | } |
||
| 78 | } |
||
| 79 | $GLOBALS['egw'] = unserialize($_SESSION[Session::EGW_OBJECT_CACHE]); |
||
| 80 | |||
| 81 | if (is_object($GLOBALS['egw']) && ($GLOBALS['egw'] instanceof Egw)) // only egw object has wakeup2, setups egw_minimal eg. has not! |
||
| 82 | { |
||
| 83 | $GLOBALS['egw']->wakeup2(); // adapt the restored egw-object/enviroment to this request (eg. changed current app) |
||
| 84 | |||
| 85 | $GLOBALS['egw_info']['flags']['session_restore_time'] = microtime(true) - $GLOBALS['egw_info']['flags']['page_start_time']; |
||
| 86 | if (is_object($GLOBALS['egw']->translation)) return; // exit this file, as the rest of the file creates a new egw-object and -enviroment |
||
| 87 | } |
||
| 88 | // egw object could NOT be restored from the session, create a new one |
||
| 89 | unset($GLOBALS['egw']); |
||
| 90 | $GLOBALS['egw_info'] = array('flags'=>$GLOBALS['egw_info']['flags']); |
||
| 91 | unset($GLOBALS['egw_info']['flags']['restored_from_session']); |
||
| 92 | unset($_SESSION[Session::EGW_INFO_CACHE]); |
||
| 93 | unset($_SESSION[Session::EGW_REQUIRED_FILES]); |
||
| 94 | unset($_SESSION[Session::EGW_OBJECT_CACHE]); |
||
| 95 | } |
||
| 96 | } |
||
| 97 | else // destroy the session-cache if called by login or logout |
||
| 98 | { |
||
| 99 | unset($_SESSION[Session::EGW_INFO_CACHE]); |
||
| 100 | unset($_SESSION[Session::EGW_REQUIRED_FILES]); |
||
| 101 | unset($_SESSION[Session::EGW_OBJECT_CACHE]); |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | /****************************************************************************\ |
||
| 106 | * Multi-Domain support * |
||
| 107 | \****************************************************************************/ |
||
| 108 | |||
| 109 | $GLOBALS['egw_info']['user']['domain'] = Session::search_instance( |
||
| 110 | isset($_POST['login']) ? $_POST['login'] : (isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : $_SERVER['REMOTE_USER']), |
||
| 111 | Session::get_request('domain'),$GLOBALS['egw_info']['server']['default_domain'], |
||
| 112 | array($_SERVER['HTTP_HOST'], $_SERVER['SERVER_NAME']),$GLOBALS['egw_domain']); |
||
| 113 | |||
| 114 | $GLOBALS['egw_info']['server'] += $GLOBALS['egw_domain'][$GLOBALS['egw_info']['user']['domain']]; |
||
| 115 | |||
| 116 | // the egw-object instanciates all sub-classes (eg. $GLOBALS['egw']->db) and the egw_info array |
||
| 117 | $GLOBALS['egw'] = new Egw(array_keys($GLOBALS['egw_domain'])); |
||
| 118 | |||
| 119 | // store domain config user&pw as a hash (originals get unset) |
||
| 120 | $GLOBALS['egw_info']['server']['config_hash'] = Session::user_pw_hash($GLOBALS['egw_domain'][$GLOBALS['egw_info']['user']['domain']]['config_user'], |
||
| 121 | $GLOBALS['egw_domain'][$GLOBALS['egw_info']['user']['domain']]['config_passwd'],true); |
||
| 122 | |||
| 123 | if ($GLOBALS['egw_info']['flags']['currentapp'] != 'login' && !$GLOBALS['egw_info']['server']['show_domain_selectbox']) |
||
| 124 | { |
||
| 125 | unset($GLOBALS['egw_domain']); // we kill this for security reasons |
||
| 126 | unset($GLOBALS['egw_info']['server']['header_admin_user']); |
||
| 127 | unset($GLOBALS['egw_info']['server']['header_admin_password']); |
||
| 128 | } |
||
| 129 | |||
| 130 | // saving the the egw_info array and the egw-object in the session |
||
| 131 | if ($GLOBALS['egw_info']['flags']['currentapp'] != 'login') |
||
| 132 | { |
||
| 133 | $_SESSION[Session::EGW_INFO_CACHE] = $GLOBALS['egw_info']; |
||
| 134 | unset($_SESSION[Session::EGW_INFO_CACHE]['flags']); // dont save the flags, they change on each request |
||
| 135 | |||
| 136 | // dont save preferences, as Session::verify restores them from instance cache anyway |
||
| 137 | $_SESSION[Session::EGW_INFO_CACHE]['user']['preferences'] = array( |
||
| 138 | // we need user language as it is used before preferences get restored! |
||
| 139 | 'common' => array('lang' => $GLOBALS['egw_info']['user']['preferences']['common']['lang']), |
||
| 140 | ); |
||
| 141 | |||
| 142 | // dont save apps, as Session::verify restores them from instance cache anyway |
||
| 143 | unset($_SESSION[Session::EGW_INFO_CACHE]['apps']); |
||
| 144 | |||
| 145 | // store only which apps user has, Session::verify restores it from egw_info[apps] |
||
| 146 | $_SESSION[Session::EGW_INFO_CACHE]['user']['apps'] = array_keys((array)$_SESSION[Session::EGW_INFO_CACHE]['user']['apps']); |
||
| 147 | |||
| 148 | $_SESSION[Session::EGW_OBJECT_CACHE] = serialize($GLOBALS['egw']); |
||
| 149 | } |
||
| 150 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.