summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKatolaZ <katolaz@freaknet.org>2018-07-31 21:49:59 +0100
committerKatolaZ <katolaz@freaknet.org>2018-07-31 21:49:59 +0100
commit181800b700d89f79b57ba634a19a3fa62ad6d9a5 (patch)
treed5de1a5186768b6645f3ae4267e1169d4e7e9c15
parentfdba713eea76ecaf1d5c9829b1b4a6c511d95989 (diff)
infinite loop
-rwxr-xr-xburrow62
1 files changed, 50 insertions, 12 deletions
diff --git a/burrow b/burrow
index be0739f..4ac35fd 100755
--- a/burrow
+++ b/burrow
@@ -1,14 +1,19 @@
#!/bin/sh
-### read from $1 and print on stdout a list of DIR selectors
-### one per line, terminated by a line with ".\r\n"
+### read from $1 and print on stdout a list of MENU selectors IDs
+### in the format:
+###
+### 1|SELECTOR|HOST|PORT|SHA256
+###
+### where SHA256 is the SHA256SUM of "1|SELECTOR|HOST|PORT"
+###
## function
get_dirs(){
+ src_id="$1"
OLDIFS=$IFS
#IFS=$'\t\n'
-## IFS="$(echo t | tr t \\t)
-##"
IFS="|"
+ src_dir=$(echo "${src_id}" | cut -c -2)
while read name sel host port; do
## echo " --- name: \"$name\""
## echo " --- sel: \"$sel\""
@@ -17,19 +22,52 @@ get_dirs(){
TYPE=$(echo "$name" | cut -c 1)
## echo " --- TYPE \"$TYPE\""
## echo "$TYPE, $name, $sel, $host, $port"
+ port=$(echo $port | sed -r -e 's/\r//g')
+ dir_id=$(echo "${TYPE}|${sel}|${host}|${port}" | sed 's/^1||/1|\/|/g')
+ dest_id=$(echo "${dir_id}" | sha256sum | cut -d " " -f 1 )
+ echo "${src_id}" "${dest_id}" >&2
[ "${TYPE}" = "1" ] && {
- port=$(echo $port | sed -r -e 's/\r//g')
- dir_id=$(echo "${TYPE}|${sel}|${host}|${port}" | sed 's/^1||/1|\/|/g')
- sid=$(echo "${dir_id}" | sha256sum | cut -d " " -f 1 )
- echo "${dir_id}|${sid}"
+ echo "${dir_id}|${dest_id}" | tee -a ${src_dir}/${src_id}
}
done
- IFS=$OLDIFS
+ IFS="$OLDIFS"
}
-FIN=${1:-"/dev/stdin"}
-SRC="$2"
+### get a MENU selector ID (as generated by get_dirs) and retrieves it
+### from the gopherspace
+###
+## function
+retrieve_selector(){
+ sel="$1"
+ SEL=$(echo "$1" | cut -d "|" -f 2)
+ HOST=$(echo "$1" | cut -d "|" -f 3)
+ PORT=$(echo "$1" | cut -d "|" -f 4)
+ printf "${SEL}\r\n" | netcat -w 15 "${HOST}" "${PORT}"
+
+}
+
+###
+### Check if a given selector has been visited. In that case, just
+### output the corresponding file (which contains all the outgoing links
+### of the selector) and exits
+###
+## function
+check_selector_present(){
+ sel_id="$1"
+ sel_dir="$(echo ${sel_id} | cut -c -2)"
+ [ -d "${sel_dir}" -a -f "${sel_dir}/${sel_id}" ] && cat ${sel_dir}/${sel_id} && echo ${sel_id}>>present && exit 1
+ [ ! -d "${sel_dir}" ] && mkdir -p "${sel_dir}"
+}
+
+
+SRC="$1"
+
+src_id=$(echo "$SRC" | cut -d "|" -f 5 )
+
+check_selector_present "${src_id}"
-cat "$FIN" | sed -r -e 's/\t/|/g' | get_dirs
+echo "selector ${src_id} not found" >> logfile.txt
+retrieve_selector "$SRC" | sed -r -e 's/\t/|/g' | get_dirs "${src_id}"
+