Compare commits

...

6 Commits

4 changed files with 43 additions and 12 deletions

26
README.md Normal file
View File

@ -0,0 +1,26 @@
# thunix wiki
Requires a webserver and PHP. The web server needs to be configured to:
- serve wiki.php by default (not index.php)
- when a requested URL does not correspond to an actual file, pass the requested page to wiki.php?page=
On apache, this is achieved by provided [.htaccess](.htaccess). On nginx, you can do something like:
```
server {
listen 80;
root /var/www/wiki_webroot;
index wiki.php;
server_name _;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
}
location ~ ^/(.+)$ {
try_files $uri $uri/ /wiki.php?page=$1;
}
}
```

View File

@ -5,7 +5,4 @@ $site_name="Thunix Wiki";
//Root for the site, in a browser
$site_root="https://wiki.thunix.net";
//Local base root for app files
$doc_root="/var/www/wiki.thunix.net/";
?>

3
includes/404.md Normal file
View File

@ -0,0 +1,3 @@
# 404
This page ("$page") does not exist.

View File

@ -7,23 +7,28 @@ Parsedown is licensed under the MIT license.
include('config.php');
include('parsedown-1.7.3/Parsedown.php');
$page = $_GET['page'];
$page = isset($_GET['page']) ? $_GET['page'] : 'main';
// Sanitize page request so we don't allow to read EVERY markdown file
// for example ../../../home/foobar/mysecretdocument
if (strpos($page, "../") !== false) {
header('HTTP/1.0 403 Forbidden');
exit();
}
$content_file = "articles/$page.md";
$Parsedown = new Parsedown();
$Parsedown->setSafeMode(true);
if ( $page == "") {
$page = "main";
}
if(isset($_GET['style']))
$site_style = $_GET['style'];
else
$site_style="site";
$header = file_get_contents("$doc_root/includes/header.md");
$sidebar = file_get_contents("$doc_root/includes/sidebar.md");
$content = file_get_contents("$doc_root/articles/$page.md");
$footer = file_get_contents("$doc_root/includes/footer.md");
$header = file_get_contents("includes/header.md");
$sidebar = file_get_contents("includes/sidebar.md");
$content = file_exists($content_file) ? file_get_contents($content_file) : str_replace('$page', "$page", file_get_contents("includes/404.md"));
$footer = file_get_contents("includes/footer.md");
print "<!DOCTYPE html>
<html lang='en'>