oculon 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -4
- package/dist/cli/main.js +184 -0
- package/dist/core/calls.d.ts +63 -0
- package/dist/core/calls.js +120 -0
- package/dist/core/evm.d.ts +20 -0
- package/dist/core/evm.js +165 -0
- package/dist/core/http.d.ts +11 -0
- package/dist/core/http.js +113 -30
- package/dist/core/pdf.d.ts +51 -0
- package/dist/core/pdf.js +211 -0
- package/dist/core/quota.js +3 -0
- package/dist/core/verdict.d.ts +30 -0
- package/dist/core/verdict.js +164 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +54 -0
- package/dist/mcp.d.ts +1 -0
- package/dist/mcp.js +159 -5
- package/dist/modules/address.d.ts +32 -0
- package/dist/modules/address.js +91 -0
- package/dist/modules/checks.d.ts +59 -0
- package/dist/modules/checks.js +134 -0
- package/dist/modules/doc.d.ts +61 -0
- package/dist/modules/doc.js +715 -0
- package/dist/modules/headers.d.ts +50 -0
- package/dist/modules/headers.js +108 -0
- package/dist/modules/honeypot.d.ts +36 -0
- package/dist/modules/honeypot.js +53 -0
- package/dist/modules/iban.d.ts +30 -0
- package/dist/modules/iban.js +82 -0
- package/dist/modules/lookalike.d.ts +34 -0
- package/dist/modules/lookalike.js +122 -0
- package/dist/modules/personal.d.ts +1 -1
- package/dist/modules/personal.js +14 -4
- package/dist/modules/utility.d.ts +147 -0
- package/dist/modules/utility.js +403 -0
- package/dist/report-pdf.d.ts +7 -0
- package/dist/report-pdf.js +81 -0
- package/dist/telegram.d.ts +2 -0
- package/dist/telegram.js +43 -6
- package/dist/web/assets/logo-200.png +0 -0
- package/dist/web/burns.d.ts +21 -0
- package/dist/web/burns.js +53 -0
- package/dist/web/card.d.ts +28 -0
- package/dist/web/card.js +75 -0
- package/dist/web/index.html +76 -4
- package/dist/web/landing.html +1 -1
- package/dist/web/legal.html +1 -1
- package/dist/web/mcp.html +1 -1
- package/dist/web/openapi.js +6 -0
- package/dist/web/pages.d.ts +24 -0
- package/dist/web/pages.js +139 -0
- package/dist/web/public.js +7 -1
- package/dist/web/server.d.ts +17 -0
- package/dist/web/server.js +207 -7
- package/dist/web/token.html +98 -0
- package/dist/web/token.json +9 -0
- package/dist/web/utility.html +251 -0
- package/package.json +1 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-rendered pages for the replay log (/replay/<id>), source status (/status) and the AI-agent guides
|
|
3
|
+
* (/llms.txt, /llms-full.txt). Plain HTML in the site's look; no scripts needed to read them.
|
|
4
|
+
*/
|
|
5
|
+
import type { SourceStatus } from '../core/calls.js';
|
|
6
|
+
import type { CheckRecord } from '../modules/checks.js';
|
|
7
|
+
/** /replay/<id>: what a check said and every source it called, in order. */
|
|
8
|
+
export declare function replayPage(c: CheckRecord, history: {
|
|
9
|
+
id: string;
|
|
10
|
+
at: string;
|
|
11
|
+
verdict: string | null;
|
|
12
|
+
risk: number | null;
|
|
13
|
+
}[], base: string): string;
|
|
14
|
+
/** /status: which sources answered in the last day. */
|
|
15
|
+
export declare function statusPage(list: SourceStatus[], base: string, hours: number): string;
|
|
16
|
+
export interface ToolDoc {
|
|
17
|
+
name: string;
|
|
18
|
+
description: string;
|
|
19
|
+
inputSchema: Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
/** /llms.txt: a short guide for AI agents (llmstxt.org format). */
|
|
22
|
+
export declare function llmsTxt(tools: ToolDoc[], base: string, mcpUrl: string): string;
|
|
23
|
+
/** /llms-full.txt: every tool with its full description and arguments. */
|
|
24
|
+
export declare function llmsFull(tools: ToolDoc[], base: string, mcpUrl: string): string;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
const esc = (s) => String(s ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]);
|
|
2
|
+
const when = (iso) => `${iso.slice(0, 16).replace('T', ' ')} UTC`;
|
|
3
|
+
function shell(title, desc, body, canonical) {
|
|
4
|
+
return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
5
|
+
<title>${esc(title)}</title><meta name="description" content="${esc(desc)}"><meta name="robots" content="noindex">
|
|
6
|
+
<link rel="icon" type="image/png" href="/favicon.ico"><meta name="theme-color" content="#000000">
|
|
7
|
+
<link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
8
|
+
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600&family=Space+Mono:wght@400;700&display=swap" rel="stylesheet">
|
|
9
|
+
<style>
|
|
10
|
+
:root{--line:#1f2a2d;--soft:#cfd8da;--mut:#8fa3a7;--y:#00f0ff;--bad:#ff5d6c;--warn:#f5a524;--ok:#3ddc97;--sans:'Space Grotesk',system-ui,sans-serif;--mono:'Space Mono',ui-monospace,Consolas,monospace}
|
|
11
|
+
*{box-sizing:border-box}html,body{overflow-x:clip}
|
|
12
|
+
body{margin:0;background:#000;color:#fff;font-family:var(--sans);-webkit-font-smoothing:antialiased}
|
|
13
|
+
a{color:var(--y)}
|
|
14
|
+
header{border-bottom:1px solid #222}header .in{display:flex;justify-content:space-between;align-items:center;padding:18px clamp(16px,3vw,40px);gap:16px}
|
|
15
|
+
.logo{font-size:16px;font-weight:600;letter-spacing:.4em;text-decoration:none;color:#fff}.logo img{width:20px;height:20px;vertical-align:-4px;margin-right:12px}
|
|
16
|
+
header nav{display:flex;gap:20px;font-size:14px}header nav a{color:var(--soft);text-decoration:none}
|
|
17
|
+
main{max-width:980px;margin:0 auto;padding:48px clamp(16px,4vw,40px) 90px}
|
|
18
|
+
.lbl{font:12px var(--mono);letter-spacing:.14em;text-transform:uppercase;color:var(--mut)}
|
|
19
|
+
h1{margin:10px 0 8px;font-size:clamp(28px,4.5vw,44px);font-weight:400;letter-spacing:-.03em;line-height:1.1;overflow-wrap:anywhere}
|
|
20
|
+
h2{margin:40px 0 12px;font-size:20px;font-weight:500;padding-top:18px;border-top:1px solid #222}
|
|
21
|
+
p,li{color:var(--soft);font-size:16px;line-height:1.65}
|
|
22
|
+
.pill{display:inline-block;font:700 13px var(--mono);letter-spacing:.06em;text-transform:uppercase;padding:6px 10px;color:#000;background:var(--mut)}
|
|
23
|
+
.pill.bad{background:var(--bad);color:#fff}.pill.warn{background:var(--warn)}.pill.ok{background:var(--ok)}
|
|
24
|
+
.kv{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:10px;margin-top:22px}
|
|
25
|
+
.kv div{border:1px solid var(--line);padding:12px 14px;background:rgba(4,10,12,.9)}.kv b{display:block;font:400 11px var(--mono);letter-spacing:.14em;color:var(--mut);text-transform:uppercase}.kv span{display:block;margin-top:6px;font:700 15px var(--mono);overflow-wrap:anywhere}
|
|
26
|
+
.tw{overflow-x:auto;border:1px solid var(--line)}
|
|
27
|
+
table{width:100%;border-collapse:collapse;font:13px var(--mono)}
|
|
28
|
+
th{text-align:left;font-weight:400;color:var(--mut);letter-spacing:.1em;text-transform:uppercase;font-size:11px;padding:10px 10px;border-bottom:1px solid var(--line);white-space:nowrap}
|
|
29
|
+
td{padding:9px 10px;border-bottom:1px solid #111a1c;color:#e8eef0;vertical-align:top}
|
|
30
|
+
td.n{text-align:right;white-space:nowrap}
|
|
31
|
+
.bar{display:inline-block;height:8px;background:var(--y);vertical-align:middle;min-width:2px}
|
|
32
|
+
.s-LIVE{color:var(--ok)}.s-CACHED{color:var(--y)}.s-ERROR{color:var(--bad)}.s-UNAVAILABLE{color:var(--warn)}
|
|
33
|
+
.st{font:700 12px var(--mono);text-transform:uppercase;letter-spacing:.08em}.st.up{color:var(--ok)}.st.slow{color:var(--warn)}.st.degraded{color:var(--warn)}.st.down{color:var(--bad)}
|
|
34
|
+
.btn{display:inline-block;font:700 13px var(--mono);letter-spacing:.08em;background:var(--y);color:#000;padding:11px 15px;text-decoration:none;margin:6px 10px 0 0}
|
|
35
|
+
.btn.o{background:none;color:var(--y);border:1px solid rgba(0,240,255,.5)}
|
|
36
|
+
.note{font-size:13px;color:var(--mut)}
|
|
37
|
+
pre{white-space:pre-wrap;overflow-wrap:anywhere;background:#050b0d;border:1px solid var(--line);padding:14px;font:12px/1.6 var(--mono);color:#dfe7e9;max-height:520px;overflow:auto}
|
|
38
|
+
footer{border-top:1px solid #222}footer .in{max-width:980px;margin:0 auto;padding:22px clamp(16px,4vw,40px);font:12px var(--mono);color:#5e5e5e;display:flex;justify-content:space-between;gap:12px;flex-wrap:wrap}footer a{color:var(--mut)}
|
|
39
|
+
@media (max-width:720px){.kv{grid-template-columns:repeat(2,minmax(0,1fr))}}
|
|
40
|
+
</style><link rel="canonical" href="${esc(canonical)}"></head><body>
|
|
41
|
+
<header><div class="in"><a class="logo" href="/"><img src="/assets/logo.svg" alt="">OCULON</a><nav><a href="/app">App</a><a href="/docs">Docs</a><a href="/status">Status</a></nav></div></header>
|
|
42
|
+
<main>${body}</main>
|
|
43
|
+
<footer><div class="in"><span>Oculon contributors · MIT</span><span><a href="/">Home</a> · <a href="/docs">Docs</a> · <a href="/status">Status</a> · <a href="/thetoken">Token</a></span></div></footer>
|
|
44
|
+
</body></html>`;
|
|
45
|
+
}
|
|
46
|
+
/** /replay/<id>: what a check said and every source it called, in order. */
|
|
47
|
+
export function replayPage(c, history, base) {
|
|
48
|
+
const v = c.verdict;
|
|
49
|
+
const t0 = c.calls.length ? Date.parse(c.calls[0].at) - c.calls[0].ms : Date.parse(c.createdAt);
|
|
50
|
+
const maxMs = Math.max(1, ...c.calls.map((k) => k.ms));
|
|
51
|
+
const rows = c.calls.map((k, i) => `<tr><td class="n">${i + 1}</td><td class="n">+${Math.max(0, ((Date.parse(k.at) - k.ms - t0) / 1000)).toFixed(2)}s</td><td>${esc(k.source)}</td><td>${esc(k.host)}${k.via ? ' <span class="note">(mirror)</span>' : ''}</td><td class="s-${esc(k.status)}">${esc(k.status)}${k.note ? `<div class="note">${esc(k.note)}</div>` : ''}</td><td class="n">${k.ms} ms <span class="bar" style="width:${Math.round((k.ms / maxMs) * 80)}px"></span></td></tr>`).join('');
|
|
52
|
+
const seen = c.seenBefore ? `<h2>Seen before</h2><p>Last checked ${esc(when(c.seenBefore.at))}, verdict then: <b>${esc(c.seenBefore.verdict ?? 'none')}</b>. ${c.seenBefore.changes.length ? '' : 'Nothing changed since then.'}</p>${c.seenBefore.changes.length ? `<ul>${c.seenBefore.changes.map((x) => `<li>${esc(x)}</li>`).join('')}</ul>` : ''}` : '';
|
|
53
|
+
const hist = history.length > 1 ? `<h2>History of this target</h2><div class="tw"><table><tr><th>When</th><th>Verdict</th><th>Risk</th><th></th></tr>${history.map((h) => `<tr><td>${esc(when(h.at))}</td><td>${esc(h.verdict ?? '-')}</td><td class="n">${h.risk ?? '-'}</td><td>${h.id === c.id ? '<span class="note">this check</span>' : `<a href="/replay/${esc(h.id)}">replay</a>`}</td></tr>`).join('')}</table></div>` : '';
|
|
54
|
+
const result = c.result ? `<h2>Full result</h2><pre>${esc(JSON.stringify(c.result, null, 2).slice(0, 60_000))}</pre>` : '';
|
|
55
|
+
const body = `<div class="lbl">Replay log · ${esc(c.kind)}</div><h1>${esc(c.label)}</h1>
|
|
56
|
+
<p><span class="pill ${esc(v.tone)}">${esc(v.verdict ?? 'result')}</span>${v.risk !== null ? ` <span class="note">risk ${v.risk}/100</span>` : ''}</p>
|
|
57
|
+
<div class="kv"><div><b>Checked</b><span>${esc(when(c.createdAt))}</span></div><div><b>Took</b><span>${(c.durationMs / 1000).toFixed(1)} s</span></div><div><b>Source calls</b><span>${c.calls.length}</span></div><div><b>Live / cached / failed</b><span>${v.sources.live} / ${v.sources.cached} / ${v.sources.failed}</span></div></div>
|
|
58
|
+
<p><a class="btn" href="/report/${esc(c.id)}.pdf">Download PDF report</a><a class="btn o" href="/app#investigate">Run a new check</a></p>
|
|
59
|
+
${v.points.length ? `<h2>Why</h2><ul>${v.points.map((p) => `<li>${esc(p)}</li>`).join('')}</ul>` : ''}${seen}
|
|
60
|
+
<h2>Every source called</h2><p class="note">In the order they answered. Cached answers took 0 ms. A failed source is not a finding; a mirror answered when the main host was down.</p>
|
|
61
|
+
${rows ? `<div class="tw"><table><tr><th>#</th><th>Start</th><th>Source</th><th>Host</th><th>Status</th><th>Time</th></tr>${rows}</table></div>` : '<p>No network calls: this check ran on the input alone.</p>'}
|
|
62
|
+
${hist}${result}<p class="note" style="margin-top:28px">Kept for 90 days. Anyone with this link can see it.</p>`;
|
|
63
|
+
return shell(`Replay: ${c.label}`, `Oculon replay log of a ${c.kind} check`, body, `${base}/replay/${c.id}`);
|
|
64
|
+
}
|
|
65
|
+
/** /status: which sources answered in the last day. */
|
|
66
|
+
export function statusPage(list, base, hours) {
|
|
67
|
+
const n = (s) => list.filter((x) => x.state === s).length;
|
|
68
|
+
const rows = list.map((s) => `<tr><td>${esc(s.source)}<div class="note">${esc(s.hosts.join(', '))}</div></td><td><span class="st ${s.state}">${s.state}</span>${s.skippedUntil ? `<div class="note">skipped until ${esc(s.skippedUntil.slice(11, 16))} UTC, fallback in use</div>` : ''}</td><td class="n">${s.okPct}%</td><td class="n">${s.calls}</td><td class="n">${s.medianMs === null ? '-' : `${s.medianMs} ms`}</td><td>${s.lastError ? `${esc(s.lastError.at.slice(11, 16))} <span class="note">${esc(s.lastError.note)}</span>` : '<span class="note">none</span>'}</td></tr>`).join('');
|
|
69
|
+
const body = `<div class="lbl">Source status · last ${hours} hours</div><h1>Which sources are up, slow or down.</h1>
|
|
70
|
+
<p>Every check calls public sources. This page shows how each one answered Oculon in the last ${hours} hours, measured from real calls. When a source keeps failing it is skipped for a few minutes and a mirror or the last cached answer is used instead, and the result says so.</p>
|
|
71
|
+
<div class="kv"><div><b>Up</b><span style="color:var(--ok)">${n('up')}</span></div><div><b>Slow</b><span style="color:var(--warn)">${n('slow')}</span></div><div><b>Degraded</b><span style="color:var(--warn)">${n('degraded')}</span></div><div><b>Down</b><span style="color:var(--bad)">${n('down')}</span></div></div>
|
|
72
|
+
<h2>Sources</h2>${rows ? `<div class="tw"><table><tr><th>Source</th><th>State</th><th>Worked</th><th>Calls</th><th>Median</th><th>Last error</th></tr>${rows}</table></div>` : '<p>No live calls yet in this window.</p>'}
|
|
73
|
+
<p class="note" style="margin-top:20px">Up: the last calls worked. Degraded: some of the last five failed. Down: they all failed, or the source is being skipped. Slow: median above 5 seconds. JSON: <a href="/api/status">/api/status</a>.</p>`;
|
|
74
|
+
return shell('Oculon status', 'Which Oculon sources are up, slow or down', body, `${base}/status`);
|
|
75
|
+
}
|
|
76
|
+
const FIRST_SENTENCE = /^.*?(?<!\be\.g|\bi\.e|\bvs)[.?!](?=\s+[A-Z("]|$)/;
|
|
77
|
+
const WS = /\s+/g;
|
|
78
|
+
/** First sentence, not fooled by "e.g." or "i.e.". */
|
|
79
|
+
function firstSentence(d) {
|
|
80
|
+
const m = FIRST_SENTENCE.exec(d.replace(WS, ' '));
|
|
81
|
+
return (m ? m[0] : d).trim();
|
|
82
|
+
}
|
|
83
|
+
/** /llms.txt: a short guide for AI agents (llmstxt.org format). */
|
|
84
|
+
export function llmsTxt(tools, base, mcpUrl) {
|
|
85
|
+
const groups = [
|
|
86
|
+
['Everyday checks', /scam|url_check|doc_check|iban|email_headers|lookalike|phone|password|breaches|company|email_security|recall|travel|fact_check/],
|
|
87
|
+
['Threat intel', /ip_check|hash|ransomware|vulns|cve|package|exposure|bgp|blackout|cloud/],
|
|
88
|
+
['Crypto', /token|wallet|honeypot|address_check|robinhood|defi|protocol|sanctions/],
|
|
89
|
+
];
|
|
90
|
+
const line = (t) => `- [${t.name}](${base}/llms-full.txt#${t.name}): ${firstSentence(t.description)}`;
|
|
91
|
+
const used = new Set();
|
|
92
|
+
const sections = groups.map(([g, re]) => {
|
|
93
|
+
const ts = tools.filter((t) => re.test(t.name) && !used.has(t.name));
|
|
94
|
+
ts.forEach((t) => used.add(t.name));
|
|
95
|
+
return `## ${g}\n\n${ts.map(line).join('\n')}`;
|
|
96
|
+
});
|
|
97
|
+
const rest = tools.filter((t) => !used.has(t.name));
|
|
98
|
+
return `# Oculon
|
|
99
|
+
|
|
100
|
+
> Free, open-source OSINT engine (MIT). Checks things before you trust them: messages, links, documents, IBANs, phone numbers, email headers, IPs, file hashes, tokens and wallets. Every answer lists the sources it used and whether each was live, cached or unavailable.
|
|
101
|
+
|
|
102
|
+
Use it from an AI agent over MCP: add ${mcpUrl} as a remote MCP server (no key, no sign-in), or run \`npx oculon mcp\` locally. ${tools.length} tools.
|
|
103
|
+
|
|
104
|
+
Rules for agents:
|
|
105
|
+
- Report data as given. A source marked ERROR or UNAVAILABLE is not a finding.
|
|
106
|
+
- Check tools return a verdict, a risk score, reasons, and a check id. Pass \`brief: true\` to any tool for a short answer with fewer tokens.
|
|
107
|
+
- A check id opens a replay log (${base}/replay/<id>) with every source call, and a PDF report (${base}/report/<id>.pdf).
|
|
108
|
+
- Source health: ${base}/status (JSON at ${base}/api/status).
|
|
109
|
+
|
|
110
|
+
## Docs
|
|
111
|
+
|
|
112
|
+
- [Full tool reference](${base}/llms-full.txt): every tool with its arguments
|
|
113
|
+
- [Documentation](${base.replace('//app.', '//docs.')}): install, CLI, SDK, MCP, web
|
|
114
|
+
- [OpenAPI](${base}/openapi.json): the HTTP API
|
|
115
|
+
- [Source code](https://github.com/oculonlive/oculon)
|
|
116
|
+
|
|
117
|
+
${sections.join('\n\n')}
|
|
118
|
+
|
|
119
|
+
## Optional
|
|
120
|
+
|
|
121
|
+
${rest.map(line).join('\n')}
|
|
122
|
+
`;
|
|
123
|
+
}
|
|
124
|
+
/** /llms-full.txt: every tool with its full description and arguments. */
|
|
125
|
+
export function llmsFull(tools, base, mcpUrl) {
|
|
126
|
+
const args = (s) => {
|
|
127
|
+
const props = (s.properties ?? {});
|
|
128
|
+
const req = new Set((s.required ?? []));
|
|
129
|
+
const rows = Object.entries(props).map(([k, p]) => ` - \`${k}\` (${p.type ?? 'any'}${req.has(k) ? ', required' : ''})${p.description ? `: ${p.description}` : ''}${p.enum ? ` One of: ${p.enum.join(', ')}.` : ''}`);
|
|
130
|
+
return rows.length ? rows.join('\n') : ' - no arguments';
|
|
131
|
+
};
|
|
132
|
+
return `# Oculon: full tool reference
|
|
133
|
+
|
|
134
|
+
MCP endpoint: ${mcpUrl} (remote, no key) or \`npx oculon mcp\` (local, stdio).
|
|
135
|
+
Every tool also takes \`brief\` (boolean): a short answer for agents (verdict, risk, top reasons, sources, check id).
|
|
136
|
+
Check tools return \`check.id\`: replay log at ${base}/replay/<id>, PDF report at ${base}/report/<id>.pdf.
|
|
137
|
+
|
|
138
|
+
${tools.map((t) => `## ${t.name}\n\n${t.description}\n\nArguments:\n${args(t.inputSchema)}\n`).join('\n')}`;
|
|
139
|
+
}
|
package/dist/web/public.js
CHANGED
|
@@ -10,6 +10,8 @@ import { createHash, timingSafeEqual } from 'node:crypto';
|
|
|
10
10
|
/** Read-only endpoints the public pages call. Everything else needs the admin cookie. */
|
|
11
11
|
export const PUBLIC_API = new Set([
|
|
12
12
|
'/api/meta',
|
|
13
|
+
'/api/status',
|
|
14
|
+
'/api/check',
|
|
13
15
|
'/api/readme',
|
|
14
16
|
'/api/console',
|
|
15
17
|
'/api/signals',
|
|
@@ -51,9 +53,13 @@ export const PUBLIC_API = new Set([
|
|
|
51
53
|
'/api/breaches',
|
|
52
54
|
'/api/phone',
|
|
53
55
|
'/api/satellites',
|
|
56
|
+
'/api/iban',
|
|
57
|
+
'/api/lookalike',
|
|
58
|
+
'/api/honeypot',
|
|
59
|
+
'/api/address',
|
|
54
60
|
]);
|
|
55
61
|
/** Endpoints that start outside work (a CLI process or several upstream calls) get a tighter budget. */
|
|
56
|
-
const HEAVY = new Set(['/api/console', '/api/rhtoken', '/api/verify', '/api/url', '/api/travel', '/api/audit', '/api/recall', '/api/emailsec', '/api/country', '/api/airport', '/api/scam', '/api/ip', '/api/hash', '/api/company', '/api/phone']);
|
|
62
|
+
const HEAVY = new Set(['/api/console', '/api/rhtoken', '/api/verify', '/api/url', '/api/travel', '/api/audit', '/api/recall', '/api/emailsec', '/api/country', '/api/airport', '/api/scam', '/api/ip', '/api/hash', '/api/company', '/api/phone', '/api/lookalike', '/api/honeypot', '/api/address']);
|
|
57
63
|
/** Signals from these modules describe the owner's own watchlist, cases, fences, votes or raw social streams. */
|
|
58
64
|
const PRIVATE_MODULES = new Set(['meerkat', 'case', 'fence', 'feedback', 'live']);
|
|
59
65
|
export function publicSignals(list) {
|
package/dist/web/server.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { type Server } from 'node:http';
|
|
2
2
|
import { Oculon } from '../index.js';
|
|
3
3
|
import { type Delivery } from '../modules/personal.js';
|
|
4
|
+
import { type BurnInfo } from './burns.js';
|
|
4
5
|
export interface WebOptions {
|
|
6
|
+
/** RPC for the burn list on /thetoken (default ROBINHOOD_PUBLIC_RPC_URL) and a fetch for tests. */
|
|
7
|
+
burnRpcUrl?: string;
|
|
8
|
+
burnFetch?: typeof fetch;
|
|
5
9
|
port?: number;
|
|
6
10
|
host?: string;
|
|
7
11
|
/** Open to the internet: read-only overview and docs for visitors, full app only with the admin cookie. */
|
|
@@ -61,6 +65,19 @@ export declare const POST_ROUTES: Record<string, PostHandler>;
|
|
|
61
65
|
* and on the public domain points /app and /docs links at their subdomains.
|
|
62
66
|
*/
|
|
63
67
|
export declare function renderPage(html: string, domain: string | null): string;
|
|
68
|
+
export interface TokenInfo {
|
|
69
|
+
ca: string;
|
|
70
|
+
chain: string;
|
|
71
|
+
ticker: string;
|
|
72
|
+
explorer: string;
|
|
73
|
+
launchpad: string;
|
|
74
|
+
txBase: string;
|
|
75
|
+
deployBlock: number;
|
|
76
|
+
}
|
|
77
|
+
/** The burn section on /thetoken: total, share of supply and every burn with its time and transaction. */
|
|
78
|
+
export declare function burnBlock(b: BurnInfo | null, t: Partial<TokenInfo>): string;
|
|
79
|
+
/** The address block on /thetoken, from src/web/token.json. An empty address says no token is official yet. */
|
|
80
|
+
export declare function tokenBlock(t: Partial<TokenInfo>): string;
|
|
64
81
|
export declare function createWebServer(opts?: WebOptions): {
|
|
65
82
|
server: Server;
|
|
66
83
|
oculon: Oculon;
|
package/dist/web/server.js
CHANGED
|
@@ -23,6 +23,10 @@ import { addPersonal, confirmEmail, emailStatus, listPersonal, personalAlerts, r
|
|
|
23
23
|
import { mailEnabled } from '../sources/resend.js';
|
|
24
24
|
import { analyst, crossExamine, isAnalystModel } from '../analyst.js';
|
|
25
25
|
import { scrubSecrets } from '../core/keys.js';
|
|
26
|
+
import { readBurns, rpcClient } from './burns.js';
|
|
27
|
+
import { CHECK_ROUTES } from '../modules/checks.js';
|
|
28
|
+
import { llmsFull, llmsTxt, replayPage, statusPage } from './pages.js';
|
|
29
|
+
import { UTILITY, badgeSvg, createNonce, getInvestigation, holderFor, listInvestigations, runSafety, safetyState, signOutHolder, startInvestigation, startInvestigationHold, startSafety, startSafetyHold, tokenConfig, verifyHolder } from '../modules/utility.js';
|
|
26
30
|
/** Analyst questions and cross-examinations per visitor address per hour on a public install. */
|
|
27
31
|
const ANALYST_PER_HOUR = Number(process.env.OCULON_ANALYST_PER_HOUR ?? 40);
|
|
28
32
|
const analystHits = new Map();
|
|
@@ -276,6 +280,10 @@ export const ROUTES = {
|
|
|
276
280
|
},
|
|
277
281
|
'/api/breaches': async (q, o) => slim(await o.breaches((q.get('domain') ?? '').slice(0, 120))),
|
|
278
282
|
'/api/phone': async (q, o) => slim(await o.phoneCheck(need(q, 'number', 32), q.get('country') ? { country: q.get('country').slice(0, 2) } : {})),
|
|
283
|
+
'/api/iban': async (q, o) => slim(await o.ibanCheck(need(q, 'iban', 64), q.get('country') ? { country: q.get('country').slice(0, 2) } : {})),
|
|
284
|
+
'/api/lookalike': async (q, o) => slim(await o.lookalikes(need(q, 'domain', 120))),
|
|
285
|
+
'/api/honeypot': async (q, o) => slim(await o.honeypotCheck(need(q, 'address', 60), q.get('chain') ? { chain: q.get('chain').slice(0, 12) } : {})),
|
|
286
|
+
'/api/address': async (q, o) => slim(await o.addressCheck(need(q, 'address', 120), q.get('network') ? { network: q.get('network').slice(0, 20) } : {})),
|
|
279
287
|
'/api/satellites': async (q, o) => slim(await o.satellites((q.get('q') ?? '').slice(0, 60))),
|
|
280
288
|
'/api/papers': async (q, o) => slim(await o.papers(need(q, 'topic', 200), q.get('years') ? { years: Number(q.get('years')) || 3 } : {})),
|
|
281
289
|
'/api/country': async (q, o) => {
|
|
@@ -382,6 +390,13 @@ async function readJson(req, limit = 10_000) {
|
|
|
382
390
|
/** Writes that change what the whole install watches. */
|
|
383
391
|
const OWNER_ONLY = new Set(['/api/monitor', '/api/watch/delete', '/api/fences', '/api/fences/delete', '/api/cases']);
|
|
384
392
|
export const POST_ROUTES = {
|
|
393
|
+
// Raw email headers can be several kilobytes, too long for a query string.
|
|
394
|
+
'/api/headers': async (b, o) => {
|
|
395
|
+
const raw = String(b.headers ?? '');
|
|
396
|
+
if (!raw.trim())
|
|
397
|
+
throw new HttpError(400, 'missing headers');
|
|
398
|
+
return slim(await o.headerCheck(raw.slice(0, 100_000)));
|
|
399
|
+
},
|
|
385
400
|
'/api/fences': (b, o) => {
|
|
386
401
|
const box = Array.isArray(b.box) ? b.box.map(Number) : null;
|
|
387
402
|
if (!box || box.length !== 4)
|
|
@@ -516,12 +531,42 @@ export function renderPage(html, domain) {
|
|
|
516
531
|
.replace(/href="\/app(#[^"]*)?"/g, (_m, h) => `href="https://app.${domain}/${h ?? ''}"`)
|
|
517
532
|
.replace(/href="\/report"/g, `href="https://app.${domain}/report"`)
|
|
518
533
|
.replace(/href="\/ask"/g, `href="https://${domain}/ask"`)
|
|
534
|
+
.replace(/href="\/thetoken"/g, `href="https://${domain}/thetoken"`)
|
|
535
|
+
.replace(/href="\/utility"/g, `href="https://${domain}/utility"`)
|
|
519
536
|
.replace(/href="\/docs(?:#([^"]*))?"/g, (_m, h) => `href="https://docs.${domain}/${h ?? ''}"`)
|
|
520
537
|
.replace(/href="\/(privacy|terms)(#[^"]*)?"/g, (_m, p, h) => `href="${main}/${p}${h ?? ''}"`)
|
|
521
538
|
.replace(/href="\/"/g, `href="${main}/"`);
|
|
522
539
|
}
|
|
523
540
|
return out;
|
|
524
541
|
}
|
|
542
|
+
/** The burn section on /thetoken: total, share of supply and every burn with its time and transaction. */
|
|
543
|
+
export function burnBlock(b, t) {
|
|
544
|
+
if (!b)
|
|
545
|
+
return '';
|
|
546
|
+
const esc = (s) => s.replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]);
|
|
547
|
+
const base = /^https:\/\/[^\s"'<>]+$/.test(t.txBase ?? '') ? t.txBase.replace(/\/$/, '') : '';
|
|
548
|
+
const when = (iso) => `${iso.slice(0, 10)} ${iso.slice(11, 16)} UTC`;
|
|
549
|
+
const short = (tx) => `${tx.slice(0, 10)}…${tx.slice(-6)}`;
|
|
550
|
+
const rows = b.burns.map((x) => `<tr><td>${esc(when(x.time))}<br>${base ? `<a href="${esc(base)}/tx/${esc(x.tx)}" target="_blank" rel="noopener">${esc(short(x.tx))}</a>` : `<span>${esc(short(x.tx))}</span>`}</td><td class="n">${esc(x.amount)}</td></tr>`).join('');
|
|
551
|
+
return `<div class="burn"><div class="lbl">Burned</div><div class="btot"><span>${esc(b.total)}</span>${b.percent ? `<em>${esc(b.percent)} of supply</em>` : ''}</div>`
|
|
552
|
+
+ (rows ? `<div class="btable"><table><thead><tr><th>Time · transaction</th><th class="n">Amount</th></tr></thead><tbody>${rows}</tbody></table></div>` : '<p>No burns yet.</p>')
|
|
553
|
+
+ `<p class="bnote">Read live from the chain: transfers to the dead and zero addresses. Updated ${esc(when(b.checkedAt))}.</p></div>`;
|
|
554
|
+
}
|
|
555
|
+
/** The address block on /thetoken, from src/web/token.json. An empty address says no token is official yet. */
|
|
556
|
+
export function tokenBlock(t) {
|
|
557
|
+
const esc = (s) => s.replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]);
|
|
558
|
+
const ca = (t.ca ?? '').trim();
|
|
559
|
+
if (!ca)
|
|
560
|
+
return '<div class="ca none"><p>No official token address has been posted yet. Until it appears here, on X and on GitHub at the same time, any address claimed to be Oculon is not ours.</p></div>';
|
|
561
|
+
const safe = (u) => (/^https:\/\/[^\s"'<>]+$/.test(u ?? '') ? u : '');
|
|
562
|
+
const launchpad = safe(t.launchpad), explorer = safe(t.explorer);
|
|
563
|
+
// The third cell links to the launchpad page when there is one, otherwise to a block explorer.
|
|
564
|
+
const link = launchpad ? { k: 'Launchpad', u: launchpad, label: new URL(launchpad).hostname.replace(/^www\./, '') } : explorer ? { k: 'Explorer', u: explorer, label: 'view' } : null;
|
|
565
|
+
const cell = (k, v) => `<div><b>${k}</b><span>${v ? esc(v) : '-'}</span></div>`;
|
|
566
|
+
const badge = /^0x[0-9a-fA-F]{40}$/.test(ca) ? `<a class="sbadge" href="/safety/${esc(ca.toLowerCase())}" title="Live safety check of this token"><img src="/badge/${esc(ca.toLowerCase())}.svg" alt="Oculon safety badge" height="22"></a>` : '';
|
|
567
|
+
return `<div class="ca"><div class="lbl">Contract address</div><div class="addr"><code id="ca-value">${esc(ca)}</code><button id="copy-ca" type="button">COPY</button></div>${badge}`
|
|
568
|
+
+ `<div class="meta">${cell('Chain', (t.chain ?? '').trim())}${cell('Ticker', (t.ticker ?? '').trim() ? `$${(t.ticker ?? '').trim().replace(/^\$/, '')}` : '')}<div><b>${link ? link.k : 'Explorer'}</b><span>${link ? `<a href="${esc(link.u)}" target="_blank" rel="noopener">${esc(link.label)}</a>` : '-'}</span></div></div></div>`;
|
|
569
|
+
}
|
|
525
570
|
function send(res, status, body, type, cache = 'no-store') {
|
|
526
571
|
res.writeHead(status, {
|
|
527
572
|
'content-type': type,
|
|
@@ -532,6 +577,9 @@ function send(res, status, body, type, cache = 'no-store') {
|
|
|
532
577
|
});
|
|
533
578
|
res.end(body);
|
|
534
579
|
}
|
|
580
|
+
function siteDomainEarly(opts) {
|
|
581
|
+
return (opts.domain ?? process.env.OCULON_DOMAIN ?? '').trim().toLowerCase() || null;
|
|
582
|
+
}
|
|
535
583
|
export function createWebServer(opts = {}) {
|
|
536
584
|
const oculon = opts.oculon ?? new Oculon();
|
|
537
585
|
const log = opts.log ?? (() => { });
|
|
@@ -543,7 +591,8 @@ export function createWebServer(opts = {}) {
|
|
|
543
591
|
// OCULON_OPEN=1 opens the whole app to every visitor (no sign-in, no read-only gate, no rate limit).
|
|
544
592
|
const openApp = opts.open ?? process.env.OCULON_OPEN === '1';
|
|
545
593
|
// One MCP server for the HTTP transport, sharing this server's Oculon instance.
|
|
546
|
-
const
|
|
594
|
+
const appBase = siteDomainEarly(opts) ? `https://app.${siteDomainEarly(opts)}` : `http://127.0.0.1:${opts.port ?? 4747}`;
|
|
595
|
+
const mcpServer = new McpServer(() => oculon, { remote: publicMode, baseUrl: appBase });
|
|
547
596
|
// OCULON_PURGE_ONCHAIN=1 clears data left by the paused on-chain modules when the server starts.
|
|
548
597
|
if (!onchainEnabled() && process.env.OCULON_PURGE_ONCHAIN === '1') {
|
|
549
598
|
const removed = oculon.ctx.store.purgeOnchain();
|
|
@@ -554,6 +603,31 @@ export function createWebServer(opts = {}) {
|
|
|
554
603
|
// A Cloudflare Worker serves app.<domain> and docs.<domain> by forwarding to this server with the site name
|
|
555
604
|
// and the client address in headers. Those headers count only when they carry the shared edge secret.
|
|
556
605
|
const edgeSecret = (opts.edgeSecret ?? process.env.OCULON_EDGE_SECRET ?? '').trim() || null;
|
|
606
|
+
// Live safety badges: active monitors are re-checked about every 15 minutes.
|
|
607
|
+
const safetyTimer = setInterval(() => {
|
|
608
|
+
void runSafety(oculon).then((changes) => { for (const c of changes)
|
|
609
|
+
log(`safety badge ${c.token}: ${c.from ?? 'new'} -> ${c.to}`); }).catch(() => { });
|
|
610
|
+
}, 5 * 60_000);
|
|
611
|
+
safetyTimer.unref();
|
|
612
|
+
// Burns on /thetoken come from the chain RPC, cached for five minutes; a failed read keeps the last good one.
|
|
613
|
+
let burnCache = null;
|
|
614
|
+
const tokenBurns = async (t) => {
|
|
615
|
+
const url = opts.burnRpcUrl ?? process.env.ROBINHOOD_PUBLIC_RPC_URL?.trim();
|
|
616
|
+
if (!url || !/^0x[0-9a-fA-F]{40}$/.test(t.ca ?? '') || !t.deployBlock)
|
|
617
|
+
return null;
|
|
618
|
+
const key = `${t.ca}:${t.deployBlock}`;
|
|
619
|
+
if (burnCache && burnCache.key === key && Date.now() - burnCache.at < 300_000)
|
|
620
|
+
return burnCache.info;
|
|
621
|
+
try {
|
|
622
|
+
const info = await readBurns(rpcClient(url, opts.burnFetch), t.ca, t.deployBlock);
|
|
623
|
+
burnCache = { at: Date.now(), key, info };
|
|
624
|
+
return info;
|
|
625
|
+
}
|
|
626
|
+
catch (e) {
|
|
627
|
+
log(`token burns: ${e.message}`);
|
|
628
|
+
return burnCache?.key === key ? burnCache.info : null;
|
|
629
|
+
}
|
|
630
|
+
};
|
|
557
631
|
/** The page a browser sees on the MCP endpoint: the URL to add, client snippets and the tools this endpoint lists. */
|
|
558
632
|
const mcpPage = async (onPath) => {
|
|
559
633
|
const r = (await mcpServer.handle({ jsonrpc: '2.0', id: 0, method: 'tools/list' }));
|
|
@@ -658,6 +732,56 @@ export function createWebServer(opts = {}) {
|
|
|
658
732
|
const msg = url.pathname === '/mail/confirm' ? (ok ? 'Alerts confirmed. You will get an email when one of your monitors finds a change.' : 'This confirmation link is no longer valid.') : ok ? 'You are unsubscribed. No more monitor emails will be sent.' : 'This address was already unsubscribed.';
|
|
659
733
|
return send(res, 200, `<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Oculon alerts</title><body style="margin:0;background:#000;color:#f2f2f2;font-family:system-ui,sans-serif;display:grid;place-items:center;min-height:100vh;padding:16px"><div style="max-width:460px"><p style="font:600 12px monospace;letter-spacing:.2em;color:#00f0ff"><img src="/assets/logo.svg" alt="" width="18" height="18" style="vertical-align:-4px;margin-right:10px">OCULON</p><h1 style="font-weight:500">${msg}</h1><p><a style="color:#00f0ff" href="${siteDomain ? `https://app.${siteDomain}/#watch` : '/app#watch'}">Open your monitors →</a></p></div></body>`, 'text/html; charset=utf-8');
|
|
660
734
|
}
|
|
735
|
+
// $OCULON utility: burn-to-investigate, live safety badges and the holder tier (see modules/utility.ts).
|
|
736
|
+
const badge = /^\/badge\/(0x[0-9a-fA-F]{40})\.svg$/.exec(url.pathname)?.[1];
|
|
737
|
+
if (badge && req.method === 'GET')
|
|
738
|
+
return send(res, 200, badgeSvg(safetyState(oculon.ctx, badge)), 'image/svg+xml; charset=utf-8', 'public, max-age=300');
|
|
739
|
+
if ((/^\/utility\/?$/.test(url.pathname) || /^\/investigation\/[0-9a-f]{12}$/.test(url.pathname) || /^\/safety\/0x[0-9a-fA-F]{40}$/.test(url.pathname)) && req.method === 'GET' && hostName.split('.')[0] !== 'docs') {
|
|
740
|
+
return send(res, 200, renderPage(readFileSync(join(HERE, 'utility.html'), 'utf8'), siteDomain && hostName.endsWith(siteDomain) ? siteDomain : null), 'text/html; charset=utf-8');
|
|
741
|
+
}
|
|
742
|
+
if (url.pathname.startsWith('/api/utility/')) {
|
|
743
|
+
if (!admin)
|
|
744
|
+
return send(res, 403, '{"error":"not available on this install"}', 'application/json');
|
|
745
|
+
if (req.method === 'POST' && !sameSite())
|
|
746
|
+
return send(res, 403, '{"error":"forbidden"}', 'application/json');
|
|
747
|
+
const owner = `web:${visitor()}`;
|
|
748
|
+
const json = (v, status = 200) => send(res, status, JSON.stringify(v), 'application/json; charset=utf-8');
|
|
749
|
+
try {
|
|
750
|
+
if (req.method === 'GET') {
|
|
751
|
+
if (url.pathname === '/api/utility/info')
|
|
752
|
+
return json({ token: tokenConfig(), amounts: { investigate: UTILITY.investigate.toString(), safety: UTILITY.safety.toString(), holdInvestigate: UTILITY.holdInvestigate.toString(), holdSafety: UTILITY.holdSafety.toString(), holder: UTILITY.holder.toString() }, safetyDays: UTILITY.safetyDays, holderMonitors: UTILITY.holderMonitors, holder: holderFor(oculon.ctx, owner), investigations: listInvestigations(oculon.ctx, 12) });
|
|
753
|
+
if (url.pathname === '/api/utility/investigation') {
|
|
754
|
+
const v = getInvestigation(oculon.ctx, url.searchParams.get('id') ?? '');
|
|
755
|
+
return v ? json(v) : json({ error: 'no such investigation' }, 404);
|
|
756
|
+
}
|
|
757
|
+
if (url.pathname === '/api/utility/safety') {
|
|
758
|
+
const t = url.searchParams.get('token') ?? '';
|
|
759
|
+
if (!/^0x[0-9a-fA-F]{40}$/.test(t))
|
|
760
|
+
throw new HttpError(400, 'give a token address');
|
|
761
|
+
return json(safetyState(oculon.ctx, t));
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
if (req.method === 'POST') {
|
|
765
|
+
const b = await readJson(req);
|
|
766
|
+
if (url.pathname === '/api/utility/nonce')
|
|
767
|
+
return json(createNonce(siteDomain ?? hostName, String(b.address ?? '')));
|
|
768
|
+
if (url.pathname === '/api/utility/holder')
|
|
769
|
+
return json(await verifyHolder(oculon.ctx, owner, String(b.message ?? ''), String(b.signature ?? '')));
|
|
770
|
+
if (url.pathname === '/api/utility/signout') {
|
|
771
|
+
signOutHolder(oculon.ctx, owner);
|
|
772
|
+
return json({ ok: true });
|
|
773
|
+
}
|
|
774
|
+
if (url.pathname === '/api/utility/investigate')
|
|
775
|
+
return json(b.mode === 'hold' ? await startInvestigationHold(oculon, String(b.target ?? ''), String(b.address ?? ''), String(b.nonce ?? ''), String(b.signature ?? '')) : await startInvestigation(oculon, String(b.tx ?? ''), String(b.target ?? ''), String(b.signature ?? '')));
|
|
776
|
+
if (url.pathname === '/api/utility/safety')
|
|
777
|
+
return json(b.mode === 'hold' ? await startSafetyHold(oculon, String(b.token ?? ''), String(b.address ?? ''), String(b.nonce ?? ''), String(b.signature ?? '')) : await startSafety(oculon, String(b.tx ?? ''), String(b.token ?? ''), String(b.signature ?? '')));
|
|
778
|
+
}
|
|
779
|
+
return json({ error: 'not found' }, 404);
|
|
780
|
+
}
|
|
781
|
+
catch (e) {
|
|
782
|
+
return json({ error: e.message }, e instanceof HttpError ? e.status : 400);
|
|
783
|
+
}
|
|
784
|
+
}
|
|
661
785
|
if (url.pathname === '/api/my' || url.pathname.startsWith('/api/my/')) {
|
|
662
786
|
if (!admin)
|
|
663
787
|
return send(res, 403, '{"error":"not available on this install"}', 'application/json');
|
|
@@ -666,14 +790,14 @@ export function createWebServer(opts = {}) {
|
|
|
666
790
|
const owner = `web:${visitor()}`;
|
|
667
791
|
try {
|
|
668
792
|
if (req.method === 'GET' && url.pathname === '/api/my')
|
|
669
|
-
return send(res, 200, JSON.stringify({ monitors: listPersonal(oculon.ctx, owner), alerts: personalAlerts(oculon.ctx, owner, 40), email: emailStatus(oculon.ctx, owner), mail: mailEnabled(), owner: !publicMode || isAdmin(req, adminToken) }), 'application/json; charset=utf-8');
|
|
793
|
+
return send(res, 200, JSON.stringify({ monitors: listPersonal(oculon.ctx, owner), alerts: personalAlerts(oculon.ctx, owner, 40), email: emailStatus(oculon.ctx, owner), mail: mailEnabled(), owner: !publicMode || isAdmin(req, adminToken), holder: holderFor(oculon.ctx, owner) }), 'application/json; charset=utf-8');
|
|
670
794
|
if (req.method === 'POST') {
|
|
671
795
|
const b = await readJson(req);
|
|
672
796
|
if (url.pathname === '/api/my/monitors') {
|
|
673
797
|
const text = String(b.text ?? '').trim();
|
|
674
798
|
if (text.length < 4 || text.length > 300)
|
|
675
799
|
throw new HttpError(400, 'describe what to watch in 4-300 characters');
|
|
676
|
-
return send(res, 200, JSON.stringify(await addPersonal(oculon.ctx, owner, text)), 'application/json; charset=utf-8');
|
|
800
|
+
return send(res, 200, JSON.stringify(await addPersonal(oculon.ctx, owner, text, holderFor(oculon.ctx, owner) ? UTILITY.holderMonitors : undefined)), 'application/json; charset=utf-8');
|
|
677
801
|
}
|
|
678
802
|
if (url.pathname === '/api/my/monitors/delete')
|
|
679
803
|
return send(res, 200, JSON.stringify({ removed: removePersonal(oculon.ctx, owner, Number(b.id)) }), 'application/json');
|
|
@@ -745,6 +869,28 @@ export function createWebServer(opts = {}) {
|
|
|
745
869
|
if (req.method === 'POST' && OWNER_ONLY.has(url.pathname) && !owner) {
|
|
746
870
|
return send(res, 403, '{"error":"the shared watchlist is managed by the owner; add your own monitors instead"}', 'application/json');
|
|
747
871
|
}
|
|
872
|
+
if (url.pathname === '/api/doc' && req.method === 'POST') {
|
|
873
|
+
if (!sameSite())
|
|
874
|
+
return send(res, 403, '{"error":"forbidden"}', 'application/json');
|
|
875
|
+
const ip = (viaEdge && String(req.headers['x-oculon-client-ip'] ?? '').trim()) || clientIp(req);
|
|
876
|
+
if (publicMode && !isAdmin(req, adminToken) && !analystLimit(ip))
|
|
877
|
+
return send(res, 429, '{"error":"You have checked a lot this hour. Try again a bit later."}', 'application/json');
|
|
878
|
+
try {
|
|
879
|
+
const b = await readJson(req, 15_000_000);
|
|
880
|
+
const b64 = String(b.data ?? '').replace(/^data:[^;]+;base64,/, '');
|
|
881
|
+
if (!b64)
|
|
882
|
+
throw new HttpError(400, 'choose a file first');
|
|
883
|
+
const file = Buffer.from(b64, 'base64');
|
|
884
|
+
const name = String(b.name ?? 'document').slice(0, 120);
|
|
885
|
+
const { createHash } = await import('node:crypto');
|
|
886
|
+
const r = await oculon.recordCheck('doc', createHash('sha256').update(file).digest('hex'), () => oculon.docCheck(file, name), { label: name });
|
|
887
|
+
log('POST /api/doc');
|
|
888
|
+
return send(res, 200, JSON.stringify({ ...slim(r.value), check: r.check }), 'application/json; charset=utf-8');
|
|
889
|
+
}
|
|
890
|
+
catch (e) {
|
|
891
|
+
return send(res, e instanceof HttpError ? e.status : 400, JSON.stringify({ error: e.message }), 'application/json; charset=utf-8');
|
|
892
|
+
}
|
|
893
|
+
}
|
|
748
894
|
if (req.method === 'POST' && POST_ROUTES[url.pathname]) {
|
|
749
895
|
// Writes only from this dashboard: a custom header (forces a CORS preflight that this server never
|
|
750
896
|
// grants), a JSON body, and a same-host Origin when the browser sends one.
|
|
@@ -761,8 +907,10 @@ export function createWebServer(opts = {}) {
|
|
|
761
907
|
return send(res, 403, '{"error":"forbidden"}', 'application/json');
|
|
762
908
|
}
|
|
763
909
|
try {
|
|
764
|
-
const body = await readJson(req);
|
|
765
|
-
const out =
|
|
910
|
+
const body = await readJson(req, url.pathname === '/api/headers' ? 200_000 : undefined);
|
|
911
|
+
const out = url.pathname === '/api/headers'
|
|
912
|
+
? await oculon.recordCheck('headers', String(body.headers ?? ''), async () => POST_ROUTES[url.pathname](body, oculon), { label: `email headers: ${(/^subject:\s*(.+)$/im.exec(String(body.headers ?? ''))?.[1] ?? 'pasted').slice(0, 70)}` }).then((r) => ({ ...r.value, check: r.check }))
|
|
913
|
+
: await POST_ROUTES[url.pathname](body, oculon);
|
|
766
914
|
log(`POST ${url.pathname}`);
|
|
767
915
|
return send(res, 200, JSON.stringify(out), 'application/json; charset=utf-8');
|
|
768
916
|
}
|
|
@@ -772,6 +920,46 @@ export function createWebServer(opts = {}) {
|
|
|
772
920
|
}
|
|
773
921
|
if (req.method !== 'GET')
|
|
774
922
|
return send(res, 405, '{"error":"method not allowed"}', 'application/json');
|
|
923
|
+
{
|
|
924
|
+
const base = siteDomain ? `https://app.${siteDomain}` : `http://${req.headers.host ?? '127.0.0.1'}`;
|
|
925
|
+
if (url.pathname === '/llms.txt' || url.pathname === '/llms-full.txt') {
|
|
926
|
+
const r = (await mcpServer.handle({ jsonrpc: '2.0', id: 0, method: 'tools/list' }));
|
|
927
|
+
const tools = r?.result?.tools ?? [];
|
|
928
|
+
const mcpUrl = siteDomain ? `https://mcp.${siteDomain}` : `${base}/mcp`;
|
|
929
|
+
res.setHeader('access-control-allow-origin', '*');
|
|
930
|
+
return send(res, 200, url.pathname === '/llms.txt' ? llmsTxt(tools, base, mcpUrl) : llmsFull(tools, base, mcpUrl), 'text/plain; charset=utf-8', 'public, max-age=3600');
|
|
931
|
+
}
|
|
932
|
+
if (url.pathname === '/status' || url.pathname === '/status/') {
|
|
933
|
+
const hours = Math.min(48, Number(url.searchParams.get('hours') ?? 24) || 24);
|
|
934
|
+
return send(res, 200, statusPage(oculon.sourceStatus(hours), base, hours), 'text/html; charset=utf-8', 'no-cache');
|
|
935
|
+
}
|
|
936
|
+
if (url.pathname === '/api/status') {
|
|
937
|
+
const hours = Math.min(48, Number(url.searchParams.get('hours') ?? 24) || 24);
|
|
938
|
+
res.setHeader('access-control-allow-origin', '*');
|
|
939
|
+
return send(res, 200, JSON.stringify({ hours, sources: oculon.sourceStatus(hours) }), 'application/json; charset=utf-8');
|
|
940
|
+
}
|
|
941
|
+
const replayId = /^\/replay\/([A-Za-z0-9_-]{10,40})\/?$/.exec(url.pathname)?.[1];
|
|
942
|
+
if (replayId) {
|
|
943
|
+
const c = oculon.check(replayId);
|
|
944
|
+
if (!c)
|
|
945
|
+
return send(res, 404, '<!doctype html><meta charset="utf-8"><title>Not found</title><body style="background:#000;color:#ccc;font-family:system-ui;padding:40px"><p>This check does not exist, or it is older than 90 days.</p>', 'text/html; charset=utf-8');
|
|
946
|
+
return send(res, 200, replayPage(c, oculon.checkHistory(replayId), base), 'text/html; charset=utf-8', 'private, max-age=60');
|
|
947
|
+
}
|
|
948
|
+
if (url.pathname === '/api/check') {
|
|
949
|
+
const c = oculon.check(url.searchParams.get('id') ?? '');
|
|
950
|
+
if (!c)
|
|
951
|
+
return send(res, 404, '{"error":"no such check"}', 'application/json');
|
|
952
|
+
return send(res, 200, JSON.stringify({ ...c, history: oculon.checkHistory(c.id) }), 'application/json; charset=utf-8');
|
|
953
|
+
}
|
|
954
|
+
const reportId = /^\/report\/([A-Za-z0-9_-]{10,40})\.pdf$/.exec(url.pathname)?.[1];
|
|
955
|
+
if (reportId) {
|
|
956
|
+
const pdf = oculon.checkPdf(reportId, base);
|
|
957
|
+
if (!pdf)
|
|
958
|
+
return send(res, 404, '{"error":"no such check"}', 'application/json');
|
|
959
|
+
res.writeHead(200, { 'content-type': 'application/pdf', 'content-disposition': `inline; filename="oculon-${reportId.slice(0, 8)}.pdf"`, 'cache-control': 'private, max-age=300', 'x-content-type-options': 'nosniff' });
|
|
960
|
+
return void res.end(pdf);
|
|
961
|
+
}
|
|
962
|
+
}
|
|
775
963
|
if (url.pathname === '/openapi.json') {
|
|
776
964
|
res.setHeader('access-control-allow-origin', '*');
|
|
777
965
|
return send(res, 200, JSON.stringify(openApiSpec(siteDomain ? `https://app.${siteDomain}` : `http://${req.headers.host ?? '127.0.0.1'}`), null, 2), 'application/json; charset=utf-8', 'public, max-age=3600');
|
|
@@ -803,7 +991,7 @@ export function createWebServer(opts = {}) {
|
|
|
803
991
|
const sub = hostName.split('.')[0];
|
|
804
992
|
// Docs sections have their own addresses: docs.<domain>/install, or /docs/install on a single host.
|
|
805
993
|
const docsSection = (sub === 'docs' ? /^\/([a-z0-9][a-z0-9-]{0,60})\/?$/ : /^\/docs\/([a-z0-9][a-z0-9-]{0,60})\/?$/).exec(url.pathname)?.[1];
|
|
806
|
-
if (docsSection && !['api', 'assets', 'app', 'report', 'r', 'proof', 'ask'].includes(docsSection)) {
|
|
994
|
+
if (docsSection && !['api', 'assets', 'app', 'report', 'r', 'proof', 'ask', 'thetoken'].includes(docsSection)) {
|
|
807
995
|
if (siteDomain && sub !== 'docs') {
|
|
808
996
|
res.writeHead(301, { location: `https://docs.${siteDomain}/${docsSection}${url.search}`, 'cache-control': 'no-store' });
|
|
809
997
|
return res.end();
|
|
@@ -819,6 +1007,15 @@ export function createWebServer(opts = {}) {
|
|
|
819
1007
|
}
|
|
820
1008
|
return send(res, 200, renderPage(readFileSync(join(HERE, PAGE_FILES[page]), 'utf8'), siteDomain && hostName.endsWith(siteDomain) ? siteDomain : null), 'text/html; charset=utf-8');
|
|
821
1009
|
}
|
|
1010
|
+
if (/^\/thetoken\/?$/.test(url.pathname) && sub !== 'docs') {
|
|
1011
|
+
let info = {};
|
|
1012
|
+
try {
|
|
1013
|
+
info = JSON.parse(readFileSync(join(HERE, 'token.json'), 'utf8'));
|
|
1014
|
+
}
|
|
1015
|
+
catch { /* no file: nothing official */ }
|
|
1016
|
+
const html = readFileSync(join(HERE, 'token.html'), 'utf8').replace('{{TOKEN_BLOCK}}', tokenBlock(info) + burnBlock(await tokenBurns(info), info));
|
|
1017
|
+
return send(res, 200, renderPage(html, siteDomain && hostName.endsWith(siteDomain) ? siteDomain : null), 'text/html; charset=utf-8');
|
|
1018
|
+
}
|
|
822
1019
|
if (url.pathname === '/manifest.webmanifest')
|
|
823
1020
|
return send(res, 200, readFileSync(join(HERE, 'manifest.webmanifest'), 'utf8'), 'application/manifest+json; charset=utf-8', 'no-cache');
|
|
824
1021
|
if (url.pathname === '/sw.js')
|
|
@@ -861,7 +1058,10 @@ export function createWebServer(opts = {}) {
|
|
|
861
1058
|
try {
|
|
862
1059
|
if (!onchainEnabled() && ONCHAIN_ROUTES.has(url.pathname))
|
|
863
1060
|
return send(res, 404, '{"error":"on-chain features are paused"}', 'application/json');
|
|
864
|
-
|
|
1061
|
+
const ck = CHECK_ROUTES[url.pathname];
|
|
1062
|
+
let out = ck && url.searchParams.get(ck.param)?.trim()
|
|
1063
|
+
? await oculon.recordCheck(ck.kind, url.searchParams.get(ck.param).trim(), async () => route(url.searchParams, oculon)).then((r) => (r.value && typeof r.value === 'object' ? { ...r.value, check: r.check } : r.value))
|
|
1064
|
+
: await route(url.searchParams, oculon);
|
|
865
1065
|
if (!onchainEnabled())
|
|
866
1066
|
out = withoutOnchain(url.pathname, out);
|
|
867
1067
|
if (!admin && url.pathname === '/api/signals')
|