mirror of
https://github.com/hackdiaz-dev/free-turn-proxy.git
synced 2026-10-12 09:41:53 +02:00
fix(routes): починить установку маршрутов в routes.ps1 на Windows
Два Windows-specific бага мешали ставить /32-маршруты к TURN-реле: - log.Printf пишет в stderr, а usage гонит `2>&1 | routes.ps1`. В Windows PowerShell 5.1 `2>&1` на нативном exe оборачивает каждую stderr-строку в ErrorRecord (нет метода .Trim()) — `$_.Trim()` бросал исключение на каждой строке, ни одна не матчилась. Заменено на $_.Trim(), который коэрсит и String, и ErrorRecord в текст строки лога. - New-NetRoute требует -InterfaceIndex (параметр mandatory); без него в non-interactive пайпе cmdlet падал. InterfaceIndex берётся из того же default-route, что и NextHop.
This commit is contained in:
+13
-6
@@ -1,20 +1,26 @@
|
||||
# Usage: .\client.exe -debug ... 2>&1 | .\scripts\routes.ps1
|
||||
# Requires Administrator privileges.
|
||||
|
||||
$gateway = Get-NetRoute `
|
||||
$defaultRoute = Get-NetRoute `
|
||||
-DestinationPrefix "0.0.0.0/0" `
|
||||
-ErrorAction SilentlyContinue `
|
||||
| Sort-Object RouteMetric `
|
||||
| Select-Object -First 1 -ExpandProperty NextHop
|
||||
| Select-Object -First 1
|
||||
|
||||
if (-not $gateway) {
|
||||
Write-Error "Could not determine default gateway"
|
||||
$gateway = $defaultRoute.NextHop
|
||||
$ifIndex = $defaultRoute.InterfaceIndex
|
||||
|
||||
if (-not $gateway -or -not $ifIndex) {
|
||||
Write-Error "Could not determine default gateway / interface"
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host "Default gateway: $gateway"
|
||||
Write-Host "Default gateway: $gateway (ifIndex $ifIndex)"
|
||||
|
||||
$input | ForEach-Object {
|
||||
$line = $_.Trim()
|
||||
# 2>&1 на нативном exe оборачивает stderr-строки в ErrorRecord (нет .Trim()).
|
||||
# "$_" приводит и String, и ErrorRecord к тексту строки лога.
|
||||
$line = "$_".Trim()
|
||||
if ($line -eq "") { return }
|
||||
|
||||
$prefix = $null
|
||||
@@ -51,6 +57,7 @@ $input | ForEach-Object {
|
||||
New-NetRoute `
|
||||
-DestinationPrefix $prefix `
|
||||
-NextHop $gateway `
|
||||
-InterfaceIndex $ifIndex `
|
||||
-PolicyStore ActiveStore `
|
||||
-ErrorAction Stop | Out-Null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user