Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ All notable changes to **omp-web** (`@kahme247/ompweb`) are documented in this f

## [Unreleased]

### Added

- **Settings → Mobile app tells you how to reach this server from a phone.** The new `GET /api/mobile-access` reports the binding (`-H`/`OMP_WEB_HOSTNAME`), whether a password is configured, the addresses a phone can type in (Tailscale MagicDNS when `tailscale` is installed, then Tailscale and LAN IPv4s, never loopback) and the exact install commands for the CLI, the Windows tray, systemd and launchd. It never changes the binding and never returns a credential — only whether the hash is present. The Tailscale probe runs a fixed install path with a sanitized environment, so a `tailscale` binary on `PATH` cannot read the server's secrets.

### Fixes & Improvements

- **In-app updates work when ompweb runs as a systemd service.** The update worker ran inside the service's cgroup, so stopping the server killed the worker too: nothing was installed, the service could stay down (`Restart=on-failure` does not restart a clean SIGTERM exit), and every page load reopened the update dialog at "Stop ompweb-managed sessions". The worker now runs in its own transient scope (`systemd-run --scope`) and stops, updates and starts the unit through `systemctl`, starting it again if the install fails.
Expand Down
40 changes: 40 additions & 0 deletions app/api/mobile-access/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { NextResponse } from "next/server";
import { networkInterfaces } from "node:os";
import {
candidateAddresses,
classifyExposure,
DEFAULT_MOBILE_PORT,
detectBindHostname,
mobileAccessMethods,
parseMobilePort,
probeMagicDnsName,
} from "@/lib/mobile-access";
import { isWebPasswordEnabled, webPasswordConfigurationProblem } from "@/lib/web-auth";

export const dynamic = "force-dynamic";

/**
* GET /api/mobile-access — read-only facts for Settings → Mobile app. The
* endpoint cannot change the binding and never returns the password (only
* whether one is configured).
*/
export async function GET(req: Request) {
const hostname = detectBindHostname();
const port = parseMobilePort(new URL(req.url).port) ?? parseMobilePort(process.env.PORT) ?? DEFAULT_MOBILE_PORT;
// Optional and time-boxed inside the helper: a missing tailscale binary
// resolves without spawning, and a slow one is cut off by its timeout.
const magicDnsName = await probeMagicDnsName();
return NextResponse.json({
binding: {
hostname,
exposure: classifyExposure(hostname),
port,
},
password: {
configured: isWebPasswordEnabled(),
problem: webPasswordConfigurationProblem() !== null,
},
addresses: candidateAddresses({ interfaces: networkInterfaces(), port, magicDnsName }),
methods: mobileAccessMethods(),
});
}
102 changes: 102 additions & 0 deletions components/SettingsConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,106 @@ function AgentToolsSetting() {
);
}

type MobileAccessData = {
binding: { hostname: string | null; exposure: "loopback" | "network" | "unknown"; port: number };
password: { configured: boolean; problem: boolean };
addresses: Array<{ url: string; label: "magicdns" | "tailscale" | "lan" }>;
methods: Array<{ id: "cli" | "windowsTray" | "systemd" | "launchd"; commands: string[] }>;
};

