diff --git a/.gitignore b/.gitignore index fb80b9f..b995589 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ strato-auth.json venv certbot.env +__pycache__ \ No newline at end of file diff --git a/certbotstratoapi.py b/certbotstratoapi.py index 0d409a3..695b03c 100644 --- a/certbotstratoapi.py +++ b/certbotstratoapi.py @@ -1,10 +1,11 @@ """Certbot-Strato-API Class""" import os import re -import sys +import urllib import pyotp import requests +from bs4 import BeautifulSoup class CertbotStratoApi: @@ -53,7 +54,8 @@ def login_2fa( """ # Is 2FA used - if not re.search(r'

\s*Zwei-Faktor-Authentifizierung\s*<\/h1>', response.text): + soup = BeautifulSoup(response.text, 'html.parser') + if soup.find('h1', string=re.compile('Zwei\\-Faktor\\-Authentifizierung')) is not None: print('INFO: 2FA is not used.') return response if (not totp_secret) or (not totp_devicename): @@ -63,12 +65,9 @@ def login_2fa( param = {'identifier': username} # Set parameter 'totp_token' - result = re.search( - r'', - response.text) - if result: - param['totp_token'] = result.group('totp_token') + totp_input = soup.find('input', attrs={'type': 'hidden', 'name': 'totp_token'}) + if totp_input is not None: + param['totp_token'] = totp_input['value'] else: print('ERROR: Parsing error on 2FA site by totp_token.') return response @@ -76,6 +75,8 @@ def login_2fa( # Set parameter 'action_customer_login.x' param['action_customer_login.x'] = 1 + # No idea what this regex does + # TODO: rewrite with beautifulsoup # Set parameter pw_id for device in re.finditer( rf'