173 lines
6.7 KiB
PowerShell
173 lines
6.7 KiB
PowerShell
# SVS TaskGate: Self-contained PowerShell Task Runner UI (All-in-One Script)
|
|
|
|
# ----- 1. TASK REGISTRY -----
|
|
$TaskRegistry = @{
|
|
Onboarding = @(
|
|
@{ Key = "installSVSMSP"; Label = "Install SVSMSP Module"; Function = "Install-SVSMSP" }
|
|
@{ Key = "installDattoRMM"; Label = "Install DattoRMM"; Function = "Install-DattoRMM" }
|
|
@{ Key = "installCyberQP"; Label = "Install CyberQP"; Function = "Install-CyberQP" }
|
|
)
|
|
Offboarding = @(
|
|
@{ Key = "uninstallSVSMSP"; Label = "Uninstall SVSMSP Module"; Function = "Uninstall-SVSMSP" }
|
|
@{ Key = "uninstallDattoRMM"; Label = "Uninstall DattoRMM"; Function = "Uninstall-DattoRMM" }
|
|
@{ Key = "uninstallCyberQP"; Label = "Uninstall CyberQP"; Function = "Uninstall-CyberQP" }
|
|
)
|
|
Tweaks = @(
|
|
@{ Key = "setPowerPlan"; Label = "Set Power Plan"; Function = "Set-SVSPowerPlan" }
|
|
@{ Key = "enableBitLocker"; Label = "Enable BitLocker"; Function = "Enable-BitLocker" }
|
|
)
|
|
}
|
|
|
|
# ----- 2. FUNCTION STUBS (Replace with real logic) -----
|
|
function Install-SVSMSP { Write-Host "Installing SVSMSP Module..." }
|
|
function Install-DattoRMM { Write-Host "Installing DattoRMM..." }
|
|
function Install-CyberQP { Write-Host "Installing CyberQP..." }
|
|
function Uninstall-SVSMSP { Write-Host "Uninstalling SVSMSP Module..." }
|
|
function Uninstall-DattoRMM { Write-Host "Uninstalling DattoRMM..." }
|
|
function Uninstall-CyberQP { Write-Host "Uninstalling CyberQP..." }
|
|
function Set-SVSPowerPlan { Write-Host "Setting SVS Power Plan..." }
|
|
function Enable-BitLocker { Write-Host "Enabling BitLocker..." }
|
|
|
|
# ----- 3. HTML UI GENERATOR -----
|
|
function Get-TasksHtml($group) {
|
|
$html = ""
|
|
foreach ($task in $TaskRegistry[$group]) {
|
|
$html += "<label><input type='checkbox' value='$($task.Key)'> $($task.Label)</label><br>`n"
|
|
}
|
|
return $html
|
|
}
|
|
|
|
$HtmlContent = @"
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>SVS TaskGate</title>
|
|
<style>
|
|
body { font-family: Arial, sans-serif; margin: 40px; background: #181c1f; color: #fff; }
|
|
h2 { color: #33aaff; }
|
|
.section { margin-bottom: 32px; }
|
|
.btn { padding: 10px 24px; margin-top: 8px; background: #33aaff; color: #fff; border: none; border-radius: 4px; cursor: pointer; }
|
|
.btn:disabled { background: #444; }
|
|
#output { margin-top: 20px; color: #2ecc40; font-weight: bold; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>SVS TaskGate</h1>
|
|
<div class="section">
|
|
<h2>Onboarding</h2>
|
|
<div id='onboarding-tasks'>
|
|
$(Get-TasksHtml 'Onboarding')
|
|
</div>
|
|
<button class="btn" onclick="runTasks('Onboarding')">Run Onboarding</button>
|
|
</div>
|
|
<div class="section">
|
|
<h2>Offboarding</h2>
|
|
<div id='offboarding-tasks'>
|
|
$(Get-TasksHtml 'Offboarding')
|
|
</div>
|
|
<button class="btn" onclick="runTasks('Offboarding')">Run Offboarding</button>
|
|
</div>
|
|
<div class="section">
|
|
<h2>Tweaks</h2>
|
|
<div id='tweaks-tasks'>
|
|
$(Get-TasksHtml 'Tweaks')
|
|
</div>
|
|
<button class="btn" onclick="runTasks('Tweaks')">Run Tweaks</button>
|
|
</div>
|
|
<div id="output"></div>
|
|
<script>
|
|
function runTasks(group) {
|
|
const container = document.getElementById(group.toLowerCase() + '-tasks');
|
|
const checkboxes = container.querySelectorAll('input[type="checkbox"]:checked');
|
|
const selected = Array.from(checkboxes).map(cb => cb.value);
|
|
if(selected.length==0){alert('No tasks selected');return;}
|
|
fetch('/run-tasks', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ group: group, tasks: selected })
|
|
})
|
|
.then(r=>r.json()).then(d=>{
|
|
document.getElementById('output').textContent = 'Executed: ' + d.executed.join(', ');
|
|
})
|
|
.catch(e => alert('Failed: ' + e));
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|
|
"@
|
|
|
|
# ----- 4. HTTP LISTENER (Self-contained, single-file, no dependencies) -----
|
|
Add-Type -AssemblyName System.Net.HttpListener
|
|
|
|
$listener = New-Object System.Net.HttpListener
|
|
$listener.Prefixes.Add("http://localhost:8081/")
|
|
$listener.Start()
|
|
Write-Host "TaskGate listening at http://localhost:8081/"
|
|
|
|
# Open browser to UI (Edge, fallback Chrome)
|
|
try {
|
|
Start-Process "msedge.exe" -ArgumentList "--app=http://localhost:8081/"
|
|
} catch {
|
|
Start-Process "chrome.exe" "http://localhost:8081/"
|
|
}
|
|
|
|
while ($listener.IsListening) {
|
|
$context = $listener.GetContext()
|
|
$req = $context.Request
|
|
$res = $context.Response
|
|
|
|
try {
|
|
switch ($req.Url.AbsolutePath) {
|
|
"/" {
|
|
$bytes = [System.Text.Encoding]::UTF8.GetBytes($HtmlContent)
|
|
$res.ContentType = "text/html"
|
|
$res.ContentLength64 = $bytes.Length
|
|
$res.OutputStream.Write($bytes, 0, $bytes.Length)
|
|
$res.OutputStream.Close()
|
|
}
|
|
"/run-tasks" {
|
|
if ($req.HttpMethod -ne "POST") {
|
|
$res.StatusCode = 405
|
|
$res.OutputStream.Close()
|
|
continue
|
|
}
|
|
$reader = New-Object IO.StreamReader $req.InputStream
|
|
$body = $reader.ReadToEnd() | ConvertFrom-Json
|
|
$group = $body.group
|
|
$selectedKeys = $body.tasks
|
|
$executed = @()
|
|
foreach ($key in $selectedKeys) {
|
|
$task = $TaskRegistry[$group] | Where-Object { $_.Key -eq $key }
|
|
if ($task) {
|
|
try {
|
|
& $task.Function
|
|
$executed += $task.Label
|
|
} catch {
|
|
$executed += "$($task.Label) (ERROR)"
|
|
}
|
|
}
|
|
}
|
|
$resp = @{ status = "OK"; executed = $executed }
|
|
$bytes = [System.Text.Encoding]::UTF8.GetBytes(($resp | ConvertTo-Json))
|
|
$res.ContentType = "application/json"
|
|
$res.ContentLength64 = $bytes.Length
|
|
$res.OutputStream.Write($bytes, 0, $bytes.Length)
|
|
$res.OutputStream.Close()
|
|
}
|
|
default {
|
|
$res.StatusCode = 404
|
|
$bytes = [System.Text.Encoding]::UTF8.GetBytes("404 Not Found")
|
|
$res.OutputStream.Write($bytes, 0, $bytes.Length)
|
|
$res.OutputStream.Close()
|
|
}
|
|
}
|
|
} catch {
|
|
$res.StatusCode = 500
|
|
$err = "Error: $($_.Exception.Message)"
|
|
$bytes = [System.Text.Encoding]::UTF8.GetBytes($err)
|
|
$res.OutputStream.Write($bytes, 0, $bytes.Length)
|
|
$res.OutputStream.Close()
|
|
}
|
|
}
|