From 7cca9f27bacbdf99c5b39b925f56109de8faa496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Sat, 15 Oct 2022 22:15:29 +0200 Subject: kratek.sh --- README.md | 6 ++++++ kratek.sh | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100755 kratek.sh 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 "
moja spletna stran" + 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 -- cgit v1.2.3