2 error_reporting(E_ALL);
3 ini_set('display_errors', TRUE);
5 define('DOCROOT', getcwd());
6 set_include_path(implode(PATH_SEPARATOR, [ DOCROOT, __DIR__ ]));
8 include_once 'error.inc.php';
10 # setup requested page
12 $request = preg_replace('/\?.*/', '', @$_SERVER['PATH_INFO'] ?: $_SERVER['REQUEST_URI']);
13 $request = urldecode(trim($request, '/')) ?: 'index';
15 $staticpage = "$request.html";
16 if (file_exists($staticpage)) {
17 if (is_link($staticpage)) {
18 $target = preg_replace('/\.html$/', '', readlink($staticpage));
19 header("HTTP/1.1 302 Shorthand");
20 header("Location: $target");
24 elseif (file_exists("$request/index.html")) {
25 $staticpage = "$request/index.html";
28 require_once('article.inc.php');
29 $Page = new ArchiveArticle($staticpage);
31 # user login and control
33 include_once 'auth.inc.php'; // sets global $User
35 if ($Page->restricted) {
38 http_response_code(303);
39 $target = urlencode($Page->link);
40 header("Location: /login?goto=$target");
45 # prepare page contents
47 header(sprintf('Content-Security-Policy: %s', implode('; ', [
48 "default-src 'self' 'unsafe-inline' http://cdn.ckeditor.com", # some overrides remain
49 "img-src 'self' data: http://cdn.ckeditor.com", # inline svg (in css)
50 "base-uri 'self'", # only local pages
51 "frame-ancestors 'none'", # prevent malicious embedding
55 'user' => $User->login ?: '',
56 'url' => htmlspecialchars($_SERVER['REQUEST_URI']),
59 if ($User->admin("edit {$Page->link}")) {
60 include_once 'edit/head.inc.php';
63 if (isset($Page->raw)) {
64 $Page->raw = '<div class="static">'."\n\n".$Page->raw."</div>\n\n";
67 # output dynamic and/or static html
69 include_once 'format.inc.php';
72 if ($Page->handler and !require("./{$Page->handler}/index.php")) {
73 # replace contents by code output on false return
74 $Page->raw = ob_get_clean();
77 # keep article contents
78 if (!isset($Page->body)) {
80 http_response_code(404);
81 @require '404.inc.html';
82 $Page->raw = ob_get_clean() . $Page->raw;
86 include_once 'page.inc.php';