Haxe18 / telekom_fon_connect

Script for automatic login @ Telekom_FON Hotspot with your telekom credentials
Other
15 stars 8 forks source link

Doing request to hotspot login page to fetch source code ? #7

Closed ArseneR81 closed 2 years ago

ArseneR81 commented 3 years ago

I already changed the two lines in the telekom_fon_connect.conf ` fon_username: 491701234567

fon_password: xxx-xxx-xxx ` accordingly. When running follwing command

./telekom_fon_connect.py -c telekom_fon_connect.conf

I get following logcat:

2021-05-24 17:57:08,606 INFO Doing request to hotspot login page to fetch source code 2021-05-24 17:57:08,750 ERROR Error when parsing html code to get post data. Either a (temporary) error or script is not working anymore. Will try again 2021-05-24 17:57:09,354 INFO You are not online, try to login now 2021-05-24 17:57:09,355 INFO Doing request to hotspot login page to fetch source code ^CTraceback (most recent call last): File "./telekom_fon_connect.py", line 332, in <module> sys.exit(main()) # If no arg, pass none File "./telekom_fon_connect.py", line 319, in main status = do_login(username,password,test_url,rlp_request_whitelist,telekom_api_endpoint,session_api_url,login_api_url,loglvl,login_url) File "./telekom_fon_connect.py", line 144, in do_login fon_source = do_request(url=login_url, level=loglvl) # Get source of login page to extract some infos to create a session File "./telekom_fon_connect.py", line 98, in do_request r = requests.get(url=url, timeout=timeout) # Do normal get request File "/usr/lib/python2.7/dist-packages/requests/api.py", line 75, in get return request('get', url, params=params, **kwargs) File "/usr/lib/python2.7/dist-packages/requests/api.py", line 60, in request return session.request(method=method, url=url, **kwargs) File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 533, in request resp = self.send(prep, **send_kwargs) File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 646, in send r = adapter.send(request, **kwargs) File "/usr/lib/python2.7/dist-packages/requests/adapters.py", line 449, in send timeout=timeout File "/usr/lib/python2.7/dist-packages/urllib3/connectionpool.py", line 600, in urlopen chunked=chunked) File "/usr/lib/python2.7/dist-packages/urllib3/connectionpool.py", line 377, in _make_request httplib_response = conn.getresponse(buffering=True) File "/usr/lib/python2.7/httplib.py", line 1137, in getresponse response.begin() File "/usr/lib/python2.7/httplib.py", line 448, in begin version, status, reason = self._read_status() File "/usr/lib/python2.7/httplib.py", line 404, in _read_status line = self.fp.readline(_MAXLINE + 1) File "/usr/lib/python2.7/socket.py", line 480, in readline data = self._sock.recv(self._rbufsize) File "/usr/lib/python2.7/dist-packages/urllib3/contrib/pyopenssl.py", line 285, in recv if not util.wait_for_read(self.socket, self.socket.gettimeout()): File "/usr/lib/python2.7/dist-packages/urllib3/util/wait.py", line 143, in wait_for_read return wait_for_socket(sock, read=True, timeout=timeout) File "/usr/lib/python2.7/dist-packages/urllib3/util/wait.py", line 104, in poll_wait_for_socket return bool(_retry_on_intr(do_poll, timeout)) File "/usr/lib/python2.7/dist-packages/urllib3/util/wait.py", line 53, in _retry_on_intr return fn(timeout) File "/usr/lib/python2.7/dist-packages/urllib3/util/wait.py", line 102, in do_poll return poll_obj.poll(t) KeyboardInterrupt

Whats the error about?

Haxe18 commented 3 years ago

Hi,

please attach an log with debug mode output. Either you call the script with -v to get all infos to stdout or you copy the content out of /tmp/debug.log (or whatever you defined in as log_file). Please check the log for sensitive infomations like you fon_username and fon_password before posting !

ArseneR81 commented 3 years ago

please attach an log with debug mode output.

Here you go:

