Update SVSTaskGate.ps1
This commit is contained in:
154
SVSTaskGate.ps1
154
SVSTaskGate.ps1
@@ -12,6 +12,11 @@ if (-not $Global:LogCache -or -not ($Global:LogCache -is [System.Collections.Arr
|
||||
}
|
||||
|
||||
|
||||
$global:ApiUrl = "https://example-api-url.com"
|
||||
$global:ApiKey = "your-api-key-here"
|
||||
$global:ApiSecretKey = "your-secret-key-here"
|
||||
|
||||
|
||||
# Check if the Write-Log function exists
|
||||
if (-not (Get-Command -Name Write-Log -CommandType Function -ErrorAction SilentlyContinue)) {
|
||||
# If the Write-Log function doesn't exist, create the Write-LogHelper function
|
||||
@@ -596,11 +601,11 @@ function GetHtmlContent {
|
||||
|
||||
if (dattoRMMCheckbox.checked) {
|
||||
optionsContainer.style.display = 'block';
|
||||
// n8nPasswordContainer.style.display = 'block';
|
||||
n8nPasswordContainer.style.display = 'block';
|
||||
dattoRMMContainer.style.display = 'block';
|
||||
} else {
|
||||
optionsContainer.style.display = 'none';
|
||||
// n8nPasswordContainer.style.display = 'none';
|
||||
n8nPasswordContainer.style.display = 'none';
|
||||
dattoRMMContainer.style.display = 'none';
|
||||
}
|
||||
}
|
||||
@@ -612,7 +617,7 @@ function GetHtmlContent {
|
||||
const DattoRMMContainer = document.getElementById('DattoRMMContainer');
|
||||
|
||||
optionsContainer.style.display = checkbox.checked ? 'block' : 'none';
|
||||
// n8nPasswordContainer.style.display = checkbox.checked ? 'block' : 'none';
|
||||
n8nPasswordContainer.style.display = checkbox.checked ? 'block' : 'none';
|
||||
DattoRMMContainer.style.display = checkbox.checked ? 'block' : 'none';
|
||||
}
|
||||
|
||||
@@ -649,7 +654,7 @@ function GetHtmlContent {
|
||||
}
|
||||
|
||||
try {
|
||||
appendLog("Fetching sites and API credentials...", "yellow");
|
||||
appendLog("Fetching sites...", "yellow");
|
||||
|
||||
const response = await fetch('/getn8npw', {
|
||||
method: 'POST',
|
||||
@@ -661,68 +666,108 @@ function GetHtmlContent {
|
||||
throw new Error('Failed to fetch sites. Please try again.');
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
// Populate the dropdown with sites
|
||||
const sites = await response.json();
|
||||
dropdown.innerHTML = '';
|
||||
data.Sites.forEach(site => {
|
||||
|
||||
sites.forEach(site => {
|
||||
const option = document.createElement('option');
|
||||
option.value = site.UID; // Adjust based on your data structure
|
||||
option.textContent = site.Name; // Adjust based on your data structure
|
||||
// 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");
|
||||
|
||||
// Store the API credentials globally for later use
|
||||
window.ApiUrl = data.ApiUrl;
|
||||
window.ApiKey = data.ApiKey;
|
||||
window.ApiSecretKey = data.ApiSecretKey;
|
||||
} catch (error) {
|
||||
}
|
||||
catch (error) {
|
||||
dropdown.innerHTML = '<option value="">Fetching sites failed</option>';
|
||||
appendLog('Error: ' + error.message, "red");
|
||||
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 checkedValues = Array.from(document.querySelectorAll('input[name="dattoRMMOption"]:checked')).map(c => c.value);
|
||||
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"]');
|
||||
|
||||
if (!window.ApiUrl || !window.ApiKey || !window.ApiSecretKey) {
|
||||
appendLog("API credentials are missing. Please fetch them first.", "red");
|
||||
return;
|
||||
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 (checkedValues.includes('inputVar')) {
|
||||
installRMMCommand += ' -PushSiteVars';
|
||||
}
|
||||
if (checkedValues.includes('rmm')) {
|
||||
installRMMCommand += ' -InstallRMM';
|
||||
}
|
||||
if (checkedValues.includes('exe')) {
|
||||
installRMMCommand += ' -SaveCopy';
|
||||
}
|
||||
|
||||
fetch('/installrmm', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ installRMMCommand, UID, Name })
|
||||
});
|
||||
}
|
||||
|
||||
let installRMMCommand = `Install-DattoRMM -ApiUrl '${window.ApiUrl}' -ApiKey '${window.ApiKey}' -ApiSecretKey '${window.ApiSecretKey}'`;
|
||||
|
||||
if (checkedValues.includes('inputVar')) {
|
||||
installRMMCommand += ' -PushSiteVars';
|
||||
}
|
||||
if (checkedValues.includes('rmm')) {
|
||||
installRMMCommand += ' -InstallRMM';
|
||||
}
|
||||
if (checkedValues.includes('exe')) {
|
||||
installRMMCommand += ' -SaveCopy';
|
||||
if (setSVSPowerplan.checked) {
|
||||
fetch('/installSVSPowerplan', { method: 'GET' });
|
||||
appendLog("Setting SVS Powerplan", "cyan");
|
||||
}
|
||||
|
||||
console.log("Generated Command:", installRMMCommand);
|
||||
if (installSVSMSPModule.checked) {
|
||||
fetch('/installSVSMSPModule', { method: 'GET' });
|
||||
appendLog("Installing CyberQP", "cyan");
|
||||
|
||||
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 (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");
|
||||
fetch('/quit', { method: 'GET' })
|
||||
@@ -804,18 +849,18 @@ try {
|
||||
$data = ConvertFrom-Json $body
|
||||
$password = $data.password
|
||||
|
||||
# Run the function to fetch data
|
||||
Get-N8nWebhookData -AuthHeaderValue $password
|
||||
|
||||
# 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)
|
||||
$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
|
||||
$buffer = [System.Text.Encoding]::UTF8.GetBytes($responseData)
|
||||
$response.ContentType = "application/json"
|
||||
$response.ContentLength64 = $buffer.Length
|
||||
$response.OutputStream.Write($buffer, 0, $buffer.Length)
|
||||
@@ -823,7 +868,6 @@ try {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
"/installrmm" {
|
||||
if ($request.HttpMethod -eq "POST") {
|
||||
$bodyStream = New-Object IO.StreamReader $request.InputStream
|
||||
|
||||
Reference in New Issue
Block a user