Update TGBeta.ps1
This commit is contained in:
424
TGBeta.ps1
424
TGBeta.ps1
@@ -822,62 +822,76 @@ function GetHtmlContent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function triggerInstall() {
|
function triggerInstall() {
|
||||||
const dropdown = document.getElementById('dattoRmmDropdown');
|
const dropdown = document.getElementById('dattoRmmDropdown');
|
||||||
const UID = dropdown.options[dropdown.selectedIndex]?.value || null;
|
const UID = dropdown.options[dropdown.selectedIndex].value;
|
||||||
const Name = dropdown.options[dropdown.selectedIndex]?.text || null;
|
const Name = dropdown.options[dropdown.selectedIndex].text;
|
||||||
|
|
||||||
const tasks = [];
|
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"]');
|
||||||
|
|
||||||
if (document.querySelector('input[name="installSVSMSPModule"]').checked) {
|
// Priority 1: Install SVSMSP Module
|
||||||
tasks.push({ name: "installSVSMSPModule", priority: 1 });
|
if (installSVSMSPModule.checked) {
|
||||||
|
appendLog("Installing SVSMSP Module (Priority 1)...", "cyan");
|
||||||
|
fetch('/installSVSMSPModule', { method: 'GET' })
|
||||||
}
|
}
|
||||||
|
|
||||||
if (document.querySelector('input[name="installDattoRMM"]').checked) {
|
// Priority 2: Install DattoRMM
|
||||||
const selectedOptions = Array.from(document.querySelectorAll('input[name="dattoRMMOption"]:checked'))
|
if (installDattoRMM.checked) {
|
||||||
.map(option => option.value);
|
const DattoRMMCheckbox = document.querySelectorAll('input[name="dattoRMMOption"]:checked');
|
||||||
|
appendLog("Installing selected site RMM (Priority 2)...", "cyan");
|
||||||
|
|
||||||
tasks.push({
|
const checkedValues = Array.from(DattoRMMCheckbox).map(c => c.value);
|
||||||
name: "installDattoRMM",
|
|
||||||
priority: 2,
|
|
||||||
details: { UID, Name, options: selectedOptions },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (document.querySelector('input[name="setSVSPowerplan"]').checked) {
|
const payload = {
|
||||||
tasks.push({ name: "setSVSPowerplan", priority: 3 });
|
checkedValues, // Array of selected checkbox values
|
||||||
}
|
UID, // Selected site UID
|
||||||
|
Name // Selected site name
|
||||||
|
};
|
||||||
|
|
||||||
if (document.querySelector('input[name="installCyberQP"]').checked) {
|
fetch('/installrmm', {
|
||||||
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({ tasks }),
|
body: JSON.stringify(payload)
|
||||||
});
|
})
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error("Failed to execute tasks.");
|
|
||||||
}
|
|
||||||
|
|
||||||
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");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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' })
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function endSession() {
|
function endSession() {
|
||||||
@@ -986,99 +1000,255 @@ try {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Execute-Task {
|
"/installSVSMSPModule" {
|
||||||
param (
|
if ($request.HttpMethod -eq "GET") {
|
||||||
[string]$TaskName,
|
try {
|
||||||
[hashtable]$Details
|
Install-SVSMSP -InstallToolkit
|
||||||
)
|
$responseString = "Install SVSMSP Module triggered successfully."
|
||||||
|
$response.StatusCode = 200
|
||||||
switch ($TaskName) {
|
} catch {
|
||||||
"installSVSMSPModule" {
|
$responseString = "Error triggering Install SVSMSP Module: $_"
|
||||||
Write-LogHybrid -Message "Starting task: $TaskName" -Level "Info"
|
$response.StatusCode = 500
|
||||||
# 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"
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$responseString = "Method not allowed. Use GET."
|
||||||
|
$response.StatusCode = 405
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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 {
|
|
||||||
$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 executing tasks: $($_.Exception.Message)"
|
|
||||||
$response.StatusCode = 500
|
|
||||||
}
|
|
||||||
|
|
||||||
$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
|
||||||
$response.OutputStream.Write($buffer, 0, $buffer.Length)
|
$response.OutputStream.Write($buffer, 0, $buffer.Length)
|
||||||
$response.OutputStream.Close()
|
$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
|
||||||
|
$response.OutputStream.Write($buffer, 0, $buffer.Length)
|
||||||
|
$response.OutputStream.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
"/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
|
||||||
|
|||||||
Reference in New Issue
Block a user