summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2022-10-15 22:15:29 +0200
committerAnton Luka Šijanec <anton@sijanec.eu>2022-10-15 22:15:29 +0200
commit7cca9f27bacbdf99c5b39b925f56109de8faa496 (patch)
tree8f5b8420dddc41d7439d16d99538f751b61911b3
parentUpdate index.php (diff)
downloadbalkan-shortlink-master.tar
balkan-shortlink-master.tar.gz
balkan-shortlink-master.tar.bz2
balkan-shortlink-master.tar.lz
balkan-shortlink-master.tar.xz
balkan-shortlink-master.tar.zst
balkan-shortlink-master.zip
-rw-r--r--README.md6
-rwxr-xr-xkratek.sh72
2 files changed, 78 insertions, 0 deletions
diff --git a/README.md b/README.md
index 322ea39..7629825 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,9 @@
+# kratek.sh
+
+cgi script used on http://4a.si.
+
+ --- below is old text ---
+
# balkan-shortlink
Šortlink generator written in PHP and MySQL
diff --git a/kratek.sh b/kratek.sh
new file mode 100755
index 0000000..f298b20
--- /dev/null
+++ b/kratek.sh
@@ -0,0 +1,72 @@
+#!/bin/sh
+f="`cut -d/ -f2 <<<"$DOCUMENT_URI" | head -n1`"
+k="`tr "&" "\n" <<<"$QUERY_STRING" | grep -m1 '^k=' | cut -d= -f2 | head -n1`"
+d="`tr "&" "\n" <<<"$QUERY_STRING" | grep -m1 '^d=' | cut -d= -f2 | head -n1`"
+if [ x"$f" = x ]
+then
+ true
+else
+ k="$f"
+fi
+if grep '^[[:alnum:]]*$' <<<"$k" > /dev/null && grep '^[[:alnum:]]*$' <<<"$d" > /dev/null
+then
+ r="`grep --text ^"$k"\\\\s /tmp/db 2> /dev/null | cut -f2 | head -n1`"
+else
+ b=1
+fi
+if [ x = x"$f" ]
+then
+ if [ x = x"$k" ] && [ x = x"$d" ]
+ then
+ echo Status: 200
+ echo Content-Type: text/html
+ echo
+ echo "<form><label for=k>kratek</label><input id=k name=k><label for=d>dolg</label><input id=d name=d><input type=submit></form><a href=//splet.sijanec.eu>moja spletna stran</a>"
+ echo
+ else
+ if [ x"$r" = x ]
+ then
+ if [ x$b = x1 ]
+ then
+ echo Status: 400
+ echo Content-Type: text/plain
+ echo
+ echo 400
+ echo 'grep ^[[:alnum:]]*$ <<<"$x"'
+ echo
+ else
+ echo "$k $d" >> /tmp/db
+ echo Status: 201
+ echo Content-Type: text/plain
+ echo
+ fi
+ else
+ echo Status: 409
+ echo Content-Type: text/plain
+ echo
+ echo 409
+ echo '[ x"`grep --text ^"$k"$ db | cut -f2^`" = x ]'
+ echo "$r"
+ fi
+ fi
+else
+ if [ x"$r" = x ]
+ then
+ echo Status: 404
+ echo Content-Type: text/plain
+ echo
+ echo 404
+ echo 'grep --text ^"$k"$ db | cut -f2'
+ echo f: "$f"
+ echo k: "$k"
+ echo d: "$d"
+ echo
+ else
+ echo Status: 301
+ echo Content-Type: text/plain
+ echo Location: "$r"
+ echo
+ echo "$r"
+ echo
+ fi
+fi