Setup-SMTPGraphRelay.ps1 aktualisiert
This commit is contained in:
1 parent
832fc63f6b
commit
f14efa5ef7
1 file changed
+70
-50
+70
-50
@@ -978,81 +978,101 @@ function Manage-FailedQueue {
|
||||
}
|
||||
|
||||
function Manage-SmtpAuth {
|
||||
$config = Get-RelayConfig -TargetPath ($InstallPath)
|
||||
if (-not $config) { Write-Fail "config.json nicht gefunden."; return }
|
||||
$config = Ensure-SmtpAuthConfig -Config ($config)
|
||||
$config = Get-RelayConfig -TargetPath ($InstallPath);
|
||||
if (-not $config) { Write-Fail "config.json nicht gefunden."; return; }
|
||||
$config = Ensure-SmtpAuthConfig -Config ($config);
|
||||
|
||||
while ($true) {
|
||||
Clear-Host
|
||||
Write-Title "SMTPGraphRelay - SMTP-AUTH"
|
||||
Clear-Host;
|
||||
Write-Title "SMTPGraphRelay - SMTP-AUTH";
|
||||
|
||||
Write-Host " [1] SMTP-AUTH erforderlich EIN/AUS"
|
||||
Write-Host " [2] Benutzer hinzufuegen"
|
||||
Write-Host " [3] Benutzer anzeigen"
|
||||
Write-Host " [4] Passwort aendern"
|
||||
Write-Host " [5] Benutzer loeschen"
|
||||
Write-Host " [6] Netze ohne Auth verwalten"
|
||||
Write-Host " [7] Max. Fehlversuche aendern"
|
||||
Write-Host " [0] Zurueck`n"
|
||||
$users = @($config.Smtp.AuthUsers);
|
||||
$authState = if ([bool]$config.Smtp.RequireAuth) { "ERFORDERLICH" } else { "optional / nicht erforderlich" };
|
||||
|
||||
$choice = Read-Host "Auswahl"
|
||||
Write-Host "Status: $authState";
|
||||
Write-Host "Benutzer: $($users.Count)";
|
||||
Write-Host "Max. Fehlversuche: $($config.Smtp.AuthMaxFailures)";
|
||||
Write-Host "Ohne Auth erlaubte Netze: $(@($config.Smtp.AllowUnauthenticatedNetworks) -join ', ')";
|
||||
Write-Host "";
|
||||
Write-Host " [1] SMTP-AUTH erforderlich EIN/AUS";
|
||||
Write-Host " [2] Benutzer hinzufuegen";
|
||||
Write-Host " [3] Benutzer anzeigen";
|
||||
Write-Host " [4] Passwort aendern";
|
||||
Write-Host " [5] Benutzer loeschen";
|
||||
Write-Host " [6] Netze ohne Auth verwalten";
|
||||
Write-Host " [7] Max. Fehlversuche aendern";
|
||||
Write-Host " [0] Zurueck`n";
|
||||
|
||||
$choice = Read-Host "Auswahl";
|
||||
|
||||
switch ($choice) {
|
||||
"1" {
|
||||
$config.Smtp.RequireAuth = -not [bool]$config.Smtp.RequireAuth
|
||||
Save-SmtpAuthConfigAndRestart -Config ($config)
|
||||
Write-Ok "Status geaendert."; Read-Host "Enter"
|
||||
$config.Smtp.RequireAuth = -not [bool]$config.Smtp.RequireAuth;
|
||||
if ($config.Smtp.RequireAuth -and @($config.Smtp.AuthUsers).Count -eq 0) {
|
||||
Write-Warn "AUTH wurde aktiviert, aber es existiert noch kein SMTP-Benutzer.";
|
||||
}
|
||||
Save-SmtpAuthConfigAndRestart -Config ($config);
|
||||
Write-Ok "Status geaendert."; Read-Host "Enter";
|
||||
}
|
||||
"2" {
|
||||
$username = Read-Host "Benutzername"
|
||||
$existing = @($config.Smtp.AuthUsers) | Where-Object { ([string]$_.Username).Equals($username, [StringComparison]::OrdinalIgnoreCase) } | Select-Object -First 1
|
||||
if ($existing) { Write-Fail "Benutzer existiert bereits."; Read-Host "Enter"; continue }
|
||||
$username = Read-Host "Benutzername";
|
||||
if ([string]::IsNullOrWhiteSpace($username) -or $username -notmatch '^[A-Za-z0-9._@-]{1,128}$') { Write-Fail "Ungueltiger Benutzername."; Read-Host "Enter"; continue; }
|
||||
$existing = @($config.Smtp.AuthUsers) | Where-Object { ([string]$_.Username).Equals($username, [StringComparison]::OrdinalIgnoreCase) } | Select-Object -First 1;
|
||||
if ($existing) { Write-Fail "Benutzer existiert bereits."; Read-Host "Enter"; continue; }
|
||||
|
||||
$plain1 = Read-Host "Passwort"
|
||||
$plain2 = Read-Host "Passwort wiederholen"
|
||||
if ($plain1.Length -lt 8 -or $plain1 -cne$plain2) { Write-Fail "Passwort ungueltig."; Read-Host "Enter"; continue }
|
||||
$plain1 = Read-Host "Passwort";
|
||||
$plain2 = Read-Host "Passwort wiederholen";
|
||||
if ($plain1.Length -lt 8 -or $plain1 -cne $plain2) { Write-Fail "Passwort ungueltig (mind. 8 Zeichen oder stimmen nicht ueberein)."; Read-Host "Enter"; continue; }
|
||||
|
||||
$record = New-SmtpPasswordRecord -Password ($plain1)
|
||||
$newUser = [pscustomobject]@{ Username =$username; Salt = $record.Salt; PasswordHash =$record.PasswordHash; Iterations = $record.Iterations }$config.Smtp.AuthUsers = @($config.Smtp.AuthUsers) + @($newUser)
|
||||
Save-SmtpAuthConfigAndRestart -Config ($config)
|
||||
Write-Ok "Angelegt."; Read-Host "Enter"
|
||||
$record = New-SmtpPasswordRecord -Password ($plain1);
|
||||
$newUser = [pscustomobject]@{ Username = $username; Salt = $record.Salt; PasswordHash = $record.PasswordHash; Iterations = $record.Iterations };
|
||||
$config.Smtp.AuthUsers = @($config.Smtp.AuthUsers) + @($newUser);
|
||||
Save-SmtpAuthConfigAndRestart -Config ($config);
|
||||
Write-Ok "Angelegt."; Read-Host "Enter";
|
||||
}
|
||||
"3" {
|
||||
if (@($config.Smtp.AuthUsers).Count -eq 0) { Write-Warn "Keine SMTP-Benutzer vorhanden."; } else { @($config.Smtp.AuthUsers) | Format-Table Username,Iterations -AutoSize; }
|
||||
Read-Host "Enter";
|
||||
}
|
||||
"3" { @($config.Smtp.AuthUsers) | Format-Table Username,Iterations -AutoSize; Read-Host "Enter" }
|
||||
"4" {
|
||||
$username = Read-Host "Benutzername"
|
||||
$user = @($config.Smtp.AuthUsers) | Where-Object { ([string]$_.Username).Equals($username, [StringComparison]::OrdinalIgnoreCase) } | Select-Object -First 1
|
||||
if (-not $user) { Write-Fail "Benutzer nicht gefunden."; Read-Host "Enter"; continue }
|
||||
$username = Read-Host "Benutzername";
|
||||
$user = @($config.Smtp.AuthUsers) | Where-Object { ([string]$_.Username).Equals($username, [StringComparison]::OrdinalIgnoreCase) } | Select-Object -First 1;
|
||||
if (-not $user) { Write-Fail "Benutzer nicht gefunden."; Read-Host "Enter"; continue; }
|
||||
|
||||
$plain1 = Read-Host "Neues Passwort"
|
||||
$plain2 = Read-Host "Passwort wiederholen"
|
||||
if ($plain1.Length -lt 8 -or $plain1 -cne$plain2) { Write-Fail "Passwort ungueltig."; Read-Host "Enter"; continue }
|
||||
$plain1 = Read-Host "Neues Passwort";
|
||||
$plain2 = Read-Host "Passwort wiederholen";
|
||||
if ($plain1.Length -lt 8 -or $plain1 -cne $plain2) { Write-Fail "Passwort ungueltig (mind. 8 Zeichen oder stimmen nicht ueberein)."; Read-Host "Enter"; continue; }
|
||||
|
||||
$record = New-SmtpPasswordRecord -Password ($plain1)
|
||||
$user.Salt =$record.Salt; $user.PasswordHash =$record.PasswordHash; $user.Iterations =$record.Iterations
|
||||
Save-SmtpAuthConfigAndRestart -Config ($config)
|
||||
Write-Ok "Geaendert."; Read-Host "Enter"
|
||||
$record = New-SmtpPasswordRecord -Password ($plain1);
|
||||
$user.Salt = $record.Salt; $user.PasswordHash = $record.PasswordHash; $user.Iterations = $record.Iterations;
|
||||
Save-SmtpAuthConfigAndRestart -Config ($config);
|
||||
Write-Ok "Geaendert."; Read-Host "Enter";
|
||||
}
|
||||
"5" {
|
||||
$username = Read-Host "Benutzername"
|
||||
$username = Read-Host "Benutzername";
|
||||
$found = @($config.Smtp.AuthUsers) | Where-Object { ([string]$_.Username).Equals($username, [StringComparison]::OrdinalIgnoreCase) };
|
||||
if (-not $found) { Write-Fail "Benutzer nicht gefunden."; Read-Host "Enter"; continue; }
|
||||
if (Confirm-Yes "Loeschen?") {
|
||||
$config.Smtp.AuthUsers = @($config.Smtp.AuthUsers | Where-Object { -not ([string]$_.Username).Equals($username, [StringComparison]::OrdinalIgnoreCase) })
|
||||
Save-SmtpAuthConfigAndRestart -Config ($config)
|
||||
$config.Smtp.AuthUsers = @($config.Smtp.AuthUsers | Where-Object { -not ([string]$_.Username).Equals($username, [StringComparison]::OrdinalIgnoreCase) });
|
||||
Save-SmtpAuthConfigAndRestart -Config ($config);
|
||||
Write-Ok "Geloescht.";
|
||||
}
|
||||
Read-Host "Enter";
|
||||
}
|
||||
"6" {
|
||||
$current = @($config.Smtp.AllowUnauthenticatedNetworks) -join ","
|
||||
$input = Read-Default "Netze/IPs ohne AUTH" $(if ($current) {$current } else { "-" })
|
||||
if ($input -eq "-") { $config.Smtp.AllowUnauthenticatedNetworks = @() } else { $config.Smtp.AllowUnauthenticatedNetworks = @($input -split "," | ForEach-Object { $_.Trim() } \vert{} Where-Object {$_ }) }
|
||||
Save-SmtpAuthConfigAndRestart -Config ($config)
|
||||
$current = @($config.Smtp.AllowUnauthenticatedNetworks) -join ",";
|
||||
$input = Read-Default "Netze/IPs ohne AUTH" $(if ($current) {$current } else { "-" });
|
||||
if ($input -eq "-") { $config.Smtp.AllowUnauthenticatedNetworks = @(); } else { $config.Smtp.AllowUnauthenticatedNetworks = @($input -split "," | ForEach-Object { $_.Trim() } | Where-Object { $_ }); }
|
||||
Save-SmtpAuthConfigAndRestart -Config ($config);
|
||||
}
|
||||
"7" {
|
||||
$value = Read-Host "Max. Fehlversuche"
|
||||
if ($value -match '^\d+$') {$config.Smtp.AuthMaxFailures = [int]$value; Save-SmtpAuthConfigAndRestart -Config ($config) }
|
||||
$value = Read-Host "Max. Fehlversuche";
|
||||
if ($value -match '^\d+$') { $config.Smtp.AuthMaxFailures = [int]$value; Save-SmtpAuthConfigAndRestart -Config ($config); }
|
||||
}
|
||||
"0" { return }
|
||||
"0" { return; }
|
||||
}
|
||||
$config = Get-RelayConfig -TargetPath ($InstallPath)
|
||||
$config = Ensure-SmtpAuthConfig -Config ($config)
|
||||
$config = Get-RelayConfig -TargetPath ($InstallPath);
|
||||
$config = Ensure-SmtpAuthConfig -Config ($config);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user