aboutsummaryrefslogtreecommitdiffstats
path: root/nocompile/libexec/gopherd.sh
diff options
context:
space:
mode:
Diffstat (limited to 'nocompile/libexec/gopherd.sh')
-rwxr-xr-xnocompile/libexec/gopherd.sh33
1 files changed, 33 insertions, 0 deletions
diff --git a/nocompile/libexec/gopherd.sh b/nocompile/libexec/gopherd.sh
new file mode 100755
index 0000000..6d12cd6
--- /dev/null
+++ b/nocompile/libexec/gopherd.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+#I'm aware of the LFI. Have fun looking around my server.
+read -t 10 req
+base="$1"
+req=$(echo "$req" | tr -d '\r')
+realpath=$(realpath ${base}${req})
+if grep -v "^${base}" <<< "${realpath}" > /dev/null;then
+ echo ${base}
+ echo ${realpath}
+ exit 1
+fi
+hostname=$(/usr/local/bin/hop0 $(/usr/local/libexec/peerip))
+type=$(file "${realpath}" | cut -d: -f2-)
+if grep directory <<< "$type" 2>&1 > /dev/null; then
+ if [ -e "${realpath}/.header" ];then
+ cat "${realpath}/.header" | sed "s/^/i&/g" | sed "s/\$/"`printf "\r"`"/g"
+ fi
+ for i in $(ls "${realpath}");do
+ stype=$(file "${realpath}/${i}" | cut -d: -f2-)
+ if grep directory <<< "$stype" 2>&1 > /dev/null; then
+ printf "1%s\t%s\t%s\t70\r\n" ${req}/${i} ${req}/${i} $hostname
+ else
+ printf "0%s\t%s\t%s\t70\r\n" ${req}/${i} ${req}/${i} $hostname
+ fi
+ done
+ printf ".\r\n"
+else
+ if stat "${realpath}" | cut '-d ' -f3 | grep x >/dev/null;then
+ "${realpath}"
+ else
+ cat "${realpath}"
+ fi
+fi