feat: Реализована нативная установка sing-box с системными утилитами и веб-сервером, заменяя устаревшие скрипты.

This commit is contained in:
2025-12-29 13:24:11 +03:00
parent a837072454
commit f04d04fa61
12 changed files with 1049 additions and 1320 deletions

59
scripts/lib/Common.ps1 Normal file
View File

@@ -0,0 +1,59 @@
# ==========================================
# 🛠️ COMMON UTILS
# ==========================================
# --- ЦВЕТА И ВЫВОД ---
function Write-Step { param($msg) Write-Host "`n📦 $msg" -ForegroundColor Cyan }
function Write-Success { param($msg) Write-Host "$msg" -ForegroundColor Green }
function Write-Warning { param($msg) Write-Host " ⚠️ $msg" -ForegroundColor Yellow }
function Write-Error { param($msg) Write-Host "$msg" -ForegroundColor Red }
function Write-Info { param($msg) Write-Host " $msg" -ForegroundColor Gray }
function Write-Header {
param($Title)
Write-Host ""
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host " $Title" -ForegroundColor Cyan
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host ""
}
# --- ПОЛЕЗНЫЕ ФУНКЦИИ ---
function Get-ScriptDirectory {
if ($PSScriptRoot) { return $PSScriptRoot }
return Split-Path -Parent $MyInvocation.MyCommand.Path
}
function Ensure-Admin {
$isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
if (-not $isAdmin) {
Write-Host "⛔ Требуются права АДМИНИСТРАТОРА!" -ForegroundColor Red
Write-Host " Пожалуйста, запустите скрипт от имени администратора." -ForegroundColor Gray
Start-Sleep -Seconds 3
exit 1
}
}
function Show-Menu {
param(
[string]$Title,
[System.Collections.Specialized.OrderedDictionary]$Options,
[string]$Prompt = "👉 Ваш выбор"
)
if ($Title) {
Write-Host "`n$Title" -ForegroundColor Yellow
}
$keys = $Options.Keys
foreach ($key in $keys) {
Write-Host " [$key] $($Options[$key])" -ForegroundColor White
}
Write-Host ""
return Read-Host "$Prompt"
}

140
scripts/lib/Net.ps1 Normal file
View File

@@ -0,0 +1,140 @@
# ==========================================
# 🌐 NET UTILS
# ==========================================
# --- CONFIG ---
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# --- ФУНКЦИИ ---
$script:HwidFile = "C:\Tools\sing-box\hwid"
$script:AppName = "VPN-Proxy-Control by Dokril"
function Get-HWID {
# Генерация или чтение HWID из файла
if (Test-Path $script:HwidFile) {
return (Get-Content $script:HwidFile -Raw).Trim()
}
# Генерируем новый HWID
$hwid = [Guid]::NewGuid().ToString("N").Substring(0, 16)
# Сохраняем
$dir = Split-Path $script:HwidFile -Parent
if (!(Test-Path $dir)) { New-Item -ItemType Directory -Path $dir -Force | Out-Null }
Set-Content -Path $script:HwidFile -Value $hwid
return $hwid
}
function Get-SubscriptionHeaders {
# Формируем заголовки как в server.py
$osName = "windows"
$osVersion = [Environment]::OSVersion.Version.ToString()
return @{
"User-Agent" = "singbox"
"x-hwid" = (Get-HWID)
"x-device-os" = $osName
"x-ver-os" = $osVersion
"x-device-model" = $script:AppName
}
}
function Download-File {
param(
[string]$Url,
[string]$Destination,
[string]$UserAgent = "VPN-Proxy-Installer"
)
try {
$req = [System.Net.HttpWebRequest]::Create($Url)
$req.UserAgent = $UserAgent
$resp = $req.GetResponse()
$stream = $resp.GetResponseStream()
$fs = [System.IO.File]::Create($Destination)
$msgLen = $resp.ContentLength
$buffer = New-Object byte[] 10240
$count = 0
$total = 0
do {
$count = $stream.Read($buffer, 0, $buffer.Length)
$fs.Write($buffer, 0, $count)
$total += $count
# Можно добавить прогресс бар, но пока просто качаем
} while ($count -gt 0)
$fs.Close()
$stream.Close()
$resp.Close()
return $true
}
catch {
Write-Error "Ошибка скачивания: $_"
return $false
}
}
function Get-SubscriptionData {
param(
[string]$Url,
[string]$UserAgent = "singbox",
$Headers = @{}
)
Write-Info "Загружаю подписку..."
$rawContent = $null
$userInfo = @{}
# 1. Получаем ответ
try {
$response = Invoke-WebRequest -Uri $Url -Headers $Headers -TimeoutSec 15 -UseBasicParsing
$rawContent = $response.Content
# Парсим subscription-userinfo header
$userInfoHeader = $response.Headers["subscription-userinfo"]
if ($userInfoHeader) {
$parts = $userInfoHeader -split ";"
foreach ($part in $parts) {
if ($part -match "(\w+)=(\d+)") {
$userInfo[$matches[1]] = [int64]$matches[2]
}
}
}
}
catch {
return @{
success = $false
error = "Ошибка загрузки: $($_.Exception.Message)"
rawContent = $null
}
}
# 2. Пробуем парсить как JSON
try {
$config = $rawContent | ConvertFrom-Json
return @{
success = $true
config = $config
rawContent = $rawContent
userInfo = $userInfo
}
}
catch {
# JSON не распарсился — возвращаем rawContent для дальнейшей обработки
return @{
success = $false
error = "Ответ не в формате JSON (возможно Base64 или список ссылок)"
rawContent = $rawContent
userInfo = $userInfo
}
}
}