2021-05-25 10:44:15,553 DEBUG Working with configfile: telekom_fon_connect.conf 2021-05-25 10:44:15,553 INFO log_level is : DEBUG 2021-05-25 10:44:15,559 DEBUG Starting new HTTP connection (1): online-status.cf:80 2021-05-25 10:44:15,610 DEBUG http://online-status.cf:80 "HEAD / HTTP/1.1" 302 0 2021-05-25 10:44:15,614 DEBUG send: HEAD / HTTP/1.1 Host: online-status.cf Connection: keep-alive Accept-Encoding: gzip, deflate Accept: / User-Agent: python-requests/2.21.0 reply: HTTP/1.0 302 Moved Temporarily header: Connection: close header: Pragma: no-cache header: Expires: Fri, 01 Jan 1971 00:00:00 GMT header: Cache-Control: no-cache, must-revalidate header: P3P: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT" header: Location: https://telekom.portal.fon.com/ARCDTA03/fon/79b07a3f12fe2b39bdf172ccee2ec7748?res=notyet&uamip=172.17.2.1&uamport=3990&challenge=af15c&called=E8-75-DC-47-FF-EE&mac=D8-A6-32-32-51-76&ip=172.17.2.14&nasid=E8-75-DC-47-FF-EE&sessionid=8564b89700000002&userurl=http%3a%2f%2fonline-status.cf%2f&md=41D7783916EB168D334F24FA9 header: Content-Type: text/html; charset=UTF-8 header: Content-Length: 1024 2021-05-25 10:44:24,071 INFO You are not online, try to login now 2021-05-25 10:44:24,071 DEBUG Login Url is already defined, use it 2021-05-25 10:44:24,072 DEBUG Hotspot login and status page is https://telekom.portal.fon.com/ARCDTA03/fon/79b07a3f12fe2b39bdf172ccee2ec7748?res=notyet&uamip=172.17.2.1&uamport=3990&challenge=af15c&called=E8-75-DC-47-FF-EE&mac=D8-A6-32-32-51-76&ip=172.17.2.14&nasid=E8-75-DC-47-FF-EE&sessionid=8564b89700000002&userurl=http%3a%2f%2fonline-status.cf%2f&md=41D7783916EB168D334F24FA9 2021-05-25 10:44:24,072 INFO Doing request to hotspot login page to fetch source code 2021-05-25 10:44:24,073 DEBUG Doing request to https://telekom.portal.fon.com/ARCDTA03/fon/79b07a3f12fe2b39bdf172ccee2ec7748?res=notyet&uamip=172.17.2.1&uamport=3990&challenge=af15c&called=E8-75-DC-47-FF-EE&mac=D8-A6-32-32-51-76&ip=172.17.2.14&nasid=E8-75-DC-47-FF-EE&sessionid=8564b89700000002&userurl=http%3a%2f%2fonline-status.cf%2f&md=41D7783916EB168D334F24FA9 to fetch source code to create post data 2021-05-25 10:44:24,078 DEBUG Starting new HTTPS connection (1): telekom.portal.fon.com:443

The 302 repley was repeating so I shortened it in this output.

Haxe18 commented 3 years ago

Hi thanks for the debug output, helps me a lot at testing.

Please do not cut the output, the important part in this case begins right after the cut ...

But for me in debugging on a non TelekomHotspot connection, testing with the given URL the script is working. See yourself:

