Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- REM Autor: John LLewelyn
- REM Description: Remote Bitdefender definition updater automation for Kerio Firewall.
- 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.
- REM Requirements: wget, putty, winscp and 7z.
- 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"
- 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.
- REM This script has only been tested on the Microsoft Windows 10 v1709 operating system.
- REM Updated: 01/31/2018
- TITLE Task BitDefender Definition Update Firewall
- REM CONFIGURATION
- REM Settings: Storage unit letter
- set "drive=C"
- REM Settings: Names of Folders
- set "ProjectName=BitDefender"
- set "DownloadFolderName=Downloads"
- set "DefinitionFolderName=Definition"
- set "CommandsFolderName=Commands"
- set "BinFolderName=bin"
- REM Settings: Directory Routes
- set "HomeDir=%drive%:\%ProjectName%"
- set "DownDir=%HomeDir%\%DownloadFolderName%"
- set "DefinitionDir=%HomeDir%\%DefinitionFolderName%"
- set "CommandsDir=%HomeDir%\%CommandsFolderName%"
- set "BinaryDir=%HomeDir%\%BinFolderName%"
- REM Settings: Download Definition
- set "DownloadDefinition=http://download.bitdefender.com/updates/update_av64bit/cumulative.zip"
- REM Settings: Download package complements.
- REM FTP server provider.
- set "FTPHost=compucheap-firewall.ddns.net"
- set "FTPPort=21"
- set "FTPUser=anonymous"
- set "FTPPass=password"
- set "PackageWGET32=wget-1.19.4-win32.zip"
- set "PackageWGET64=wget-1.19.4-win64.zip"
- set "PackageZIP=7z1801-extra.zip"
- set "PackagePUTTY32=putty-0.70-win32.zip"
- set "PackagePUTTY64=putty-0.70-win64.zip"
- set "PackageWINSCP=WinSCP-5.11.3-Portable.zip"
- REM Settings: Script Names Files
- set "firstscript=Part1.txt"
- set "secondscript=Part2.txt"
- set "uploadscript=UploadFiles.txt"
- set "scriptwget=WGET.txt"
- set "scriptzip=7zip.txt"
- set "scriptputty=PUTTY.txt"
- set "scriptwinscp=WINSCP.txt"
- REM Server settings "kerio control firewall" remote ssh
- set "SSHuser=root"
- set "SSHpassword=herepassword"
- set "SSHipaddress=192.168.1.1"
- set "SSHport=22"
- set "SSHhostkey=ssh-rsa 2048 --:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--"
- set "SSHtimeout=1000"
- REM Settings: Required Binaries
- reg Query "HKLM\Hardware\Description\System\CentralProcessor\0" | find /i "x86" > NUL && set OS=32BIT || set OS=64BIT
- if %OS%==32BIT goto plugins32
- if %OS%==64BIT goto plugins64
- :plugins32
- set "wget=%BinaryDir%\wget-win32\wget.exe"
- set "putty=%BinaryDir%\putty-win32\putty.exe"
- set "winscp=%BinaryDir%\winscp-win32\WinSCP.exe"
- set "zip=%BinaryDir%\7z-extra\7za.exe"
- goto clean
- :plugins64
- set "wget=%BinaryDir%\wget-win64\wget.exe"
- set "putty=%BinaryDir%\putty-win64\putty.exe"
- set "winscp=%BinaryDir%\winscp-win32\WinSCP.exe"
- set "zip=%BinaryDir%\7z-extra\x64\7za.exe"
- goto clean
- REM maintenance
- :clean
- RD /S /Q "%CommandsDir%"
- RD /S /Q "%DefinitionDir%"
- REM RD /S /Q "%DownDir%"
- mkdir "%CommandsDir%" >nul
- mkdir "%DownDir%" >nul
- mkdir "%DefinitionDir%" >nul
- mkdir "%BinaryDir%" >nul
- cls
- goto messages
- REM Messages
- :messages
- set "msg1=The package is missing. Downloading the WGET package for Windows, Please Wait..."
- set "msg2=The package is missing. Downloading the 7-Zip package for Windows, Please Wait..."
- set "msg3=The package is missing. Downloading the PUTTY package for Windows, Please Wait..."
- set "msg4=The package is missing. Downloading the WinSCP package for Windows, Please Wait..."
- set "msg5=No internet connection, try later..."
- set "msg6=There is no connection to the Firewall, check its configuration."
- set "msg7=Downloading Definition Update, Please Wait..."
- set "msg8=Uncompressing the Definition, Please Wait..."
- set "msg9=Does not connect with definition host!"
- set "msg10=The definition update was a success!"
- set "msg11=Transferring Definition to Kerio Control Firewall"
- REM COMMANDS
- :createcommands
- REM Creating 1st script
- (
- echo /opt/kerio/winroute/tinydbclient "UPDATE Antivir SET Av1Enabled=0"
- echo rm -r /var/winroute/bitdefender/Plugins/
- echo mkdir /var/winroute/bitdefender/Plugins/
- echo mkdir /var/winroute/bitdefender/Plugins/1/
- echo exit
- ) >%CommandsDir%\%firstscript%
- REM Creating 2nd script
- (
- echo ln -s /var/winroute/bitdefender/Plugins/1/bdcore.so.linux-x86_64 /var/winroute/bitdefender/Plugins/1/bdcore.so
- echo /opt/kerio/winroute/tinydbclient "UPDATE Antivir SET Av1Enabled=1"
- echo exit
- ) >%CommandsDir%\%secondscript%
- REM Creating UploadFiles script
- (
- echo option batch on
- echo option confirm off
- echo open %SSHuser%:%SSHpassword%@%SSHipaddress%:%SSHport% -timeout="%SSHtimeout%" -hostkey="%SSHhostkey%"
- echo option transfer binary
- echo lcd "%DefinitionDir%"
- echo cd /var/winroute/bitdefender/Plugins/1/
- echo put "*.*"
- echo close
- echo exit
- ) >%CommandsDir%\%uploadscript%
- REM Creting Script WGET
- (
- echo open %FTPHost% %FTPPort%
- echo %FTPUser%
- echo %FTPPass%
- echo binary
- echo lcd "%DownDir%"
- echo cd /plugins/
- echo get "%PackageWGET32%"
- echo get "%PackageWGET64%"
- echo close
- echo quit
- ) >%CommandsDir%\%scriptwget%
- REM Creating Script ZIP
- (
- echo open %FTPHost% %FTPPort%
- echo %FTPUser%
- echo %FTPPass%
- echo binary
- echo lcd "%DownDir%"
- echo cd /plugins/
- echo get "%PackageZIP%"
- echo close
- echo quit
- ) >%CommandsDir%\%scriptzip%
- REM Creating Script Putty
- (
- echo open %FTPHost% %FTPPort%
- echo %FTPUser%
- echo %FTPPass%
- echo binary
- echo lcd "%DownDir%"
- echo cd /plugins/
- echo get "%PackagePUTTY32%"
- echo get "%PackagePUTTY64%"
- echo close
- echo quit
- ) >%CommandsDir%\%scriptputty%
- REM Creating Script WinSCP
- (
- echo open %FTPHost% %FTPPort%
- echo %FTPUser%
- echo %FTPPass%
- echo binary
- echo lcd "%DownDir%"
- echo cd /plugins/
- echo get "%PackageWINSCP%"
- echo close
- echo quit
- ) >%CommandsDir%\%scriptwinscp%
- goto internetconnection
- REM Checking Connectivity
- :internetconnection
- cls
- @ping -n 1 www.google.com|find "bytes=" >NUL
- IF NOT ERRORLEVEL 1 goto check
- IF ERRORLEVEL 1 goto test2
- :test2
- cls
- @ping -n 3 www.google.com|find "bytes=" >NUL
- IF NOT ERRORLEVEL 1 goto check
- IF ERRORLEVEL 1 goto test3
- :test3
- cls
- @ping -n 1 8.8.8.8|find "bytes=" >NUL
- IF NOT ERRORLEVEL 1 goto check
- IF ERRORLEVEL 1 goto noconnection
- REM Checking Binaries
- :check
- if exist %wget% (
- goto checkzip
- ) else (
- goto nowget
- )
- :checkzip
- if exist %zip% (
- goto checkputty
- ) else (
- goto nozip
- )
- :checkputty
- if exist %putty% (
- goto checkwinscp
- ) else (
- goto noputty
- )
- :checkwinscp
- if exist %winscp% (
- goto download
- ) else (
- goto nowinscp
- )
- REM downloading definition
- :download
- cls
- color 2F
- echo #############################################################################################
- echo %msg7%
- echo #############################################################################################
- %wget% -r -S -N -nd -nH --directory-prefix="%DownDir%" "%DownloadDefinition%"
- IF NOT ERRORLEVEL 1 goto decompress
- IF ERRORLEVEL 1 goto :nodefinitionhosts
- REM Decompress definition update
- :decompress
- TITLE Task BitDefender Definition Update Firewall
- cls
- color 1F
- echo ##############################################################################################
- echo %msg8%
- echo ##############################################################################################
- %zip% x -tzip -y %DownDir%\cumulative.zip -o%DefinitionDir% >nul
- goto createremotedir
- REM Connecting with firewall and upload definition update
- :createremotedir
- cls
- color 4F
- echo ##############################################################################################
- echo %msg11%
- echo ##############################################################################################
- %putty% -ssh %SSHuser%@%SSHipaddress% -P %SSHport% -pw %SSHpassword% -m %CommandsDir%\%firstscript%
- IF NOT ERRORLEVEL 1 goto uploadfiles
- IF ERRORLEVEL 1 goto nofirewall
- :uploadfiles
- %winscp% /console /script="%CommandsDir%\%uploadscript%"
- IF NOT ERRORLEVEL 1 goto definition
- IF ERRORLEVEL 1 goto nofirewall
- :definition
- %putty% -ssh %SSHuser%@%SSHipaddress% -P %SSHport% -pw %SSHpassword% -m %CommandsDir%\%secondscript%
- IF NOT ERRORLEVEL 1 goto finalized
- IF ERRORLEVEL 1 goto nofirewall
- REM negative messages
- :nowget
- cls
- color 4F
- echo ##############################################################################################
- echo %msg1%
- echo ##############################################################################################
- ftp -v -i -s:%CommandsDir%\%scriptwget%
- PowerShell Expand-Archive -Path "%DownDir%\%PackageWGET32%" -DestinationPath "%BinaryDir%\wget-win32"
- PowerShell Expand-Archive -Path "%DownDir%\%PackageWGET64%" -DestinationPath "%BinaryDir%\wget-win64"
- goto check
- :nozip
- cls
- color 4F
- echo ##############################################################################################
- echo %msg2%
- echo ##############################################################################################
- ftp -v -i -s:%CommandsDir%\%scriptzip%
- PowerShell Expand-Archive -Path "%DownDir%\%PackageZIP%" -DestinationPath "%BinaryDir%\7z-extra"
- goto check
- :noputty
- cls
- color 4F
- echo ##############################################################################################
- echo %msg3%
- echo ##############################################################################################
- ftp -v -i -s:%CommandsDir%\%scriptputty%
- PowerShell Expand-Archive -Path "%DownDir%\%PackagePUTTY32%" -DestinationPath "%BinaryDir%\putty-win32"
- PowerShell Expand-Archive -Path "%DownDir%\%PackagePUTTY64%" -DestinationPath "%BinaryDir%\putty-win64"
- goto check
- :nowinscp
- cls
- color 4F
- echo ##############################################################################################
- echo %msg4%
- echo ##############################################################################################
- ftp -v -i -s:%CommandsDir%\%scriptwinscp%
- PowerShell Expand-Archive -Path "%DownDir%\%PackageWINSCP%" -DestinationPath "%BinaryDir%\winscp-win32"
- goto check
- :noconnection
- cls
- color 4F
- echo ##############################################################################################
- echo %msg5%
- echo ##############################################################################################
- @timeout /t 15
- exit
- :nofirewall
- cls
- color 4F
- echo ##############################################################################################
- echo %msg6%
- echo ##############################################################################################
- @timeout /t 15
- exit
- :nodefinitionhosts
- cls
- color 4F
- echo ##############################################################################################
- echo %msg9%
- echo ##############################################################################################
- @timeout /t 15
- exit
- REM Positive messages
- :finalized
- cls
- color 5F
- echo ##############################################################################################
- echo %msg10%
- echo ##############################################################################################
- @timeout /t 15
- exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement