Files
vpn-proxy/scripts/setup-discord.ps1

275 lines
9.2 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ==========================================
# 🎮 DISCORD PROXY SETUP
# ==========================================
param(
[switch]$Force,
[switch]$Debug
)
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
. "$ScriptDir\lib\Common.ps1"
. "$ScriptDir\lib\Net.ps1"
. "$ScriptDir\lib\System.ps1"
if ($Debug) { Set-DebugMode -Enabled $true }
Write-Header "НАСТРОЙКА DISCORD / VESKTOP" -ClearScreen
Ensure-Admin
$InstallPath = "C:\Tools\ProxiFyre"
$ConfigPath = "$InstallPath\app-config.json"
$DriverUrl = "https://github.com/wiresock/ndisapi/releases/download/v3.6.2/Windows.Packet.Filter.3.6.2.1.x64.msi"
$AppUrl = "https://github.com/wiresock/proxifyre/releases/download/v2.1.4/ProxiFyre-v2.1.4-x64-signed.zip"
# --- ФУНКЦИИ ---
function Test-ProxyConnection {
param([string]$ProxyAddr)
Write-Info "Проверка подключения к прокси $ProxyAddr..."
try {
$parts = $ProxyAddr -split ":"
$host_ = $parts[0]
$port = [int]$parts[1]
# 1. Проверяем TCP соединение
$tcp = New-Object System.Net.Sockets.TcpClient
$tcp.Connect($host_, $port)
$tcp.Close()
Write-Success "TCP соединение установлено"
# 2. Пробуем получить внешний IP через прокси (используем curl для SOCKS5)
try {
$result = & curl.exe -s -x "socks5://$ProxyAddr" "http://v4.ident.me" --connect-timeout 5 2>$null
if ($result -match "^\d+\.\d+\.\d+\.\d+$") {
Write-Success "Внешний IP через прокси: $result"
return $true
}
}
catch {}
Write-Warning "TCP работает, но не удалось получить IP. Возможно прокси не полностью настроен."
return $true
}
catch {
Write-Error "Не удалось подключиться к $ProxyAddr"
Write-Host " Убедитесь, что прокси запущен и доступен." -ForegroundColor Gray
return $false
}
}
function Get-CurrentConfig {
if (Test-Path $ConfigPath) {
try {
$cfg = Get-Content $ConfigPath -Raw | ConvertFrom-Json
return @{
Apps = $cfg.proxies[0].appNames -join ", "
Proxy = $cfg.proxies[0].socks5ProxyEndpoint
}
}
catch {}
}
return $null
}
function Install-ProxiFyre {
# Установка драйвера
Write-Step "Установка драйвера..."
$msi = "$env:TEMP\WinpkFilter.msi"
if (Download-File -Url $DriverUrl -Destination $msi) {
Start-Process msiexec.exe -ArgumentList "/i `"$msi`" /qn /norestart" -Wait
Write-Success "Драйвер готов"
}
# Установка ProxiFyre
Write-Step "Установка ProxiFyre..."
New-Item -ItemType Directory -Path $InstallPath -Force | Out-Null
$zip = "$env:TEMP\ProxiFyre.zip"
if (Download-File -Url $AppUrl -Destination $zip) {
Expand-Archive -Path $zip -DestinationPath $InstallPath -Force
$exe = Get-ChildItem $InstallPath -Recurse -Filter "ProxiFyre.exe" | Select -First 1
if ($exe.DirectoryName -ne $InstallPath) {
Copy-Item "$($exe.DirectoryName)\*" $InstallPath -Recurse -Force
}
Write-Success "Распаковано"
}
}
function Configure-And-Start {
param($TargetApps, $ProxyAddr)
# Конфиг
$cfg = @{
logLevel = "Info"
proxies = @(@{
appNames = $TargetApps
socks5ProxyEndpoint = $ProxyAddr
supportedProtocols = @("TCP", "UDP")
})
excludes = @()
}
$cfg | ConvertTo-Json -Depth 5 | Set-Content $ConfigPath -Encoding UTF8
# Служба
Write-Step "Перезапуск службы..."
if (Get-DebugMode) {
& "$InstallPath\ProxiFyre.exe" stop
& "$InstallPath\ProxiFyre.exe" install
& "$InstallPath\ProxiFyre.exe" start
}
else {
& "$InstallPath\ProxiFyre.exe" stop 2>&1 | Out-Null
& "$InstallPath\ProxiFyre.exe" install 2>&1 | Out-Null
& "$InstallPath\ProxiFyre.exe" start 2>&1 | Out-Null
}
Write-Success "Готово! Discord должен работать через прокси."
}
function Select-Apps {
Write-Host "`n🎮 Какие приложения проксировать?" -ForegroundColor Yellow
$appOpts = [Ordered]@{
"1" = "Discord"
"2" = "Vesktop"
"3" = "Discord + Vesktop"
}
$appChoice = Show-Menu -Options $appOpts
$result = switch ($appChoice) {
"1" { @("Discord") }
"2" { @("Vesktop") }
"3" { @("Vesktop", "Discord") }
default { @("Discord") }
}
return $result
}
function Get-ProxyAddress {
# Проверяем локальный sing-box
$singboxStatus = Get-TaskStatus -Name "SingBoxProxy"
$localProxy = "127.0.0.1:1080"
if ($singboxStatus -eq "Running") {
Write-Info "Обнаружен работающий VPN клиент (Sing-box)."
Write-Host " Рекомендуется использовать локальный прокси: " -NoNewline -ForegroundColor Gray
Write-Host $localProxy -ForegroundColor Green
$useLocal = Read-Host " Использовать локальный? (y/n) [y]"
if ($useLocal -ne 'n') {
return $localProxy
}
}
else {
Write-Warning "VPN клиент не запущен!"
Write-Host " Вы можете указать адрес удалённого прокси." -ForegroundColor Gray
}
# Запрашиваем адрес
while ($true) {
$proxyAddr = Read-Host "`n Введите адрес прокси (IP:порт)"
if ([string]::IsNullOrWhiteSpace($proxyAddr)) {
Write-Warning "Адрес не указан"
continue
}
if ($proxyAddr -notmatch "^[\d\.]+:\d+$") {
Write-Error "Неверный формат. Ожидается: IP:порт (например 192.168.1.100:1080)"
continue
}
# Проверяем подключение
if (Test-ProxyConnection -ProxyAddr $proxyAddr) {
return $proxyAddr
}
$retry = Read-Host " Попробовать другой адрес? (y/n)"
if ($retry -ne 'y') { return $null }
}
}
# --- MAIN ---
$isInstalled = Test-Path "$InstallPath\ProxiFyre.exe"
$discSvc = Get-Service -Name "ProxiFyreService" -ErrorAction SilentlyContinue
$currentConfig = Get-CurrentConfig
if ($isInstalled -and $currentConfig -and -not $Force) {
# Уже установлено — показываем меню управления
Write-Info "ProxiFyre уже установлен."
Write-Host ""
Write-Host " Статус: " -NoNewline -ForegroundColor Gray
if ($discSvc.Status -eq 'Running') {
Write-Host "АКТИВЕН" -ForegroundColor Green
}
else {
Write-Host "ОСТАНОВЛЕН" -ForegroundColor Yellow
}
Write-Host " Приложения: $($currentConfig.Apps)" -ForegroundColor Gray
Write-Host " Прокси: $($currentConfig.Proxy)" -ForegroundColor Gray
Write-Host ""
$opts = [Ordered]@{
"1" = "Изменить настройки (приложения/прокси)"
"2" = "Проверить подключение к прокси"
"3" = "Перезапустить службу"
"4" = "Остановить службу"
"5" = "Переустановить"
"b" = "Назад"
}
$action = Show-Menu -Options $opts
switch ($action) {
"1" {
$targetApps = Select-Apps
$proxyAddr = Get-ProxyAddress
if ($proxyAddr) {
Configure-And-Start -TargetApps $targetApps -ProxyAddr $proxyAddr
}
}
"2" {
Test-ProxyConnection -ProxyAddr $currentConfig.Proxy | Out-Null
}
"3" {
Write-Step "Перезапуск службы..."
Start-Process "$InstallPath\ProxiFyre.exe" -ArgumentList "stop" -Wait -NoNewWindow
Start-Process "$InstallPath\ProxiFyre.exe" -ArgumentList "start" -Wait -NoNewWindow
Write-Success "Перезапущено!"
}
"4" {
Start-Process "$InstallPath\ProxiFyre.exe" -ArgumentList "stop" -Wait -NoNewWindow
Write-Success "Остановлено!"
}
"5" {
$Force = $true
}
"b" { exit }
}
if (-not $Force) {
Start-Sleep -Seconds 2
exit
}
}
# --- НОВАЯ УСТАНОВКА ---
if (-not $isInstalled -or $Force) {
Install-ProxiFyre
}
$targetApps = Select-Apps
$proxyAddr = Get-ProxyAddress
if (-not $proxyAddr) {
Write-Error "Прокси не настроен. Выход."
Start-Sleep -Seconds 2
exit
}
Configure-And-Start -TargetApps $targetApps -ProxyAddr $proxyAddr
Start-Sleep -Seconds 3