Update SVSTaskGate.ps1

This commit is contained in:
2025-01-05 01:36:34 -05:00
parent 6f0f3e3c56
commit ee549e5949

View File

@@ -649,7 +649,7 @@ function GetHtmlContent {
}
try {
appendLog("Fetching sites and API credentials...", "yellow");
appendLog("Fetching sites...", "yellow");
const response = await fetch('/getn8npw', {
method: 'POST',
@@ -658,35 +658,28 @@ function GetHtmlContent {
});
if (!response.ok) {
throw new Error('Failed to fetch data. Please try again.');
throw new Error('Failed to fetch sites. Please try again.');
}
const data = await response.json();
// Populate the dropdown with sites
const sites = await response.json();
dropdown.innerHTML = '';
data.Sites.forEach(site => {
sites.forEach(site => {
const option = document.createElement('option');
option.value = site.UID; // Adjust property names based on your actual data
// Adjust property names based on your actual data
option.value = site.UID;
option.textContent = site.Name;
dropdown.appendChild(option);
});
// Store the API credentials globally for later use
window.apiConfig = {
ApiUrl: data.ApiUrl,
ApiKey: data.ApiKey,
ApiSecretKey: data.ApiSecretKey
};
appendLog("Sites and API credentials fetched successfully.", "green");
} catch (error) {
appendLog("Sites fetched successfully, please select a site!", "green");
}
catch (error) {
dropdown.innerHTML = '<option value="">Fetching sites failed</option>';
appendLog('Error: ' + error.message, "red");
appendLog('Error:' + error.message, "red");
}
}
function triggerInstall() {
const dropdown = document.getElementById('dattoRmmDropdown');
const UID = dropdown.options[dropdown.selectedIndex].value;
@@ -845,31 +838,17 @@ try {
$data = ConvertFrom-Json $body
$password = $data.password
# Fetch data using Get-N8nWebhookData
$webhookData = Get-N8nWebhookData -AuthHeaderValue $password
if (-not $webhookData) {
Write-Host "No data returned from Get-N8nWebhookData. Please check the password or API." -ForegroundColor Red
Get-N8nWebhookData -AuthHeaderValue $password
$sites = Install-DattoRMM -ApiUrl $ApiUrl -ApiKey $ApiKey -ApiSecretKey $ApiSecretKey -FetchSitesOnly
if (-not $sites) {
Write-Host "No sites returned. Please check the API." -ForegroundColor Red
$response.StatusCode = 500
$buffer = [System.Text.Encoding]::UTF8.GetBytes("Failed to fetch data")
$buffer = [System.Text.Encoding]::UTF8.GetBytes("No sites found")
$response.OutputStream.Write($buffer, 0, $buffer.Length)
$response.OutputStream.Close()
continue
}
# Populate API-related variables
$global:ApiUrl = $webhookData.ApiUrl
$global:ApiKey = $webhookData.ApiKey
$global:ApiSecretKey = $webhookData.ApiSecretKey
# Include the API variables in the response
$responseData = @{
ApiUrl = $global:ApiUrl
ApiKey = $global:ApiKey
ApiSecretKey = $global:ApiSecretKey
Sites = Install-DattoRMM -ApiUrl $global:ApiUrl -ApiKey $global:ApiKey -ApiSecretKey $global:ApiSecretKey -FetchSitesOnly
} | ConvertTo-Json -Depth 10
$responseData = $sites | ConvertTo-Json
$buffer = [System.Text.Encoding]::UTF8.GetBytes($responseData)
$response.ContentType = "application/json"
$response.ContentLength64 = $buffer.Length
@@ -878,7 +857,6 @@ try {
}
}
"/installrmm" {
if ($request.HttpMethod -eq "POST") {
$bodyStream = New-Object IO.StreamReader $request.InputStream