Update TGBeta.ps1
This commit is contained in:
413
TGBeta.ps1
413
TGBeta.ps1
@@ -822,76 +822,62 @@ function GetHtmlContent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function triggerInstall() {
|
async function triggerInstall() {
|
||||||
const dropdown = document.getElementById('dattoRmmDropdown');
|
const dropdown = document.getElementById('dattoRmmDropdown');
|
||||||
const UID = dropdown.options[dropdown.selectedIndex].value;
|
const UID = dropdown.options[dropdown.selectedIndex]?.value || null;
|
||||||
const Name = dropdown.options[dropdown.selectedIndex].text;
|
const Name = dropdown.options[dropdown.selectedIndex]?.text || null;
|
||||||
|
|
||||||
const setSVSPowerplan = document.querySelector('input[name="setSVSPowerplan"]');
|
const tasks = [];
|
||||||
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 (document.querySelector('input[name="installSVSMSPModule"]').checked) {
|
||||||
if (installSVSMSPModule.checked) {
|
tasks.push({ name: "installSVSMSPModule", priority: 1 });
|
||||||
appendLog("Installing SVSMSP Module (Priority 1)...", "cyan");
|
|
||||||
fetch('/installSVSMSPModule', { method: 'GET' })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Priority 2: Install DattoRMM
|
if (document.querySelector('input[name="installDattoRMM"]').checked) {
|
||||||
if (installDattoRMM.checked) {
|
const selectedOptions = Array.from(document.querySelectorAll('input[name="dattoRMMOption"]:checked'))
|
||||||
const DattoRMMCheckbox = document.querySelectorAll('input[name="dattoRMMOption"]:checked');
|
.map(option => option.value);
|
||||||
appendLog("Installing selected site RMM (Priority 2)...", "cyan");
|
|
||||||
|
|
||||||
const checkedValues = Array.from(DattoRMMCheckbox).map(c => c.value);
|
tasks.push({
|
||||||
|
name: "installDattoRMM",
|
||||||
|
priority: 2,
|
||||||
|
details: { UID, Name, options: selectedOptions },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const payload = {
|
if (document.querySelector('input[name="setSVSPowerplan"]').checked) {
|
||||||
checkedValues, // Array of selected checkbox values
|
tasks.push({ name: "setSVSPowerplan", priority: 3 });
|
||||||
UID, // Selected site UID
|
}
|
||||||
Name // Selected site name
|
|
||||||
};
|
|
||||||
|
|
||||||
fetch('/installrmm', {
|
if (document.querySelector('input[name="installCyberQP"]').checked) {
|
||||||
|
tasks.push({ name: "installCyberQP", priority: 4 });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (document.querySelector('input[name="installRocketCyber"]').checked) {
|
||||||
|
tasks.push({ name: "installRocketCyber", priority: 5 });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (document.querySelector('input[name="installThreatLocker"]').checked) {
|
||||||
|
tasks.push({ name: "installThreatLocker", priority: 6 });
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch('/executeTasks', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify(payload)
|
body: JSON.stringify({ tasks }),
|
||||||
})
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error("Failed to execute tasks.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lower-priority tasks
|
const result = await response.json();
|
||||||
if (setSVSPowerplan.checked) {
|
console.log(result);
|
||||||
fetch('/SetSVSPowerplan', { method: 'GET' })
|
appendLog("All tasks completed successfully.", "green");
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
appendLog(`Error executing tasks: ${error.message}`, "red");
|
||||||
}
|
}
|
||||||
|
|
||||||
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' })
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function endSession() {
|
function endSession() {
|
||||||
@@ -1000,120 +986,89 @@ try {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
"/installSVSMSPModule" {
|
function Execute-Task {
|
||||||
if ($request.HttpMethod -eq "GET") {
|
param (
|
||||||
|
[string]$TaskName,
|
||||||
|
[hashtable]$Details
|
||||||
|
)
|
||||||
|
|
||||||
|
switch ($TaskName) {
|
||||||
|
"installSVSMSPModule" {
|
||||||
|
Write-LogHybrid -Message "Starting task: $TaskName" -Level "Info"
|
||||||
|
# Add your task execution logic here
|
||||||
|
Start-Sleep -Seconds 2 # Simulate task execution
|
||||||
|
Write-LogHybrid -Message "Completed task: $TaskName" -Level "Success"
|
||||||
|
}
|
||||||
|
"installDattoRMM" {
|
||||||
|
Write-LogHybrid -Message "Starting task: $TaskName" -Level "Info"
|
||||||
|
$UID = $Details["UID"]
|
||||||
|
$Name = $Details["Name"]
|
||||||
|
$Options = $Details["options"]
|
||||||
|
# Add your task execution logic here
|
||||||
|
Start-Sleep -Seconds 3 # Simulate task execution
|
||||||
|
Write-LogHybrid -Message "Completed task: $TaskName for site $Name (UID: $UID)" -Level "Success"
|
||||||
|
}
|
||||||
|
"setSVSPowerplan" {
|
||||||
|
Write-LogHybrid -Message "Starting task: $TaskName" -Level "Info"
|
||||||
|
# Add your task execution logic here
|
||||||
|
Start-Sleep -Seconds 1 # Simulate task execution
|
||||||
|
Write-LogHybrid -Message "Completed task: $TaskName" -Level "Success"
|
||||||
|
}
|
||||||
|
"installCyberQP" {
|
||||||
|
Write-LogHybrid -Message "Starting task: $TaskName" -Level "Info"
|
||||||
|
# Add your task execution logic here
|
||||||
|
Start-Sleep -Seconds 2 # Simulate task execution
|
||||||
|
Write-LogHybrid -Message "Completed task: $TaskName" -Level "Success"
|
||||||
|
}
|
||||||
|
"installRocketCyber" {
|
||||||
|
Write-LogHybrid -Message "Starting task: $TaskName" -Level "Info"
|
||||||
|
# Add your task execution logic here
|
||||||
|
Start-Sleep -Seconds 2 # Simulate task execution
|
||||||
|
Write-LogHybrid -Message "Completed task: $TaskName" -Level "Success"
|
||||||
|
}
|
||||||
|
"installThreatLocker" {
|
||||||
|
Write-LogHybrid -Message "Starting task: $TaskName" -Level "Info"
|
||||||
|
# Add your task execution logic here
|
||||||
|
Start-Sleep -Seconds 2 # Simulate task execution
|
||||||
|
Write-LogHybrid -Message "Completed task: $TaskName" -Level "Success"
|
||||||
|
}
|
||||||
|
default {
|
||||||
|
Write-LogHybrid -Message "Unknown task: $TaskName" -Level "Warning"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Execute-PrioritizedTasks {
|
||||||
|
param (
|
||||||
|
[Parameter(Mandatory = $true)]
|
||||||
|
[array]$Tasks
|
||||||
|
)
|
||||||
|
|
||||||
|
$SortedTasks = $Tasks | Sort-Object -Property priority
|
||||||
|
|
||||||
|
foreach ($task in $SortedTasks) {
|
||||||
|
$TaskName = $task.name
|
||||||
|
$Details = $task.details
|
||||||
|
Execute-Task -TaskName $TaskName -Details $Details
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Output "All tasks completed."
|
||||||
|
}
|
||||||
|
|
||||||
|
# Route to handle incoming task execution request
|
||||||
|
if ($request.HttpMethod -eq "POST" -and $request.Url.AbsolutePath -eq "/executeTasks") {
|
||||||
try {
|
try {
|
||||||
Install-SVSMSP -InstallToolkit
|
$body = Get-Content -Raw -Path $request.InputStream | ConvertFrom-Json
|
||||||
$responseString = "Install SVSMSP Module triggered successfully."
|
$Tasks = $body.tasks
|
||||||
|
Execute-PrioritizedTasks -Tasks $Tasks
|
||||||
|
|
||||||
|
$responseString = "All tasks executed successfully."
|
||||||
$response.StatusCode = 200
|
$response.StatusCode = 200
|
||||||
} catch {
|
} catch {
|
||||||
$responseString = "Error triggering Install SVSMSP Module: $_"
|
$responseString = "Error executing tasks: $($_.Exception.Message)"
|
||||||
$response.StatusCode = 500
|
$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()
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
"/installrmm" {
|
|
||||||
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: Extract Data from the Request
|
|
||||||
$checkedValues = $requestData.checkedValues
|
|
||||||
$UID = $requestData.UID
|
|
||||||
$Name = $requestData.Name
|
|
||||||
|
|
||||||
# Step 3: Validate Input
|
|
||||||
if (-not $checkedValues -or -not $UID -or -not $Name) {
|
|
||||||
Write-LogHybrid -Message "Invalid input received. Missing required parameters: UID, Name, or checkbox values." -Level "Error"
|
|
||||||
$response.StatusCode = 400
|
|
||||||
$responseString = "Error: Missing required input parameters."
|
|
||||||
$buffer = [System.Text.Encoding]::UTF8.GetBytes($responseString)
|
|
||||||
$response.OutputStream.Write($buffer, 0, $buffer.Length)
|
|
||||||
$response.OutputStream.Close()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
# Step 4: Build the PowerShell Command Dynamically
|
|
||||||
$installRMMCommand = "Install-DattoRMM -ApiUrl '$ApiUrl' -ApiKey '$ApiKey' -ApiSecretKey '$ApiSecretKey' -SiteName $Name -SiteUID $UID "
|
|
||||||
|
|
||||||
if ($checkedValues -contains 'inputVar') {
|
|
||||||
$installRMMCommand += " -PushSiteVars"
|
|
||||||
}
|
|
||||||
if ($checkedValues -contains 'rmm') {
|
|
||||||
$installRMMCommand += " -InstallRMM"
|
|
||||||
}
|
|
||||||
if ($checkedValues -contains 'exe') {
|
|
||||||
$installRMMCommand += " -SaveCopy"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Step 5: Execute the Command
|
|
||||||
try {
|
|
||||||
Invoke-Expression $installRMMCommand
|
|
||||||
$responseString = "RMM installation triggered successfully for $Name."
|
|
||||||
Write-LogHybrid -Message $responseString -Level "Success"
|
|
||||||
$response.StatusCode = 200
|
|
||||||
} catch {
|
|
||||||
$responseString = "Error triggering RMM installation: $($_.Exception.Message)"
|
|
||||||
Write-LogHybrid -Message $responseString -Level "Error"
|
|
||||||
$response.StatusCode = 500
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
# Log General Errors
|
|
||||||
$errorString = "An error occurred while processing the /installrmm request: $($_.Exception.Message)"
|
|
||||||
Write-LogHybrid -Message $errorString -Level "Error"
|
|
||||||
$response.StatusCode = 500
|
|
||||||
$responseString = $errorString
|
|
||||||
}
|
|
||||||
|
|
||||||
# Step 6: Return 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 {
|
|
||||||
# Handle Invalid HTTP Methods
|
|
||||||
$response.StatusCode = 405
|
|
||||||
$response.StatusDescription = "Method Not Allowed"
|
|
||||||
$responseString = "Error: Only POST requests are allowed."
|
|
||||||
$buffer = [System.Text.Encoding]::UTF8.GetBytes($responseString)
|
|
||||||
$response.OutputStream.Write($buffer, 0, $buffer.Length)
|
|
||||||
$response.OutputStream.Close()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"/setSVSPowerplan" {
|
|
||||||
if ($request.HttpMethod -eq "GET") {
|
|
||||||
|
|
||||||
try {
|
|
||||||
Set-SVSPowerPlan
|
|
||||||
$responseString = "Setting SVS PowerPlan triggered successfully."
|
|
||||||
$response.StatusCode = 200
|
|
||||||
} catch {
|
|
||||||
$responseString = "Error triggering Setting SVS PowerPlan: $_"
|
|
||||||
$response.StatusCode = 500
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$responseString = "Method not allowed. Use GET."
|
|
||||||
$response.StatusCode = 405
|
|
||||||
}
|
|
||||||
$buffer = [System.Text.Encoding]::UTF8.GetBytes($responseString)
|
$buffer = [System.Text.Encoding]::UTF8.GetBytes($responseString)
|
||||||
$response.ContentType = "text/plain"
|
$response.ContentType = "text/plain"
|
||||||
$response.ContentLength64 = $buffer.Length
|
$response.ContentLength64 = $buffer.Length
|
||||||
@@ -1122,134 +1077,6 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
"/installCyberQP" {
|
|
||||||
if ($request.HttpMethod -eq "GET") {
|
|
||||||
try {
|
|
||||||
Install-CyberQP
|
|
||||||
$responseString = "Install CyberQP triggered successfully."
|
|
||||||
$response.StatusCode = 200
|
|
||||||
} catch {
|
|
||||||
$responseString = "Error triggering Install CyberQP: $_"
|
|
||||||
$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()
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
"/installSplashtop" {
|
|
||||||
if ($request.HttpMethod -eq "GET") {
|
|
||||||
try {
|
|
||||||
Install-Splashtop
|
|
||||||
$responseString = "Install Splashtop triggered successfully."
|
|
||||||
$response.StatusCode = 200
|
|
||||||
} catch {
|
|
||||||
$responseString = "Error triggering Install Splashtop: $_"
|
|
||||||
$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()
|
|
||||||
}
|
|
||||||
|
|
||||||
"/installRocketCyber" {
|
|
||||||
if ($request.HttpMethod -eq "GET") {
|
|
||||||
try {
|
|
||||||
Install-RocketCyber
|
|
||||||
$responseString = "Install RocketCyber triggered successfully."
|
|
||||||
$response.StatusCode = 200
|
|
||||||
} catch {
|
|
||||||
$responseString = "Error triggering Install RocketCyber: $_"
|
|
||||||
$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()
|
|
||||||
}
|
|
||||||
|
|
||||||
"/installThreatLocker" {
|
|
||||||
if ($request.HttpMethod -eq "GET") {
|
|
||||||
try {
|
|
||||||
Install-ThreatLocker
|
|
||||||
$responseString = "Install ThreatLocker 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 {
|
|
||||||
Install-SVSHelpDesk
|
|
||||||
$responseString = "Install SVSHelpDesk triggered successfully."
|
|
||||||
$response.StatusCode = 200
|
|
||||||
} catch {
|
|
||||||
$responseString = "Error triggering Install SVSHelpDesk: $_"
|
|
||||||
$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()
|
|
||||||
}
|
|
||||||
|
|
||||||
"/installSVSWatchtower" {
|
|
||||||
if ($request.HttpMethod -eq "GET") {
|
|
||||||
Install-SVSWatchtower
|
|
||||||
try {
|
|
||||||
Install-SVSWatchtower
|
|
||||||
$responseString = "Install SVSWatchtower triggered successfully."
|
|
||||||
$response.StatusCode = 200
|
|
||||||
} catch {
|
|
||||||
$responseString = "Error triggering Install SVSWatchtower: $_"
|
|
||||||
$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()
|
|
||||||
}
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
# 4) NEW ROUTE: /getLogs
|
# 4) NEW ROUTE: /getLogs
|
||||||
# Returns $Global:LogCache as JSON for the polling function
|
# Returns $Global:LogCache as JSON for the polling function
|
||||||
|
|||||||
Reference in New Issue
Block a user