Last active
June 10, 2024 14:26
-
-
Save fuchsi/a1326d448a29109ec19f8657ec5928f2 to your computer and use it in GitHub Desktop.
New Propaganda upload script
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/bash | |
# | |
# New Propaganda Upload Script | |
# Copyright (C) 2018 Daniel Müller <perlfuchsi@gmail.com> | |
# | |
# 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 3 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, see <https://www.gnu.org/licenses/>. | |
## | |
# Tracker URL | |
# required | |
TRACKER_URL=${TRACKER_URL:-"https://irrenhaus.dyndns.dk"} | |
## | |
# Path to a supported maketorrent program | |
# optional, but you can only upload .torrent meta files if empty | |
# - mktorrent (https://github.com/Rudde/mktorrent) | |
# - maketorrent(https://github.com/fuchsi/maketorrent) | |
# - gomaketorrent (https://github.com/fuchsi/gomaketorrent) | |
MAKETORRENT=${MAKETORRENT:-"/usr/bin/mktorrent"} | |
## | |
# Maketorrent options | |
# -a announce urls | |
# -l piece length (2^n bytes; 2^21 = 2MB, which should be ok for most files) | |
# -c comment | |
# -p private flag | |
# -t threads | |
# See maketorrent --help for more options | |
MAKETORRENT_OPTS=${MAKETORRENT_OPTS:-"-a https://irrenhaus.dyndns.dk/announce.php -l 21 -p"} | |
## | |
# Login mode | |
# required | |
# 'cookie' use the uid, pass (and passhash) cookies for authentication | |
# 'username' use your username/password/pin combination for authentication | |
LOGIN_MODE="username" | |
## | |
# Username | |
# required for username login mode | |
LOGIN_USERNAME="" | |
## | |
# Password | |
# required for username login mode | |
LOGIN_PASSWORD="" | |
## | |
# PIN | |
# required for username login mode | |
LOGIN_PIN="" | |
## | |
# UID Cookie | |
# required for cookie login mode | |
COOKIE_UID="" | |
## | |
# Pass Cookie | |
# required for cookie login mode | |
COOKIE_PASS="" | |
## | |
# Passhash Cookie | |
# optional for cookie login mode | |
# NOT USED | |
COOKIE_PASSHASH="" | |
## | |
# Cookie Jar | |
# required, where your cookies are stored | |
COOKIE_JAR="/tmp/irrenhaus-cookies.jar" | |
## | |
# rtorrent watch dir | |
# optional | |
# | |
WATCHDIR=${WATCHDIR:-"/path/to/watchdir"} | |
## | |
# Download dir | |
# required | |
# Where your downloaded torrents are stored | |
DOWNLOAD_DIR=${DOWNLOAD_DIR:-"/path/to/download_dir"} | |
## | |
# Everything below should not be changed | |
## | |
## | |
# categories | |
categories[1]="A-book" | |
categories[2]="Album/Sampler" | |
categories[3]="Musik Pack" | |
categories[4]="Musik DVD/Vids" | |
categories[5]="Doku HD" | |
categories[6]="Doku HD Pack" | |
categories[7]="Doku SD" | |
categories[8]="Doku SD Pack" | |
categories[9]="Nintendo" | |
categories[10]="PC" | |
categories[11]="PlayStation" | |
categories[12]="XboX" | |
categories[13]="eBooks" | |
categories[14]="Mobilgeräte" | |
categories[15]="Software" | |
categories[16]="DVDR" | |
categories[17]="1080p" | |
categories[18]="720p" | |
categories[19]="h264/x264" | |
categories[20]="Xvid" | |
categories[21]="XXX" | |
categories[22]="Serie HD" | |
categories[23]="Serie HD Pack" | |
categories[24]="Serie SD" | |
categories[25]="Serie SD Pack" | |
categories[26]="Sport" | |
categories[27]="TV" | |
categories[28]="3-D" | |
## | |
# Help Mode | |
if [ $# = "0" ]; then | |
echo "irrenhaus upload script v0.1" | |
echo "usage $0 <file to upload> <nfo file> <image file> <category id>" | |
echo "" | |
echo "'file to upload' can be a .torrent file, a single file or a directory" | |
echo "nfo and image files can be local or remote files " | |
echo "category must be a valid category id. Run '$0 categories' for help" | |
exit 1 | |
fi | |
## | |
# Categories Mode | |
if [ $1 = "categories" ]; then | |
echo "Available categories:" | |
echo "ID: Name" | |
echo "" | |
# This loop will fail badly, if categories has gaps in it or is zero based | |
for index in $(seq 1 $((${#categories[@]} - 1))); do | |
echo "${index}: ${categories[$index]}" | |
done | |
fi | |
# Check the upload file | |
UPLOAD_FILE="$1" | |
NFO_FILE="$2" | |
IMAGE_FILE="$3" | |
CATEGORY="$4" | |
CREATE_TORRENT=0 | |
TORRENT_FILE="" | |
TORRENT_NAME="" | |
CURL_OPTS="-s" | |
# if nfo / image are fetched from remote urls, delete them afterwards | |
delete_nfo=0 | |
delete_image=0 | |
cleanup () { | |
# cleanup | |
if [ -e $COOKIE_JAR ]; then | |
rm $COOKIE_JAR | |
fi | |
if [ -e /tmp/irrenhaus-login ]; then | |
rm /tmp/irrenhaus-login | |
fi | |
if [ -e /tmp/irrenhaus-upload ]; then | |
rm /tmp/irrenhaus-upload | |
fi | |
if [ $delete_nfo -eq 1 ]; then | |
rm $NFO_FILE | |
fi | |
if [ $delete_image -eq 1 ]; then | |
rm $IMAGE_FILE | |
fi | |
if [ $CREATE_TORRENT -eq 1 ]; then | |
rm $TORRENT_FILE | |
fi | |
} | |
## | |
# Failure function | |
# Shows an error message, cleans up and exits with status 1 | |
# message (string) | |
goto_fail () { | |
local message="$1" | |
echo $message | |
cleanup | |
# exit with status 1 | |
exit 1 | |
} | |
if [ ! -e "${UPLOAD_FILE}" ]; then | |
goto_fail "Error: upload file not found" | |
fi | |
if [ ! -e "${NFO_FILE}" ]; then | |
# Check if NFO is a remote file | |
if [[ "${NFO_FILE}" =~ https?://* ]]; then | |
tmpfile=$(tempfile -s .nfo) | |
curl -o $tmpfile ${NFO_FILE} | |
delete_nfo=1 | |
NFO_FILE=$tmpfile | |
else | |
goto_fail "Error: nfo file not found" | |
fi | |
fi | |
if [ ! -e "${IMAGE_FILE}" ]; then | |
# Check if the image is a remote file | |
if [[ "${IMAGE_FILE}" =~ https?://* ]]; then | |
tmpfile=$(tempfile -s .jpg) | |
curl -o $tmpfile ${IMAGE_FILE} | |
delete_image=1 | |
IMAGE_FILE=$tmpfile | |
else | |
goto_fail "Error: image file not found" | |
fi | |
fi | |
# upload file is a directory | |
if [ -d "${UPLOAD_FILE}" ]; then | |
CREATE_TORRENT=1 | |
else | |
# check if it's a .torrent file | |
if [[ "${UPLOAD_FILE}" =~ *.torrent ]]; then | |
CREATE_TORRENT=0 | |
TORRENT_FILE="${UPLOAD_FILE}" | |
TORRENT_NAME=$(basename "${UPLOAD_FILE}" .torrent) | |
else | |
CREATE_TORRENT=1 | |
fi | |
fi | |
if [ $CREATE_TORRENT -eq 1 ]; then | |
ext=$(expr match "${UPLOAD_FILE}" ".*\.\(.*\)") | |
TORRENT_NAME=$(basename "${UPLOAD_FILE}" .$ext) | |
TORRENT_FILE="/tmp/${TORRENT_NAME}.torrent" | |
if [ ! -x "${MAKETORRENT}" ]; then | |
goto_fail "Error: could not execute the maketorrent program" | |
fi | |
if [ ! -e "${TORRENT_FILE}" ]; then | |
${MAKETORRENT} ${MAKETORRENT_OPTS} -n "${TORRENT_NAME}" -o "${TORRENT_FILE}" "${UPLOAD_FILE}" | |
if [ $? -ne 0 ]; then | |
goto_fail "Error: maketorrent failed (Status: $?)" | |
fi | |
fi | |
fi | |
## | |
# Login | |
if [ "${LOGIN_MODE}" = "username" ]; then | |
if [ -z "${LOGIN_USERNAME}" ]; then | |
goto_fail "You must supply a username" | |
elif [ -z "${LOGIN_PASSWORD}" ]; then | |
goto_fail "You must supply a password" | |
elif [ -z "${LOGIN_PIN}" ]; then | |
goto_fail "You must supply a pin" | |
fi | |
if [ ! -e "${COOKIE_JAR}" ]; then | |
# this is not optimal, bcz the credentials end up in the process list | |
curl ${CURL_OPTS} -X POST -H "Content-Type: application/x-www-form-urlencoded" -c ${COOKIE_JAR} -d "username=${LOGIN_USERNAME}&password=${LOGIN_PASSWORD}&pin=${LOGIN_PIN}" -o /tmp/irrenhaus-login ${TRACKER_URL}/takelogin.php | |
if [ ! -e "${COOKIE_JAR}" ]; then | |
goto_fail "Error: Cookie jar is empty" | |
fi | |
# This is a bit dirty. If the login is succesful a simple redirect is issued, which results in an empty response | |
# to be sure, the response code should be checked, too | |
if [ -n "$(cat /tmp/irrenhaus-login)" ]; then | |
goto_fail "Error: Login failed" | |
fi | |
# add the new cookie jar to the curl opts | |
CURL_OPTS="${CURL_OPTS} -b ${COOKIE_JAR}" | |
fi | |
elif [ "${LOGIN_MODE}" = "cookie" ]; then | |
if [ -z "${COOKIE_UID}" ]; then | |
goto_fail "You must supply the UID Cookie" | |
elif [ -z "${COOKIE_PASS}" ]; then | |
goto_fail "You must supply the PASS Cookie" | |
fi | |
# passhash is not used | |
# same as normal login, credentials (cookies) end up in process list | |
CURL_OPTS="${CURL_OPTS} -b \"uid: ${COOKIE_UID}; pass: ${COOKIE_PASS}\"" | |
fi | |
## Upload the torrent | |
curl ${CURL_OPTS} -F "name=${TORRENT_NAME}" -F "type=${CATEGORY}" -F "descr=<${NFO_FILE}" -F "file=@${TORRENT_FILE}" -F "nfo=@${NFO_FILE}" -F "pic1=@${IMAGE_FILE}" -o /tmp/irrenhaus-upload ${TRACKER_URL}/takeupload.php | |
if [ $? != 0 ]; then | |
goto_fail "Error: Upload failed (cURL: $?)" | |
fi | |
if [ ! -e /tmp/irrenhaus-upload ]; then | |
goto_fail "Error: Upload failed" | |
fi | |
if [ -n "$(grep "TorrentUpload-Upload fehlgeschlagen!" /tmp/irrenhaus-upload)" ]; then | |
goto_fail "Error: Upload failed (Server Side Error)" | |
fi | |
error_check=$(grep "Beim Upload ist ein schwerwiegender Fehler aufgetreten:" /tmp/irrenhaus-upload) | |
if [ -n "${error_check}" ]; then | |
echo "Error: Upload failed" | |
duplicate=$(echo $error_check| grep "Dieses File existiert schon auf dem Tracker" | grep -Po 'details.php\?id=\d+') | |
if [ -n "${duplicate}" ]; then | |
goto_fail "Reason: Duplicate torrent (${TRACKER_URL}/${duplicate})" | |
else | |
error_msg=$(echo "$error_check" | grep -Po '<p style="color:red">(.+)</p>') | |
error_msg=${error_msg/'<p style="color:red">'/} | |
error_msg=${error_msg//<p>/} | |
error_msg=${error_msg//<\/p>/ } | |
goto_fail "Reason: $error_msg" | |
fi | |
fi | |
ok_check=$(grep "Dein Torrent wurde erfolgreich hochgeladen" /tmp/irrenhaus-upload) | |
if [ -n "${ok_check}" ]; then | |
torrent_link=$(grep -Po '<a href="details.php\?id=\d+\">Weiter zu den Details Deines Torrents</a>' /tmp/irrenhaus-upload | grep -Po 'details.php\?id=\d+') | |
torrent_id=$(echo "${torrent_link}" | grep -Po '\d+') | |
echo "Upload OK: ${TRACKER_URL}/${torrent_link}" | |
if [ -d ${DOWNLOAD_DIR} ]; then | |
curl ${CURL_OPTS} -o "${DOWNLOAD_DIR}/${TORRENT_NAME}.torrent" ${TRACKER_URL}/torrent=${torrent_id} | |
if [ $? != 0 ]; then | |
goto_fail "Error: Download failed (cURL: $?)" | |
fi | |
if [ ! -e "${DOWNLOAD_DIR}/${TORRENT_NAME}.torrent" ]; then | |
goto_fail "Error: Download failed (torrent file does not exist)" | |
fi | |
if [ -d "${WATCHDIR}" ]; then | |
cp "${DOWNLOAD_DIR}/${TORRENT_NAME}.torrent" "${WATCHDIR}/${TORRENT_NAME}.torrent" | |
fi | |
fi | |
fi | |
cleanup |
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/bash | |
# | |
# New Propaganda Upload Script | |
# Copyright (C) 2018 Daniel Müller <perlfuchsi@gmail.com> | |
# | |
# 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 3 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, see <https://www.gnu.org/licenses/>. | |
## | |
# Updated for the new Upload form (upxform) | |
# The Protocol is PITA but with some docs it's doable | |
# Docs for the new Protocol: https://gist.github.com/fuchsi/5e63c902a8a68020c76af0517a1ed3a5 | |
## | |
# Tracker URL | |
# required | |
TRACKER_URL=${TRACKER_URL:-"https://irrenhaus.dyndns.dk"} | |
## | |
# Path to a supported maketorrent program | |
# optional, but you can only upload .torrent meta files if empty | |
# - mktorrent (https://github.com/Rudde/mktorrent) | |
# - maketorrent (https://github.com/fuchsi/maketorrent) | |
# - gomaketorrent (https://github.com/fuchsi/gomaketorrent) | |
MAKETORRENT=${MAKETORRENT:-"/usr/bin/mktorrent"} | |
## | |
# Maketorrent options | |
# -a announce urls | |
# -l piece length (2^n bytes; 2^21 = 2MB, which should be ok for most files) | |
# -c comment | |
# -p private flag | |
MAKETORRENT_OPTS=${MAKETORRENT_OPTS:-"-a https://irrenhaus.dyndns.dk/announce.php -l 21 -p -v"} | |
## | |
# Login mode | |
# required | |
# 'cookie' use the uid, pass (and passhash) cookies for authentication | |
# 'username' use your username/password/pin combination for authentication | |
LOGIN_MODE="username" | |
## | |
# Username | |
# required for username login mode | |
LOGIN_USERNAME="" | |
## | |
# Password | |
# required for username login mode | |
LOGIN_PASSWORD="" | |
## | |
# PIN | |
# required for username login mode | |
LOGIN_PIN="" | |
## | |
# UID Cookie | |
# required for cookie login mode | |
COOKIE_UID="" | |
## | |
# Pass Cookie | |
# required for cookie login mode | |
COOKIE_PASS="" | |
## | |
# Passhash Cookie | |
# optional for cookie login mode | |
# NOT USED | |
COOKIE_PASSHASH="" | |
## | |
# Cookie Jar | |
# required, where your cookies are stored | |
COOKIE_JAR="/tmp/irrenhaus-cookies.jar" | |
## | |
# rtorrent watch dir | |
# optional | |
# | |
WATCHDIR=${WATCHDIR:-"/path/to/watchdir"} | |
## | |
# Download dir | |
# required | |
# Where your downloaded torrents are stored | |
DOWNLOAD_DIR=${DOWNLOAD_DIR:-"/path/to/download_dir"} | |
## | |
# Everything below should not be changed | |
## | |
## | |
# categories | |
categories[1]="A-book" | |
categories[2]="Album/Sampler" | |
categories[3]="Musik Pack" | |
categories[4]="Musik DVD/Vids" | |
categories[5]="Doku HD" | |
categories[6]="Doku HD Pack" | |
categories[7]="Doku SD" | |
categories[8]="Doku SD Pack" | |
categories[9]="Nintendo" | |
categories[10]="PC" | |
categories[11]="PlayStation" | |
categories[12]="XboX" | |
categories[13]="eBooks" | |
categories[14]="Mobilgeräte" | |
categories[15]="Software" | |
categories[16]="DVDR" | |
categories[17]="1080p" | |
categories[18]="720p" | |
categories[19]="h264/x264" | |
categories[20]="Xvid" | |
categories[21]="XXX" | |
categories[22]="Serie HD" | |
categories[23]="Serie HD Pack" | |
categories[24]="Serie SD" | |
categories[25]="Serie SD Pack" | |
categories[26]="Sport" | |
categories[27]="TV" | |
categories[28]="3-D" | |
## | |
# Help Mode | |
if [ $# = "0" ]; then | |
echo "irrenhaus upload script v0.1" | |
echo "usage $0 <file to upload> <nfo file> <image file> <category id>" | |
echo "" | |
echo "'file to upload' can be a .torrent file, a single file or a directory" | |
echo "nfo and image files can be local or remote files " | |
echo "category must be a valid category id. Run '$0 categories' for help" | |
exit 1 | |
fi | |
## | |
# Categories Mode | |
if [ $1 = "categories" ]; then | |
echo "Available categories:" | |
echo "ID: Name" | |
echo "" | |
# This loop will fail badly, if categories has gaps in it or is zero based | |
for index in $(seq 1 $((${#categories[@]} - 1))); do | |
echo "${index}: ${categories[$index]}" | |
done | |
fi | |
# Check the upload file | |
UPLOAD_FILE="$1" | |
NFO_FILE="$2" | |
IMAGE_FILE="$3" | |
CATEGORY="$4" | |
CREATE_TORRENT=0 | |
TORRENT_FILE="" | |
TORRENT_NAME="" | |
CURL_OPTS="-s" | |
USER_ID="" | |
# if nfo / image are fetched from remote urls, delete them afterwards | |
delete_nfo=0 | |
delete_image=0 | |
cleanup () { | |
# cleanup | |
if [ -e $COOKIE_JAR ]; then | |
rm $COOKIE_JAR | |
fi | |
if [ -e /tmp/irrenhaus-login ]; then | |
rm /tmp/irrenhaus-login | |
fi | |
if [ -e /tmp/irrenhaus-upload ]; then | |
rm /tmp/irrenhaus-upload | |
fi | |
if [ $delete_nfo -eq 1 ]; then | |
rm $NFO_FILE | |
fi | |
if [ $delete_image -eq 1 ]; then | |
rm $IMAGE_FILE | |
fi | |
if [ $CREATE_TORRENT -eq 1 ]; then | |
rm $TORRENT_FILE | |
fi | |
} | |
## | |
# Failure function | |
# Shows an error message, cleans up and exits with status 1 | |
# message (string) | |
goto_fail () { | |
local message="$1" | |
echo $message | |
cleanup | |
# exit with status 1 | |
exit 1 | |
} | |
if [ ! -e "${UPLOAD_FILE}" ]; then | |
goto_fail "Error: upload file not found" | |
fi | |
if [ ! -e "${NFO_FILE}" ]; then | |
# Check if NFO is a remote file | |
if [[ "${NFO_FILE}" =~ https?://* ]]; then | |
tmpfile=$(tempfile -s .nfo) | |
curl -o $tmpfile ${NFO_FILE} | |
delete_nfo=1 | |
NFO_FILE=$tmpfile | |
else | |
goto_fail "Error: nfo file not found" | |
fi | |
fi | |
if [ ! -e "${IMAGE_FILE}" ]; then | |
# Check if the image is a remote file | |
if [[ "${IMAGE_FILE}" =~ https?://* ]]; then | |
tmpfile=$(tempfile -s .jpg) | |
curl -o $tmpfile ${IMAGE_FILE} | |
delete_image=1 | |
IMAGE_FILE=$tmpfile | |
else | |
goto_fail "Error: image file not found" | |
fi | |
fi | |
# upload file is a directory | |
if [ -d "${UPLOAD_FILE}" ]; then | |
CREATE_TORRENT=1 | |
else | |
# check if it's a .torrent file | |
if [[ "${UPLOAD_FILE}" =~ *.torrent ]]; then | |
CREATE_TORRENT=0 | |
TORRENT_FILE="${UPLOAD_FILE}" | |
TORRENT_NAME=$(basename "${UPLOAD_FILE}" .torrent) | |
else | |
CREATE_TORRENT=1 | |
fi | |
fi | |
if [ $CREATE_TORRENT -eq 1 ]; then | |
ext=$(expr match "${UPLOAD_FILE}" ".*\.\(.*\)") | |
TORRENT_NAME=$(basename "${UPLOAD_FILE}" .$ext) | |
TORRENT_FILE="/tmp/${TORRENT_NAME}.torrent" | |
if [ ! -x "${MAKETORRENT}" ]; then | |
goto_fail "Error: could not execute the maketorrent program" | |
fi | |
if [ ! -e "${TORRENT_FILE}" ]; then | |
${MAKETORRENT} ${MAKETORRENT_OPTS} -n "${TORRENT_NAME}" -o "${TORRENT_FILE}" "${UPLOAD_FILE}" | |
if [ $? -ne 0 ]; then | |
goto_fail "Error: maketorrent failed (Status: $?)" | |
fi | |
fi | |
fi | |
## | |
# Login | |
if [ "${LOGIN_MODE}" = "username" ]; then | |
if [ -z "${LOGIN_USERNAME}" ]; then | |
goto_fail "You must supply a username" | |
elif [ -z "${LOGIN_PASSWORD}" ]; then | |
goto_fail "You must supply a password" | |
elif [ -z "${LOGIN_PIN}" ]; then | |
goto_fail "You must supply a pin" | |
fi | |
if [ ! -e "${COOKIE_JAR}" ]; then | |
# this is not optimal, bcz the credentials end up in the process list | |
curl ${CURL_OPTS} -X POST -H "Content-Type: application/x-www-form-urlencoded" -c ${COOKIE_JAR} -d "username=${LOGIN_USERNAME}&password=${LOGIN_PASSWORD}&pin=${LOGIN_PIN}" -o /tmp/irrenhaus-login ${TRACKER_URL}/takelogin.php | |
if [ ! -e "${COOKIE_JAR}" ]; then | |
goto_fail "Error: Cookie jar is empty" | |
fi | |
# This is a bit dirty. If the login is succesful a simple redirect is issued, which results in an empty response | |
# to be sure, the response code should be checked, too | |
if [ -n "$(cat /tmp/irrenhaus-login)" ]; then | |
goto_fail "Error: Login failed" | |
fi | |
# add the new cookie jar to the curl opts | |
CURL_OPTS="${CURL_OPTS} -b ${COOKIE_JAR}" | |
USER_ID=$(grep uid ${COOKIE_JAR} | awk -F'\t' '{printf $7}') | |
fi | |
elif [ "${LOGIN_MODE}" = "cookie" ]; then | |
if [ -z "${COOKIE_UID}" ]; then | |
goto_fail "You must supply the UID Cookie" | |
elif [ -z "${COOKIE_PASS}" ]; then | |
goto_fail "You must supply the PASS Cookie" | |
fi | |
# passhash is not used | |
# same as normal login, credentials (cookies) end up in process list | |
CURL_OPTS="${CURL_OPTS} -b \"uid: ${COOKIE_UID}; pass: ${COOKIE_PASS}\"" | |
USER_ID=$COOKIE_UID | |
fi | |
CURL="curl ${CURL_OPTS}" | |
UPLOAD_URL="${TRACKER_URL}/upxproc.php" | |
## Clear the last upload | |
resp=$($CURL "${UPLOAD_URL}?cancelUpload=${USER_ID}") | |
#echo "response: ${resp}" | |
if [ $? != 0 ]; then | |
goto_fail "Error: clear failed (cURL: $?)" | |
fi | |
if [ "${resp:0:1}" != "0" ]; then | |
goto_fail "Error: clear failed (response: $resp)" | |
fi | |
## Upload the torrent | |
resp=$($CURL -F "singlefile=torrent" -F "inp_torrent=@${TORRENT_FILE}" "${UPLOAD_URL}?name=${TORRENT_NAME}&setcatdata=${CATEGORY}") | |
#echo "response: ${resp}" | |
if [ $? != 0 ]; then | |
goto_fail "Error: torrent upload failed (cURL: $?)" | |
fi | |
if [ "${resp:0:1}" != "0" ]; then | |
goto_fail "Error: torrent upload failed (response: $resp)" | |
fi | |
## Upload the NFO | |
resp=$($CURL -F "singlefile=nfo" -F "inp_nfo=@${NFO_FILE}" "${UPLOAD_URL}?setdbnfo=1") | |
#echo "response: ${resp}" | |
if [ $? != 0 ]; then | |
goto_fail "Error: nfo upload failed (cURL: $?)" | |
fi | |
if [ "${resp:0:1}" != "0" ]; then | |
goto_fail "Error: nfo upload failed (response: $resp)" | |
fi | |
## Upload the Image | |
resp=$($CURL -F "singlefile=pic" -F "inp_pic1=@${IMAGE_FILE}" "${UPLOAD_URL}") | |
#echo "response: ${resp}" | |
if [ $? != 0 ]; then | |
goto_fail "Error: image upload failed (cURL: $?)" | |
fi | |
if [ "${resp:0:1}" != "0" ]; then | |
goto_fail "Error: image upload failed (response: $resp)" | |
fi | |
## Finish the Upload | |
resp=$($CURL "${UPLOAD_URL}?upxact=make&setdbnfo=1") | |
#echo "response: ${resp}" | |
if [ $? != 0 ]; then | |
goto_fail "Error: finish failed (cURL: $?)" | |
fi | |
if [ "${resp:0:1}" != "0" ]; then | |
goto_fail "Error: finish failed (response: $resp)" | |
fi | |
echo $resp > /tmp/irrenhaus-upload | |
if [ ! -e /tmp/irrenhaus-upload ]; then | |
goto_fail "Error: Upload failed" | |
fi | |
if [ -n "$(grep "TorrentUpload-Upload fehlgeschlagen!" /tmp/irrenhaus-upload)" ]; then | |
goto_fail "Error: Upload failed (Server Side Error)" | |
fi | |
ok_check=$(grep "Weiter zu den Details Deines Torrents" /tmp/irrenhaus-upload) | |
if [ -n "${ok_check}" ]; then | |
torrent_link=$(grep -Po '<a href="details.php\?id=\d+\">Weiter zu den Details Deines Torrents</a>' /tmp/irrenhaus-upload | grep -Po 'details.php\?id=\d+') | |
torrent_id=$(echo "${torrent_link}" | grep -Po '\d+') | |
echo "Upload OK: ${TRACKER_URL}/${torrent_link}" | |
if [ -d ${DOWNLOAD_DIR} ]; then | |
curl ${CURL_OPTS} -o "${DOWNLOAD_DIR}/${TORRENT_NAME}.torrent" ${TRACKER_URL}/torrent=${torrent_id} | |
if [ $? != 0 ]; then | |
goto_fail "Error: Download failed (cURL: $?)" | |
fi | |
if [ ! -e "${DOWNLOAD_DIR}/${TORRENT_NAME}.torrent" ]; then | |
goto_fail "Error: Download failed (torrent file does not exist)" | |
fi | |
if [ -d "${WATCHDIR}" ]; then | |
cp "${DOWNLOAD_DIR}/${TORRENT_NAME}.torrent" "${WATCHDIR}/${TORRENT_NAME}.torrent" | |
fi | |
fi | |
fi | |
cleanup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment