Update TGBeta.ps1

This commit is contained in:
2025-01-05 19:43:18 -05:00
parent cb486e014e
commit 33636035ea

View File

@@ -387,10 +387,10 @@ function GetHtmlContent {
.logo-container { .logo-container {
text-align: center; text-align: center;
padding: 20px; padding: 20px;
background-color: #1e1e1e; /* Matches the background color */ background-color: #1e1e1e;
} }
.logo-container img { .logo-container img {
max-width: 300px; /* Adjust size as needed */ max-width: 300px;
height: auto; height: auto;
} }
.container { .container {
@@ -565,21 +565,7 @@ function GetHtmlContent {
<br><br> <br><br>
</div> </div>
</div> </div>
<div id="n8nPasswordContainer" style="display: none;">
<label for="n8nPassword">Enter n8n Password:</label><br>
<input type="password" id="n8nPassword" class="password-input" placeholder="Enter N8N Password">
</div>
<br>
<div id="DattoRMMContainer" style="display: none;">
<label for="dattoRmmDropdown">Select a Datto RMM site:</label><br>
<select id="dattoRmmDropdown" class="dropdown">
<option value="">Fetching sites...</option>
$siteOptions
</select>
</div>
<div class="button-group"> <div class="button-group">
<button class="install-button" id="fetchSitesButton" onclick="fetchSites()" disabled>Fetch
Sites</button>
<button class="install-button" onclick="triggerInstall()">Install</button> <button class="install-button" onclick="triggerInstall()">Install</button>
<button class="exit-button" onclick="endSession()">Exit</button> <button class="exit-button" onclick="endSession()">Exit</button>
</div> </div>
@@ -589,261 +575,65 @@ function GetHtmlContent {
</div> </div>
</div> </div>
</div> </div>
<script> <script>
function toggleOnboardCheckboxes(selectedCheckbox) { function toggleOnboardCheckboxes(selectAllCheckbox) {
const checkboxes = document.querySelectorAll('#onboardTab input[type="checkbox"]'); const checkboxes = document.querySelectorAll('.checkbox-group input[type="checkbox"]');
const dattoRMMCheckbox = document.getElementById('installDattoRMMCheckbox');
const optionsContainer = document.getElementById('dattoRMMOptionsContainer');
const n8nPasswordContainer = document.getElementById('n8nPasswordContainer');
const dattoRMMContainer = document.getElementById('DattoRMMContainer');
checkboxes.forEach(checkbox => { checkboxes.forEach(checkbox => {
if (checkbox !== selectedCheckbox) { if (checkbox !== selectAllCheckbox) {
checkbox.checked = selectedCheckbox.checked; checkbox.checked = selectAllCheckbox.checked;
} }
}); });
if (dattoRMMCheckbox.checked) { appendLog(selectAllCheckbox.checked ? "All checkboxes selected." : "All checkboxes deselected.", "cyan");
optionsContainer.style.display = 'block';
n8nPasswordContainer.style.display = 'block';
dattoRMMContainer.style.display = 'block';
} else {
optionsContainer.style.display = 'none';
n8nPasswordContainer.style.display = 'none';
dattoRMMContainer.style.display = 'none';
}
} }
function toggleDattoRMMOptions() { function toggleDattoRMMOptions() {
const checkbox = document.getElementById('installDattoRMMCheckbox'); const dattoRMMCheckbox = document.getElementById('installDattoRMMCheckbox');
const optionsContainer = document.getElementById('dattoRMMOptionsContainer'); const optionsContainer = document.getElementById('dattoRMMOptionsContainer');
const n8nPasswordContainer = document.getElementById('n8nPasswordContainer'); optionsContainer.style.display = dattoRMMCheckbox.checked ? 'block' : 'none';
const DattoRMMContainer = document.getElementById('DattoRMMContainer'); appendLog(dattoRMMCheckbox.checked ? "Datto RMM options shown." : "Datto RMM options hidden.", "cyan");
optionsContainer.style.display = checkbox.checked ? 'block' : 'none';
n8nPasswordContainer.style.display = checkbox.checked ? 'block' : 'none';
DattoRMMContainer.style.display = checkbox.checked ? 'block' : 'none';
}
const tabButtons = document.querySelectorAll('.tab-button');
const tabContents = document.querySelectorAll('.tab-content');
const logArea = document.getElementById('logArea');
const fetchSitesButton = document.getElementById('fetchSitesButton');
const n8nPasswordInput = document.getElementById('n8nPassword');
tabButtons.forEach(button => {
button.addEventListener('click', () => {
tabButtons.forEach(btn => {
btn.classList.remove('active');
btn.setAttribute('aria-expanded', 'false');
});
tabContents.forEach(tab => tab.classList.remove('active'));
button.classList.add('active');
button.setAttribute('aria-expanded', 'true');
document.getElementById(button.dataset.tab).classList.add('active');
});
});
n8nPasswordInput.addEventListener('input', () => {
fetchSitesButton.disabled = n8nPasswordInput.value.length < 4;
});
// Trigger fetchSites() on Enter key press
n8nPasswordInput.addEventListener('keydown', (event) => {
if (event.key === 'Enter' && n8nPasswordInput.value.length >= 4) {
fetchSites(); // Call the fetchSites function
}
});
async function fetchSites() {
const password = document.getElementById('n8nPassword').value;
const dropdown = document.getElementById('dattoRmmDropdown');
if (!password) {
appendLog("Please enter the n8n password.", "red");
return;
}
try {
appendLog("Fetching sites...", "yellow");
const response = await fetch('/getn8npw', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ password })
});
if (!response.ok) {
throw new Error('Failed to fetch sites. Please try again.');
}
const sites = await response.json();
dropdown.innerHTML = '';
sites.forEach(site => {
const option = document.createElement('option');
// Adjust property names based on your actual data
option.value = site.UID;
option.textContent = site.Name;
dropdown.appendChild(option);
});
appendLog("Sites fetched successfully, please select a site!", "green");
}
catch (error) {
dropdown.innerHTML = '<option value="">Fetching sites failed</option>';
appendLog('Error:' + error.message, "red");
}
} }
function triggerInstall() { function triggerInstall() {
const dropdown = document.getElementById('dattoRmmDropdown'); const checkboxes = document.querySelectorAll('.checkbox-group input[type="checkbox"]:checked');
const UID = dropdown && dropdown.options[dropdown.selectedIndex] const selectedCheckboxes = Array.from(checkboxes).map(checkbox => checkbox.id);
? dropdown.options[dropdown.selectedIndex].value
: null;
const Name = dropdown && dropdown.options[dropdown.selectedIndex]
? dropdown.options[dropdown.selectedIndex].text
: "Unknown Site";
const setSVSPowerplan = document.querySelector('input[name="setSVSPowerplan"]'); if (selectedCheckboxes.includes('installDattoRMMCheckbox')) {
const installSVSMSPModule = document.querySelector('input[name="installSVSMSPModule"]'); const dattoRMMOptions = document.querySelectorAll('input[name="dattoRMMOption"]:checked');
const installDattoRMM = document.querySelector('input[name="installDattoRMM"]'); const dattoRMMValues = Array.from(dattoRMMOptions).map(option => option.value);
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"]');
// Ensure UID is selected before proceeding appendLog(`Installing Datto RMM with options: ${dattoRMMValues.join(', ')}`, "cyan");
if (!UID) { // Perform the Datto RMM installation logic here
appendLog("Please select a site from the dropdown.", "red");
return;
} }
// Install DattoRMM if checked selectedCheckboxes.forEach(id => {
if (installDattoRMM.checked) { appendLog(`Task ${id} triggered.`, "green");
const DattoRMMCheckbox = document.querySelectorAll('input[name="dattoRMMOption"]:checked'); // Add specific logic for each checkbox task
appendLog("Installing selected site RMM...", "cyan");
const checkedValues = Array.from(DattoRMMCheckbox).map(c => c.value);
const payload = {
checkedValues, // Array of selected checkbox values
UID, // Selected site UID
Name // Selected site name
};
fetch('/installrmm', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
})
.then(() => appendLog("Datto RMM installation triggered successfully.", "green"))
.catch(error => appendLog(`Error installing Datto RMM: ${error.message}`, "red"));
}
// Execute lower-priority tasks sequentially
if (setSVSPowerplan.checked) {
fetch('/SetSVSPowerplan', { method: 'GET' })
.then(() => appendLog("SVS Powerplan set successfully.", "green"))
.catch(error => appendLog(`Error setting SVS Powerplan: ${error.message}`, "red"));
}
if (installSVSMSPModule.checked) {
fetch('/installSVSMSPModule', { method: 'GET' })
.then(() => appendLog("SVSMSP Module installed successfully.", "green"))
.catch(error => appendLog(`Error installing SVSMSP Module: ${error.message}`, "red"));
}
if (installCyberQP.checked) {
fetch('/installCyberQP', { method: 'GET' })
.then(() => appendLog("CyberQP installed successfully.", "green"))
.catch(error => appendLog(`Error installing CyberQP: ${error.message}`, "red"));
}
if (installSplashtop.checked) {
fetch('/installSplashtop', { method: 'GET' })
.then(() => appendLog("Splashtop installed successfully.", "green"))
.catch(error => appendLog(`Error installing Splashtop: ${error.message}`, "red"));
}
if (installSVSHelpDesk.checked) {
fetch('/installSVSHelpDesk', { method: 'GET' })
.then(() => appendLog("SVS HelpDesk installed successfully.", "green"))
.catch(error => appendLog(`Error installing SVS HelpDesk: ${error.message}`, "red"));
}
if (installSVSWatchtower.checked) {
fetch('/installSVSWatchtower', { method: 'GET' })
.then(() => appendLog("SVS Watchtower installed successfully.", "green"))
.catch(error => appendLog(`Error installing SVS Watchtower: ${error.message}`, "red"));
}
if (installThreatLocker.checked) {
fetch('/installThreatLocker', { method: 'GET' })
.then(() => appendLog("ThreatLocker installed successfully.", "green"))
.catch(error => appendLog(`Error installing ThreatLocker: ${error.message}`, "red"));
}
if (installRocketCyber.checked) {
fetch('/installRocketCyber', { method: 'GET' })
.then(() => appendLog("RocketCyber installed successfully.", "green"))
.catch(error => appendLog(`Error installing RocketCyber: ${error.message}`, "red"));
}
}
function endSession() {
appendLog("Session ended. Closing application...", "yellow");
fetch('/quit', { method: 'GET' })
.then(response => {
if (!response.ok) {
throw new Error('Failed to end session');
}
window.close();
})
.catch(error => {
appendLog("Error ending session: " + error.message, "red");
}); });
} }
function appendLog(message, color = "white") { function appendLog(message, color = "white") {
const log = document.createElement('p'); const logArea = document.getElementById('logArea');
log.style.color = color; const logEntry = document.createElement('p');
log.textContent = message; logEntry.textContent = message;
document.getElementById('logArea').appendChild(log); logEntry.style.color = color;
logArea.appendChild(logEntry);
} }
function endSession() {
// ------------------------------------------------------------------- appendLog("Session ended. Closing application...", "yellow");
// 3) POLL THE SERVER LOGS (NEW) fetch('/quit', { method: 'GET' })
// ------------------------------------------------------------------- .then(() => {
let lastLogCount = 0; window.close();
async function fetchLogs() { })
try { .catch(error => {
const resp = await fetch('/getLogs'); appendLog(`Error ending session: ${error.message}`, "red");
if (!resp.ok) return; });
const logs = await resp.json(); // array of {Timestamp, Level, Message}
// Append only new messages
for (let i = lastLogCount; i < logs.length; i++) {
// We'll display each new line in "white" or a color of your choice
appendLog(logs[i].Message, "white");
} }
lastLogCount = logs.length;
} catch (err) {
console.error("Error fetching logs:", err);
}
}
// Poll logs every 3 seconds (feel free to adjust)
setInterval(fetchLogs, 3000);
// -------------------------------------------------------------------
</script> </script>
</body> </body>
</html> </html>
"@ "@
} }