Session-Caching, Domain-/Gruppen-Skripte; KeePass-DB aus Repo entfernen
- inwx_common.py: Login mit Session-Cache, KP_PW-Option - inwx_list/add: Domain als Argument, gemeinsamer Helfer - inwx_domains(_owner).py: Domains alphabetisch, NS, Gruppen via citeq-TXT (DNS) - hosting.kdbx aus Tracking genommen und in .gitignore Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+17
-50
@@ -1,40 +1,17 @@
|
||||
#!/usr/bin/env python3
|
||||
import sys
|
||||
import os
|
||||
import subprocess
|
||||
import argparse
|
||||
|
||||
# Import-Fix für die Library-Struktur
|
||||
try:
|
||||
from INWX.Domrobot import ApiClient
|
||||
except ImportError:
|
||||
from inwx.Domrobot import ApiClient
|
||||
from inwx_common import get_client, call_api
|
||||
|
||||
# --- KONFIGURATION ---
|
||||
API_URL = 'https://api.domrobot.com'
|
||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
KP_DB_PATH = os.path.join(BASE_DIR, "hosting.kdbx")
|
||||
KP_ENTRY_NAME = "inwx"
|
||||
DOMAIN = "ma151.de"
|
||||
# Login/Session-Handling steckt in inwx_common.py.
|
||||
|
||||
def get_creds():
|
||||
"""Holt die Daten sicher aus KeePassXC."""
|
||||
try:
|
||||
cmd = ["keepassxc-cli", "show", "-s", KP_DB_PATH, KP_ENTRY_NAME]
|
||||
output = subprocess.check_output(cmd, text=True)
|
||||
creds = {}
|
||||
for line in output.splitlines():
|
||||
if ":" in line:
|
||||
k, v = line.split(":", 1)
|
||||
creds[k.strip().lower()] = v.strip()
|
||||
return creds.get("username") or creds.get("benutzername"), creds.get("password") or creds.get("passwort")
|
||||
except Exception as e:
|
||||
print(f"❌ KeePass-Fehler: {e}")
|
||||
return None, None
|
||||
|
||||
def main():
|
||||
# 1. Argument-Parser einrichten
|
||||
parser = argparse.ArgumentParser(description=f"DNS-Record zu {DOMAIN} hinzufügen.")
|
||||
parser = argparse.ArgumentParser(description="DNS-Record zu einer Domain hinzufügen.")
|
||||
parser.add_argument("domain", help="Domain (z.B. ma151.de)")
|
||||
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)")
|
||||
@@ -42,34 +19,23 @@ def main():
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
# 2. Zugangsdaten laden
|
||||
user, password = get_creds()
|
||||
if not user or not password:
|
||||
sys.exit(1)
|
||||
# 2. Client holen (nutzt ggf. die zwischengespeicherte Session)
|
||||
api = get_client()
|
||||
|
||||
api = ApiClient(api_url=API_URL)
|
||||
|
||||
# 3. Login
|
||||
login_res = api.login(user, password)
|
||||
if login_res['code'] != 1000:
|
||||
print(f"❌ Login fehlgeschlagen: {login_res['msg']}")
|
||||
sys.exit(1)
|
||||
|
||||
# 4. Prüfen, ob der Record existiert
|
||||
full_name = f"{args.name}.{DOMAIN}"
|
||||
# 3. Prüfen, ob der Record existiert
|
||||
full_name = f"{args.name}.{args.domain}"
|
||||
print(f"🔍 Prüfe {full_name} ({args.type} -> {args.content})...")
|
||||
|
||||
info_res = api.call_api('nameserver.info', {'domain': DOMAIN})
|
||||
info_res = call_api(api, 'nameserver.info', {'domain': args.domain})
|
||||
if info_res['code'] != 1000:
|
||||
print(f"❌ Fehler bei Domain-Info: {info_res['msg']}")
|
||||
api.logout()
|
||||
sys.exit(1)
|
||||
|
||||
records = info_res['resData'].get('record', [])
|
||||
already_exists = False
|
||||
for rec in records:
|
||||
if (rec['name'].rstrip('.') == full_name and
|
||||
rec['type'].upper() == args.type.upper() and
|
||||
if (rec['name'].rstrip('.') == full_name and
|
||||
rec['type'].upper() == args.type.upper() and
|
||||
rec['content'] == args.content):
|
||||
already_exists = True
|
||||
break
|
||||
@@ -77,22 +43,23 @@ def main():
|
||||
if already_exists:
|
||||
print(f"ℹ️ Record existiert bereits. Keine Aktion erforderlich.")
|
||||
else:
|
||||
# 5. Record erstellen
|
||||
# 4. Record erstellen
|
||||
print(f"🚀 Erstelle neuen Record...")
|
||||
create_res = api.call_api('nameserver.createRecord', {
|
||||
'domain': DOMAIN,
|
||||
create_res = call_api(api, 'nameserver.createRecord', {
|
||||
'domain': args.domain,
|
||||
'name': args.name,
|
||||
'type': args.type.upper(),
|
||||
'content': args.content,
|
||||
'ttl': args.ttl
|
||||
})
|
||||
|
||||
|
||||
if create_res['code'] == 1000:
|
||||
print(f"✅ Erfolg! Record ID: {create_res['resData']['id']}")
|
||||
else:
|
||||
print(f"❌ Fehler: {create_res['msg']} (Code: {create_res['code']})")
|
||||
|
||||
api.logout()
|
||||
# Kein logout() -> die Session bleibt gültig und kann wiederverwendet werden.
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user