/** Read-only guide for the Android app: binding, password state, addresses, exact commands. */
function MobileAppCard() {
const { t } = useI18n();
const [data, setData] = useState<MobileAccessData | null>(null);
const [failed, setFailed] = useState(false);
useEffect(() => {
let alive = true;
fetch("/api/mobile-access")
.then((res) => (res.ok ? res.json() as Promise<MobileAccessData> : Promise.reject(new Error(`HTTP ${res.status}`))))
.then((next) => { if (alive) setData(next); })
.catch(() => { if (alive) setFailed(true); });
return () => { alive = false; };
}, []);
const bindingText = data === null ? ""
: t(`settingsConfig.mobileAppBinding.${data.binding.exposure}`, {
hostname: data.binding.hostname ?? "—",
port: String(data.binding.port),
});
const methodTitleKey: Record<MobileAccessData["methods"][number]["id"], string> = {
cli: "settingsConfig.mobileAppCli",
windowsTray: "settingsConfig.mobileAppWindowsTray",
systemd: "settingsConfig.mobileAppSystemd",
launchd: "settingsConfig.mobileAppLaunchd",
};
const methodHintKey: Record<MobileAccessData["methods"][number]["id"], string> = {
cli: "settingsConfig.mobileAppCliHint",
windowsTray: "settingsConfig.mobileAppWindowsTrayHint",
systemd: "settingsConfig.mobileAppSystemdHint",
launchd: "settingsConfig.mobileAppLaunchdHint",
};
return (
<section style={{ padding: 14, border: "1px solid var(--border)", borderRadius: "var(--radius-card)", background: "var(--bg-panel)", display: "flex", flexDirection: "column", gap: 12 }}>
<div>
<div className="settings-card-title" style={{ marginBottom: 4 }}>{t("settingsConfig.mobileAppTitle")}</div>
<div className="settings-card-desc">{t("settingsConfig.mobileAppDesc")}</div>
</div>
{failed && <Alert variant="warning" description={t("settingsConfig.mobileAppLoadFailed")} />}
{data !== null && (
<>
<div style={{ display: "flex", flexDirection: "column", gap: 4, fontSize: 12.5 }}>
<div>{bindingText}</div>
<div>{data.password.problem ? t("settingsConfig.mobileAppPasswordProblem") : data.password.configured ? t("settingsConfig.mobileAppPasswordSet") : t("settingsConfig.mobileAppPasswordMissing")}</div>
{data.binding.exposure !== "network" && <div style={{ color: "var(--warning, #b45309)" }}>{t("settingsConfig.mobileAppNetworkHint")}</div>}
</div>
<div style={{ display: "flex", flexDirection: "column", gap: 6 }}>
<div className="settings-section-title" style={{ fontSize: 12.5, fontWeight: 600 }}>{t("settingsConfig.mobileAppAddresses")}</div>
{data.addresses.length === 0
? <div style={{ color: "var(--text-muted)", fontSize: 12.5 }}>{t("settingsConfig.mobileAppNoAddresses")}</div>
: data.addresses.map((address) => (
<div key={address.url} style={{ display: "flex", alignItems: "center", gap: 8, flexWrap: "wrap" }}>
<code style={{ fontSize: 12.5 }}>{address.url}</code>
<span style={{ color: "var(--text-muted)", fontSize: 11.5 }}>{t(`settingsConfig.mobileAppLabel.${address.label}`)}</span>
<button
type="button"
onClick={() => { void copyText(address.url).catch(() => toast.error(t("appShell.commandCopyFailed"))); }}
title={t("appShell.copyCommand")}
aria-label={t("appShell.copyCommand")}
style={{ border: "none", background: "none", cursor: "pointer", color: "var(--text-muted)", padding: 2, display: "inline-flex" }}
>
<Copy size={13} />
</button>
</div>
))}
</div>
<div style={{ display: "flex", flexDirection: "column", gap: 8 }}>
<div className="settings-section-title" style={{ fontSize: 12.5, fontWeight: 600 }}>{t("settingsConfig.mobileAppSteps")}</div>
{data.methods.map((method) => (
<div key={method.id} style={{ display: "flex", flexDirection: "column", gap: 4 }}>
<div style={{ fontSize: 12.5, fontWeight: 600 }}>{t(methodTitleKey[method.id])}</div>
<div style={{ color: "var(--text-muted)", fontSize: 12, lineHeight: 1.45 }}>{t(methodHintKey[method.id])}</div>
{method.commands.map((command) => (
<div key={command} style={{ display: "flex", alignItems: "center", gap: 6 }}>
<code style={{ fontSize: 12, overflowWrap: "anywhere", minWidth: 0 }}>{command}</code>
<button
type="button"
onClick={() => { void copyText(command).catch(() => toast.error(t("appShell.commandCopyFailed"))); }}
title={t("appShell.copyCommand")}
aria-label={t("appShell.copyCommand")}
style={{ border: "none", background: "none", cursor: "pointer", color: "var(--text-muted)", padding: 2, display: "inline-flex", flexShrink: 0 }}
>
<Copy size={13} />
</button>
</div>
))}
</div>
))}
</div>
</>
)}
</section>
);
}

