From 8a584f67aaabae081502ab1c10489858f610ff3f Mon Sep 17 00:00:00 2001
From: noxilixon <93288913+noxilixon@users.noreply.github.com>
Date: Wed, 1 Nov 2023 23:04:55 +0100
Subject: [PATCH] Added path based redirect (#19)
---
apache/util.conf | 31 +++++++++++++++++++++++
www/knoteninfo.php | 63 ++++++++++++++++++++++++++++++++++++++--------
2 files changed, 84 insertions(+), 10 deletions(-)
diff --git a/apache/util.conf b/apache/util.conf
index c54b480..8f7e110 100644
--- a/apache/util.conf
+++ b/apache/util.conf
@@ -54,3 +54,34 @@
CustomLog /var/log/apache2/util.berlin.freifunk.net-access.log combined
ErrorLog /var/log/apache2/util.berlin.freifunk.net-error.log
+
+
+ ServerName ff.berlin
+ ServerAdmin "info@berlin.freifunk.net"
+ SSLEngine on
+ SSLCertificateFile /etc/letsencrypt/live/ff.berlin/cert.pem
+ SSLCertificateChainFile /etc/letsencrypt/live/ff.berlin/chain.pem
+ SSLCertificateKeyFile /etc/letsencrypt/live/ff.berlin/privkey.pem
+
+ DocumentRoot /var/www/util.berlin.freifunk.net/www
+
+
+ Options +FollowSymLinks -Indexes
+ AllowOverride None
+ Require all granted
+
+
+ # Always call the knoteninfo.php script
+ DirectoryIndex knoteninfo.php
+
+ # Deny access to all other PHP files
+
+ Require all denied
+
+
+ Require all granted
+
+
+ CustomLog /var/log/apache2/ff.berlin-access.log combined
+ ErrorLog /var/log/apache2/ff.berlin-error.log
+
diff --git a/www/knoteninfo.php b/www/knoteninfo.php
index b11dc0d..f724171 100644
--- a/www/knoteninfo.php
+++ b/www/knoteninfo.php
@@ -1,14 +1,56 @@
documentation (wiki)
+// /m/ -> map (hopglass)
+// /s/ -> statistics (monitor)
+
+$path_elements = getPathElements($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME']);
+
+if (count($_GET)) {
+ $knoten = ($_GET["knoten"] ?? "%");
+ $typ = ($_GET["typ"] ?? "");
+} else if (count($path_elements) == 2) {
+ switch ($path_elements[0]) {
+ case "d":
+ $typ = "wiki";
+ break;
+ case "m":
+ $typ = "hopglass";
+ break;
+ case "s":
+ $typ = "monitor";
+ break;
+ }
+ ;
+ $knoten = $path_elements[1];
+} else {
+ die("Keine gültige Anfrage.");
+}
-$knoten = ($_GET["knoten"] ?? "%");
$knoten = preg_replace("/\.olsr$/", "", $knoten);
if(preg_match('/[^A-Za-z0-9\\.\\-\\_]/', $knoten)) die("Ungültiger Knotenname.");
-$typ = ($_GET["typ"] ?? "");
+
+function getPathElements($request_uri, $script_name) {
+
+ if (strpos($request_uri, $script_name) === 0) {
+ $request_path = substr($request_uri, strlen($script_name));
+ } else {
+ $request_path = $request_uri;
+ }
+
+ $parsed_url = parse_url($request_path);
+ $path = $parsed_url['path'];
+ return explode('/', trim($path, '/'));
+}
+
function getUrl($url) {
$ctx = stream_context_create(["http" => ["method" => "GET"]]);
@@ -18,7 +60,8 @@ function getUrl($url) {
return $res;
}
-function getWikiLink($knoten) {
+
+function getWikiLink($knoten){
$url = "https://wiki.freifunk.net/api.php?action=ask&query=[[Hat_Knoten%3A%3A".$knoten."]]|%3FModification%20date|sort%3DModification%20date|order%3Ddesc&format=json";
$body = getUrl($url);
$json = json_decode($body);
@@ -56,11 +99,11 @@ function getWikiLink($knoten) {
echo "$knoten auf...";
echo "
".
- "zu berlin.freifunk.net