Advertisement
Guest User

Untitled

a guest
Jul 5th, 2016
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. USERNAME="user"
  2. PASSWORD="password"
  3.  
  4.  
  5. if [ "$#" -ne 1 ]; then
  6. echo "Missing argument: URLs file (containing one URL per line)." >&2
  7. exit 1
  8. fi
  9.  
  10.  
  11. URLSFILE="${1}"
  12. if [ ! -r "${URLSFILE}" ]; then
  13. echo "Cannot read URLs file ${URLSFILE}. Exit." >&2
  14. exit 1
  15. fi
  16. if [ ! -s "${URLSFILE}" ]; then
  17. echo "URLs file is empty. Exit." >&2
  18. exit 1
  19. fi
  20.  
  21.  
  22. TMPDIR="$(mktemp -d)"
  23. # Install trap that removes the temporary directory recursively
  24. # upon exit (except for when this program retrieves SIGKILL).
  25. trap 'rm -rf "$TMPDIR"' EXIT
  26.  
  27.  
  28. LOGINRESPFILE="${TMPDIR}/login.response"
  29. LOGINOUTPUTFILE="${TMPDIR}/login.outerr"
  30. COOKIESFILE="${TMPDIR}/login.cookies"
  31. LOGINURL="http://uploaded.net/io/login"
  32.  
  33.  
  34. echo "Temporary directory: ${TMPDIR}"
  35. echo "Log in via POST request to ${LOGINURL}, save cookies."
  36. wget --save-cookies=${COOKIESFILE} --server-response \
  37. --output-document ${LOGINRESPFILE} \
  38. --post-data="id=${USERNAME}&pw=${PASSWORD}" \
  39. ${LOGINURL} > ${LOGINOUTPUTFILE} 2>&1
  40.  
  41. # Status code is 200 even if login failed.
  42. # Uploaded sends a '{"err":"User and password do not match!"}'-like response
  43. # body in case of error.
  44.  
  45. echo "Verify that login response is empty."
  46. # Response is more than 0 bytes in case of login error.
  47. if [ -s "${LOGINRESPFILE}" ]; then
  48. echo "Login response larger than 0 bytes. Print response and exit." >&2
  49. cat "${LOGINRESPFILE}"
  50. exit 1
  51. fi
  52.  
  53. # Zero response size does not necessarily imply successful login.
  54. # Wget adds three commented lines to the cookies file by default, so
  55. # set cookies should result in more than three lines in this file.
  56. COOKIESFILELINES="$(cat ${COOKIESFILE} | wc -l)"
  57. echo "${COOKIESFILELINES} lines in cookies file found."
  58. if [ "${COOKIESFILELINES}" -lt "4" ]; then
  59. echo "Expected >3 lines in cookies file. Exit.". >&2
  60. exit 1
  61. fi
  62.  
  63. echo "Process URLs."
  64. # Assume that login worked. Iterate through URLs.
  65. while read CURRENTURL; do
  66. if [ "x$CURRENTURL" = "x" ]; then
  67. # Skip empty lines.
  68. continue
  69. fi
  70. echo -e "\n\n"
  71. TMPFILE="$(mktemp --tmpdir=${TMPDIR} response.html.XXXX)"
  72. echo "GET ${CURRENTURL} (use auth cookie), store response."
  73. wget --no-verbose --load-cookies=${COOKIESFILE} \
  74. --output-document ${TMPFILE} ${CURRENTURL}
  75.  
  76. if [ ! -s "${TMPFILE}" ]; then
  77. echo "No HTML response: ${TMPFILE} is zero size. Skip processing."
  78. continue
  79. fi
  80.  
  81. # Extract (temporarily valid) download URL from HTML.
  82. LINEOFINTEREST="$(grep post ${TMPFILE} | grep action | grep uploaded)"
  83. # Match entire line, include space after action="bla" , replace
  84. # entire line with first group, which is bla.
  85. DLURL=$(echo $LINEOFINTEREST | sed 's/.*action="\(.\+\)" .*/\1/')
  86. echo "Extracted download URL: ${DLURL}"
  87. # This file contains account details, so delete as soon as not required
  88. # anymore.
  89. rm -f "${TMPFILE}"
  90. echo "POST to URL w/o data. Response is file. Get filename from header."
  91. # --content-disposition should extract the proper filename.
  92. wget --content-disposition --post-data='' "${DLURL}"
  93. done < "${URLSFILE}"
  94.  
  95.  
  96. Uploaded Links funktionieren nur im Folgendem Format: uploaded.net/FILE/ID
  97. Einfach als .sh speichern und dann ausführen mit ./download.sh ul.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement