summaryrefslogtreecommitdiffstats
path: root/kratek.sh
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 /kratek.sh
parentUpdate index.php (diff)
downloadbalkan-shortlink-7cca9f27bacbdf99c5b39b925f56109de8faa496.tar
balkan-shortlink-7cca9f27bacbdf99c5b39b925f56109de8faa496.tar.gz
balkan-shortlink-7cca9f27bacbdf99c5b39b925f56109de8faa496.tar.bz2
balkan-shortlink-7cca9f27bacbdf99c5b39b925f56109de8faa496.tar.lz
balkan-shortlink-7cca9f27bacbdf99c5b39b925f56109de8faa496.tar.xz
balkan-shortlink-7cca9f27bacbdf99c5b39b925f56109de8faa496.tar.zst
balkan-shortlink-7cca9f27bacbdf99c5b39b925f56109de8faa496.zip
Diffstat (limited to 'kratek.sh')
-rwxr-xr-xkratek.sh72
1 files changed, 72 insertions, 0 deletions
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