fix: firewall block/unblock in INPUT, FORWARD, and mangle PREROUTING chains; combine SSH calls to avoid timeouts; check actual iptables rules instead of settings config

This commit is contained in:
Reditus committed 2026-05-14 00:37:45 +01:00
1 parent ae86251196
commit 67ad94ea26
2 files changed
+22 -22

No files matched your search

+3 -1
View File
@@ -698,13 +698,15 @@ if (-not $SshValid) {
$tmpFwScript = Join-Path $env:TEMP ([System.IO.Path]::GetRandomFileName() + ".sh")
$fwContent = "for PORT in $($portsToBlock -join ' '); do`n"
$fwContent += " if iptables -C FORWARD -p tcp --dport `$PORT -s 127.0.0.1 -j ACCEPT 2>/dev/null; then`n"
$fwContent += " if iptables -t mangle -C PREROUTING -p tcp --dport `$PORT -s 127.0.0.1 -j ACCEPT 2>/dev/null; then`n"
$fwContent += " echo 'Port `$PORT already blocked'`n"
$fwContent += " else`n"
$fwContent += " iptables -I INPUT 1 -p tcp --dport `$PORT -s 127.0.0.1 -j ACCEPT`n"
$fwContent += " iptables -I INPUT 2 -p tcp --dport `$PORT -j DROP`n"
$fwContent += " iptables -I FORWARD 1 -p tcp --dport `$PORT -s 127.0.0.1 -j ACCEPT`n"
$fwContent += " iptables -I FORWARD 2 -p tcp --dport `$PORT -j DROP`n"
$fwContent += " iptables -t mangle -I PREROUTING 1 -p tcp --dport `$PORT -s 127.0.0.1 -j ACCEPT`n"
$fwContent += " iptables -t mangle -I PREROUTING 2 -p tcp --dport `$PORT -j DROP`n"
$fwContent += " echo 'Port `$PORT blocked'`n"
$fwContent += " fi`n"
$fwContent += "done`n"