Created
March 28, 2025 18:14
-
-
Save greenido/5c1bb2ba59b340943626e1f45481990a to your computer and use it in GitHub Desktop.
BitDefender Alert Test Setup and Execution Script - Install NodeJS (if we don't have it) and fetch testing script and run it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# BitDefender Alert Test Setup and Execution Script | |
param( | |
[string]$GistUrl = "https://gist.githubusercontent.com/greenido/044823b9e1ab3c409fe4d3b04dad8292/raw/638b7199564efc59062b1d314f4aec567863d748/test-bitDefender.js", | |
[string]$ScriptName = "bitdefender_alert_test.js" | |
) | |
# Function to check if Node.js is installed | |
function Test-NodeJSInstalled { | |
try { | |
$nodeVersion = node --version | |
return $true | |
} | |
catch { | |
return $false | |
} | |
} | |
# Function to install Node.js using Chocolatey | |
function Install-NodeJS { | |
# Check if Chocolatey is installed | |
if (!(Get-Command choco -ErrorAction SilentlyContinue)) { | |
Write-Host "Installing Chocolatey package manager..." -ForegroundColor Yellow | |
# PowerShell script to install Chocolatey | |
Set-ExecutionPolicy Bypass -Scope Process -Force | |
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 | |
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) | |
} | |
# Install Node.js using Chocolatey | |
Write-Host "Installing Node.js..." -ForegroundColor Green | |
choco install nodejs -y | |
} | |
# Function to download script from Gist | |
function Download-BitDefenderScript { | |
param( | |
[string]$Url, | |
[string]$OutputFile | |
) | |
try { | |
Write-Host "Downloading BitDefender alert test script..." -ForegroundColor Cyan | |
Invoke-WebRequest -Uri $Url -OutFile $OutputFile | |
if (Test-Path $OutputFile) { | |
Write-Host "Script downloaded successfully: $OutputFile" -ForegroundColor Green | |
return $true | |
} | |
else { | |
Write-Host "Failed to download script" -ForegroundColor Red | |
return $false | |
} | |
} | |
catch { | |
Write-Host "Error downloading script: $($_.Exception.Message)" -ForegroundColor Red | |
return $false | |
} | |
} | |
# Function to install Winston logging library | |
function Install-WinstonLibrary { | |
param( | |
[string]$ScriptDirectory | |
) | |
Write-Host "Installing Winston logging library..." -ForegroundColor Cyan | |
# Change to script directory | |
Push-Location $ScriptDirectory | |
# Initialize npm project if not exists | |
if (!(Test-Path "package.json")) { | |
npm init -y | |
} | |
# Install winston | |
npm install winston | |
Pop-Location | |
} | |
# Function to validate downloaded script | |
function Test-ScriptIntegrity { | |
param( | |
[string]$ScriptPath | |
) | |
try { | |
$scriptContent = Get-Content $ScriptPath -Raw | |
# Basic integrity checks | |
if ($scriptContent -match 'class BitDefenderAlertSimulator') { | |
Write-Host "Script integrity verified." -ForegroundColor Green | |
return $true | |
} | |
else { | |
Write-Host "Script integrity check failed." -ForegroundColor Red | |
return $false | |
} | |
} | |
catch { | |
Write-Host "Error checking script integrity: $($_.Exception.Message)" -ForegroundColor Red | |
return $false | |
} | |
} | |
# Main script execution | |
function Main { | |
# Determine script directory | |
$ScriptDirectory = Split-Path -Parent $PSCommandPath | |
# Full path for the script | |
$ScriptPath = Join-Path $ScriptDirectory $ScriptName | |
# Check if Node.js is installed | |
if (!(Test-NodeJSInstalled)) { | |
Write-Host "Node.js not found. Proceeding with installation..." -ForegroundColor Yellow | |
Install-NodeJS | |
# Refresh environment variables | |
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") | |
} | |
else { | |
Write-Host "Node.js is already installed." -ForegroundColor Green | |
} | |
# Download the script | |
$downloadSuccess = Download-BitDefenderScript -Url $GistUrl -OutputFile $ScriptPath | |
# Validate downloaded script | |
if ($downloadSuccess) { | |
$scriptValid = Test-ScriptIntegrity -ScriptPath $ScriptPath | |
if ($scriptValid) { | |
# Install Winston library | |
Install-WinstonLibrary -ScriptDirectory $ScriptDirectory | |
# Run the BitDefender alert test script | |
Write-Host "Running BitDefender Alert Test Script..." -ForegroundColor Magenta | |
node $ScriptPath | |
} | |
else { | |
Write-Host "Script validation failed. Aborting execution." -ForegroundColor Red | |
} | |
} | |
else { | |
Write-Host "Failed to download or process the script." -ForegroundColor Red | |
} | |
} | |
# Execute the main function | |
Main | |
# Optional: Pause to view results (comment out in production) | |
Read-Host "Press Enter to exit..." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment