]> git.armaanb.net Git - bin.git/commitdiff
slink: add program
authorArmaan Bhojwani <me@armaanb.net>
Tue, 29 Jun 2021 01:30:56 +0000 (21:30 -0400)
committerArmaan Bhojwani <me@armaanb.net>
Tue, 29 Jun 2021 01:30:56 +0000 (21:30 -0400)
man/slink.1.scd [new file with mode: 0644]
slink [new file with mode: 0755]

diff --git a/man/slink.1.scd b/man/slink.1.scd
new file mode 100644 (file)
index 0000000..3bbe169
--- /dev/null
@@ -0,0 +1,24 @@
+slink(1)
+
+# NAME
+*slink* - link shortener
+
+# SYNOPSIS
+Run with your favorite web server
+
+# DESCRIPTION
+CGI program written in awk that reads a list of redirects from a file and serves
+them. Looks for the list in */etc/slink* or from the file specified in the first
+command line argument. The first column of the file has the initial path (in
+$PATH_INFO format), and the second column has the target.
+
+## EXAMPLE
+```
+/first-input https://target-url.com
+/second-input https://second-target-url.com
+/third-input https://third-target-url.com
+```
+
+# COPYRIGHT
+This is free and unencumbered software released into the public domain. For more
+information, please refer to <https://unlicense.org/>.
diff --git a/slink b/slink
new file mode 100755 (executable)
index 0000000..40b8828
--- /dev/null
+++ b/slink
@@ -0,0 +1,31 @@
+#!/usr/bin/env sh
+
+awk -v path=$PATH_INFO '
+BEGIN {
+               if (path == "/") {
+                               print "Content-type: text/plain\n \
+You'\''ve reached Armaan'\''s link shortner. Not much to see here on the index"
+                               cut = 1
+                               exit 1
+               }
+}
+
+path == $1 {
+               printf "Content-type: text/html\n \
+<!DOCTYPE html><html lang=\"en\"><head> \
+<meta http-equiv=\"refresh\" content=\"0; URL=%s\"> \
+</head><body> \
+<p>If you are not redirected automatically, please follow this link: \
+<a href=\"%s\">%s</a>.</p> \
+</body></html>\n", $2, $2, $2
+               cut = 1
+               exit 0
+}
+
+END {
+               if (cut) exit 0
+               print "Status: 404 \
+Content-type: text/plain\n \
+Path not found."
+}
+' ${1:-/etc/slink}