#! /bin/sh # Copyright 2004 Leslie A. Hensley # hensleyl@papermountain.org # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA PN=`basename "$0"` # Program name VER=0.4 : ${DROPOFF_SERVER="dropoff.org"} : ${DROPOFF_PORT="80"} : ${DROPOFF_TELNET_DELAY="2"} Usage () { echo >&2 "$PN - share a file on the internet, $VER usage: $PN [-n name] [-c | -p |file] -n: use 'name' instead of the name of the file as it's storage name -h: display this help If a file, the -c option, or the -p option is not provided then stdin is used. Uses wget if available." exit 1 } # cribbed from http://www.shelldorado.com/scripts/cmds/urlencode.txt urlencode() { EncodeEOL="$1" shift awk ' BEGIN { # We assume an awk implementation that is just plain dumb. # We will convert an character to its ASCII value with the # table ord[], and produce two-digit hexadecimal output # without the printf("%02X") feature. EOL = "%0A" # "end of line" string (encoded) split ("1 2 3 4 5 6 7 8 9 A B C D E F", hextab, " ") hextab [0] = 0 for ( i=1; i<=255; ++i ) ord [ sprintf ("%c", i) "" ] = i + 0 if ("'"$EncodeEOL"'" == "yes") EncodeEOL = 1; else EncodeEOL = 0 FirstLine = 1 } { if ( FirstLine == 0 && EncodeEOL ) printf("%s", EOL); else FirstLine = 0 encoded = "" for ( i=1; i<=length ($0); ++i ) { c = substr ($0, i, 1) if ( c ~ /[a-zA-Z0-9.-]/ ) { encoded = encoded c # safe character } else if ( c == " " ) { encoded = encoded "+" # special handling } else { # unsafe character, encode it as a two-digit hex-number lo = ord [c] % 16 hi = int (ord [c] / 16); encoded = encoded "%" hextab [hi] hextab [lo] } } printf("%s", encoded) } ' "$@" #Handle binary files if [ `cat "$@" | sed -n '$p' | wc -l` -eq 1 ] && [ $EncodeEOL == "yes" ] then echo -n "%0A" fi } set -- `getopt n:pch "$@" 2>/dev/null` || Usage [ $# -lt 1 ] && Usage # "getopt" detected an error while [ $# -gt 0 ] do case "$1" in -n) name="$2";shift;; --) shift; break;; -h) Usage;; -*) Usage;; *) break;; # First file name esac shift done : ${name=`basename "$1"`} if (wget --version) > /dev/null 2>&1 then (echo -n "http://$DROPOFF_SERVER:$DROPOFF_PORT/store?ver=$VER&name="; (echo -n "$name" | urlencode "no"); echo -n "&data="; urlencode "yes" "$@") | wget -q -i - -O - else (echo -n "GET /store?ver=$VER&name="; (echo -n "$name" | urlencode "no"); echo -n "&data="; urlencode "yes" "$@"; echo; sleep $DROPOFF_TELNET_DELAY) | telnet $DROPOFF_SERVER $DROPOFF_PORT 2> /dev/null | sed -e "1,3d" fi echo