root@raspberrypi4:~/telekom_fon_connect# python3 telekom_fon_connect.py -v -c ./telekom_fon_connect.conf
2021-05-25 22:55:13,072 DEBUG Working with configfile: ./telekom_fon_connect.conf
2021-05-25 22:55:13,073 INFO log_level is : DEBUG
2021-05-25 22:55:13,074 INFO You are not online, try to login now
2021-05-25 22:55:13,074 DEBUG Login Url is already defined, use it
2021-05-25 22:55:13,074 DEBUG Hotspot login and status page is https://telekom.portal.fon.com/ARCDTA03/fon/79b07a3f12fe2b39bdf172ccee2ec7748?res=notyet&uamip=172.17.2.1&uamport=3990&challenge=af15c&called=E8-75-DC-47-FF-EE&mac=D8-A6-32-32-51-76&ip=172.17.2.14&nasid=E8-75-DC-47-FF-EE&sessionid=8564b89700000002&userurl=http%3a%2f%2fonline-status.cf%2f&md=41D7783916EB168D334F24FA9#/start
2021-05-25 22:55:13,075 INFO Doing request to hotspot login page to fetch source code
2021-05-25 22:55:13,075 DEBUG Doing request to https://telekom.portal.fon.com/ARCDTA03/fon/79b07a3f12fe2b39bdf172ccee2ec7748?res=notyet&uamip=172.17.2.1&uamport=3990&challenge=af15c&called=E8-75-DC-47-FF-EE&mac=D8-A6-32-32-51-76&ip=172.17.2.14&nasid=E8-75-DC-47-FF-EE&sessionid=8564b89700000002&userurl=http%3a%2f%2fonline-status.cf%2f&md=41D7783916EB168D334F24FA9#/start to fetch source code to create post data
2021-05-25 22:55:13,080 DEBUG Starting new HTTPS connection (1): telekom.portal.fon.com:443
2021-05-25 22:55:13,221 DEBUG https://telekom.portal.fon.com:443 "GET /ARCDTA03/fon/79b07a3f12fe2b39bdf172ccee2ec7748?res=notyet&uamip=172.17.2.1&uamport=3990&challenge=af15c&called=E8-75-DC-47-FF-EE&mac=D8-A6-32-32-51-76&ip=172.17.2.14&nasid=E8-75-DC-47-FF-EE&sessionid=8564b89700000002&userurl=http%3a%2f%2fonline-status.cf%2f&md=41D7783916EB168D334F24FA9 HTTP/1.1" 200 None
2021-05-25 22:55:13,238 DEBUG send: GET /ARCDTA03/fon/79b07a3f12fe2b39bdf172ccee2ec7748?res=notyet&uamip=172.17.2.1&uamport=3990&challenge=af15c&called=E8-75-DC-47-FF-EE&mac=D8-A6-32-32-51-76&ip=172.17.2.14&nasid=E8-75-DC-47-FF-EE&sessionid=8564b89700000002&userurl=http%3a%2f%2fonline-status.cf%2f&md=41D7783916EB168D334F24FA9 HTTP/1.1
Host: telekom.portal.fon.com
User-Agent: python-requests/2.21.0
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
reply: HTTP/1.1 200 OK
header: Server: nginx
header: Date: Tue, 25 May 2021 20:55:13 GMT
header: Content-Type: text/html; charset=utf-8
header: Transfer-Encoding: chunked
header: Connection: keep-alive
header: Set-Cookie: symfony=t4tacr23h3a6ceik2a23d73a55; path=/
header: Expires: Thu, 19 Nov 1981 08:52:00 GMT
header: Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
header: Pragma: no-cache
header: Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
header: Set-Cookie: symfony=t4tacr23h3a6ceik2a23d73a55; path=/
2021-05-25 22:55:13,242 DEBUG Start parsing html to get post data
2021-05-25 22:55:13,254 DEBUG Post data found
2021-05-25 22:55:13,256 DEBUG Postdata created
2021-05-25 22:55:13,259 DEBUG Starting new HTTPS connection (1): rlp.telekom.de:443
2021-05-25 22:55:13,436 DEBUG https://rlp.telekom.de:443 "POST /wlan/rest/contentapi HTTP/1.1" 200 1899
2021-05-25 22:55:13,441 DEBUG send: POST /wlan/rest/contentapi HTTP/1.1
Host: rlp.telekom.de
User-Agent: python-requests/2.21.0
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
Content-Length: 970
send: {"location": {}, "partnerRegRequest": {}, "rlpRequest": {"HSPNAME": "FON:DE", "VNPNAME": "FON:DE", "WISPURL": "https://telekom.portal.fon.com/ARCDTA03/fon/79b07a3f12fe2b39bdf172ccee2ec7748?res=vnp-login&nasid=E8-75-DC-47-FF-EE&uamip=172.17.2.1&uamport=3990&mac=D8-A6-32-32-51-76&challenge=af15c&HSPNAME=FON%3ADE&VNPNAME=FON%3ADE&LOCATIONNAME=FON%3ADE&userurl=http%3A%2F%2Fonline-status.cf%2F&strAGB=1&LOCATIONID=FON%3ADE&LANGUAGE=de_DE&selectTab=tab-login-fon", "WISPURLHOME": "https://telekom.portal.fon.com/ARCDTA03/fon/79b07a3f12fe2b39bdf172ccee2ec7748?res=notyet&nasid=E8-75-DC-47-FF-EE&uamip=172.17.2.1&uamport=3990&mac=D8-A6-32-32-51-76&challenge=af15c&userurl=http%3A%2F%2Fonline-status.cf%2F&ip=172.17.2.14&called=E8-75-DC-47-FF-EE&sessionid=8564b89700000002&md=41D7783916EB168D334F24FA9&selectTab=tab-login-fon", "LOCATIONNAME": "FON:DE", "LOCATIONID": "FON:DE", "LANGUAGE": "de_DE", "fon_status": "false", "fon_err_status": "false"}, "session": {}, "user": {}}
reply: HTTP/1.1 200 200
header: Date: Tue, 25 May 2021 20:55:13 GMT
header: Server: Apache
header: X-Frame-Options: SAMEORIGIN
header: vary: Origin
header: Access-Control-Allow-Credentials: true
header: Access-Control-Expose-Headers: X-CSA-JSESSIONID
header: Set-Cookie: JSESSIONID=7549386B3BE1B8A0835126ABA0CB83C7.P9; Path=/wlan; Secure; HttpOnly
header: Set-Cookie: JSESSIONID=7549386B3BE1B8A0835126ABA0CB83C7.P9; Path=/wlan; Secure; HttpOnly
header: X-CSA-JSESSIONID: 7549386B3BE1B8A0835126ABA0CB83C7.P9
header: Cache-Control: no-cache, no-store, must-revalidate
header: Pragma: no-cache
header: Expires: Thu, 01 Jan 1970 00:00:00 GMT
header: Content-Type: application/json;charset=UTF-8
header: Strict-Transport-Security: max-age=15768000
header: Content-Length: 1899
header: Keep-Alive: timeout=5, max=50
header: Connection: Keep-Alive
2021-05-25 22:55:13,446 INFO Session @ Telekom api successfull created
2021-05-25 22:55:13,449 DEBUG Starting new HTTPS connection (1): rlp.telekom.de:443
2021-05-25 22:55:13,617 DEBUG https://rlp.telekom.de:443 "POST /wlan/rest/login;jsessionid=7549386B3BE1B8A0835126ABA0CB83C7.P9 HTTP/1.1" 200 541
2021-05-25 22:55:13,622 DEBUG send: POST /wlan/rest/login;jsessionid=7549386B3BE1B8A0835126ABA0CB83C7.P9 HTTP/1.1
Host: rlp.telekom.de
User-Agent: python-requests/2.21.0
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
Content-Length: 68
send: {"username": "******@t-mobile.de", "password": "000-000-000"}
reply: HTTP/1.1 200 200
header: Date: Tue, 25 May 2021 20:55:13 GMT
header: Server: Apache
header: X-Frame-Options: SAMEORIGIN
header: vary: Origin
header: Access-Control-Allow-Credentials: true
header: Access-Control-Expose-Headers: X-CSA-JSESSIONID
header: Set-Cookie: DT_H=Nzk5MzQyMzA3; Max-Age=1800; Expires=Tue, 25-May-2021 21:14:55 GMT; Path=/
header: X-CSA-JSESSIONID: 7549386B3BE1B8A0835126ABA0CB83C7.P9
header: Cache-Control: no-cache, no-store, must-revalidate
header: Pragma: no-cache
header: Expires: Thu, 01 Jan 1970 00:00:00 GMT
header: Content-Type: application/json;charset=UTF-8
header: Strict-Transport-Security: max-age=15768000
header: Content-Length: 541
header: Keep-Alive: timeout=5, max=50
header: Connection: Keep-Alive
2021-05-25 22:55:13,627 INFO Authentification @ Telekom api was successfull, got login url
2021-05-25 22:55:13,630 DEBUG Starting new HTTPS connection (1): telekom.portal.fon.com:443
2021-05-25 22:55:13,799 DEBUG https://telekom.portal.fon.com:443 "GET /ARCDTA03/fon/79b07a3f12fe2b39bdf172ccee2ec7748?res=vnp-login&nasid=E8-75-DC-47-FF-EE&uamip=172.17.2.1&uamport=3990&mac=D8-A6-32-32-51-76&challenge=af15c&HSPNAME=FON%3ADE&VNPNAME=FON%3ADE&LOCATIONNAME=FON%3ADE&userurl=http%3A%2F%2Fonline-status.cf%2F&strAGB=1&LOCATIONID=FON%3ADE&LANGUAGE=de_DE&selectTab=tab-login-fon&ANID=****%40t-mobile.de&ANIDPASSWORD=L1%2BznRF7C4Z1RsFgO4QQpD5AAW0SYPAAmcbFzqIIquRabZ8WlSgAAAmGfX2%2ZOp&CLOCK_INITIAL_VALUE=0&CLOCK_COUNT_DIRECTION=1&RESULT=1 HTTP/1.1" 302 None
2021-05-25 22:55:13,804 DEBUG Starting new HTTP connection (1): 172.17.2.1:3990

