472 lines
14 KiB
HTML
472 lines
14 KiB
HTML
<!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. This device switches Alienware AW3423DWF when Samsung input matches the configured local port code: DP1 = 15, DP2 = 19, HDMI = 17.
|
|
</p>
|
|
</section>
|
|
|
|
<section class="layout">
|
|
<article class="card">
|
|
<h2>Settings</h2>
|
|
<form id="settings-form">
|
|
<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>
|
|
<label class="field" for="aux-monitor">
|
|
<span>Auxiliary Trigger Monitor</span>
|
|
<select id="aux-monitor">
|
|
<option value="">Auto-detect</option>
|
|
</select>
|
|
</label>
|
|
<p class="hint">Port and auxiliary monitor 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"),
|
|
port: document.getElementById("device-port"),
|
|
auxMonitor: document.getElementById("aux-monitor"),
|
|
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 escapeHtml(text) {
|
|
return String(text)
|
|
.replaceAll("&", "&")
|
|
.replaceAll("<", "<")
|
|
.replaceAll(">", ">")
|
|
.replaceAll("\"", """)
|
|
.replaceAll("'", "'");
|
|
}
|
|
|
|
function renderAuxiliaryMonitorOptions(payloadCandidates, configuredAuxId) {
|
|
const candidates = Array.isArray(payloadCandidates) ? payloadCandidates : [];
|
|
const currentValue = els.auxMonitor.value || "";
|
|
const desiredValue = formDirty ? currentValue : (configuredAuxId || "");
|
|
|
|
const options = ['<option value="">Auto-detect</option>'];
|
|
for (const candidate of candidates) {
|
|
if (!candidate || !candidate.id) {
|
|
continue;
|
|
}
|
|
const label = candidate.label || candidate.id;
|
|
const inputCode = candidate.input_code === null || candidate.input_code === undefined
|
|
? "n/a"
|
|
: String(candidate.input_code);
|
|
options.push(
|
|
`<option value="${escapeHtml(candidate.id)}">${escapeHtml(label)} (input: ${escapeHtml(inputCode)})</option>`
|
|
);
|
|
}
|
|
els.auxMonitor.innerHTML = options.join("");
|
|
|
|
const desiredExists = [...els.auxMonitor.options].some((opt) => opt.value === desiredValue);
|
|
els.auxMonitor.value = desiredExists ? desiredValue : "";
|
|
}
|
|
|
|
function renderStatus(payload) {
|
|
const config = payload.config || {};
|
|
const portVal = config.device_port;
|
|
const auxMonitorVal = config.auxiliary_monitor_id;
|
|
|
|
if (!formDirty && document.activeElement !== els.port) {
|
|
els.port.value = portVal ?? "DP1";
|
|
}
|
|
if (document.activeElement !== els.auxMonitor || !formDirty) {
|
|
renderAuxiliaryMonitorOptions(payload.trigger_monitor_candidates, auxMonitorVal);
|
|
}
|
|
|
|
els.stats.innerHTML = [
|
|
stat("This Device Port", config.device_port),
|
|
stat("Configured Aux Monitor", config.auxiliary_monitor_id),
|
|
stat("Active Trigger Monitor", payload.active_trigger_monitor_id),
|
|
stat("Samsung Present", payload.samsung_present ? "Yes" : "No"),
|
|
stat("Trigger Input", payload.trigger_input_code),
|
|
stat("Trigger Target Port", payload.trigger_target_port),
|
|
stat("Trigger Matches This Device Port", payload.trigger_matches_device_port ? "Yes" : "No"),
|
|
stat("Alienware Detected", payload.alienware_detected ? "Yes" : "No"),
|
|
stat("Alienware Input", payload.alienware_input_code),
|
|
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("Target Slot", payload.ddm_slot),
|
|
stat("Switch 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"}">Switch ${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 port = els.port.value;
|
|
const auxiliaryMonitorId = els.auxMonitor.value || null;
|
|
|
|
if (!port) {
|
|
els.msg.className = "message error";
|
|
els.msg.textContent = "A 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_port: port,
|
|
auxiliary_monitor_id: auxiliaryMonitorId,
|
|
}),
|
|
});
|
|
|
|
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 port and auxiliary monitor selection.";
|
|
} catch (error) {
|
|
els.msg.className = "message error";
|
|
els.msg.textContent = error.message;
|
|
} finally {
|
|
els.saveBtn.disabled = false;
|
|
}
|
|
}
|
|
|
|
els.port.addEventListener("change", () => {
|
|
formDirty = true;
|
|
});
|
|
els.auxMonitor.addEventListener("change", () => {
|
|
formDirty = true;
|
|
});
|
|
els.form.addEventListener("submit", saveSettings);
|
|
loadStatus(true);
|
|
setInterval(() => loadStatus(false), 1500);
|
|
</script>
|
|
</body>
|
|
</html>
|