feat: Major directory reorganization and cleanup
Reorganized project structure for better maintainability and reduced disk usage by 95.9% (11 GB -> 451 MB). Directory Reorganization (85% reduction in root files): - Created docs/ with subdirectories (deployment, testing, database, etc.) - Created infrastructure/vpn-configs/ for VPN scripts - Moved 90+ files from root to organized locations - Archived obsolete documentation (context system, offline mode, zombie debugging) - Moved all test files to tests/ directory - Root directory: 119 files -> 18 files Disk Cleanup (10.55 GB recovered): - Deleted Rust build artifacts: 9.6 GB (target/ directories) - Deleted Python virtual environments: 161 MB (venv/ directories) - Deleted Python cache: 50 KB (__pycache__/) New Structure: - docs/ - All documentation organized by category - docs/archives/ - Obsolete but preserved documentation - infrastructure/ - VPN configs and SSH setup - tests/ - All test files consolidated - logs/ - Ready for future logs Benefits: - Cleaner root directory (18 vs 119 files) - Logical organization of documentation - 95.9% disk space reduction - Faster navigation and discovery - Better portability (build artifacts excluded) Build artifacts can be regenerated: - Rust: cargo build --release (5-15 min per project) - Python: pip install -r requirements.txt (2-3 min) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
121
infrastructure/vpn-configs/Setup/Install-PST-VPN.ps1
Normal file
121
infrastructure/vpn-configs/Setup/Install-PST-VPN.ps1
Normal file
@@ -0,0 +1,121 @@
|
||||
# PST VPN Installation Script
|
||||
# Run this script as Administrator (Right-click > Run as Administrator)
|
||||
|
||||
Write-Host "Installing PST VPN Configuration..." -ForegroundColor Cyan
|
||||
|
||||
# Check if running as Administrator
|
||||
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
|
||||
|
||||
if (-not $isAdmin) {
|
||||
Write-Host "ERROR: This script must be run as Administrator!" -ForegroundColor Red
|
||||
Write-Host "Right-click PowerShell and select 'Run as Administrator', then run this script again." -ForegroundColor Yellow
|
||||
pause
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Define paths
|
||||
$sourceDir = "D:\ClaudeTools"
|
||||
$destDir = "C:\Program Files\OpenVPN\config"
|
||||
|
||||
# Check if OpenVPN is installed
|
||||
if (-not (Test-Path $destDir)) {
|
||||
Write-Host "ERROR: OpenVPN does not appear to be installed!" -ForegroundColor Red
|
||||
Write-Host "Expected directory not found: $destDir" -ForegroundColor Yellow
|
||||
Write-Host "Please install OpenVPN GUI first from: https://openvpn.net/community-downloads/" -ForegroundColor Yellow
|
||||
pause
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Copy configuration files
|
||||
Write-Host "`nCopying configuration files..." -ForegroundColor Yellow
|
||||
|
||||
try {
|
||||
Copy-Item "$sourceDir\PST-NW-VPN-Windows.ovpn" -Destination $destDir -Force
|
||||
Write-Host "[OK] Copied PST-NW-VPN-Windows.ovpn" -ForegroundColor Green
|
||||
|
||||
Copy-Item "$sourceDir\PST-NW-VPN-auth.txt" -Destination $destDir -Force
|
||||
Write-Host "[OK] Copied PST-NW-VPN-auth.txt" -ForegroundColor Green
|
||||
}
|
||||
catch {
|
||||
Write-Host "[ERROR] Failed to copy files: $_" -ForegroundColor Red
|
||||
pause
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Secure the credentials file
|
||||
Write-Host "`nSecuring credentials file..." -ForegroundColor Yellow
|
||||
$authFile = "$destDir\PST-NW-VPN-auth.txt"
|
||||
|
||||
try {
|
||||
# Get current ACL
|
||||
$acl = Get-Acl $authFile
|
||||
|
||||
# Disable inheritance and remove inherited permissions
|
||||
$acl.SetAccessRuleProtection($true, $false)
|
||||
|
||||
# Remove all existing rules
|
||||
$acl.Access | ForEach-Object { $acl.RemoveAccessRule($_) | Out-Null }
|
||||
|
||||
# Add SYSTEM - Full Control
|
||||
$systemRule = New-Object System.Security.AccessControl.FileSystemAccessRule(
|
||||
"SYSTEM", "FullControl", "Allow"
|
||||
)
|
||||
$acl.AddAccessRule($systemRule)
|
||||
|
||||
# Add Administrators - Full Control
|
||||
$adminRule = New-Object System.Security.AccessControl.FileSystemAccessRule(
|
||||
"Administrators", "FullControl", "Allow"
|
||||
)
|
||||
$acl.AddAccessRule($adminRule)
|
||||
|
||||
# Apply the ACL
|
||||
Set-Acl $authFile $acl
|
||||
|
||||
Write-Host "[OK] Credentials file secured (SYSTEM and Administrators only)" -ForegroundColor Green
|
||||
}
|
||||
catch {
|
||||
Write-Host "[WARNING] Could not secure credentials file: $_" -ForegroundColor Yellow
|
||||
Write-Host "Please manually secure this file via Properties > Security" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
# Check for OpenVPN service
|
||||
Write-Host "`nChecking OpenVPN Interactive Service..." -ForegroundColor Yellow
|
||||
|
||||
$service = Get-Service -Name "OpenVPNServiceInteractive" -ErrorAction SilentlyContinue
|
||||
|
||||
if ($service) {
|
||||
Write-Host "[OK] OpenVPN Interactive Service found" -ForegroundColor Green
|
||||
|
||||
if ($service.StartType -ne "Automatic") {
|
||||
Write-Host "Setting service to Automatic startup..." -ForegroundColor Yellow
|
||||
Set-Service -Name "OpenVPNServiceInteractive" -StartupType Automatic
|
||||
Write-Host "[OK] Service set to Automatic" -ForegroundColor Green
|
||||
}
|
||||
|
||||
if ($service.Status -ne "Running") {
|
||||
Write-Host "Starting OpenVPN Interactive Service..." -ForegroundColor Yellow
|
||||
Start-Service -Name "OpenVPNServiceInteractive"
|
||||
Write-Host "[OK] Service started" -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-Host "[WARNING] OpenVPN Interactive Service not found" -ForegroundColor Yellow
|
||||
Write-Host "You may need to reinstall OpenVPN with service components" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
# Summary
|
||||
Write-Host "`n========================================" -ForegroundColor Cyan
|
||||
Write-Host "Installation Complete!" -ForegroundColor Green
|
||||
Write-Host "========================================" -ForegroundColor Cyan
|
||||
Write-Host "`nConfiguration files installed to:" -ForegroundColor White
|
||||
Write-Host " $destDir" -ForegroundColor Gray
|
||||
Write-Host "`nNext steps:" -ForegroundColor White
|
||||
Write-Host " 1. Open OpenVPN GUI (system tray)" -ForegroundColor Gray
|
||||
Write-Host " 2. Right-click > Connect to 'PST-NW-VPN-Windows'" -ForegroundColor Gray
|
||||
Write-Host " 3. Optionally configure 'Start on Boot' for auto-connect" -ForegroundColor Gray
|
||||
Write-Host "`nConnection Details:" -ForegroundColor White
|
||||
Write-Host " Server: 64.139.88.249:1194" -ForegroundColor Gray
|
||||
Write-Host " Username: pst-admin (auto-login configured)" -ForegroundColor Gray
|
||||
Write-Host "`n"
|
||||
|
||||
pause
|
||||
178
infrastructure/vpn-configs/Setup/PST-L2TP-VPN-Manual-Setup.txt
Normal file
178
infrastructure/vpn-configs/Setup/PST-L2TP-VPN-Manual-Setup.txt
Normal file
@@ -0,0 +1,178 @@
|
||||
PST L2TP/IPsec VPN - Manual Setup Guide
|
||||
========================================
|
||||
|
||||
Connection Details:
|
||||
-------------------
|
||||
VPN Name: PST-NW-VPN
|
||||
Server: 64.139.88.249
|
||||
Type: L2TP/IPsec with Pre-Shared Key
|
||||
Username: pst-admin
|
||||
Password: 24Hearts$
|
||||
Pre-Shared Key (PSK): rrClvnmUeXEFo90Ol+z7tfsAZHeSK6w7
|
||||
|
||||
|
||||
AUTOMATED SETUP (RECOMMENDED):
|
||||
===============================
|
||||
Run as Administrator in PowerShell:
|
||||
cd D:\ClaudeTools
|
||||
.\Setup-PST-L2TP-VPN.ps1
|
||||
|
||||
This will:
|
||||
- Create the VPN connection (all users)
|
||||
- Configure L2TP/IPsec with PSK
|
||||
- Save credentials
|
||||
- Set up auto-connect at startup
|
||||
|
||||
|
||||
MANUAL SETUP:
|
||||
==============
|
||||
|
||||
Method 1: Using PowerShell (Quick)
|
||||
-----------------------------------
|
||||
Run as Administrator:
|
||||
|
||||
# Create VPN connection
|
||||
Add-VpnConnection -Name "PST-NW-VPN" -ServerAddress "64.139.88.249" -TunnelType L2tp -EncryptionLevel Required -AuthenticationMethod MSChapv2 -L2tpPsk "rrClvnmUeXEFo90Ol+z7tfsAZHeSK6w7" -AllUserConnection -RememberCredential -Force
|
||||
|
||||
# Connect and save credentials
|
||||
rasdial "PST-NW-VPN" pst-admin 24Hearts$
|
||||
|
||||
# Disconnect
|
||||
rasdial "PST-NW-VPN" /disconnect
|
||||
|
||||
|
||||
Method 2: Using Windows GUI
|
||||
----------------------------
|
||||
1. Open Settings > Network & Internet > VPN
|
||||
2. Click "Add VPN"
|
||||
3. VPN provider: Windows (built-in)
|
||||
4. Connection name: PST-NW-VPN
|
||||
5. Server name or address: 64.139.88.249
|
||||
6. VPN type: L2TP/IPsec with pre-shared key
|
||||
7. Pre-shared key: rrClvnmUeXEFo90Ol+z7tfsAZHeSK6w7
|
||||
8. Type of sign-in info: User name and password
|
||||
9. User name: pst-admin
|
||||
10. Password: 24Hearts$
|
||||
11. Check "Remember my sign-in info"
|
||||
12. Click Save
|
||||
|
||||
|
||||
PRE-LOGIN AUTO-CONNECT SETUP:
|
||||
==============================
|
||||
|
||||
Option 1: Task Scheduler (Recommended)
|
||||
---------------------------------------
|
||||
1. Open Task Scheduler (taskschd.msc)
|
||||
2. Create Task (not Basic Task)
|
||||
3. General tab:
|
||||
- Name: PST-VPN-AutoConnect
|
||||
- Run whether user is logged on or not
|
||||
- Run with highest privileges
|
||||
4. Triggers tab:
|
||||
- New > At startup
|
||||
- Delay task for: 30 seconds (optional)
|
||||
5. Actions tab:
|
||||
- Action: Start a program
|
||||
- Program: C:\Windows\System32\rasdial.exe
|
||||
- Arguments: "PST-NW-VPN" pst-admin 24Hearts$
|
||||
6. Conditions tab:
|
||||
- Uncheck "Start only if on AC power"
|
||||
7. Settings tab:
|
||||
- Check "Run task as soon as possible after scheduled start is missed"
|
||||
8. Click OK
|
||||
|
||||
|
||||
Option 2: Startup Script
|
||||
-------------------------
|
||||
Create: C:\Windows\System32\GroupPolicy\Machine\Scripts\Startup\connect-vpn.bat
|
||||
|
||||
Content:
|
||||
@echo off
|
||||
timeout /t 30 /nobreak
|
||||
rasdial "PST-NW-VPN" pst-admin 24Hearts$
|
||||
|
||||
Then:
|
||||
1. Run gpedit.msc
|
||||
2. Computer Configuration > Windows Settings > Scripts > Startup
|
||||
3. Add > Browse > Select connect-vpn.bat
|
||||
4. OK
|
||||
|
||||
|
||||
TESTING:
|
||||
========
|
||||
|
||||
Test Connection:
|
||||
rasdial "PST-NW-VPN"
|
||||
|
||||
Check Status:
|
||||
rasdial
|
||||
|
||||
Disconnect:
|
||||
rasdial "PST-NW-VPN" /disconnect
|
||||
|
||||
View Connection Details:
|
||||
Get-VpnConnection -Name "PST-NW-VPN" -AllUserConnection
|
||||
|
||||
|
||||
VERIFY PRE-LOGIN:
|
||||
=================
|
||||
1. Reboot the computer
|
||||
2. At the login screen, press Ctrl+Alt+Del
|
||||
3. Click the network icon (bottom right)
|
||||
4. You should see "PST-NW-VPN" listed
|
||||
5. It should show as "Connected" if auto-connect worked
|
||||
|
||||
|
||||
TROUBLESHOOTING:
|
||||
================
|
||||
|
||||
Connection fails:
|
||||
- Check server address: ping 64.139.88.249
|
||||
- Verify Windows Firewall allows L2TP (UDP 500, 1701, 4500)
|
||||
- Try disabling "Require encryption" temporarily
|
||||
|
||||
Error 789 (L2TP connection attempt failed):
|
||||
- Windows Firewall may be blocking
|
||||
- Registry fix required for NAT-T
|
||||
|
||||
Registry Fix for NAT-T (if needed):
|
||||
Run as Administrator:
|
||||
reg add HKLM\SYSTEM\CurrentControlSet\Services\PolicyAgent /v AssumeUDPEncapsulationContextOnSendRule /t REG_DWORD /d 2 /f
|
||||
|
||||
Then reboot.
|
||||
|
||||
Error 691 (Access denied):
|
||||
- Check username/password
|
||||
- Verify server allows L2TP connections
|
||||
|
||||
Can't see VPN at login screen:
|
||||
- Ensure connection was created with -AllUserConnection flag
|
||||
- Verify RasMan service is running: services.msc
|
||||
- Check "Remote Access Connection Manager" is set to Automatic
|
||||
|
||||
|
||||
REMOVING VPN:
|
||||
=============
|
||||
|
||||
Remove VPN connection:
|
||||
Remove-VpnConnection -Name "PST-NW-VPN" -AllUserConnection -Force
|
||||
|
||||
Remove auto-connect task:
|
||||
Unregister-ScheduledTask -TaskName "PST-VPN-AutoConnect" -Confirm:$false
|
||||
|
||||
|
||||
SECURITY NOTES:
|
||||
===============
|
||||
- Credentials are stored in Windows Credential Manager
|
||||
- PSK is stored in the VPN connection settings
|
||||
- For maximum security, use certificate-based auth instead of PSK
|
||||
- The scheduled task contains password in plain text - secure task XML file permissions
|
||||
|
||||
|
||||
ADVANTAGES OVER OPENVPN:
|
||||
========================
|
||||
- Built into Windows (no third-party software)
|
||||
- Native pre-login support
|
||||
- Simple configuration
|
||||
- Managed through Windows settings
|
||||
- Works with Windows RAS/RRAS services
|
||||
150
infrastructure/vpn-configs/Setup/PST-VPN-Setup-Instructions.txt
Normal file
150
infrastructure/vpn-configs/Setup/PST-VPN-Setup-Instructions.txt
Normal file
@@ -0,0 +1,150 @@
|
||||
PEACEFULE SPIRIT VPN SETUP - Pre-Login Auto-Connect with OpenVPN GUI
|
||||
========================================================================
|
||||
|
||||
Files Created:
|
||||
--------------
|
||||
1. PST-NW-VPN-Windows.ovpn (Modified config for Windows)
|
||||
2. PST-NW-VPN-auth.txt (Credentials file)
|
||||
|
||||
INSTALLATION STEPS:
|
||||
===================
|
||||
|
||||
Step 1: Install OpenVPN GUI (if not already installed)
|
||||
-------------------------------------------------------
|
||||
1. Download OpenVPN GUI from: https://openvpn.net/community-downloads/
|
||||
2. Install using default settings
|
||||
3. Install as Administrator to enable system service mode
|
||||
|
||||
Step 2: Copy Configuration Files to OpenVPN Config Directory
|
||||
-------------------------------------------------------------
|
||||
You need to copy both files to the OpenVPN config directory:
|
||||
|
||||
OPTION A - For System-Wide Service (Pre-Login):
|
||||
Copy both files to: C:\Program Files\OpenVPN\config\
|
||||
|
||||
Commands (Run as Administrator in PowerShell):
|
||||
|
||||
Copy-Item "D:\ClaudeTools\PST-NW-VPN-Windows.ovpn" -Destination "C:\Program Files\OpenVPN\config\"
|
||||
Copy-Item "D:\ClaudeTools\PST-NW-VPN-auth.txt" -Destination "C:\Program Files\OpenVPN\config\"
|
||||
|
||||
OPTION B - For User-Level Only (Not Pre-Login):
|
||||
Copy both files to: C:\Users\YourUsername\OpenVPN\config\
|
||||
|
||||
Step 3: Verify File Permissions (IMPORTANT for Security)
|
||||
---------------------------------------------------------
|
||||
The credentials file should be protected:
|
||||
|
||||
1. Right-click PST-NW-VPN-auth.txt
|
||||
2. Properties > Security tab
|
||||
3. Click "Advanced"
|
||||
4. Remove "Users" group (leave only SYSTEM and Administrators)
|
||||
5. Apply changes
|
||||
|
||||
Step 4: Configure OpenVPN Interactive Service (for Pre-Login)
|
||||
--------------------------------------------------------------
|
||||
1. Press Win+R, type: services.msc
|
||||
2. Find "OpenVPNServiceInteractive" or "OpenVPN Interactive Service"
|
||||
3. Right-click > Properties
|
||||
4. Set "Startup type" to: Automatic
|
||||
5. Click "Start" to start the service now
|
||||
6. Click "OK"
|
||||
|
||||
Step 5: Connect to VPN
|
||||
----------------------
|
||||
OPTION A - Using OpenVPN GUI (User Interface):
|
||||
1. Right-click OpenVPN GUI icon in system tray
|
||||
2. Select "PST-NW-VPN-Windows" > Connect
|
||||
3. Connection should auto-authenticate with saved credentials
|
||||
|
||||
OPTION B - Using Command Line (for testing):
|
||||
Run as Administrator:
|
||||
|
||||
cd "C:\Program Files\OpenVPN\bin"
|
||||
openvpn-gui --connect PST-NW-VPN-Windows.ovpn
|
||||
|
||||
Step 6: Configure Auto-Connect on Startup (Optional)
|
||||
-----------------------------------------------------
|
||||
To automatically connect when Windows starts:
|
||||
|
||||
1. Right-click OpenVPN GUI icon in system tray
|
||||
2. Settings > Advanced
|
||||
3. Check "Launch on Windows startup"
|
||||
4. Check "Silent connection (always)"
|
||||
5. In the main window, right-click the connection
|
||||
6. Select "Start on Boot"
|
||||
|
||||
Alternative: Using Windows Task Scheduler for Pre-Login Auto-Connect
|
||||
---------------------------------------------------------------------
|
||||
1. Open Task Scheduler (taskschd.msc)
|
||||
2. Create Task (not Basic Task)
|
||||
3. General tab:
|
||||
- Name: "PST VPN Auto-Connect"
|
||||
- Select "Run whether user is logged on or not"
|
||||
- Check "Run with highest privileges"
|
||||
4. Triggers tab:
|
||||
- New > At startup
|
||||
5. Actions tab:
|
||||
- Program: C:\Program Files\OpenVPN\bin\openvpn.exe
|
||||
- Arguments: --config "C:\Program Files\OpenVPN\config\PST-NW-VPN-Windows.ovpn"
|
||||
- Start in: C:\Program Files\OpenVPN\bin
|
||||
6. Conditions tab:
|
||||
- Uncheck "Start the task only if the computer is on AC power"
|
||||
7. Click OK and enter administrator credentials
|
||||
|
||||
VERIFICATION:
|
||||
=============
|
||||
1. Check connection status in OpenVPN GUI
|
||||
2. Visit https://whatismyipaddress.com/ to verify your IP changed
|
||||
3. Expected IP: 64.139.88.249 (the VPN server)
|
||||
|
||||
TROUBLESHOOTING:
|
||||
================
|
||||
Connection fails:
|
||||
- Check Windows Firewall allows OpenVPN
|
||||
- Verify credentials in PST-NW-VPN-auth.txt are correct
|
||||
- Check logs: C:\Program Files\OpenVPN\log\
|
||||
|
||||
Service won't start:
|
||||
- Run as Administrator
|
||||
- Check Event Viewer for OpenVPN errors
|
||||
- Verify TAP adapter is installed (should be installed with OpenVPN)
|
||||
|
||||
Credential issues:
|
||||
- Ensure auth file has exactly 2 lines: username on line 1, password on line 2
|
||||
- No extra spaces or blank lines
|
||||
- File must be in same directory as .ovpn file
|
||||
|
||||
KEY CHANGES MADE FROM ORIGINAL CONFIG:
|
||||
=======================================
|
||||
1. Removed Linux-specific lines:
|
||||
- user nobody
|
||||
- group nogroup
|
||||
(These cause errors on Windows)
|
||||
|
||||
2. Added credentials file reference:
|
||||
- auth-user-pass PST-NW-VPN-auth.txt
|
||||
(Enables auto-login)
|
||||
|
||||
3. Renamed config file to indicate Windows compatibility
|
||||
|
||||
SECURITY NOTES:
|
||||
===============
|
||||
- The PST-NW-VPN-auth.txt file contains your password in plain text
|
||||
- Ensure file permissions restrict access to Administrators only
|
||||
- Do not share this file or commit to version control
|
||||
- Consider using Windows Credential Manager for additional security
|
||||
|
||||
CONNECTION DETAILS:
|
||||
===================
|
||||
VPN Server: 64.139.88.249:1194
|
||||
Protocol: TCP
|
||||
Username: pst-admin
|
||||
Encryption: AES-256-CBC with SHA1 auth
|
||||
Gateway: Full tunnel (all traffic routed through VPN)
|
||||
|
||||
SUPPORT:
|
||||
========
|
||||
If you encounter issues, check:
|
||||
1. OpenVPN logs in system tray menu
|
||||
2. Windows Event Viewer > Application logs
|
||||
3. Verify network connectivity to 64.139.88.249:1194
|
||||
233
infrastructure/vpn-configs/Setup/Setup-PST-L2TP-VPN.ps1
Normal file
233
infrastructure/vpn-configs/Setup/Setup-PST-L2TP-VPN.ps1
Normal file
@@ -0,0 +1,233 @@
|
||||
# PST L2TP/IPsec VPN Setup Script
|
||||
# Run as Administrator
|
||||
|
||||
Write-Host "========================================" -ForegroundColor Cyan
|
||||
Write-Host "PST L2TP/IPsec VPN Setup" -ForegroundColor Cyan
|
||||
Write-Host "========================================" -ForegroundColor Cyan
|
||||
|
||||
# Check if running as Administrator
|
||||
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
|
||||
|
||||
if (-not $isAdmin) {
|
||||
Write-Host "`n[ERROR] This script must be run as Administrator!" -ForegroundColor Red
|
||||
Write-Host "Right-click PowerShell and select 'Run as Administrator'" -ForegroundColor Yellow
|
||||
pause
|
||||
exit 1
|
||||
}
|
||||
|
||||
# VPN Configuration
|
||||
$vpnName = "PST-NW-VPN"
|
||||
$serverAddress = "64.139.88.249"
|
||||
$psk = "rrClvnmUeXEFo90Ol+z7tfsAZHeSK6w7"
|
||||
$username = "pst-admin"
|
||||
$password = "24Hearts$"
|
||||
|
||||
Write-Host "`nStep 1: Creating VPN Connection..." -ForegroundColor Yellow
|
||||
|
||||
# Remove existing VPN connection if it exists
|
||||
$existing = Get-VpnConnection -Name $vpnName -AllUserConnection -ErrorAction SilentlyContinue
|
||||
if ($existing) {
|
||||
Write-Host "Removing existing VPN connection..." -ForegroundColor Gray
|
||||
Remove-VpnConnection -Name $vpnName -AllUserConnection -Force
|
||||
}
|
||||
|
||||
# Create new L2TP/IPsec VPN connection (All Users - for pre-login)
|
||||
try {
|
||||
Add-VpnConnection `
|
||||
-Name $vpnName `
|
||||
-ServerAddress $serverAddress `
|
||||
-TunnelType L2tp `
|
||||
-EncryptionLevel Required `
|
||||
-AuthenticationMethod MSChapv2 `
|
||||
-L2tpPsk $psk `
|
||||
-AllUserConnection `
|
||||
-RememberCredential `
|
||||
-PassThru `
|
||||
-Force
|
||||
|
||||
Write-Host "[OK] VPN connection created" -ForegroundColor Green
|
||||
}
|
||||
catch {
|
||||
Write-Host "[ERROR] Failed to create VPN connection: $_" -ForegroundColor Red
|
||||
pause
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host "`nStep 2: Configuring Split-Tunnel and DNS..." -ForegroundColor Yellow
|
||||
|
||||
# Configure split-tunnel (don't route all traffic through VPN)
|
||||
try {
|
||||
Set-VpnConnection -Name $vpnName -SplitTunneling $true -AllUserConnection
|
||||
Write-Host "[OK] Split-tunneling enabled (only remote network traffic uses VPN)" -ForegroundColor Green
|
||||
}
|
||||
catch {
|
||||
Write-Host "[WARNING] Could not enable split-tunneling: $_" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
# Set DNS server for VPN connection
|
||||
try {
|
||||
# Get the VPN interface (will be available after first connection)
|
||||
# We'll set this after the test connection
|
||||
Write-Host "[INFO] DNS will be configured after first connection" -ForegroundColor Gray
|
||||
}
|
||||
catch {
|
||||
Write-Host "[WARNING] Could not configure DNS: $_" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
Write-Host "`nStep 3: Configuring IPsec Settings..." -ForegroundColor Yellow
|
||||
|
||||
# Set VPN connection to use pre-shared key
|
||||
try {
|
||||
Set-VpnConnectionIPsecConfiguration `
|
||||
-ConnectionName $vpnName `
|
||||
-AuthenticationTransformConstants SHA256128 `
|
||||
-CipherTransformConstants AES128 `
|
||||
-EncryptionMethod AES128 `
|
||||
-IntegrityCheckMethod SHA256 `
|
||||
-DHGroup Group14 `
|
||||
-PfsGroup None `
|
||||
-Force
|
||||
|
||||
Write-Host "[OK] IPsec settings configured" -ForegroundColor Green
|
||||
}
|
||||
catch {
|
||||
Write-Host "[WARNING] Could not set advanced IPsec settings: $_" -ForegroundColor Yellow
|
||||
Write-Host "Using default IPsec configuration" -ForegroundColor Gray
|
||||
}
|
||||
|
||||
Write-Host "`nStep 4: Saving VPN Credentials..." -ForegroundColor Yellow
|
||||
|
||||
# Create secure credential
|
||||
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
|
||||
|
||||
# Save credentials using rasdial (works for pre-login)
|
||||
try {
|
||||
# Use rasdial to save credentials in the system
|
||||
$rasDialCmd = "rasdial `"$vpnName`" $username $password"
|
||||
|
||||
# Connect once to save credentials, then disconnect
|
||||
Write-Host "Testing connection and saving credentials..." -ForegroundColor Gray
|
||||
$result = cmd /c "rasdial `"$vpnName`" $username $password" 2>&1
|
||||
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
Write-Host "[OK] Connection successful - credentials saved" -ForegroundColor Green
|
||||
|
||||
# Configure DNS for VPN interface
|
||||
Start-Sleep -Seconds 3
|
||||
Write-Host "Configuring DNS server (192.168.0.2)..." -ForegroundColor Gray
|
||||
|
||||
try {
|
||||
# Get the VPN interface
|
||||
$vpnInterface = Get-NetAdapter | Where-Object { $_.InterfaceDescription -like "*WAN Miniport (L2TP)*" -and $_.Status -eq "Up" }
|
||||
|
||||
if ($vpnInterface) {
|
||||
Set-DnsClientServerAddress -InterfaceIndex $vpnInterface.InterfaceIndex -ServerAddresses "192.168.0.2"
|
||||
Write-Host "[OK] DNS set to 192.168.0.2" -ForegroundColor Green
|
||||
}
|
||||
else {
|
||||
Write-Host "[WARNING] Could not find active VPN interface for DNS config" -ForegroundColor Yellow
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Host "[WARNING] Could not set DNS: $_" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
# Disconnect
|
||||
Start-Sleep -Seconds 2
|
||||
rasdial $vpnName /disconnect | Out-Null
|
||||
Write-Host "[OK] Disconnected" -ForegroundColor Green
|
||||
}
|
||||
else {
|
||||
Write-Host "[WARNING] Connection test failed, but credentials may be saved" -ForegroundColor Yellow
|
||||
Write-Host "Error: $result" -ForegroundColor Gray
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Host "[WARNING] Could not test connection: $_" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
Write-Host "`nStep 5: Configuring Auto-Connect (Optional)..." -ForegroundColor Yellow
|
||||
Write-Host "Creating Task Scheduler job for auto-connect at startup..." -ForegroundColor Gray
|
||||
|
||||
# Create a scheduled task to connect at startup (before login)
|
||||
$taskName = "PST-VPN-AutoConnect"
|
||||
|
||||
# Remove existing task if present
|
||||
Unregister-ScheduledTask -TaskName $taskName -Confirm:$false -ErrorAction SilentlyContinue
|
||||
|
||||
# Copy the connection script to a system location
|
||||
$scriptSource = "D:\ClaudeTools\Connect-PST-VPN.ps1"
|
||||
$scriptDest = "C:\Windows\System32\Connect-PST-VPN.ps1"
|
||||
|
||||
if (Test-Path $scriptSource) {
|
||||
Copy-Item $scriptSource -Destination $scriptDest -Force
|
||||
Write-Host "[OK] Connection script copied to system directory" -ForegroundColor Green
|
||||
}
|
||||
|
||||
# Create task action to run PowerShell script
|
||||
$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-ExecutionPolicy Bypass -WindowStyle Hidden -File `"$scriptDest`""
|
||||
|
||||
# Create task trigger (at startup)
|
||||
$trigger = New-ScheduledTaskTrigger -AtStartup
|
||||
|
||||
# Create task principal (run as SYSTEM for pre-login)
|
||||
$principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount -RunLevel Highest
|
||||
|
||||
# Create task settings
|
||||
$settings = New-ScheduledTaskSettingsSet `
|
||||
-AllowStartIfOnBatteries `
|
||||
-DontStopIfGoingOnBatteries `
|
||||
-StartWhenAvailable `
|
||||
-RestartCount 3 `
|
||||
-RestartInterval (New-TimeSpan -Minutes 1)
|
||||
|
||||
# Register the task
|
||||
try {
|
||||
Register-ScheduledTask `
|
||||
-TaskName $taskName `
|
||||
-Action $action `
|
||||
-Trigger $trigger `
|
||||
-Principal $principal `
|
||||
-Settings $settings `
|
||||
-Description "Auto-connect to PST VPN at system startup" | Out-Null
|
||||
|
||||
Write-Host "[OK] Auto-connect scheduled task created" -ForegroundColor Green
|
||||
}
|
||||
catch {
|
||||
Write-Host "[WARNING] Could not create scheduled task: $_" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
# Summary
|
||||
Write-Host "`n========================================" -ForegroundColor Cyan
|
||||
Write-Host "Setup Complete!" -ForegroundColor Green
|
||||
Write-Host "========================================" -ForegroundColor Cyan
|
||||
|
||||
Write-Host "`nVPN Configuration:" -ForegroundColor White
|
||||
Write-Host " Name: $vpnName" -ForegroundColor Gray
|
||||
Write-Host " Server: $serverAddress" -ForegroundColor Gray
|
||||
Write-Host " Type: L2TP/IPsec with Pre-Shared Key" -ForegroundColor Gray
|
||||
Write-Host " Username: $username" -ForegroundColor Gray
|
||||
Write-Host " Tunnel Mode: Split-Tunnel (only remote traffic uses VPN)" -ForegroundColor Gray
|
||||
Write-Host " DNS Server: 192.168.0.2" -ForegroundColor Gray
|
||||
Write-Host " Auto-connect: Enabled (scheduled task)" -ForegroundColor Gray
|
||||
|
||||
Write-Host "`nConnection Methods:" -ForegroundColor White
|
||||
Write-Host " 1. Windows Settings > Network > VPN > '$vpnName' > Connect" -ForegroundColor Gray
|
||||
Write-Host " 2. Command line: powershell -File C:\Windows\System32\Connect-PST-VPN.ps1" -ForegroundColor Gray
|
||||
Write-Host " 3. Simple: rasdial `"$vpnName`" (DNS must be set manually)" -ForegroundColor Gray
|
||||
Write-Host " 4. Automatic at startup (via scheduled task with DNS config)" -ForegroundColor Gray
|
||||
|
||||
Write-Host "`nPre-Login Connection:" -ForegroundColor White
|
||||
Write-Host " - This VPN is available to all users" -ForegroundColor Gray
|
||||
Write-Host " - Will auto-connect at system startup" -ForegroundColor Gray
|
||||
Write-Host " - Credentials are saved system-wide" -ForegroundColor Gray
|
||||
|
||||
Write-Host "`nManagement:" -ForegroundColor White
|
||||
Write-Host " - View connection: Get-VpnConnection -Name '$vpnName' -AllUserConnection" -ForegroundColor Gray
|
||||
Write-Host " - Connect manually: rasdial '$vpnName'" -ForegroundColor Gray
|
||||
Write-Host " - Disconnect: rasdial '$vpnName' /disconnect" -ForegroundColor Gray
|
||||
Write-Host " - Remove VPN: Remove-VpnConnection -Name '$vpnName' -AllUserConnection" -ForegroundColor Gray
|
||||
Write-Host " - Remove auto-connect: Unregister-ScheduledTask -TaskName '$taskName'" -ForegroundColor Gray
|
||||
|
||||
Write-Host "`n"
|
||||
pause
|
||||
Reference in New Issue
Block a user