122 lines
4.2 KiB
PowerShell
122 lines
4.2 KiB
PowerShell
# ==========================================
|
|
# 📜 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 }
|
|
}
|