/** Server-side omp-web setting (issue #104): KEY=VALUE text injected into the
* `omp` child process. Parsing/validation lives in lib/omp/agent-env.ts; this only
* feeds it localized messages and renders the result. */
Expand Down Expand Up @@ -1770,6 +1870,8 @@ export function SettingsConfig({ activeTab, toolCallsDefaultCollapsed, onToolCal

<AgentEnvSetting />

<MobileAppCard />

{/* ompweb app update card */}
<section style={{ padding: 14, border: appUpdateIsAvailable ? "1px solid color-mix(in srgb, var(--accent) 45%, var(--border))" : "1px solid var(--border)", borderRadius: "var(--radius-card)", background: "var(--bg-panel)", display: "flex", flexDirection: "column", gap: 10 }}>
<div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", gap: 12 }}>
Expand Down
13 changes: 13 additions & 0 deletions lib/api-contract.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,16 @@ test("new-session route never forwards a session id into the child RPC", async (
const route = await readFile(new URL("../app/api/agent/new/route.ts", import.meta.url), "utf8");
assert.match(route, /delete promptCommand\.sessionId/);
});

test("the tailscale probe runs a fixed binary with a sanitized environment", async () => {
const source = await readFile(new URL("./mobile-access.ts", import.meta.url), "utf8");

// A PATH lookup ran whatever a project, an npm `bin` directory or
// ~/.local/bin provided — with this server's environment, which holds
// OMP_WEB_PASSWORD_HASH. Only fixed install locations may be executed.
assert.doesNotMatch(source, /process\.env\.PATH/);
assert.match(source, /"\/usr\/bin\/tailscale"/);
assert.match(source, /"Tailscale IPN", "tailscale\.exe"/);
// Same rule as ps/PowerShell: child processes never inherit the secrets.
assert.match(source, /env: createChildProcessEnvironment\(\)/);
});
24 changes: 24 additions & 0 deletions lib/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,30 @@
"settingsConfig.agentTools": "Agent tools (cross-session)",
"settingsConfig.agentToolsDesc": "Allow agents to call list_sessions, new_session and send_to_session to reach other omp-web sessions, even with no browser tab open. Messages delivered this way are prefixed with the sending session's ID. A per-session rate limit and a chain-depth limit stop sessions looping messages to each other. Applies to sessions started or reconnected after saving.",
"settingsConfig.agentToolsSaveFailed": "Could not save the agent tools setting",
"settingsConfig.mobileAppTitle": "Mobile app",
"settingsConfig.mobileAppDesc": "The Android app connects to this server directly. Use one of the addresses below, then sign in with your ompweb password.",
"settingsConfig.mobileAppBinding.loopback": "Server binding: {hostname}:{port} (loopback only).",
"settingsConfig.mobileAppBinding.network": "Server binding: {hostname}:{port} (reachable from your network).",
"settingsConfig.mobileAppBinding.unknown": "Server binding: unknown (port {port}).",
"settingsConfig.mobileAppPasswordSet": "Password protection is configured.",
"settingsConfig.mobileAppPasswordMissing": "No password is configured. Set one before exposing this server to the network.",
"settingsConfig.mobileAppPasswordProblem": "The password configuration is broken. Fix it before connecting a phone.",
"settingsConfig.mobileAppNetworkHint": "The server is not listening on the network. Restart it with one of the commands below and use the network address.",
"settingsConfig.mobileAppAddresses": "Addresses",
"settingsConfig.mobileAppNoAddresses": "No network address was found. Connect a network interface or start Tailscale.",
"settingsConfig.mobileAppLabel.magicdns": "Tailscale MagicDNS",
"settingsConfig.mobileAppLabel.tailscale": "Tailscale",
"settingsConfig.mobileAppLabel.lan": "Local network",
"settingsConfig.mobileAppSteps": "Expose this server",
"settingsConfig.mobileAppCli": "Command line",
"settingsConfig.mobileAppCliHint": "Generate a password hash, then start ompweb on all interfaces. The hash is not echoed.",
"settingsConfig.mobileAppWindowsTray": "Windows tray app",
"settingsConfig.mobileAppWindowsTrayHint": "Store the hash for your user, then install the tray app bound to all interfaces.",
"settingsConfig.mobileAppSystemd": "systemd service",
"settingsConfig.mobileAppSystemdHint": "The installer hashes the password and writes the unit. A network binding is refused without a password.",
"settingsConfig.mobileAppLaunchd": "launchd service",
"settingsConfig.mobileAppLaunchdHint": "The installer hashes the password and writes the plist. A network binding is refused without a password.",
"settingsConfig.mobileAppLoadFailed": "Could not load the mobile access details.",
"settingsConfig.agentEnv": "Agent environment variables",
"settingsConfig.agentEnvDesc": "Extra environment variables handed to the omp process, for example the API key an MCP server needs. One KEY=VALUE per line; # comments and blank lines are ignored.",
"settingsConfig.agentEnvNote": "Saved values are injected when a session starts. Sessions that are already running keep the environment they started with, so restart them to pick up the new values. Variables omp-web needs itself (PATH, HOME, PI_CODING_AGENT_DIR, OMP_WEB_*, and similar) cannot be set here.",
Expand Down
24 changes: 24 additions & 0 deletions lib/i18n/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,30 @@
"settingsConfig.autoResumeSessionsSaveFailed": "再開設定を保存できませんでした",
"settingsConfig.autoResumeSessionsDesc": "エージェントの作業中に omp-web が再起動した場合、それらのセッションを再開し、各エージェントに「Session interrupted and resumed. Continue as you would have done without the interruption.」と伝えます。再起動の時点で進行中だった作業(実行中のコマンドなど)は失われます。",
"settingsConfig.autoResumeSessions": "再起動後に実行中のセッションを再開",
"settingsConfig.mobileAppTitle": "モバイルアプリ",
"settingsConfig.mobileAppDesc": "Android アプリはこのサーバーに直接接続します。以下のアドレスを使用し、ompweb のパスワードでサインインしてください。",
"settingsConfig.mobileAppBinding.loopback": "サーバーのバインド: {hostname}:{port}(ループバックのみ)。",
"settingsConfig.mobileAppBinding.network": "サーバーのバインド: {hostname}:{port}(ネットワークから到達可能)。",
"settingsConfig.mobileAppBinding.unknown": "サーバーのバインド: 不明(ポート {port})。",
"settingsConfig.mobileAppPasswordSet": "パスワード保護が設定されています。",
"settingsConfig.mobileAppPasswordMissing": "パスワードが設定されていません。ネットワークに公開する前に設定してください。",
"settingsConfig.mobileAppPasswordProblem": "パスワード設定が壊れています。スマートフォンを接続する前に修正してください。",
"settingsConfig.mobileAppNetworkHint": "サーバーはネットワークで待ち受けていません。以下のコマンドのいずれかで再起動し、ネットワークアドレスを使用してください。",
"settingsConfig.mobileAppAddresses": "アドレス",
"settingsConfig.mobileAppNoAddresses": "ネットワークアドレスが見つかりません。ネットワークインターフェースを接続するか Tailscale を起動してください。",
"settingsConfig.mobileAppLabel.magicdns": "Tailscale MagicDNS",
"settingsConfig.mobileAppLabel.tailscale": "Tailscale",
"settingsConfig.mobileAppLabel.lan": "ローカルネットワーク",
"settingsConfig.mobileAppSteps": "このサーバーを公開する",
"settingsConfig.mobileAppCli": "コマンドライン",
"settingsConfig.mobileAppCliHint": "パスワードハッシュを生成し、すべてのインターフェースで ompweb を起動します。ハッシュは画面に表示されません。",
"settingsConfig.mobileAppWindowsTray": "Windows トレイアプリ",
"settingsConfig.mobileAppWindowsTrayHint": "ユーザーのハッシュを保存し、すべてのインターフェースにバインドしたトレイアプリをインストールします。",
"settingsConfig.mobileAppSystemd": "systemd サービス",
"settingsConfig.mobileAppSystemdHint": "インストーラーがパスワードをハッシュ化してユニットを書き込みます。ネットワークバインドではパスワードなしでは拒否されます。",
"settingsConfig.mobileAppLaunchd": "launchd サービス",
"settingsConfig.mobileAppLaunchdHint": "インストーラーがパスワードをハッシュ化して plist を書き込みます。ネットワークバインドではパスワードなしでは拒否されます。",
"settingsConfig.mobileAppLoadFailed": "モバイルアクセスの詳細を読み込めませんでした。",
"settingsConfig.agentEnv": "エージェントの環境変数",
"settingsConfig.agentEnvDesc": "omp プロセスに渡される追加の環境変数です(例: MCP サーバーが必要とする API キー)。1 行につき 1 つの KEY=VALUE を記述します。# で始まる行と空行は無視されます。",
"settingsConfig.agentEnvNote": "保存した値はセッションの開始時に注入されます。実行中のセッションは開始時の環境のままなので、新しい値を反映するには再起動してください。omp-web 自身が必要とする変数(PATH、HOME、PI_CODING_AGENT_DIR、OMP_WEB_* など)はここでは設定できません。",
Expand Down
Loading