JWLLEWELYN

BitDefenderUpdateDefinition.cmd

May 31st, 2017
634
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @echo off
  2. REM Autor: John LLewelyn
  3. REM Description: Remote Bitdefender definition updater automation for Kerio Firewall.
  4. REM This batch script allows you to self-manage a basic task in Windows to update the BitDefender antivirus in the Kerio Control Firewall v9.2.x.
  5. REM Requirements: wget, putty, winscp and 7z.
  6. REM Create a new folder in the root of the system unit or in another storage unit "BitDefender", copy this script, paste and save with notepad with the name "Start.cmd"
  7. REM Create a basic Windows task that executes the script every day of the week in a time of little traffic, 12:00 am for example.
  8. REM This script has only been tested on the Microsoft Windows 10 v1709 operating system.
  9.  
  10. REM Updated: 01/31/2018
  11.  
  12. TITLE Task BitDefender Definition Update Firewall
  13.  
  14. REM CONFIGURATION
  15.  
  16. REM Settings: Storage unit letter
  17. set "drive=C"
  18.  
  19. REM Settings: Names of Folders
  20. set "ProjectName=BitDefender"
  21. set "DownloadFolderName=Downloads"
  22. set "DefinitionFolderName=Definition"
  23. set "CommandsFolderName=Commands"
  24. set "BinFolderName=bin"
  25.  
  26. REM Settings: Directory Routes
  27. set "HomeDir=%drive%:\%ProjectName%"
  28. set "DownDir=%HomeDir%\%DownloadFolderName%"
  29. set "DefinitionDir=%HomeDir%\%DefinitionFolderName%"
  30. set "CommandsDir=%HomeDir%\%CommandsFolderName%"
  31. set "BinaryDir=%HomeDir%\%BinFolderName%"
  32.  
  33. REM Settings: Download Definition
  34. set "DownloadDefinition=http://download.bitdefender.com/updates/update_av64bit/cumulative.zip"
  35.  
  36. REM Settings: Download package complements.
  37. REM FTP server provider.
  38. set "FTPHost=compucheap-firewall.ddns.net"
  39. set "FTPPort=21"
  40. set "FTPUser=anonymous"
  41. set "FTPPass=password"
  42. set "PackageWGET32=wget-1.19.4-win32.zip"
  43. set "PackageWGET64=wget-1.19.4-win64.zip"
  44. set "PackageZIP=7z1801-extra.zip"
  45. set "PackagePUTTY32=putty-0.70-win32.zip"
  46. set "PackagePUTTY64=putty-0.70-win64.zip"
  47. set "PackageWINSCP=WinSCP-5.11.3-Portable.zip"
  48.  
  49. REM Settings: Script Names Files
  50. set "firstscript=Part1.txt"
  51. set "secondscript=Part2.txt"
  52. set "uploadscript=UploadFiles.txt"
  53. set "scriptwget=WGET.txt"
  54. set "scriptzip=7zip.txt"
  55. set "scriptputty=PUTTY.txt"
  56. set "scriptwinscp=WINSCP.txt"
  57.  
  58. REM Server settings "kerio control firewall" remote ssh
  59. set "SSHuser=root"
  60. set "SSHpassword=herepassword"
  61. set "SSHipaddress=192.168.1.1"
  62. set "SSHport=22"
  63. set "SSHhostkey=ssh-rsa 2048 --:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--"
  64. set "SSHtimeout=1000"
  65.  
  66. REM Settings: Required Binaries
  67. reg Query "HKLM\Hardware\Description\System\CentralProcessor\0" | find /i "x86" > NUL && set OS=32BIT || set OS=64BIT
  68.  
  69. if %OS%==32BIT goto plugins32
  70. if %OS%==64BIT goto plugins64
  71.  
  72. :plugins32
  73. set "wget=%BinaryDir%\wget-win32\wget.exe"
  74. set "putty=%BinaryDir%\putty-win32\putty.exe"
  75. set "winscp=%BinaryDir%\winscp-win32\WinSCP.exe"
  76. set "zip=%BinaryDir%\7z-extra\7za.exe"
  77. goto clean
  78.  
  79. :plugins64
  80. set "wget=%BinaryDir%\wget-win64\wget.exe"
  81. set "putty=%BinaryDir%\putty-win64\putty.exe"
  82. set "winscp=%BinaryDir%\winscp-win32\WinSCP.exe"
  83. set "zip=%BinaryDir%\7z-extra\x64\7za.exe"
  84. goto clean
  85.  
  86. REM maintenance
  87. :clean
  88. RD /S /Q "%CommandsDir%"
  89. RD /S /Q "%DefinitionDir%"
  90. REM RD /S /Q "%DownDir%"
  91. mkdir "%CommandsDir%" >nul
  92. mkdir "%DownDir%" >nul
  93. mkdir "%DefinitionDir%" >nul
  94. mkdir "%BinaryDir%" >nul
  95. cls
  96. goto messages
  97.  
  98. REM Messages
  99. :messages
  100. set "msg1=The package is missing. Downloading the WGET package for Windows, Please Wait..."
  101. set "msg2=The package is missing. Downloading the 7-Zip package for Windows, Please Wait..."
  102. set "msg3=The package is missing. Downloading the PUTTY package for Windows, Please Wait..."
  103. set "msg4=The package is missing. Downloading the WinSCP package for Windows, Please Wait..."
  104. set "msg5=No internet connection, try later..."
  105. set "msg6=There is no connection to the Firewall, check its configuration."
  106. set "msg7=Downloading Definition Update, Please Wait..."
  107. set "msg8=Uncompressing the Definition, Please Wait..."
  108. set "msg9=Does not connect with definition host!"
  109. set "msg10=The definition update was a success!"
  110. set "msg11=Transferring Definition to Kerio Control Firewall"
  111.  
  112. REM COMMANDS
  113. :createcommands
  114. REM Creating 1st script
  115. (
  116.      echo /opt/kerio/winroute/tinydbclient "UPDATE Antivir SET Av1Enabled=0"
  117.      echo rm -r /var/winroute/bitdefender/Plugins/
  118.      echo mkdir /var/winroute/bitdefender/Plugins/
  119.      echo mkdir /var/winroute/bitdefender/Plugins/1/
  120.      echo exit
  121. ) >%CommandsDir%\%firstscript%
  122.  
  123. REM Creating 2nd script
  124. (
  125.      echo ln -s /var/winroute/bitdefender/Plugins/1/bdcore.so.linux-x86_64 /var/winroute/bitdefender/Plugins/1/bdcore.so
  126.      echo /opt/kerio/winroute/tinydbclient "UPDATE Antivir SET Av1Enabled=1"
  127.      echo exit
  128. ) >%CommandsDir%\%secondscript%
  129.  
  130. REM Creating UploadFiles script
  131. (
  132.      echo option batch on
  133.      echo option confirm off
  134.      echo open %SSHuser%:%SSHpassword%@%SSHipaddress%:%SSHport% -timeout="%SSHtimeout%" -hostkey="%SSHhostkey%"
  135.      echo option transfer binary
  136.      echo lcd "%DefinitionDir%"
  137.      echo cd /var/winroute/bitdefender/Plugins/1/
  138.      echo put "*.*"
  139.      echo close
  140.      echo exit
  141. ) >%CommandsDir%\%uploadscript%
  142.  
  143. REM Creting Script WGET
  144. (
  145.      echo open %FTPHost% %FTPPort%
  146.      echo %FTPUser%
  147.      echo %FTPPass%
  148.      echo binary
  149.      echo lcd "%DownDir%"
  150.      echo cd /plugins/
  151.      echo get "%PackageWGET32%"
  152.      echo get "%PackageWGET64%"
  153.      echo close
  154.      echo quit
  155. ) >%CommandsDir%\%scriptwget%
  156.  
  157. REM Creating Script ZIP
  158. (
  159.      echo open %FTPHost% %FTPPort%
  160.      echo %FTPUser%
  161.      echo %FTPPass%
  162.      echo binary
  163.      echo lcd "%DownDir%"
  164.      echo cd /plugins/
  165.      echo get "%PackageZIP%"
  166.      echo close
  167.      echo quit
  168. ) >%CommandsDir%\%scriptzip%
  169.  
  170. REM Creating Script Putty
  171. (
  172.      echo open %FTPHost% %FTPPort%
  173.      echo %FTPUser%
  174.      echo %FTPPass%
  175.      echo binary
  176.      echo lcd "%DownDir%"
  177.      echo cd /plugins/
  178.      echo get "%PackagePUTTY32%"
  179.      echo get "%PackagePUTTY64%"
  180.      echo close
  181.      echo quit
  182. ) >%CommandsDir%\%scriptputty%
  183.  
  184. REM Creating Script WinSCP
  185. (
  186.      echo open %FTPHost% %FTPPort%
  187.      echo %FTPUser%
  188.      echo %FTPPass%
  189.      echo binary
  190.      echo lcd "%DownDir%"
  191.      echo cd /plugins/
  192.      echo get "%PackageWINSCP%"
  193.      echo close
  194.      echo quit
  195. ) >%CommandsDir%\%scriptwinscp%
  196. goto internetconnection
  197. REM Checking Connectivity
  198. :internetconnection
  199. cls
  200. @ping -n 1 www.google.com|find "bytes=" >NUL
  201. IF NOT ERRORLEVEL 1 goto check
  202. IF     ERRORLEVEL 1 goto test2
  203.  
  204. :test2
  205. cls
  206. @ping -n 3 www.google.com|find "bytes=" >NUL
  207. IF NOT ERRORLEVEL 1 goto check
  208. IF     ERRORLEVEL 1 goto test3
  209.  
  210. :test3
  211. cls
  212. @ping -n 1 8.8.8.8|find "bytes=" >NUL
  213. IF NOT ERRORLEVEL 1 goto check
  214. IF     ERRORLEVEL 1 goto noconnection
  215.  
  216. REM Checking Binaries
  217. :check
  218. if exist %wget% (
  219.     goto checkzip
  220.     ) else (
  221.         goto nowget
  222. )
  223.  
  224. :checkzip
  225. if exist %zip% (
  226.     goto checkputty
  227.     ) else (
  228.         goto nozip
  229. )
  230.  
  231. :checkputty
  232. if exist %putty% (
  233.     goto checkwinscp
  234.     ) else (
  235.         goto noputty
  236. )
  237.  
  238. :checkwinscp
  239. if exist %winscp% (
  240.     goto download
  241.     ) else (
  242.         goto nowinscp
  243. )
  244.  
  245. REM downloading definition
  246. :download
  247. cls
  248. color 2F
  249. echo #############################################################################################
  250. echo %msg7%
  251. echo #############################################################################################
  252. %wget% -r -S -N -nd -nH --directory-prefix="%DownDir%" "%DownloadDefinition%"
  253. IF NOT ERRORLEVEL 1 goto decompress
  254. IF     ERRORLEVEL 1 goto :nodefinitionhosts
  255.  
  256. REM Decompress definition update
  257. :decompress
  258. TITLE Task BitDefender Definition Update Firewall
  259. cls
  260. color 1F
  261. echo ##############################################################################################
  262. echo %msg8%
  263. echo ##############################################################################################
  264. %zip% x -tzip -y %DownDir%\cumulative.zip -o%DefinitionDir% >nul
  265. goto createremotedir
  266.  
  267. REM Connecting with firewall and upload definition update
  268. :createremotedir
  269. cls
  270. color 4F
  271. echo ##############################################################################################
  272. echo %msg11%
  273. echo ##############################################################################################
  274. %putty% -ssh %SSHuser%@%SSHipaddress% -P %SSHport% -pw %SSHpassword% -m %CommandsDir%\%firstscript%
  275. IF NOT ERRORLEVEL 1 goto uploadfiles
  276. IF     ERRORLEVEL 1 goto nofirewall
  277.  
  278. :uploadfiles
  279. %winscp% /console /script="%CommandsDir%\%uploadscript%"
  280. IF NOT ERRORLEVEL 1 goto definition
  281. IF     ERRORLEVEL 1 goto nofirewall
  282.  
  283. :definition
  284. %putty% -ssh %SSHuser%@%SSHipaddress% -P %SSHport% -pw %SSHpassword% -m %CommandsDir%\%secondscript%
  285. IF NOT ERRORLEVEL 1 goto finalized
  286. IF     ERRORLEVEL 1 goto nofirewall
  287.  
  288. REM negative messages
  289. :nowget
  290. cls
  291. color 4F
  292. echo ##############################################################################################
  293. echo %msg1%
  294. echo ##############################################################################################
  295. ftp -v -i -s:%CommandsDir%\%scriptwget%
  296. PowerShell Expand-Archive -Path "%DownDir%\%PackageWGET32%" -DestinationPath "%BinaryDir%\wget-win32"
  297. PowerShell Expand-Archive -Path "%DownDir%\%PackageWGET64%" -DestinationPath "%BinaryDir%\wget-win64"
  298. goto check
  299.  
  300. :nozip
  301. cls
  302. color 4F
  303. echo ##############################################################################################
  304. echo %msg2%
  305. echo ##############################################################################################
  306. ftp -v -i -s:%CommandsDir%\%scriptzip%
  307. PowerShell Expand-Archive -Path "%DownDir%\%PackageZIP%" -DestinationPath "%BinaryDir%\7z-extra"
  308. goto check
  309.  
  310. :noputty
  311. cls
  312. color 4F
  313. echo ##############################################################################################
  314. echo %msg3%
  315. echo ##############################################################################################
  316. ftp -v -i -s:%CommandsDir%\%scriptputty%
  317. PowerShell Expand-Archive -Path "%DownDir%\%PackagePUTTY32%" -DestinationPath "%BinaryDir%\putty-win32"
  318. PowerShell Expand-Archive -Path "%DownDir%\%PackagePUTTY64%" -DestinationPath "%BinaryDir%\putty-win64"
  319. goto check
  320.  
  321. :nowinscp
  322. cls
  323. color 4F
  324. echo ##############################################################################################
  325. echo %msg4%
  326. echo ##############################################################################################
  327. ftp -v -i -s:%CommandsDir%\%scriptwinscp%
  328. PowerShell Expand-Archive -Path "%DownDir%\%PackageWINSCP%" -DestinationPath "%BinaryDir%\winscp-win32"
  329. goto check
  330.  
  331. :noconnection
  332. cls
  333. color 4F
  334. echo ##############################################################################################
  335. echo %msg5%
  336. echo ##############################################################################################
  337. @timeout /t 15
  338. exit
  339.  
  340. :nofirewall
  341. cls
  342. color 4F
  343. echo ##############################################################################################
  344. echo %msg6%
  345. echo ##############################################################################################
  346. @timeout /t 15
  347. exit
  348.  
  349. :nodefinitionhosts
  350. cls
  351. color 4F
  352. echo ##############################################################################################
  353. echo %msg9%
  354. echo ##############################################################################################
  355. @timeout /t 15
  356. exit
  357.  
  358. REM Positive messages
  359. :finalized
  360. cls
  361. color 5F
  362. echo ##############################################################################################
  363. echo %msg10%
  364. echo ##############################################################################################
  365. @timeout /t 15
  366. exit
RAW Paste Data