| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
if ( array_key_exists('HTTP_X_MOZ', $_SERVER) |
|---|
| 15 |
&& $_SERVER['HTTP_X_MOZ'] == 'prefetch') |
|---|
| 16 |
{ |
|---|
| 17 |
header('Cache-Control: no-cache'); |
|---|
| 18 |
header('Pragma: no-cache'); |
|---|
| 19 |
header('HTTP/1.0 403 Forbidden'); |
|---|
| 20 |
echo '403: Forbidden<br><br>Prefetching not allowed.'; |
|---|
| 21 |
exit; |
|---|
| 22 |
} |
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
$redirect_test_uri = (string)$_SERVER['REQUEST_URI']; |
|---|
| 33 |
if ( !isset($_SERVER['MIDCOM_COMPAT_REDIR']) |
|---|
| 34 |
|| (bool)$_SERVER['MIDCOM_COMPAT_REDIR'] !== false) |
|---|
| 35 |
{ |
|---|
| 36 |
$redirect_test_uri = preg_replace('/\.html$/', '', $redirect_test_uri); |
|---|
| 37 |
} |
|---|
| 38 |
if ( !preg_match('%\?|/$|midcom-.+-|/.+\..+$%', $redirect_test_uri) |
|---|
| 39 |
&& ( !isset($_POST) |
|---|
| 40 |
|| empty($_POST)) |
|---|
| 41 |
) |
|---|
| 42 |
{ |
|---|
| 43 |
header('HTTP/1.0 301 Moved Permanently'); |
|---|
| 44 |
header("Location: {$redirect_test_uri}/"); |
|---|
| 45 |
echo "301: new location <a href='{$redirect_test_uri}/'>{$redirect_test_uri}/</a>"; |
|---|
| 46 |
exit(); |
|---|
| 47 |
} |
|---|
| 48 |
unset($redirect_test_uri); |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
header('X-Powered-By: Midgard/' . mgd_version()); |
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
error_reporting(E_ALL); |
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
if (! defined('MIDCOM_ROOT')) |
|---|
| 63 |
{ |
|---|
| 64 |
define('MIDCOM_ROOT', dirname(__FILE__)); |
|---|
| 65 |
} |
|---|
| 66 |
if (! defined('MIDCOM_STATIC_ROOT')) |
|---|
| 67 |
{ |
|---|
| 68 |
$pos = strrpos(MIDCOM_ROOT, '/'); |
|---|
| 69 |
if ($pos === false) |
|---|
| 70 |
{ |
|---|
| 71 |
|
|---|
| 72 |
die ('MIDCOM_ROOT did not contain a slash, this should not happen and is most probably the cause of a configuration error.'); |
|---|
| 73 |
} |
|---|
| 74 |
define('MIDCOM_STATIC_ROOT', substr(MIDCOM_ROOT,0,$pos) . '/static'); |
|---|
| 75 |
} |
|---|
| 76 |
if (! defined('MIDCOM_STATIC_URL')) |
|---|
| 77 |
{ |
|---|
| 78 |
define('MIDCOM_STATIC_URL', '/midcom-static'); |
|---|
| 79 |
} |
|---|
| 80 |
if (! defined('MIDCOM_CONFIG_FILE_BEFORE')) |
|---|
| 81 |
{ |
|---|
| 82 |
define('MIDCOM_CONFIG_FILE_BEFORE', '/etc/midgard/midcom.conf'); |
|---|
| 83 |
} |
|---|
| 84 |
if (! defined('MIDCOM_CONFIG_FILE_AFTER')) |
|---|
| 85 |
{ |
|---|
| 86 |
define('MIDCOM_CONFIG_FILE_AFTER', '/etc/midgard/midcom-after.conf'); |
|---|
| 87 |
} |
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
require('constants.php'); |
|---|
| 92 |
require('globals.php'); |
|---|
| 93 |
require('midcom/config/midcom_config.php'); |
|---|
| 94 |
ini_set('track_errors', '1'); |
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
if (! defined('MIDCOM_XDEBUG')) |
|---|
| 100 |
{ |
|---|
| 101 |
if (function_exists('xdebug_start_profiling')) |
|---|
| 102 |
{ |
|---|
| 103 |
define('MIDCOM_XDEBUG', 1); |
|---|
| 104 |
} |
|---|
| 105 |
else if (function_exists('xdebug_break')) |
|---|
| 106 |
{ |
|---|
| 107 |
define('MIDCOM_XDEBUG', 2); |
|---|
| 108 |
} |
|---|
| 109 |
else |
|---|
| 110 |
{ |
|---|
| 111 |
define('MIDCOM_XDEBUG', 0); |
|---|
| 112 |
} |
|---|
| 113 |
} |
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
require('midcom/debug.php'); |
|---|
| 118 |
|
|---|
| 119 |
debug_add("Start of MidCOM run: {$_SERVER['REQUEST_URI']}", MIDCOM_LOG_DEBUG); |
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
function midcom_autoload($class_name) |
|---|
| 127 |
{ |
|---|
| 128 |
static $autoloaded = 0; |
|---|
| 129 |
|
|---|
| 130 |
if (substr($class_name, 0, 15) == 'midcom_service_') |
|---|
| 131 |
{ |
|---|
| 132 |
|
|---|
| 133 |
$class_name = str_replace('midcom_service_', 'midcom_services_', $class_name); |
|---|
| 134 |
} |
|---|
| 135 |
|
|---|
| 136 |
$path = MIDCOM_ROOT . '/' . str_replace('_', '/', $class_name) . '.php'; |
|---|
| 137 |
$path = str_replace('//', '/_', $path); |
|---|
| 138 |
|
|---|
| 139 |
if ( basename($path) == 'dba.php' |
|---|
| 140 |
|| basename($path) == 'db.php') |
|---|
| 141 |
{ |
|---|
| 142 |
|
|---|
| 143 |
//debug_add("Autoloader got '{$path}' which is DBA class, going one above"); |
|---|
| 144 |
|
|---|
| 145 |
// Ensure we have the component loaded |
|---|
| 146 |
$_MIDCOM->dbclassloader->load_component_for_class($class_name); |
|---|
| 147 |
if (class_exists($class_name)) |
|---|
| 148 |
{ |
|---|
| 149 |
return; |
|---|
| 150 |
} |
|---|
| 151 |
|
|---|
| 152 |
$path = dirname($path) . ".php"; |
|---|
| 153 |
} |
|---|
| 154 |
|
|---|
| 155 |
if ( basename($path) == 'interface.php' |
|---|
| 156 |
&& $class_name != 'midcom_baseclasses_components_interface') |
|---|
| 157 |
{ |
|---|
| 158 |
|
|---|
| 159 |
//debug_add("Autoloader got '{$path}' which is component interface class, loading the component instead"); |
|---|
| 160 |
$_MIDCOM->dbclassloader->load_component_for_class($class_name); |
|---|
| 161 |
return; |
|---|
| 162 |
} |
|---|
| 163 |
|
|---|
| 164 |
if (!file_exists($path)) |
|---|
| 165 |
{ |
|---|
| 166 |
$original_path = $path; |
|---|
| 167 |
$path = str_replace('.php', '/main.php', $path); |
|---|
| 168 |
|
|---|
| 169 |
if (!file_exists($path)) |
|---|
| 170 |
{ |
|---|
| 171 |
debug_add("Autoloader got '{$original_path}' and tried {$path} but neither was not found, aborting"); |
|---|
| 172 |
return; |
|---|
| 173 |
} |
|---|
| 174 |
} |
|---|
| 175 |
|
|---|
| 176 |
require($path); |
|---|
| 177 |
$autoloaded++; |
|---|
| 178 |
|
|---|
| 179 |
} |
|---|
| 180 |
|
|---|
| 181 |
spl_autoload_register('midcom_autoload'); |
|---|
| 182 |
|
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
require('midcom/helper/misc.php'); |
|---|
| 187 |
require('midcom/helper/formatters.php'); |
|---|
| 188 |
|
|---|
| 189 |
$auth = new midcom_services_auth(); |
|---|
| 190 |
$auth->initialize(); |
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
require('midcom/services/cache.php'); |
|---|
| 197 |
midcom_services_cache_startup(); |
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 |
require('midcom/services/_i18n_l10n.php'); |
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 |
require('midcom/application.php'); |
|---|
| 210 |
|
|---|
| 211 |
$_MIDCOM = new midcom_application(); |
|---|
| 212 |
$_MIDCOM->auth = $auth; |
|---|
| 213 |
|
|---|
| 214 |
$_MIDCOM->initialize(); |
|---|
| 215 |
|
|---|
| 216 |
if (file_exists(MIDCOM_CONFIG_FILE_AFTER)) |
|---|
| 217 |
{ |
|---|
| 218 |
include(MIDCOM_CONFIG_FILE_AFTER); |
|---|
| 219 |
} |
|---|
| 220 |
?> |
|---|