aufrufparameter
This commit is contained in:
+31
-37
@@ -2,6 +2,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import argparse
|
||||||
|
|
||||||
# Import-Fix für die Library-Struktur
|
# Import-Fix für die Library-Struktur
|
||||||
try:
|
try:
|
||||||
@@ -14,16 +15,10 @@ API_URL = 'https://api.domrobot.com'
|
|||||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
KP_DB_PATH = os.path.join(BASE_DIR, "hosting.kdbx")
|
KP_DB_PATH = os.path.join(BASE_DIR, "hosting.kdbx")
|
||||||
KP_ENTRY_NAME = "inwx"
|
KP_ENTRY_NAME = "inwx"
|
||||||
|
|
||||||
# Daten für den neuen Record
|
|
||||||
DOMAIN = "ma151.de"
|
DOMAIN = "ma151.de"
|
||||||
NEW_NAME = "srv1" # Subdomain
|
|
||||||
NEW_TYPE = "A" # Record-Typ
|
|
||||||
NEW_VALUE = "167.86.90.246"
|
|
||||||
NEW_TTL = 3600 # Time to Live in Sekunden
|
|
||||||
|
|
||||||
def get_creds():
|
def get_creds():
|
||||||
"""Liest User/Passwort sicher aus KeePassXC."""
|
"""Holt die Daten sicher aus KeePassXC."""
|
||||||
try:
|
try:
|
||||||
cmd = ["keepassxc-cli", "show", "-s", KP_DB_PATH, KP_ENTRY_NAME]
|
cmd = ["keepassxc-cli", "show", "-s", KP_DB_PATH, KP_ENTRY_NAME]
|
||||||
output = subprocess.check_output(cmd, text=True)
|
output = subprocess.check_output(cmd, text=True)
|
||||||
@@ -38,65 +33,64 @@ def get_creds():
|
|||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
# 1. Argument-Parser einrichten
|
||||||
|
parser = argparse.ArgumentParser(description=f"DNS-Record zu {DOMAIN} hinzufügen.")
|
||||||
|
parser.add_argument("type", help="Typ des Records (z.B. A, AAAA, CNAME, TXT)")
|
||||||
|
parser.add_argument("name", help="Name/Subdomain (z.B. srv1)")
|
||||||
|
parser.add_argument("content", help="Wert des Records (z.B. die IP-Adresse)")
|
||||||
|
parser.add_argument("--ttl", type=int, default=3600, help="TTL in Sekunden (Standard: 3600)")
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
# 2. Zugangsdaten laden
|
||||||
user, password = get_creds()
|
user, password = get_creds()
|
||||||
if not user or not password:
|
if not user or not password:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
api = ApiClient(api_url=API_URL)
|
api = ApiClient(api_url=API_URL)
|
||||||
|
|
||||||
# 1. Login
|
# 3. Login
|
||||||
login_res = api.login(user, password)
|
login_res = api.login(user, password)
|
||||||
if login_res['code'] != 1000:
|
if login_res['code'] != 1000:
|
||||||
print(f"❌ Login fehlgeschlagen: {login_res['msg']}")
|
print(f"❌ Login fehlgeschlagen: {login_res['msg']}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
print(f"✅ Login erfolgreich. Prüfe Record: {NEW_NAME}.{DOMAIN} ({NEW_TYPE} -> {NEW_VALUE})")
|
# 4. Prüfen, ob der Record existiert
|
||||||
|
full_name = f"{args.name}.{DOMAIN}"
|
||||||
|
print(f"🔍 Prüfe {full_name} ({args.type} -> {args.content})...")
|
||||||
|
|
||||||
# 2. Prüfen, ob der Record bereits existiert
|
|
||||||
# Wir rufen alle Records der Domain ab
|
|
||||||
info_res = api.call_api('nameserver.info', {'domain': DOMAIN})
|
info_res = api.call_api('nameserver.info', {'domain': DOMAIN})
|
||||||
|
|
||||||
if info_res['code'] != 1000:
|
if info_res['code'] != 1000:
|
||||||
print(f"❌ Fehler beim Abrufen der Domain-Info: {info_res['msg']}")
|
print(f"❌ Fehler bei Domain-Info: {info_res['msg']}")
|
||||||
api.logout()
|
api.logout()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
records = info_res['resData'].get('record', [])
|
records = info_res['resData'].get('record', [])
|
||||||
|
|
||||||
# Den FQDN (Full Qualified Domain Name) zusammenbauen, wie INWX ihn speichert
|
|
||||||
full_name = f"{NEW_NAME}.{DOMAIN}"
|
|
||||||
|
|
||||||
# Suche nach Dubletten
|
|
||||||
already_exists = False
|
already_exists = False
|
||||||
for rec in records:
|
for rec in records:
|
||||||
# INWX gibt Namen oft mit oder ohne Punkt am Ende zurück, wir prüfen beides
|
if (rec['name'].rstrip('.') == full_name and
|
||||||
rec_name = rec['name'].rstrip('.')
|
rec['type'].upper() == args.type.upper() and
|
||||||
if (rec_name == full_name and
|
rec['content'] == args.content):
|
||||||
rec['type'] == NEW_TYPE and
|
|
||||||
rec['content'] == NEW_VALUE):
|
|
||||||
already_exists = True
|
already_exists = True
|
||||||
break
|
break
|
||||||
|
|
||||||
if already_exists:
|
if already_exists:
|
||||||
print(f"ℹ️ Record existiert bereits exakt so. Keine Änderung nötig.")
|
print(f"ℹ️ Record existiert bereits. Keine Aktion erforderlich.")
|
||||||
else:
|
else:
|
||||||
print(f"🚀 Record nicht gefunden. Erstelle {full_name}...")
|
# 5. Record erstellen
|
||||||
|
print(f"🚀 Erstelle neuen Record...")
|
||||||
# 3. Record erstellen
|
create_res = api.call_api('nameserver.createRecord', {
|
||||||
create_params = {
|
|
||||||
'domain': DOMAIN,
|
'domain': DOMAIN,
|
||||||
'name': NEW_NAME,
|
'name': args.name,
|
||||||
'type': NEW_TYPE,
|
'type': args.type.upper(),
|
||||||
'content': NEW_VALUE,
|
'content': args.content,
|
||||||
'ttl': NEW_TTL
|
'ttl': args.ttl
|
||||||
}
|
})
|
||||||
|
|
||||||
create_res = api.call_api('nameserver.createRecord', create_params)
|
|
||||||
|
|
||||||
if create_res['code'] == 1000:
|
if create_res['code'] == 1000:
|
||||||
print(f"✅ Erfolg! Record wurde mit ID {create_res['resData']['id']} angelegt.")
|
print(f"✅ Erfolg! Record ID: {create_res['resData']['id']}")
|
||||||
else:
|
else:
|
||||||
print(f"❌ Fehler beim Erstellen: {create_res['msg']} (Code: {create_res['code']})")
|
print(f"❌ Fehler: {create_res['msg']} (Code: {create_res['code']})")
|
||||||
|
|
||||||
api.logout()
|
api.logout()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user