Update TriggerInstall.ps1
This commit is contained in:
@@ -81,3 +81,157 @@ async function triggerInstall() {
|
|||||||
|
|
||||||
appendLog("All tasks completed.", "green");
|
appendLog("All tasks completed.", "green");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#######
|
||||||
|
|
||||||
|
async function triggerInstall() {
|
||||||
|
const dropdown = document.getElementById('dattoRmmDropdown');
|
||||||
|
const UID = dropdown.options[dropdown.selectedIndex]?.value || null;
|
||||||
|
const Name = dropdown.options[dropdown.selectedIndex]?.text || null;
|
||||||
|
|
||||||
|
const tasks = [];
|
||||||
|
|
||||||
|
if (document.querySelector('input[name="installSVSMSPModule"]').checked) {
|
||||||
|
tasks.push({ name: "installSVSMSPModule", priority: 1 });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (document.querySelector('input[name="installDattoRMM"]').checked) {
|
||||||
|
const selectedOptions = Array.from(document.querySelectorAll('input[name="dattoRMMOption"]:checked'))
|
||||||
|
.map(option => option.value);
|
||||||
|
|
||||||
|
tasks.push({
|
||||||
|
name: "installDattoRMM",
|
||||||
|
priority: 2,
|
||||||
|
details: { UID, Name, options: selectedOptions },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (document.querySelector('input[name="setSVSPowerplan"]').checked) {
|
||||||
|
tasks.push({ name: "setSVSPowerplan", priority: 3 });
|
||||||
|
}
|
||||||
|
|
||||||
|
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({ tasks }),
|
||||||
|
});
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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 {
|
||||||
|
$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)
|
||||||
|
$response.ContentType = "text/plain"
|
||||||
|
$response.ContentLength64 = $buffer.Length
|
||||||
|
$response.OutputStream.Write($buffer, 0, $buffer.Length)
|
||||||
|
$response.OutputStream.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user