Update TGBeta.ps1

This commit is contained in:
2025-01-28 01:15:11 -05:00
parent 491e23ef72
commit d75cf87695

View File

@@ -410,9 +410,29 @@ function Install-SVSMSP {
# - "/installrmm": Handles RMM installation with dynamic parameters. # - "/installrmm": Handles RMM installation with dynamic parameters.
# - Additional routes for tweaks and other tasks. # - Additional routes for tweaks and other tasks.
# Listener initialization$listener = New-Object System.Net.HttpListener ### Listener Initialization with Error Handling
$listener.Prefixes.Add("http://localhost:8081/") try {
$listener.Start() # Create a new HttpListener object
$listener = New-Object System.Net.HttpListener
# Check if the object was successfully created
if (-not $listener) {
throw "Failed to initialize HttpListener."
}
# Add prefix for the listener
$listener.Prefixes.Add("http://localhost:8081/")
Write-LogHybrid -Message "Listener initialized with prefix http://localhost:8081/" -Level "Info"
# Start the listener
$listener.Start()
Write-LogHybrid -Message "Listener started successfully." -Level "Info"
} catch {
# Log the error and rethrow it for visibility
Write-LogHybrid -Message "Critical error initializing listener: $($_.Exception.Message)" -Level "Error"
throw $_
}
function Get-N8nWebhookData { function Get-N8nWebhookData {
@@ -1950,6 +1970,17 @@ catch {
} }
finally { finally {
if ($listener -ne $null) {
try {
Write-LogHybrid -Message "Stopping the listener." -Level "Info"
$listener.Stop() $listener.Stop()
$listener.Close() $listener.Close()
Write-LogHybrid -Message "Listener stopped successfully." -Level "Info"
} catch {
Write-LogHybrid -Message "Error stopping the listener: $($_.Exception.Message)" -Level "Error"
}
} else {
Write-LogHybrid -Message "Listener object is null; nothing to stop." -Level "Warning"
}
} }