Add internal KVM switch dashboard and service
This commit is contained in:
@@ -0,0 +1,439 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Internal KVM Switch</title>
|
||||
<style>
|
||||
:root {
|
||||
--bg-a: #f8f2e8;
|
||||
--bg-b: #eef6f3;
|
||||
--panel: rgba(255, 255, 255, 0.82);
|
||||
--ink: #102027;
|
||||
--ink-soft: #4f6169;
|
||||
--line: rgba(16, 32, 39, 0.16);
|
||||
--ok: #0f766e;
|
||||
--warn: #b45309;
|
||||
--err: #b91c1c;
|
||||
--chip: #e9f6f3;
|
||||
--shadow: 0 28px 56px rgba(12, 30, 44, 0.14);
|
||||
--radius: 18px;
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; }
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
min-height: 100vh;
|
||||
color: var(--ink);
|
||||
font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
|
||||
background:
|
||||
radial-gradient(1100px 520px at -10% -10%, rgba(15, 118, 110, 0.18), transparent 60%),
|
||||
radial-gradient(900px 460px at 110% 110%, rgba(180, 83, 9, 0.16), transparent 60%),
|
||||
linear-gradient(140deg, var(--bg-a) 0%, var(--bg-b) 100%);
|
||||
}
|
||||
|
||||
.shell {
|
||||
max-width: 1080px;
|
||||
margin: 0 auto;
|
||||
padding: 28px 20px 38px;
|
||||
}
|
||||
|
||||
.hero,
|
||||
.card {
|
||||
border: 1px solid var(--line);
|
||||
border-radius: calc(var(--radius) + 4px);
|
||||
background: var(--panel);
|
||||
box-shadow: var(--shadow);
|
||||
backdrop-filter: blur(8px);
|
||||
}
|
||||
|
||||
.hero {
|
||||
padding: 24px;
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
|
||||
.eyebrow {
|
||||
margin: 0 0 10px;
|
||||
font-size: 0.78rem;
|
||||
letter-spacing: 0.15em;
|
||||
text-transform: uppercase;
|
||||
color: var(--ok);
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin: 0 0 12px;
|
||||
font-size: clamp(1.9rem, 3.1vw, 3rem);
|
||||
line-height: 1.05;
|
||||
}
|
||||
|
||||
.hero p {
|
||||
margin: 0;
|
||||
color: var(--ink-soft);
|
||||
line-height: 1.55;
|
||||
max-width: 70ch;
|
||||
}
|
||||
|
||||
.layout {
|
||||
display: grid;
|
||||
gap: 16px;
|
||||
grid-template-columns: 1.05fr 1.25fr;
|
||||
}
|
||||
|
||||
@media (max-width: 920px) {
|
||||
.layout {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.card {
|
||||
padding: 18px;
|
||||
border-radius: var(--radius);
|
||||
}
|
||||
|
||||
.card h2 {
|
||||
margin: 0 0 14px;
|
||||
font-size: 1.05rem;
|
||||
}
|
||||
|
||||
.field {
|
||||
display: block;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
|
||||
.field span {
|
||||
display: block;
|
||||
font-size: 0.92rem;
|
||||
margin-bottom: 7px;
|
||||
font-weight: 650;
|
||||
}
|
||||
|
||||
input[type="number"],
|
||||
select {
|
||||
width: 100%;
|
||||
border: 1px solid rgba(16, 32, 39, 0.2);
|
||||
border-radius: 12px;
|
||||
padding: 12px 13px;
|
||||
font-size: 1rem;
|
||||
color: var(--ink);
|
||||
background: #fff;
|
||||
outline: none;
|
||||
transition: border-color 140ms ease, box-shadow 140ms ease;
|
||||
}
|
||||
|
||||
input[type="number"]:focus,
|
||||
select:focus {
|
||||
border-color: var(--ok);
|
||||
box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.15);
|
||||
}
|
||||
|
||||
.hint {
|
||||
margin: 2px 0 14px;
|
||||
color: var(--ink-soft);
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
code {
|
||||
background: rgba(16, 32, 39, 0.06);
|
||||
border-radius: 6px;
|
||||
padding: 2px 6px;
|
||||
font-family: Consolas, "Courier New", monospace;
|
||||
font-size: 0.86em;
|
||||
}
|
||||
|
||||
.actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
button {
|
||||
border: 0;
|
||||
border-radius: 999px;
|
||||
padding: 10px 16px;
|
||||
font-weight: 700;
|
||||
font-size: 0.96rem;
|
||||
color: #fff;
|
||||
background: linear-gradient(135deg, #0f766e, #0a5b55);
|
||||
box-shadow: 0 14px 28px rgba(15, 118, 110, 0.26);
|
||||
cursor: pointer;
|
||||
transition: transform 120ms ease, filter 120ms ease;
|
||||
}
|
||||
|
||||
button:hover { transform: translateY(-1px); }
|
||||
button:disabled { opacity: 0.68; cursor: wait; transform: none; }
|
||||
|
||||
.message {
|
||||
min-height: 20px;
|
||||
margin-top: 12px;
|
||||
font-size: 0.9rem;
|
||||
color: var(--ink-soft);
|
||||
}
|
||||
|
||||
.message.error { color: var(--err); }
|
||||
.message.ok { color: var(--ok); }
|
||||
|
||||
.stats {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
@media (max-width: 560px) {
|
||||
.stats { grid-template-columns: 1fr; }
|
||||
}
|
||||
|
||||
.stat {
|
||||
border: 1px solid rgba(16, 32, 39, 0.12);
|
||||
border-radius: 12px;
|
||||
padding: 10px 12px;
|
||||
background: linear-gradient(180deg, #ffffff, #f7faf9);
|
||||
}
|
||||
|
||||
.stat .k {
|
||||
display: block;
|
||||
color: var(--ink-soft);
|
||||
font-size: 0.78rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.08em;
|
||||
margin-bottom: 5px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.stat .v {
|
||||
display: block;
|
||||
font-size: 1rem;
|
||||
font-weight: 700;
|
||||
color: var(--ink);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.tags {
|
||||
margin-top: 10px;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.tag {
|
||||
border-radius: 999px;
|
||||
padding: 6px 10px;
|
||||
font-size: 0.8rem;
|
||||
font-weight: 700;
|
||||
background: var(--chip);
|
||||
color: #065f59;
|
||||
border: 1px solid rgba(6, 95, 89, 0.18);
|
||||
}
|
||||
|
||||
.tag.warn {
|
||||
background: #fff6e9;
|
||||
border-color: rgba(180, 83, 9, 0.28);
|
||||
color: #92400e;
|
||||
}
|
||||
|
||||
.errors {
|
||||
margin-top: 12px;
|
||||
padding-left: 18px;
|
||||
color: var(--err);
|
||||
font-size: 0.92rem;
|
||||
}
|
||||
|
||||
.errors li + li {
|
||||
margin-top: 5px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main class="shell">
|
||||
<section class="hero">
|
||||
<p class="eyebrow">Alienware-Only Targeting</p>
|
||||
<h1>Internal KVM Switch Dashboard</h1>
|
||||
<p>
|
||||
Samsung is trigger-only and uses fixed codes: Tower = 15 and Laptop = 19. This dashboard only controls which Alienware input port each machine should switch to.
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section class="layout">
|
||||
<article class="card">
|
||||
<h2>Settings</h2>
|
||||
<form id="settings-form">
|
||||
<label class="field" for="device-role">
|
||||
<span>This Device Role</span>
|
||||
<select id="device-role" required>
|
||||
<option value="tower">Tower</option>
|
||||
<option value="laptop">Laptop</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="field" for="device-port">
|
||||
<span>This Device Alienware Port</span>
|
||||
<select id="device-port" required>
|
||||
<option value="DP1">DP1</option>
|
||||
<option value="DP2">DP2</option>
|
||||
<option value="HDMI">HDMI</option>
|
||||
</select>
|
||||
</label>
|
||||
<p class="hint">Samsung trigger logic is fixed: <code>15 = Tower</code>, <code>19 = Laptop</code>. The selected role and port are saved locally in <code>config.json</code>.</p>
|
||||
<div class="actions">
|
||||
<button id="save-btn" type="submit">Save Settings</button>
|
||||
</div>
|
||||
<div id="form-message" class="message" aria-live="polite"></div>
|
||||
</form>
|
||||
</article>
|
||||
|
||||
<article class="card">
|
||||
<h2>Live Status</h2>
|
||||
<div id="stats" class="stats"></div>
|
||||
<div id="tags" class="tags"></div>
|
||||
<ul id="errors" class="errors"></ul>
|
||||
</article>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<script>
|
||||
const els = {
|
||||
form: document.getElementById("settings-form"),
|
||||
role: document.getElementById("device-role"),
|
||||
port: document.getElementById("device-port"),
|
||||
saveBtn: document.getElementById("save-btn"),
|
||||
msg: document.getElementById("form-message"),
|
||||
stats: document.getElementById("stats"),
|
||||
tags: document.getElementById("tags"),
|
||||
errors: document.getElementById("errors"),
|
||||
};
|
||||
let formDirty = false;
|
||||
|
||||
function safe(value) {
|
||||
return value === null || value === undefined || value === "" ? "n/a" : String(value);
|
||||
}
|
||||
|
||||
function stat(label, value) {
|
||||
return `<div class="stat"><span class="k">${label}</span><span class="v">${safe(value)}</span></div>`;
|
||||
}
|
||||
|
||||
function renderStatus(payload) {
|
||||
const config = payload.config || {};
|
||||
const roleVal = config.device_role;
|
||||
const portVal = config.device_port;
|
||||
|
||||
if (!formDirty && document.activeElement !== els.role) {
|
||||
els.role.value = roleVal ?? "tower";
|
||||
}
|
||||
if (!formDirty && document.activeElement !== els.port) {
|
||||
els.port.value = portVal ?? "DP1";
|
||||
}
|
||||
|
||||
els.stats.innerHTML = [
|
||||
stat("Device Role", config.device_role),
|
||||
stat("This Device Port", config.device_port),
|
||||
stat("Samsung Present", payload.samsung_present ? "Yes" : "No"),
|
||||
stat("Trigger Input", payload.trigger_input_code),
|
||||
stat("Tower Trigger", "15"),
|
||||
stat("Laptop Trigger", "19"),
|
||||
stat("Alienware Detected", payload.alienware_detected ? "Yes" : "No"),
|
||||
stat("Alienware Input", payload.alienware_input_code),
|
||||
stat("Resolved Target", payload.resolved_target),
|
||||
stat("Attempted This Samsung Session", payload.samsung_session_attempted ? "Yes" : "No"),
|
||||
stat("Successful This Samsung Session", payload.samsung_session_successful ? "Yes" : "No"),
|
||||
stat("Attempts This Samsung Session", payload.samsung_session_attempt_count),
|
||||
stat("Waiting For Samsung Disconnect", payload.waiting_for_samsung_disconnect ? "Yes" : "No"),
|
||||
stat("DDM Slot", payload.ddm_slot),
|
||||
stat("DDM Ready", payload.ddm_ready ? "Yes" : "No"),
|
||||
stat("Last Result", payload.last_switch_result),
|
||||
stat("Last Switch At", payload.last_switch_at),
|
||||
].join("");
|
||||
|
||||
const tagHtml = [];
|
||||
tagHtml.push(`<span class="tag${payload.ddm_ready ? "" : " warn"}">DDM ${payload.ddm_ready ? "Ready" : "Not Ready"}</span>`);
|
||||
tagHtml.push(`<span class="tag${payload.alienware_detected ? "" : " warn"}">Alienware ${payload.alienware_detected ? "Detected" : "Missing"}</span>`);
|
||||
tagHtml.push(`<span class="tag${payload.samsung_present ? "" : " warn"}">Samsung ${payload.samsung_present ? "Present" : "Missing"}</span>`);
|
||||
tagHtml.push(`<span class="tag${payload.samsung_session_successful ? "" : " warn"}">Session ${payload.samsung_session_successful ? "Successful" : "Pending"}</span>`);
|
||||
els.tags.innerHTML = tagHtml.join("");
|
||||
|
||||
const errors = Array.isArray(payload.errors) ? payload.errors : [];
|
||||
els.errors.innerHTML = errors.map((err) => `<li>${err}</li>`).join("");
|
||||
}
|
||||
|
||||
async function loadStatus(showErrorInForm = false) {
|
||||
try {
|
||||
const response = await fetch("/api/status", { cache: "no-store" });
|
||||
if (!response.ok) {
|
||||
throw new Error("Unable to load live status.");
|
||||
}
|
||||
renderStatus(await response.json());
|
||||
} catch (error) {
|
||||
if (showErrorInForm) {
|
||||
els.msg.className = "message error";
|
||||
els.msg.textContent = error.message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function saveSettings(event) {
|
||||
event.preventDefault();
|
||||
|
||||
const role = els.role.value;
|
||||
const port = els.port.value;
|
||||
|
||||
if (!role || !port) {
|
||||
els.msg.className = "message error";
|
||||
els.msg.textContent = "Both device role and device port must be selected.";
|
||||
return;
|
||||
}
|
||||
|
||||
els.saveBtn.disabled = true;
|
||||
els.msg.className = "message";
|
||||
els.msg.textContent = "Saving settings...";
|
||||
|
||||
try {
|
||||
const response = await fetch("/api/settings", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
device_role: role,
|
||||
device_port: port,
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
let detail = "Settings save failed.";
|
||||
try {
|
||||
const payload = await response.json();
|
||||
if (Array.isArray(payload.detail)) {
|
||||
detail = payload.detail
|
||||
.map((item) => item.msg || JSON.stringify(item))
|
||||
.join(" ");
|
||||
} else {
|
||||
detail = payload.detail || detail;
|
||||
}
|
||||
} catch (_) {
|
||||
detail = "Settings save failed.";
|
||||
}
|
||||
throw new Error(detail);
|
||||
}
|
||||
|
||||
const payload = await response.json();
|
||||
formDirty = false;
|
||||
renderStatus(payload);
|
||||
els.msg.className = "message ok";
|
||||
els.msg.textContent = "Settings saved. Poller now uses this device port.";
|
||||
} catch (error) {
|
||||
els.msg.className = "message error";
|
||||
els.msg.textContent = error.message;
|
||||
} finally {
|
||||
els.saveBtn.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
els.port.addEventListener("change", () => {
|
||||
formDirty = true;
|
||||
});
|
||||
els.role.addEventListener("change", () => {
|
||||
formDirty = true;
|
||||
});
|
||||
els.form.addEventListener("submit", saveSettings);
|
||||
loadStatus(true);
|
||||
setInterval(() => loadStatus(false), 1500);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user