-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenable.ps1
More file actions
107 lines (96 loc) · 4.69 KB
/
enable.ps1
File metadata and controls
107 lines (96 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# evo-tls-proxy - Enable Script
# Requires: Run as Administrator
# Actions: Generate certs, modify hosts file, set NODE_EXTRA_CA_CERTS, start TLS proxy
param(
[switch]$SkipHosts,
[switch]$SkipProxy
)
$ErrorActionPreference = "Stop"
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$CertsDir = Join-Path $ScriptDir "certs"
$CaCrtPath = Join-Path $CertsDir "ca.crt"
$HostsFile = "C:\Windows\System32\drivers\etc\hosts"
$HostsMarker = "# EvoRouter-TLS-Proxy"
$TargetEntry = "127.0.0.1 api.anthropic.com $HostsMarker"
# ── Check Admin ──
$isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isAdmin) {
Write-Host "[evo-tls-proxy] Requesting Administrator privileges..." -ForegroundColor Yellow
Start-Process PowerShell -ArgumentList "-ExecutionPolicy Bypass -File `"$($MyInvocation.MyCommand.Path)`"" -Verb RunAs
exit
}
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " EvoRouter TLS Proxy - ENABLE" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# ── Step 1: Generate certs if needed ──
if (-not (Test-Path (Join-Path $CertsDir "server.crt"))) {
Write-Host "[Step 1] Generating certificates..." -ForegroundColor Yellow
& node (Join-Path $ScriptDir "generate-cert.js")
if ($LASTEXITCODE -ne 0) {
Write-Host "[ERROR] Certificate generation failed." -ForegroundColor Red
Read-Host "Press Enter to exit"
exit 1
}
} else {
Write-Host "[Step 1] Certificates already exist, skipping." -ForegroundColor Green
}
# ── Step 2: Modify hosts file ──
if (-not $SkipHosts) {
Write-Host "[Step 2] Modifying hosts file..." -ForegroundColor Yellow
$hostsContent = Get-Content $HostsFile -Raw -ErrorAction SilentlyContinue
if ($hostsContent -match [regex]::Escape($HostsMarker)) {
Write-Host " -> hosts entry already exists, skipping." -ForegroundColor Green
} else {
# Backup
$backupPath = Join-Path $ScriptDir "hosts.bak"
Copy-Item $HostsFile $backupPath -Force
Write-Host " -> Backed up hosts to: $backupPath" -ForegroundColor Gray
# Append entry
Add-Content -Path $HostsFile -Value "`n$TargetEntry" -Encoding ASCII
Write-Host " -> Added: $TargetEntry" -ForegroundColor Green
}
# Flush DNS
ipconfig /flushdns | Out-Null
Write-Host " -> DNS cache flushed." -ForegroundColor Gray
} else {
Write-Host "[Step 2] Skipped hosts modification (--SkipHosts)." -ForegroundColor Gray
}
# ── Step 3: Set NODE_EXTRA_CA_CERTS ──
Write-Host "[Step 3] Setting NODE_EXTRA_CA_CERTS environment variable..." -ForegroundColor Yellow
$currentVal = [Environment]::GetEnvironmentVariable("NODE_EXTRA_CA_CERTS", "User")
if ($currentVal -eq $CaCrtPath) {
Write-Host " -> Already set correctly, skipping." -ForegroundColor Green
} else {
if ($currentVal) {
Write-Host " -> Warning: NODE_EXTRA_CA_CERTS was set to: $currentVal" -ForegroundColor Yellow
Write-Host " -> Previous value saved to: NODE_EXTRA_CA_CERTS_BACKUP" -ForegroundColor Yellow
[Environment]::SetEnvironmentVariable("NODE_EXTRA_CA_CERTS_BACKUP", $currentVal, "User")
}
[Environment]::SetEnvironmentVariable("NODE_EXTRA_CA_CERTS", $CaCrtPath, "User")
$env:NODE_EXTRA_CA_CERTS = $CaCrtPath
Write-Host " -> Set NODE_EXTRA_CA_CERTS = $CaCrtPath" -ForegroundColor Green
}
# ── Step 4: Start TLS Proxy ──
if (-not $SkipProxy) {
Write-Host "[Step 4] Proxy auto-start skipped by design." -ForegroundColor Yellow
Write-Host " -> Run start-proxy-visible.bat manually to launch the proxy in Windows Terminal." -ForegroundColor Green
} else {
Write-Host "[Step 4] Skipped proxy start (--SkipProxy)." -ForegroundColor Gray
}
# ── Done ──
Write-Host ""
Write-Host "========================================" -ForegroundColor Green
Write-Host " ENABLED SUCCESSFULLY" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Green
Write-Host ""
Write-Host " Checklist:" -ForegroundColor White
Write-Host " [1] Remove ANTHROPIC_BASE_URL from your environment (if set)" -ForegroundColor Yellow
Write-Host " [2] Restart Claude Code / any terminal that uses it" -ForegroundColor Yellow
Write-Host " [3] Run start-proxy-visible.bat to start the TLS proxy" -ForegroundColor Yellow
Write-Host " [4] EvoRouter must be running on port 4010" -ForegroundColor Yellow
Write-Host ""
Write-Host " To disable: run disable.bat or disable.ps1" -ForegroundColor Gray
Write-Host ""
Read-Host "Press Enter to close"