mad/hosts/up_lainsafe.sh
kittykat a62ac882de
# 2025.03.08 - [mad] Only check files in determining which curl header
# 2025.03.06 - [uploadhive] Disable global resume for servers without resume
# 2025.03.05 - [torup] Fix torup removed response change from prior
# 2025.03.05 - [mad] Add uploadflix.cc back to recommended download upload host lists (working)
# 2025.03.04 - [mad] Add "expect100-timeout" header to curl upload request
# 2025.03.03 - [up_sendspace] Add sendspace.com as upload host (300MB)
# 2025.03.01 - [filedot] Fix filename parsing. Add 3 second wait for Free Download post.
# 2025.03.01 - [torup] Update file removed response
# 2025.02.26 - [uploadhive] Fix "Wrong IP" error -- use uploadhive.com IP4 address to connect for post
# 2025.02.26 - [up_lainsafe] Fix retry terminal output
2025-03-11 01:03:01 +00:00

158 lines
6.3 KiB
Bash

#! Name: up_lainsafe.sh
#! Author: kittykat
#! Version: 2025.02.26
#! Desc: Add support for uploading files to dashfile.net
#! Info: https://pomf2.lain.la/<filehash>
#! MaxSize: 1GB
#! Expire: ??
#! Usage: Copy this file into the ./${ScriptDir}/hosts/ folder
#!
#!
#! ------------ REQUIRED SECTION ---------------
#! @[UPDATE] ListUploadHosts: This string is loaded into mad.sh and allows dynamic handling of new url data
#! Format: '/HostCode/HostNick/HostFuncPrefix@'
#! HostCode: <aUniqueCodeForHost> (ie. 'fh' for filehaus -- cannot be used by other hosts)
#! HostNick: What is displayed throughout MAD output
#! HostFuncPrefix: <aUniqueStringThatMustPrefixHostFunctions> ie. 'fh' -- fh_UploadFile()
#! * Note: Must begin with a letter a-z (functions beginning with numbers are no bueno)
HostCode='lain'
HostNick='lainsafe'
HostFuncPrefix='lain'
#!
#! !! DO NOT UPDATE OR REMOVE !!
#! This merges the Required HostAndDomainRegexes into mad.sh
ListUploadHosts=${ListUploadHosts}'/'${HostCode}'/'${HostNick}'/'${HostFuncPrefix}'@'
#!
#!
#! Configurables
#! -------------
#!
#! ------------ (1) Host Main Upload Function --------------- #
#!
#! @REQUIRED: Host Main Upload function
#! Must be named specifically as such:
#! <HostFuncPrefix>_UploadFile()
lain_UploadFile() {
local _hostCode=${1}
local filepath=${2}
local filecnt=${3}
local pline=${4}
local filename="${filepath##*/}"
warnAndRetryUnknownError=false
exitUploadError=false
exitUploadNotAvailable=false
fileAlreadyDone=false
tor_identity="${RANDOM}"
UploadTicket="${WorkDir}/.flocks/upload_${_hostCode}_${filepath//[^a-zA-Z0-9]/}"
MaxUploadSizeInBytes=1073741824
fsize=$(GetFileSize "$filepath" "false")
if ((fsize > MaxUploadSizeInBytes)); then
rm -f "${UploadTicket}"
echo -e "${YELLOW}| SKIP${NC}: The size of $filename is to large for $_hostCode. ($fsize > $MaxUploadSizeInBytes)"
failedUpload "$pline" "${filepath}" "${_hostCode}" "Skipping upload. The size of $filename is to large for $_hostCode. ($fsize > $MaxUploadSizeInBytes)"
return 1
fi
finalAttempt="false"
for ((z=0; z<=$MaxUploadRetries; z++)); do
if [[ $z -eq $MaxUploadRetries ]] ; then
finalAttempt="true"
fi
trap "rm -f "${UploadTicket}"; echo ""; tput cnorm; exit" 0 1 2 3 6 15
if lain_PostFile "${filepath}" "${_hostCode}" "${filename}" "${filecnt}" $((z+1)) $finalAttempt $pline ; then
return 0
elif [[ $z -lt $MaxUploadRetries ]]; then
if [[ "${fileAlreadyDone}" == "true" ]] ; then
break
fi
if [[ "${warnAndRetryUnknownError}" == "true" ]] ; then
if [[ "${DebugAllEnabled}" == "true" ]] ; then
debugHtml "${filepath##*/}" "error" "Retry due to an unknown issue: attempt #$((z+1)) of ${MaxUploadRetries}"
fi
fi
if [[ "${exitUploadError}" == "true" || "${exitUploadNotAvailable}" == "true" ]] ; then
if [[ "${DebugAllEnabled}" == "true" ]] ; then
debugHtml "${filepath##*/}" "error" "Exit due to unrecoverable issue"
fi
rm -f "${UploadTicket}"
break
fi
echo -e "\n${YELLOW}A recoverable error occurred, retry attempt $((z+1))/${MaxUploadRetries}${NC}"
sleep 3
fi
done
rm -f "${UploadTicket}"
}
#!
#! ----------- (2) Post File / Upload File Function --------------- #
#!
lain_PostFile() {
local filepath=$1
local _hostCode=$2
local filename=$3
local fileCnt=$4
local retryCnt=$5
local finalAttempt=$6
local pline=${7}
UploadTicket="${WorkDir}/.flocks/upload_${_hostCode}_${filepath//[^a-zA-Z0-9]/}"
echo -e "[${YELLOW}${_hostCode}${NC}] Uploading ${GREEN}${filename}${NC}"
for ((i=0; i<=20; i++)); do
if ((i > 0)); then
printf "\033[1A\r"
printf "\033[1A\r"
printf "\033[1A\r"
printf "\033[1A\r"
printf "\033[1A\r"
printf "\33[2K\r"
fi
echo -e "${BLUE}| Attempt:${NC} $((i+1))${NC}"
tor_identity="${RANDOM}"
PostUrlHost='https://pomf.lain.la/upload.php?output=html'
arrFiles=("$filepath")
trap "rm -f ${UploadTicket}; echo ""; tput cnorm; exit" 0 1 2 3 6 15
response=$(tor_curl_upload --insecure -i \
-H "Content-Type: multipart/form-data" \
-F "files[]=@${arrFiles[@]}" \
"${PostUrlHost}")
if [[ "${DebugAllEnabled}" == "true" ]] ; then
debugHtml "${filepath##*/}" "${_hostCode}_upload" "post_url: ${PostUrlHost}"$'\n'"${response}"
fi
if [[ -z $response ]] || grep -Eqi 'HTTP/2 403|403 Forbidden' <<< "${response}" ; then
if [[ "${finalAttempt}" == "true" ]] ; then
err=$(grep -oPi '(?<=HTTP/).*?(?=$)' <<< "$response")
printf "\\n"
echo -e "${RED}| Upload failed. Status: ${err}${NC}"
failedRetryUpload "$pline" "${filepath}" "${_hostCode}" "Failed to upload file" "Status: $err"
exitUploadError=true
return 1
else
continue
fi
elif grep -Eqi 'a href="https://pomf2.lain.la/f/' <<< "${response}" ; then
url=$(grep -oPi -m 1 '(?<=a href=").*?(?=">https:)' <<< "$response")
filesize=$(GetFileSize "$filepath" "false")
downloadLink="$url"
echo -e "${GREEN}| Upload Success${NC}"
echo -e "| Size: ${BLUE}${filesize}${NC} bytes${NC}"
echo -e "| Link: ${YELLOW}${downloadLink}${NC}"
successUpload "$pline" "${filepath}" "${_hostCode}" "${filesize}" "${downloadLink}" "{$response}"
return 0
else
err=$(grep -oPi '(?<=HTTP/).*?(?=$)' <<< "$response")
if [[ "${finalAttempt}" == "true" ]] ; then
printf "\\n"
echo -e "${RED}| Upload failed. Status: ${err}${NC}"
failedRetryUpload "$pline" "${filepath}" "${_hostCode}" "Failed to upload file" "Status: $err"
exitUploadError=true
return 1
else
return 1
fi
fi
done
printf "\\n"
echo -e "${RED}| Upload failed. Status: ${err}${NC}"
return 1
}
#!
#! --------------- Host Extra Functions ------------------- #
#!