summaryrefslogtreecommitdiff
path: root/nocompile/libexec
diff options
context:
space:
mode:
authorEpoch Qwert <epoch@53flpnlls43fcguy.onion>2014-12-24 07:31:09 -0600
committerEpoch Qwert <epoch@53flpnlls43fcguy.onion>2014-12-24 07:31:09 -0600
commit9750d3845bd5bbc2e5e76134b8c4a902faa9bce9 (patch)
tree1b38f9a5a0e80eee6be6d93d33aeab0dd9ca641b /nocompile/libexec
parent612926651db0c13fa9f45f58764b56ab132b211c (diff)
downloadmisc-9750d3845bd5bbc2e5e76134b8c4a902faa9bce9.tar.gz
misc-9750d3845bd5bbc2e5e76134b8c4a902faa9bce9.zip
added IPv6 support to hop0, peerip, and gopherd.sh
gopherd.sh got lots of other updates too. speed is for measuring how many lines per second your pipes can do.
Diffstat (limited to 'nocompile/libexec')
-rwxr-xr-xnocompile/libexec/gopherd.sh42
1 files changed, 29 insertions, 13 deletions
diff --git a/nocompile/libexec/gopherd.sh b/nocompile/libexec/gopherd.sh
index 9d3ba5c..57b3554 100755
--- a/nocompile/libexec/gopherd.sh
+++ b/nocompile/libexec/gopherd.sh
@@ -1,13 +1,14 @@
#!/bin/bash
export PATH=$PATH:/usr/local/bin
-#set these two variables if you have your server behind DMZ
read -t 10 req
base="$1"
-req=$(echo "$req" | tr -d '\r')
-realpath=$(realpath ${base}${req})
+arg=$(echo "$req" | tr -d '\r' | cut -f2)
+req=$(echo "$req" | tr -d '\r' | cut -f1)
+realpath="$(realpath "${base}${req}")"
if grep -v "^${base}" <<< "${realpath}" > /dev/null;then
echo ${base}
echo ${realpath}
+ echo 'error!!! cant find base in realpath'
exit 1
fi
myIP=$(hop0 $(/usr/local/libexec/peerip | head -n1))
@@ -15,28 +16,43 @@ hostname=$(rdns ${myIP})
if [ ! "${hostname}" ]; then
hostname=${myIP}
else
- if [ $(dig +short $hostname) != ${myIP} ];then
- logger "hostname (${hostname}) and IP (${myIP}) aren't matching up. >_>";
- exit 2
+ if strstr "${myIP}" ":";then
+ if [ $(dig -t AAAA +short $hostname) != ${myIP} ];then
+ logger "hostname (${hostname}) and IP (${myIP}) aren't matching up.";
+ exit 2
+ fi
+ else
+ if [ $(dig -t A +short $hostname) != ${myIP} ];then
+ logger "hostname (${hostname}) and IP (${myIP}) aren't matching up.";
+ exit 2
+ fi
fi
fi
+export hostname
+export port=70
type=$(file "${realpath}" | cut -d: -f2-)
-if grep directory <<< "$type" 2>&1 > /dev/null; then
+if strstr "$type" "directory";then
if [ -e "${realpath}/.header" ];then
- cat "${realpath}/.header" | sed "s/^/i&/g" | sed "s/\$/"`printf "\r"`"/g"
+ cat "${realpath}/.header" | while read -r l;do
+ printf "i%s\t%s\t%s\t%s\r\n" "$l" "fake" "(NULL)" "0"
+ done
fi
- for i in $(ls "${realpath}");do
+ ls "${realpath}" | while read i;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
+ if strstr "$stype" "directory"; then
+ printf "1%s\t%s\t%s\t%s\r\n" "${req}/${i}" "${req}/${i}" $hostname $port
else
- printf "0%s\t%s\t%s\t70\r\n" ${req}/${i} ${req}/${i} $hostname
+ if stat "${realpath}/${i}" | cut '-d ' -f3 | grep x >/dev/null;then
+ printf "7%s\t%s\t%s\t%s\r\n" "${req}/${i}" "${req}/${i}" $hostname $port
+ else
+ printf "0%s\t%s\t%s\t%s\r\n" "${req}/${i}" "${req}/${i}" $hostname $port
+ fi
fi
done
printf ".\r\n"
else
if stat "${realpath}" | cut '-d ' -f3 | grep x >/dev/null;then
- "${realpath}"
+ "${realpath}" $arg | sed "s/\$/"`printf "\r"`"/g"
else
cat "${realpath}"
fi