2005-01-14 17:40:57 +01:00
|
|
|
<?php
|
2023-08-31 22:44:40 +02:00
|
|
|
|
2005-01-14 17:40:57 +01:00
|
|
|
/**
|
2015-10-27 21:30:58 +01:00
|
|
|
* Forwarder/Router to doku.php
|
|
|
|
*
|
|
|
|
* In normal usage, this script simply redirects to doku.php. However it can also be used as a routing
|
|
|
|
* script with PHP's builtin webserver. It takes care of .htaccess compatible rewriting, directory/file
|
|
|
|
* access permission checking and passing on static files.
|
|
|
|
*
|
|
|
|
* Usage example:
|
|
|
|
*
|
|
|
|
* php -S localhost:8000 index.php
|
2005-01-14 17:40:57 +01:00
|
|
|
*
|
|
|
|
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
|
|
|
* @author Andreas Gohr <andi@splitbrain.org>
|
|
|
|
*/
|
2023-08-31 22:44:40 +02:00
|
|
|
|
2023-08-30 14:48:22 +02:00
|
|
|
if (PHP_SAPI != 'cli-server') {
|
|
|
|
if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/');
|
2020-06-11 23:01:10 +02:00
|
|
|
require_once(DOKU_INC . 'inc/init.php');
|
2019-03-12 03:34:23 +01:00
|
|
|
|
2020-06-01 08:00:43 +02:00
|
|
|
send_redirect(wl($conf['start']));
|
2015-10-27 21:30:58 +01:00
|
|
|
}
|
|
|
|
|
2020-06-11 23:01:10 +02:00
|
|
|
// ROUTER starts below
|
2015-10-27 21:30:58 +01:00
|
|
|
|
2020-06-11 23:01:10 +02:00
|
|
|
// avoid path traversal
|
2015-10-27 21:30:58 +01:00
|
|
|
$_SERVER['SCRIPT_NAME'] = str_replace('/../', '/', $_SERVER['SCRIPT_NAME']);
|
|
|
|
|
2020-06-11 23:01:10 +02:00
|
|
|
// routing aka. rewriting
|
|
|
|
if (preg_match('/^\/_media\/(.*)/', $_SERVER['SCRIPT_NAME'], $m)) {
|
|
|
|
// media dispatcher
|
2015-10-27 21:30:58 +01:00
|
|
|
$_GET['media'] = $m[1];
|
|
|
|
require $_SERVER['DOCUMENT_ROOT'] . '/lib/exe/fetch.php';
|
2020-06-11 23:01:10 +02:00
|
|
|
} elseif (preg_match('/^\/_detail\/(.*)/', $_SERVER['SCRIPT_NAME'], $m)) {
|
|
|
|
// image detail view
|
2015-10-27 21:30:58 +01:00
|
|
|
$_GET['media'] = $m[1];
|
|
|
|
require $_SERVER['DOCUMENT_ROOT'] . '/lib/exe/detail.php';
|
2020-06-11 23:01:10 +02:00
|
|
|
} elseif (preg_match('/^\/_export\/([^\/]+)\/(.*)/', $_SERVER['SCRIPT_NAME'], $m)) {
|
|
|
|
// exports
|
2015-10-27 21:30:58 +01:00
|
|
|
$_GET['do'] = 'export_' . $m[1];
|
|
|
|
$_GET['id'] = $m[2];
|
|
|
|
require $_SERVER['DOCUMENT_ROOT'] . '/doku.php';
|
2020-06-11 23:01:10 +02:00
|
|
|
} elseif (
|
|
|
|
$_SERVER['SCRIPT_NAME'] !== '/index.php' &&
|
|
|
|
file_exists($_SERVER['DOCUMENT_ROOT'] . $_SERVER['SCRIPT_NAME'])
|
|
|
|
) {
|
|
|
|
// existing files
|
2015-10-27 21:30:58 +01:00
|
|
|
|
2020-06-11 23:01:10 +02:00
|
|
|
// access limitiations
|
2023-08-30 14:48:22 +02:00
|
|
|
if (
|
|
|
|
preg_match('/\/([._]ht|README$|VERSION$|COPYING$)/', $_SERVER['SCRIPT_NAME']) ||
|
2016-01-19 19:55:20 +01:00
|
|
|
preg_match('/^\/(data|conf|bin|inc)\//', $_SERVER['SCRIPT_NAME'])
|
2015-10-27 21:30:58 +01:00
|
|
|
) {
|
2020-06-30 09:15:19 +02:00
|
|
|
header('HTTP/1.1 403 Forbidden');
|
2015-10-27 21:30:58 +01:00
|
|
|
die('Access denied');
|
|
|
|
}
|
|
|
|
|
2023-09-15 16:25:49 +02:00
|
|
|
if (str_ends_with($_SERVER['SCRIPT_NAME'], '.php')) {
|
2015-10-27 21:30:58 +01:00
|
|
|
# php scripts
|
|
|
|
require $_SERVER['DOCUMENT_ROOT'] . $_SERVER['SCRIPT_NAME'];
|
|
|
|
} else {
|
|
|
|
# static files
|
|
|
|
return false;
|
|
|
|
}
|
2020-06-11 23:01:10 +02:00
|
|
|
} else {
|
|
|
|
// treat everything else as a potential wiki page
|
|
|
|
// working around https://bugs.php.net/bug.php?id=61286
|
2020-06-30 09:19:08 +02:00
|
|
|
$request_path = preg_split('/\?/', $_SERVER['REQUEST_URI'], 2)[0];
|
2020-06-11 23:01:10 +02:00
|
|
|
if (isset($_SERVER['PATH_INFO'])) {
|
|
|
|
$_GET['id'] = $_SERVER['PATH_INFO'];
|
2020-06-30 09:20:35 +02:00
|
|
|
} elseif ($request_path != '/' && $request_path != '/index.php') {
|
2020-06-11 23:01:10 +02:00
|
|
|
$_GET['id'] = $_SERVER['SCRIPT_NAME'];
|
|
|
|
}
|
|
|
|
|
|
|
|
require $_SERVER['DOCUMENT_ROOT'] . '/doku.php';
|
2015-10-27 21:30:58 +01:00
|
|
|
}
|