diff --git a/manage.ps1 b/manage.ps1 index 0a5958f..7340a47 100644 --- a/manage.ps1 +++ b/manage.ps1 @@ -78,6 +78,7 @@ while ($true) { Write-Host " [3] 🔄 Обновить статус" -ForegroundColor White + Write-Host " [L] 📜 Просмотр логов" -ForegroundColor White Write-Host " [U] ❌ Удалить всё (Uninstall)" -ForegroundColor Red Write-Host " [q] Выход" -ForegroundColor White Write-Host "" @@ -88,6 +89,7 @@ while ($true) { "1" { & "$ScriptDir\scripts\setup-singbox.ps1" } "2" { & "$ScriptDir\scripts\setup-discord.ps1" } "3" { continue } + "l" { & "$ScriptDir\scripts\view-logs.ps1" } "u" { & "$ScriptDir\scripts\uninstall-all.ps1" } "q" { exit } } diff --git a/scripts/setup-discord.ps1 b/scripts/setup-discord.ps1 index 3773f88..5370e39 100644 --- a/scripts/setup-discord.ps1 +++ b/scripts/setup-discord.ps1 @@ -107,11 +107,12 @@ function Install-ProxiFyre { function Configure-And-Start { param($TargetApps, $ProxyAddr) - # Конфиг + # Конфиг (гарантируем, что appNames - массив) + $appNamesArray = @($TargetApps) $cfg = @{ logLevel = "Info" proxies = @(@{ - appNames = $TargetApps + appNames = $appNamesArray socks5ProxyEndpoint = $ProxyAddr supportedProtocols = @("TCP", "UDP") }) @@ -182,12 +183,74 @@ function Configure-And-Start { Write-Success "Готово! Служба стабильна." } +function Get-AppPath { + Write-Host "`n📁 Укажите путь до папки с приложением" -ForegroundColor Yellow + Write-Host " (Будут проксированы все .exe из этой папки)" -ForegroundColor Gray + + # Стандартные пути установки Discord-клиентов + $defaultPaths = @{ + "Discord" = "$env:LOCALAPPDATA\Discord" + "Discord PTB" = "$env:LOCALAPPDATA\DiscordPTB" + "Discord Canary" = "$env:LOCALAPPDATA\DiscordCanary" + "Vesktop" = "$env:LOCALAPPDATA\vesktop" + "Lightcord" = "$env:LOCALAPPDATA\Lightcord" + } + + $suggestions = @() + foreach ($app in $defaultPaths.Keys) { + if (Test-Path $defaultPaths[$app]) { + $suggestions += @{ Name = $app; Path = $defaultPaths[$app] } + } + } + + if ($suggestions.Count -gt 0) { + Write-Host "`n Найденные приложения:" -ForegroundColor Cyan + for ($i = 0; $i -lt $suggestions.Count; $i++) { + Write-Host " [$($i+1)] $($suggestions[$i].Name): $($suggestions[$i].Path)" -ForegroundColor Gray + } + Write-Host " [c] Указать свой путь" -ForegroundColor Gray + + $choice = Read-Host "`n Выберите" + if ($choice -match "^\d+$" -and [int]$choice -ge 1 -and [int]$choice -le $suggestions.Count) { + return @($suggestions[[int]$choice - 1].Path) + } + } + + # Ручной ввод пути + while ($true) { + $path = Read-Host " Путь до папки" + + if ([string]::IsNullOrWhiteSpace($path)) { + Write-Warning "Путь не указан" + continue + } + + if (Test-Path $path) { + $exeCount = (Get-ChildItem $path -Filter "*.exe" -Recurse -ErrorAction SilentlyContinue).Count + if ($exeCount -gt 0) { + Write-Success "Найдено $exeCount исполняемых файлов" + return @($path) + } + else { + Write-Warning "В папке не найдено .exe файлов" + } + } + else { + Write-Error "Папка не существует: $path" + } + + $retry = Read-Host " Попробовать другой путь? (y/n)" + if ($retry -ne 'y') { return $null } + } +} + function Select-Apps { Write-Host "`n🎮 Какие приложения проксировать?" -ForegroundColor Yellow $appOpts = [Ordered]@{ - "1" = "Discord" - "2" = "Vesktop" - "3" = "Discord + Vesktop" + "1" = "Discord (по имени процесса)" + "2" = "Vesktop (по имени процесса)" + "3" = "Discord + Vesktop (по имени процесса)" + "4" = "Указать путь до папки приложения" } $appChoice = Show-Menu -Options $appOpts @@ -196,6 +259,7 @@ function Select-Apps { "1" { @("Discord", "Update") } "2" { @("Vesktop") } "3" { @("Vesktop", "Discord", "Update") } + "4" { Get-AppPath } default { @("Discord", "Update") } } return $result diff --git a/scripts/setup-singbox.ps1 b/scripts/setup-singbox.ps1 index f55555d..286bbf7 100644 --- a/scripts/setup-singbox.ps1 +++ b/scripts/setup-singbox.ps1 @@ -68,7 +68,7 @@ function New-SingboxConfig { param($Outbound, $Port) return @{ - log = @{ level = "info"; timestamp = $true } + log = @{ level = "info"; timestamp = $true; output = "$InstallDir\singbox.log" } dns = @{ independent_cache = $true } inbounds = @( @{ diff --git a/scripts/view-logs.ps1 b/scripts/view-logs.ps1 new file mode 100644 index 0000000..bbde619 --- /dev/null +++ b/scripts/view-logs.ps1 @@ -0,0 +1,121 @@ +# ========================================== +# 📜 LOG VIEWER +# ========================================== +# View logs from sing-box and ProxiFyre + +param([switch]$Follow) + +$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path +. "$ScriptDir\lib\Common.ps1" + +$SingboxLog = "C:\Tools\sing-box\singbox.log" +$ProxiFyreLog = "C:\Tools\ProxiFyre" + +function Show-LogFile { + param( + [string]$Path, + [string]$Title, + [int]$Lines = 30, + [string]$Color = "Gray" + ) + + if (Test-Path $Path) { + Write-Host "`n═══ $Title ═══" -ForegroundColor Cyan + $content = Get-Content $Path -Tail $Lines -ErrorAction SilentlyContinue + if ($content) { + $content | ForEach-Object { Write-Host " $_" -ForegroundColor $Color } + } + else { + Write-Host " (Лог пустой)" -ForegroundColor DarkGray + } + } + else { + Write-Host "`n═══ $Title ═══" -ForegroundColor Cyan + Write-Host " (Файл не найден: $Path)" -ForegroundColor DarkGray + } +} + +function Tail-Logs { + Write-Host "`n📜 Режим отслеживания логов (Ctrl+C для выхода)" -ForegroundColor Yellow + Write-Host " sing-box: $SingboxLog" -ForegroundColor DarkGray + Write-Host " ProxiFyre: $ProxiFyreLog\*.log" -ForegroundColor DarkGray + Write-Host "" + + $sbPos = 0 + $pfPos = 0 + $pfLogFile = $null + + # Initial positions + if (Test-Path $SingboxLog) { $sbPos = (Get-Item $SingboxLog).Length } + $pfLogFile = Get-ChildItem "$ProxiFyreLog\*.log" -ErrorAction SilentlyContinue | Sort-Object LastWriteTime | Select-Object -Last 1 + if ($pfLogFile) { $pfPos = $pfLogFile.Length } + + try { + while ($true) { + Start-Sleep -Milliseconds 500 + + # Sing-box + if (Test-Path $SingboxLog) { + $newSize = (Get-Item $SingboxLog).Length + if ($newSize -gt $sbPos) { + $content = Get-Content $SingboxLog -Tail 20 -ErrorAction SilentlyContinue + # Show only new lines (approximate) + $content | Select-Object -Last ([math]::Max(1, [math]::Ceiling(($newSize - $sbPos) / 100))) | ForEach-Object { + Write-Host "[SB] $_" -ForegroundColor Green + } + $sbPos = $newSize + } + } + + # ProxiFyre + $pfLogFile = Get-ChildItem "$ProxiFyreLog\*.log" -ErrorAction SilentlyContinue | Sort-Object LastWriteTime | Select-Object -Last 1 + if ($pfLogFile) { + $newSize = $pfLogFile.Length + if ($newSize -gt $pfPos) { + $content = Get-Content $pfLogFile.FullName -Tail 20 -ErrorAction SilentlyContinue + $content | Select-Object -Last ([math]::Max(1, [math]::Ceiling(($newSize - $pfPos) / 100))) | ForEach-Object { + Write-Host "[PF] $_" -ForegroundColor Yellow + } + $pfPos = $newSize + } + } + } + } + catch { + Write-Host "`nОстановлено." -ForegroundColor Gray + } +} + +# --- MAIN --- + +Write-Header "ПРОСМОТР ЛОГОВ" -ClearScreen + +$opts = [Ordered]@{ + "1" = "Показать последние логи" + "2" = "Следить за логами в реальном времени (tail -f)" + "b" = "Назад" +} + +$choice = Show-Menu -Options $opts + +switch ($choice) { + "1" { + Show-LogFile -Path $SingboxLog -Title "SING-BOX (VPN)" -Lines 50 -Color "Green" + + $pfLog = Get-ChildItem "$ProxiFyreLog\*.log" -ErrorAction SilentlyContinue | Sort-Object LastWriteTime | Select-Object -Last 1 + if ($pfLog) { + Show-LogFile -Path $pfLog.FullName -Title "PROXIFYRE (Discord)" -Lines 50 -Color "Yellow" + } + else { + Write-Host "`n═══ PROXIFYRE (Discord) ═══" -ForegroundColor Cyan + Write-Host " (Логов не найдено в $ProxiFyreLog)" -ForegroundColor DarkGray + } + + Write-Host "" + Read-Host "Нажмите Enter для выхода" + } + "2" { + Tail-Logs + } + "b" { exit } +}