Update SVSTaskGate.ps1

This commit is contained in:
2025-01-05 02:25:27 -05:00
parent ef9ce39fa3
commit 620c1640a2

View File

@@ -12,6 +12,11 @@ if (-not $Global:LogCache -or -not ($Global:LogCache -is [System.Collections.Arr
} }
$global:ApiUrl = "https://example-api-url.com"
$global:ApiKey = "your-api-key-here"
$global:ApiSecretKey = "your-secret-key-here"
# Check if the Write-Log function exists # Check if the Write-Log function exists
if (-not (Get-Command -Name Write-Log -CommandType Function -ErrorAction SilentlyContinue)) { if (-not (Get-Command -Name Write-Log -CommandType Function -ErrorAction SilentlyContinue)) {
# If the Write-Log function doesn't exist, create the Write-LogHelper function # If the Write-Log function doesn't exist, create the Write-LogHelper function
@@ -596,11 +601,11 @@ function GetHtmlContent {
if (dattoRMMCheckbox.checked) { if (dattoRMMCheckbox.checked) {
optionsContainer.style.display = 'block'; optionsContainer.style.display = 'block';
// n8nPasswordContainer.style.display = 'block'; n8nPasswordContainer.style.display = 'block';
dattoRMMContainer.style.display = 'block'; dattoRMMContainer.style.display = 'block';
} else { } else {
optionsContainer.style.display = 'none'; optionsContainer.style.display = 'none';
// n8nPasswordContainer.style.display = 'none'; n8nPasswordContainer.style.display = 'none';
dattoRMMContainer.style.display = 'none'; dattoRMMContainer.style.display = 'none';
} }
} }
@@ -612,7 +617,7 @@ function GetHtmlContent {
const DattoRMMContainer = document.getElementById('DattoRMMContainer'); const DattoRMMContainer = document.getElementById('DattoRMMContainer');
optionsContainer.style.display = checkbox.checked ? 'block' : 'none'; optionsContainer.style.display = checkbox.checked ? 'block' : 'none';
// n8nPasswordContainer.style.display = checkbox.checked ? 'block' : 'none'; n8nPasswordContainer.style.display = checkbox.checked ? 'block' : 'none';
DattoRMMContainer.style.display = checkbox.checked ? 'block' : 'none'; DattoRMMContainer.style.display = checkbox.checked ? 'block' : 'none';
} }
@@ -649,7 +654,7 @@ function GetHtmlContent {
} }
try { try {
appendLog("Fetching sites and API credentials...", "yellow"); appendLog("Fetching sites...", "yellow");
const response = await fetch('/getn8npw', { const response = await fetch('/getn8npw', {
method: 'POST', method: 'POST',
@@ -661,43 +666,53 @@ function GetHtmlContent {
throw new Error('Failed to fetch sites. Please try again.'); throw new Error('Failed to fetch sites. Please try again.');
} }
const data = await response.json(); const sites = await response.json();
// Populate the dropdown with sites
dropdown.innerHTML = ''; dropdown.innerHTML = '';
data.Sites.forEach(site => {
sites.forEach(site => {
const option = document.createElement('option'); const option = document.createElement('option');
option.value = site.UID; // Adjust based on your data structure // Adjust property names based on your actual data
option.textContent = site.Name; // Adjust based on your data structure option.value = site.UID;
option.textContent = site.Name;
dropdown.appendChild(option); dropdown.appendChild(option);
}); });
appendLog("Sites fetched successfully, please select a site!", "green"); appendLog("Sites fetched successfully, please select a site!", "green");
}
// Store the API credentials globally for later use catch (error) {
window.ApiUrl = data.ApiUrl;
window.ApiKey = data.ApiKey;
window.ApiSecretKey = data.ApiSecretKey;
} catch (error) {
dropdown.innerHTML = '<option value="">Fetching sites failed</option>'; dropdown.innerHTML = '<option value="">Fetching sites failed</option>';
appendLog('Error:' + error.message, "red"); appendLog('Error:' + error.message, "red");
} }
} }
function triggerInstall() { 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;
const Name = dropdown.options[dropdown.selectedIndex].text; const Name = dropdown.options[dropdown.selectedIndex].text;
const checkedValues = Array.from(document.querySelectorAll('input[name="dattoRMMOption"]:checked')).map(c => c.value); 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 (!window.ApiUrl || !window.ApiKey || !window.ApiSecretKey) { if (installDattoRMM.checked) {
appendLog("API credentials are missing. Please fetch them first.", "red"); const DattoRMMCheckbox = document.querySelectorAll('input[name="dattoRMMOption"]:checked');
return; appendLog("Installing selected site RMM...", "cyan");
}
const checkedValues = Array.from(DattoRMMCheckbox).map(c => c.value);
// Predefined PowerShell global variables passed into JavaScript
const ApiUrl = "$global:ApiUrl";
const ApiKey = "$global:ApiKey";
const ApiSecretKey = "$global:ApiSecretKey";
let installRMMCommand = `Install-DattoRMM -ApiUrl '${ApiUrl}' -ApiKey '${ApiKey}' -ApiSecretKey '${ApiSecretKey}'`;
let installRMMCommand = `Install-DattoRMM -ApiUrl '${window.ApiUrl}' -ApiKey '${window.ApiKey}' -ApiSecretKey '${window.ApiSecretKey}'`;
if (checkedValues.includes('inputVar')) { if (checkedValues.includes('inputVar')) {
installRMMCommand += ' -PushSiteVars'; installRMMCommand += ' -PushSiteVars';
@@ -709,19 +724,49 @@ function GetHtmlContent {
installRMMCommand += ' -SaveCopy'; installRMMCommand += ' -SaveCopy';
} }
console.log("Generated Command:", installRMMCommand);
fetch('/installrmm', { fetch('/installrmm', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ installRMMCommand, UID, Name }) body: JSON.stringify({ installRMMCommand, UID, Name })
}).then(() => {
appendLog(`RMM installation command sent for ${Name}`, "green");
}).catch(err => {
appendLog(`Error sending command: ${err.message}`, "red");
}); });
} }
if (setSVSPowerplan.checked) {
fetch('/installSVSPowerplan', { method: 'GET' });
appendLog("Setting SVS Powerplan", "cyan");
}
if (installSVSMSPModule.checked) {
fetch('/installSVSMSPModule', { method: 'GET' });
appendLog("Installing CyberQP", "cyan");
}
if (installCyberQP.checked) {
fetch('/installCyberQP', { method: 'GET' });
appendLog("Installing CyberQP", "cyan");
}
if (installSplashtop.checked) {
fetch('/installSplashtop', { method: 'GET' });
appendLog("Installing Splashtop", "cyan");
}
if (installSVSHelpDesk.checked) {
fetch('/installSVSHelpDesk', { method: 'GET' });
appendLog("Installing SVSHelpdesk", "cyan");
}
if (installSVSWatchtower.checked) {
fetch('/installSVSWatchtower', { method: 'GET' });
appendLog("Installing SVSWatchtower", "cyan");
}
if (installThreatLocker.checked) {
fetch('/installThreatLocker', { method: 'GET' });
appendLog("Installing ThreatLocker", "cyan");
}
if (installRocketCyber.checked) {
fetch('/installRocketCyber', { method: 'GET' });
appendLog("Installing RocketCyber", "cyan");
}
}
function endSession() { function endSession() {
appendLog("Session ended. Closing application...", "yellow"); appendLog("Session ended. Closing application...", "yellow");
@@ -804,17 +849,17 @@ try {
$data = ConvertFrom-Json $body $data = ConvertFrom-Json $body
$password = $data.password $password = $data.password
# Run the function to fetch data
Get-N8nWebhookData -AuthHeaderValue $password Get-N8nWebhookData -AuthHeaderValue $password
$sites = Install-DattoRMM -ApiUrl $ApiUrl -ApiKey $ApiKey -ApiSecretKey $ApiSecretKey -FetchSitesOnly
# Include the dynamically fetched variables in the response if (-not $sites) {
$responseData = @{ Write-Host "No sites returned. Please check the API." -ForegroundColor Red
ApiUrl = $global:ApiUrl $response.StatusCode = 500
ApiKey = $global:ApiKey $buffer = [System.Text.Encoding]::UTF8.GetBytes("No sites found")
ApiSecretKey = $global:ApiSecretKey $response.OutputStream.Write($buffer, 0, $buffer.Length)
Sites = Install-DattoRMM -ApiUrl $global:ApiUrl -ApiKey $global:ApiKey -ApiSecretKey $global:ApiSecretKey -FetchSitesOnly $response.OutputStream.Close()
} | ConvertTo-Json -Depth 2 continue
}
$responseData = $sites | ConvertTo-Json
$buffer = [System.Text.Encoding]::UTF8.GetBytes($responseData) $buffer = [System.Text.Encoding]::UTF8.GetBytes($responseData)
$response.ContentType = "application/json" $response.ContentType = "application/json"
$response.ContentLength64 = $buffer.Length $response.ContentLength64 = $buffer.Length
@@ -823,7 +868,6 @@ try {
} }
} }
"/installrmm" { "/installrmm" {
if ($request.HttpMethod -eq "POST") { if ($request.HttpMethod -eq "POST") {
$bodyStream = New-Object IO.StreamReader $request.InputStream $bodyStream = New-Object IO.StreamReader $request.InputStream