forked from Buxdehuda/strato-certbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth-hook.py
45 lines (39 loc) · 1.39 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
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3
"""Authentification hook in Certbot to Strato dns"""
import json
import os
import sys
import time
from certbotstratoapi import CertbotStratoApi
def main():
"""Run authentification hook."""
# get authentication data
with open(
os.path.dirname(__file__) + os.path.normcase('/strato-auth.json'),
encoding='UTF-8',
) as file:
auth = json.load(file)
username = auth.get('username')
password = auth.get('password')
totp_secret = auth.get('totp_secret')
totp_devicename = auth.get('totp_devicename')
if auth.get('waiting_time', 0).isdigit():
waiting_time = int(auth.get('waiting_time', 0))
else:
waiting_time = 0
strato = CertbotStratoApi()
if not strato.login(username, password, totp_secret, totp_devicename):
print('ERROR: Strato login not accepted.')
sys.exit(1)
# Requests package id which package contains domain to be verified
strato.get_package_id()
# Requests all current TXT/CNAME/SPF/DKIM records from Strato
strato.get_txt_records()
# Add verification token record
strato.set_amce_record()
# Sets all TXT/CNAME/SPF/DKIM records with AMCE record in dns server
strato.push_txt_records()
# Sleep to give the DNS Server time to get ready
time.sleep(waiting_time)
if __name__ == '__main__':
main()