-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsweb_test.py
89 lines (69 loc) · 1.86 KB
/
sweb_test.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import getpass
import random
import sys
import time
from typing import cast
from certbot_dns_sweb.sweb_api import SWebAPI
from certbot_dns_sweb.sweb_client import SWebClient
if len(sys.argv) >= 2:
username = sys.argv[1]
else:
username = input("Username: ")
if len(sys.argv) >= 3:
domain = sys.argv[2]
else:
domain = input("Domain to test: ")
if sys.stdin.isatty():
password = getpass.getpass()
else:
password = input("Password: ")
print()
if not password:
print("Password is not set")
sys.exit(1)
print("Authenticate on SpaceWeb...")
c = SWebClient(
username=username,
password=password,
user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36",
)
print("Successfully authenticated; api version", c.jsonrpc_api_version)
api = SWebAPI(c)
print("Showing all DNS records:")
time.sleep(2) # I'm a human!
print()
for x in api.domains_dns_info(domain):
print(x)
print()
print(f"Adding TXT record for _test-challenge.{domain}")
value = str(random.randrange(10**8, 10**9))
time.sleep(3)
edit_resp = api.domains_dns_edit_txt(
domain=domain,
action="add",
subdomain="_test-challenge",
value=value,
)
print("Response:", repr(edit_resp))
print("Press Enter to remove the TXT record")
input()
del_resp = None
for x in api.domains_dns_info_find(
domain=domain,
subdomain="_test-challenge",
type="TXT",
):
if x["value"] == value:
print(f"Removing TXT record for _test-challenge.{domain}")
time.sleep(3)
del_resp = api.domains_dns_edit_txt(
domain=domain,
action="del",
subdomain="_test-challenge",
index=cast(int, x["index"]),
)
print("Response:", repr(del_resp))
break
if del_resp is None:
print("We have a problem with domains_dns_info_find")
print("Done.")