156
scripts/lib/System.ps1 Normal file
View File

@@ -0,0 +1,156 @@
# ==========================================
# 🖥️ SYSTEM UTILS
# ==========================================
# --- СИСТЕМНАЯ ИНФОРМАЦИЯ ---
function Get-HWID {
param([string]$StoreDir)
$hwidFile = "$StoreDir\hwid"
if (Test-Path $hwidFile) {
return (Get-Content $hwidFile -Raw).Trim()
}
$hwid = [System.Guid]::NewGuid().ToString("N").Substring(0, 16)
if (!(Test-Path $StoreDir)) {
New-Item -ItemType Directory -Path $StoreDir -Force | Out-Null
}
Set-Content -Path $hwidFile -Value $hwid
return $hwid
}
function Get-SystemInfo {
return @{
os = "windows"
version = [System.Environment]::OSVersion.Version.Major.ToString()
}
}
# --- DOCKER ---
function Test-Docker {
$status = @{
Installed = $false
Running = $false
Compose = $false
}
try {
$ver = docker --version 2>&1
if ($LASTEXITCODE -eq 0) { $status.Installed = $true }
}
catch {}
if ($status.Installed) {
try {
$info = docker info 2>&1
if ($LASTEXITCODE -eq 0) { $status.Running = $true }
}
catch {}
}
if ($status.Running) {
try {
$comp = docker compose version 2>&1
if ($LASTEXITCODE -eq 0) { $status.Compose = $true }
}
catch {
# Check legacy
try {
$comp = docker-compose --version 2>&1
if ($LASTEXITCODE -eq 0) { $status.Compose = $true }
}
catch {}
}
}
return $status
}
# --- СЛУЖБЫ И ЗАДАЧИ ---
function Manage-ScheduledTask {
param(
[string]$Name,
[string]$ExePath,
[string]$Arguments,
[string]$WorkDir,
[string]$Action = "Install" # Install, Uninstall, Start, Stop
)
switch ($Action) {
"Install" {
# Удаляем старую
Unregister-ScheduledTask -TaskName $Name -Confirm:$false -ErrorAction SilentlyContinue
$act = New-ScheduledTaskAction -Execute "$ExePath" -Argument "$Arguments" -WorkingDirectory $WorkDir
$trig = New-ScheduledTaskTrigger -AtStartup
$princ = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount -RunLevel Highest
$sett = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable -RestartCount 3 -RestartInterval (New-TimeSpan -Minutes 1)
Register-ScheduledTask -TaskName $Name -Action $act -Trigger $trig -Principal $princ -Settings $sett -Force | Out-Null
return $true
}
"Uninstall" {
Unregister-ScheduledTask -TaskName $Name -Confirm:$false -ErrorAction SilentlyContinue
}
"Start" {
Start-ScheduledTask -TaskName $Name -ErrorAction SilentlyContinue
}
"Stop" {
Stop-ScheduledTask -TaskName $Name -ErrorAction SilentlyContinue
# Пытаемся убить процесс по имени exe
if ($ExePath) {
$procName = [System.IO.Path]::GetFileNameWithoutExtension($ExePath)
if ($procName) {
Stop-Process -Name $procName -Force -ErrorAction SilentlyContinue
}
}
}
}
}
function Get-TaskStatus {
param([string]$Name)
$task = Get-ScheduledTask -TaskName $Name -ErrorAction SilentlyContinue
if ($task) {
# Если задача в статусе Running — возвращаем Running
if ($task.State -eq "Running") {
return "Running"
}
# Если задача Ready — проверяем, работает ли процесс sing-box
# (scheduled task может быть Ready даже когда процесс работает)
$process = Get-Process -Name "sing-box" -ErrorAction SilentlyContinue
if ($process) {
return "Running"
}
return $task.State
}
return $null
}
function Ensure-FirewallPort {
param(
[int]$Port,
[string]$Name,
[string]$Protocol = "TCP"
)
$rule = Get-NetFirewallRule -DisplayName $Name -ErrorAction SilentlyContinue
if (-not $rule) {
New-NetFirewallRule -DisplayName $Name -Direction Inbound -LocalPort $Port -Protocol $Protocol -Action Allow -Profile Any | Out-Null
return $true
}
return $false
}
function Get-LocalIPs {
return (Get-NetIPAddress -AddressFamily IPv4 -InterfaceAlias * | Where-Object { $_.IPAddress -notmatch "^127\." -and $_.IPAddress -notmatch "^169\.254\." }).IPAddress
}

