Add DCGI/CGI to parse bozohttpd directory listing and show text files - gophercgis - Collection of gopher CGI/DCGI for geomyidae
(HTM) hg clone https://bitbucket.org/iamleot/gophercgis
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) changeset 70b909bd9bc3eea1393a4e97ec4887d60b303d06
(DIR) parent b56ff3e7f25fe2ffb97347d65fcef5c49e8feb01
(HTM) Author: Leonardo Taccari <iamleot@gmail.com>
Date: Fri, 1 Mar 2019 18:39:24
Add DCGI/CGI to parse bozohttpd directory listing and show text files
XXX: Binary files are treated like text files and that's a bug/known
XXX: limitation!
Diffstat:
bozodirs/bozodirs.dcgi | 28 ++++++++++++++++++++++++++++
bozodirs/fetch.cgi | 13 +++++++++++++
2 files changed, 41 insertions(+), 0 deletions(-)
---
diff -r b56ff3e7f25f -r 70b909bd9bc3 bozodirs/bozodirs.dcgi
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bozodirs/bozodirs.dcgi Fri Mar 01 18:39:24 2019 +0100
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+. ../common/config.sh
+
+CGI="${CGI_BASEDIR}/bozodirs/fetch.cgi"
+DCGI="${CGI_BASEDIR}/bozodirs/bozodirs.dcgi"
+
+if [ -n "$2" ]; then
+ url=$2
+else
+ exit 1
+fi
+
+curl -Lgs -- "${url}" |
+awk -v url="${url}" -v cgi="${CGI}" -v dcgi="${DCGI}" \
+'
+{
+ if (match($0, /href="[^"]+"/)) {
+ href = substr($0, RSTART + 6, RLENGTH - 7)
+ type = substr(href, length(href)) == "/" ? 1 : 0
+ printf("[%s|%s|%s?%s|server|port]\n",
+ type,
+ href,
+ type ? dcgi : cgi,
+ url href)
+ }
+}
+'
diff -r b56ff3e7f25f -r 70b909bd9bc3 bozodirs/fetch.cgi
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bozodirs/fetch.cgi Fri Mar 01 18:39:24 2019 +0100
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+. ../common/config.sh
+
+CGI="${CGI_BASEDIR}/bozodirs/fetch.cgi"
+
+if [ -n "$2" ]; then
+ url=$2
+else
+ exit 1
+fi
+
+curl -Lgs -- "${url}"