@echo off
REM ============================================================
REM Cyber-Medi Secure Access — One-Click WARP Installer
REM ============================================================
REM This script downloads, installs, and configures Cloudflare
REM WARP for secure access to your healthcare portal.
REM ============================================================

echo.
echo ============================================================
echo  Cyber-Medi Secure Access — Installing...
echo ============================================================
echo.

REM Check for admin
net session >nul 2>&1
if %errorlevel% neq 0 (
    echo [!] Administrator access required.
    echo     Right-click this file and select "Run as administrator"
    pause
    exit /b 1
)

set INSTALL_DIR=%ProgramFiles%\Cloudflare\Cloudflare WARP
set WARP_CLI="%INSTALL_DIR%\warp-cli.exe"

if exist "%INSTALL_DIR%\warp-cli.exe" (
    echo [OK] WARP is already installed. Configuring...
    goto :configure
)

echo [1/3] Downloading Cloudflare WARP...
set TEMP_MSI=%TEMP%\Cloudflare_WARP.msi
powershell -Command "Invoke-WebRequest -Uri 'https://www.cloudflare.com/static/misc/warp/Cloudflare_WARP_Release-x64.msi' -OutFile '%TEMP_MSI%' -UseBasicParsing"
if %errorlevel% neq 0 (
    echo [ERROR] Download failed. Check your internet connection.
    pause
    exit /b 1
)

echo [2/3] Installing (this may take a minute)...
msiexec /i "%TEMP_MSI%" /quiet /norestart ORGANIZATION=cyberellum SUPPORT_URL="https://cyber-medi.us"
timeout /t 5 >nul
del "%TEMP_MSI%" 2>nul

:configure
echo [3/3] Configuring secure connection...
reg add "HKLM\SOFTWARE\Cloudflare\CloudflareWARP" /v "organization" /t REG_SZ /d "cyberellum" /f >nul 2>&1
reg add "HKLM\SOFTWARE\Cloudflare\CloudflareWARP" /v "onboarding" /t REG_SZ /d "false" /f >nul 2>&1
reg add "HKLM\SOFTWARE\Cloudflare\CloudflareWARP" /v "support_url" /t REG_SZ /d "https://cyber-medi.us" /f >nul 2>&1

%WARP_CLI% --accept-tos >nul 2>&1
%WARP_CLI% set-mode warp+doh >nul 2>&1
%WARP_CLI% connect >nul 2>&1
timeout /t 3 >nul

echo.
echo ============================================================
echo  DONE! WARP is installed and connecting.
echo.
echo  Next steps:
echo  1. Look for the WARP icon in your system tray (bottom right)
echo  2. It will ask you to log in — use your registered email
echo  3. Once connected, go to: https://health.cyber-medi.us
echo ============================================================
echo.
pause
