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
|
# Check if the Write-Log function exists
|
||||||
if (-not (Get-Command -Name Write-Log -CommandType Function -ErrorAction SilentlyContinue)) {
|
if (-not (Get-Command -Name Write-Log -CommandType Function -ErrorAction SilentlyContinue)) {
|
||||||
# If the Write-Log function doesn't exist, create the Write-LogHelper function
|
# If the Write-Log function doesn't exist, create the Write-LogHelper function
|
||||||
@@ -596,11 +601,11 @@ function GetHtmlContent {
|
|||||||
|
|
||||||
if (dattoRMMCheckbox.checked) {
|
if (dattoRMMCheckbox.checked) {
|
||||||
optionsContainer.style.display = 'block';
|
optionsContainer.style.display = 'block';
|
||||||
// n8nPasswordContainer.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';
|
||||||
// n8nPasswordContainer.style.display = 'none';
|
n8nPasswordContainer.style.display = 'none';
|
||||||
dattoRMMContainer.style.display = 'none';
|
dattoRMMContainer.style.display = 'none';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -612,7 +617,7 @@ function GetHtmlContent {
|
|||||||
const DattoRMMContainer = document.getElementById('DattoRMMContainer');
|
const DattoRMMContainer = document.getElementById('DattoRMMContainer');
|
||||||
|
|
||||||
optionsContainer.style.display = checkbox.checked ? 'block' : 'none';
|
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';
|
DattoRMMContainer.style.display = checkbox.checked ? 'block' : 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -649,7 +654,7 @@ function GetHtmlContent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
appendLog("Fetching sites and API credentials...", "yellow");
|
appendLog("Fetching sites...", "yellow");
|
||||||
|
|
||||||
const response = await fetch('/getn8npw', {
|
const response = await fetch('/getn8npw', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -661,68 +666,108 @@ function GetHtmlContent {
|
|||||||
throw new Error('Failed to fetch sites. Please try again.');
|
throw new Error('Failed to fetch sites. Please try again.');
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json();
|
const sites = await response.json();
|
||||||
|
|
||||||
// Populate the dropdown with sites
|
|
||||||
dropdown.innerHTML = '';
|
dropdown.innerHTML = '';
|
||||||
data.Sites.forEach(site => {
|
|
||||||
|
sites.forEach(site => {
|
||||||
const option = document.createElement('option');
|
const option = document.createElement('option');
|
||||||
option.value = site.UID; // Adjust based on your data structure
|
// Adjust property names based on your actual data
|
||||||
option.textContent = site.Name; // Adjust based on your data structure
|
option.value = site.UID;
|
||||||
|
option.textContent = site.Name;
|
||||||
dropdown.appendChild(option);
|
dropdown.appendChild(option);
|
||||||
});
|
});
|
||||||
|
|
||||||
appendLog("Sites fetched successfully, please select a site!", "green");
|
appendLog("Sites fetched successfully, please select a site!", "green");
|
||||||
|
}
|
||||||
// Store the API credentials globally for later use
|
catch (error) {
|
||||||
window.ApiUrl = data.ApiUrl;
|
|
||||||
window.ApiKey = data.ApiKey;
|
|
||||||
window.ApiSecretKey = data.ApiSecretKey;
|
|
||||||
} catch (error) {
|
|
||||||
dropdown.innerHTML = '<option value="">Fetching sites failed</option>';
|
dropdown.innerHTML = '<option value="">Fetching sites failed</option>';
|
||||||
appendLog('Error: ' + error.message, "red");
|
appendLog('Error:' + error.message, "red");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function triggerInstall() {
|
function triggerInstall() {
|
||||||
const dropdown = document.getElementById('dattoRmmDropdown');
|
const dropdown = document.getElementById('dattoRmmDropdown');
|
||||||
const UID = dropdown.options[dropdown.selectedIndex].value;
|
const UID = dropdown.options[dropdown.selectedIndex].value;
|
||||||
const Name = dropdown.options[dropdown.selectedIndex].text;
|
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) {
|
if (installDattoRMM.checked) {
|
||||||
appendLog("API credentials are missing. Please fetch them first.", "red");
|
const DattoRMMCheckbox = document.querySelectorAll('input[name="dattoRMMOption"]:checked');
|
||||||
return;
|
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 (setSVSPowerplan.checked) {
|
||||||
|
fetch('/installSVSPowerplan', { method: 'GET' });
|
||||||
if (checkedValues.includes('inputVar')) {
|
appendLog("Setting SVS Powerplan", "cyan");
|
||||||
installRMMCommand += ' -PushSiteVars';
|
|
||||||
}
|
|
||||||
if (checkedValues.includes('rmm')) {
|
|
||||||
installRMMCommand += ' -InstallRMM';
|
|
||||||
}
|
|
||||||
if (checkedValues.includes('exe')) {
|
|
||||||
installRMMCommand += ' -SaveCopy';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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' },
|
if (installCyberQP.checked) {
|
||||||
body: JSON.stringify({ installRMMCommand, UID, Name })
|
fetch('/installCyberQP', { method: 'GET' });
|
||||||
}).then(() => {
|
appendLog("Installing CyberQP", "cyan");
|
||||||
appendLog(`RMM installation command sent for ${Name}`, "green");
|
}
|
||||||
}).catch(err => {
|
if (installSplashtop.checked) {
|
||||||
appendLog(`Error sending command: ${err.message}`, "red");
|
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() {
|
function endSession() {
|
||||||
appendLog("Session ended. Closing application...", "yellow");
|
appendLog("Session ended. Closing application...", "yellow");
|
||||||
fetch('/quit', { method: 'GET' })
|
fetch('/quit', { method: 'GET' })
|
||||||
@@ -804,18 +849,18 @@ try {
|
|||||||
$data = ConvertFrom-Json $body
|
$data = ConvertFrom-Json $body
|
||||||
$password = $data.password
|
$password = $data.password
|
||||||
|
|
||||||
# Run the function to fetch data
|
|
||||||
Get-N8nWebhookData -AuthHeaderValue $password
|
Get-N8nWebhookData -AuthHeaderValue $password
|
||||||
|
$sites = Install-DattoRMM -ApiUrl $ApiUrl -ApiKey $ApiKey -ApiSecretKey $ApiSecretKey -FetchSitesOnly
|
||||||
# Include the dynamically fetched variables in the response
|
if (-not $sites) {
|
||||||
$responseData = @{
|
Write-Host "No sites returned. Please check the API." -ForegroundColor Red
|
||||||
ApiUrl = $global:ApiUrl
|
$response.StatusCode = 500
|
||||||
ApiKey = $global:ApiKey
|
$buffer = [System.Text.Encoding]::UTF8.GetBytes("No sites found")
|
||||||
ApiSecretKey = $global:ApiSecretKey
|
$response.OutputStream.Write($buffer, 0, $buffer.Length)
|
||||||
Sites = Install-DattoRMM -ApiUrl $global:ApiUrl -ApiKey $global:ApiKey -ApiSecretKey $global:ApiSecretKey -FetchSitesOnly
|
$response.OutputStream.Close()
|
||||||
} | ConvertTo-Json -Depth 2
|
continue
|
||||||
|
}
|
||||||
$buffer = [System.Text.Encoding]::UTF8.GetBytes($responseData)
|
$responseData = $sites | ConvertTo-Json
|
||||||
|
$buffer = [System.Text.Encoding]::UTF8.GetBytes($responseData)
|
||||||
$response.ContentType = "application/json"
|
$response.ContentType = "application/json"
|
||||||
$response.ContentLength64 = $buffer.Length
|
$response.ContentLength64 = $buffer.Length
|
||||||
$response.OutputStream.Write($buffer, 0, $buffer.Length)
|
$response.OutputStream.Write($buffer, 0, $buffer.Length)
|
||||||
@@ -823,7 +868,6 @@ try {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
"/installrmm" {
|
"/installrmm" {
|
||||||
if ($request.HttpMethod -eq "POST") {
|
if ($request.HttpMethod -eq "POST") {
|
||||||
$bodyStream = New-Object IO.StreamReader $request.InputStream
|
$bodyStream = New-Object IO.StreamReader $request.InputStream
|
||||||
|
|||||||
Reference in New Issue
Block a user