forked from Buxdehuda/strato-certbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth-hook.py
32 lines (25 loc) · 1.1 KB
/
auth-hook.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python3
import json
import os
import re
import requests
def main():
# get authentication
with open("strato-auth.json") as file:
auth = json.load(file)
username = auth["username"]
password = auth["password"]
api_url = "https://www.strato.de/apps/CustomerService"
txt_key = "_acme-challenge"
txt_value = os.environ["CERTBOT_VALIDATION"]
domain_name = re.search(r"(\w+\.\w+)$", os.environ["CERTBOT_DOMAIN"]).group(1)
# setup session for cookie sharing
http_session = requests.session()
# request session id
request = http_session.get(api_url)
request = http_session.post(api_url, { "identifier": username, "passwd": password, "action_customer_login.x": "Login" })
session_id = re.search(r"sessionID=(.*?)\"", request.text).group(1)
# set txt record
http_session.post(api_url, { "sessionID": session_id, "cID": "1", "node": "ManageDomains", "vhost": domain_name, "spf_type": "NONE", "prefix": txt_key, "type": "TXT", "value": txt_value, "action_change_txt_records": "Einstellung+übernehmen" })
if __name__ == "__main__":
main()