Friday, October 8, 2010

Post to PasteBin from Command-Line

Full credit for "urlencode" script goes to the author. 
I modified original "urlencode" script slightly to meet my 
needs. Original script can be downloaded at:  
http://www.shelldorado.com/scripts/cmds/urlencode
 
============
pastebin.sh
============


 
#!/bin/bash
#

name="your_name"
format="text"
expire_date="N"
private="0"


if [ -z $1 ]; then
 echo
 echo "[*] usage:  `basename $0`  filename"
 echo
 exit
fi


#DATA=`cat "$@" | uuencode -m -`
DATA=`cat "$@" | urlencode.sh -l`

curl -s -d paste_code="$DATA" -d paste_name="$name" -d paste_format="$format" -d
paste_expire_date="$expire_date" -d paste_private=$private --include http:
//pastebin.com/api_public.php | grep 'http://pastebin.com/' 
 


============
urlencode.sh
============



##########################################################################
# Title      : urlencode - encode URL data
# Author     : Heiner Steven (heiner.steven@odn.de)
# Date       : 2000-03-15
# Requires   : awk
# Categories : File Conversion, WWW, CGI
# SCCS-Id.   : @(#) urlencode 1.4 06/10/29
##########################################################################

PN=`basename "$0"`   # Program name
VER='1.4'

: ${AWK=awk}

Usage () {
    echo >&2 "$PN - encode URL data, $VER
usage: $PN [-l] [file ...]
    -l:  encode line endings (result will be one line of output)

The default is to encode each input line on its own."
    exit 1
}

Msg () {
    for MsgLine
    do echo "$PN: $MsgLine" >&2
    done
}

Fatal () { Msg "$@"; exit 1; }

set -- `getopt hl "$@" 2>/dev/null` || Usage
[ $# -lt 1 ] && Usage   # "getopt" detected an error

EncodeEOL=no
while [ $# -gt 0 ]
do
    case "$1" in
     -l) EncodeEOL=yes;;
 --) shift; break;;
 -h) Usage;;
 -*) Usage;;
 *) break;;   # First file name
    esac
    shift
done

LANG=C export LANG
$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 = "%0D%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
    }
    {
 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]
     }
 }
 if ( EncodeEOL ) {
     printf ("%s", encoded EOL)
 } else {
     print encoded
 }
    }
    END {
     #if ( EncodeEOL ) print ""
    }
' $@



0 comments:

Post a Comment