šŸ’¾ Archived View for gemini.omarpolo.com ā€ŗ post ā€ŗ gmid-cgi-and-services.gmi captured on 2024-08-25 at 07:23:11. Gemini links have been rewritten to link to archived content

View Raw

More Information

ā¬…ļø Previous capture (2023-01-29)

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

gmid update, cgi support and services

status update and cool gemini stuff

Written while listening to ā€œPiccola CittĆ ā€ by Francesco Guccini.

Published: 2020-11-10

Tagged with:

#gemini

Iā€™ve just tagged the version 1.3 of gmid, a dead simple zero configuration gemini server, which brings in CGI scripts supports.

gmid project page

gmid presentation

This gave me the opportunity to play around with CGI scripts, and I had a blast! Iā€™m currently hosting 3 scripts, written in three different scripting languages, because why not?

Hello World

Hello World

This was the first script I ran while adding the CGI support. Is a simple shell script that uses ā€˜printfā€™ and ā€˜echoā€™. You can find the ā€œfullā€ source code in the gmid manpage.

Yeah, counting this felt just like cheatingā€¦

OpenBSD manpages

man

Itā€™s like man.cgi, only written in rc ā€“ the plan9 shell ā€“ and with less features. It ask the user for a manpage and it will render it.

How it looks (37.9K)

This also exposed a difference in how plan9portsā€™ rc and whoever the upstream for the FreeBSD rc package is treat the empty string.

In plan9ports rc, the following code do the right thingā„¢

if (~ $QUERY_STRING '') {
	echo '10 manpage:^M' # the ^M should be the real CR
	exit 0
}

but if you run the same snippet using the rc shell that comes with the FreeBSD rc package, it wonā€™t work. The workaround is to check for the length of the list, thing that works everywhere fortunately.

if (~ $#QUERY_STRING 0) { # <- added ā€˜#ā€™ after the sigil 
	echo '10 manpage:^M'
	exit 0
}

For the uninitialised, in rc shell every variabile is a list of string, so a undefined variable is an empty list. The ā€˜$#varā€™ evaluates to the length of the list ā€˜varā€™.

This is all due the fact that, while I use OpenBSD on my desktop, for ā€œhistorical reasonsā€ Iā€™m using FreeBSD on my server.

If you are interested in how to serve the OpenBSD manpages from a system thatā€™s not OpenBSD, Iā€™m not sure what the best option is, but what I did was to download and extract all the sets in a directory, say $HOME/man, than pointed the MANPATH environment variable to $HOME/man/usr/share/man:$HOME/man/usr/X11R6/man. To finish, Iā€™ve build mandoc and ran makewhatis. The script is using ā€˜manā€™ from ā€˜mandocā€™ and not the system ā€˜manā€™.

mandoc website

GemPKG

GemPKG, explore the OpenBSD port catalog

WebPKG, the HTTP version

This is a ā€œportā€ of another project I worked on recently, WebPKG. Itā€™s a gemini interface to the OpenBSD port catalog. It features a full text search across package name, comment, DESCR and maintainer, as well as a package ā€œpresentation pageā€ with some links, the whole description and the readme.

The URLs are also intuitive:

GemPKG Screenshot (32.1K)

This is the biggest of the three scripts, with its whopping 132 lines of python. Itā€™s powered by the same database Iā€™m using for webpkg, the ā€œofficialā€ (I mean, the maintainer is espie@, you canā€™t get more official than that, amrite?) sqlite database, with an extra virtual table for the full text search.

Future plans

I donā€™t really have a clear list of things, but I want for sure to enhance these scripts, ā€˜manā€™ in particular. It would be cool to have structured URLs to reach the manpages, and maybe render the pages as gemtext instead of plain text. Having the ā€œSEE ALSOā€ section rendered as a list of links would be really, really useful.

For GemPKG/WebPKG I donā€™t know what could be added, maybe some sort of listing of the directories? Dunno.

On the gmid side, I definitely want to add support for virtual hosts and automatic certificates generation. These will hopefully be the 1.4 and 1.5 versions. Then Iā€™d also like to split gmid into multiple process: I heard that OpenBSDā€™ httpd(8)/relayd(8) uses privsep to further protect the certificate, Iā€™ll definitely look into that.

Thanks for reading and, as always, patches are welcome. Just open a PR on github or send me a patch at <op at omarpolo dot com>.

-- text: CC0 1.0; code: public domain (unless specified otherwise). No copyright here.