feat: status dots show whether a link's address answers

With STATUS_CHECKS=true the server requests the address of every link of
the open dashboard once a minute and the tile shows a green dot or a red
ring. Off by default: users choose the addresses, so a user could find
out which hosts and ports the server reaches.
This commit is contained in:
Niklas Haiden
2026-11-21 19:19:44 +01:00
parent cba6eddc56
commit b6e5d81dc0
7 changed files with 192 additions and 10 deletions
+5
View File
@@ -19,5 +19,10 @@ OIDC_CLIENT_ID=
OIDC_CLIENT_SECRET= OIDC_CLIENT_SECRET=
OIDC_PROVIDER_NAME=SSO OIDC_PROVIDER_NAME=SSO
# Set to "true" to show on every link whether its address answers. The server then
# calls the addresses that users save as links, once a minute. Leave it off when
# people you do not trust can sign up: they could probe your network with it.
STATUS_CHECKS=false
# SearXNG instance (must be reachable from the browser and from this server) # SearXNG instance (must be reachable from the browser and from this server)
SEARXNG_URL= SEARXNG_URL=
+8
View File
@@ -49,6 +49,7 @@ Build it yourself: `docker build -t dahoam .`
| `DISABLE_SIGNUP` | `true` closes email/password registration. Set it after you made your account. | | `DISABLE_SIGNUP` | `true` closes email/password registration. Set it after you made your account. |
| `OIDC_DISCOVERY_URL`, `OIDC_CLIENT_ID`, `OIDC_CLIENT_SECRET` | Turns on the SSO button. Redirect URI: `<BETTER_AUTH_URL>/api/auth/callback/sso` | | `OIDC_DISCOVERY_URL`, `OIDC_CLIENT_ID`, `OIDC_CLIENT_SECRET` | Turns on the SSO button. Redirect URI: `<BETTER_AUTH_URL>/api/auth/callback/sso` |
| `OIDC_PROVIDER_NAME` | Text on the SSO button ("Continue with …") | | `OIDC_PROVIDER_NAME` | Text on the SSO button ("Continue with …") |
| `STATUS_CHECKS` | `true` shows on every link whether its address answers. Off by default, see Notes. |
| `SEARXNG_URL` | Your SearXNG instance. Makes SearXNG selectable in Settings. | | `SEARXNG_URL` | Your SearXNG instance. Makes SearXNG selectable in Settings. |
## Use ## Use
@@ -71,6 +72,8 @@ Build it yourself: `docker build -t dahoam .`
site's `/favicon.ico`. When the library has a light version of the icon (`github-light`), site's `/favicon.ico`. When the library has a light version of the icon (`github-light`),
that one is used, because the cards are dark. Or type in the field to search that library and click an icon, that one is used, because the cards are dark. Or type in the field to search that library and click an icon,
paste an image URL, or upload your own image (PNG, JPEG, WebP, AVIF or SVG, up to 1 MB). paste an image URL, or upload your own image (PNG, JPEG, WebP, AVIF or SVG, up to 1 MB).
- **Status** (with `STATUS_CHECKS=true`): a green dot on a link means that its address
answers, a red ring that it does not. Checked once a minute.
- **Search**: `/` focuses the bar. `!w cats` uses DuckDuckGo bangs. `/settings`, `/add link`, - **Search**: `/` focuses the bar. `!w cats` uses DuckDuckGo bangs. `/settings`, `/add link`,
`/add card`, `/add dashboard` and `/sign out` run commands. `/add card`, `/add dashboard` and `/sign out` run commands.
- **Open a link from the search bar**: type the start of its name (`jel` for Jellyfin). The - **Open a link from the search bar**: type the start of its name (`jel` for Jellyfin). The
@@ -87,6 +90,11 @@ Build it yourself: `docker build -t dahoam .`
- Suggestions come from DuckDuckGo, or from SearXNG (`/autocompleter`) when it is the - Suggestions come from DuckDuckGo, or from SearXNG (`/autocompleter`) when it is the
selected engine. The server fetches them, the browser never calls those hosts directly. selected engine. The server fetches them, the browser never calls those hosts directly.
- Status checks: the server requests each link's address (a GET, redirects are not
followed, the answer is thrown away) and tells the browser only up or down. Up is any
answer below 500, and also a certificate that the server does not trust. Because users
choose the addresses, a user can find out which hosts and ports the server can reach.
Turn it on for people you trust, together with `DISABLE_SIGNUP=true`.
- SSO does not take over an existing password account with the same email - SSO does not take over an existing password account with the same email
(Better Auth blocks it, because password emails are not verified). Use one or the other per email. (Better Auth blocks it, because password emails are not verified). Use one or the other per email.
- Icon lookups send the link name to the jsDelivr CDN. The link dialog also loads the - Icon lookups send the link name to the jsDelivr CDN. The link dialog also loads the
+18 -1
View File
@@ -1,4 +1,4 @@
import { useEffect, useRef, useState } from "react" import { createContext, useContext, useEffect, useRef, useState } from "react"
import { useDndContext } from "@dnd-kit/core" import { useDndContext } from "@dnd-kit/core"
import { useSortable } from "@dnd-kit/sortable" import { useSortable } from "@dnd-kit/sortable"
import { CSS } from "@dnd-kit/utilities" import { CSS } from "@dnd-kit/utilities"
@@ -16,6 +16,9 @@ export type HomeLink = {
lightIcon: string | null lightIcon: string | null
} }
/** Per link id: does its address answer? No entry: not checked (yet). */
export const StatusContext = createContext<Partial<Record<string, boolean>>>({})
type IconProps = { link: HomeLink; className?: string } type IconProps = { link: HomeLink; className?: string }
/** Starts the fallback chain again when the link changes. */ /** Starts the fallback chain again when the link changes. */
@@ -98,6 +101,7 @@ export function LinkTile({
transition, transition,
isDragging, isDragging,
} = useSortable({ id: link.id, disabled: { droppable: cardDragged } }) } = useSortable({ id: link.id, disabled: { droppable: cardDragged } })
const up = useContext(StatusContext)[link.id]
return ( return (
<div <div
ref={setNodeRef} ref={setNodeRef}
@@ -115,6 +119,19 @@ export function LinkTile({
className="block touch-manipulation rounded-2xl transition-colors outline-none select-none [-webkit-touch-callout:none] hover:bg-white/10 focus-visible:bg-white/10 focus-visible:ring-2 focus-visible:ring-white/60" className="block touch-manipulation rounded-2xl transition-colors outline-none select-none [-webkit-touch-callout:none] hover:bg-white/10 focus-visible:bg-white/10 focus-visible:ring-2 focus-visible:ring-white/60"
> >
<TileFace link={link} /> <TileFace link={link} />
{up !== undefined && (
// at the lower right corner of the icon. Filled green or a red ring:
// the shape differs too, not only the color.
<span
title={up ? "Reachable" : "Not reachable"}
className={cn(
"absolute top-[58px] right-[18px] size-3 rounded-full border-2",
up ? "border-black/70 bg-success" : "border-danger bg-black/80"
)}
>
{!up && <span className="sr-only">, not reachable</span>}
</span>
)}
</a> </a>
<button <button
type="button" type="button"
+20
View File
@@ -16,6 +16,7 @@ import { CLOCK_FONTS, CLOCK_STYLES } from "@/lib/clock"
import { libraryNames } from "@/lib/icon-library" import { libraryNames } from "@/lib/icon-library"
import { lightVariant } from "@/lib/icons" import { lightVariant } from "@/lib/icons"
import { ENGINES, parseSuggestions } from "@/lib/search" import { ENGINES, parseSuggestions } from "@/lib/search"
import { isReachable, statusChecks } from "@/lib/status"
const httpUrl = z.url({ protocol: /^https?$/ }).max(2000) const httpUrl = z.url({ protocol: /^https?$/ }).max(2000)
@@ -148,9 +149,28 @@ export const getDashboard = createServerFn({ method: "GET" })
clockFont: s?.clockFont ?? "serif", clockFont: s?.clockFont ?? "serif",
clockStyle: s?.clockStyle ?? "solid", clockStyle: s?.clockStyle ?? "solid",
searxngUrl: process.env.SEARXNG_URL || null, searxngUrl: process.env.SEARXNG_URL || null,
statusChecks,
} }
}) })
/** For every link of a dashboard: does its address answer? Empty when the checks are off. */
export const getStatuses = createServerFn({ method: "GET" })
.validator(z.object({ dashboardId: z.uuid() }))
.handler(async ({ data }): Promise<Record<string, boolean>> => {
const user = await requireUser()
if (!statusChecks) return {}
// only addresses that this user saved as links, never one from the request
const links = await db
.select({ id: link.id, url: link.url })
.from(link)
.innerJoin(card, eq(card.id, link.cardId))
.where(
and(eq(link.userId, user.id), eq(card.dashboardId, data.dashboardId))
)
const up = await Promise.all(links.map((l) => isReachable(l.url)))
return Object.fromEntries(links.map((l, i) => [l.id, up[i]]))
})
export const saveLink = createServerFn({ method: "POST" }) export const saveLink = createServerFn({ method: "POST" })
.validator( .validator(
z.object({ z.object({
+52
View File
@@ -0,0 +1,52 @@
import assert from "node:assert/strict"
import { createServer } from "node:http"
import { test } from "node:test"
import { isReachable, isUp } from "./status.ts"
test("isUp: any answer below 500", () => {
assert.equal(isUp({ status: 200 }), true)
assert.equal(isUp({ status: 302 }), true)
assert.equal(isUp({ status: 401 }), true) // a login page is an app that runs
assert.equal(isUp({ status: 404 }), true)
assert.equal(isUp({ status: 500 }), false)
assert.equal(isUp({ status: 502 }), false)
})
test("isUp: a certificate that this server does not trust is still an answer", () => {
const failed = (code: string) =>
Object.assign(new TypeError("fetch failed"), { cause: { code } })
assert.equal(isUp({ error: failed("DEPTH_ZERO_SELF_SIGNED_CERT") }), true)
assert.equal(isUp({ error: failed("UNABLE_TO_VERIFY_LEAF_SIGNATURE") }), true)
assert.equal(isUp({ error: failed("ERR_TLS_CERT_ALTNAME_INVALID") }), true)
assert.equal(isUp({ error: failed("ECONNREFUSED") }), false)
assert.equal(isUp({ error: failed("ENOTFOUND") }), false)
assert.equal(
isUp({ error: new DOMException("timeout", "TimeoutError") }),
false
)
assert.equal(isUp({ error: null }), false)
})
test("isReachable: asks the address, once per minute", async () => {
let requests = 0
const server = createServer((req, res) => {
requests++
res.writeHead(req.url === "/broken" ? 503 : 302, {
Location: "http://127.0.0.1:1/",
})
res.end()
})
await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve))
const { port } = server.address() as { port: number }
const base = `http://127.0.0.1:${port}`
try {
// the redirect is not followed: its target does not answer
assert.equal(await isReachable(`${base}/`), true)
assert.equal(await isReachable(`${base}/`), true)
assert.equal(requests, 1)
assert.equal(await isReachable(`${base}/broken`), false)
} finally {
server.close()
}
assert.equal(await isReachable("http://127.0.0.1:1/"), false) // nothing listens
})
+45
View File
@@ -0,0 +1,45 @@
// Is the address of a link reachable? Server side: the server asks, not the browser,
// so it also works for apps that do not allow requests from other pages.
/** Off unless the operator turns it on: users make the server call addresses they typed. */
export const statusChecks = process.env.STATUS_CHECKS === "true"
const TTL = 60_000
const TIMEOUT = 4000
/** Per address the last check, also while it runs, so one address is asked once a minute. */
const checks = new Map<string, { at: number; up: Promise<boolean> }>()
// A server answered, only this server does not trust its certificate (self-signed,
// private CA). The browser of the user may well trust it.
const CERTIFICATE = /CERT|SELF_SIGNED|UNABLE_TO_VERIFY|ALTNAME/
/** Up: any answer below 500. An app behind a proxy that is down answers 502 to 504. */
export function isUp(result: { status: number } | { error: unknown }) {
if ("status" in result) return result.status < 500
const cause = (result.error as { cause?: { code?: unknown } } | null)?.cause
return typeof cause?.code === "string" && CERTIFICATE.test(cause.code)
}
async function check(url: string) {
try {
const res = await fetch(url, {
// a redirect is an answer: do not follow it to another host
redirect: "manual",
signal: AbortSignal.timeout(TIMEOUT),
})
void res.body?.cancel() // the page itself is of no interest
return isUp(res)
} catch (error) {
return isUp({ error })
}
}
export function isReachable(url: string) {
const now = Date.now()
if (checks.size > 1000)
for (const [key, { at }] of checks) if (now - at > TTL) checks.delete(key)
let last = checks.get(url)
if (!last || now - last.at > TTL)
checks.set(url, (last = { at: now, up: check(url) }))
return last.up
}
+37 -2
View File
@@ -1,4 +1,4 @@
import { useState } from "react" import { useEffect, useState } from "react"
import { import {
Link, Link,
createFileRoute, createFileRoute,
@@ -19,11 +19,12 @@ import { CardGrid } from "@/components/card-grid"
import { Clock } from "@/components/clock" import { Clock } from "@/components/clock"
import { LinkDialog } from "@/components/link-dialog" import { LinkDialog } from "@/components/link-dialog"
import type { LinkTarget } from "@/components/link-dialog" import type { LinkTarget } from "@/components/link-dialog"
import { StatusContext } from "@/components/link-tile"
import { Logo } from "@/components/logo" import { Logo } from "@/components/logo"
import { SearchBar } from "@/components/search-bar" import { SearchBar } from "@/components/search-bar"
import { Wallpaper } from "@/components/wallpaper" import { Wallpaper } from "@/components/wallpaper"
import { authClient } from "@/lib/auth-client" import { authClient } from "@/lib/auth-client"
import { getDashboard } from "@/lib/dashboard.functions" import { getDashboard, getStatuses } from "@/lib/dashboard.functions"
import { Button } from "@/vendor/collabry/components/Button/Button" import { Button } from "@/vendor/collabry/components/Button/Button"
import { cn } from "@/vendor/collabry/lib/cn" import { cn } from "@/vendor/collabry/lib/cn"
@@ -44,9 +45,41 @@ export const Route = createFileRoute("/")({
const onWallpaper = const onWallpaper =
"rounded-full text-white/80 hover:bg-white/10 hover:text-white" "rounded-full text-white/80 hover:bg-white/10 hover:text-white"
/**
* Which links answer, asked again every minute and when the tab is opened again.
* `links` is their ids: a new link is checked at once.
*/
function useStatuses(on: boolean, dashboardId: string, links: string) {
const [statuses, setStatuses] = useState<Record<string, boolean>>({})
useEffect(() => {
if (!on) return
let stale = false
const load = () => {
if (document.hidden) return
getStatuses({ data: { dashboardId } })
.then((found) => !stale && setStatuses(found))
.catch(() => {}) // the dots stay as they were
}
load()
const timer = setInterval(load, 60_000)
document.addEventListener("visibilitychange", load)
return () => {
stale = true
clearInterval(timer)
document.removeEventListener("visibilitychange", load)
}
}, [on, dashboardId, links])
return statuses
}
function Dashboard() { function Dashboard() {
const data = Route.useLoaderData() const data = Route.useLoaderData()
const router = useRouter() const router = useRouter()
const statuses = useStatuses(
data.statusChecks,
data.dashboardId,
data.cards.flatMap((c) => c.links.map((l) => l.id)).join()
)
const [link, setLink] = useState<LinkTarget | null>(null) const [link, setLink] = useState<LinkTarget | null>(null)
const [card, setCard] = useState<CardTarget | null>(null) const [card, setCard] = useState<CardTarget | null>(null)
@@ -161,6 +194,7 @@ function Dashboard() {
</div> </div>
<div className="mt-[7vh] flex w-full flex-col items-center"> <div className="mt-[7vh] flex w-full flex-col items-center">
<StatusContext value={statuses}>
<CardGrid <CardGrid
cards={data.cards} cards={data.cards}
onAddCard={() => setCard("new")} onAddCard={() => setCard("new")}
@@ -168,6 +202,7 @@ function Dashboard() {
onEditLink={setLink} onEditLink={setLink}
onEditCard={setCard} onEditCard={setCard}
/> />
</StatusContext>
</div> </div>
<div className="flex-[3]" /> <div className="flex-[3]" />