Advertisement
Guest User

Untitled

a guest
Jan 30th, 2017
127
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env bash
  2.  
  3. #Needs curl
  4. USERNAME="Smile4ever"
  5. USERPASS="*******"
  6. WIKIAPI="https://nl.wikipedia.org/w/api.php"
  7. cookie_jar="wikicj"
  8. #Will store file in wikifile
  9.  
  10. echo "UTF8 check: ☠"
  11. #################login
  12. echo "Logging into $WIKIAPI as $USERNAME..."
  13. #Login part 1
  14. #printf "%s" "Logging in (1/2)..."
  15. echo "Logging in (1/2)..."
  16. CR=$(curl -S \
  17.     --location \
  18.     --retry 2 \
  19.     --retry-delay 5\
  20.     --cookie $cookie_jar \
  21.     --cookie-jar $cookie_jar \
  22.     --user-agent "Curl Shell Script" \
  23.     --keepalive-time 60 \
  24.     --header "Accept-Language: en-us" \
  25.     --header "Connection: keep-alive" \
  26.     --compressed \
  27.     --request "GET" "${WIKIAPI}?action=query&meta=tokens&type=login&format=json")
  28.  
  29. echo "$CR" | jq
  30.  
  31. rm login.json
  32. echo "$CR" > login.json
  33. TOKEN=$(jq '.query.tokens.logintoken' login.json)
  34. TOKEN="${TOKEN//\"/}" #replace double quote by nothing
  35. TOKEN="${TOKEN//\+\\/%2b%5c}" #replace +\ by %2b%5c
  36. TOKEN="${TOKEN//\\/}" #replace \ by nothing
  37.  
  38. echo $TOKEN
  39.  
  40. if [ "$TOKEN" == "null" ]; then
  41.     echo "Login part 1 failed."
  42.     echo $CR
  43.     exit   
  44. else
  45.     echo "Logging in (1/2)...Complete" 
  46. fi
  47.  
  48. #Login part 2
  49. echo "Logging in (2/2)..."
  50. CR=$(curl -S \
  51.     --location \
  52.     --cookie $cookie_jar \
  53.     --cookie-jar $cookie_jar \
  54.     --user-agent "Curl Shell Script" \
  55.     --keepalive-time 60 \
  56.     --header "Accept-Language: en-us" \
  57.     --header "Connection: keep-alive" \
  58.     --compressed \
  59.     --data-urlencode "username=${USERNAME}" \
  60.     --data-urlencode "password=${USERPASS}" \
  61.     --data-urlencode "rememberMe=1" \
  62.     --data-urlencode "logintoken=${TOKEN}" \
  63.     --data-urlencode "loginreturnurl=http://google.be" \
  64.     --request "POST" "${WIKIAPI}?action=clientlogin&format=json")
  65.  
  66. #TODO-Add login part 2 check
  67. echo "$CR" | jq
  68. echo "Successfully logged in as $USERNAME."
  69.  
  70. ###############
  71. #Get edit token
  72. echo "Fetching edit token..."
  73. CR=$(curl -S \
  74.     --location \
  75.     --cookie $cookie_jar \
  76.     --cookie-jar $cookie_jar \
  77.     --user-agent "Curl Shell Script" \
  78.     --keepalive-time 60 \
  79.     --header "Accept-Language: en-us" \
  80.     --header "Connection: keep-alive" \
  81.     --compressed \
  82.     --request "POST" "${WIKIAPI}?action=query&meta=tokens&format=json")
  83.  
  84. CR2=($CR)
  85. echo "$CR" | jq
  86. EDITTOKEN=${CR2[8]}
  87. if [ ${#EDITTOKEN} = 34 ]; then
  88.     echo "Edit token is: $EDITTOKEN"
  89. else
  90.     echo "Edit token not set."
  91.     echo $CR
  92.     exit
  93. fi
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement