From 46d0fcd7ce3862e0679f618bcd93f2ce30367a94 Mon Sep 17 00:00:00 2001 From: Armaan Bhojwani Date: Mon, 28 Jun 2021 21:30:56 -0400 Subject: [PATCH] slink: add program --- man/slink.1.scd | 24 ++++++++++++++++++++++++ slink | 31 +++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 man/slink.1.scd create mode 100755 slink diff --git a/man/slink.1.scd b/man/slink.1.scd new file mode 100644 index 0000000..3bbe169 --- /dev/null +++ b/man/slink.1.scd @@ -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 . diff --git a/slink b/slink new file mode 100755 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 \ + \ + \ + \ +

If you are not redirected automatically, please follow this link: \ +%s.

\ +\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} -- 2.39.2