The connection to 172.17.2.1 will not finish because i am not connected to a fon hotspot.

Don't know where your problem is located, not reproducible for me sorry.

Haxe18 commented 3 years ago

@ArseneR81 Do you have any update about your problem ?

ArseneR81 commented 3 years ago

@ArseneR81 Do you have any update about your problem ?

Not yet. Instead of an Email in the config file, I used a phone number like:

fon_username: 49152345678 fon_password: xxx-xxx-xxx

I was thinking of purchasing Telekom Fon pass for a day, to test it with something else than a phonenumber.

ArseneR81 commented 3 years ago

I could connect with following command in terminal:

python3 telekom_fon_connect.py -c telekom_fon_connect.conf

Before I used always

./telekom_fon_connect.py -c telekom_fon_connect.conf

  1. What unit does the sleeptime has. e.g. for the default value 30? Is it minutes to reconnect?

Time to wait in deamon mode between online checks.

  1. Hoe can I set a deamon so that the script is started automatically adfter each restart and reruns every 30 minutes for instancd?
Haxe18 commented 3 years ago

Not yet. Instead of an Email in the config file, I used a phone number like:

fon_username: 49152345678 fon_password: xxx-xxx-xxx

Works also, my definition of number@t-mobile.de is the mentioned mail address on the login page, using the mobile number only is the username on the page. But your error when parsing html is thrown before login, so this is not related to the issue.

I was thinking of purchasing Telekom Fon pass for a day, to test it with something else than a phonenumber.

You're welcome to test the script with something else than the telekom credentials. I don't know if its working. But if it's not working i can't patch this in the script lack of missing account. This script is tested and designed only for usage with a telekom account !

python3 telekom_fon_connect.py

This is the safe way to run this script with python3. If you call the script with ./telekom_fon_connect.py your system resolves the shebang !/usr/bin/python to the default python version on your system. But the script is tested and working with python2 and python3, so the way to exec doesn't matter as long as the need libaries are installed for both python versions ;) The script does exactly the same in both versions.

What unit does the sleeptime has. e.g. for the default value 30? Is it minutes to reconnect?

Not explained by me in readme, sorry for that is fixed now. But if you search yourself for sleeptime in script you will find this line:

time.sleep(float(sleeptime)) # Sleep for n seconds before check status again

Hoe can I set a deamon so that the script is started automatically adfter each restart and reruns every 30 minutes for instancd?

To check online status only every 30 mins instead of 30 seconds, set a sleeptime of 1800 :) To autostart the script, google is your friend. I don't know which system you are using, if it's a linux use systemd :)

But this is end user stuff now and not related to the script/project/issue.

The initial reported error was as guessed by the scripts error message temporary i would say, so I think the issue can be closed now ?