Port presets on their own tab of the Ports page
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9be92a5606
commit
7eee807d9e
4 files changed
+237
-222
No files matched your search
@@ -1022,7 +1022,7 @@ host (`ss`), which catches services listening on localhost only — a scan from
|
|||||||
elsewhere can't see those, so they'd otherwise look free. Re-run the agent
|
elsewhere can't see those, so they'd otherwise look free. Re-run the agent
|
||||||
install one-liner on a host to pick that up.
|
install one-liner on a host to pick that up.
|
||||||
|
|
||||||
**Port presets** (Network → Ports). A preset is a named list of ports written once — *Remote access* (SSH, RDP, VNC, WinRM), *Databases* (MySQL, PostgreSQL, Redis, MongoDB …), *Web*, *File sharing*, *Homelab tools* come ready-made, and are ordinary presets you can change or delete. Add your own by typing one port to a line (`3389 RDP`, `53/udp DNS`). A preset does three things: it **names ports** — a port in any preset shows its name (3389 → RDP) on every server's Ports card, in the agent table and in the new-port alert ("a new port is listening — 3389/tcp RDP"), without a label typed for each host, and a name you write yourself always wins; it **checks hosts** — pick any number of servers and see in one table which of the preset's TCP ports are open on each, from a scan from the app (private addresses only, at the server's first known address; what it finds is remembered like any scan); and it **names the open ports on all of them** in one go, keeping names somebody already wrote unless you say to replace them. Note that a port with a name counts as noted, so writing names also quiets the new-port alert for those ports. A scan only looks at TCP; a UDP port in a preset is only given its name. Operators change presets; everyone sees them.
|
**Port presets** (Network → Ports → the *Presets* tab). A preset is a named list of ports written once — *Remote access* (SSH, RDP, VNC, WinRM), *Databases* (MySQL, PostgreSQL, Redis, MongoDB …), *Web*, *File sharing*, *Homelab tools* come ready-made, and are ordinary presets you can change or delete. Add your own by typing one port to a line (`3389 RDP`, `53/udp DNS`). A preset does three things: it **names ports** — a port in any preset shows its name (3389 → RDP) on every server's Ports card, in the agent table and in the new-port alert ("a new port is listening — 3389/tcp RDP"), without a label typed for each host, and a name you write yourself always wins; it **checks hosts** — pick any number of servers and see in one table which of the preset's TCP ports are open on each, from a scan from the app (private addresses only, at the server's first known address; what it finds is remembered like any scan); and it **names the open ports on all of them** in one go, keeping names somebody already wrote unless you say to replace them. Note that a port with a name counts as noted, so writing names also quiets the new-port alert for those ports. A scan only looks at TCP; a UDP port in a preset is only given its name. Operators change presets; everyone sees them.
|
||||||
|
|
||||||
**Network → Ports** is the cross-server counterpart: one page listing every
|
**Network → Ports** is the cross-server counterpart: one page listing every
|
||||||
port every agent currently reports as listening, across all servers at once
|
port every agent currently reports as listening, across all servers at once
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ even further, to admin only:
|
|||||||
admin-only (applying an existing tag to a server needs operator).
|
admin-only (applying an existing tag to a server needs operator).
|
||||||
- **Ports**: everyone can see both the agent-reported and manual tables;
|
- **Ports**: everyone can see both the agent-reported and manual tables;
|
||||||
adding, editing, or deleting a manual port opening needs operator.
|
adding, editing, or deleting a manual port opening needs operator.
|
||||||
- **Port presets** (Network → Ports): everyone can see them and the names they give ports; creating, changing and removing one, scanning hosts for one and writing its names onto many hosts' ports need operator.
|
- **Port presets** (Network → Ports → Presets tab): everyone can see them and the names they give ports; creating, changing and removing one, scanning hosts for one and writing its names onto many hosts' ports need operator.
|
||||||
- **Admin Links**: everyone can see and open every server's admin
|
- **Admin Links**: everyone can see and open every server's admin
|
||||||
bookmarks, from that server's own page or the summary page; adding,
|
bookmarks, from that server's own page or the summary page; adding,
|
||||||
editing, or removing one needs operator, from either place.
|
editing, or removing one needs operator, from either place.
|
||||||
|
|||||||
@@ -491,7 +491,7 @@ export default function ServerPorts({
|
|||||||
<StatusBadges entry={p} />
|
<StatusBadges entry={p} />
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{p.label ?? (p.service ? <span className="text-secondary" title="Named by a port preset (Network → Ports)">{p.service}</span> : <span className="text-secondary">—</span>)}
|
{p.label ?? (p.service ? <span className="text-secondary" title="Named by a port preset (Network → Ports → Presets)">{p.service}</span> : <span className="text-secondary">—</span>)}
|
||||||
{p.agent?.process && <div className="text-secondary small">{p.agent.process}</div>}
|
{p.agent?.process && <div className="text-secondary small">{p.agent.process}</div>}
|
||||||
</td>
|
</td>
|
||||||
<td className="text-secondary">{p.comment ?? "—"}</td>
|
<td className="text-secondary">{p.comment ?? "—"}</td>
|
||||||
|
|||||||
+234
-219
@@ -1,7 +1,7 @@
|
|||||||
import { removeWithUndo } from "../utils/undoable";
|
import { removeWithUndo } from "../utils/undoable";
|
||||||
import { useEffect, useState, type FormEvent } from "react";
|
import { useEffect, useState, type FormEvent } from "react";
|
||||||
import TimeAgo from "../components/TimeAgo";
|
import TimeAgo from "../components/TimeAgo";
|
||||||
import { Link } from "react-router-dom";
|
import { Link, useSearchParams } from "react-router-dom";
|
||||||
import {
|
import {
|
||||||
api,
|
api,
|
||||||
type AgentPortRow,
|
type AgentPortRow,
|
||||||
@@ -18,6 +18,7 @@ import { downloadCsv } from "../utils/csv";
|
|||||||
import { formatAgo } from "../utils/duration";
|
import { formatAgo } from "../utils/duration";
|
||||||
import { ErrorNotice } from "../components/Notice";
|
import { ErrorNotice } from "../components/Notice";
|
||||||
import PortPresets from "../components/PortPresets";
|
import PortPresets from "../components/PortPresets";
|
||||||
|
import ViewTabs from "../components/ViewTabs";
|
||||||
import { EmptyRow, LoadingRow } from "../components/EmptyState";
|
import { EmptyRow, LoadingRow } from "../components/EmptyState";
|
||||||
|
|
||||||
const emptyForm: PortForwardInput = {
|
const emptyForm: PortForwardInput = {
|
||||||
@@ -33,6 +34,8 @@ const emptyForm: PortForwardInput = {
|
|||||||
|
|
||||||
export default function Ports({ user }: { user: CurrentUser }) {
|
export default function Ports({ user }: { user: CurrentUser }) {
|
||||||
const canEdit = user.role === "admin" || user.role === "operator";
|
const canEdit = user.role === "admin" || user.role === "operator";
|
||||||
|
const [params] = useSearchParams();
|
||||||
|
const view = params.get("view") === "presets" ? "presets" : "ports";
|
||||||
|
|
||||||
const [agentPorts, setAgentPorts] = useState<AgentPortRow[] | null>(null);
|
const [agentPorts, setAgentPorts] = useState<AgentPortRow[] | null>(null);
|
||||||
const [reportingServers, setReportingServers] = useState(0);
|
const [reportingServers, setReportingServers] = useState(0);
|
||||||
@@ -186,251 +189,263 @@ export default function Ports({ user }: { user: CurrentUser }) {
|
|||||||
<>
|
<>
|
||||||
<h2 className="page-title mb-3">Ports</h2>
|
<h2 className="page-title mb-3">Ports</h2>
|
||||||
|
|
||||||
<PortPresets canEdit={canEdit} />
|
<ViewTabs
|
||||||
|
label="Ports view"
|
||||||
|
tabs={[
|
||||||
|
{ to: "/ports", label: "Ports", active: view === "ports" },
|
||||||
|
{ to: "/ports?view=presets", label: "Presets", active: view === "presets" },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{view === "presets" && <PortPresets canEdit={canEdit} />}
|
||||||
|
|
||||||
|
{view === "ports" && (
|
||||||
|
<>
|
||||||
|
<div className="row g-3 mb-3">
|
||||||
|
<div className="col-12">
|
||||||
|
<div className="card">
|
||||||
|
<div className="card-header">
|
||||||
|
<h3 className="card-title">Ports reported by agents</h3>
|
||||||
|
<div className="card-actions">
|
||||||
|
<span className="text-secondary me-3">
|
||||||
|
{reportingServers} of {totalServers} server{totalServers !== 1 ? "s" : ""} reporting
|
||||||
|
</span>
|
||||||
|
<button className="btn btn-sm btn-outline-secondary" onClick={exportAgentCsv} disabled={!sortedAgentPorts?.length}>
|
||||||
|
Export CSV
|
||||||
|
</button>
|
||||||
|
<button className="btn btn-sm btn-outline-secondary" onClick={loadAgentPorts}>
|
||||||
|
Refresh
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<ErrorNotice error={agentError} className="m-3" />
|
||||||
|
<div className="table-responsive">
|
||||||
|
<table className="table table-vcenter card-table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<SortableTh<AgentPortRow> label="Server" sortKeyName="serverName" activeKey={agentSortKey} direction={agentSortDir} onSort={requestAgentSort} />
|
||||||
|
<SortableTh<AgentPortRow> label="Protocol" sortKeyName="protocol" activeKey={agentSortKey} direction={agentSortDir} onSort={requestAgentSort} />
|
||||||
|
<SortableTh<AgentPortRow> label="Port" sortKeyName="port" activeKey={agentSortKey} direction={agentSortDir} onSort={requestAgentSort} />
|
||||||
|
<th>Service</th>
|
||||||
|
<th>Address</th>
|
||||||
|
<th>Process</th>
|
||||||
|
<SortableTh<AgentPortRow> label="Last report" sortKeyName="lastSeenAt" activeKey={agentSortKey} direction={agentSortDir} onSort={requestAgentSort} />
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{(agentPageItems ?? []).map((p) => (
|
||||||
|
<tr key={`${p.serverId}-${p.protocol}-${p.port}`}>
|
||||||
|
<td>
|
||||||
|
<Link to={`/servers/${p.serverId}`}>{p.serverName}</Link>
|
||||||
|
{p.serverHostname && <div className="text-secondary small">{p.serverHostname}</div>}
|
||||||
|
</td>
|
||||||
|
<td className="text-uppercase text-secondary">{p.protocol}</td>
|
||||||
|
<td>{p.port}</td>
|
||||||
|
<td className="text-secondary" title={p.service ? "Named by a port preset" : undefined}>{p.service ?? "—"}</td>
|
||||||
|
<td className="text-secondary">
|
||||||
|
{p.addresses.join(", ")}
|
||||||
|
{p.localOnly && <span className="badge bg-secondary-lt text-secondary ms-2">local only</span>}
|
||||||
|
</td>
|
||||||
|
<td className="text-secondary">{p.process ?? "—"}</td>
|
||||||
|
<td className="text-secondary"><TimeAgo value={p.lastSeenAt} /></td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
{agentPorts === null && <LoadingRow colSpan={7} />}
|
||||||
|
{agentPorts !== null && agentPorts.length === 0 && (
|
||||||
|
<EmptyRow colSpan={7} title="No listening ports reported yet" hint="Each server's agent lists what is listening with its next report. Install or update the agent to see ports here." action={{ label: "Go to Servers", to: "/servers" }} />
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<Pagination page={agentPage} pageCount={agentPageCount} totalCount={agentTotalCount} onPageChange={setAgentPage} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{canEdit && showForm && (
|
||||||
|
<div className="card mb-3">
|
||||||
|
<div className="card-header">
|
||||||
|
<h3 className="card-title">{editing ? `Edit "${editing.label}"` : "Add a manual port opening"}</h3>
|
||||||
|
</div>
|
||||||
|
<form onSubmit={submit}>
|
||||||
|
<div className="card-body row g-3">
|
||||||
|
<div className="col-md-3">
|
||||||
|
<label className="form-label">Label</label>
|
||||||
|
<input
|
||||||
|
className="form-control"
|
||||||
|
required
|
||||||
|
placeholder="Plex remote access"
|
||||||
|
value={form.label}
|
||||||
|
onChange={(e) => setForm({ ...form, label: e.target.value })}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="col-md-2">
|
||||||
|
<label className="form-label">External port</label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
className="form-control"
|
||||||
|
required
|
||||||
|
min={1}
|
||||||
|
max={65535}
|
||||||
|
value={form.externalPort || ""}
|
||||||
|
onChange={(e) => setForm({ ...form, externalPort: Number(e.target.value) })}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="col-md-2">
|
||||||
|
<label className="form-label">Protocol</label>
|
||||||
|
<select
|
||||||
|
className="form-select"
|
||||||
|
value={form.protocol}
|
||||||
|
onChange={(e) => setForm({ ...form, protocol: e.target.value as "tcp" | "udp" })}
|
||||||
|
>
|
||||||
|
<option value="tcp">TCP</option>
|
||||||
|
<option value="udp">UDP</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div className="col-md-2">
|
||||||
|
<label className="form-label">Internal port</label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
className="form-control"
|
||||||
|
min={1}
|
||||||
|
max={65535}
|
||||||
|
placeholder="if different"
|
||||||
|
value={form.internalPort ?? ""}
|
||||||
|
onChange={(e) => setForm({ ...form, internalPort: e.target.value ? Number(e.target.value) : null })}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="col-md-3">
|
||||||
|
<label className="form-label">Server (optional)</label>
|
||||||
|
<select
|
||||||
|
className="form-select"
|
||||||
|
value={form.serverId ?? ""}
|
||||||
|
onChange={(e) => setForm({ ...form, serverId: e.target.value ? Number(e.target.value) : null })}
|
||||||
|
>
|
||||||
|
<option value="">— none —</option>
|
||||||
|
{(servers ?? []).map((s) => (
|
||||||
|
<option key={s.id} value={s.id}>
|
||||||
|
{s.name}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div className="col-md-3">
|
||||||
|
<label className="form-label">Destination</label>
|
||||||
|
<input
|
||||||
|
className="form-control"
|
||||||
|
placeholder="IP/host, if not a tracked server"
|
||||||
|
value={form.destination ?? ""}
|
||||||
|
onChange={(e) => setForm({ ...form, destination: e.target.value })}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="col-md-3">
|
||||||
|
<label className="form-label">Source</label>
|
||||||
|
<input
|
||||||
|
className="form-control"
|
||||||
|
placeholder="Home router, OPNsense, Cloudflare Tunnel…"
|
||||||
|
value={form.source ?? ""}
|
||||||
|
onChange={(e) => setForm({ ...form, source: e.target.value })}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="col-md-3">
|
||||||
|
<label className="form-label">Comment</label>
|
||||||
|
<input
|
||||||
|
className="form-control"
|
||||||
|
value={form.comment ?? ""}
|
||||||
|
onChange={(e) => setForm({ ...form, comment: e.target.value })}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="card-footer d-flex gap-2">
|
||||||
|
<button type="submit" className="btn btn-primary" disabled={saving}>
|
||||||
|
{editing ? "Save changes" : "Add port opening"}
|
||||||
|
</button>
|
||||||
|
<button type="button" className="btn" onClick={cancelForm}>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<div className="row g-3 mb-3">
|
|
||||||
<div className="col-12">
|
|
||||||
<div className="card">
|
<div className="card">
|
||||||
<div className="card-header">
|
<div className="card-header">
|
||||||
<h3 className="card-title">Ports reported by agents</h3>
|
<h3 className="card-title">Manual port openings</h3>
|
||||||
|
<p className="text-secondary mb-0 me-auto">
|
||||||
|
Router port forwards, edge firewall rules, cloud security groups — anything opened further out on the
|
||||||
|
network that this app can't see on its own.
|
||||||
|
</p>
|
||||||
<div className="card-actions">
|
<div className="card-actions">
|
||||||
<span className="text-secondary me-3">
|
{canEdit && !showForm && (
|
||||||
{reportingServers} of {totalServers} server{totalServers !== 1 ? "s" : ""} reporting
|
<button className="btn btn-primary btn-sm" onClick={startAdd}>
|
||||||
</span>
|
Add port opening
|
||||||
<button className="btn btn-sm btn-outline-secondary" onClick={exportAgentCsv} disabled={!sortedAgentPorts?.length}>
|
</button>
|
||||||
|
)}
|
||||||
|
<button className="btn btn-sm btn-outline-secondary" onClick={exportForwardsCsv} disabled={!sortedForwards?.length}>
|
||||||
Export CSV
|
Export CSV
|
||||||
</button>
|
</button>
|
||||||
<button className="btn btn-sm btn-outline-secondary" onClick={loadAgentPorts}>
|
|
||||||
Refresh
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<ErrorNotice error={agentError} className="m-3" />
|
<ErrorNotice error={forwardError} className="m-3" />
|
||||||
<div className="table-responsive">
|
<div className="table-responsive">
|
||||||
<table className="table table-vcenter card-table">
|
<table className="table table-vcenter card-table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<SortableTh<AgentPortRow> label="Server" sortKeyName="serverName" activeKey={agentSortKey} direction={agentSortDir} onSort={requestAgentSort} />
|
<SortableTh<PortForward> label="Label" sortKeyName="label" activeKey={forwardSortKey} direction={forwardSortDir} onSort={requestForwardSort} />
|
||||||
<SortableTh<AgentPortRow> label="Protocol" sortKeyName="protocol" activeKey={agentSortKey} direction={agentSortDir} onSort={requestAgentSort} />
|
<SortableTh<PortForward>
|
||||||
<SortableTh<AgentPortRow> label="Port" sortKeyName="port" activeKey={agentSortKey} direction={agentSortDir} onSort={requestAgentSort} />
|
label="External port"
|
||||||
<th>Service</th>
|
sortKeyName="externalPort"
|
||||||
<th>Address</th>
|
activeKey={forwardSortKey}
|
||||||
<th>Process</th>
|
direction={forwardSortDir}
|
||||||
<SortableTh<AgentPortRow> label="Last report" sortKeyName="lastSeenAt" activeKey={agentSortKey} direction={agentSortDir} onSort={requestAgentSort} />
|
onSort={requestForwardSort}
|
||||||
|
/>
|
||||||
|
<th>Destination</th>
|
||||||
|
<SortableTh<PortForward> label="Source" sortKeyName="source" activeKey={forwardSortKey} direction={forwardSortDir} onSort={requestForwardSort} />
|
||||||
|
<th>Comment</th>
|
||||||
|
{canEdit && <th className="w-1">Actions</th>}
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{(agentPageItems ?? []).map((p) => (
|
{(sortedForwards ?? []).map((f) => (
|
||||||
<tr key={`${p.serverId}-${p.protocol}-${p.port}`}>
|
<tr key={f.id}>
|
||||||
|
<td>{f.label}</td>
|
||||||
<td>
|
<td>
|
||||||
<Link to={`/servers/${p.serverId}`}>{p.serverName}</Link>
|
<span className="text-uppercase text-secondary me-1">{f.protocol}</span>
|
||||||
{p.serverHostname && <div className="text-secondary small">{p.serverHostname}</div>}
|
{f.externalPort}
|
||||||
|
{f.internalPort && f.internalPort !== f.externalPort && (
|
||||||
|
<span className="text-secondary"> → {f.internalPort}</span>
|
||||||
|
)}
|
||||||
</td>
|
</td>
|
||||||
<td className="text-uppercase text-secondary">{p.protocol}</td>
|
|
||||||
<td>{p.port}</td>
|
|
||||||
<td className="text-secondary" title={p.service ? "Named by a port preset" : undefined}>{p.service ?? "—"}</td>
|
|
||||||
<td className="text-secondary">
|
<td className="text-secondary">
|
||||||
{p.addresses.join(", ")}
|
{f.serverId ? <Link to={`/servers/${f.serverId}`}>{f.serverName}</Link> : f.destination || "—"}
|
||||||
{p.localOnly && <span className="badge bg-secondary-lt text-secondary ms-2">local only</span>}
|
{f.serverId && f.destination && <div className="small">{f.destination}</div>}
|
||||||
</td>
|
</td>
|
||||||
<td className="text-secondary">{p.process ?? "—"}</td>
|
<td className="text-secondary">{f.source ?? "—"}</td>
|
||||||
<td className="text-secondary"><TimeAgo value={p.lastSeenAt} /></td>
|
<td className="text-secondary">{f.comment ?? "—"}</td>
|
||||||
|
{canEdit && (
|
||||||
|
<td>
|
||||||
|
<div className="btn-list flex-nowrap">
|
||||||
|
<button className="btn btn-sm" onClick={() => startEdit(f)}>
|
||||||
|
Edit
|
||||||
|
</button>
|
||||||
|
<button className="btn btn-sm btn-outline-danger" onClick={() => remove(f)}>
|
||||||
|
Delete
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
)}
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
))}
|
||||||
{agentPorts === null && <LoadingRow colSpan={7} />}
|
{forwards === null && <LoadingRow colSpan={canEdit ? 6 : 5} />}
|
||||||
{agentPorts !== null && agentPorts.length === 0 && (
|
{forwards !== null && forwards.length === 0 && (
|
||||||
<EmptyRow colSpan={7} title="No listening ports reported yet" hint="Each server's agent lists what is listening with its next report. Install or update the agent to see ports here." action={{ label: "Go to Servers", to: "/servers" }} />
|
<EmptyRow colSpan={canEdit ? 6 : 5} title="No port openings recorded" hint="Write down what is forwarded through the router or opened by hand, so it isn't forgotten." action={canEdit ? { label: "Record one", onClick: startAdd } : undefined} />
|
||||||
)}
|
)}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<Pagination page={agentPage} pageCount={agentPageCount} totalCount={agentTotalCount} onPageChange={setAgentPage} />
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</>
|
||||||
</div>
|
|
||||||
|
|
||||||
{canEdit && showForm && (
|
|
||||||
<div className="card mb-3">
|
|
||||||
<div className="card-header">
|
|
||||||
<h3 className="card-title">{editing ? `Edit "${editing.label}"` : "Add a manual port opening"}</h3>
|
|
||||||
</div>
|
|
||||||
<form onSubmit={submit}>
|
|
||||||
<div className="card-body row g-3">
|
|
||||||
<div className="col-md-3">
|
|
||||||
<label className="form-label">Label</label>
|
|
||||||
<input
|
|
||||||
className="form-control"
|
|
||||||
required
|
|
||||||
placeholder="Plex remote access"
|
|
||||||
value={form.label}
|
|
||||||
onChange={(e) => setForm({ ...form, label: e.target.value })}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="col-md-2">
|
|
||||||
<label className="form-label">External port</label>
|
|
||||||
<input
|
|
||||||
type="number"
|
|
||||||
className="form-control"
|
|
||||||
required
|
|
||||||
min={1}
|
|
||||||
max={65535}
|
|
||||||
value={form.externalPort || ""}
|
|
||||||
onChange={(e) => setForm({ ...form, externalPort: Number(e.target.value) })}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="col-md-2">
|
|
||||||
<label className="form-label">Protocol</label>
|
|
||||||
<select
|
|
||||||
className="form-select"
|
|
||||||
value={form.protocol}
|
|
||||||
onChange={(e) => setForm({ ...form, protocol: e.target.value as "tcp" | "udp" })}
|
|
||||||
>
|
|
||||||
<option value="tcp">TCP</option>
|
|
||||||
<option value="udp">UDP</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div className="col-md-2">
|
|
||||||
<label className="form-label">Internal port</label>
|
|
||||||
<input
|
|
||||||
type="number"
|
|
||||||
className="form-control"
|
|
||||||
min={1}
|
|
||||||
max={65535}
|
|
||||||
placeholder="if different"
|
|
||||||
value={form.internalPort ?? ""}
|
|
||||||
onChange={(e) => setForm({ ...form, internalPort: e.target.value ? Number(e.target.value) : null })}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="col-md-3">
|
|
||||||
<label className="form-label">Server (optional)</label>
|
|
||||||
<select
|
|
||||||
className="form-select"
|
|
||||||
value={form.serverId ?? ""}
|
|
||||||
onChange={(e) => setForm({ ...form, serverId: e.target.value ? Number(e.target.value) : null })}
|
|
||||||
>
|
|
||||||
<option value="">— none —</option>
|
|
||||||
{(servers ?? []).map((s) => (
|
|
||||||
<option key={s.id} value={s.id}>
|
|
||||||
{s.name}
|
|
||||||
</option>
|
|
||||||
))}
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div className="col-md-3">
|
|
||||||
<label className="form-label">Destination</label>
|
|
||||||
<input
|
|
||||||
className="form-control"
|
|
||||||
placeholder="IP/host, if not a tracked server"
|
|
||||||
value={form.destination ?? ""}
|
|
||||||
onChange={(e) => setForm({ ...form, destination: e.target.value })}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="col-md-3">
|
|
||||||
<label className="form-label">Source</label>
|
|
||||||
<input
|
|
||||||
className="form-control"
|
|
||||||
placeholder="Home router, OPNsense, Cloudflare Tunnel…"
|
|
||||||
value={form.source ?? ""}
|
|
||||||
onChange={(e) => setForm({ ...form, source: e.target.value })}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="col-md-3">
|
|
||||||
<label className="form-label">Comment</label>
|
|
||||||
<input
|
|
||||||
className="form-control"
|
|
||||||
value={form.comment ?? ""}
|
|
||||||
onChange={(e) => setForm({ ...form, comment: e.target.value })}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="card-footer d-flex gap-2">
|
|
||||||
<button type="submit" className="btn btn-primary" disabled={saving}>
|
|
||||||
{editing ? "Save changes" : "Add port opening"}
|
|
||||||
</button>
|
|
||||||
<button type="button" className="btn" onClick={cancelForm}>
|
|
||||||
Cancel
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="card">
|
|
||||||
<div className="card-header">
|
|
||||||
<h3 className="card-title">Manual port openings</h3>
|
|
||||||
<p className="text-secondary mb-0 me-auto">
|
|
||||||
Router port forwards, edge firewall rules, cloud security groups — anything opened further out on the
|
|
||||||
network that this app can't see on its own.
|
|
||||||
</p>
|
|
||||||
<div className="card-actions">
|
|
||||||
{canEdit && !showForm && (
|
|
||||||
<button className="btn btn-primary btn-sm" onClick={startAdd}>
|
|
||||||
Add port opening
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
<button className="btn btn-sm btn-outline-secondary" onClick={exportForwardsCsv} disabled={!sortedForwards?.length}>
|
|
||||||
Export CSV
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<ErrorNotice error={forwardError} className="m-3" />
|
|
||||||
<div className="table-responsive">
|
|
||||||
<table className="table table-vcenter card-table">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<SortableTh<PortForward> label="Label" sortKeyName="label" activeKey={forwardSortKey} direction={forwardSortDir} onSort={requestForwardSort} />
|
|
||||||
<SortableTh<PortForward>
|
|
||||||
label="External port"
|
|
||||||
sortKeyName="externalPort"
|
|
||||||
activeKey={forwardSortKey}
|
|
||||||
direction={forwardSortDir}
|
|
||||||
onSort={requestForwardSort}
|
|
||||||
/>
|
|
||||||
<th>Destination</th>
|
|
||||||
<SortableTh<PortForward> label="Source" sortKeyName="source" activeKey={forwardSortKey} direction={forwardSortDir} onSort={requestForwardSort} />
|
|
||||||
<th>Comment</th>
|
|
||||||
{canEdit && <th className="w-1">Actions</th>}
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{(sortedForwards ?? []).map((f) => (
|
|
||||||
<tr key={f.id}>
|
|
||||||
<td>{f.label}</td>
|
|
||||||
<td>
|
|
||||||
<span className="text-uppercase text-secondary me-1">{f.protocol}</span>
|
|
||||||
{f.externalPort}
|
|
||||||
{f.internalPort && f.internalPort !== f.externalPort && (
|
|
||||||
<span className="text-secondary"> → {f.internalPort}</span>
|
|
||||||
)}
|
|
||||||
</td>
|
|
||||||
<td className="text-secondary">
|
|
||||||
{f.serverId ? <Link to={`/servers/${f.serverId}`}>{f.serverName}</Link> : f.destination || "—"}
|
|
||||||
{f.serverId && f.destination && <div className="small">{f.destination}</div>}
|
|
||||||
</td>
|
|
||||||
<td className="text-secondary">{f.source ?? "—"}</td>
|
|
||||||
<td className="text-secondary">{f.comment ?? "—"}</td>
|
|
||||||
{canEdit && (
|
|
||||||
<td>
|
|
||||||
<div className="btn-list flex-nowrap">
|
|
||||||
<button className="btn btn-sm" onClick={() => startEdit(f)}>
|
|
||||||
Edit
|
|
||||||
</button>
|
|
||||||
<button className="btn btn-sm btn-outline-danger" onClick={() => remove(f)}>
|
|
||||||
Delete
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
)}
|
|
||||||
</tr>
|
|
||||||
))}
|
|
||||||
{forwards === null && <LoadingRow colSpan={canEdit ? 6 : 5} />}
|
|
||||||
{forwards !== null && forwards.length === 0 && (
|
|
||||||
<EmptyRow colSpan={canEdit ? 6 : 5} title="No port openings recorded" hint="Write down what is forwarded through the router or opened by hand, so it isn't forgotten." action={canEdit ? { label: "Record one", onClick: startAdd } : undefined} />
|
|
||||||
)}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user