init.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. <?php
  2. /**
  3. * init.php -- initialisation file
  4. *
  5. * File should be loaded in every file in src/ or plugins that occupate an entire frame
  6. *
  7. * @copyright &copy; 2006 The SquirrelMail Project Team
  8. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  9. * @version $Id$
  10. * @package squirrelmail
  11. */
  12. /**
  13. * This is a development version so in order to track programmer mistakes we
  14. * set the error reporting to E_ALL
  15. FIXME: disabling this for now, because we now have $sm_debug_mode, but the problem with that is that we don't know what it will be until we have loaded the config file, a good 175 lines below after several important files have been included, etc. For now, we'll trust that developers have turned on E_ALL in php.ini anyway, but this can be uncommented if not.
  16. */
  17. //error_reporting(E_ALL);
  18. /**
  19. * Make sure we have a page name
  20. *
  21. */
  22. if ( !defined('PAGE_NAME') ) define('PAGE_NAME', NULL);
  23. /**
  24. * If register_globals are on, unregister globals.
  25. * Second test covers boolean set as string (php_value register_globals off).
  26. */
  27. if ((bool) ini_get('register_globals') &&
  28. strtolower(ini_get('register_globals'))!='off') {
  29. /**
  30. * Remove all globals that are not reserved by PHP
  31. * 'value' and 'key' are used by foreach. Don't unset them inside foreach.
  32. */
  33. foreach ($GLOBALS as $key => $value) {
  34. switch($key) {
  35. case 'HTTP_POST_VARS':
  36. case '_POST':
  37. case 'HTTP_GET_VARS':
  38. case '_GET':
  39. case 'HTTP_COOKIE_VARS':
  40. case '_COOKIE':
  41. case 'HTTP_SERVER_VARS':
  42. case '_SERVER':
  43. case 'HTTP_ENV_VARS':
  44. case '_ENV':
  45. case 'HTTP_POST_FILES':
  46. case '_FILES':
  47. case '_REQUEST':
  48. case 'HTTP_SESSION_VARS':
  49. case '_SESSION':
  50. case 'GLOBALS':
  51. case 'key':
  52. case 'value':
  53. break;
  54. default:
  55. unset($GLOBALS[$key]);
  56. }
  57. }
  58. // Unset variables used in foreach
  59. unset($GLOBALS['key']);
  60. unset($GLOBALS['value']);
  61. }
  62. /**
  63. * Used as a dummy value, e.g., for passing as an empty
  64. * hook argument (where the value is passed by reference,
  65. * and therefore NULL itself is not acceptable).
  66. */
  67. global $null;
  68. $null = NULL;
  69. /**
  70. * [#1518885] session.use_cookies = off breaks SquirrelMail
  71. *
  72. * When session cookies are not used, all http redirects, meta refreshes,
  73. * src/download.php and javascript URLs are broken. Setting must be set
  74. * before session is started.
  75. */
  76. if (!(bool)ini_get('session.use_cookies') ||
  77. ini_get('session.use_cookies') == 'off') {
  78. ini_set('session.use_cookies','1');
  79. }
  80. /**
  81. * calculate SM_PATH and calculate the base_uri
  82. * assumptions made: init.php is only called from plugins or from the src dir.
  83. * files in the plugin directory may not be part of a subdirectory called "src"
  84. *
  85. */
  86. if (isset($_SERVER['SCRIPT_NAME'])) {
  87. $a = explode('/', $_SERVER['SCRIPT_NAME']);
  88. } elseif (isset($HTTP_SERVER_VARS['SCRIPT_NAME'])) {
  89. $a = explode('/', $HTTP_SERVER_VARS['SCRIPT_NAME']);
  90. } else {
  91. $error = 'Unable to detect script environment. Please test your PHP '
  92. . 'settings and send your PHP core configuration, $_SERVER and '
  93. . '$HTTP_SERVER_VARS contents to the SquirrelMail developers.';
  94. die($error);
  95. }
  96. $sSM_PATH = '';
  97. for($i = count($a) -2; $i > -1; --$i) {
  98. $sSM_PATH .= '../';
  99. if ($a[$i] === 'src' || $a[$i] === 'plugins') {
  100. break;
  101. }
  102. }
  103. $base_uri = implode('/', array_slice($a, 0, $i)). '/';
  104. define('SM_PATH',$sSM_PATH);
  105. define('SM_BASE_URI', $base_uri);
  106. /**
  107. * global var $bInit is used to check if initialisation took place.
  108. * At this moment it's a workarounf for the include of addrbook_search_html
  109. * inside compose.php. If we found a better way then remove this. Do only use
  110. * this var if you know for sure a page can be called stand alone and be included
  111. * in another file.
  112. */
  113. $bInit = true;
  114. /**
  115. * This theme as a failsafe if no themes were found, or if we error
  116. * out before anything could be initialised.
  117. */
  118. $color = array();
  119. $color[0] = '#DCDCDC'; /* light gray TitleBar */
  120. $color[1] = '#800000'; /* red */
  121. $color[2] = '#CC0000'; /* light red Warning/Error Messages */
  122. $color[3] = '#A0B8C8'; /* green-blue Left Bar Background */
  123. $color[4] = '#FFFFFF'; /* white Normal Background */
  124. $color[5] = '#FFFFCC'; /* light yellow Table Headers */
  125. $color[6] = '#000000'; /* black Text on left bar */
  126. $color[7] = '#0000CC'; /* blue Links */
  127. $color[8] = '#000000'; /* black Normal text */
  128. $color[9] = '#ABABAB'; /* mid-gray Darker version of #0 */
  129. $color[10] = '#666666'; /* dark gray Darker version of #9 */
  130. $color[11] = '#770000'; /* dark red Special Folders color */
  131. $color[12] = '#EDEDED';
  132. $color[13] = '#800000'; /* (dark red) Color for quoted text -- > 1 quote */
  133. $color[14] = '#ff0000'; /* (red) Color for quoted text -- >> 2 or more */
  134. $color[15] = '#002266'; /* (dark blue) Unselectable folders */
  135. $color[16] = '#ff9933'; /* (orange) Highlight color */
  136. require(SM_PATH . 'include/constants.php');
  137. require(SM_PATH . 'functions/global.php');
  138. require(SM_PATH . 'functions/strings.php');
  139. require(SM_PATH . 'functions/arrays.php');
  140. /* load default configuration */
  141. require(SM_PATH . 'config/config_default.php');
  142. /* reset arrays in default configuration */
  143. $ldap_server = array();
  144. $plugins = array();
  145. $fontsets = array();
  146. $aTemplateSet = array();
  147. $aTemplateSet[0]['ID'] = 'default';
  148. $aTemplateSet[0]['NAME'] = 'Default';
  149. /* load site configuration */
  150. require(SM_PATH . 'config/config.php');
  151. /* load local configuration overrides */
  152. if (file_exists(SM_PATH . 'config/config_local.php')) {
  153. require(SM_PATH . 'config/config_local.php');
  154. }
  155. /**
  156. * Set PHP error reporting level based on the SquirrelMail debug mode
  157. */
  158. $error_level = 0;
  159. if ($sm_debug_mode & SM_DEBUG_MODE_SIMPLE)
  160. $error_level |= E_ERROR;
  161. if ($sm_debug_mode & SM_DEBUG_MODE_MODERATE
  162. || $sm_debug_mode & SM_DEBUG_MODE_ADVANCED)
  163. $error_level |= E_ALL;
  164. if ($sm_debug_mode & SM_DEBUG_MODE_STRICT)
  165. $error_level |= E_STRICT;
  166. error_reporting($error_level);
  167. require(SM_PATH . 'functions/plugin.php');
  168. require(SM_PATH . 'include/languages.php');
  169. require(SM_PATH . 'class/template/Template.class.php');
  170. require(SM_PATH . 'class/error.class.php');
  171. /**
  172. * If magic_quotes_runtime is on, SquirrelMail breaks in new and creative ways.
  173. * Force magic_quotes_runtime off.
  174. * tassium@squirrelmail.org - I put it here in the hopes that all SM code includes this.
  175. * If there's a better place, please let me know.
  176. */
  177. ini_set('magic_quotes_runtime','0');
  178. /* if running with magic_quotes_gpc then strip the slashes
  179. from POST and GET global arrays */
  180. if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc()) {
  181. sqstripslashes($_GET);
  182. sqstripslashes($_POST);
  183. }
  184. /* strip any tags added to the url from PHP_SELF.
  185. This fixes hand crafted url XXS expoits for any
  186. page that uses PHP_SELF as the FORM action */
  187. $_SERVER['PHP_SELF'] = strip_tags($_SERVER['PHP_SELF']);
  188. $PHP_SELF = php_self();
  189. /**
  190. * Initialize the session
  191. */
  192. /** set the name of the session cookie */
  193. if (!isset($session_name) || !$session_name) {
  194. $session_name = 'SQMSESSID';
  195. }
  196. /**
  197. * When session.auto_start is On we want to destroy/close the session
  198. */
  199. $sSessionAutostartName = session_name();
  200. $sCookiePath = null;
  201. if (isset($sSessionAutostartName) && $sSessionAutostartName !== $session_name) {
  202. $sCookiePath = ini_get('session.cookie_path');
  203. $sCookieDomain = ini_get('session.cookie_domain');
  204. // reset the cookie
  205. setcookie($sSessionAutostartName,'',time() - 604800,$sCookiePath,$sCookieDomain);
  206. @session_destroy();
  207. session_write_close();
  208. }
  209. /**
  210. * includes from classes stored in the session
  211. */
  212. require(SM_PATH . 'class/mime.class.php');
  213. ini_set('session.name' , $session_name);
  214. session_set_cookie_params (0, $base_uri);
  215. sqsession_is_active();
  216. /**
  217. * When on login page, have to reset the user session, making
  218. * sure to save session restore data first
  219. */
  220. if (PAGE_NAME == 'login') {
  221. if (!sqGetGlobalVar('session_expired_post', $sep, SQ_SESSION))
  222. $sep = '';
  223. if (!sqGetGlobalVar('session_expired_location', $sel, SQ_SESSION))
  224. $sel = '';
  225. sqsession_destroy();
  226. session_write_close();
  227. /**
  228. * in some rare instances, the session seems to stick
  229. * around even after destroying it (!!), so if it does,
  230. * we'll manually flatten the $_SESSION data
  231. */
  232. if (!empty($_SESSION))
  233. $_SESSION = array();
  234. /**
  235. * Allow administrators to define custom session handlers
  236. * for SquirrelMail without needing to change anything in
  237. * php.ini (application-level).
  238. *
  239. * In config_local.php, admin needs to put:
  240. *
  241. * $custom_session_handlers = array(
  242. * 'my_open_handler',
  243. * 'my_close_handler',
  244. * 'my_read_handler',
  245. * 'my_write_handler',
  246. * 'my_destroy_handler',
  247. * 'my_gc_handler',
  248. * );
  249. * session_module_name('user');
  250. * session_set_save_handler(
  251. * $custom_session_handlers[0],
  252. * $custom_session_handlers[1],
  253. * $custom_session_handlers[2],
  254. * $custom_session_handlers[3],
  255. * $custom_session_handlers[4],
  256. * $custom_session_handlers[5]
  257. * );
  258. *
  259. * We need to replicate that code once here because PHP has
  260. * long had a bug that resets the session handler mechanism
  261. * when the session data is also destroyed. Because of this
  262. * bug, even administrators who define custom session handlers
  263. * via a PHP pre-load defined in php.ini (auto_prepend_file)
  264. * will still need to define the $custom_session_handlers array
  265. * in config_local.php.
  266. */
  267. global $custom_session_handlers;
  268. if (!empty($custom_session_handlers)) {
  269. $open = $custom_session_handlers[0];
  270. $close = $custom_session_handlers[1];
  271. $read = $custom_session_handlers[2];
  272. $write = $custom_session_handlers[3];
  273. $destroy = $custom_session_handlers[4];
  274. $gc = $custom_session_handlers[5];
  275. session_module_name('user');
  276. session_set_save_handler($open, $close, $read, $write, $destroy, $gc);
  277. }
  278. sqsession_is_active();
  279. session_regenerate_id();
  280. // put session restore data back into session if necessary
  281. if (!empty($sel)) {
  282. sqsession_register($sel, 'session_expired_location');
  283. if (!empty($sep))
  284. sqsession_register($sep, 'session_expired_post');
  285. }
  286. }
  287. /**
  288. * SquirrelMail internal version number -- DO NOT CHANGE
  289. * $sm_internal_version = array (release, major, minor)
  290. */
  291. $SQM_INTERNAL_VERSION = explode('.', SM_VERSION, 3);
  292. $SQM_INTERNAL_VERSION[2] = intval($SQM_INTERNAL_VERSION[2]);
  293. /* load prefs system; even when user not logged in, should be OK to do this here */
  294. require(SM_PATH . 'functions/prefs.php');
  295. // FIXME: config/plugin_hooks.php has not yet been loaded (see a few lines below); so this hook call should I think not be working -- has anyone actually tested it? Is there any reason we cannot move this prefs code block down below "MAIN PLUGIN LOADING CODE HERE" (see below)? Reading the code, I *think* it should be OK, but.... Also, note that this code would then be placed immediately next to the config_override hook, and since it makes little sense to execute two hooks in a row, I will propose removing config_override (although sadly, it is less clear to plugin authors that they should use the prefs_backend hook to do any configuration override work in their plugin)
  296. $prefs_backend = do_hook('prefs_backend', $null);
  297. if (isset($prefs_backend) && !empty($prefs_backend) && file_exists(SM_PATH . $prefs_backend)) {
  298. require(SM_PATH . $prefs_backend);
  299. } elseif (isset($prefs_dsn) && !empty($prefs_dsn)) {
  300. require(SM_PATH . 'functions/db_prefs.php');
  301. } else {
  302. require(SM_PATH . 'functions/file_prefs.php');
  303. }
  304. /* if plugins are disabled only for one user and
  305. * the current user is NOT that user, turn them
  306. * back on
  307. */
  308. sqgetGlobalVar('username',$username,SQ_SESSION);
  309. if ($disable_plugins && !empty($disable_plugins_user)
  310. && $username != $disable_plugins_user) {
  311. $disable_plugins = false;
  312. }
  313. /* remove all plugins if they are disabled */
  314. if ($disable_plugins) {
  315. $plugins = array();
  316. }
  317. /**
  318. * Include Compatibility plugin if available.
  319. */
  320. if (!$disable_plugins && file_exists(SM_PATH . 'plugins/compatibility/functions.php'))
  321. include_once(SM_PATH . 'plugins/compatibility/functions.php');
  322. /**
  323. * MAIN PLUGIN LOADING CODE HERE
  324. * On init, we no longer need to load all plugin setup files.
  325. * Now, we load the statically generated hook registrations here
  326. * and let the hook calls include only the plugins needed.
  327. */
  328. $squirrelmail_plugin_hooks = array();
  329. if (!$disable_plugins && file_exists(SM_PATH . 'config/plugin_hooks.php')) {
  330. require(SM_PATH . 'config/plugin_hooks.php');
  331. }
  332. /**
  333. * allow plugins to override main configuration; hook is placed
  334. * here to allow plugins to use session information to do their work
  335. */
  336. do_hook('config_override', $null);
  337. /**
  338. * DISABLED.
  339. * Remove globalized session data in rg=on setups
  340. *
  341. * Code can be utilized when session is started, but data is not loaded.
  342. * We have already loaded configuration and other important vars. Can't
  343. * clean session globals here, beside, the cleanout of globals at the
  344. * top of this file will have removed anything this code would find anyway.
  345. if ((bool) @ini_get('register_globals') &&
  346. strtolower(ini_get('register_globals'))!='off') {
  347. foreach ($_SESSION as $key => $value) {
  348. unset($GLOBALS[$key]);
  349. }
  350. }
  351. */
  352. sqsession_register(SM_BASE_URI,'base_uri');
  353. /**
  354. * Retrieve the language cookie
  355. */
  356. if (! sqgetGlobalVar('squirrelmail_language',$squirrelmail_language,SQ_COOKIE)) {
  357. $squirrelmail_language = '';
  358. }
  359. /**
  360. * Do something special for some pages. This is based on the PAGE_NAME constant
  361. * set at the top of every page.
  362. */
  363. switch (PAGE_NAME) {
  364. case 'style':
  365. // need to get the right template set up
  366. //
  367. sqGetGlobalVar('templateid', $templateid, SQ_GET);
  368. // sanitize just in case...
  369. //
  370. $templateid = preg_replace('/(\.\.\/){1,}/', '', $templateid);
  371. // make sure given template actually is available
  372. //
  373. $found_templateset = false;
  374. for ($i = 0; $i < count($aTemplateSet); ++$i) {
  375. if ($aTemplateSet[$i]['ID'] == $templateid) {
  376. $found_templateset = true;
  377. break;
  378. }
  379. }
  380. // FIXME: do we need/want to check here for actual (physical) presence of template sets?
  381. // selected template not available, fall back to default template
  382. //
  383. if (!$found_templateset) {
  384. $sTemplateID = Template::get_default_template_set();
  385. } else {
  386. $sTemplateID = $templateid;
  387. }
  388. session_write_close();
  389. break;
  390. case 'mailto':
  391. // nothing to do
  392. break;
  393. case 'redirect':
  394. require(SM_PATH . 'functions/auth.php');
  395. //nobreak;
  396. case 'login':
  397. require(SM_PATH . 'functions/display_messages.php' );
  398. require(SM_PATH . 'functions/page_header.php');
  399. require(SM_PATH . 'functions/html.php');
  400. // reset template file cache
  401. //
  402. $sTemplateID = Template::get_default_template_set();
  403. Template::cache_template_file_hierarchy(TRUE);
  404. /**
  405. * Make sure icon variables are setup for the login page.
  406. */
  407. $icon_theme = $icon_themes[$icon_theme_def]['PATH'];
  408. /*
  409. * NOTE: The $icon_theme_path var should contain the path to the icon
  410. * theme to use. If the admin has disabled icons, or the user has
  411. * set the icon theme to "None," no icons will be used.
  412. */
  413. $icon_theme_path = (!$use_icons || $icon_theme=='none') ? NULL : ($icon_theme == 'template' ? SM_PATH . Template::calculate_template_images_directory($sTemplateID) : $icon_theme);
  414. /**
  415. * cleanup old cookies with a cookie path the same as the standard php.ini
  416. * cookie path. All previous SquirrelMail version used the standard php.ini
  417. * cookie path for storing the session name. That behaviour changed.
  418. */
  419. if ($sCookiePath !== SM_BASE_URI) {
  420. /**
  421. * do not delete the standard sessions with session.name is i.e. PHPSESSID
  422. * because they probably belong to other php apps
  423. */
  424. if (ini_get('session.name') !== $sSessionAutostartName) {
  425. // This does not work. Sometimes the cookie with SQSESSID=deleted and path /
  426. // is picked up in webmail.php => login will fail
  427. //sqsetcookie(ini_get('session.name'),'',0,$sCookiePath);
  428. }
  429. }
  430. break;
  431. default:
  432. require(SM_PATH . 'functions/display_messages.php' );
  433. require(SM_PATH . 'functions/page_header.php');
  434. require(SM_PATH . 'functions/html.php');
  435. /**
  436. * Check if we are logged in
  437. */
  438. require(SM_PATH . 'functions/auth.php');
  439. if ( !sqsession_is_registered('user_is_logged_in') ) {
  440. // use $message to indicate what logout text the user
  441. // will see... if 0, typical "You must be logged in"
  442. // if 1, information that the user session was saved
  443. // and will be resumed after (re)login
  444. //
  445. $message = 0;
  446. // First we store some information in the new session to prevent
  447. // information-loss.
  448. //
  449. $session_expired_post = $_POST;
  450. $session_expired_location = PAGE_NAME;
  451. if (!sqsession_is_registered('session_expired_post')) {
  452. sqsession_register($session_expired_post,'session_expired_post');
  453. }
  454. if (!sqsession_is_registered('session_expired_location')) {
  455. sqsession_register($session_expired_location,'session_expired_location');
  456. if ($session_expired_location == 'compose')
  457. $message = 1;
  458. }
  459. // signout page will deal with users who aren't logged
  460. // in on its own; don't show error here
  461. //
  462. if ( PAGE_NAME == 'signout' ) {
  463. return;
  464. }
  465. /**
  466. * Initialize the template object (logout_error uses it)
  467. */
  468. /*
  469. * $sTemplateID is not initialized when a user is not logged in, so we
  470. * will use the config file defaults here. If the neccesary variables
  471. * are net set, force a default value.
  472. */
  473. $sTemplateID = Template::get_default_template_set();
  474. $oTemplate = Template::construct_template($sTemplateID);
  475. set_up_language($squirrelmail_language, true);
  476. if (!$message)
  477. logout_error( _("You must be logged in to access this page.") );
  478. else
  479. logout_error( _("Your session has expired, but will be resumed after logging in again.") );
  480. exit;
  481. }
  482. sqgetGlobalVar('authz',$authz,SQ_SESSION);
  483. /**
  484. * Setting the prefs backend
  485. */
  486. sqgetGlobalVar('prefs_cache', $prefs_cache, SQ_SESSION );
  487. sqgetGlobalVar('prefs_are_cached', $prefs_are_cached, SQ_SESSION );
  488. if ( !sqsession_is_registered('prefs_are_cached') ||
  489. !isset( $prefs_cache) ||
  490. !is_array( $prefs_cache)) {
  491. $prefs_are_cached = false;
  492. $prefs_cache = false; //array();
  493. }
  494. /**
  495. * initializing user settings
  496. */
  497. require(SM_PATH . 'include/load_prefs.php');
  498. // i do not understand the frames language cookie story
  499. /**
  500. * We'll need this to later have a noframes version
  501. *
  502. * Check if the user has a language preference, but no cookie.
  503. * Send him a cookie with his language preference, if there is
  504. * such discrepancy.
  505. */
  506. $my_language = getPref($data_dir, $username, 'language');
  507. if ($my_language != $squirrelmail_language) {
  508. sqsetcookie('squirrelmail_language', $my_language, time()+2592000, $base_uri);
  509. }
  510. // /dont understand
  511. /**
  512. * Set up the language.
  513. */
  514. $err=set_up_language(getPref($data_dir, $username, 'language'));
  515. // Japanese translation used without mbstring support
  516. if ($err==2) {
  517. $sError = "<p>Your administrator needs to have PHP installed with the multibyte string extension enabled (using configure option --enable-mbstring).</p>\n"
  518. . "<p>This system has assumed that you accidently switched to Japanese and has reverted your language preference to English.</p>\n"
  519. . "<p>Please refresh this page in order to continue using your webmail.</p>\n";
  520. error_box($sError);
  521. }
  522. $timeZone = getPref($data_dir, $username, 'timezone');
  523. /* Check to see if we are allowed to set the TZ environment variable.
  524. * We are able to do this if ...
  525. * safe_mode is disabled OR
  526. * safe_mode_allowed_env_vars is empty (you are allowed to set any) OR
  527. * safe_mode_allowed_env_vars contains TZ
  528. */
  529. $tzChangeAllowed = (!ini_get('safe_mode')) ||
  530. !strcmp(ini_get('safe_mode_allowed_env_vars'),'') ||
  531. preg_match('/^([\w_]+,)*TZ/', ini_get('safe_mode_allowed_env_vars'));
  532. if ( $timeZone != SMPREF_NONE && ($timeZone != "")
  533. && $tzChangeAllowed ) {
  534. // get time zone key, if strict or custom strict timezones are used
  535. if (isset($time_zone_type) &&
  536. ($time_zone_type == 1 || $time_zone_type == 3)) {
  537. /* load time zone functions */
  538. require(SM_PATH . 'include/timezones.php');
  539. $realTimeZone = sq_get_tz_key($timeZone);
  540. } else {
  541. $realTimeZone = $timeZone;
  542. }
  543. // set time zone
  544. if ($realTimeZone) {
  545. putenv("TZ=".$realTimeZone);
  546. }
  547. }
  548. /**
  549. * php 5.1.0 added time zone functions. Set time zone with them in order
  550. * to prevent E_STRICT notices and allow time zone modifications in safe_mode.
  551. */
  552. if (function_exists('date_default_timezone_set')) {
  553. if ($timeZone != SMPREF_NONE && $timeZone != "") {
  554. date_default_timezone_set($timeZone);
  555. } else {
  556. // interface runs on server's time zone. Remove php E_STRICT complains
  557. $default_timezone = @date_default_timezone_get();
  558. date_default_timezone_set($default_timezone);
  559. }
  560. }
  561. break;
  562. }
  563. /*
  564. * $sTemplateID is not initialized when a user is not logged in, so we
  565. * will use the config file defaults here. If the neccesary variables
  566. * are not set, force a default value.
  567. *
  568. * If the user is logged in, $sTemplateID will be set in load_prefs.php,
  569. * so we shouldn't change it here.
  570. */
  571. if (!isset($sTemplateID)) {
  572. $sTemplateID = Template::get_default_template_set();
  573. $icon_theme_path = !$use_icons ? NULL : Template::calculate_template_images_directory($sTemplateID);
  574. }
  575. // template object may have already been constructed in load_prefs.php
  576. //
  577. if (empty($oTemplate)) {
  578. $oTemplate = Template::construct_template($sTemplateID);
  579. }
  580. // We want some variables to always be available to the template
  581. //
  582. $oTemplate->assign('javascript_on',
  583. (sqGetGlobalVar('user_is_logged_in', $user_is_logged_in, SQ_SESSION)
  584. ? checkForJavascript() : 0));
  585. $oTemplate->assign('base_uri', sqm_baseuri());
  586. $always_include = array('sTemplateID', 'icon_theme_path');
  587. foreach ($always_include as $var) {
  588. $oTemplate->assign($var, (isset($$var) ? $$var : NULL));
  589. }
  590. // A few output elements are used often, so just get them once here
  591. //
  592. $nbsp = $oTemplate->fetch('non_breaking_space.tpl');
  593. $br = $oTemplate->fetch('line_break.tpl');
  594. /**
  595. * Initialize our custom error handler object
  596. */
  597. $oErrorHandler = new ErrorHandler($oTemplate,'error_message.tpl');
  598. /**
  599. * Activate custom error handling
  600. */
  601. if (version_compare(PHP_VERSION, "4.3.0", ">=")) {
  602. $oldErrorHandler = set_error_handler(array($oErrorHandler, 'SquirrelMailErrorhandler'));
  603. } else {
  604. $oldErrorHandler = set_error_handler('SquirrelMailErrorhandler');
  605. }
  606. // ============================================================================
  607. // ================= End of Live Code, Beginning of Functions =================
  608. // ============================================================================
  609. /**
  610. * Javascript support detection function
  611. * @param boolean $reset recheck javascript support if set to true.
  612. * @return integer SMPREF_JS_ON or SMPREF_JS_OFF ({@see include/constants.php})
  613. * @since 1.5.1
  614. */
  615. function checkForJavascript($reset = FALSE) {
  616. global $data_dir, $username, $javascript_on, $javascript_setting;
  617. if ( !$reset && sqGetGlobalVar('javascript_on', $javascript_on, SQ_SESSION) )
  618. return $javascript_on;
  619. $user_is_logged_in = FALSE;
  620. if ( $reset || !isset($javascript_setting) )
  621. $javascript_setting = getPref($data_dir, $username, 'javascript_setting', SMPREF_JS_AUTODETECT);
  622. if ( !sqGetGlobalVar('new_js_autodetect_results', $js_autodetect_results) &&
  623. !sqGetGlobalVar('js_autodetect_results', $js_autodetect_results) )
  624. $js_autodetect_results = SMPREF_JS_OFF;
  625. if ( $javascript_setting == SMPREF_JS_AUTODETECT )
  626. $javascript_on = $js_autodetect_results;
  627. else
  628. $javascript_on = $javascript_setting;
  629. sqsession_register($javascript_on, 'javascript_on');
  630. return $javascript_on;
  631. }
  632. function sqm_baseuri() {
  633. global $base_uri;
  634. return $base_uri;
  635. }