💾 Archived View for rawtext.club › ~sloum › geminilist › 001044.gmi captured on 2020-10-31 at 02:00:36. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2020-09-24)

-=-=-=-=-=-=-

<-- back to the mailing list

Gemini and CGI hosting

Sean Conner sean at conman.org

Mon May 25 22:06:58 BST 2020

- - - - - - - - - - - - - - - - - - - 

It was thus said that the Great peteyboy at sdf.org once stated:

Cool, i will check that out. But is that a custom app, then? There's no
.cgi file or anything you're pointing to. How'd you implement it?

You are right it's not a CGI script [1]. It's a custom module I added tothe server [2]. The source code is here:

gemini://gemini.conman.org/extensions/GLV-1/handlers/hilo.lua

and most of it is just error checking, I can still walk you through the codethough.

function handler(_,_,loc,match)

The handler gets four parameters, but I don't care about the first two(the first is the configuration paremeters for the handler, which for thishandler I don't care about, and the second is the client certificate info,again, there is none). The third one is the broken down URL, for example:

{ scheme = "gemini", path = "/hilo/1082", query = "33", host = "gemini.conman.org", port = 1965.000000, }

The last parameter is the path portion of the URL broken up into twocomponents (it's specified in the configuration portion how to split thepath up) and for the example above, it would be:

{ "/hilo/" , "1082" }

When you first enter the game, the second element of the match paramterwill be "", so that starts a game, which generates a random number andgenerates a link that contains the encoded number (I wanted something simpleto demonstrate the 10 status codes, I didn't want to make this bulletproof).

If there's no query portion to the URL, then I return a status code of 10with a prompt. If there *is* a query portion, I decode the query string anddo some error checking (making sure it's formatted properly and a number). I then convert the second portion of the match paramter to a value torecover the original number, compare it to the guess and return a 10 statuscode if it's not right, or a 20 if you guessed it.

It could very well be a CGI script, and I could make it look exactly thesame with the same URLs and everything [3], but I went this route because Icould, and it was a bit easier to implement.

-spc

[1] The server it's running on does support CGI.

[2] Because its' easy enough to write a custom module (or handler) for GLV-1.12556.

[3] In my server, when it comes across a file that is marked executable, and CGI is enabled, will then treat the file as a CGI script. No special extensions required. For example:

gemini://gemini.conman.org/cgi/test gemini://gemini.conman.org/cgi/test/1082 gemini://gemini.conman.org/cgi/test/1082?33

Here, the CGI script is called "test".