CGI with Vger

Update 2022-02-02: added tic-tac-toe.cgi; see below

I have been running vger on my OpenBSD server for a while and am pretty happy with it. It is written by OpenBSD developer solene@ and has the right combination of small codebase and use of security mitigations like unveil(2).

Last week, I came across a capsule that features a "like button" on its pages:

This got me curious about CGI with gemini. After asking on tilde.chat #gemini IRC, tomasino gave me some hints, including from his video on the topic:

First I thought I would need a different gemini server to do that, but then I saw that vger supports CGI via the `-c` flag. I created a directory `cgi-bin` and passed it to vger in inetd.conf which now looks like this:

127.0.0.1:11965	stream	tcp	nowait	gemini_user	/usr/local/bin/vger	vger -i -v -d /var/gemini/ -c /var/gemini/thfr.info/cgi-bin

I started with my first hello-world script, based on what I had previously made for HTTP CGI. I quickly realized that instead of "Content-type text/plain" I had to send "20 text/gemini" as the header, followed by CRLF (20 indicates success in gemini specification).

That worked, so I set out to make 2 other, more interactive CGI examples. Here is a list of the (fairly simple) early CGI applications:

Hello World
Persistent Counter
Popcat clone (missing counter and statistics)
Tic-Tac-Toe

Popcat is based on:

And here the links to view or download the source code of these 3 examples:

Potential Future Project Ideas

Remaining Questions