Re: Sending message to user from protocol
By: deepthaw to Digital Man on Thu Nov 12 2020 08:57 pm
As mentioned earlier, I spent the evening teaching myself bash scripting by writing an http file transfer protocol. Nothing fancy, what it does is copy the files requested to a directory on your web server then sends them a URL which expires that they can use to download them in a web browser. Might be nice for sites that use that fancy HTML telnet client for which I never got any of the protocols to work (but then they're probably using the rest of echicken's stuff which lets them download via ftp and ... i just wanted to learn some bash.)
Anyways: This is barely tested but seems to work. I'm new with linux programming, bash especially, so there's bound to be some security bugs I've not found yet.
Save it to your /sbbs/exec, and add a new protocol called HTTP or whatever. command line for download should be %!httpdl.sh%. %h %f and batch download should be %!httpdl.sh%. %h @%f make sure to enable native application and socket IO. (It was DM himself who tipped me off that my approach was wrong.)
#!/bin/bash
# we generate a uuid to use for storage of the files. we only keep
# the first 8 characters
uuid=$(uuidgen)
dirhash="${uuid:0:8}"
# the base url from which files will be downloaded downloadprefix="
http://deepthaw.net/bbs_downloads/"
mkdir -m715 "/var/www/html/bbs_downloads/$dirhash" # is 715 safe?
# setup some needed variables
descriptor="$1" # socket descriptor
files="$2" # file or list of files if it starts with @
# if the first character in the name of $files is @, we read every line
if [ "${files:0:1}" == '@' ]; then
batch="${files:1}"
while IFS=$' \t\n\r' read -r line; # i hate bash
do
cp -p "$line" "/var/www/html/bbs_downloads/$dirhash"
done < "$batch"
else
cp -p "$files" "/var/www/html/bbs_downloads/$dirhash"
fi
# from at package - lets us schedule jobs for later
echo "rm -rf /var/www/html/bbs_downloads/$dirhash" | at now +60 minutes
# tell users where to find the files on the website
&$descriptor printf 'your file(s) will be available at\r\n%s%s/ for one hour.\$
# close socket
exec >&-
---
þ Synchronet þ c.o.r.t.e.x 2.0.2.0 |
telnet://deepthaw.net