Mediafire: script Bash per upload di files da console
Di seguito pubblico uno script utile per chi vuole caricare su mediafire uno o più file da console senza dover utilizzare un browser web. Questo script è utile in caso di job notturni o programmi che non richiedono l’intervento dell’utente.
#!/bin/bash # # Copyright (c) 2011 vittorio benintende # (vittorio@lucullo.it - http://www.morzello.com). # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # 3. Neither the name of the Site nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE SITE AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE SITE OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # # --- PARAMS --- # # login and password must be url-encoded! # MF_LOGIN='mediafire%40morzello.com' MF_PWD='mypass' # --- PARAMS --- # # DO NOT MODIFY LINES BELOW # MF_FILES="$@" if [ "z${MF_FILES}" = "z" ]; then echo echo "No file(s) specified." echo echo "USAGE: $0 : file1 file2 ..." echo exit 1 fi OUTPUT_FILE=$(mktemp) COOKIE_FILE=$(mktemp) rdom () { local IFS=\> ; read -d \< E C ;} wget -q --save-cookies ${COOKIE_FILE} --keep-session-cookies -O /dev/null "https://www.mediafire.com/" wget -q --load-cookies ${COOKIE_FILE} --save-cookies ${COOKIE_FILE} --keep-session-cookies --referer="https://www.mediafire.com/" \ --post-data "login_email=${MF_LOGIN}&login_pass=${MF_PWD}&login_remember=on&submit_login.x=97&submit_login.y=18" \ -O /dev/null "https://www.mediafire.com/dynamic/login.php" wget -q --load-cookies ${COOKIE_FILE} --save-cookies ${COOKIE_FILE} --keep-session-cookies --referer="https://www.mediafire.com/myfiles.php" \ -O ${OUTPUT_FILE} "https://www.mediafire.com//basicapi/uploaderconfiguration.php?45144" UPLOAD_SESSION=$(while rdom; do if [[ ${E} = "upload_session" ]]; then echo ${C} exit fi done < ${OUTPUT_FILE}) # echo "Upload Session = ${UPLOAD_SESSION}" UKEY=$(while rdom; do if [[ ${E} = "ukey" ]]; then echo ${C} exit fi done < ${OUTPUT_FILE}) # echo "UKey = ${UKEY}" TRACKKEY=$(while rdom; do if [[ ${E} = "trackkey" ]]; then echo ${C} exit fi done < ${OUTPUT_FILE}) # echo "Track Key = ${TRACKKEY}" FOLDERKEY=$(while rdom; do if [[ ${E} = "folderkey" ]]; then echo ${C} exit fi done < ${OUTPUT_FILE}) # echo "Folder Key = ${FOLDERKEY}" MFULCONFIG=$(while rdom; do if [[ ${E} = "MFULConfig" ]]; then echo ${C} exit fi done < ${OUTPUT_FILE}) # echo "MFUL Config = ${MFULCONFIG}" MF_USER=$(while rdom; do if [[ ${E} = "user" ]]; then echo ${C} exit fi done < ${OUTPUT_FILE}) # echo "User = ${MF_USER}" for FILENAME in ${MF_FILES}; do SHORT_FILENAME=$(basename "${FILENAME}") FILESIZE=$(stat -c%s "${FILENAME}") wget -q --load-cookies ${COOKIE_FILE} --save-cookies ${COOKIE_FILE} --keep-session-cookies --referer="https://www.mediafire.com/myfile.php" \ --header="Content-Type: application/octet-stream" \ --header="X-Filename: ${SHORT_FILENAME}" \ --header="X-Filesize: ${FILESIZE}" \ --post-file="${FILENAME}" \ -O ${OUTPUT_FILE} "https://www.mediafire.com/douploadtoapi/?type=basic&ukey=${UKEY}&user=${MF_USER}&uploadkey=${FOLDERKEY}&filenum=0&uploader=0&MFULConfig=${MFULCONFIG}" RESKEY=$(while rdom; do if [[ ${E} = "key" ]]; then echo ${C} exit fi done < ${OUTPUT_FILE}) # echo "${FILENAME} > ${RESKEY}" # get result RUN=1 while [ ${RUN} -eq 1 ]; do wget -q --load-cookies ${COOKIE_FILE} --save-cookies ${COOKIE_FILE} --keep-session-cookies --referer="https://www.mediafire.com/myfile.php" \ -O ${OUTPUT_FILE} "https://www.mediafire.com/basicapi/pollupload.php?key=${RESKEY}&MFULConfig=${MFULCONFIG}" QUICKKEY=$(while rdom; do if [[ ${E} = "quickkey" ]]; then echo ${C} exit fi done < ${OUTPUT_FILE}) FILEERROR=$(while rdom; do if [[ ${E} = "fileerror" ]]; then echo ${C} exit fi done < ${OUTPUT_FILE}) # echo "${QUICKKEY} ; ${FILEERROR}" RUN=0 if [ "z${FILEERROR}" = "z" ] && [ "z${QUICKKEY}" = "z" ]; then RUN=1 fi # #..#... #... # case "${FILEERROR}" in 1) FILEERROR=" 1 : File too large." ;; 2) FILEERROR=" 2 : File too small." ;; 3) FILEERROR=" 3 : Archive is bad." ;; 4) FILEERROR=" 4 : Archive is bad or password protected." ;; 5) FILEERROR=" 5 : Virus found." ;; 13) FILEERROR="13 : File already uploaded." ;; 9) FILEERROR=" 9 : Archive has an unknown problem." ;; 10) FILEERROR="10 : Invalid image." ;; 6) FILEERROR=" 6 : File lost." ;; 7) FILEERROR=" 7 : Error scanning file." ;;#... File too large. 1 0 #... File too small. 2 0 #... Archive is bad. 3 0 #... Archive is bad or password protected. 4 0 #... Virus found. 5 0 #... File already uploaded. 13 0 #... Archive has an unknown problem. 9 0 #... Invalid image. 10 0 #... File lost. 6 1 #... Error scanning file. 7 1 #... Disk error. 8,11 1 #.. Database error. 12 1 FILEERROR=" 8 : Disk error." ;; 11) FILEERROR="11 : Disk error." ;; 12) FILEERROR="12 : Database error." ;; *) FILEERROR="0 : Success." ;; esac done echo "${FILEERROR} | ${FILENAME} > ${QUICKKEY}" done rm ${OUTPUT_FILE} rm ${COOKIE_FILE}
Prima di iniziare
Prima di utilizzare lo script è necessario impostare i parametri di login e password in uso su medaifire. Bisogna ricordare che questi paramentri sono url-encoded; questo perchè vengono esposti direttamente nell’url di login. Ad esempio:
mediafile@morzello.com -> mediafire%40morzello.com
Usare lo script
Per utilizzare lo script basta indicare il file o i file da inviare al server:
./mfup.sh myfile.txt all.* /root/repo/*
Ricordate però che non verranno prese in considerazione le sottocartelle.
Alla prossima