Update SVSTaskGate.ps1
This commit is contained in:
113
SVSTaskGate.ps1
113
SVSTaskGate.ps1
@@ -649,7 +649,7 @@ function GetHtmlContent {
|
||||
}
|
||||
|
||||
try {
|
||||
appendLog("Fetching sites...", "yellow");
|
||||
appendLog("Fetching sites and API credentials...", "yellow");
|
||||
|
||||
const response = await fetch('/getn8npw', {
|
||||
method: 'POST',
|
||||
@@ -661,53 +661,43 @@ function GetHtmlContent {
|
||||
throw new Error('Failed to fetch sites. Please try again.');
|
||||
}
|
||||
|
||||
const sites = await response.json();
|
||||
dropdown.innerHTML = '';
|
||||
const data = await response.json();
|
||||
|
||||
sites.forEach(site => {
|
||||
// Populate the dropdown with sites
|
||||
dropdown.innerHTML = '';
|
||||
data.Sites.forEach(site => {
|
||||
const option = document.createElement('option');
|
||||
// Adjust property names based on your actual data
|
||||
option.value = site.UID;
|
||||
option.textContent = site.Name;
|
||||
option.value = site.UID; // Adjust based on your data structure
|
||||
option.textContent = site.Name; // Adjust based on your data structure
|
||||
dropdown.appendChild(option);
|
||||
});
|
||||
|
||||
appendLog("Sites fetched successfully, please select a site!", "green");
|
||||
}
|
||||
catch (error) {
|
||||
|
||||
// Store the API credentials globally for later use
|
||||
window.ApiUrl = data.ApiUrl;
|
||||
window.ApiKey = data.ApiKey;
|
||||
window.ApiSecretKey = data.ApiSecretKey;
|
||||
} catch (error) {
|
||||
dropdown.innerHTML = '<option value="">Fetching sites failed</option>';
|
||||
appendLog('Error: ' + error.message, "red");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function triggerInstall() {
|
||||
const dropdown = document.getElementById('dattoRmmDropdown');
|
||||
const UID = dropdown.options[dropdown.selectedIndex].value;
|
||||
const Name = dropdown.options[dropdown.selectedIndex].text;
|
||||
|
||||
const setSVSPowerplan = document.querySelector('input[name="setSVSPowerplan"]');
|
||||
const installSVSMSPModule = document.querySelector('input[name="installSVSMSPModule"]');
|
||||
const installDattoRMM = document.querySelector('input[name="installDattoRMM"]');
|
||||
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"]');
|
||||
const checkedValues = Array.from(document.querySelectorAll('input[name="dattoRMMOption"]:checked')).map(c => c.value);
|
||||
|
||||
if (installDattoRMM.checked) {
|
||||
const DattoRMMCheckbox = document.querySelectorAll('input[name="dattoRMMOption"]:checked');
|
||||
appendLog("Installing selected site RMM...", "cyan");
|
||||
|
||||
const checkedValues = Array.from(DattoRMMCheckbox).map(c => c.value);
|
||||
|
||||
// Predefined PowerShell global variables passed into JavaScript
|
||||
// const ApiUrl = "$global:ApiUrl";
|
||||
// const ApiKey = "$global:ApiKey";
|
||||
// const ApiSecretKey = "$global:ApiSecretKey";
|
||||
|
||||
// let installRMMCommand = `Install-DattoRMM -ApiUrl '${ApiUrl}' -ApiKey '${ApiKey}' -ApiSecretKey '${ApiSecretKey}'`;
|
||||
if (!window.ApiUrl || !window.ApiKey || !window.ApiSecretKey) {
|
||||
appendLog("API credentials are missing. Please fetch them first.", "red");
|
||||
return;
|
||||
}
|
||||
|
||||
let installRMMCommand = `Install-DattoRMM -ApiUrl '${window.ApiUrl}' -ApiKey '${window.ApiKey}' -ApiSecretKey '${window.ApiSecretKey}'`;
|
||||
|
||||
if (checkedValues.includes('inputVar')) {
|
||||
installRMMCommand += ' -PushSiteVars';
|
||||
@@ -719,49 +709,19 @@ function GetHtmlContent {
|
||||
installRMMCommand += ' -SaveCopy';
|
||||
}
|
||||
|
||||
console.log("Generated Command:", installRMMCommand);
|
||||
|
||||
fetch('/installrmm', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ installRMMCommand, UID, Name })
|
||||
}).then(() => {
|
||||
appendLog(`RMM installation command sent for ${Name}`, "green");
|
||||
}).catch(err => {
|
||||
appendLog(`Error sending command: ${err.message}`, "red");
|
||||
});
|
||||
}
|
||||
|
||||
if (setSVSPowerplan.checked) {
|
||||
fetch('/installSVSPowerplan', { method: 'GET' });
|
||||
appendLog("Setting SVS Powerplan", "cyan");
|
||||
}
|
||||
|
||||
if (installSVSMSPModule.checked) {
|
||||
fetch('/installSVSMSPModule', { method: 'GET' });
|
||||
appendLog("Installing CyberQP", "cyan");
|
||||
|
||||
}
|
||||
|
||||
if (installCyberQP.checked) {
|
||||
fetch('/installCyberQP', { method: 'GET' });
|
||||
appendLog("Installing CyberQP", "cyan");
|
||||
}
|
||||
if (installSplashtop.checked) {
|
||||
fetch('/installSplashtop', { method: 'GET' });
|
||||
appendLog("Installing Splashtop", "cyan");
|
||||
}
|
||||
if (installSVSHelpDesk.checked) {
|
||||
fetch('/installSVSHelpDesk', { method: 'GET' });
|
||||
appendLog("Installing SVSHelpdesk", "cyan");
|
||||
}
|
||||
if (installSVSWatchtower.checked) {
|
||||
fetch('/installSVSWatchtower', { method: 'GET' });
|
||||
appendLog("Installing SVSWatchtower", "cyan");
|
||||
}
|
||||
if (installThreatLocker.checked) {
|
||||
fetch('/installThreatLocker', { method: 'GET' });
|
||||
appendLog("Installing ThreatLocker", "cyan");
|
||||
}
|
||||
if (installRocketCyber.checked) {
|
||||
fetch('/installRocketCyber', { method: 'GET' });
|
||||
appendLog("Installing RocketCyber", "cyan");
|
||||
}
|
||||
}
|
||||
|
||||
function endSession() {
|
||||
appendLog("Session ended. Closing application...", "yellow");
|
||||
@@ -844,17 +804,17 @@ try {
|
||||
$data = ConvertFrom-Json $body
|
||||
$password = $data.password
|
||||
|
||||
# Run the function to fetch data
|
||||
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("No sites found")
|
||||
$response.OutputStream.Write($buffer, 0, $buffer.Length)
|
||||
$response.OutputStream.Close()
|
||||
continue
|
||||
}
|
||||
$responseData = $sites | ConvertTo-Json
|
||||
|
||||
# Include the dynamically fetched 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 2
|
||||
|
||||
$buffer = [System.Text.Encoding]::UTF8.GetBytes($responseData)
|
||||
$response.ContentType = "application/json"
|
||||
$response.ContentLength64 = $buffer.Length
|
||||
@@ -863,6 +823,7 @@ try {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
"/installrmm" {
|
||||
if ($request.HttpMethod -eq "POST") {
|
||||
$bodyStream = New-Object IO.StreamReader $request.InputStream
|
||||
|
||||
Reference in New Issue
Block a user