2023-07-23 01:07:35 +03:00
|
|
|
#!/bin/sh
|
2023-07-21 20:56:12 +03:00
|
|
|
|
|
|
|
. ./config
|
|
|
|
|
|
|
|
remote_ip=$SOCAT_PEERADDR
|
|
|
|
die(){
|
|
|
|
rm access_granted/"$remote_ip"
|
2023-07-21 22:18:04 +03:00
|
|
|
echo 'bye'
|
|
|
|
pkill -P $PPID
|
2023-07-21 20:56:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mkdir -p -m 700 access_granted
|
2023-07-24 01:08:09 +03:00
|
|
|
mkdir -p -m 700 access_denied
|
|
|
|
|
|
|
|
if [ -f access_denied/"$remote_ip" ]; then exit 0; fi
|
2023-07-24 02:26:39 +03:00
|
|
|
. ./mastodon_api.sh
|
2023-07-24 01:08:09 +03:00
|
|
|
|
2023-07-21 20:56:12 +03:00
|
|
|
generator_session=$(zcat -f $system_dict | shuf -n 2 | tr -d "\n'")
|
|
|
|
randpadding=$(head -c 8 /dev/urandom | base64)
|
|
|
|
printf "$randpadding\t$generator_session\n"
|
2023-07-22 22:42:54 +03:00
|
|
|
|
|
|
|
while read -r cmd mesg; do
|
|
|
|
if [ "$cmd" = "reg" ]; then
|
|
|
|
key=$(echo "$mesg" | cut -d' ' -f 2)
|
|
|
|
session=$(echo "$mesg" | cut -d' ' -f 1)
|
|
|
|
if [ "$session" = "$generator_session" ] && [ "$key" = "$pass_for_bbs" ]; then
|
|
|
|
touch access_granted/"$remote_ip"
|
|
|
|
echo hi $remote_ip
|
|
|
|
else
|
2023-07-21 20:56:12 +03:00
|
|
|
die
|
2023-07-21 22:18:04 +03:00
|
|
|
break
|
2023-07-21 20:56:12 +03:00
|
|
|
fi
|
2023-07-22 22:42:54 +03:00
|
|
|
fi
|
|
|
|
if [ ! -f access_granted/"$remote_ip" ]; then # Drop unregistred handshake
|
|
|
|
die
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
# ---
|
|
|
|
case $cmd in
|
|
|
|
"post") toot "$mesg" | jq '.id, .errors' ;;
|
|
|
|
"reply")
|
|
|
|
reply_id=$(echo "$mesg" | cut -d' ' -f 1)
|
|
|
|
status=$(echo "$mesg" | cut -d' ' -f 2-)
|
|
|
|
reply=$reply_id toot "$status" | jq '.id, .errors'
|
|
|
|
reply=''
|
|
|
|
;;
|
2023-07-24 11:17:48 +03:00
|
|
|
"home")
|
|
|
|
tlhome=$(timeline_home "$mesg")
|
|
|
|
tlhome_len=$(echo "$tlhome" | wc -l)
|
|
|
|
current_pos=1
|
|
|
|
while read -r cursor; do
|
|
|
|
if [ ':q' = "$cursor" ]; then break; fi
|
|
|
|
if [ ':all' = "$cursor" ]; then echo "$tlhome"; break; fi
|
|
|
|
echo "$tlhome" | awk "NR==$current_pos"
|
|
|
|
current_pos=$(($current_pos + 1))
|
|
|
|
if [ $current_pos -gt $tlhome_len ]; then break; fi
|
|
|
|
done
|
|
|
|
;;
|
2023-07-22 22:42:54 +03:00
|
|
|
"reg") printf 'bbs > '; continue ;;
|
|
|
|
"x")
|
|
|
|
case $mesg in
|
|
|
|
"http"*) w3m -dump -T text/html -cols 34 -o 'display_link_number=1' "$mesg" ;;
|
|
|
|
*) echo 'only http(s)' ;;
|
|
|
|
esac
|
|
|
|
;;
|
2023-07-23 01:07:35 +03:00
|
|
|
"testio")
|
|
|
|
printf 'test io > '
|
|
|
|
while read -r testinput; do
|
|
|
|
if [ ':q' = "$testinput" ]; then break; fi
|
|
|
|
if [ '1M' = "$testinput" ]; then
|
|
|
|
dd if=/dev/zero bs=1K count=1024 2>&1
|
|
|
|
else
|
|
|
|
echo "$testinput" | dd 2>&1
|
|
|
|
fi
|
|
|
|
printf 'test io > '
|
|
|
|
done
|
|
|
|
toot $full_status | jq '.id, .errors'
|
|
|
|
;;
|
2023-07-22 22:42:54 +03:00
|
|
|
*) die; break ;;
|
|
|
|
esac
|
|
|
|
printf 'bbs > '
|
|
|
|
done
|
2023-07-21 20:56:12 +03:00
|
|
|
rm access_granted/"$remote_ip"
|
|
|
|
echo 'session was close'
|