adele/ergol-http
3
4
Fork
You've already forked ergol-http
1

Add a whitelist of capsules mirrored on HTTP #8

Closed
opened 2022年01月05日 16:12:45 +01:00 by rdelaage · 9 comments
Collaborator
Copy link

Currently it is impossible to follow a link to another capsule, it could be interesting to have a list of capsule also served on HTTP (e.g. automatic list of all capsules also served by the same ergol-http instance, manual list of other capsules like https://gemini.circumlunar.space/).

Instead of being redirected to a page showing a warning message you could be redirected the http(s) version of the capsule.

Currently it is impossible to follow a link to another capsule, it could be interesting to have a list of capsule also served on HTTP (e.g. automatic list of all capsules also served by the same ergol-http instance, manual list of other capsules like https://gemini.circumlunar.space/). Instead of being redirected to a page showing a warning message you could be redirected the http(s) version of the capsule.
Owner
Copy link

Does it mean ergol-http connect to these other servers through gemeini protocol, parse content and propose html version ?

Does it mean ergol-http connect to these other servers through gemeini protocol, parse content and propose html version ?
Author
Collaborator
Copy link

No, ergol-http just know that the capsule is mirrored on http (by itself or another server) so it redirect to this http mirror. For exemple example1.net is mirrored by ergol-http and has a link to examples.org, it knows that examples.org is mirrored by Kineto so it shows a to http://examples.org

No, ergol-http just know that the capsule is mirrored on http (by itself or another server) so it redirect to this http mirror. For exemple example1.net is mirrored by ergol-http and has a link to examples.org, it knows that examples.org is mirrored by Kineto so it shows a to http://examples.org
Author
Collaborator
Copy link

Do you think something like this is adequate ?

diff --git a/config-sample.php b/config-sample.php
index f41ea0c..5c92601 100644
--- a/config-sample.php
+++ b/config-sample.php
@@ -7,3 +7,5 @@ define('CONFIG_TYPE', 'ergol');
 // See ergol.json description on
 // https://codeberg.org/adele.work/ergol#configuration-ergol-json
 define('CONFIG_PATH', __DIR__."/../ergol.json");
+
+define('WHITELIST_DOMAINS_PATH', __DIR__.'/whitelist_domains.txt');
diff --git a/index.php b/index.php
index 33b145d..7c7f12b 100755
--- a/index.php
+++ b/index.php
@@ -131,6 +131,8 @@ if(strpos($_SERVER['HTTP_HOST'],':')!==false)
 else
 	$capsule = strtolower($_SERVER['HTTP_HOST']);
 
+$whitelist_domains = explode("\n", file_get_contents(WHITELIST_DOMAINS_PATH));
+
 $response = false;
 $response_code = 0;
 $body = false;
@@ -356,6 +358,7 @@ exit;
 
 function gmi2html($capsule, $body, $lang, $urlgem, $favicon)
 {
+	global $whitelist_domains;
 	if(isset($_SERVER['REQUEST_SCHEME'])) {
 		$scheme = $_SERVER['REQUEST_SCHEME'];
 	}
@@ -437,7 +440,12 @@ function gmi2html($capsule, $body, $lang, $urlgem, $favicon)
 					$lines[] = '<a href="'.str_replace('gemini://'.$capsule,$scheme.'://'.$_SERVER['HTTP_HOST'], $link[0]).'">'.htmlentities(empty($link[1])?rawurldecode($link[0]):$link[1])."</a>";
 				}
 				else if(str_starts_with($link[0], 'gemini://')) {
-					$lines[] = '<a href="/?qx='.urlencode($link[0]).'">'.htmlentities(empty($link[1])?rawurldecode($link[0]):$link[1])."</a>";
+					$link_domain = parse_url($link[0], PHP_URL_HOST);
+					if(in_array($link_domain, $whitelist_domains))
+						$link_href = str_replace('gemini://','http://',$link[0]);
+					else
+						$link_href = '/?qx='.urlencode($link[0]);
+					$lines[] = '<a href="'.$link_href.'">'.htmlentities(empty($link[1])?rawurldecode($link[0]):$link[1])."</a>";
 				}
 				else {
 					$lines[] = '<a href="'.$link[0].'">'.htmlentities(empty($link[1])?rawurldecode($link[0]):$link[1])."</a>";
 

The goal is to have a basic 'whitelist_domains.txt` file with the host you know that are mirrored on the web and this list is automatically completed with the host in your config file.

Do you think something like this is adequate ? ``` diff --git a/config-sample.php b/config-sample.php index f41ea0c..5c92601 100644 --- a/config-sample.php +++ b/config-sample.php @@ -7,3 +7,5 @@ define('CONFIG_TYPE', 'ergol'); // See ergol.json description on // https://codeberg.org/adele.work/ergol#configuration-ergol-json define('CONFIG_PATH', __DIR__."/../ergol.json"); + +define('WHITELIST_DOMAINS_PATH', __DIR__.'/whitelist_domains.txt'); diff --git a/index.php b/index.php index 33b145d..7c7f12b 100755 --- a/index.php +++ b/index.php @@ -131,6 +131,8 @@ if(strpos($_SERVER['HTTP_HOST'],':')!==false) else $capsule = strtolower($_SERVER['HTTP_HOST']); +$whitelist_domains = explode("\n", file_get_contents(WHITELIST_DOMAINS_PATH)); + $response = false; $response_code = 0; $body = false; @@ -356,6 +358,7 @@ exit; function gmi2html($capsule, $body, $lang, $urlgem, $favicon) { + global $whitelist_domains; if(isset($_SERVER['REQUEST_SCHEME'])) { $scheme = $_SERVER['REQUEST_SCHEME']; } @@ -437,7 +440,12 @@ function gmi2html($capsule, $body, $lang, $urlgem, $favicon) $lines[] = '<a href="'.str_replace('gemini://'.$capsule,$scheme.'://'.$_SERVER['HTTP_HOST'], $link[0]).'">'.htmlentities(empty($link[1])?rawurldecode($link[0]):$link[1])."</a>"; } else if(str_starts_with($link[0], 'gemini://')) { - $lines[] = '<a href="/?qx='.urlencode($link[0]).'">'.htmlentities(empty($link[1])?rawurldecode($link[0]):$link[1])."</a>"; + $link_domain = parse_url($link[0], PHP_URL_HOST); + if(in_array($link_domain, $whitelist_domains)) + $link_href = str_replace('gemini://','http://',$link[0]); + else + $link_href = '/?qx='.urlencode($link[0]); + $lines[] = '<a href="'.$link_href.'">'.htmlentities(empty($link[1])?rawurldecode($link[0]):$link[1])."</a>"; } else { $lines[] = '<a href="'.$link[0].'">'.htmlentities(empty($link[1])?rawurldecode($link[0]):$link[1])."</a>"; ``` The goal is to have a basic 'whitelist_domains.txt` file with the host you know that are mirrored on the web and this list is automatically completed with the host in your config file.
Owner
Copy link

This seems great !

This seems great !
Owner
Copy link

In fact, why having a whitelist_domains.txt ? all known hosts are in config file.

In fact, why having a whitelist_domains.txt ? all known hosts are in config file.
Author
Collaborator
Copy link

Not really, for exemple my own server knows rdelaage.ovh and patu.re but if I want to link pollux.casa, it will show a warning because this is on an other server. So if I know that your capsule is proxied on http I can add it to whitelist_domains.txt to tell ergo-http "ok you can convert gemini://pollux.casa to http://pollux.casa, it will work".

The goal is to have a single $whitelist_domains with both the domains retrived from the config and the domains you manually added to the file.

Not really, for exemple my own server knows rdelaage.ovh and patu.re but if I want to link pollux.casa, it will show a warning because this is on an other server. So if I know that your capsule is proxied on http I can add it to whitelist_domains.txt to tell ergo-http "ok you can convert gemini://pollux.casa to http://pollux.casa, it will work". The goal is to have a single `$whitelist_domains` with both the domains retrived from the config and the domains you manually added to the file.
Author
Collaborator
Copy link

I have opened a PR #9

I have opened a PR #9
Owner
Copy link

You're right, let's go.

I think you have autorization to merge your PR, haven't you ?

You're right, let's go. I think you have autorization to merge your PR, haven't you ?
Author
Collaborator
Copy link

Yes, this is done :)

Yes, this is done :)
Sign in to join this conversation.
No Branch/Tag specified
main
No results found.
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
adele/ergol-http#8
Reference in a new issue
adele/ergol-http
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?