@echo off
REM === NetManager RustDesk Deploy ===
setlocal
cd /d "%~dp0"
set SERVER=10.10.10.254
set KEY=2MseUdaNLL9luek2KJN8zwjDstOksq+MubIq+qZWXhs=
set PASS=Sp543605x
set SECRET=d839bd225dfdf8f8500bffcd152862a9
set DEPT=Spital
set TARGET_IP=

echo [1/5] Instalare RustDesk...
set RDSETUP=
for %%f in (rustdesk*.exe) do set RDSETUP=%%f
if not defined RDSETUP (echo EROARE: pune rustdesk*.exe in acest folder ^& pause ^& exit /b 1)
"%RDSETUP%" --silent-install
timeout /t 10 /nobreak >nul

set RD=C:\Program Files\RustDesk\rustdesk.exe
if not exist "%RD%" set RD=C:\Program Files (x86)\RustDesk\rustdesk.exe

echo [2/5] Configurare server...
set CFG=%APPDATA%\RustDesk\config
if not exist "%CFG%" mkdir "%CFG%"
(
echo rendezvous_server = '%SERVER%'
echo nat_type = 1
echo serial = 0
echo.
echo [options]
echo custom-rendezvous-server = '%SERVER%'
echo relay-server = '%SERVER%'
echo key = '%KEY%'
) > "%CFG%\RustDesk2.toml"

net stop RustDesk >nul 2>&1
net start RustDesk >nul 2>&1
timeout /t 5 /nobreak >nul

echo [3/5] Parola unattended...
"%RD%" --password %PASS%
timeout /t 2 /nobreak >nul

echo [4/5] Citire ID...
for /f "delims=" %%i in ('""%RD%" --get-id"') do set RDID=%%i

echo Detectare IP/MAC...
set IP=
for /f "tokens=2 delims=:" %%a in ('ipconfig ^| findstr /R /C:"IPv4"') do if not defined IP set IP=%%a
set IP=%IP: =%
set MAC=
for /f "tokens=1" %%m in ('getmac /fo table /nh ^| findstr /R /C:"-.*-.*-"') do if not defined MAC set MAC=%%m

echo [5/5] Inregistrare in NetManager...
curl -k -X POST "https://%SERVER%/api/rustdesk_register.php" -H "Content-Type: application/json" -d "{\"rustdesk_id\":\"%RDID%\",\"name\":\"%COMPUTERNAME%\",\"department\":\"%DEPT%\",\"ip\":\"%IP%\",\"target_ip\":\"%TARGET_IP%\",\"mac\":\"%MAC%\",\"password\":\"%PASS%\",\"secret\":\"%SECRET%\"}"

echo.
echo =====================================
echo  PC: %COMPUTERNAME%
echo  ID RustDesk: %RDID%
echo  Parola: %PASS%
echo  IP tinta: %TARGET_IP%
echo  Inregistrat in NetManager.
echo =====================================
pause
endlocal
