Files
Logo/TriggerInstall.ps1

238 lines
8.4 KiB
PowerShell

// priority
async function triggerInstall() {
const dropdown = document.getElementById('dattoRmmDropdown');
const UID = dropdown.options[dropdown.selectedIndex].value;
const Name = dropdown.options[dropdown.selectedIndex].text;
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"]');
async function executeFetch(url, options = {}) {
try {
appendLog(`Starting ${url}...`, "cyan");
const response = await fetch(url, options);
if (!response.ok) throw new Error(`Failed at ${url}: ${response.statusText}`);
appendLog(`${url} completed successfully.`, "green");
} catch (error) {
appendLog(`Error: ${error.message}`, "red");
}
}
// Priority 1: Install SVSMSP Module
if (installSVSMSPModule.checked) {
await executeFetch('/installSVSMSPModule', { method: 'GET' });
}
// 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
};
await executeFetch('/installrmm', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
}
// Lower-priority tasks
if (setSVSPowerplan.checked) {
await executeFetch('/SetSVSPowerplan', { method: 'GET' });
}
if (installCyberQP.checked) {
await executeFetch('/installCyberQP', { method: 'GET' });
}
if (installSplashtop.checked) {
await executeFetch('/installSplashtop', { method: 'GET' });
}
if (installSVSHelpDesk.checked) {
await executeFetch('/installSVSHelpDesk', { method: 'GET' });
}
if (installSVSWatchtower.checked) {
await executeFetch('/installSVSWatchtower', { method: 'GET' });
}
if (installThreatLocker.checked) {
await executeFetch('/installThreatLocker', { method: 'GET' });
}
if (installRocketCyber.checked) {
await executeFetch('/installRocketCyber', { method: 'GET' });
}
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()
}