Update testTaskGate.ps1
This commit is contained in:
410
testTaskGate.ps1
410
testTaskGate.ps1
@@ -1,338 +1,172 @@
|
|||||||
###-----------------------------------------------------------------------------###
|
# SVS TaskGate: Self-contained PowerShell Task Runner UI (All-in-One Script)
|
||||||
### SVS TaskGate Launcher
|
|
||||||
###-----------------------------------------------------------------------------###
|
|
||||||
|
|
||||||
# 1) GLOBAL LOG CACHE
|
# ----- 1. TASK REGISTRY -----
|
||||||
if (-not $Global:LogCache -or -not ($Global:LogCache -is [System.Collections.ArrayList])) {
|
$TaskRegistry = @{
|
||||||
$Global:LogCache = New-Object System.Collections.ArrayList
|
Onboarding = @(
|
||||||
}
|
@{ Key = "installSVSMSP"; Label = "Install SVSMSP Module"; Function = "Install-SVSMSP" }
|
||||||
|
@{ Key = "installDattoRMM"; Label = "Install DattoRMM"; Function = "Install-DattoRMM" }
|
||||||
#region Write-LogHybrid
|
@{ Key = "installCyberQP"; Label = "Install CyberQP"; Function = "Install-CyberQP" }
|
||||||
if (-not (Get-Command Write-Log -ErrorAction SilentlyContinue)) {
|
)
|
||||||
function Write-LogHelper {
|
Offboarding = @(
|
||||||
param(
|
@{ Key = "uninstallSVSMSP"; Label = "Uninstall SVSMSP Module"; Function = "Uninstall-SVSMSP" }
|
||||||
[string]$Message,
|
@{ Key = "uninstallDattoRMM"; Label = "Uninstall DattoRMM"; Function = "Uninstall-DattoRMM" }
|
||||||
[ValidateSet("Info","Warning","Error","Success","General")]
|
@{ Key = "uninstallCyberQP"; Label = "Uninstall CyberQP"; Function = "Uninstall-CyberQP" }
|
||||||
[string]$Level = "Info",
|
)
|
||||||
[string]$TaskCategory = "GeneralTask",
|
Tweaks = @(
|
||||||
[switch]$LogToEvent,
|
@{ Key = "setPowerPlan"; Label = "Set Power Plan"; Function = "Set-SVSPowerPlan" }
|
||||||
[string]$EventSource = "SVSMSP_Module",
|
@{ Key = "enableBitLocker"; Label = "Enable BitLocker"; Function = "Enable-BitLocker" }
|
||||||
[string]$EventLog = "Application"
|
|
||||||
)
|
)
|
||||||
$EventID = switch($Level){
|
|
||||||
"Info" {1000}; "Warning"{2000}; "Error"{3000}; "Success"{4000}; default{1000}
|
|
||||||
}
|
|
||||||
$Icon = switch($Level){
|
|
||||||
"Info" { [char]0x1F4CB }
|
|
||||||
"Warning" { [char]0x26A0 }
|
|
||||||
"Error" { [char]0x274C }
|
|
||||||
"Success" { [char]0x2705 }
|
|
||||||
default { [char]0x1F4E6 }
|
|
||||||
}
|
|
||||||
$entry = [PSCustomObject]@{
|
|
||||||
Timestamp = (Get-Date).ToString("yyyy-MM-dd HH:mm:ss")
|
|
||||||
Level = $Level
|
|
||||||
Message = "$Icon [$Level] [$TaskCategory] $Message (Event ID: $EventID)"
|
|
||||||
}
|
|
||||||
[void]$Global:LogCache.Add($entry)
|
|
||||||
if ($LogToEvent) {
|
|
||||||
try {
|
|
||||||
if (-not (Get-EventLog -LogName $EventLog -Source $EventSource -ErrorAction SilentlyContinue)) {
|
|
||||||
New-EventLog -LogName $EventLog -Source $EventSource -ErrorAction SilentlyContinue
|
|
||||||
}
|
|
||||||
Write-EventLog -LogName $EventLog -Source $EventSource `
|
|
||||||
-EntryType $Level -EventId $EventID -Message $Message
|
|
||||||
} catch {
|
|
||||||
Write-Host "⚠ Failed writing to EventLog: $($_.Exception.Message)" -ForegroundColor Yellow
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function Write-LogHybrid { param($Message,$Level,$TaskCategory,$LogToEvent)
|
|
||||||
Write-LogHelper -Message $Message -Level $Level -TaskCategory $TaskCategory -LogToEvent:$LogToEvent
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
function Write-LogHybrid { param($Message,$Level,$TaskCategory,$LogToEvent)
|
|
||||||
Write-Log -Message $Message -Level $Level -TaskCategory $TaskCategory -LogToEvent:$LogToEvent
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Write-LogHybrid -Message "Starting SVS TaskGate" -Level Info -TaskCategory Startup -LogToEvent
|
|
||||||
|
|
||||||
#region Helpers for DattoRMM, LastPass, SVS Module…
|
# ----- 2. FUNCTION STUBS (Replace with real logic) -----
|
||||||
# (Insert your existing Install-DattoRMM-Helper, LastPass and Install-SVSMSP functions here.)
|
function Install-SVSMSP { Write-Host "Installing SVSMSP Module..." }
|
||||||
#endregion
|
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
|
||||||
|
}
|
||||||
|
|
||||||
#region HTTP Listener Setup
|
$HtmlContent = @"
|
||||||
$listener = New-Object System.Net.HttpListener
|
|
||||||
$listener.Prefixes.Add("http://localhost:8081/")
|
|
||||||
$listener.Start()
|
|
||||||
Write-LogHybrid -Message "Listener started on http://localhost:8081/" -Level Info -TaskCategory Listener
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
|
|
||||||
#region HTML UI & CSS
|
|
||||||
function GetHtmlContent {
|
|
||||||
@"
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta charset="UTF-8">
|
||||||
<title>SVS TaskGate</title>
|
<title>SVS TaskGate</title>
|
||||||
<link rel="icon" href="https://git.svstools.com/syelle/Logo/raw/branch/main/SVS_Favicon.ico">
|
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
:root {
|
body { font-family: Arial, sans-serif; margin: 40px; background: #181c1f; color: #fff; }
|
||||||
--background-color: rgba(18,18,18,1);
|
h2 { color: #33aaff; }
|
||||||
--border-color: rgba(255,127,0,0.25);
|
.section { margin-bottom: 32px; }
|
||||||
--white-color: rgba(255,255,255,1);
|
.btn { padding: 10px 24px; margin-top: 8px; background: #33aaff; color: #fff; border: none; border-radius: 4px; cursor: pointer; }
|
||||||
--gray-color: rgba(102,102,102,1);
|
.btn:disabled { background: #444; }
|
||||||
--btn-success: rgba(40,167,69,1);
|
#output { margin-top: 20px; color: #2ecc40; font-weight: bold; }
|
||||||
--btn-success-disabled: rgba(108,117,125,1);
|
|
||||||
--btn-danger: rgba(220,53,69,1);
|
|
||||||
--btn-sidebar-light-gray: rgba(68,68,68,1);
|
|
||||||
--btn-sidebar-blue: rgba(30,144,255,1);
|
|
||||||
--btn-hover: rgba(0,86,179,1);
|
|
||||||
--btn-hover-scale: 1.05;
|
|
||||||
}
|
|
||||||
body {
|
|
||||||
margin:0; padding:0;
|
|
||||||
background:var(--background-color);
|
|
||||||
color:var(--white-color);
|
|
||||||
font-family:Arial,sans-serif;
|
|
||||||
height:100vh; overflow:hidden;
|
|
||||||
}
|
|
||||||
.logo-container {
|
|
||||||
padding:20px; background:var(--background-color);
|
|
||||||
}
|
|
||||||
.logo-container img { max-width:200px; }
|
|
||||||
.container { display:flex; height:calc(100% - 60px); }
|
|
||||||
.sidebar {
|
|
||||||
width:200px; padding:10px;
|
|
||||||
background:var(--background-color);
|
|
||||||
}
|
|
||||||
.sidebar button {
|
|
||||||
width:100%; margin-bottom:10px; padding:10px;
|
|
||||||
background:var(--btn-sidebar-light-gray);
|
|
||||||
border:none; border-radius:4px;
|
|
||||||
color:var(--white-color);
|
|
||||||
text-align:left; cursor:pointer;
|
|
||||||
transition:background 0.2s,transform 0.2s;
|
|
||||||
}
|
|
||||||
.sidebar button.active {
|
|
||||||
background:var(--btn-sidebar-blue);
|
|
||||||
}
|
|
||||||
.sidebar button:hover {
|
|
||||||
background:var(--btn-hover);
|
|
||||||
transform:scale(var(--btn-hover-scale));
|
|
||||||
}
|
|
||||||
.content {
|
|
||||||
flex:1; padding:20px; overflow-y:auto;
|
|
||||||
}
|
|
||||||
.tab-content { display:none; }
|
|
||||||
.tab-content.active { display:block; }
|
|
||||||
.button-group {
|
|
||||||
margin-top:20px; text-align:right;
|
|
||||||
}
|
|
||||||
.button-group button {
|
|
||||||
margin-left:10px; padding:0.75rem 1.5rem;
|
|
||||||
border:none; border-radius:4px; cursor:pointer;
|
|
||||||
font-size:1rem;
|
|
||||||
transition:opacity 0.1s;
|
|
||||||
}
|
|
||||||
.button-group button:hover:not(:disabled) { opacity:0.9; }
|
|
||||||
.install-button {
|
|
||||||
background:var(--btn-success); color:#fff;
|
|
||||||
}
|
|
||||||
.install-button:disabled {
|
|
||||||
background:var(--btn-success-disabled); cursor:not-allowed;
|
|
||||||
}
|
|
||||||
.exit-button {
|
|
||||||
background:var(--btn-danger); color:#fff;
|
|
||||||
}
|
|
||||||
/* HIDE the old log pane */
|
|
||||||
.log { display:none !important; }
|
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<h1>SVS TaskGate</h1>
|
||||||
<div class="logo-container">
|
<div class="section">
|
||||||
<img src="https://git.svstools.com/syelle/Logo/raw/branch/main/SVS_logo.svg" alt="SVS Logo">
|
<h2>Onboarding</h2>
|
||||||
|
<div id='onboarding-tasks'>
|
||||||
|
$(Get-TasksHtml 'Onboarding')
|
||||||
</div>
|
</div>
|
||||||
|
<button class="btn" onclick="runTasks('Onboarding')">Run Onboarding</button>
|
||||||
<div class="container">
|
|
||||||
<div class="sidebar">
|
|
||||||
<button class="tab-button active" data-tab="onboardTab" aria-expanded="true">On-Boarding</button>
|
|
||||||
<button class="tab-button" data-tab="tweaksTab">Apply Tweaks</button>
|
|
||||||
<button class="tab-button" data-tab="SVSAppsTab">Install SVS Apps</button>
|
|
||||||
</div>
|
</div>
|
||||||
|
<div class="section">
|
||||||
<div class="content">
|
<h2>Offboarding</h2>
|
||||||
<!-- On-Boarding (just placeholder for context) -->
|
<div id='offboarding-tasks'>
|
||||||
<div id="onboardTab" class="tab-content active">
|
$(Get-TasksHtml 'Offboarding')
|
||||||
<h2>On-Boarding</h2>
|
|
||||||
<p>…your original onboarding controls…</p>
|
|
||||||
</div>
|
</div>
|
||||||
|
<button class="btn" onclick="runTasks('Offboarding')">Run Offboarding</button>
|
||||||
<!-- Tweaks Tab -->
|
|
||||||
<div id="tweaksTab" class="tab-content">
|
|
||||||
<h2>Apply Tweaks</h2>
|
|
||||||
<div id="tweaksGroup" class="checkbox-group">
|
|
||||||
<label><input type="checkbox" id="disableAnimations"> Disable Animations</label><br>
|
|
||||||
<label><input type="checkbox" id="optimizePerformance"> Optimize Performance</label><br>
|
|
||||||
<label><input type="checkbox" id="increaseFontSize"> Increase Font Size</label>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="button-group">
|
<div class="section">
|
||||||
<button class="install-button" onclick="triggerTweaks()">Apply Tweaks</button>
|
<h2>Tweaks</h2>
|
||||||
|
<div id='tweaks-tasks'>
|
||||||
|
$(Get-TasksHtml 'Tweaks')
|
||||||
</div>
|
</div>
|
||||||
|
<button class="btn" onclick="runTasks('Tweaks')">Run Tweaks</button>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="output"></div>
|
||||||
<!-- SVS Apps Tab -->
|
|
||||||
<div id="SVSAppsTab" class="tab-content">
|
|
||||||
<h2>Install SVS Apps</h2>
|
|
||||||
<div id="wingetGroup" class="checkbox-group">
|
|
||||||
<h4>Winget Apps</h4>
|
|
||||||
<label><input class="winget-checkbox" name="wingetLastpass" type="checkbox"> LastPass</label><br>
|
|
||||||
<label><input class="winget-checkbox" name="wingetBitwarden" type="checkbox"> Bitwarden</label>
|
|
||||||
</div>
|
|
||||||
<div id="extensionsGroup" class="checkbox-group">
|
|
||||||
<h4>Browser Extensions</h4>
|
|
||||||
<label><input class="extension-checkbox" name="installLastPassChrome" type="checkbox"> LastPass Chrome</label><br>
|
|
||||||
<label><input class="extension-checkbox" name="installLastPassEdge" type="checkbox"> LastPass Edge</label>
|
|
||||||
</div>
|
|
||||||
<div class="button-group">
|
|
||||||
<button class="install-button" onclick="triggerSVSApps()">Install SVS Apps</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// 1) TAB NAVIGATION
|
function runTasks(group) {
|
||||||
const tabButtons = document.querySelectorAll('.tab-button');
|
const container = document.getElementById(group.toLowerCase() + '-tasks');
|
||||||
const tabContents = document.querySelectorAll('.tab-content');
|
const checkboxes = container.querySelectorAll('input[type="checkbox"]:checked');
|
||||||
tabButtons.forEach(btn => {
|
const selected = Array.from(checkboxes).map(cb => cb.value);
|
||||||
btn.addEventListener('click', () => {
|
if(selected.length==0){alert('No tasks selected');return;}
|
||||||
tabButtons.forEach(b=>{ b.classList.remove('active'); b.setAttribute('aria-expanded','false') });
|
fetch('/run-tasks', {
|
||||||
tabContents.forEach(c=>c.classList.remove('active'));
|
|
||||||
btn.classList.add('active');
|
|
||||||
btn.setAttribute('aria-expanded','true');
|
|
||||||
document.getElementById(btn.dataset.tab).classList.add('active');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// 2) TRIGGER APPLY TWEAKS
|
|
||||||
function triggerTweaks() {
|
|
||||||
const tweaks = Array.from(
|
|
||||||
document.querySelectorAll('#tweaksGroup input[type="checkbox"]')
|
|
||||||
)
|
|
||||||
.filter(cb=>cb.checked)
|
|
||||||
.map(cb=>cb.id);
|
|
||||||
|
|
||||||
if (tweaks.length === 0) {
|
|
||||||
alert("Select at least one tweak.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
fetch('/runTweaks', {
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers:{'Content-Type':'application/json'},
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ tweaks })
|
body: JSON.stringify({ group: group, tasks: selected })
|
||||||
})
|
})
|
||||||
.then(r=>r.ok ? alert("Tweaks applied!") : alert("Error applying tweaks"))
|
.then(r=>r.json()).then(d=>{
|
||||||
.catch(e=>alert("Network error: "+e));
|
document.getElementById('output').textContent = 'Executed: ' + d.executed.join(', ');
|
||||||
}
|
|
||||||
|
|
||||||
// 3) TRIGGER INSTALL SVS APPS
|
|
||||||
function triggerSVSApps() {
|
|
||||||
const wingetSel = Array.from(
|
|
||||||
document.querySelectorAll('.winget-checkbox')
|
|
||||||
).filter(cb=>cb.checked).map(cb=>cb.name);
|
|
||||||
const extSel = Array.from(
|
|
||||||
document.querySelectorAll('.extension-checkbox')
|
|
||||||
).filter(cb=>cb.checked).map(cb=>cb.name);
|
|
||||||
|
|
||||||
if (wingetSel.length+extSel.length === 0) {
|
|
||||||
alert("Select at least one app or extension.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
fetch('/installSVSApps', {
|
|
||||||
method: 'POST',
|
|
||||||
headers:{'Content-Type':'application/json'},
|
|
||||||
body: JSON.stringify({ winget: wingetSel, extensions: extSel })
|
|
||||||
})
|
})
|
||||||
.then(r=>r.ok ? alert("Installation triggered!") : alert("Error triggering install"))
|
.catch(e => alert('Failed: ' + e));
|
||||||
.catch(e=>alert("Network error: "+e));
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
"@
|
"@
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
|
# ----- 4. HTTP LISTENER (Self-contained, single-file, no dependencies) -----
|
||||||
|
Add-Type -AssemblyName System.Net.HttpListener
|
||||||
|
|
||||||
# 3) LAUNCH THE UI
|
$listener = New-Object System.Net.HttpListener
|
||||||
Start-Process "msedge.exe" -ArgumentList "--app=http://localhost:8081/"
|
$listener.Prefixes.Add("http://localhost:8081/")
|
||||||
|
$listener.Start()
|
||||||
|
Write-Host "TaskGate listening at http://localhost:8081/"
|
||||||
|
|
||||||
|
# Open browser to UI (Edge, fallback Chrome)
|
||||||
#region 4) ROUTE HANDLING
|
|
||||||
try {
|
try {
|
||||||
while ($listener.IsListening) {
|
Start-Process "msedge.exe" -ArgumentList "--app=http://localhost:8081/"
|
||||||
$ctx = $listener.GetContext()
|
} catch {
|
||||||
$req = $ctx.Request
|
Start-Process "chrome.exe" "http://localhost:8081/"
|
||||||
$res = $ctx.Response
|
}
|
||||||
|
|
||||||
|
while ($listener.IsListening) {
|
||||||
|
$context = $listener.GetContext()
|
||||||
|
$req = $context.Request
|
||||||
|
$res = $context.Response
|
||||||
|
|
||||||
|
try {
|
||||||
switch ($req.Url.AbsolutePath) {
|
switch ($req.Url.AbsolutePath) {
|
||||||
"/" {
|
"/" {
|
||||||
$html = GetHtmlContent
|
$bytes = [System.Text.Encoding]::UTF8.GetBytes($HtmlContent)
|
||||||
$bytes = [Text.Encoding]::UTF8.GetBytes($html)
|
|
||||||
$res.ContentType = "text/html"
|
$res.ContentType = "text/html"
|
||||||
$res.ContentLength64 = $bytes.Length
|
$res.ContentLength64 = $bytes.Length
|
||||||
$res.OutputStream.Write($bytes,0,$bytes.Length)
|
$res.OutputStream.Write($bytes, 0, $bytes.Length)
|
||||||
$res.OutputStream.Close()
|
$res.OutputStream.Close()
|
||||||
}
|
}
|
||||||
|
"/run-tasks" {
|
||||||
"/runTweaks" {
|
if ($req.HttpMethod -ne "POST") {
|
||||||
if ($req.HttpMethod -eq "POST") {
|
$res.StatusCode = 405
|
||||||
$body = (New-Object IO.StreamReader $req.InputStream).ReadToEnd() | ConvertFrom-Json
|
$res.OutputStream.Close()
|
||||||
Write-LogHybrid -Message "Tweaks: $($body.tweaks -join ', ')" -Level Info -TaskCategory Tweaks
|
continue
|
||||||
# TODO: call your actual tweak functions here...
|
}
|
||||||
$res.StatusCode = 200
|
$reader = New-Object IO.StreamReader $req.InputStream
|
||||||
$res.OutputStream.Write(([Text.Encoding]::UTF8.GetBytes("OK")),0,2)
|
$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)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
"/installSVSApps" {
|
|
||||||
if ($req.HttpMethod -eq "POST") {
|
|
||||||
$data = (New-Object IO.StreamReader $req.InputStream).ReadToEnd() | ConvertFrom-Json
|
|
||||||
Write-LogHybrid -Message "Winget: $($data.winget -join ', ')" -Level Info -TaskCategory "SVSApps"
|
|
||||||
Write-LogHybrid -Message "Extensions: $($data.extensions -join ', ')" -Level Info -TaskCategory "SVSApps"
|
|
||||||
# TODO: invoke your winget & extension helpers here...
|
|
||||||
$res.StatusCode = 200
|
|
||||||
$res.OutputStream.Write(([Text.Encoding]::UTF8.GetBytes("OK")),0,2)
|
|
||||||
}
|
}
|
||||||
|
$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()
|
||||||
}
|
}
|
||||||
|
|
||||||
"/quit" {
|
|
||||||
$res.StatusCode = 200
|
|
||||||
$res.OutputStream.Write(([Text.Encoding]::UTF8.GetBytes("bye")),0,3)
|
|
||||||
$listener.Stop()
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
default {
|
default {
|
||||||
$res.StatusCode = 404
|
$res.StatusCode = 404
|
||||||
$res.OutputStream.Write(([Text.Encoding]::UTF8.GetBytes("Not Found")),0,9)
|
$bytes = [System.Text.Encoding]::UTF8.GetBytes("404 Not Found")
|
||||||
|
$res.OutputStream.Write($bytes, 0, $bytes.Length)
|
||||||
|
$res.OutputStream.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch {
|
||||||
}
|
$res.StatusCode = 500
|
||||||
finally {
|
$err = "Error: $($_.Exception.Message)"
|
||||||
if ($listener) {
|
$bytes = [System.Text.Encoding]::UTF8.GetBytes($err)
|
||||||
Write-LogHybrid -Message "Stopping listener" -Level Info -TaskCategory Listener
|
$res.OutputStream.Write($bytes, 0, $bytes.Length)
|
||||||
$listener.Stop(); $listener.Close()
|
$res.OutputStream.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user