Update TGBeta.ps1

This commit is contained in:
2025-05-26 23:26:53 -04:00
parent bb9794e19f
commit c393a1aa10

View File

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