-
-
Save plytro/770999 to your computer and use it in GitHub Desktop.
bash post to tmbo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
## tmbo.sh -- my attempt at posting from the command line | |
## tmbo: lnk, twitter: @oogali | |
## | |
BASE_URL=thismight.be/offensive | |
TMBO_CONFIG=${HOME}/.tmbo | |
CURL=`which curl 2>/dev/null` | |
if [ -z "${CURL}" ]; then | |
echo "$0: curl is not installed" | |
exit 1 | |
fi | |
CURL_ARGS="-s -f" | |
FILE=`which file 2>/dev/null` | |
if [ -z "${FILE}" ]; then | |
echo "$0: file is not installed" | |
exit 1 | |
fi | |
## check if we're on OS X, different arg for mime type | |
uname -a | grep -q 'Darwin' | |
if [ $? -eq 0 ]; then | |
FILE_ARGS="-bI" | |
else | |
FILE_ARGS="-bi" | |
fi | |
while getopts "cf:mnrst" o ; do | |
case ${o} in | |
c) | |
tags="${tags}[cc]" | |
comment=1 | |
;; | |
f) | |
CONFIG=${OPTARG} | |
;; | |
m) | |
tags="${tags}[mp]" | |
;; | |
n) | |
nsfw=1 | |
;; | |
r) | |
tags="${tags}[tiar]" | |
;; | |
s) | |
tags="${tags}[scroller]" | |
;; | |
t) | |
tmbo=1 | |
;; | |
*) | |
echo "$0: unknown option" | |
exit 1 | |
;; | |
esac | |
done | |
shift $((${OPTIND} - 1)) | |
if [ $# -lt 1 ]; then | |
echo "$0 <tags> <image to upload> [filename]" | |
exit 1 | |
fi | |
image=${1} | |
echo "${image}" | grep "^http[s]*://" | |
if [ $? -eq 0 ]; then | |
downloaded=`mktemp /tmp/tmbo.XXXXXXXX` | |
if [ -z "${downloaded}" ] || [ ! -f "${downloaded}" ]; then | |
echo "$0: could not create temporary file to download" | |
exit 1 | |
fi | |
${CURL} ${CURL_ARGS} -o ${downloaded} ${image} | |
if [ $? -ne 0 ]; then | |
echo "$0: could not connect to remote url" | |
rm -f ${downloaded} | |
exit 1 | |
fi | |
${FILE} ${FILE_ARGS} ${downloaded} | grep -q '^image/' | |
if [ $? -ne 0 ]; then | |
echo "$0: downloaded file is not an image, try again" | |
rm -f ${downloaded} | |
fi | |
image=${downloaded} | |
fi | |
if [ $# -eq 1 ]; then | |
filename=`basename ${1}` | |
else | |
filename=${2} | |
fi | |
if [ ! -f "${TMBO_CONFIG}" ]; then | |
echo "$0: no configuration file found" | |
exit 1 | |
fi | |
. ${TMBO_CONFIG} | |
if [ -z "${TMBO_USERNAME}" ] || [ -z "${TMBO_PASSWORD}" ]; then | |
echo "$0: missing username or password. check configuration file" | |
exit 1 | |
fi | |
cookie_jar=`mktemp /tmp/tmbo.XXXXXXXX` | |
if [ -z "${cookie_jar}" ] || [ ! -f "${cookie_jar}" ]; then | |
echo "$0: could not create temporary cookie store" | |
exit 1 | |
fi | |
srv_output=`mktemp /tmp/tmbo.XXXXXXXX` | |
if [ -z "${srv_output}" ] || [ ! -f "${srv_output}" ]; then | |
echo "$0: could not create temporary output file" | |
exit 1 | |
fi | |
CURL_ARGS="-b ${cookie_jar} -c ${cookie_jar} -o ${srv_output} -i -s -f" | |
## create a new session | |
${CURL} ${CURL_ARGS} "http://${BASE_URL}" | |
if [ $? -ne 0 ]; then | |
echo "$0: could not connect to tmbo server" | |
rm -f ${cookie_jar} ${srv_output} ${downloaded} | |
exit 1 | |
fi | |
## log in | |
${CURL} ${CURL_ARGS} -d "username=${TMBO_USERNAME}&password=${TMBO_PASSWORD}" "https://${BASE_URL}/logn.php" | |
if [ $? -ne 0 ]; then | |
echo "$0: could not connect to tmbo server" | |
rm -f ${cookie_jar} ${srv_output} ${downloaded} | |
exit 1 | |
fi | |
grep -q '^Location: /offensive/?c=' ${srv_output} | |
if [ $? -ne 0 ]; then | |
echo "$0: could not log into tmbo, check your credentials" | |
cat ${srv_output} | |
rm -f ${cookie_jar} ${srv_output} ${downloaded} | |
exit 1 | |
fi | |
${CURL} ${CURL_ARGS} "http://${BASE_URL}/index.php?c=upload" | |
if [ $? -ne 0 ]; then | |
echo "$0: could not connect to tmbo server" | |
rm -f ${cookie_jar} ${srv_output} ${downloaded} | |
exit 1 | |
fi | |
remaining_uploads=`grep "You have [0-9]* uploads left" "${srv_output}" | sed 's/.*You have \([0-9]*\) uploads left.*/\1/g'` | |
if [ -z "${remaining_uploads}" ] || [ "${remaining_uploads}" -eq 0 ]; then | |
echo "$0: sorry, no more uploads today" | |
else | |
if [ ! -z "${tags}" ]; then | |
tags="${tags} " | |
fi | |
## urlencode the filename | |
#filename=`echo -n "${tags}${filename}" | perl -p -e 's/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg'` | |
if [ ! -z "${nsfw}" ]; then | |
postargs="${postargs}-F 'nsfw=1' " | |
fi | |
if [ ! -z "${tmbo}" ]; then | |
postargs="${postargs}-F 'tmbo=1' " | |
fi | |
${CURL} ${CURL_ARGS} -F "c=upload" -F "filename=${filename}" ${postargs} -F "image=@${image};filename=${filename}" "http://${BASE_URL}/index.php" | |
if [ $? -ne 0 ]; then | |
echo "$0: could not connect to tmbo server" | |
rm -f ${cookie_jar} ${srv_output} ${downloaded} | |
exit 1 | |
fi | |
grep -q 'Your upload can be viewed' ${srv_output} | |
if [ $? -ne 0 ]; then | |
grep -q 'Compress my file.' ${srv_output} | |
if [ $? -eq 0 ]; then | |
${CURL} ${CURL_ARGS} -d "c=upload" -d "resample=Compress%20my%20file%2e" "http://${BASE_URL}/index.php" | |
if [ $? -ne 0 ]; then | |
echo "$0: could not connect to tmbo server" | |
rm -f ${cookie_jar} ${srv_output} ${downloaded} | |
exit 1 | |
fi | |
url=`grep 'Your upload can be viewed' ${srv_output} | sed 's/.*href="\.\(.*\)">here.*/\1/g'` | |
echo "http://${BASE_URL}/${url}" | |
fi | |
else | |
url=`grep 'Your upload can be viewed' ${srv_output} | sed 's/.*href="\.\(.*\)">here.*/\1/g'` | |
echo "http://${BASE_URL}/${url}" | |
fi | |
fi | |
## logout | |
${CURL} ${CURL_ARGS} https://${BASE_URL}/logout.php | |
if [ $? -ne 0 ]; then | |
echo "$0: could not connect to tmbo server" | |
rm -f ${cookie_jar} ${srv_output} ${downloaded} | |
exit 1 | |
fi | |
rm -f ${cookie_jar} ${srv_output} ${downloaded} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment