Update SVSTaskGate.ps1
This commit is contained in:
@@ -649,7 +649,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',
|
||||||
@@ -658,35 +658,28 @@ function GetHtmlContent {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
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();
|
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 property names based on your actual data
|
// Adjust property names based on your actual data
|
||||||
|
option.value = site.UID;
|
||||||
option.textContent = site.Name;
|
option.textContent = site.Name;
|
||||||
dropdown.appendChild(option);
|
dropdown.appendChild(option);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Store the API credentials globally for later use
|
appendLog("Sites fetched successfully, please select a site!", "green");
|
||||||
window.apiConfig = {
|
}
|
||||||
ApiUrl: data.ApiUrl,
|
catch (error) {
|
||||||
ApiKey: data.ApiKey,
|
|
||||||
ApiSecretKey: data.ApiSecretKey
|
|
||||||
};
|
|
||||||
|
|
||||||
appendLog("Sites and API credentials fetched successfully.", "green");
|
|
||||||
} 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;
|
||||||
@@ -838,47 +831,32 @@ try {
|
|||||||
$response.OutputStream.Close()
|
$response.OutputStream.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
"/getn8npw" {
|
"/getn8npw" {
|
||||||
if ($request.HttpMethod -eq "POST") {
|
if ($request.HttpMethod -eq "POST") {
|
||||||
$bodyStream = New-Object IO.StreamReader $request.InputStream
|
$bodyStream = New-Object IO.StreamReader $request.InputStream
|
||||||
$body = $bodyStream.ReadToEnd()
|
$body = $bodyStream.ReadToEnd()
|
||||||
$data = ConvertFrom-Json $body
|
$data = ConvertFrom-Json $body
|
||||||
$password = $data.password
|
$password = $data.password
|
||||||
|
|
||||||
# Fetch data using Get-N8nWebhookData
|
Get-N8nWebhookData -AuthHeaderValue $password
|
||||||
$webhookData = Get-N8nWebhookData -AuthHeaderValue $password
|
$sites = Install-DattoRMM -ApiUrl $ApiUrl -ApiKey $ApiKey -ApiSecretKey $ApiSecretKey -FetchSitesOnly
|
||||||
|
if (-not $sites) {
|
||||||
if (-not $webhookData) {
|
Write-Host "No sites returned. Please check the API." -ForegroundColor Red
|
||||||
Write-Host "No data returned from Get-N8nWebhookData. Please check the password or API." -ForegroundColor Red
|
|
||||||
$response.StatusCode = 500
|
$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.Write($buffer, 0, $buffer.Length)
|
||||||
$response.OutputStream.Close()
|
$response.OutputStream.Close()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
$responseData = $sites | ConvertTo-Json
|
||||||
# Populate API-related variables
|
$buffer = [System.Text.Encoding]::UTF8.GetBytes($responseData)
|
||||||
$global:ApiUrl = $webhookData.ApiUrl
|
$response.ContentType = "application/json"
|
||||||
$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
|
|
||||||
|
|
||||||
$buffer = [System.Text.Encoding]::UTF8.GetBytes($responseData)
|
|
||||||
$response.ContentType = "application/json"
|
|
||||||
$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" {
|
"/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
|
||||||
|
|||||||
Reference in New Issue
Block a user