From cc6a74e69dc1696db4519a50fa3fb3447fd8a405 Mon Sep 17 00:00:00 2001 From: Stephan Yelle Date: Sat, 25 Jan 2025 19:07:16 -0500 Subject: [PATCH] Update TGBeta.ps1 --- TGBeta.ps1 | 108 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 94 insertions(+), 14 deletions(-) diff --git a/TGBeta.ps1 b/TGBeta.ps1 index 3363fb6..7935174 100644 --- a/TGBeta.ps1 +++ b/TGBeta.ps1 @@ -817,37 +817,56 @@ function GetHtmlContent { }); function toggleOffboardCheckboxes(selectAllCheckbox) { - // Get all checkboxes inside the offboardTab container - const checkboxes = document - .getElementById('offboardTab') - .querySelectorAll('input[type="checkbox"]:not(#selectAllOffboardCheckbox)'); - - // Set the checked state of all checkboxes to match the "Select All" checkbox + const checkboxes = document.querySelectorAll('#offboardTab input[type="checkbox"]:not(#selectAllOffboardCheckbox)'); checkboxes.forEach(checkbox => { checkbox.checked = selectAllCheckbox.checked; }); } - function updateSelectAllOffboard() { const selectAllCheckbox = document.getElementById('selectAllOffboardCheckbox'); - const checkboxes = document - .getElementById('offboardTab') - .querySelectorAll('input[type="checkbox"]:not(#selectAllOffboardCheckbox)'); - - // If any checkbox is unchecked, uncheck "Select All" + const checkboxes = document.querySelectorAll('#offboardTab input[type="checkbox"]:not(#selectAllOffboardCheckbox)'); selectAllCheckbox.checked = Array.from(checkboxes).every(checkbox => checkbox.checked); } - // Attach the updateSelectAllOffboard function to all individual checkboxes document.querySelectorAll('#offboardTab input[type="checkbox"]:not(#selectAllOffboardCheckbox)').forEach(checkbox => { checkbox.addEventListener('change', updateSelectAllOffboard); }); + function triggerOffboard() { - appendLog("testeteteteteteet") + const checkboxes = document.querySelectorAll('#offboardTab input[type="checkbox"]:not(#selectAllOffboardCheckbox)'); + const selectedTasks = Array.from(checkboxes) + .filter(checkbox => checkbox.checked) + .map(checkbox => checkbox.name); + + if (selectedTasks.length === 0) { + appendLog("Please select at least one offboarding task.", "red"); + return; + } + + appendLog("Starting offboarding tasks...", "yellow"); + + fetch('/offboard', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ SelectedTasks: selectedTasks }) + }) + .then(response => { + if (!response.ok) { + throw new Error('Failed to execute offboarding tasks.'); + } + return response.text(); + }) + .then(message => { + appendLog(message, "green"); + }) + .catch(error => { + appendLog("Error: " + error.message, "red"); + }); } + function toggleTweaksCheckboxes(selectAllCheckbox) { // Get all checkboxes inside the tweaksTab container const checkboxes = document @@ -1474,6 +1493,67 @@ try { $response.OutputStream.Close() } + "/offboard" { + if ($request.HttpMethod -eq "POST") { + try { + # Read the Request Body + $bodyStream = New-Object IO.StreamReader $request.InputStream + $body = $bodyStream.ReadToEnd() + $requestData = ConvertFrom-Json $body + + $selectedTasks = $requestData.SelectedTasks + + if (-not $selectedTasks -or $selectedTasks.Count -eq 0) { + $response.StatusCode = 400 + $responseString = "Error: No offboarding tasks selected." + $buffer = [System.Text.Encoding]::UTF8.GetBytes($responseString) + $response.OutputStream.Write($buffer, 0, $buffer.Length) + $response.OutputStream.Close() + return + } + + # Process each selected task + foreach ($task in $selectedTasks) { + switch ($task) { + "uninstallSVSMSPModule" { Uninstall-SVSMSP } + "uninstallThreatLocker" { Uninstall-ThreatLocker } + "uninstallCyberQP" { Uninstall-CyberQP } + "uninstallDattoEDR" { Uninstall-DattoEDR } + "uninstallDattoRMM" { Uninstall-DattoRMM } + "uninstallRocketCyber" { Uninstall-RocketCyber } + "uninstallSplashtop" { Uninstall-Splashtop } + "uninstallSVSHelpdesk" { Uninstall-SVSHelpdesk } + "uninstallSVSWatchtower" { Uninstall-SVSWatchtower } + default { + Write-LogHybrid -Message "Unknown task: $task" -Level "Warning" + } + } + } + + # Return Success Response + $responseString = "Offboarding tasks executed successfully." + $response.StatusCode = 200 + } catch { + $responseString = "Error processing offboarding tasks: $($_.Exception.Message)" + $response.StatusCode = 500 + } + + # Send the Response + $buffer = [System.Text.Encoding]::UTF8.GetBytes($responseString) + $response.ContentType = "text/plain" + $response.ContentLength64 = $buffer.Length + $response.OutputStream.Write($buffer, 0, $buffer.Length) + $response.OutputStream.Close() + } else { + $responseString = "Method not allowed. Use POST." + $response.StatusCode = 405 + $buffer = [System.Text.Encoding]::UTF8.GetBytes($responseString) + $response.OutputStream.Write($buffer, 0, $buffer.Length) + $response.OutputStream.Close() + } + } + + "/runTweaks" { if ($request.HttpMethod -eq "POST") { try {