Update TGBeta.ps1

This commit is contained in:
2025-05-26 23:14:18 -04:00
parent 22e33f0d8f
commit 877e9fd7e7

View File

@@ -349,7 +349,7 @@ try {
}
#endregion
function Get-N8nWebhookData {
function Get-WebhookData {
param (
[Parameter(Mandatory = $true)]
[string]$AuthHeaderValue
@@ -509,7 +509,7 @@ function GetHtmlContent {
color: var(--white-color);
}
#n8nPasswordContainer {
#PasswordContainer {
display: none;
margin-top: 20px;
}
@@ -666,9 +666,9 @@ function GetHtmlContent {
</label>
</div>
</div>
<div id="n8nPasswordContainer" style="display: none;">
<label for="n8nPassword">Enter Password:</label><br>
<input type="password" id="n8nPassword" class="password-input" placeholder="Enter Password">
<div id="PasswordContainer" style="display: none;">
<label for="Password">Enter Password:</label><br>
<input type="password" id="Password" class="password-input" placeholder="Enter Password">
</div>
<br>
<div id="DattoRMMContainer" style="display: none;">
@@ -905,15 +905,15 @@ function GetHtmlContent {
function toggleDattoRMMVisibility() {
const dattoRMMCheckbox = document.getElementById('installDattoRMMCheckbox');
const optionsContainer = document.getElementById('dattoRMMOptionsContainer');
const n8nPasswordContainer = document.getElementById('n8nPasswordContainer');
const PasswordContainer = document.getElementById('PasswordContainer');
const dattoRMMContainer = document.getElementById('DattoRMMContainer');
if (dattoRMMCheckbox.checked) {
optionsContainer.style.display = 'block';
n8nPasswordContainer.style.display = 'block';
PasswordContainer.style.display = 'block';
dattoRMMContainer.style.display = 'block';
} else {
optionsContainer.style.display = 'none';
n8nPasswordContainer.style.display = 'none';
PasswordContainer.style.display = 'none';
dattoRMMContainer.style.display = 'none';
}
}
@@ -1079,19 +1079,19 @@ function GetHtmlContent {
function toggleDattoRMMOptions() {
const dattoRMMCheckbox = document.getElementById('installDattoRMMCheckbox');
const optionsContainer = document.getElementById('dattoRMMOptionsContainer');
const n8nPasswordContainer = document.getElementById('n8nPasswordContainer');
const PasswordContainer = document.getElementById('PasswordContainer');
const dattoRMMContainer = document.getElementById('DattoRMMContainer');
const subCheckboxes = document.querySelectorAll('#dattoRMMOptionsContainer input[type="checkbox"]');
if (dattoRMMCheckbox.checked) {
optionsContainer.style.display = 'block';
n8nPasswordContainer.style.display = 'block';
PasswordContainer.style.display = 'block';
dattoRMMContainer.style.display = 'block';
subCheckboxes.forEach(subCheckbox => {
subCheckbox.checked = true;
});
} else {
optionsContainer.style.display = 'none';
n8nPasswordContainer.style.display = 'none';
PasswordContainer.style.display = 'none';
dattoRMMContainer.style.display = 'none';
subCheckboxes.forEach(subCheckbox => {
subCheckbox.checked = false;
@@ -1176,33 +1176,33 @@ function GetHtmlContent {
}
// =======================================================================
// SECTION: n8n Password Input and Fetch Sites Button
// SECTION: Password Input and Fetch Sites Button
// =======================================================================
const logArea = document.getElementById('logArea');
const fetchSitesButton = document.getElementById('fetchSitesButton');
const n8nPasswordInput = document.getElementById('n8nPassword');
n8nPasswordInput.addEventListener('input', () => {
fetchSitesButton.disabled = n8nPasswordInput.value.length < 4;
const PasswordInput = document.getElementById('Password');
PasswordInput.addEventListener('input', () => {
fetchSitesButton.disabled = PasswordInput.value.length < 4;
});
n8nPasswordInput.addEventListener('keydown', (event) => {
if (event.key === 'Enter' && n8nPasswordInput.value.length >= 12) {
PasswordInput.addEventListener('keydown', (event) => {
if (event.key === 'Enter' && PasswordInput.value.length >= 12) {
fetchSites();
}
});
// =======================================================================
// SECTION: Fetch Sites from n8n
// SECTION: Fetch Sites from
// =======================================================================
async function fetchSites() {
const password = document.getElementById('n8nPassword').value;
const password = document.getElementById('Password').value;
const dropdown = document.getElementById('dattoRmmDropdown');
if (!password) {
appendLog("Please enter the n8n password.", "red");
appendLog("Please enter the password.", "red");
return;
}
try {
appendLog("Fetching sites...", "yellow");
const response = await fetch('/getn8npw', {
const response = await fetch('/getpw', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ password })
@@ -1418,14 +1418,14 @@ try {
$response.OutputStream.Write($buffer, 0, $buffer.Length)
$response.OutputStream.Close()
}
"/getn8npw" {
"/getpw" {
if ($request.HttpMethod -eq "POST") {
try {
$bodyStream = New-Object IO.StreamReader $request.InputStream
$body = $bodyStream.ReadToEnd()
$data = ConvertFrom-Json $body
$password = $data.password
Get-N8nWebhookData -AuthHeaderValue $password
Get-WebhookData -AuthHeaderValue $password
$sites = Install-DattoRMM-Helper -ApiUrl $ApiUrl -ApiKey $ApiKey -ApiSecretKey $ApiSecretKey -FetchSitesOnly
if (-not $sites) {
Write-Host "No sites returned. Please check the API." -ForegroundColor Red
@@ -1442,7 +1442,7 @@ try {
$response.OutputStream.Write($buffer, 0, $buffer.Length)
$response.OutputStream.Close()
} catch {
Write-LogHybrid -Message "Error processing /getn8npw: $($_.Exception.Message)" -Level "Error"
Write-LogHybrid -Message "Error processing /getpw: $($_.Exception.Message)" -Level "Error"
$response.StatusCode = 500
$buffer = [System.Text.Encoding]::UTF8.GetBytes("Error: Failed to process the request.")
$response.OutputStream.Write($buffer, 0, $buffer.Length)