@echo off
setlocal

set "REGKEY=HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
set "PROXY_SERVER=proxy.bozok.edu.tr:4128"
set "HBYS_URL=https://dishbys.bozok.edu.tr:8090"

:: Mevcut proxy durumunu oku
set "PROXY_ENABLE=0"
for /f "tokens=3" %%A in ('reg query "%REGKEY%" /v ProxyEnable 2^>nul ^| find /i "ProxyEnable"') do set "PROXY_ENABLE=%%A"

if /i "%PROXY_ENABLE%"=="0x1" (
    :: Proxy acik: kapat
    reg add "%REGKEY%" /v ProxyEnable /t REG_DWORD /d 0 /f >nul
    echo Proxy kapatildi.
) else (
    :: Proxy kapali: sunucu bilgilerini ayarla ve ac
    reg add "%REGKEY%" /v ProxyServer /t REG_SZ /d "%PROXY_SERVER%" /f >nul
    reg add "%REGKEY%" /v ProxyEnable /t REG_DWORD /d 1 /f >nul
    echo Proxy etkinlestirildi: %PROXY_SERVER%
    
    :: Proxy aktif edildiginde HBYS sayfasini otomatik ac
    start %HBYS_URL%
)

:: Windows'un proxy ayarlarini hemen yenile
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
 "$src = '[DllImport(\"wininet.dll\", SetLastError=true)] public static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int dwBufferLength);';" ^
 "Add-Type -MemberDefinition $src -Name WinInet -Namespace Native;" ^
 "[void][Native.WinInet]::InternetSetOption([IntPtr]::Zero, 39, [IntPtr]::Zero, 0);" ^
 "[void][Native.WinInet]::InternetSetOption([IntPtr]::Zero, 37, [IntPtr]::Zero, 0);"

echo.
timeout /t 7