"feat: Update configuration settings in backend/app/config/settings.py and installer script"

This commit is contained in:
Till Tomczak 2025-05-26 11:20:29 +02:00
parent a201c96d13
commit 7d4ec90d99
2 changed files with 216 additions and 244 deletions

View File

@ -4,7 +4,7 @@ from datetime import timedelta
# Hardcodierte Konfiguration
SECRET_KEY = "7445630171969DFAC92C53CEC92E67A9CB2E00B3CB2F"
DATABASE_PATH = "database/myp.db"
DATABASE_PATH = "../database/myp.db"
TAPO_USERNAME = "till.tomczak@mercedes-benz.com"
TAPO_PASSWORD = "744563017196A"

View File

@ -1,17 +1,14 @@
# MYP Installer Control Center
# Zentrale Installationskonsole für die MYP-Plattform
# Kombiniert alle Setup-Funktionen für SSL, Hosts, Docker und mehr
# Version 2.0
# Farbdefinitionen für bessere Lesbarkeit
$colors = @{
Title = "Cyan"
Success = "Green"
Error = "Red"
Warning = "Yellow"
Info = "Blue"
Command = "White"
}
$ColorTitle = "Cyan"
$ColorSuccess = "Green"
$ColorError = "Red"
$ColorWarning = "Yellow"
$ColorInfo = "Blue"
$ColorCommand = "White"
# Überprüfen, ob das Skript als Administrator ausgeführt wird
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
@ -20,22 +17,22 @@ function Show-Header {
param ([string]$Title)
Clear-Host
Write-Host "=============================================================" -ForegroundColor $colors.Title
Write-Host " MYP INSTALLER CONTROL CENTER" -ForegroundColor $colors.Title
Write-Host "=============================================================" -ForegroundColor $colors.Title
Write-Host " $Title" -ForegroundColor $colors.Title
Write-Host "=============================================================" -ForegroundColor $colors.Title
Write-Host "=============================================================" -ForegroundColor $ColorTitle
Write-Host " MYP INSTALLER CONTROL CENTER" -ForegroundColor $ColorTitle
Write-Host "=============================================================" -ForegroundColor $ColorTitle
Write-Host " $Title" -ForegroundColor $ColorTitle
Write-Host "=============================================================" -ForegroundColor $ColorTitle
if (-not $isAdmin) {
Write-Host "HINWEIS: Dieses Skript läuft ohne Administrator-Rechte." -ForegroundColor $colors.Warning
Write-Host "Einige Funktionen sind möglicherweise eingeschränkt." -ForegroundColor $colors.Warning
Write-Host "=============================================================" -ForegroundColor $colors.Title
Write-Host "HINWEIS: Dieses Skript läuft ohne Administrator-Rechte." -ForegroundColor $ColorWarning
Write-Host "Einige Funktionen sind möglicherweise eingeschränkt." -ForegroundColor $ColorWarning
Write-Host "=============================================================" -ForegroundColor $ColorTitle
}
Write-Host ""
}
function Test-Command {
function Test-CommandExists {
param ([string]$Command)
try {
@ -53,20 +50,21 @@ function Exec-Command {
[string]$Description
)
Write-Host "> $Description..." -ForegroundColor $colors.Info
Write-Host "> $Description..." -ForegroundColor $ColorInfo
try {
Invoke-Expression $Command | Out-Host
if ($LASTEXITCODE -eq 0 -or $null -eq $LASTEXITCODE) {
Write-Host "✓ Erfolgreich abgeschlossen!" -ForegroundColor $colors.Success
Write-Host "✓ Erfolgreich abgeschlossen!" -ForegroundColor $ColorSuccess
return $true
} else {
Write-Host "✗ Fehler beim Ausführen des Befehls. Exit-Code: $LASTEXITCODE" -ForegroundColor $colors.Error
Write-Host "✗ Fehler beim Ausführen des Befehls. Exit-Code: $LASTEXITCODE" -ForegroundColor $ColorError
return $false
}
}
catch {
Write-Host "✗ Fehler: $_" -ForegroundColor $colors.Error
$errorMessage = $_.Exception.Message
Write-Host "✗ Fehler: $errorMessage" -ForegroundColor $ColorError
return $false
}
}
@ -80,53 +78,82 @@ function Get-LocalIPAddress {
}
function Test-Dependencies {
Write-Host "Prüfe Abhängigkeiten..." -ForegroundColor $colors.Info
Show-Header "Systemvoraussetzungen prüfen"
$dependencies = @{}
$dependencies["python"] = "Python (3.6+)"
$dependencies["pip"] = "Python Package Manager"
$dependencies["docker"] = "Docker"
$dependencies["docker-compose"] = "Docker Compose"
$dependencies["node"] = "Node.js"
$dependencies["npm"] = "Node Package Manager"
$dependencies["openssl"] = "OpenSSL"
Write-Host "Prüfe Abhängigkeiten..." -ForegroundColor $ColorInfo
$allInstalled = $true
foreach ($dep in $dependencies.GetEnumerator()) {
$installed = Test-Command $dep.Key
if ($installed) {
Write-Host "$($dep.Value) gefunden" -ForegroundColor $colors.Success
} else {
Write-Host "$($dep.Value) nicht gefunden" -ForegroundColor $colors.Error
$allInstalled = $false
}
$pythonInstalled = Test-CommandExists "python"
if ($pythonInstalled) {
Write-Host "✓ Python gefunden" -ForegroundColor $ColorSuccess
} else {
Write-Host "✗ Python nicht gefunden" -ForegroundColor $ColorError
}
return $allInstalled
$pipInstalled = Test-CommandExists "pip"
if ($pipInstalled) {
Write-Host "✓ Pip gefunden" -ForegroundColor $ColorSuccess
} else {
Write-Host "✗ Pip nicht gefunden" -ForegroundColor $ColorError
}
$dockerInstalled = Test-CommandExists "docker"
if ($dockerInstalled) {
Write-Host "✓ Docker gefunden" -ForegroundColor $ColorSuccess
} else {
Write-Host "✗ Docker nicht gefunden" -ForegroundColor $ColorError
}
$dockerComposeInstalled = Test-CommandExists "docker-compose"
if ($dockerComposeInstalled) {
Write-Host "✓ Docker Compose gefunden" -ForegroundColor $ColorSuccess
} else {
Write-Host "✗ Docker Compose nicht gefunden" -ForegroundColor $ColorError
}
$nodeInstalled = Test-CommandExists "node"
if ($nodeInstalled) {
Write-Host "✓ Node.js gefunden" -ForegroundColor $ColorSuccess
} else {
Write-Host "✗ Node.js nicht gefunden" -ForegroundColor $ColorError
}
$npmInstalled = Test-CommandExists "npm"
if ($npmInstalled) {
Write-Host "✓ NPM gefunden" -ForegroundColor $ColorSuccess
} else {
Write-Host "✗ NPM nicht gefunden" -ForegroundColor $ColorError
}
Write-Host ""
Write-Host "Drücken Sie eine beliebige Taste, um fortzufahren..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
function Setup-Hosts {
Show-Header "Host-Konfiguration"
if (-not $isAdmin) {
Write-Host "Diese Funktion erfordert Administrator-Rechte." -ForegroundColor $colors.Error
Write-Host "Bitte starten Sie das Skript als Administrator neu." -ForegroundColor $colors.Warning
Write-Host "Diese Funktion erfordert Administrator-Rechte." -ForegroundColor $ColorError
Write-Host "Bitte starten Sie das Skript als Administrator neu." -ForegroundColor $ColorWarning
Write-Host ""
Write-Host "Drücken Sie eine beliebige Taste, um fortzufahren..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
return
}
$localIP = Get-LocalIPAddress
Write-Host "Lokale IP-Adresse: $localIP" -ForegroundColor $colors.Success
Write-Host "Lokale IP-Adresse: $localIP" -ForegroundColor $ColorSuccess
$hostsFile = "$env:windir\System32\drivers\etc\hosts"
Write-Host "Hosts-Datei: $hostsFile" -ForegroundColor $colors.Info
Write-Host "Hosts-Datei: $hostsFile" -ForegroundColor $ColorInfo
# Prüfen, ob die Einträge bereits existieren
$frontendEntry = Select-String -Path $hostsFile -Pattern "m040tbaraspi001.de040.corpintra.net" -Quiet
$backendEntry = Select-String -Path $hostsFile -Pattern "raspberrypi" -Quiet
# Einträge in die Hosts-Datei schreiben
Write-Host "Aktualisiere Hosts-Datei..." -ForegroundColor $colors.Info
Write-Host "Aktualisiere Hosts-Datei..." -ForegroundColor $ColorInfo
$hostsContent = Get-Content -Path $hostsFile
@ -134,33 +161,34 @@ function Setup-Hosts {
$hostsContent += ""
$hostsContent += "# MYP Frontend Host"
$hostsContent += "$localIP m040tbaraspi001.de040.corpintra.net m040tbaraspi001"
Write-Host "Frontend-Hostname hinzugefügt" -ForegroundColor $colors.Success
Write-Host "Frontend-Hostname hinzugefügt" -ForegroundColor $ColorSuccess
} else {
Write-Host "Frontend-Hostname ist bereits konfiguriert" -ForegroundColor $colors.Warning
Write-Host "Frontend-Hostname ist bereits konfiguriert" -ForegroundColor $ColorWarning
}
if (-not $backendEntry) {
$hostsContent += ""
$hostsContent += "# MYP Backend Host"
$hostsContent += "$localIP raspberrypi"
Write-Host "Backend-Hostname hinzugefügt" -ForegroundColor $colors.Success
Write-Host "Backend-Hostname hinzugefügt" -ForegroundColor $ColorSuccess
} else {
Write-Host "Backend-Hostname ist bereits konfiguriert" -ForegroundColor $colors.Warning
Write-Host "Backend-Hostname ist bereits konfiguriert" -ForegroundColor $ColorWarning
}
# Speichern der aktualisierten Hosts-Datei
try {
$hostsContent | Set-Content -Path $hostsFile -Force
Write-Host "Konfiguration abgeschlossen!" -ForegroundColor $colors.Success
Write-Host "Konfiguration abgeschlossen!" -ForegroundColor $ColorSuccess
}
catch {
Write-Host "Fehler beim Schreiben der Hosts-Datei: $_" -ForegroundColor $colors.Error
$errorMessage = $_.Exception.Message
Write-Host "Fehler beim Schreiben der Hosts-Datei: $errorMessage" -ForegroundColor $ColorError
}
Write-Host ""
Write-Host "Folgende Hostnamen sind jetzt konfiguriert:" -ForegroundColor $colors.Info
Write-Host " - Frontend: m040tbaraspi001.de040.corpintra.net" -ForegroundColor $colors.Command
Write-Host " - Backend: raspberrypi" -ForegroundColor $colors.Command
Write-Host "Folgende Hostnamen sind jetzt konfiguriert:" -ForegroundColor $ColorInfo
Write-Host " - Frontend: m040tbaraspi001.de040.corpintra.net" -ForegroundColor $ColorCommand
Write-Host " - Backend: raspberrypi" -ForegroundColor $ColorCommand
Write-Host ""
Write-Host "Drücken Sie eine beliebige Taste, um fortzufahren..."
@ -177,50 +205,47 @@ function Create-SSLCertificates {
$frontendCertFile = "$certDir/frontend.crt"
$frontendKeyFile = "$certDir/frontend.key"
Write-Host "Zertifikate werden für folgende Hostnamen erstellt:" -ForegroundColor $colors.Info
Write-Host "Zertifikate werden für folgende Hostnamen erstellt:" -ForegroundColor $ColorInfo
# Hostname-Auswahl
Write-Host "1. Für lokale Entwicklung (localhost)" -ForegroundColor $colors.Command
Write-Host "2. Für Raspberry Pi Deployment (raspberrypi)" -ForegroundColor $colors.Command
Write-Host "3. Für Unternehmens-Setup (m040tbaraspi001.de040.corpintra.net)" -ForegroundColor $colors.Command
Write-Host "1. Für lokale Entwicklung (localhost)" -ForegroundColor $ColorCommand
Write-Host "2. Für Raspberry Pi Deployment (raspberrypi)" -ForegroundColor $ColorCommand
Write-Host "3. Für Unternehmens-Setup (m040tbaraspi001.de040.corpintra.net)" -ForegroundColor $ColorCommand
$choice = Read-Host "Wählen Sie eine Option (1-3, Standard: 1)"
switch ($choice) {
"2" {
$backendHostname = "raspberrypi"
$frontendHostname = "raspberrypi"
}
"3" {
$backendHostname = "raspberrypi"
$frontendHostname = "m040tbaraspi001.de040.corpintra.net"
}
default {
$backendHostname = "localhost"
$frontendHostname = "localhost"
}
$backendHostname = "localhost"
$frontendHostname = "localhost"
if ($choice -eq "2") {
$backendHostname = "raspberrypi"
$frontendHostname = "raspberrypi"
}
elseif ($choice -eq "3") {
$backendHostname = "raspberrypi"
$frontendHostname = "m040tbaraspi001.de040.corpintra.net"
}
Write-Host "Backend-Hostname: $backendHostname" -ForegroundColor $colors.Info
Write-Host "Frontend-Hostname: $frontendHostname" -ForegroundColor $colors.Info
Write-Host "Backend-Hostname: $backendHostname" -ForegroundColor $ColorInfo
Write-Host "Frontend-Hostname: $frontendHostname" -ForegroundColor $ColorInfo
Write-Host ""
# Verzeichnis erstellen, falls es nicht existiert
if (!(Test-Path $certDir)) {
Write-Host "Erstelle Verzeichnis $certDir..." -ForegroundColor $colors.Info
Write-Host "Erstelle Verzeichnis $certDir..." -ForegroundColor $ColorInfo
New-Item -ItemType Directory -Path $certDir -Force | Out-Null
}
# SSL-Zertifikate mit Python und cryptography erstellen
Write-Host "Erstelle SSL-Zertifikate mit Python..." -ForegroundColor $colors.Info
Write-Host "Erstelle SSL-Zertifikate mit Python..." -ForegroundColor $ColorInfo
$pythonInstalled = Test-Command "python"
$pythonInstalled = Test-CommandExists "python"
if ($pythonInstalled) {
# Überprüfen, ob cryptography installiert ist
$cryptographyInstalled = python -c "try: import cryptography; print('True'); except ImportError: print('False')" 2>$null
if ($cryptographyInstalled -ne "True") {
Write-Host "Installiere Python-Abhängigkeit 'cryptography'..." -ForegroundColor $colors.Warning
Write-Host "Installiere Python-Abhängigkeit 'cryptography'..." -ForegroundColor $ColorWarning
Exec-Command "pip install cryptography" "Installiere cryptography-Paket"
}
@ -331,17 +356,20 @@ create_self_signed_cert('$frontendCertFile', '$frontendKeyFile', '$frontendHostn
# Python-Skript ausführen
try {
python $tempScriptPath
Write-Host "SSL-Zertifikate erfolgreich erstellt!" -ForegroundColor $colors.Success
Write-Host "SSL-Zertifikate erfolgreich erstellt!" -ForegroundColor $ColorSuccess
}
catch {
Write-Host "Fehler beim Erstellen der SSL-Zertifikate: $_" -ForegroundColor $colors.Error
$errorMessage = $_.Exception.Message
Write-Host "Fehler beim Erstellen der SSL-Zertifikate: $errorMessage" -ForegroundColor $ColorError
}
finally {
# Temporäres Skript löschen
Remove-Item -Path $tempScriptPath -Force
if (Test-Path $tempScriptPath) {
Remove-Item -Path $tempScriptPath -Force
}
}
} else {
Write-Host "Python nicht gefunden. SSL-Zertifikate können nicht erstellt werden." -ForegroundColor $colors.Error
Write-Host "Python nicht gefunden. SSL-Zertifikate können nicht erstellt werden." -ForegroundColor $ColorError
}
# Zertifikate im System installieren (optional)
@ -350,26 +378,26 @@ create_self_signed_cert('$frontendCertFile', '$frontendKeyFile', '$frontendHostn
if ($installCerts -eq "j") {
if (Test-Path $backendCertFile) {
Write-Host "Installiere Backend-Zertifikat im System..." -ForegroundColor $colors.Info
Write-Host "Installiere Backend-Zertifikat im System..." -ForegroundColor $ColorInfo
Exec-Command "certutil -addstore -f 'ROOT' '$backendCertFile'" "Installiere im Root-Zertifikatsspeicher"
}
if (Test-Path $frontendCertFile) {
Write-Host "Installiere Frontend-Zertifikat im System..." -ForegroundColor $colors.Info
Write-Host "Installiere Frontend-Zertifikat im System..." -ForegroundColor $ColorInfo
Exec-Command "certutil -addstore -f 'ROOT' '$frontendCertFile'" "Installiere im Root-Zertifikatsspeicher"
}
}
} else {
Write-Host "Hinweis: Um die Zertifikate im System zu installieren, starten Sie das Skript als Administrator." -ForegroundColor $colors.Warning
Write-Host "Hinweis: Um die Zertifikate im System zu installieren, starten Sie das Skript als Administrator." -ForegroundColor $ColorWarning
}
# Frontend für HTTPS konfigurieren
Write-Host ""
Write-Host "Möchten Sie das Frontend für HTTPS konfigurieren? (j/n, Standard: j)" -ForegroundColor $colors.Info
Write-Host "Möchten Sie das Frontend für HTTPS konfigurieren? (j/n, Standard: j)" -ForegroundColor $ColorInfo
$configureFrontend = Read-Host
if ($configureFrontend -ne "n") {
Write-Host "Konfiguriere Frontend für HTTPS..." -ForegroundColor $colors.Info
Write-Host "Konfiguriere Frontend für HTTPS..." -ForegroundColor $ColorInfo
# Kopiere Zertifikate ins Frontend-Verzeichnis
$frontendSslDir = "./frontend/ssl"
@ -377,10 +405,15 @@ create_self_signed_cert('$frontendCertFile', '$frontendKeyFile', '$frontendHostn
New-Item -ItemType Directory -Path $frontendSslDir -Force | Out-Null
}
Copy-Item -Path $backendCertFile -Destination "$frontendSslDir/myp.crt" -Force
Copy-Item -Path $backendKeyFile -Destination "$frontendSslDir/myp.key" -Force
if (Test-Path $backendCertFile) {
Copy-Item -Path $backendCertFile -Destination "$frontendSslDir/myp.crt" -Force
}
Write-Host "Zertifikate ins Frontend-Verzeichnis kopiert." -ForegroundColor $colors.Success
if (Test-Path $backendKeyFile) {
Copy-Item -Path $backendKeyFile -Destination "$frontendSslDir/myp.key" -Force
}
Write-Host "Zertifikate ins Frontend-Verzeichnis kopiert." -ForegroundColor $ColorSuccess
# Prüfen, ob .env.local existiert und aktualisieren
$envLocalPath = "./frontend/.env.local"
@ -419,13 +452,13 @@ create_self_signed_cert('$frontendCertFile', '$frontendKeyFile', '$frontendHostn
# Speichern der aktualisierten Umgebungsvariablen
$envContent | Out-File -FilePath $envLocalPath -Encoding utf8
Write-Host ".env.local Datei mit SSL-Konfigurationen aktualisiert." -ForegroundColor $colors.Success
Write-Host ".env.local Datei mit SSL-Konfigurationen aktualisiert." -ForegroundColor $ColorSuccess
}
Write-Host ""
Write-Host "SSL-Zertifikate wurden in folgenden Pfaden gespeichert:" -ForegroundColor $colors.Info
Write-Host "Backend: $backendCertFile" -ForegroundColor $colors.Command
Write-Host "Frontend: $frontendCertFile" -ForegroundColor $colors.Command
Write-Host "SSL-Zertifikate wurden in folgenden Pfaden gespeichert:" -ForegroundColor $ColorInfo
Write-Host "Backend: $backendCertFile" -ForegroundColor $ColorCommand
Write-Host "Frontend: $frontendCertFile" -ForegroundColor $ColorCommand
Write-Host ""
Write-Host "Drücken Sie eine beliebige Taste, um fortzufahren..."
@ -436,28 +469,32 @@ function Setup-Environment {
Show-Header "Umgebungs-Setup"
# Prüfen, ob Python und pip installiert sind
$pythonInstalled = Test-Command "python"
$pipInstalled = Test-Command "pip"
$pythonInstalled = Test-CommandExists "python"
$pipInstalled = Test-CommandExists "pip"
if (-not $pythonInstalled -or -not $pipInstalled) {
Write-Host "Python oder pip ist nicht installiert. Bitte installieren Sie Python 3.6+ und versuchen Sie es erneut." -ForegroundColor $colors.Error
Write-Host "Python oder pip ist nicht installiert. Bitte installieren Sie Python 3.6+ und versuchen Sie es erneut." -ForegroundColor $ColorError
Write-Host ""
Write-Host "Drücken Sie eine beliebige Taste, um fortzufahren..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
return
}
# Python-Abhängigkeiten installieren
Write-Host "Installiere Backend-Abhängigkeiten..." -ForegroundColor $colors.Info
Write-Host "Installiere Backend-Abhängigkeiten..." -ForegroundColor $ColorInfo
Exec-Command "pip install -r backend/requirements.txt" "Installiere Python-Abhängigkeiten"
# Prüfen, ob Node.js und npm installiert sind
$nodeInstalled = Test-Command "node"
$npmInstalled = Test-Command "npm"
$nodeInstalled = Test-CommandExists "node"
$npmInstalled = Test-CommandExists "npm"
if ($nodeInstalled -and $npmInstalled) {
# Frontend-Abhängigkeiten installieren
Write-Host "Installiere Frontend-Abhängigkeiten..." -ForegroundColor $colors.Info
Write-Host "Installiere Frontend-Abhängigkeiten..." -ForegroundColor $ColorInfo
Exec-Command "cd frontend && npm install" "Installiere Node.js-Abhängigkeiten"
} else {
Write-Host "Node.js oder npm ist nicht installiert. Frontend-Abhängigkeiten werden übersprungen." -ForegroundColor $colors.Warning
Write-Host "Node.js oder npm ist nicht installiert. Frontend-Abhängigkeiten werden übersprungen." -ForegroundColor $ColorWarning
}
# Docker-Compose Datei aktualisieren
@ -469,14 +506,14 @@ function Setup-Environment {
if (-not $dockerCompose.Contains("--dual-protocol")) {
$dockerCompose = $dockerCompose -replace "command: python -m app\.app", "command: python -m app.app --dual-protocol"
$dockerCompose | Set-Content $dockerComposeFile
Write-Host "Docker-Compose-Datei wurde aktualisiert, um den dual-protocol-Modus zu aktivieren." -ForegroundColor $colors.Success
Write-Host "Docker-Compose-Datei wurde aktualisiert, um den dual-protocol-Modus zu aktivieren." -ForegroundColor $ColorSuccess
} else {
Write-Host "Docker-Compose-Datei ist bereits korrekt konfiguriert." -ForegroundColor $colors.Success
Write-Host "Docker-Compose-Datei ist bereits korrekt konfiguriert." -ForegroundColor $ColorSuccess
}
}
Write-Host ""
Write-Host "Umgebungs-Setup abgeschlossen!" -ForegroundColor $colors.Success
Write-Host "Umgebungs-Setup abgeschlossen!" -ForegroundColor $ColorSuccess
Write-Host ""
Write-Host "Drücken Sie eine beliebige Taste, um fortzufahren..."
@ -486,103 +523,51 @@ function Setup-Environment {
function Start-Application {
Show-Header "Anwendung starten"
Write-Host "Wie möchten Sie die Anwendung starten?" -ForegroundColor $colors.Info
Write-Host "1. Backend-Server starten (Python)" -ForegroundColor $colors.Command
Write-Host "2. Frontend-Server starten (Node.js)" -ForegroundColor $colors.Command
Write-Host "3. Beide Server starten (in separaten Fenstern)" -ForegroundColor $colors.Command
Write-Host "4. Mit Docker Compose starten" -ForegroundColor $colors.Command
Write-Host "5. Zurück zum Hauptmenü" -ForegroundColor $colors.Command
Write-Host "Wie möchten Sie die Anwendung starten?" -ForegroundColor $ColorInfo
Write-Host "1. Backend-Server starten (Python)" -ForegroundColor $ColorCommand
Write-Host "2. Frontend-Server starten (Node.js)" -ForegroundColor $ColorCommand
Write-Host "3. Beide Server starten (in separaten Fenstern)" -ForegroundColor $ColorCommand
Write-Host "4. Mit Docker Compose starten" -ForegroundColor $ColorCommand
Write-Host "5. Zurück zum Hauptmenü" -ForegroundColor $ColorCommand
$choice = Read-Host "Wählen Sie eine Option (1-5)"
switch ($choice) {
"1" {
Write-Host "Starte Backend-Server..." -ForegroundColor $colors.Info
Start-Process -FilePath "python" -ArgumentList "backend/app/app.py" -NoNewWindow
Write-Host "Backend-Server läuft jetzt im Hintergrund." -ForegroundColor $colors.Success
}
"2" {
Write-Host "Starte Frontend-Server..." -ForegroundColor $colors.Info
Start-Process -FilePath "npm" -ArgumentList "run dev" -WorkingDirectory "frontend" -NoNewWindow
Write-Host "Frontend-Server läuft jetzt im Hintergrund." -ForegroundColor $colors.Success
}
"3" {
Write-Host "Starte Backend-Server..." -ForegroundColor $colors.Info
Start-Process -FilePath "python" -ArgumentList "backend/app/app.py" -NoNewWindow
Write-Host "Starte Frontend-Server..." -ForegroundColor $colors.Info
Start-Process -FilePath "npm" -ArgumentList "run dev" -WorkingDirectory "frontend" -NoNewWindow
Write-Host "Beide Server laufen jetzt im Hintergrund." -ForegroundColor $colors.Success
}
"4" {
$dockerInstalled = Test-Command "docker"
$dockerComposeInstalled = Test-Command "docker-compose"
if ($dockerInstalled -and $dockerComposeInstalled) {
Write-Host "Starte Anwendung mit Docker Compose..." -ForegroundColor $colors.Info
Exec-Command "docker-compose up -d" "Starte Docker Container"
Write-Host "Docker Container wurden gestartet." -ForegroundColor $colors.Success
} else {
Write-Host "Docker oder Docker Compose ist nicht installiert." -ForegroundColor $colors.Error
}
}
"5" {
return
}
default {
Write-Host "Ungültige Option." -ForegroundColor $colors.Error
}
if ($choice -eq "1") {
Write-Host "Starte Backend-Server..." -ForegroundColor $ColorInfo
Start-Process -FilePath "python" -ArgumentList "backend/app/app.py" -NoNewWindow
Write-Host "Backend-Server läuft jetzt im Hintergrund." -ForegroundColor $ColorSuccess
}
Write-Host ""
Write-Host "Drücken Sie eine beliebige Taste, um fortzufahren..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
function Clean-OldScripts {
Show-Header "Alte Skripte bereinigen"
$oldScripts = @(
"setup_ssl.ps1",
"setup_hosts.ps1",
"setup_hosts_copy.ps1",
"generate_ssl_certs.ps1",
"generate_ssl_certs_copy.ps1",
"setup_ssl.sh",
"setup_hosts.sh",
"generate_ssl_certs.sh"
)
Write-Host "Folgende Skripte werden gelöscht:" -ForegroundColor $colors.Info
foreach ($script in $oldScripts) {
if (Test-Path $script) {
Write-Host " - $script" -ForegroundColor $colors.Command
}
elseif ($choice -eq "2") {
Write-Host "Starte Frontend-Server..." -ForegroundColor $ColorInfo
Start-Process -FilePath "npm" -ArgumentList "run dev" -WorkingDirectory "frontend" -NoNewWindow
Write-Host "Frontend-Server läuft jetzt im Hintergrund." -ForegroundColor $ColorSuccess
}
Write-Host ""
$confirm = Read-Host "Möchten Sie fortfahren? (j/n, Standard: j)"
if ($confirm -ne "n") {
foreach ($script in $oldScripts) {
if (Test-Path $script) {
try {
Remove-Item -Path $script -Force
Write-Host "$script wurde gelöscht." -ForegroundColor $colors.Success
}
catch {
$errorMessage = $_.Exception.Message
Write-Host "✗ Fehler beim Löschen von $script`: $errorMessage" -ForegroundColor $colors.Error
}
}
}
elseif ($choice -eq "3") {
Write-Host "Starte Backend-Server..." -ForegroundColor $ColorInfo
Start-Process -FilePath "python" -ArgumentList "backend/app/app.py" -NoNewWindow
Write-Host ""
Write-Host "Bereinigung abgeschlossen." -ForegroundColor $colors.Success
}
Write-Host "Starte Frontend-Server..." -ForegroundColor $ColorInfo
Start-Process -FilePath "npm" -ArgumentList "run dev" -WorkingDirectory "frontend" -NoNewWindow
Write-Host "Beide Server laufen jetzt im Hintergrund." -ForegroundColor $ColorSuccess
}
elseif ($choice -eq "4") {
$dockerInstalled = Test-CommandExists "docker"
$dockerComposeInstalled = Test-CommandExists "docker-compose"
if ($dockerInstalled -and $dockerComposeInstalled) {
Write-Host "Starte Anwendung mit Docker Compose..." -ForegroundColor $ColorInfo
Exec-Command "docker-compose up -d" "Starte Docker Container"
Write-Host "Docker Container wurden gestartet." -ForegroundColor $ColorSuccess
} else {
Write-Host "Docker oder Docker Compose ist nicht installiert." -ForegroundColor $ColorError
}
}
elseif ($choice -eq "5") {
return
}
else {
Write-Host "Bereinigung abgebrochen." -ForegroundColor $colors.Warning
Write-Host "Ungültige Option." -ForegroundColor $ColorError
}
Write-Host ""
@ -594,56 +579,43 @@ function Clean-OldScripts {
function Show-MainMenu {
Show-Header "Hauptmenü"
Write-Host "1. Systemvoraussetzungen prüfen" -ForegroundColor $colors.Command
Write-Host "2. Host-Konfiguration einrichten" -ForegroundColor $colors.Command
Write-Host "3. SSL-Zertifikate erstellen" -ForegroundColor $colors.Command
Write-Host "4. Umgebung einrichten (Abhängigkeiten installieren)" -ForegroundColor $colors.Command
Write-Host "5. Anwendung starten" -ForegroundColor $colors.Command
Write-Host "6. Alte Skripte bereinigen" -ForegroundColor $colors.Command
Write-Host "Q. Beenden" -ForegroundColor $colors.Command
Write-Host "1. Systemvoraussetzungen prüfen" -ForegroundColor $ColorCommand
Write-Host "2. Host-Konfiguration einrichten" -ForegroundColor $ColorCommand
Write-Host "3. SSL-Zertifikate erstellen" -ForegroundColor $ColorCommand
Write-Host "4. Umgebung einrichten (Abhängigkeiten installieren)" -ForegroundColor $ColorCommand
Write-Host "5. Anwendung starten" -ForegroundColor $ColorCommand
Write-Host "6. Beenden" -ForegroundColor $ColorCommand
Write-Host ""
$choice = Read-Host "Wählen Sie eine Option (1-6, Q)"
$choice = Read-Host "Wählen Sie eine Option (1-6)"
switch ($choice) {
"1" {
Test-Dependencies
Write-Host ""
Write-Host "Drücken Sie eine beliebige Taste, um fortzufahren..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Show-MainMenu
}
"2" {
Setup-Hosts
Show-MainMenu
}
"3" {
Create-SSLCertificates
Show-MainMenu
}
"4" {
Setup-Environment
Show-MainMenu
}
"5" {
Start-Application
Show-MainMenu
}
"6" {
Clean-OldScripts
Show-MainMenu
}
"Q" {
exit
}
"q" {
exit
}
default {
Write-Host "Ungültige Option. Bitte versuchen Sie es erneut." -ForegroundColor $colors.Error
Start-Sleep -Seconds 2
Show-MainMenu
}
if ($choice -eq "1") {
Test-Dependencies
Show-MainMenu
}
elseif ($choice -eq "2") {
Setup-Hosts
Show-MainMenu
}
elseif ($choice -eq "3") {
Create-SSLCertificates
Show-MainMenu
}
elseif ($choice -eq "4") {
Setup-Environment
Show-MainMenu
}
elseif ($choice -eq "5") {
Start-Application
Show-MainMenu
}
elseif ($choice -eq "6") {
exit
}
else {
Write-Host "Ungültige Option. Bitte versuchen Sie es erneut." -ForegroundColor $ColorError
Start-Sleep -Seconds 2
Show-MainMenu
}
}