New Version

This commit is contained in:
Madzone
2026-09-09 13:31:53 +02:00
parent 0206070493
commit 23312854fc
13 changed files with 498 additions and 4 deletions
+44 -1
View File
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
"""Interactive configuration for PVE-IDM; Python standard library only."""
import argparse
import getpass
import ipaddress
import json
@@ -157,6 +158,39 @@ def atomic_write(path, content):
os.unlink(temporary)
def rollback_logout():
"""Remove the remote patch and disable reinstallation in local configuration."""
os.chdir(ROOT)
executable = shutil.which('ansible-playbook')
if not executable:
raise RuntimeError('Ansible fehlt. Bitte zuerst die Ansible-Python-Umgebung aktivieren.')
config_path = ROOT / 'group_vars/all.yml'
if not config_path.is_file():
raise RuntimeError('group_vars/all.yml fehlt. Für eine manuelle Installation den Rückbau-Befehl aus der README direkt auf PVE verwenden.')
try:
import yaml
config = yaml.safe_load(config_path.read_text())
except (ImportError, ValueError) as exc:
raise RuntimeError('Konfiguration kann nicht gelesen werden. Bitte die Ansible-Python-Umgebung verwenden.') from exc
if not isinstance(config, dict):
raise RuntimeError('group_vars/all.yml muss eine YAML-Zuordnung enthalten.')
inventory_default = 'inventory/hosts.local.yml' if (ROOT / 'inventory/hosts.local.yml').exists() else 'inventory/hosts.yml'
inventory = ask('Inventory für den Rückbau', inventory_default, local_file)
command = [executable, '-i', str(Path(inventory).expanduser().resolve()), 'playbook/logout-remove.yml']
if yes('SSH-Passwort abfragen?'):
command.append('--ask-pass')
if yes('sudo-Passwort abfragen?'):
command.append('--ask-become-pass')
print('Entfernt nur den verwalteten PVE-Logout-Patch. Keycloak/OIDC und Sicherungen bleiben erhalten.')
if not yes('Logout-Patch auf den PVE-Hosts dieses Inventory jetzt zurückbauen?'):
print('Abgebrochen; keine Änderung.')
return
subprocess.run(command, check=True)
config['pve_logout_enabled'] = False
atomic_write(config_path, yaml.safe_dump(config, allow_unicode=True, sort_keys=False).encode())
print('Rückbau abgeschlossen; pve_logout_enabled=false gespeichert. PVE im Browser vollständig neu laden.')
def main():
os.chdir(ROOT)
if not sys.stdin.isatty():
@@ -197,6 +231,9 @@ def main():
https_url(url.strip(), root=True)
config['pve_redirect_uris'] = list(dict.fromkeys(u.strip() for u in ask(
'PVE-Browser-URLs, mehrere mit Komma trennen', 'https://ts01.heim.lan:8006/', redirects).split(',')))
config['pve_logout_enabled'] = yes('PVE-Logout zu Keycloak weiterleiten (optionaler WebUI-Patch)?', True)
config['pve_logout_redirect_uri'] = ask('Rücksprung nach Keycloak-Logout', config['pve_redirect_uris'][0],
lambda v: None if v in config['pve_redirect_uris'] else invalid('Eine der angegebenen PVE-Browser-URLs wählen.'))
print('\nSessions in Sekunden: 900 = 15 Minuten; 28800 = 8 Stunden')
while True:
for key, label, default in [
@@ -271,7 +308,13 @@ def main():
if __name__ == '__main__':
try:
main()
parser = argparse.ArgumentParser(description='PVE-IDM Einrichtung und Logout-Rückbau')
parser.add_argument('--rollback-logout', action='store_true', help='Logout-Patch entfernen und lokal deaktivieren')
args = parser.parse_args()
if args.rollback_logout:
rollback_logout()
else:
main()
except (KeyboardInterrupt, EOFError):
print('\nAbgebrochen.', file=sys.stderr)
sys.exit(130)