Skip to content

Commit

Permalink
Added path based redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
noxilixon committed Oct 10, 2023
1 parent 79aa1e0 commit 3385bb3
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 9 deletions.
31 changes: 31 additions & 0 deletions apache/util.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
</VirtualHost>

<VirtualHost *:443>
ServerName ff.berlin
ServerAdmin "[email protected]"
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

<Directory /var/www/util.berlin.freifunk.net/www>
Options +FollowSymLinks -Indexes
AllowOverride None
Require all granted
</Directory>

# Always call the knoteninfo.php script
DirectoryIndex knoteninfo.php

# Deny access to all other PHP files
<FilesMatch "\.php$">
Require all denied
</FilesMatch>
<Files "knoteninfo.php">
Require all granted
</Files>

CustomLog /var/log/apache2/ff.berlin-access.log combined
ErrorLog /var/log/apache2/ff.berlin-error.log
</VirtualHost>
61 changes: 52 additions & 9 deletions www/knoteninfo.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,57 @@
<?php

// https://util.berlin.freifunk.net/knoteninfo?knoten=Zwingli-Nord-2GHz&typ=wiki
// Query based redirect
// Example: https://util.berlin.freifunk.net/knoteninfo?knoten=Zwingli-Nord-2GHz&typ=wiki
// typ: wiki, monitor, owm, hopglass
//
// Path based redirect
// Example: https://ff.berlin/d/linie206-core
// /d/ -> 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];
}

if (!isset($knoten)) die("Kein Knotenname angegeben.");
if (!isset($typ)) die("Kein typ angegeben.");


$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"]]);
Expand Down Expand Up @@ -56,11 +99,11 @@ function getWikiLink($knoten) {

echo "<i>$knoten</i> auf...";
echo "<ul>".
"<li><a href=\"$owmurl\">openwifimap.net</a></li>".
"<li><a href=\"$hgurl\">hopglass.berlin.freifunk.net</a></li>".
"<li><a href=\"/knoteninfo?knoten=$knoten&typ=wiki\">wiki.freifunk.net</a></li>".
"<li><a href=\"$monurl\">monitor.berlin.freifunk.net</a></li>".
"</ul>".
"zu <a href=\"https://berlin.freifunk.net/\">berlin.freifunk.net</a></body>";
"<li><a href=\"$owmurl\">openwifimap.net</a></li>".
"<li><a href=\"$hgurl\">hopglass.berlin.freifunk.net</a></li>".
"<li><a href=\"/knoteninfo?knoten=$knoten&typ=wiki\">wiki.freifunk.net</a></li>".
"<li><a href=\"$monurl\">monitor.berlin.freifunk.net</a></li>".
"</ul>".
"zu <a href=\"https://berlin.freifunk.net/\">berlin.freifunk.net</a></body>";

?>

0 comments on commit 3385bb3

Please sign in to comment.