100
scripts/setup-discord.ps1 Normal file
View File

@@ -0,0 +1,100 @@
# ==========================================
# 🎮 DISCORD PROXY SETUP
# ==========================================
param([switch]$Force)
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
. "$ScriptDir\lib\Common.ps1"
. "$ScriptDir\lib\Net.ps1"
. "$ScriptDir\lib\System.ps1"
Write-Header "НАСТРОЙКА DISCORD / VESKTOP"
Ensure-Admin
$InstallPath = "C:\Tools\ProxiFyre"
$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"
# Проверка Sing-box
$singboxStatus = Get-TaskStatus -Name "SingBoxProxy"
$localProxy = "127.0.0.1:1080"
$useLocal = $false
if ($singboxStatus -eq "Running") {
Write-Info "Обнаружен работающий Native Sing-box."
$useLocal = $true
}
else {
Write-Warning "Native Sing-box не запущен!"
Write-Host " Для работы голосовых звонков он необходим." -ForegroundColor Gray
Write-Host " Вы можете вернуться в главное меню и настроить его." -ForegroundColor Gray
if ((Read-Host " Продолжить настройку БЕЗ него (голос может не работать)? (y/n)") -ne 'y') { exit }
}
# Меню выбора приложений
Write-Host "`n🎮 Какие приложения проксировать?" -ForegroundColor Yellow
$appOpts = [Ordered]@{
"1" = "Discord"
"2" = "Vesktop"
"3" = "Discord + Vesktop"
}
$appChoice = Show-Menu -Options $appOpts
$targetApps = switch ($appChoice) {
"1" { @("Discord") }
"2" { @("Vesktop") }
"3" { @("Vesktop", "Discord") }
default { @("Discord") }
}
$proxyAddr = $localProxy
if (!$useLocal) {
$proxyAddr = Read-Host "Введите адрес прокси (хост:порт) [Enter для $localProxy]"
if ([string]::IsNullOrWhiteSpace($proxyAddr)) { $proxyAddr = $localProxy }
}
# Установка драйвера
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..."
if (!(Test-Path $InstallPath) -or $Force) {
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
# Handle update folder structure if needed, simplified here assuming flat or check generic
$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 "Распаковано"
}
}
# Конфиг
$cfg = @{
logLevel = "Info"
proxies = @(@{
appNames = $targetApps
socks5ProxyEndpoint = $proxyAddr
supportedProtocols = @("TCP", "UDP")
})
excludes = @()
}
$cfg | ConvertTo-Json -Depth 5 | Set-Content "$InstallPath\app-config.json" -Encoding UTF8
# Служба
Write-Step "Перезапуск службы..."
Start-Process "$InstallPath\ProxiFyre.exe" -ArgumentList "stop" -Wait -NoNewWindow
Start-Process "$InstallPath\ProxiFyre.exe" -ArgumentList "install" -Wait -NoNewWindow
Start-Process "$InstallPath\ProxiFyre.exe" -ArgumentList "start" -Wait -NoNewWindow
Write-Success "Готово! Discord должен работать через прокси."
Start-Sleep -Seconds 3

