7 Star 18 Fork 4

Gitee 极速下载/DokuWiki

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/splitbrain/dokuwiki
克隆/下载
index.php 2.47 KB
一键复制 编辑 原始数据 按行查看 历史
fiwswe 提交于 2023-09-15 16:25 . Use str_starts_with/str_ends_with
<?php
/**
* 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
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Andreas Gohr <andi@splitbrain.org>
*/
if (PHP_SAPI != 'cli-server') {
if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/');
require_once(DOKU_INC . 'inc/init.php');
send_redirect(wl($conf['start']));
}
// ROUTER starts below
// avoid path traversal
$_SERVER['SCRIPT_NAME'] = str_replace('/../', '/', $_SERVER['SCRIPT_NAME']);
// routing aka. rewriting
if (preg_match('/^\/_media\/(.*)/', $_SERVER['SCRIPT_NAME'], $m)) {
// media dispatcher
$_GET['media'] = $m[1];
require $_SERVER['DOCUMENT_ROOT'] . '/lib/exe/fetch.php';
} elseif (preg_match('/^\/_detail\/(.*)/', $_SERVER['SCRIPT_NAME'], $m)) {
// image detail view
$_GET['media'] = $m[1];
require $_SERVER['DOCUMENT_ROOT'] . '/lib/exe/detail.php';
} elseif (preg_match('/^\/_export\/([^\/]+)\/(.*)/', $_SERVER['SCRIPT_NAME'], $m)) {
// exports
$_GET['do'] = 'export_' . $m[1];
$_GET['id'] = $m[2];
require $_SERVER['DOCUMENT_ROOT'] . '/doku.php';
} elseif (
$_SERVER['SCRIPT_NAME'] !== '/index.php' &&
file_exists($_SERVER['DOCUMENT_ROOT'] . $_SERVER['SCRIPT_NAME'])
) {
// existing files
// access limitiations
if (
preg_match('/\/([._]ht|README$|VERSION$|COPYING$)/', $_SERVER['SCRIPT_NAME']) ||
preg_match('/^\/(data|conf|bin|inc)\//', $_SERVER['SCRIPT_NAME'])
) {
header('HTTP/1.1 403 Forbidden');
die('Access denied');
}
if (str_ends_with($_SERVER['SCRIPT_NAME'], '.php')) {
# php scripts
require $_SERVER['DOCUMENT_ROOT'] . $_SERVER['SCRIPT_NAME'];
} else {
# static files
return false;
}
} else {
// treat everything else as a potential wiki page
// working around https://bugs.php.net/bug.php?id=61286
$request_path = preg_split('/\?/', $_SERVER['REQUEST_URI'], 2)[0];
if (isset($_SERVER['PATH_INFO'])) {
$_GET['id'] = $_SERVER['PATH_INFO'];
} elseif ($request_path != '/' && $request_path != '/index.php') {
$_GET['id'] = $_SERVER['SCRIPT_NAME'];
}
require $_SERVER['DOCUMENT_ROOT'] . '/doku.php';
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/mirrors/DokuWiki.git
git@gitee.com:mirrors/DokuWiki.git
mirrors
DokuWiki
DokuWiki
master

搜索帮助