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 UID = dropdown.options[dropdown.selectedIndex].value;
|
||||
const Name = dropdown.options[dropdown.selectedIndex].text;
|
||||
const UID = dropdown.options[dropdown.selectedIndex]?.value || null;
|
||||
const Name = 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"]');
|
||||
const tasks = [];
|
||||
|
||||
// Priority 1: Install SVSMSP Module
|
||||
if (installSVSMSPModule.checked) {
|
||||
appendLog("Installing SVSMSP Module (Priority 1)...", "cyan");
|
||||
fetch('/installSVSMSPModule', { method: 'GET' })
|
||||
if (document.querySelector('input[name="installSVSMSPModule"]').checked) {
|
||||
tasks.push({ name: "installSVSMSPModule", priority: 1 });
|
||||
}
|
||||
|
||||
// Priority 2: Install DattoRMM
|
||||
if (installDattoRMM.checked) {
|
||||
const DattoRMMCheckbox = document.querySelectorAll('input[name="dattoRMMOption"]:checked');
|
||||
appendLog("Installing selected site RMM (Priority 2)...", "cyan");
|
||||
if (document.querySelector('input[name="installDattoRMM"]').checked) {
|
||||
const selectedOptions = Array.from(document.querySelectorAll('input[name="dattoRMMOption"]:checked'))
|
||||
.map(option => option.value);
|
||||
|
||||
const checkedValues = Array.from(DattoRMMCheckbox).map(c => c.value);
|
||||
tasks.push({
|
||||
name: "installDattoRMM",
|
||||
priority: 2,
|
||||
details: { UID, Name, options: selectedOptions },
|
||||
});
|
||||
}
|
||||
|
||||
const payload = {
|
||||
checkedValues, // Array of selected checkbox values
|
||||
UID, // Selected site UID
|
||||
Name // Selected site name
|
||||
};
|
||||
if (document.querySelector('input[name="setSVSPowerplan"]').checked) {
|
||||
tasks.push({ name: "setSVSPowerplan", priority: 3 });
|
||||
}
|
||||
|
||||
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',
|
||||
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
|
||||
if (setSVSPowerplan.checked) {
|
||||
fetch('/SetSVSPowerplan', { method: 'GET' })
|
||||
const result = await response.json();
|
||||
console.log(result);
|
||||
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() {
|
||||
@@ -1000,120 +986,89 @@ try {
|
||||
}
|
||||
}
|
||||
|
||||
"/installSVSMSPModule" {
|
||||
if ($request.HttpMethod -eq "GET") {
|
||||
function Execute-Task {
|
||||
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 {
|
||||
Install-SVSMSP -InstallToolkit
|
||||
$responseString = "Install SVSMSP Module triggered successfully."
|
||||
$body = Get-Content -Raw -Path $request.InputStream | ConvertFrom-Json
|
||||
$Tasks = $body.tasks
|
||||
Execute-PrioritizedTasks -Tasks $Tasks
|
||||
|
||||
$responseString = "All tasks executed successfully."
|
||||
$response.StatusCode = 200
|
||||
} catch {
|
||||
$responseString = "Error triggering Install SVSMSP Module: $_"
|
||||
$responseString = "Error executing tasks: $($_.Exception.Message)"
|
||||
$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)
|
||||
$response.ContentType = "text/plain"
|
||||
$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
|
||||
# Returns $Global:LogCache as JSON for the polling function
|
||||
|
||||
Reference in New Issue
Block a user