Files
web-vnc/run.bat
T
Codex 6a1ee64b14 feat(run): sync UltraVNC password from run.bat + clearer noVNC errors
- run.bat: call scripts/ensure-vnc-password.ps1 so the password typed once
  also sets the UltraVNC service VNC password (UAC only when it differs);
  skip --spawn when 5900 is already taken (don't launch a 2nd winvnc).
- scripts/ensure-vnc-password.ps1: new - compares the password against
  %ProgramData%\UltraVNC\ultravnc.ini (reverse-engineered UltraVNC DES
  obfuscation) and only writes+restarts the service when it differs.
- scripts/set-vnc-password.bat: set UltraVNC service VNC password as admin
  (createpassword/setpasswd + verify, GUI fallback). Manual fallback.
- internal/server/static/vnc.html: don't let the generic 'disconnect'
  banner overwrite the specific 'securityfailure' reason (noVNC's
  disconnect event has no reason field, so it always said 'unknown').
- AGENTS.md: document the above (scripts, run.bat, UltraVNC service note).
2026-07-30 19:15:09 +03:00

133 lines
4.6 KiB
Batchfile
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
@echo off
REM ============================================================
REM web-vnc launcher - § ¯ã᪠¢ ®¤¨­ ª«¨ª. ‘¯à è¨¢ ¥â ⮫쪮 ¯ à®«ì.
REM ============================================================
chcp 866 >nul
cd /d "%~dp0"
echo.
echo === web-vnc: VNC ¢ ¡à ã§¥à¥ ===
echo.
REM --- 1. ¨­ à­¨ª ---
if exist "web-vnc.exe" goto havebin
where go >nul 2>nul
if not errorlevel 1 goto dogobuild
echo [®è¨¡ª ] web-vnc.exe ­¥ ­ ©¤¥­,   Go ­¥ ãáâ ­®¢«¥­.
echo “áâ ­®¢¨â¥ Go á https://go.dev/dl/ «¨¡® ¯®«®¦¨â¥ ᮡ࠭­ë© web-vnc.exe à冷¬.
echo.
pause
exit /b 1
:dogobuild
echo ‘®¡¨à î web-vnc.exe ...
go build -o web-vnc.exe .\cmd\web-vnc
if errorlevel 1 goto buildfail
:havebin
REM --- 2. noVNC-ª«¨¥­â ---
if exist "internal\server\static\core\rfb.js" goto havenovnc
echo noVNC-ª«¨¥­â ¥éñ ­¥ ¢áâ஥­. ëâ îáì ᪠ç âì ...
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0scripts\get-novnc.ps1"
if errorlevel 1 goto novncfail
echo ¥à¥á®¡¨à î á noVNC ...
go build -o web-vnc.exe .\cmd\web-vnc
goto havenovnc
:novncfail
echo [¯à¥¤ã¯à¥¦¤¥­¨¥] ¥ 㤠«®áì ᪠ç âì noVNC (­¥â ¨­â¥à­¥â ?).
echo ‚ ¡à ã§¥à¥ ®âªà®¥âáï áâà ­¨æ  á ¯®¤áª §ª®©. ®¢â®à¨â¥ ¯®§¦¥: scripts\get-novnc.ps1
echo.
:havenovnc
REM --- 3. VNC-á¥à¢¥à (¯®¨áª/§ £à㧪 ) ---
set "SPAWNARGS="
set "SPAWN_CMD="
if exist "vnc\winvnc.exe" goto uselocalvnc
if exist "vnc\tvnserver.exe" goto uselocalvnc
if exist "C:\Program Files\UltraVNC\winvnc.exe" goto autodetectvnc
if exist "C:\Program Files (x86)\UltraVNC\winvnc.exe" goto autodetectvnc
if exist "C:\Program Files\uvnc bvba\UltraVNC\winvnc.exe" goto autodetectvnc
if exist "C:\Program Files (x86)\uvnc bvba\UltraVNC\winvnc.exe" goto autodetectvnc
if exist "C:\Program Files\TightVNC\tvnserver.exe" goto autodetectvnc
if exist "C:\Program Files (x86)\TightVNC\tvnserver.exe" goto autodetectvnc
echo VNC-á¥à¢¥à ­¥ ­ ©¤¥­. ëâ îáì ᪠ç âì ¯®àâ â¨¢­ë© UltraVNC ...
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0scripts\get-vnc.ps1"
if errorlevel 1 goto novncserver
if exist "vnc\winvnc.exe" goto uselocalvnc
if exist "vnc\tvnserver.exe" goto uselocalvnc
goto novncserver
:uselocalvnc
if exist "vnc\winvnc.exe" set "SPAWN_CMD=vnc\winvnc.exe -run"
if exist "vnc\tvnserver.exe" if not defined SPAWN_CMD set "SPAWN_CMD=vnc\tvnserver.exe -run"
set "SPAWNARGS=--spawn-command "%SPAWN_CMD%""
echo  ©¤¥­ «®ª «ì­ë© VNC-á¥à¢¥à: %SPAWN_CMD%
goto vncdone
:autodetectvnc
echo VNC-á¥à¢¥à ­ ©¤¥­ ¢ á¨á⥬¥ ( ¢â®-®¯à¥¤¥«¥­¨¥ ¯à¨ § ¯ã᪥).
goto vncdone
:novncserver
echo [¯à¥¤ã¯à¥¦¤¥­¨¥] VNC-á¥à¢¥à ­¥ 㤠«®áì ¯®«ãç¨âì.
echo ¥§ VNC-á¥à¢¥à  à ¡®ç¨© á⮫ ­¥ ¡ã¤¥â â࠭᫨஢ âìáï.
echo “áâ ­®¢¨â¥ UltraVNC/TightVNC ¢àãç­ãî ¨«¨ ¯®¢â®à¨â¥: scripts\get-vnc.ps1
echo.
:vncdone
REM --- 4.  à®«ì ---
:getpw
set "PW="
set /p "PW=‚¢¥¤¨â¥ ¯ à®«ì ¤®áâ㯠: "
if "%PW%"=="" goto emptypw
goto gotpw
:emptypw
echo  à®«ì ­¥ ¬®¦¥â ¡ëâì ¯ãáâë¬.
goto getpw
:gotpw
REM --- 4b. Sync UltraVNC password with the one entered (only when it differs) ---
echo ‘¨­åà®­¨§¨àãî ¯ à®«ì UltraVNC á ¢¢¥¤ñ­­ë¬. ਠ­¥á®¢¯ ¤¥­¨¨ § ¯à®á¨â ¯à ¢   ¤¬¨­¨áâà â®à ...
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0scripts\ensure-vnc-password.ps1" -Password "%PW%"
if errorlevel 1 echo [¯à¥¤ã¯à¥¦¤¥­¨¥] ¥ 㤠«®áì ᨭåà®­¨§¨à®¢ âì ¯ à®«ì UltraVNC - ¯à®¤®«¦ î.
REM --- 5. •íè ¯ à®«ï + â®â ¦¥ ¯ à®«ì ¤«ï VNC-á¥à¢¥à  ---
echo ƒ¥­¥à¨àãî åíè ¯ à®«ï ...
for /f "delims=" %%i in ('web-vnc.exe --gen-hash "%PW%"') do set "HASH=%%i"
if "%HASH%"=="" goto hashfail
REM ’®â ¦¥ ¯ à®«ì ¡ã¤¥â  ¢â®¬ â¨ç¥áª¨ ¯¥à¥¤ ­ noVNC ¤«ï  ¢â®à¨§ æ¨¨ ­  VNC-á¥à¢¥à¥.
set "WEBVNC_VNC_PASSWORD=%PW%"
set "PW="
REM --- 6. „®áâã¯­ë¥  ¤à¥á  ---
echo.
echo === €¤à¥á  ¤«ï ¯®¤ª«î祭¨ï (¯®àâ 8080) ===
echo http://localhost:8080
for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0scripts\list-ips.ps1"') do echo http://%%a:8080
echo.
echo …᫨ á ¤à㣮© ¬ è¨­ë ­¥ ®âªà뢠¥âáï - ®¤¨­ à § ¢ë¯®«­¨â¥ ®â ¨¬¥­¨
echo  ¤¬¨­¨áâà â®à : scripts\open-firewall.bat
echo.
REM --- 7. ‡ ¯ã᪠---
echo ‡ ¯ã᪠î web-vnc ­  http://localhost:8080
echo Žáâ ­®¢¨âì: Ctrl+C
echo.
REM --- 6b. 5900 already listening? -> do NOT spawn a 2nd VNC server (avoid conflict with the UltraVNC service) ---
set "SPAWNFLAG=--spawn"
powershell -NoProfile -Command "try{$c=New-Object Net.Sockets.TcpClient('127.0.0.1',5900);$c.Close();exit 0}catch{exit 1}"
if not errorlevel 1 (
echo VNC-á¥à¢¥à 㦥 á«ãè ¥â 127.0.0.1:5900 - ¯®¤ª«îç îáì ª ­¥¬ã ¡¥§ --spawn.
set "SPAWNFLAG="
)
web-vnc.exe --password-hash "%HASH%" %SPAWNARGS% %SPAWNFLAG% --listen :8080
echo.
echo ‘¥à¢¥à ®áâ ­®¢«¥­.
pause
exit /b
:buildfail
echo ‘¡®àª  ­¥ 㤠« áì.
pause
exit /b 1
:hashfail
echo [®è¨¡ª ] ¥ 㤠«®áì ᣥ­¥à¨à®¢ âì åíè ¯ à®«ï.
pause
exit /b 1