streamd: serve start/stop/update, streamd.yaml, egress, module panel fixes
- Add streamd serve start|stop|restart|status|update with auto-written streamd.yaml - Panel modules: STREAMD_MODULES_DIR for describe, YAML channel fallback, textarea value fix - Per-stream WireGuard/SOCKS egress profiles + Settings UI - Drop drm-* from release builds; track streamd-bg.sh / streamd-update.sh wrappers - Docs: streamd-server-setup lifecycle and update flow
This commit is contained in:
parent
da8e1123ec
commit
8fc7e4c0b8
57 changed files with 4031 additions and 257 deletions
|
|
@ -192,12 +192,186 @@ export function settingsView(root) {
|
|||
),
|
||||
),
|
||||
);
|
||||
wrap.append(await egressCard());
|
||||
}
|
||||
|
||||
load();
|
||||
return () => {};
|
||||
}
|
||||
|
||||
async function egressCard() {
|
||||
const box = el("div.card",
|
||||
el("div.card-head",
|
||||
el("h2", { text: "Egress tunnels" }),
|
||||
el("span.spacer"),
|
||||
el("button.sm", { type: "button", text: "+ Add profile", onclick: () => openEgressDialog(reload) }),
|
||||
),
|
||||
el("p.hint", {
|
||||
text: "Named WireGuard (Linux netns + local SOCKS) or SOCKS URL profiles. " +
|
||||
"Assign a profile per stream so only that stream’s origin fetch exits via the tunnel. " +
|
||||
"Full-tunnel WG stays inside a network namespace — SSH and the dashboard keep the host route.",
|
||||
}),
|
||||
);
|
||||
const list = el("div");
|
||||
box.append(list);
|
||||
|
||||
async function reload() {
|
||||
clear(list);
|
||||
let data;
|
||||
try {
|
||||
data = await api.egress();
|
||||
} catch (err) {
|
||||
list.append(el("p.msg.err", { text: err.message }));
|
||||
return;
|
||||
}
|
||||
const profiles = data.profiles || [];
|
||||
if (!profiles.length) {
|
||||
list.append(el("p.hint", { text: "No profiles yet. Add london (or dublin, …) from a WireGuard client .conf." }));
|
||||
return;
|
||||
}
|
||||
for (const p of profiles) {
|
||||
const status = p.status || "stopped";
|
||||
const meta = [
|
||||
p.kind,
|
||||
status,
|
||||
p.listen_port ? `:${p.listen_port}` : null,
|
||||
p.egress_ip || null,
|
||||
p.has_conf ? "conf" : null,
|
||||
p.enabled ? "autostart" : null,
|
||||
].filter(Boolean).join(" · ");
|
||||
const row = el("div.row", {
|
||||
style: { alignItems: "center", gap: "8px", flexWrap: "wrap", padding: "8px 0", borderBottom: "1px solid var(--border)" },
|
||||
},
|
||||
el("div", { style: { flex: "1 1 160px" } },
|
||||
el("div.mono", { text: p.name }),
|
||||
el("small.muted", { text: meta }),
|
||||
p.last_error ? el("div.msg.err", { text: p.last_error, style: { marginTop: "4px" } }) : null,
|
||||
),
|
||||
el("button.ghost.sm", {
|
||||
type: "button", text: "Up",
|
||||
onclick: async () => {
|
||||
try { await api.egressUp(p.name); toast(`${p.name} up`); reload(); }
|
||||
catch (err) { toast(err.message, true); }
|
||||
},
|
||||
}),
|
||||
el("button.ghost.sm", {
|
||||
type: "button", text: "Down",
|
||||
onclick: async () => {
|
||||
try { await api.egressDown(p.name); toast(`${p.name} down`); reload(); }
|
||||
catch (err) { toast(err.message, true); }
|
||||
},
|
||||
}),
|
||||
el("button.ghost.sm", {
|
||||
type: "button", text: "Test IP",
|
||||
onclick: async () => {
|
||||
try {
|
||||
const r = await api.egressTest(p.name);
|
||||
toast(`${p.name} egress IP: ${r.egress_ip || r.ip || JSON.stringify(r)}`);
|
||||
reload();
|
||||
} catch (err) { toast(err.message, true); }
|
||||
},
|
||||
}),
|
||||
el("button.ghost.sm", {
|
||||
type: "button", text: "Edit",
|
||||
onclick: () => openEgressDialog(reload, p),
|
||||
}),
|
||||
el("button.ghost.sm.danger", {
|
||||
type: "button", text: "Delete",
|
||||
onclick: async () => {
|
||||
if (!confirm(`Delete egress profile ${p.name}?`)) return;
|
||||
try { await api.deleteEgress(p.name); toast("Deleted"); reload(); }
|
||||
catch (err) { toast(err.message, true); }
|
||||
},
|
||||
}),
|
||||
);
|
||||
list.append(row);
|
||||
}
|
||||
}
|
||||
|
||||
await reload();
|
||||
return box;
|
||||
}
|
||||
|
||||
function openEgressDialog(onDone, existing) {
|
||||
const isEdit = !!existing;
|
||||
const name = el("input", {
|
||||
required: true, placeholder: "london",
|
||||
value: existing?.name || "",
|
||||
disabled: isEdit,
|
||||
});
|
||||
const kind = el("select",
|
||||
el("option", { value: "wireguard", text: "WireGuard (Linux netns)", selected: !existing || existing.kind === "wireguard" }),
|
||||
el("option", { value: "socks", text: "SOCKS/HTTP URL only", selected: existing?.kind === "socks" }),
|
||||
);
|
||||
const enabled = el("input", { type: "checkbox", checked: existing ? !!existing.enabled : true });
|
||||
const socksURL = el("input", {
|
||||
placeholder: "socks5://127.0.0.1:1081",
|
||||
value: existing?.socks_url || "",
|
||||
});
|
||||
const conf = el("textarea", {
|
||||
rows: "12",
|
||||
placeholder: "[Interface]\nPrivateKey = …\nAddress = …\n\n[Peer]\nPublicKey = …\nEndpoint = …\nAllowedIPs = 0.0.0.0/0, ::/0\n",
|
||||
spellcheck: "false",
|
||||
});
|
||||
const msg = el("p.msg");
|
||||
|
||||
function syncKind() {
|
||||
socksURL.closest("label").hidden = kind.value !== "socks";
|
||||
conf.closest("label").hidden = kind.value !== "wireguard";
|
||||
}
|
||||
kind.addEventListener("change", syncKind);
|
||||
|
||||
const form = el("form",
|
||||
el("div.grid",
|
||||
el("label", el("span.lbl", { text: "Name (slug)" }), name),
|
||||
el("label", el("span.lbl", { text: "Kind" }), kind),
|
||||
el("label.inline-check", enabled, el("span", { text: "Auto-start with streamd serve" })),
|
||||
el("label.span2", el("span.lbl", { text: "SOCKS/HTTP URL" }), socksURL),
|
||||
el("label.span2", el("span.lbl", { text: "WireGuard client config" }), conf,
|
||||
el("small.hint", { text: isEdit ? "Leave blank to keep the stored conf. Pasting replaces it." : "Paste a client .conf (e.g. vps-london.conf). Private keys stay on the server." })),
|
||||
),
|
||||
msg,
|
||||
el("div.row.end", { style: { marginTop: "12px" } },
|
||||
el("button.ghost", { type: "button", text: "Cancel", onclick: () => close() }),
|
||||
el("button", { type: "submit", text: isEdit ? "Save" : "Create" }),
|
||||
),
|
||||
);
|
||||
syncKind();
|
||||
|
||||
form.addEventListener("submit", async (ev) => {
|
||||
ev.preventDefault();
|
||||
msg.textContent = "";
|
||||
msg.classList.remove("err");
|
||||
const slug = name.value.trim();
|
||||
try {
|
||||
if (isEdit) {
|
||||
const body = { kind: kind.value, enabled: enabled.checked };
|
||||
if (kind.value === "socks") body.socks_url = socksURL.value.trim();
|
||||
if (kind.value === "wireguard" && conf.value.trim()) body.conf = conf.value;
|
||||
await api.saveEgress(existing.name, body);
|
||||
} else {
|
||||
const body = { name: slug, kind: kind.value, enabled: enabled.checked };
|
||||
if (kind.value === "socks") body.socks_url = socksURL.value.trim();
|
||||
await api.createEgress(body);
|
||||
if (kind.value === "wireguard" && conf.value.trim()) {
|
||||
await api.saveEgress(slug, { conf: conf.value });
|
||||
}
|
||||
}
|
||||
toast(isEdit ? "Saved" : "Created");
|
||||
close();
|
||||
onDone();
|
||||
} catch (err) {
|
||||
msg.textContent = err.message;
|
||||
msg.classList.add("err");
|
||||
}
|
||||
});
|
||||
|
||||
const close = openModal(
|
||||
el("h2", { text: isEdit ? `Edit egress · ${existing.name}` : "Add egress profile" }),
|
||||
form,
|
||||
);
|
||||
}
|
||||
|
||||
// ---------- people and API keys ----------
|
||||
|
||||
export function peopleView(root) {
|
||||
|
|
|
|||
|
|
@ -215,8 +215,12 @@ async function uploadFile(file, reload) {
|
|||
}
|
||||
toast(`Uploading ${file.name}…`);
|
||||
try {
|
||||
const res = await api.uploadModuleZip(file);
|
||||
const name = (res.module && res.module.name) || file.name;
|
||||
// Pass stem of rte.zip → "rte" so flat release zips never become "darwin-arm64".
|
||||
let hint = "";
|
||||
const base = (file.name || "").replace(/\.zip$/i, "").trim();
|
||||
if (/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/.test(base)) hint = base;
|
||||
const res = await api.uploadModuleZip(file, hint || undefined);
|
||||
const name = (res.module && res.module.name) || hint || file.name;
|
||||
toast(`Uploaded ${name}`);
|
||||
reload();
|
||||
} catch (err) {
|
||||
|
|
|
|||
|
|
@ -33,7 +33,8 @@ export function streamCreate(root) {
|
|||
|
||||
const mpd = el("input", { placeholder: "https://…/manifest.mpd" });
|
||||
const key = el("textarea", { rows: "3", placeholder: "KID:KEY per line — leave empty for clear streams", spellcheck: "false" });
|
||||
const proxy = el("input", { placeholder: "socks5://127.0.0.1:1080 (optional)" });
|
||||
const egress = el("select", el("option", { value: "", text: "Direct (no tunnel)" }));
|
||||
const proxy = el("input", { placeholder: "socks5://… overrides egress if set" });
|
||||
const headers = el("input", { value: "{}" });
|
||||
const idle = el("input", { type: "number", value: "300", min: "30", max: "86400" });
|
||||
const drm = el("select",
|
||||
|
|
@ -98,6 +99,7 @@ export function streamCreate(root) {
|
|||
channel: chanSel.value,
|
||||
mpd: mpd.value.trim(),
|
||||
key: key.value.trim(),
|
||||
egress: egress.value.trim(),
|
||||
proxy: proxy.value.trim(),
|
||||
headers_json: headers.value.trim() || "{}",
|
||||
tags: tags.value,
|
||||
|
|
@ -171,7 +173,10 @@ export function streamCreate(root) {
|
|||
panel.append(el("div.grid",
|
||||
el("label.span2", el("span.lbl", { text: "Manifest URL" }), mpd),
|
||||
el("label.span2", el("span.lbl", { text: "Keys" }), key),
|
||||
el("label", el("span.lbl", { text: "Origin proxy" }), proxy),
|
||||
el("label", el("span.lbl", { text: "Egress tunnel" }), egress,
|
||||
el("small.hint", { text: "Named WireGuard / SOCKS profile (Settings → Egress). Direct = normal server route." })),
|
||||
el("label", el("span.lbl", { text: "Origin proxy URL" }), proxy,
|
||||
el("small.hint", { text: "Optional raw socks5:// or http://. If set, it overrides the egress dropdown." })),
|
||||
el("label", el("span.lbl", { text: "Headers JSON" }), headers),
|
||||
el("label", el("span.lbl", { text: "Encryption" }), drm),
|
||||
el("label", el("span.lbl", { text: "Rewriter" }), rewriter),
|
||||
|
|
@ -190,6 +195,8 @@ export function streamCreate(root) {
|
|||
row("Title", b.title || "—"),
|
||||
row("Module", b.app ? `${b.app} / ${b.channel || "—"}` : "—"),
|
||||
row("Manifest", b.mpd || "(from module / capture)"),
|
||||
row("Egress", b.egress || "Direct"),
|
||||
row("Origin proxy", b.proxy || "—"),
|
||||
row("Encryption", b.drm_mode),
|
||||
row("On-demand", b.on_demand ? "yes" : "no"),
|
||||
row("Public", b.public ? "yes" : "no"),
|
||||
|
|
@ -256,6 +263,19 @@ export function streamCreate(root) {
|
|||
} catch {
|
||||
// Module list is optional.
|
||||
}
|
||||
try {
|
||||
const eg = await api.egress();
|
||||
clear(egress);
|
||||
egress.append(el("option", { value: "", text: "Direct (no tunnel)" }));
|
||||
for (const p of eg.profiles || []) {
|
||||
const label = p.status && p.status !== "stopped"
|
||||
? `${p.name} (${p.kind}, ${p.status})`
|
||||
: `${p.name} (${p.kind})`;
|
||||
egress.append(el("option", { value: p.name, text: label }));
|
||||
}
|
||||
} catch {
|
||||
// Egress API optional on older servers.
|
||||
}
|
||||
paint();
|
||||
})();
|
||||
|
||||
|
|
|
|||
|
|
@ -402,6 +402,7 @@ export function streamView(root, id, tab = "live") {
|
|||
const tags = el("input", { value: s.tags || "" });
|
||||
const mpd = el("input", { value: s.mpd || "" });
|
||||
const key = el("textarea", { rows: "3", placeholder: s.has_key ? "unchanged — type to replace" : "none", spellcheck: "false" });
|
||||
const egress = el("select", el("option", { value: "", text: "Direct (no tunnel)", selected: !s.egress }));
|
||||
const proxy = el("input", { placeholder: s.has_proxy ? "unchanged — type to replace" : "none" });
|
||||
const headers = el("input", { placeholder: s.has_headers ? "unchanged — type to replace" : "{}" });
|
||||
const drm = el("select",
|
||||
|
|
@ -482,6 +483,23 @@ export function streamView(root, id, tab = "live") {
|
|||
if (s.rewriter && !rewriters.includes(s.rewriter)) {
|
||||
rewriter.append(el("option", { value: s.rewriter, text: `${s.rewriter} (stored)`, selected: true }));
|
||||
}
|
||||
try {
|
||||
const eg = await api.egress();
|
||||
clear(egress);
|
||||
egress.append(el("option", { value: "", text: "Direct (no tunnel)", selected: !s.egress }));
|
||||
for (const p of eg.profiles || []) {
|
||||
egress.append(el("option", {
|
||||
value: p.name,
|
||||
text: `${p.name} (${p.kind}${p.status ? ", " + p.status : ""})`,
|
||||
selected: s.egress === p.name,
|
||||
}));
|
||||
}
|
||||
if (s.egress && !(eg.profiles || []).some((p) => p.name === s.egress)) {
|
||||
egress.append(el("option", { value: s.egress, text: `${s.egress} (stored)`, selected: true }));
|
||||
}
|
||||
} catch {
|
||||
// Older servers without /api/egress.
|
||||
}
|
||||
})();
|
||||
|
||||
const revealBtn = el("button.ghost.sm", {
|
||||
|
|
@ -514,7 +532,8 @@ export function streamView(root, id, tab = "live") {
|
|||
el("label", el("span.lbl", { text: "Audio select" }), audioSel),
|
||||
el("label.span2", el("span.lbl", { text: "Manifest URL" }), mpd),
|
||||
el("label.span2", el("span.lbl", { text: "Keys" }), key),
|
||||
el("label", el("span.lbl", { text: "Origin proxy" }), proxy),
|
||||
el("label", el("span.lbl", { text: "Egress tunnel" }), egress),
|
||||
el("label", el("span.lbl", { text: "Origin proxy URL" }), proxy),
|
||||
el("label", el("span.lbl", { text: "Headers JSON" }), headers),
|
||||
el("label", el("span.lbl", { text: "Idle timeout (s)" }), idle),
|
||||
el("label", el("span.lbl", { text: "Segment seconds" }), hlsTime),
|
||||
|
|
@ -560,6 +579,7 @@ export function streamView(root, id, tab = "live") {
|
|||
};
|
||||
// Only send a credential when it was actually typed, so saving the form
|
||||
// does not wipe a key the browser was never given.
|
||||
body.egress = egress.value.trim();
|
||||
if (key.value.trim()) body.key = key.value.trim();
|
||||
if (proxy.value.trim()) body.proxy = proxy.value.trim();
|
||||
if (headers.value.trim()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue