| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /* |
|---|
| 4 | +-----------------------------------------------------------------------+ |
|---|
| 5 | | program/include/iniset.php | |
|---|
| 6 | | | |
|---|
| 7 | | This file is part of the Roundcube Webmail client | |
|---|
| 8 | | Copyright (C) 2008-2012, The Roundcube Dev Team | |
|---|
| 9 | | | |
|---|
| 10 | | Licensed under the GNU General Public License version 3 or | |
|---|
| 11 | | any later version with exceptions for skins & plugins. | |
|---|
| 12 | | See the README file for a full license statement. | |
|---|
| 13 | | | |
|---|
| 14 | | PURPOSE: | |
|---|
| 15 | | Setup the application envoronment required to process | |
|---|
| 16 | | any request. | |
|---|
| 17 | +-----------------------------------------------------------------------+ |
|---|
| 18 | | Author: Till Klampaeckel <till@php.net> | |
|---|
| 19 | | Thomas Bruederli <roundcube@gmail.com> | |
|---|
| 20 | +-----------------------------------------------------------------------+ |
|---|
| 21 | |
|---|
| 22 | $Id$ |
|---|
| 23 | |
|---|
| 24 | */ |
|---|
| 25 | |
|---|
| 26 | // Some users are not using Installer, so we'll check some |
|---|
| 27 | // critical PHP settings here. Only these, which doesn't provide |
|---|
| 28 | // an error/warning in the logs later. See (#1486307). |
|---|
| 29 | $crit_opts = array( |
|---|
| 30 | 'mbstring.func_overload' => 0, |
|---|
| 31 | 'suhosin.session.encrypt' => 0, |
|---|
| 32 | 'session.auto_start' => 0, |
|---|
| 33 | 'file_uploads' => 1, |
|---|
| 34 | 'magic_quotes_runtime' => 0, |
|---|
| 35 | ); |
|---|
| 36 | foreach ($crit_opts as $optname => $optval) { |
|---|
| 37 | if ($optval != ini_get($optname)) { |
|---|
| 38 | die("ERROR: Wrong '$optname' option value. Read REQUIREMENTS section in INSTALL file or use Roundcube Installer, please!"); |
|---|
| 39 | } |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | // application constants |
|---|
| 43 | define('RCMAIL_VERSION', '0.8-svn'); |
|---|
| 44 | define('RCMAIL_CHARSET', 'UTF-8'); |
|---|
| 45 | define('JS_OBJECT_NAME', 'rcmail'); |
|---|
| 46 | define('RCMAIL_START', microtime(true)); |
|---|
| 47 | |
|---|
| 48 | if (!defined('INSTALL_PATH')) { |
|---|
| 49 | define('INSTALL_PATH', dirname($_SERVER['SCRIPT_FILENAME']).'/'); |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | if (!defined('RCMAIL_CONFIG_DIR')) { |
|---|
| 53 | define('RCMAIL_CONFIG_DIR', INSTALL_PATH . 'config'); |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | // make sure path_separator is defined |
|---|
| 57 | if (!defined('PATH_SEPARATOR')) { |
|---|
| 58 | define('PATH_SEPARATOR', (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') ? ';' : ':'); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | // RC include folders MUST be included FIRST to avoid other |
|---|
| 62 | // possible not compatible libraries (i.e PEAR) to be included |
|---|
| 63 | // instead the ones provided by RC |
|---|
| 64 | $include_path = INSTALL_PATH . 'program/lib' . PATH_SEPARATOR; |
|---|
| 65 | $include_path.= ini_get('include_path'); |
|---|
| 66 | |
|---|
| 67 | if (set_include_path($include_path) === false) { |
|---|
| 68 | die("Fatal error: ini_set/set_include_path does not work."); |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | ini_set('error_reporting', E_ALL&~E_NOTICE); |
|---|
| 72 | |
|---|
| 73 | // increase maximum execution time for php scripts |
|---|
| 74 | // (does not work in safe mode) |
|---|
| 75 | @set_time_limit(120); |
|---|
| 76 | |
|---|
| 77 | // set internal encoding for mbstring extension |
|---|
| 78 | if (extension_loaded('mbstring')) { |
|---|
| 79 | mb_internal_encoding(RCMAIL_CHARSET); |
|---|
| 80 | @mb_regex_encoding(RCMAIL_CHARSET); |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | /** |
|---|
| 84 | * Use PHP5 autoload for dynamic class loading |
|---|
| 85 | * |
|---|
| 86 | * @todo Make Zend, PEAR etc play with this |
|---|
| 87 | * @todo Make our classes conform to a more straight forward CS. |
|---|
| 88 | */ |
|---|
| 89 | function rcube_autoload($classname) |
|---|
| 90 | { |
|---|
| 91 | $filename = preg_replace( |
|---|
| 92 | array( |
|---|
| 93 | '/MDB2_(.+)/', |
|---|
| 94 | '/Mail_(.+)/', |
|---|
| 95 | '/Net_(.+)/', |
|---|
| 96 | '/Auth_(.+)/', |
|---|
| 97 | '/^html_.+/', |
|---|
| 98 | '/^utf8$/', |
|---|
| 99 | ), |
|---|
| 100 | array( |
|---|
| 101 | 'MDB2/\\1', |
|---|
| 102 | 'Mail/\\1', |
|---|
| 103 | 'Net/\\1', |
|---|
| 104 | 'Auth/\\1', |
|---|
| 105 | 'html', |
|---|
| 106 | 'utf8.class', |
|---|
| 107 | ), |
|---|
| 108 | $classname |
|---|
| 109 | ); |
|---|
| 110 | |
|---|
| 111 | if ($fp = @fopen("$filename.php", 'r', true)) { |
|---|
| 112 | fclose($fp); |
|---|
| 113 | include_once("$filename.php"); |
|---|
| 114 | return true; |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | return false; |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | spl_autoload_register('rcube_autoload'); |
|---|
| 121 | |
|---|
| 122 | /** |
|---|
| 123 | * Local callback function for PEAR errors |
|---|
| 124 | */ |
|---|
| 125 | function rcube_pear_error($err) |
|---|
| 126 | { |
|---|
| 127 | error_log(sprintf("%s (%s): %s", |
|---|
| 128 | $err->getMessage(), |
|---|
| 129 | $err->getCode(), |
|---|
| 130 | $err->getUserinfo()), 0); |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | // set PEAR error handling (will also load the PEAR main class) |
|---|
| 134 | PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'rcube_pear_error'); |
|---|
| 135 | |
|---|
| 136 | // include global functions |
|---|
| 137 | require_once INSTALL_PATH . 'program/include/main.inc'; |
|---|
| 138 | require_once INSTALL_PATH . 'program/include/rcube_shared.inc'; |
|---|