keans / woice

A small python script that helps to connect to the WiFiOnICE network on ICE trains.
MIT License
4 stars 3 forks source link

Script seems no longer to work -- changes on wifionice.de? #3

Open dreirund opened 2 years ago

dreirund commented 2 years ago

Soomething seems to have changed on the wifionice.de-website again: woice up and woice down do not seem to change internet status.

I am not familiar with website request scripting, so I cannot help mutch in debugging/ re-writing code.

dreirund commented 2 years ago

I managed to get it working, with two curl calls.

Essentially, the following is enough:

  1. Do a GET a request to get the CSRF token via a cookie.
  2. Do a POST request where the CSRF cookie is passed, and the request data contains login=true and also CSRFToken properly set.

That can be achieved by the following bash script:

_csrftoken="$(curl -s -o '/dev/null' --dump-header - "${_request_url}" | grep -E "^Set-Cookie:[[:space:]]+csrf=" | tail -n1 | awk '{print $2}' | awk -F= '{print $2}' | sed -E 's|;$||')"

curl -s -o '/dev/null' -b "csrf=${_csrftoken}" -d "login=true&CSRFToken=${_csrftoken}" "${_request_url}"

I made a proper script out of it, see → here, and an Arch Linux package, see → here.

Feel free to use that knowledge fix your python script.

Regards!

keans commented 2 years ago

Since I am currently not traveling by ICE I cannot check, if there has been changes to the login. However, since there have been changes in the past this is possible. Next time I will go by ICE, I will try to check your suggestion and adapt the script.