š¾ Archived View for gemini.omarpolo.com āŗ post āŗ gmid-cgi-and-services.gmi captured on 2022-04-28 at 17:29:23. Gemini links have been rewritten to link to archived content
ā¬ ļø Previous capture (2022-01-08)
ā”ļø Next capture (2022-06-03)
-=-=-=-=-=-=-
Written while listening to āPiccola CittĆ ā by Francesco Guccini.
Published: 2020-11-10
Tagged with:
Iāve just tagged the version 1.3 of gmid, a dead simple zero configuration gemini server, which brings in CGI scripts supports.
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?
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ā¦
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.
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ā.
GemPKG, explore the OpenBSD port catalog
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:
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.
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: CC-BY-SA-4.0; code: public domain unless specified otherwise
For comments, write at < blog at omarpolo dot com > or @op@bsd.network in the fediverse.