From d013b30d4e4ed449e22e29e5155d49658068df79 Mon Sep 17 00:00:00 2001 From: Romain de Laage Date: Sun, 30 May 2021 09:49:26 +0200 Subject: [PATCH] Add warning when following an external capsule link --- index.php | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/index.php b/index.php index ea257d2..051fd24 100755 --- a/index.php +++ b/index.php @@ -37,10 +37,6 @@ error_reporting(E_ALL); require(__DIR__.'/config.php'); -if(isset($_GET['q'])) - $q = $_GET['q']; -else - $q = $_SERVER['REQUEST_URI']; // Loading config... $conf_filename = @realpath(CONFIG_PATH); @@ -135,6 +131,26 @@ $response = false; $response_code = 0; $body = false; +if(isset($_GET['qx'])) +{ + $response = "OK"; + $body = "# You are following a Gemini link to another server + +You can't access all the Geminispace with this proxy. If you want to follow this link, you have to install ans use a Gemini client. + +You asked to follow : +```gemini-url +".urldecode($_GET['qx'])." +```"; + $mime="text/html"; + $body=gmi2html($capsule, $body, 'en', $_GET['qx'], ''); +} + +if(isset($_GET['q'])) + $q = $_GET['q']; +else + $q = $_SERVER['REQUEST_URI']; + if($response === false && !isset($conf->capsules->$capsule)) { $response = "HTTP/1.1 400 BAD REQUEST"; @@ -413,7 +429,15 @@ function gmi2html($capsule, $body, $lang, $urlgem, $favicon) case "=>": $lines[]='

'; $link = explode(' ', substr($line,3), 2); - $lines[] = ''.htmlentities(empty($link[1])?rawurldecode($link[0]):$link[1]).""; + if(str_starts_with($link[0], 'gemini://'.$capsule)) { + $lines[] = ''.htmlentities(empty($link[1])?rawurldecode($link[0]):$link[1]).""; + } + else if(str_starts_with($link[0], 'gemini://')) { + $lines[] = ''.htmlentities(empty($link[1])?rawurldecode($link[0]):$link[1]).""; + } + else { + $lines[] = ''.htmlentities(empty($link[1])?rawurldecode($link[0]):$link[1]).""; + } if(strpos($link[0], '://')===false && // relative image in_array(strtolower(substr($link[0],-4)),array('.jpg','.png','.gif','jpeg','webp')) ) $lines[] = ' 🖼️

'.htmlentities(empty($link[1])?rawurldecode($link[0]):$link[1]).'
';