Blame


1 58b6d3d1 2020-11-10 op I’ve just tagged the version 1.3 of gmid, a dead simple zero configuration gemini server, which brings in CGI scripts supports.
2 58b6d3d1 2020-11-10 op
3 58b6d3d1 2020-11-10 op => /pages/gmid.gmi gmid project page
4 58b6d3d1 2020-11-10 op => /post/gmid.gmi gmid presentation
5 58b6d3d1 2020-11-10 op
6 58b6d3d1 2020-11-10 op 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?
7 58b6d3d1 2020-11-10 op
8 58b6d3d1 2020-11-10 op ### Hello World
9 58b6d3d1 2020-11-10 op => gemini://gemini.omarpolo.com/cgi/hello-world Hello World
10 58b6d3d1 2020-11-10 op
11 58b6d3d1 2020-11-10 op 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.
12 58b6d3d1 2020-11-10 op
13 58b6d3d1 2020-11-10 op Yeah, counting this felt just like cheating…
14 58b6d3d1 2020-11-10 op
15 58b6d3d1 2020-11-10 op ### OpenBSD manpages
16 58b6d3d1 2020-11-10 op => gemini://gemini.omarpolo.com/cgi/man man
17 58b6d3d1 2020-11-10 op
18 58b6d3d1 2020-11-10 op 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.
19 58b6d3d1 2020-11-10 op
20 58b6d3d1 2020-11-10 op => /img/cgi-man-elpher.png How it looks (37.9K)
21 58b6d3d1 2020-11-10 op
22 58b6d3d1 2020-11-10 op This also exposed a difference in how plan9ports’ rc and whoever the upstream for the FreeBSD rc package is treat the empty string.
23 58b6d3d1 2020-11-10 op
24 58b6d3d1 2020-11-10 op In plan9ports rc, the following code do the right thing™
25 58b6d3d1 2020-11-10 op
26 58b6d3d1 2020-11-10 op ``` rc
27 58b6d3d1 2020-11-10 op if (~ $QUERY_STRING '') {
28 58b6d3d1 2020-11-10 op echo '10 manpage:^M' # the ^M should be the real CR
29 58b6d3d1 2020-11-10 op exit 0
30 58b6d3d1 2020-11-10 op }
31 58b6d3d1 2020-11-10 op ```
32 58b6d3d1 2020-11-10 op
33 58b6d3d1 2020-11-10 op 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.
34 58b6d3d1 2020-11-10 op
35 58b6d3d1 2020-11-10 op ``` rc
36 58b6d3d1 2020-11-10 op if (~ $#QUERY_STRING 0) { # <- added ‘#’ after the sigil
37 58b6d3d1 2020-11-10 op echo '10 manpage:^M'
38 58b6d3d1 2020-11-10 op exit 0
39 58b6d3d1 2020-11-10 op }
40 58b6d3d1 2020-11-10 op ```
41 58b6d3d1 2020-11-10 op
42 58b6d3d1 2020-11-10 op 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’.
43 58b6d3d1 2020-11-10 op
44 58b6d3d1 2020-11-10 op This is all due the fact that, while I use OpenBSD on my desktop, for “historical reasons” I’m using FreeBSD on my server.
45 58b6d3d1 2020-11-10 op
46 58b6d3d1 2020-11-10 op 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’.
47 58b6d3d1 2020-11-10 op
48 58b6d3d1 2020-11-10 op => https://mandoc.bsd.lv/ mandoc website
49 58b6d3d1 2020-11-10 op
50 58b6d3d1 2020-11-10 op ### GemPKG
51 58b6d3d1 2020-11-10 op => gemini://gemini.omarpolo.com/cgi/gempkg GemPKG, explore the OpenBSD port catalog
52 58b6d3d1 2020-11-10 op => https://webpkg.omarpolo.com WebPKG, the HTTP version
53 58b6d3d1 2020-11-10 op
54 58b6d3d1 2020-11-10 op 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.
55 58b6d3d1 2020-11-10 op
56 58b6d3d1 2020-11-10 op The URLs are also intuitive:
57 58b6d3d1 2020-11-10 op * /cgi/gempkg is the home page
58 58b6d3d1 2020-11-10 op * /cgi/gempkg/search is the search page
59 58b6d3d1 2020-11-10 op * /cgi/gempkg/$PATH is the page for the port denoted by ‘$PATH’ (usually category/name, but not always)
60 58b6d3d1 2020-11-10 op
61 58b6d3d1 2020-11-10 op => /img/cgi-gempkg-amfora.png GemPKG Screenshot (32.1K)
62 58b6d3d1 2020-11-10 op
63 58b6d3d1 2020-11-10 op 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.
64 58b6d3d1 2020-11-10 op
65 58b6d3d1 2020-11-10 op ## Future plans
66 58b6d3d1 2020-11-10 op
67 58b6d3d1 2020-11-10 op 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.
68 58b6d3d1 2020-11-10 op
69 58b6d3d1 2020-11-10 op For GemPKG/WebPKG I don’t know what could be added, maybe some sort of listing of the directories? Dunno.
70 58b6d3d1 2020-11-10 op
71 58b6d3d1 2020-11-10 op 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.
72 58b6d3d1 2020-11-10 op
73 58b6d3d1 2020-11-10 op 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>.