set checkbalanceurl=%baseurl%/ostremote/v2/CheckBalance
set otpfail=0

for /f "skip=1 eol=C delims=" %%i in (' certutil -hashfile %~f0 SHA256 ') do (
echo %%i | sed "s/ //g" > %SystemDrive%\temp\compsum
set /p compsum=<%SystemDrive%\temp\compsum
del %SystemDrive%\temp\compsum
)

echo.
echo %v20002%
echo.

curl -s -H ""User-Agent": "OSTRemote2-%mainsum:~0,4%%compsum:~0,4%/1.0"" -H ""Auth": "%otp%"" %checkbalanceurl% -o %temp%\output.txt

set resulterrorcode=%errorlevel%
if not "%resulterrorcode%"=="0" (
echo fail > %temp%\serverdown_flag
goto EOF
)

jq-win32 -r ".status" %temp%\output.txt > %temp%\onlinestatus.txt
set /p onlinestatus=<%temp%\onlinestatus.txt
if not "%onlinestatus%"=="Fail" goto passcheck
jq-win32 -r ".code" %temp%\output.txt > %temp%\onlinestatus.txt
set /p errorcode=<%temp%\onlinestatus.txt
if "%errorcode%"=="00000001" echo fail > %temp%\otpfail_flag
if "%errorcode%"=="00002005" echo fail > %temp%\verincorrect_flag
goto EOF
:passcheck

jq-win32 -r ".ConsumedCredits" %temp%\output.txt > %temp%\cc.txt
set /p consumedcred=<%temp%\cc.txt
del %temp%\cc.txt
jq-win32 -r ".RemainingCredits" %temp%\output.txt > %temp%\rc.txt
set /p remainingcred=<%temp%\rc.txt
del %temp%\rc.txt
rem del %temp%\output.txt
:reuse
echo %v20004%%remainingcred%
echo %v20005%%consumedcred%

goto EOF

:EOF
