first release

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Stefan Hacker
2026-06-06 12:21:16 +02:00
parent ffc7876d17
commit 2542cf5455
13 changed files with 1037 additions and 0 deletions
+68
View File
@@ -0,0 +1,68 @@
import requests
def _headers(api_key):
return {
'X-API-Key': api_key,
'Content-Type': 'application/json',
'Accept': 'application/json',
}
def test_connection(plesk_url, api_key, verify_ssl=True):
resp = requests.get(
f'{plesk_url.rstrip("/")}/api/v2/server',
headers=_headers(api_key),
verify=verify_ssl,
timeout=10,
)
resp.raise_for_status()
return resp.json()
def update_dns_record(plesk_url, api_key, domain, subdomain, ip, verify_ssl=True):
base = plesk_url.rstrip('/')
hdrs = _headers(api_key)
# Find existing A record for this subdomain
resp = requests.get(
f'{base}/api/v2/dns/records',
params={'domain_name': domain, 'type': 'A'},
headers=hdrs,
verify=verify_ssl,
timeout=15,
)
resp.raise_for_status()
records = resp.json()
# Match by host (Plesk returns just the subdomain part, e.g. "mypc")
host_lower = subdomain.lower().rstrip('.')
match = next(
(r for r in records if r.get('host', '').lower().rstrip('.') == host_lower),
None
)
if match:
resp = requests.put(
f'{base}/api/v2/dns/records/{match["id"]}',
json={'value': ip},
headers=hdrs,
verify=verify_ssl,
timeout=15,
)
resp.raise_for_status()
else:
resp = requests.post(
f'{base}/api/v2/dns/records',
json={
'domain_name': domain,
'type': 'A',
'host': subdomain,
'value': ip,
'ttl': 300,
},
headers=hdrs,
verify=verify_ssl,
timeout=15,
)
resp.raise_for_status()