# ========================================== # 🌐 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() # Unblock file to prevent "Mark of the Web" issues Unblock-File -Path $Destination -ErrorAction SilentlyContinue 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 } } }