414
scripts/setup-singbox.ps1 Normal file
View File

@@ -0,0 +1,414 @@
# ==========================================
# 📦 SING-BOX NATIVE INSTALLER
# ==========================================
param(
[switch]$Force,
[string]$SubscriptionUrl = ""
)
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
. "$ScriptDir\lib\Common.ps1"
. "$ScriptDir\lib\Net.ps1"
. "$ScriptDir\lib\System.ps1"
# --- CONFIG ---
$SingboxVersion = "1.11.4"
$InstallDir = "C:\Tools\sing-box"
$LocalProxyPort = 1080
$SingboxUrl = "https://github.com/SagerNet/sing-box/releases/download/v$SingboxVersion/sing-box-$SingboxVersion-windows-amd64.zip"
$TaskName = "SingBoxProxy"
Ensure-Admin
# --- LOGIC ---
function Select-Server {
param($Config)
$outbounds = $Config.outbounds
$servers = @()
foreach ($outbound in $outbounds) {
if ($outbound.type -in @("vless", "vmess", "trojan", "shadowsocks", "hysteria2")) {
$servers += @{
tag = $outbound.tag
type = $outbound.type
server = $outbound.server
server_port = $outbound.server_port
outbound = $outbound
}
}
}
if ($servers.Count -eq 0) {
Write-Error "Серверы не найдены в подписке!"
return $null
}
$options = [Ordered]@{}
for ($i = 0; $i -lt $servers.Count; $i++) {
$s = $servers[$i]
$options["$($i+1)"] = "$($s.tag) ($($s.server):$($s.server_port))"
}
$choice = Show-Menu -Title "🌐 Доступные серверы" -Options $options -Prompt "👉 Выберите сервер (номер)"
$index = [int]$choice - 1
if ($index -lt 0 -or $index -ge $servers.Count) {
Write-Error "Неверный выбор!"
return $null
}
return $servers[$index]
}
function New-SingboxConfig {
param($Outbound, $Port)
return @{
log = @{ level = "info"; timestamp = $true }
dns = @{ independent_cache = $true }
inbounds = @(
@{
type = "socks"
tag = "socks-in"
listen = "0.0.0.0"
listen_port = $Port
}
)
outbounds = @(
$Outbound,
@{ type = "direct"; tag = "direct" }
)
route = @{
final = $Outbound.tag
auto_detect_interface = $true
}
}
}
function Parse-VlessUrl {
param([string]$Url)
if (-not $Url.StartsWith("vless://")) { throw "URL должен начинаться с vless://" }
# Remove scheme
$raw = $Url.Substring(8)
# Split fragment
$tag = "reality"
if ($raw -match "#(.*)$") {
$tag = [System.Web.HttpUtility]::UrlDecode($matches[1])
$raw = $raw -replace "#.*$", ""
}
# Split query
$queryStr = ""
if ($raw -match "\?(.*)$") {
$queryStr = $matches[1]
$raw = $raw -replace "\?.*$", ""
}
# Parse UUID@HOST:PORT
if ($raw -notmatch "([^@]+)@([^:]+):(\d+)") { throw "Неверный формат vless (ожидается uuid@host:port)" }
$uuid = $matches[1][0]
$serverHost = $matches[2][0]
$port = [int]$matches[3][0] # Fix for regex object access in PS
if (-not $uuid) {
# Fallback if regex returns match info differently in different PS versions
$uuid = $matches[1]
$serverHost = $matches[2]
$port = [int]$matches[3]
}
# Parse Query
$params = @{}
if ($queryStr) {
$parts = $queryStr -split "&"
foreach ($p in $parts) {
$kv = $p -split "="
if ($kv.Count -eq 2) {
$params[[System.Web.HttpUtility]::UrlDecode($kv[0])] = [System.Web.HttpUtility]::UrlDecode($kv[1])
}
}
}
# Extract
$pbk = if ($params["pbk"]) { $params["pbk"] } else { throw "Отсутствует параметр pbk (Public Key)" }
$sid = if ($params["sid"]) { $params["sid"] } else { throw "Отсутствует параметр sid (Short ID)" }
$sni = if ($params["sni"]) { $params["sni"] } else { $serverHost }
$fp = if ($params["fp"]) { $params["fp"] } else { "chrome" }
$flow = if ($params["flow"]) { $params["flow"] } else { "" }
return @{
uuid = $uuid
server = $serverHost
server_port = $port
tag = $tag
public_key = $pbk
short_id = $sid
server_name = $sni
fingerprint = $fp
flow = $flow
}
}
# --- MAIN ---
Write-Header "NATIVE SING-BOX (UDP ПОДДЕРЖКА)"
$taskStatus = Get-TaskStatus -Name $TaskName
if ($taskStatus -and -not $Force) {
Write-Info "Sing-box уже установлен."
Write-Host " Статус: $taskStatus" -ForegroundColor ($taskStatus -eq "Running" ? "Green" : "Red")
Write-Host ""
$opts = [Ordered]@{
"1" = "Сменить сервер (из подписки)"
"2" = "Ввести новую ссылку на подписку"
"3" = "Перезапустить службу"
"4" = "Остановить службу"
"5" = "Показать конфиг"
"6" = "Переустановить"
"b" = "Назад"
}
$act = Show-Menu -Options $opts
switch ($act) {
"1" {
# Reload existing sub logic could be added here, currently just re-runs install flow partially
# Simplification: treat as new setup but try to load saved sub url
$Force = $true
}
"2" { $SubscriptionUrl = ""; $Force = $true }
"3" { Manage-ScheduledTask -Name $TaskName -Action "Start"; Write-Success "Запущено!"; exit }
"4" { Manage-ScheduledTask -Name $TaskName -Action "Stop"; Write-Success "Остановлено!"; exit }
"5" { Get-Content "$InstallDir\config.json"; exit }
"6" { $Force = $true }
"b" { exit }
}
}
if ($Force -or -not $taskStatus) {
# 1. Загрузка
Write-Step "Установка Sing-box..."
if (!(Test-Path "$InstallDir\sing-box.exe")) {
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
$zipCtx = "$env:TEMP\sing-box.zip"
if (Download-File -Url $SingboxUrl -Destination $zipCtx) {
Expand-Archive -Path $zipCtx -DestinationPath $env:TEMP -Force
$extracted = Get-ChildItem "$env:TEMP\sing-box-*" -Directory | Select -First 1
Copy-Item "$($extracted.FullName)\sing-box.exe" "$InstallDir\sing-box.exe" -Force
Remove-Item $zipCtx; Remove-Item $extracted.FullName -Recurse -Force
Write-Success "Sing-box скачан"
}
else {
Read-Host "Нажмите Enter для выхода..."
exit 1
}
}
# 2. Подписка
if ([string]::IsNullOrWhiteSpace($SubscriptionUrl)) {
# Try load saved
$savedSub = "$InstallDir\sub_info.json"
if (Test-Path $savedSub) {
try {
$json = Get-Content $savedSub -Raw | ConvertFrom-Json
if ($json.url) {
Write-Info "Найдена сохраненная подписка: $($json.url)"
if ((Read-Host "Использовать? (y/n)") -eq 'y') { $SubscriptionUrl = $json.url }
}
}
catch {}
}
}
if ([string]::IsNullOrWhiteSpace($SubscriptionUrl)) {
$SubscriptionUrl = Read-Host "`n🔗 Введите URL подписки (VLESS)"
}
if ([string]::IsNullOrWhiteSpace($SubscriptionUrl)) {
Write-Error "Url не указан"
Read-Host "Нажмите Enter для выхода..."
exit
}
# --- PARSING ---
$data = @{ success = $false; config = $null; error = "" }
if ($SubscriptionUrl.StartsWith("vless://")) {
try {
$p = Parse-VlessUrl -Url $SubscriptionUrl
$outbound = [Ordered]@{
type = "vless"
tag = $p.tag
server = $p.server
server_port = $p.server_port
uuid = $p.uuid
flow = $p.flow
tls = @{
enabled = $true
server_name = $p.server_name
utls = @{ enabled = $true; fingerprint = $p.fingerprint }
reality = @{
enabled = $true
public_key = $p.public_key
short_id = $p.short_id
}
}
packet_encoding = "xudp"
}
$data.success = $true
$data.config = @{ outbounds = @($outbound) }
}
catch {
$data.error = $_.Exception.Message
}
}
else {
$data = Get-SubscriptionData -Url $SubscriptionUrl -Headers (Get-SubscriptionHeaders)
}
# --- PARSING LOGIC ENHANCEMENT ---
if (-not $data.success) {
# Fallback: Try to handle non-JSON body (Base64 or Plain Text)
try {
Write-Info "JSON парсинг не удался, пробую как список ссылок..."
$content = $data.rawContent
# Base64 decode if needed
if ($content -match "^[A-Za-z0-9+/=]+$") {
try {
$bytes = [System.Convert]::FromBase64String($content)
$content = [System.Text.Encoding]::UTF8.GetString($bytes)
}
catch {}
}
# Try to find vless:// links
$links = $content -split "[\r\n]+" | Where-Object { $_ -match "^vless://" }
if ($links.Count -gt 0) {
Write-Success "Найдено ссылок: $($links.Count)"
# Mock a config object with these links as "outbounds"
# Note: We can't fully parsing VLESS query params in pure PS easily without a lot of regex
# So we will try a simpler approach: Let sing-box do it? No, sing-box needs config.
# WORKAROUND: Create a minimal outbound for each link
# Parsing `vless://UUID@HOST:PORT?security=reality&...#NAME`
$parsedOutbounds = @()
foreach ($link in $links) {
if ($link -match "vless://([^@]+)@([^:]+):(\d+)(\?.*)?(#.*)?") {
$uuid = $matches[1]
$server = $matches[2]
$port = [int]$matches[3]
$query = $matches[4]
$hash = $matches[5]
$tag = if ($hash) { $hash.Substring(1) } else { "${server}:${port}" }
$tag = [System.Web.HttpUtility]::UrlDecode($tag)
# Parse Query Params
$flow = ""; $fp = ""; $pbk = ""; $sid = ""; $sni = ""; $serviceName = ""
if ($query) {
if ($query -match "flow=([^&]+)") { $flow = $matches[1] }
if ($query -match "fp=([^&]+)") { $fp = $matches[1] }
if ($query -match "pbk=([^&]+)") { $pbk = $matches[1] }
if ($query -match "sid=([^&]+)") { $sid = $matches[1] }
if ($query -match "sni=([^&]+)") { $sni = $matches[1] }
if ($query -match "serviceName=([^&]+)") { $serviceName = $matches[1] }
}
# Construct Sing-box outbound (REALITY based assumption for modern vless)
$out = [Ordered]@{
type = "vless"
tag = $tag
server = $server
server_port = $port
uuid = $uuid
flow = $flow
tls = @{
enabled = $true
server_name = $sni
utls = @{ enabled = $true; fingerprint = $fp }
reality = @{
enabled = $true
public_key = $pbk
short_id = $sid
}
}
packet_encoding = "xudp"
}
$parsedOutbounds += $out
}
}
if ($parsedOutbounds.Count -gt 0) {
$data.success = $true
$data.config = @{ outbounds = $parsedOutbounds }
$data.error = $null
}
else {
throw "Не удалось распарсить VLESS ссылки"
}
}
else {
throw $data.error
}
}
catch {
Write-Error "Ошибка обработки подписки: $_"
Write-Host " Скрипт поддерживает: SIP008 (JSON) или список VLESS+Reality ссылок." -ForegroundColor Yellow
Read-Host "Нажмите Enter для выхода..."
exit
}
}
# Save sub info
@{ url = $SubscriptionUrl } | ConvertTo-Json | Set-Content "$InstallDir\sub_info.json"
# 3. Выбор сервера
$server = Select-Server -Config $data.config
if (!$server) {
Read-Host "Нажмите Enter для выхода..."
exit
}
# 4. Конфиг
$cfg = New-SingboxConfig -Outbound $server.outbound -Port $LocalProxyPort
$cfg | ConvertTo-Json -Depth 10 | Set-Content "$InstallDir\config.json" -Encoding UTF8
# 5. Задача
Manage-ScheduledTask -Name $TaskName -ExePath "$InstallDir\sing-box.exe" -Arguments "run -c `"$InstallDir\config.json`"" -WorkDir $InstallDir -Action "Install"
Manage-ScheduledTask -Name $TaskName -Action "Start"
# 6. Firewall
if (Ensure-FirewallPort -Port $LocalProxyPort -Name "SingBox-Proxy-Port") {
Write-Success "Правило Firewall создано (порт $LocalProxyPort)"
}
Write-Success "Успешно установлено и запущено!"
Write-Info "Локальный прокси: 127.0.0.1:$LocalProxyPort"
$ips = Get-LocalIPs
if ($ips) {
Write-Info "Доступно из сети по адресам:"
foreach ($ip in $ips) {
Write-Host " ${ip}:$LocalProxyPort" -ForegroundColor Gray
}
}
Start-Sleep -Seconds 3
}

48
scripts/uninstall-all.ps1 Normal file
View File

@@ -0,0 +1,48 @@
# ==========================================
# 🗑️ UNINSTALL ALL (CLEANUP)
# ==========================================
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
. "$ScriptDir\lib\Common.ps1"
. "$ScriptDir\lib\System.ps1"
Write-Header "ПОЛНОЕ УДАЛЕНИЕ"
Ensure-Admin
Write-Warning "Это действие удалит весь установленный софт:"
Write-Host " - Sing-box (Служба и файлы)" -ForegroundColor Gray
Write-Host " - ProxiFyre (Служба и файлы)" -ForegroundColor Gray
Write-Host " - Драйвер WinPacketFilter" -ForegroundColor Gray
Write-Host ""
if ((Read-Host "Вы уверены? (y/n)") -ne 'y') { exit }
Write-Step "Удаление Sing-box..."
Manage-ScheduledTask -Name "SingBoxProxy" -Action "Stop"
Manage-ScheduledTask -Name "SingBoxProxy" -Action "Uninstall"
if (Test-Path "C:\Tools\sing-box") {
Remove-Item "C:\Tools\sing-box" -Recurse -Force -ErrorAction SilentlyContinue
Write-Success "Файлы удалены"
}
Write-Step "Удаление Discrod Proxy (ProxiFyre)..."
$pfDir = "C:\Tools\ProxiFyre"
if (Test-Path "$pfDir\ProxiFyre.exe") {
Start-Process "$pfDir\ProxiFyre.exe" -ArgumentList "uninstall" -Wait -NoNewWindow
Start-Sleep -Seconds 2
}
if (Test-Path $pfDir) {
Remove-Item $pfDir -Recurse -Force -ErrorAction SilentlyContinue
Write-Success "Файлы удалены"
}
Write-Step "Удаление драйвера..."
# Тут сложно удалить MSI тихо без GUID, но попробуем через known path или пропустим, т.к. драйвер может быть нужен другим
Write-Info "Драйвер WinPacketFilter оставлен (он может использоваться другим ПО)."
Write-Info "Если нужно, удалите его через 'Установка и удаление программ'."
Write-Success "Очистка завершена!"
Start-Sleep -Seconds 3