From 933435d4bac132dfbe3af3747177a346f9cddbfb Mon Sep 17 00:00:00 2001 From: Noxil Date: Tue, 10 Oct 2023 15:15:43 +0200 Subject: [PATCH] Added path based redirect --- apache/util.conf | 31 +++++++++++++++++++++++++ www/knoteninfo.php | 58 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 80 insertions(+), 9 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..c607e2f 100644 --- a/www/knoteninfo.php +++ b/www/knoteninfo.php @@ -1,14 +1,54 @@ documentation (wiki) +// /m/ -> map (hopglass) +// /s/ -> statistics (monitor) + +if (count($_GET)) { + $knoten = ($_GET["knoten"] ?? "%"); + $typ = ($_GET["typ"] ?? ""); +} + +$request_uri = $_SERVER['REQUEST_URI']; +$script_name = $_SERVER['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']; +$path_elements = explode('/', trim($path, '/')); + +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]; +} + -$knoten = ($_GET["knoten"] ?? "%"); $knoten = preg_replace("/\.olsr$/", "", $knoten); if(preg_match('/[^A-Za-z0-9\\.\\-\\_]/', $knoten)) die("Ungültiger Knotenname."); -$typ = ($_GET["typ"] ?? ""); function getUrl($url) { $ctx = stream_context_create(["http" => ["method" => "GET"]]); @@ -56,11 +96,11 @@ function getWikiLink($knoten) { echo "$knoten auf..."; echo "". - "zu berlin.freifunk.net"; + "
  • openwifimap.net
  • ". + "
  • hopglass.berlin.freifunk.net
  • ". + "
  • wiki.freifunk.net
  • ". + "
  • monitor.berlin.freifunk.net
  • ". + "". + "zu berlin.freifunk.net"; ?>