Update SVSTaskGate.ps1

This commit is contained in:
2025-01-10 22:54:43 -05:00
parent 9d662084b7
commit bc59f69052

View File

@@ -1,25 +1,13 @@
### To Modify of January 5 2025
### set the priority in the js code so it waits for one function to complete before starting the next one
### let's start thinking about the write-log -TaskCategory "On-boarding" or "Off-boarding"
### need new logo and the RGB color codes form john
### add tweak to set default provider, add to toolkit?
### add an "off board" button
### add "run tweaks" button
### need RGB color codes form john
### add the .net silent install tweaks to toolkit
### for the reg tweak need to do/undo function maybe it should have it own check box list
### new tab for client apps?
#############################################################
### Changes done
### minor change the the param of install-svsmsp
### commented out line 64
### moved logo to the left in line 384
#region Write-Log
# ---------------------------------------------------------------------------
# 1) CREATE A GLOBAL LOG CACHE (NEW)
# ---------------------------------------------------------------------------
@@ -143,6 +131,10 @@ else {
# Example usage of Write-LogHybrid
Write-LogHybrid -Message "Starting SVS TaskGate" -Level "Info" -TaskCategory "SVSTaskGate" -LogToEvent:$true
#endregion
#region SVS Module
function Install-SVSMSP {
param (
@@ -202,6 +194,9 @@ function Install-SVSMSP {
[string]$ApiSecretKey
)
function Perform-Cleanup {
Write-LogHybrid -Message "Cleanup mode enabled. Starting cleanup process..." -Level "Info" -LogToEvent
@@ -319,9 +314,7 @@ function Install-SVSMSP {
Write-LogHybrid -Message "No specific mode specified. Defaulting to toolkit installation mode..." -Level "Info" -LogToEvent
Perform-ToolkitInstallation
}
# Install-SVSMSP -InstallToolkit
#endregion SVS Module
# ----------------------------------------------------------------------------------
# START THE LISTENER
@@ -501,7 +494,7 @@ function GetHtmlContent {
</head>
<body>
<div class="logo-container">
<img src="https://git.svstools.com/syelle/Logo/raw/branch/main/SVS_Logo.svg" alt="SVS Logo">
<img src="https://git.svstools.com/syelle/Logo/raw/branch/main/SVS_logo.svg" alt="SVS Logo">
</div>
<div class="container">
<div class="sidebar">
@@ -589,9 +582,7 @@ function GetHtmlContent {
<button class="install-button" onclick="triggerInstall()">Install</button>
</div>
<div class="log" id="logArea">
<p>Logs will appear here...</p>
</div>
</div>
<!-- Off-Boarding Tab -->
<div id="offboardTab" class="tab-content inactive">
@@ -609,6 +600,9 @@ function GetHtmlContent {
<input type="checkbox" name="uninstallThreatLocker" id="uninstallThreatLockerCheckbox">
Uninstall ThreatLocker
</label>
<div class="button-group">
<button class="install-button" onclick="triggerOffboard()">Offboard</button>
</div>
</div>
</div>
<!-- tweaks Tab -->
@@ -620,8 +614,8 @@ function GetHtmlContent {
Select All
</label>
<label>
<input type="checkbox" name="enableDarkMode" id="enableDarkModeCheckbox">
Enable Dark Mode
<input type="checkbox" name="setedgedefaultsearch" id="setedgedefaultsearchCheckbox">
Set Edge Default Search Engine
</label>
<label>
<input type="checkbox" name="disableAnimations" id="disableAnimationsCheckbox">
@@ -636,11 +630,19 @@ function GetHtmlContent {
Increase Font Size
</label>
</div>
<div class="button-group">
<button class="install-button" onclick="triggerTweaks()">Tweaks</button>
</div>
</div>
<!-- Shared Exit Button -->
<div class="button-group">
<button class="exit-button" onclick="endSession()">Exit</button>
</div>
<!-- Log Area -->
<div class="log" id="logArea">
<p>Logs will appear here...</p>
</div>
</div>
<script>
@@ -713,6 +715,10 @@ function GetHtmlContent {
checkbox.addEventListener('change', updateSelectAllOffboard);
});
function triggerOffboard() {
appendLog("testeteteteteteet")
}
function toggleTweaksCheckboxes(selectAllCheckbox) {
// Get all checkboxes inside the tweaksTab container
const checkboxes = document
@@ -740,6 +746,15 @@ function GetHtmlContent {
checkbox.addEventListener('change', updateSelectAllTweaks);
});
function triggerTweaks() {
const setedgedefaultsearch = document.querySelector('input[name="setedgedefaultsearch"]');
if (setedgedefaultsearch.checked) {
fetch('/setedgedefaultsearch', { method: 'GET' })
}
}
function toggleDattoRMMOptions() {
const checkbox = document.getElementById('installDattoRMMCheckbox');
@@ -822,78 +837,130 @@ function GetHtmlContent {
}
}
function triggerInstall() {
const dropdown = document.getElementById('dattoRmmDropdown');
const UID = dropdown.options[dropdown.selectedIndex].value;
const Name = dropdown.options[dropdown.selectedIndex].text;
const UID = dropdown && dropdown.options[dropdown.selectedIndex]
? dropdown.options[dropdown.selectedIndex].value
: null;
const Name = dropdown && dropdown.options[dropdown.selectedIndex]
? dropdown.options[dropdown.selectedIndex].text
: null;
const setSVSPowerplan = document.querySelector('input[name="setSVSPowerplan"]');
const installSVSMSPModule = document.querySelector('input[name="installSVSMSPModule"]');
const installDattoRMM = document.querySelector('input[name="installDattoRMM"]');
const installCyberQP = document.querySelector('input[name="installCyberQP"]');
const installSplashtop = document.querySelector('input[name="installSplashtop"]');
const installSVSHelpDesk = document.querySelector('input[name="installSVSHelpDesk"]');
const installSVSWatchtower = document.querySelector('input[name="installSVSWatchtower"]');
const installThreatLocker = document.querySelector('input[name="installThreatLocker"]');
const installRocketCyber = document.querySelector('input[name="installRocketCyber"]');
// Priority 1: Install SVSMSP Module
if (installSVSMSPModule.checked) {
appendLog("Installing SVSMSP Module (Priority 1)...", "cyan");
fetch('/installSVSMSPModule', { method: 'GET' })
(async () => {
// Priority 1: Install SVSMSP Module
if (document.querySelector('input[name="installSVSMSPModule"]').checked) {
appendLog("Installing SVSMSP Module (Priority 1)...", "cyan");
try {
await fetch('/installSVSMSPModule', { method: 'GET' });
appendLog("SVSMSP Module installation completed.", "green");
} catch (error) {
appendLog("Error installing SVSMS", "red");
}
// Priority 2: Install DattoRMM
if (installDattoRMM.checked) {
const DattoRMMCheckbox = document.querySelectorAll('input[name="dattoRMMOption"]:checked');
appendLog("Installing selected site RMM (Priority 2)...", "cyan");
const checkedValues = Array.from(DattoRMMCheckbox).map(c => c.value);
const payload = {
checkedValues, // Array of selected checkbox values
UID, // Selected site UID
Name // Selected site name
};
fetch('/installrmm', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
})
}
// Lower-priority tasks
if (setSVSPowerplan.checked) {
fetch('/SetSVSPowerplan', { method: 'GET' })
}
if (installCyberQP.checked) {
fetch('/installCyberQP', { method: 'GET' })
}
if (installSplashtop.checked) {
fetch('/installSplashtop', { method: 'GET' })
}
if (installSVSHelpDesk.checked) {
fetch('/installSVSHelpDesk', { method: 'GET' })
}
if (installSVSWatchtower.checked) {
fetch('/installSVSWatchtower', { method: 'GET' })
}
if (installThreatLocker.checked) {
fetch('/installThreatLocker', { method: 'GET' })
}
if (installRocketCyber.checked) {
fetch('/installRocketCyber', { method: 'GET' })
}
}
// Priority 2: Install DattoRMM
if (document.querySelector('input[name="installDattoRMM"]').checked) {
appendLog("Installing DattoRMM (Priority 2)...", "cyan");
try {
const DattoRMMCheckbox = document.querySelectorAll('input[name="dattoRMMOption"]:checked');
const checkedValues = Array.from(DattoRMMCheckbox).map(c => c.value);
const payload = {
checkedValues,
UID,
Name
};
await fetch('/installrmm', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
appendLog("DattoRMM installation completed.", "green");
} catch (error) {
appendLog("Error installing DattoRMM: ${error.message}", "red");
}
}
// Priority 3: Other tasks
if (document.querySelector('input[name="setSVSPowerplan"]').checked) {
appendLog("Setting SVS Powerplan (Priority 3)...", "cyan");
try {
await fetch('/SetSVSPowerplan', { method: 'GET' });
appendLog("SVS Powerplan set successfully.", "green");
} catch (error) {
appendLog("Error setting SVS Powerplan: ${error.message}", "red");
}
}
if (document.querySelector('input[name="installCyberQP"]').checked) {
appendLog("Installing CyberQP (Priority 3)...", "cyan");
try {
await fetch('/installCyberQP', { method: 'GET' });
appendLog("CyberQP installation completed.", "green");
} catch (error) {
appendLog("Error installing CyberQP: ${error.message}", "red");
}
}
if (document.querySelector('input[name="installSplashtop"]').checked) {
appendLog("Installing Splashtop (Priority 3)...", "cyan");
try {
await fetch('/installSplashtop', { method: 'GET' });
appendLog("Splashtop installation completed.", "green");
} catch (error) {
appendLog("Error installing Splashtop: ${error.message}", "red");
}
}
if (document.querySelector('input[name="installSVSHelpDesk"]').checked) {
appendLog("Installing SVS HelpDesk (Priority 3)...", "cyan");
try {
await fetch('/installSVSHelpDesk', { method: 'GET' });
appendLog("SVS HelpDesk installation completed.", "green");
} catch (error) {
appendLog("Error installing SVS HelpDesk: ${error.message}", "red");
}
}
if (document.querySelector('input[name="installSVSWatchtower"]').checked) {
appendLog("Installing SVS Watchtower (Priority 3)...", "cyan");
try {
await fetch('/installSVSWatchtower', { method: 'GET' });
appendLog("SVS Watchtower installation completed.", "green");
} catch (error) {
appendLog("Error installing SVS Watchtower: ${error.message}", "red");
}
}
if (document.querySelector('input[name="installThreatLocker"]').checked) {
appendLog("Installing ThreatLocker (Priority 3)...", "cyan");
try {
await fetch('/installThreatLocker', { method: 'GET' });
appendLog("ThreatLocker installation completed.", "green");
} catch (error) {
appendLog("Error installing ThreatLocker: ${error.message}", "red");
}
}
if (document.querySelector('input[name="installRocketCyber"]').checked) {
appendLog("Installing RocketCyber (Priority 3)...", "cyan");
try {
await fetch('/installRocketCyber', { method: 'GET' });
appendLog("RocketCyber installation completed.", "green");
} catch (error) {
appendLog("Error installing RocketCyber: ${error.message}", "red");
}
}
})();
}
function endSession() {
appendLog("Session ended. Closing application...", "yellow");
fetch('/quit', { method: 'GET' })
@@ -914,6 +981,11 @@ function GetHtmlContent {
});
function appendLog(message, color = "white") {
const log = document.createElement('p');
log.style.color = color;
@@ -1207,6 +1279,29 @@ try {
$response.OutputStream.Close()
}
"/setedgedefaultsearch"{
if ($request.HttpMethod -eq "GET") {
write-host "it attempted it!"
try {
set-EdgeDefaultSearchProvider
$responseString = "setedgedefaultsearch triggered successfully."
$response.StatusCode = 200
} catch {
$responseString = "Error triggering Install ThreatLocker: $_"
$response.StatusCode = 500
}
} else {
$responseString = "Method not allowed. Use GET."
$response.StatusCode = 405
}
$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()
}
"/installSVSHelpDesk" {
if ($request.HttpMethod -eq "GET") {
try {
@@ -1250,6 +1345,74 @@ try {
$response.OutputStream.Close()
}
"/runTweaks" {
if ($request.HttpMethod -eq "POST") {
try {
# Step 1: Read the Request Body
$bodyStream = New-Object IO.StreamReader $request.InputStream
$body = $bodyStream.ReadToEnd()
$requestData = ConvertFrom-Json $body
# Step 2: Validate Input
$tweaks = $requestData.tweaks
if (-not $tweaks -or $tweaks.Count -eq 0) {
$response.StatusCode = 400
$responseString = "Error: No tweaks selected."
$buffer = [System.Text.Encoding]::UTF8.GetBytes($responseString)
$response.OutputStream.Write($buffer, 0, $buffer.Length)
$response.OutputStream.Close()
return
}
# Step 3: Run Selected Tweaks
foreach ($tweak in $tweaks) {
switch ($tweak) {
"enableDarkModeCheckbox" {
Write-LogHybrid -Message "Running tweak: Set Edge Default Search Engine" -Level "Info"
Set-EdgeDefaultSearchEngine
}
"disableAnimationsCheckbox" {
Write-LogHybrid -Message "Running tweak: Disable Animations" -Level "Info"
#Disable-Animations
}
"optimizePerformanceCheckbox" {
Write-LogHybrid -Message "Running tweak: Optimize Performance" -Level "Info"
#Optimize-Performance
}
"increaseFontSizeCheckbox" {
Write-LogHybrid -Message "Running tweak: Increase Font Size" -Level "Info"
#Increase-FontSize
}
default {
Write-LogHybrid -Message "Unknown tweak: $tweak" -Level "Warning"
}
}
}
# Step 4: Return Success Response
$responseString = "Selected tweaks executed successfully."
$response.StatusCode = 200
} catch {
$responseString = "Error processing tweaks: $($_.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()
}
}
# ----------------------------------------------------------------
# 4) NEW ROUTE: /getLogs
# Returns $Global:LogCache as JSON for the polling function