konoha-mcp 2.1.16 → 2.1.17
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/.agents/SOUL.md +1 -1
- package/.agents/skills/konoha/SKILL.md +30 -1
- package/.agents/skills.fingerprint +1 -1
- package/README.md +186 -219
- package/apps/web/build/adapter-node.js +1 -1
- package/apps/web/build/client/_app/immutable/assets/0.BGEsEaMd.css +2 -0
- package/apps/web/build/client/_app/immutable/assets/0.BGEsEaMd.css.br +0 -0
- package/apps/web/build/client/_app/immutable/assets/0.BGEsEaMd.css.gz +0 -0
- package/apps/web/build/client/_app/immutable/chunks/{D-Kujhko.js → 2WlqNq2Q.js} +1 -1
- package/apps/web/build/client/_app/immutable/chunks/2WlqNq2Q.js.br +0 -0
- package/apps/web/build/client/_app/immutable/chunks/2WlqNq2Q.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/chunks/B9vY64pH.js +1 -0
- package/apps/web/build/client/_app/immutable/chunks/B9vY64pH.js.br +0 -0
- package/apps/web/build/client/_app/immutable/chunks/B9vY64pH.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/chunks/{Dzm74gVd.js → BPX4jQ9l.js} +1 -1
- package/apps/web/build/client/_app/immutable/chunks/BPX4jQ9l.js.br +2 -0
- package/apps/web/build/client/_app/immutable/chunks/BPX4jQ9l.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/chunks/{fbrtLByB.js → BXssplIZ.js} +1 -1
- package/apps/web/build/client/_app/immutable/chunks/BXssplIZ.js.br +0 -0
- package/apps/web/build/client/_app/immutable/chunks/BXssplIZ.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/chunks/C-3vSv0T.js +1 -0
- package/apps/web/build/client/_app/immutable/chunks/C-3vSv0T.js.br +2 -0
- package/apps/web/build/client/_app/immutable/chunks/C-3vSv0T.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/chunks/{PrdhfbrQ.js → C7jhkUmC.js} +1 -1
- package/apps/web/build/client/_app/immutable/chunks/C7jhkUmC.js.br +0 -0
- package/apps/web/build/client/_app/immutable/chunks/{PrdhfbrQ.js.gz → C7jhkUmC.js.gz} +0 -0
- package/apps/web/build/client/_app/immutable/chunks/{7LmsTWIo.js → CfrhQlXt.js} +1 -1
- package/apps/web/build/client/_app/immutable/chunks/CfrhQlXt.js.br +0 -0
- package/apps/web/build/client/_app/immutable/chunks/CfrhQlXt.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/chunks/CgzsRqh3.js +1 -0
- package/apps/web/build/client/_app/immutable/chunks/CgzsRqh3.js.br +1 -0
- package/apps/web/build/client/_app/immutable/chunks/CgzsRqh3.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/chunks/ChmznE4L.js +2 -0
- package/apps/web/build/client/_app/immutable/chunks/ChmznE4L.js.br +0 -0
- package/apps/web/build/client/_app/immutable/chunks/ChmznE4L.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/entry/app.cdLMQHsN.js +2 -0
- package/apps/web/build/client/_app/immutable/entry/app.cdLMQHsN.js.br +0 -0
- package/apps/web/build/client/_app/immutable/entry/app.cdLMQHsN.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/entry/{start.CNV5BTCO.js → start.CJ1ccVCA.js} +2 -2
- package/apps/web/build/client/_app/immutable/entry/start.CJ1ccVCA.js.br +0 -0
- package/apps/web/build/client/_app/immutable/entry/start.CJ1ccVCA.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/0.ijG9ltjt.js +2 -0
- package/apps/web/build/client/_app/immutable/nodes/0.ijG9ltjt.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/0.ijG9ltjt.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/1.i6MXc2Yb.js +1 -0
- package/apps/web/build/client/_app/immutable/nodes/1.i6MXc2Yb.js.br +2 -0
- package/apps/web/build/client/_app/immutable/nodes/1.i6MXc2Yb.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/10.B0F7UoZ4.js +1 -0
- package/apps/web/build/client/_app/immutable/nodes/10.B0F7UoZ4.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/10.B0F7UoZ4.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/{11.4dBWH00t.js → 11.BuH1S-Sa.js} +2 -2
- package/apps/web/build/client/_app/immutable/nodes/11.BuH1S-Sa.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/11.BuH1S-Sa.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/12.DVFmb_G-.js +1 -0
- package/apps/web/build/client/_app/immutable/nodes/12.DVFmb_G-.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/12.DVFmb_G-.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/13.0PJQyjqs.js +1 -0
- package/apps/web/build/client/_app/immutable/nodes/13.0PJQyjqs.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/13.0PJQyjqs.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/14.ljEGDzwO.js +3 -0
- package/apps/web/build/client/_app/immutable/nodes/14.ljEGDzwO.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/14.ljEGDzwO.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/15.DpXDNTPX.js +1 -0
- package/apps/web/build/client/_app/immutable/nodes/15.DpXDNTPX.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/15.DpXDNTPX.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/16.qIEBxyps.js +17 -0
- package/apps/web/build/client/_app/immutable/nodes/16.qIEBxyps.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/16.qIEBxyps.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/17.CmVvQa7x.js +1 -0
- package/apps/web/build/client/_app/immutable/nodes/17.CmVvQa7x.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/17.CmVvQa7x.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/{2.Dr646Vs5.js → 2.lx602Ou_.js} +1 -1
- package/apps/web/build/client/_app/immutable/nodes/2.lx602Ou_.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/2.lx602Ou_.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/3.B-axtlUy.js +1 -0
- package/apps/web/build/client/_app/immutable/nodes/3.B-axtlUy.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/3.B-axtlUy.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/4.Cp9WmMgk.js +1 -0
- package/apps/web/build/client/_app/immutable/nodes/4.Cp9WmMgk.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/4.Cp9WmMgk.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/5.CQxJe2vk.js +1 -0
- package/apps/web/build/client/_app/immutable/nodes/5.CQxJe2vk.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/5.CQxJe2vk.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/6.5S6pozqG.js +1 -0
- package/apps/web/build/client/_app/immutable/nodes/6.5S6pozqG.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/6.5S6pozqG.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/{7.CmbiPMU3.js → 7.B5ZeCLvS.js} +1 -1
- package/apps/web/build/client/_app/immutable/nodes/7.B5ZeCLvS.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/7.B5ZeCLvS.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/8.M3fxLxa9.js +1 -0
- package/apps/web/build/client/_app/immutable/nodes/8.M3fxLxa9.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/8.M3fxLxa9.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/9.CYkQmFMJ.js +21 -0
- package/apps/web/build/client/_app/immutable/nodes/9.CYkQmFMJ.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/9.CYkQmFMJ.js.gz +0 -0
- package/apps/web/build/client/_app/version.json +1 -1
- package/apps/web/build/client/_app/version.json.br +0 -0
- package/apps/web/build/client/_app/version.json.gz +0 -0
- package/apps/web/build/server/.vite/manifest.json +15 -1
- package/apps/web/build/server/_app/immutable/assets/_layout.BGEsEaMd.css +2 -0
- package/apps/web/build/server/chunks/api.js +4 -0
- package/apps/web/build/server/chunks/api.js.map +1 -1
- package/apps/web/build/server/chunks/instance.js +3 -3
- package/apps/web/build/server/chunks/internal.js +1 -1
- package/apps/web/build/server/entries/pages/_layout.svelte.js +7 -0
- package/apps/web/build/server/entries/pages/_layout.svelte.js.map +1 -1
- package/apps/web/build/server/entries/pages/agents/_page.svelte.js +6 -2
- package/apps/web/build/server/entries/pages/agents/_page.svelte.js.map +1 -1
- package/apps/web/build/server/entries/pages/docs/_page.svelte.js +86 -2
- package/apps/web/build/server/entries/pages/docs/_page.svelte.js.map +1 -1
- package/apps/web/build/server/entries/pages/remote/_page.svelte.js +73 -0
- package/apps/web/build/server/entries/pages/remote/_page.svelte.js.map +1 -0
- package/apps/web/build/server/manifest-full.js +15 -7
- package/apps/web/build/server/manifest.js +15 -7
- package/apps/web/build/server/nodes/0.js +2 -2
- package/apps/web/build/server/nodes/1.js +1 -1
- package/apps/web/build/server/nodes/10.js +1 -1
- package/apps/web/build/server/nodes/11.js +1 -1
- package/apps/web/build/server/nodes/12.js +2 -2
- package/apps/web/build/server/nodes/13.js +2 -2
- package/apps/web/build/server/nodes/14.js +2 -2
- package/apps/web/build/server/nodes/15.js +2 -2
- package/apps/web/build/server/nodes/16.js +2 -2
- package/apps/web/build/server/nodes/17.js +8 -0
- package/apps/web/build/server/nodes/2.js +1 -1
- package/apps/web/build/server/nodes/3.js +1 -1
- package/apps/web/build/server/nodes/4.js +1 -1
- package/apps/web/build/server/nodes/5.js +1 -1
- package/apps/web/build/server/nodes/6.js +1 -1
- package/apps/web/build/server/nodes/7.js +1 -1
- package/apps/web/build/server/nodes/8.js +1 -1
- package/apps/web/build/server/nodes/9.js +1 -1
- package/apps/web/build/server/server.js +15 -7
- package/apps/web/package.json +1 -1
- package/bin/cli.js +397 -33
- package/docs/ALL-WORKFLOW-DIAGRAMS.md +135 -0
- package/docs/ARCHITECTURE.md +23 -1
- package/docs/BENCHMARK.md +53 -33
- package/docs/CLOUDFLARE_TUNNEL_GUIDE.md +119 -0
- package/docs/SecurityCompliance/security_compliance_report_google_policy_2.1.17_2026-10-08.md +87 -0
- package/docs/TELEGRAM_INTEGRATION_GUIDE.md +146 -0
- package/docs/diagrams/README.md +6 -2
- package/docs/diagrams/konoha-architecture.drawio +121 -0
- package/docs/diagrams/konoha-enterprise-architecture.drawio +121 -0
- package/package.json +1 -1
- package/src/agent_manager.js +75 -8
- package/src/crypto_vault.js +157 -0
- package/src/db.js +186 -65
- package/src/db_agents.js +1 -1
- package/src/mcp/memory_reporting.js +19 -0
- package/src/mcp/skills.js +17 -15
- package/src/mcp/workflow.js +38 -0
- package/src/migrate.js +74 -6
- package/src/persona_memory.js +1 -1
- package/src/prompt_hook.js +40 -1
- package/src/queue/inbox.js +243 -0
- package/src/queue/worker.js +413 -0
- package/src/telegram/config.js +101 -0
- package/src/telegram/notifier.js +359 -0
- package/src/telegram/poller.js +548 -0
- package/src/telegram/session_manager.js +583 -0
- package/src/templates/SOUL.md +1 -1
- package/src/templates/skills/konoha/SKILL.md +30 -1
- package/src/tunnel/config.js +89 -0
- package/src/tunnel/manager.js +216 -0
- package/src/tunnel/security.js +225 -0
- package/src/vector_search.js +21 -11
- package/src/web_server.js +358 -10
- package/apps/web/build/client/_app/immutable/assets/0.Ch0v37a-.css +0 -2
- package/apps/web/build/client/_app/immutable/assets/0.Ch0v37a-.css.br +0 -0
- package/apps/web/build/client/_app/immutable/assets/0.Ch0v37a-.css.gz +0 -0
- package/apps/web/build/client/_app/immutable/chunks/7LmsTWIo.js.br +0 -0
- package/apps/web/build/client/_app/immutable/chunks/7LmsTWIo.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/chunks/BH86Md_X.js +0 -1
- package/apps/web/build/client/_app/immutable/chunks/BH86Md_X.js.br +0 -2
- package/apps/web/build/client/_app/immutable/chunks/BH86Md_X.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/chunks/C3-t9btS.js +0 -1
- package/apps/web/build/client/_app/immutable/chunks/C3-t9btS.js.br +0 -1
- package/apps/web/build/client/_app/immutable/chunks/C3-t9btS.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/chunks/CBY268r4.js +0 -1
- package/apps/web/build/client/_app/immutable/chunks/CBY268r4.js.br +0 -3
- package/apps/web/build/client/_app/immutable/chunks/CBY268r4.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/chunks/D-Kujhko.js.br +0 -0
- package/apps/web/build/client/_app/immutable/chunks/D-Kujhko.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/chunks/Dzm74gVd.js.br +0 -0
- package/apps/web/build/client/_app/immutable/chunks/Dzm74gVd.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/chunks/Lb3VuXoN.js +0 -2
- package/apps/web/build/client/_app/immutable/chunks/Lb3VuXoN.js.br +0 -0
- package/apps/web/build/client/_app/immutable/chunks/Lb3VuXoN.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/chunks/PrdhfbrQ.js.br +0 -0
- package/apps/web/build/client/_app/immutable/chunks/fbrtLByB.js.br +0 -0
- package/apps/web/build/client/_app/immutable/chunks/fbrtLByB.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/entry/app.BeU4olDP.js +0 -2
- package/apps/web/build/client/_app/immutable/entry/app.BeU4olDP.js.br +0 -0
- package/apps/web/build/client/_app/immutable/entry/app.BeU4olDP.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/entry/start.CNV5BTCO.js.br +0 -0
- package/apps/web/build/client/_app/immutable/entry/start.CNV5BTCO.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/0.CdOP7y9P.js +0 -2
- package/apps/web/build/client/_app/immutable/nodes/0.CdOP7y9P.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/0.CdOP7y9P.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/1.BZu6jsAH.js +0 -1
- package/apps/web/build/client/_app/immutable/nodes/1.BZu6jsAH.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/1.BZu6jsAH.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/10.CZKScTFN.js +0 -1
- package/apps/web/build/client/_app/immutable/nodes/10.CZKScTFN.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/10.CZKScTFN.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/11.4dBWH00t.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/11.4dBWH00t.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/12.CSShcv5z.js +0 -1
- package/apps/web/build/client/_app/immutable/nodes/12.CSShcv5z.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/12.CSShcv5z.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/13.jWUWoBcs.js +0 -3
- package/apps/web/build/client/_app/immutable/nodes/13.jWUWoBcs.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/13.jWUWoBcs.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/14.H-jSqqen.js +0 -1
- package/apps/web/build/client/_app/immutable/nodes/14.H-jSqqen.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/14.H-jSqqen.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/15.CpAoyhzV.js +0 -17
- package/apps/web/build/client/_app/immutable/nodes/15.CpAoyhzV.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/15.CpAoyhzV.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/16.DT_-MxCT.js +0 -1
- package/apps/web/build/client/_app/immutable/nodes/16.DT_-MxCT.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/16.DT_-MxCT.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/2.Dr646Vs5.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/2.Dr646Vs5.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/3.Cgc-xN3x.js +0 -1
- package/apps/web/build/client/_app/immutable/nodes/3.Cgc-xN3x.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/3.Cgc-xN3x.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/4.CYJQ4bWz.js +0 -1
- package/apps/web/build/client/_app/immutable/nodes/4.CYJQ4bWz.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/4.CYJQ4bWz.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/5.DbHL-3Es.js +0 -1
- package/apps/web/build/client/_app/immutable/nodes/5.DbHL-3Es.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/5.DbHL-3Es.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/6.BvWH2qas.js +0 -1
- package/apps/web/build/client/_app/immutable/nodes/6.BvWH2qas.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/6.BvWH2qas.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/7.CmbiPMU3.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/7.CmbiPMU3.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/8.B9897Zm9.js +0 -1
- package/apps/web/build/client/_app/immutable/nodes/8.B9897Zm9.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/8.B9897Zm9.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/9.CGMmeMVC.js +0 -14
- package/apps/web/build/client/_app/immutable/nodes/9.CGMmeMVC.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/9.CGMmeMVC.js.gz +0 -0
- package/apps/web/build/server/_app/immutable/assets/_layout.Ch0v37a-.css +0 -2
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public Tunnel Configuration Manager.
|
|
3
|
+
* Reads and persists settings to SQLite table tunnel_config.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
const dbModule = require('../db');
|
|
9
|
+
const vault = require('../crypto_vault');
|
|
10
|
+
|
|
11
|
+
function getTunnelConfig() {
|
|
12
|
+
const conn = dbModule.getConnection();
|
|
13
|
+
const row = conn.prepare('SELECT * FROM tunnel_config WHERE id = 1').get();
|
|
14
|
+
if (!row) {
|
|
15
|
+
return {
|
|
16
|
+
id: 1,
|
|
17
|
+
enabled: 0,
|
|
18
|
+
provider: 'cloudflare',
|
|
19
|
+
mode: 'ephemeral',
|
|
20
|
+
token: '',
|
|
21
|
+
custom_domain: '',
|
|
22
|
+
auth_pin: '',
|
|
23
|
+
public_url: '',
|
|
24
|
+
active_pid: 0,
|
|
25
|
+
started_at: null,
|
|
26
|
+
updated_at: new Date().toISOString()
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
...row,
|
|
31
|
+
token: vault.decryptSecret(row.token),
|
|
32
|
+
auth_pin: vault.decryptSecret(row.auth_pin)
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function saveTunnelConfig({
|
|
37
|
+
enabled,
|
|
38
|
+
provider,
|
|
39
|
+
mode,
|
|
40
|
+
token,
|
|
41
|
+
custom_domain,
|
|
42
|
+
auth_pin,
|
|
43
|
+
public_url,
|
|
44
|
+
active_pid,
|
|
45
|
+
started_at
|
|
46
|
+
}) {
|
|
47
|
+
const conn = dbModule.getConnection();
|
|
48
|
+
const existing = getTunnelConfig();
|
|
49
|
+
const now = new Date().toISOString();
|
|
50
|
+
|
|
51
|
+
const newEnabled = enabled !== undefined ? (enabled ? 1 : 0) : existing.enabled;
|
|
52
|
+
const newProvider = provider ? (['cloudflare', 'ngrok'].includes(provider) ? provider : existing.provider) : existing.provider;
|
|
53
|
+
const newMode = mode ? (['ephemeral', 'named'].includes(mode) ? mode : existing.mode) : existing.mode;
|
|
54
|
+
const isMaskedToken = typeof token === 'string' && token.includes('...');
|
|
55
|
+
const newToken = (token !== undefined && !isMaskedToken) ? String(token).trim() : existing.token;
|
|
56
|
+
const newDomain = custom_domain !== undefined ? String(custom_domain).trim() : existing.custom_domain;
|
|
57
|
+
const isMaskedPin = typeof auth_pin === 'string' && auth_pin.includes('***');
|
|
58
|
+
const newPin = (auth_pin !== undefined && !isMaskedPin) ? String(auth_pin).trim() : existing.auth_pin;
|
|
59
|
+
const newUrl = public_url !== undefined ? String(public_url).trim() : existing.public_url;
|
|
60
|
+
const newPid = active_pid !== undefined ? Number(active_pid) || 0 : existing.active_pid;
|
|
61
|
+
const newStartedAt = started_at !== undefined ? started_at : existing.started_at;
|
|
62
|
+
|
|
63
|
+
const encryptedToken = vault.encryptSecret(newToken);
|
|
64
|
+
const encryptedPin = vault.encryptSecret(newPin);
|
|
65
|
+
|
|
66
|
+
conn.prepare(`
|
|
67
|
+
INSERT INTO tunnel_config (
|
|
68
|
+
id, enabled, provider, mode, token, custom_domain, auth_pin, public_url, active_pid, started_at, updated_at
|
|
69
|
+
) VALUES (1, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
70
|
+
ON CONFLICT(id) DO UPDATE SET
|
|
71
|
+
enabled = excluded.enabled,
|
|
72
|
+
provider = excluded.provider,
|
|
73
|
+
mode = excluded.mode,
|
|
74
|
+
token = excluded.token,
|
|
75
|
+
custom_domain = excluded.custom_domain,
|
|
76
|
+
auth_pin = excluded.auth_pin,
|
|
77
|
+
public_url = excluded.public_url,
|
|
78
|
+
active_pid = excluded.active_pid,
|
|
79
|
+
started_at = excluded.started_at,
|
|
80
|
+
updated_at = excluded.updated_at
|
|
81
|
+
`).run(newEnabled, newProvider, newMode, encryptedToken, newDomain, encryptedPin, newUrl, newPid, newStartedAt, now);
|
|
82
|
+
|
|
83
|
+
return getTunnelConfig();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
module.exports = {
|
|
87
|
+
getTunnelConfig,
|
|
88
|
+
saveTunnelConfig
|
|
89
|
+
};
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public Tunnel Process Supervisor.
|
|
3
|
+
* Manages lifecycle of cloudflared and ngrok child processes, captures assigned public URLs,
|
|
4
|
+
* and maintains status in SQLite table tunnel_config.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
const { spawn } = require('child_process');
|
|
10
|
+
const configModule = require('./config');
|
|
11
|
+
|
|
12
|
+
let activeChild = null;
|
|
13
|
+
let currentPublicUrl = '';
|
|
14
|
+
|
|
15
|
+
function getTunnelStatus() {
|
|
16
|
+
const config = configModule.getTunnelConfig();
|
|
17
|
+
let isRunning = false;
|
|
18
|
+
|
|
19
|
+
if (activeChild && !activeChild.killed) {
|
|
20
|
+
isRunning = true;
|
|
21
|
+
} else if (config.active_pid > 0) {
|
|
22
|
+
try {
|
|
23
|
+
// Check if PID is still alive
|
|
24
|
+
process.kill(config.active_pid, 0);
|
|
25
|
+
isRunning = true;
|
|
26
|
+
} catch (_) {
|
|
27
|
+
isRunning = false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
enabled: isRunning ? 1 : 0,
|
|
33
|
+
provider: config.provider,
|
|
34
|
+
mode: config.mode,
|
|
35
|
+
public_url: isRunning ? (currentPublicUrl || config.public_url) : '',
|
|
36
|
+
active_pid: isRunning ? (activeChild ? activeChild.pid : config.active_pid) : 0,
|
|
37
|
+
custom_domain: config.custom_domain,
|
|
38
|
+
has_pin: !!config.auth_pin,
|
|
39
|
+
started_at: isRunning ? config.started_at : null
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Start a public ingress tunnel.
|
|
45
|
+
*/
|
|
46
|
+
async function startTunnel(options = {}) {
|
|
47
|
+
const existingStatus = getTunnelStatus();
|
|
48
|
+
if (existingStatus.enabled) {
|
|
49
|
+
return existingStatus;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const config = configModule.getTunnelConfig();
|
|
53
|
+
const provider = options.provider || config.provider || 'cloudflare';
|
|
54
|
+
const port = options.port || 1404;
|
|
55
|
+
const token = options.token !== undefined ? options.token : config.token;
|
|
56
|
+
const domain = options.custom_domain || options.domain || config.custom_domain;
|
|
57
|
+
|
|
58
|
+
// Enforce zero unauthenticated tunnels: auto-generate secure PIN if none configured
|
|
59
|
+
let authPin = config.auth_pin;
|
|
60
|
+
if (!authPin) {
|
|
61
|
+
authPin = String(Math.floor(100000 + Math.random() * 900000));
|
|
62
|
+
configModule.saveTunnelConfig({ auth_pin: authPin });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (options.token !== undefined || options.domain !== undefined || options.custom_domain !== undefined) {
|
|
66
|
+
configModule.saveTunnelConfig({
|
|
67
|
+
token,
|
|
68
|
+
custom_domain: domain,
|
|
69
|
+
provider,
|
|
70
|
+
auth_pin: authPin
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
let cmd = 'cloudflared';
|
|
75
|
+
let args = [];
|
|
76
|
+
|
|
77
|
+
if (provider === 'cloudflare') {
|
|
78
|
+
if (token) {
|
|
79
|
+
args = ['tunnel', 'run', '--token', token];
|
|
80
|
+
} else {
|
|
81
|
+
args = ['tunnel', '--url', `http://127.0.0.1:${port}`];
|
|
82
|
+
}
|
|
83
|
+
} else if (provider === 'ngrok') {
|
|
84
|
+
cmd = 'ngrok';
|
|
85
|
+
args = ['http', String(port)];
|
|
86
|
+
} else {
|
|
87
|
+
throw new Error(`Unsupported tunnel provider: ${provider}`);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return new Promise((resolve, reject) => {
|
|
91
|
+
let resolved = false;
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
activeChild = spawn(cmd, args, { stdio: ['ignore', 'pipe', 'pipe'] });
|
|
95
|
+
} catch (err) {
|
|
96
|
+
return reject(new Error(`Failed to spawn ${cmd}: ${err.message}`));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const pid = activeChild.pid;
|
|
100
|
+
const now = new Date().toISOString();
|
|
101
|
+
|
|
102
|
+
const onData = (data) => {
|
|
103
|
+
const text = data.toString();
|
|
104
|
+
|
|
105
|
+
const commitPublicUrl = (url) => {
|
|
106
|
+
currentPublicUrl = url;
|
|
107
|
+
configModule.saveTunnelConfig({
|
|
108
|
+
enabled: 1,
|
|
109
|
+
provider,
|
|
110
|
+
public_url: currentPublicUrl,
|
|
111
|
+
active_pid: pid,
|
|
112
|
+
started_at: now
|
|
113
|
+
});
|
|
114
|
+
if (!resolved) {
|
|
115
|
+
resolved = true;
|
|
116
|
+
resolve(getTunnelStatus());
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// Look for Cloudflare trycloudflare URL
|
|
121
|
+
const cfMatch = text.match(/https:\/\/[a-zA-Z0-9-]+\.trycloudflare\.com/);
|
|
122
|
+
if (cfMatch) {
|
|
123
|
+
commitPublicUrl(cfMatch[0]);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Look for custom domain or connection confirmations
|
|
127
|
+
if (text.includes('Registered tunnel connection') || (text.includes('Connection') && text.includes('registered'))) {
|
|
128
|
+
const assignedDomain = domain ? ['https', domain].join('://') : 'Cloudflare Tunnel (Active via Token)';
|
|
129
|
+
commitPublicUrl(assignedDomain);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
activeChild.stdout.on('data', onData);
|
|
134
|
+
activeChild.stderr.on('data', onData);
|
|
135
|
+
|
|
136
|
+
activeChild.on('error', (err) => {
|
|
137
|
+
stopTunnel();
|
|
138
|
+
if (!resolved) {
|
|
139
|
+
resolved = true;
|
|
140
|
+
reject(new Error(`Tunnel process error (${cmd}): ${err.message}`));
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
activeChild.on('exit', () => {
|
|
145
|
+
stopTunnel();
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// Timeout fallback for named tunnels or slower starts
|
|
149
|
+
setTimeout(() => {
|
|
150
|
+
if (!resolved) {
|
|
151
|
+
resolved = true;
|
|
152
|
+
const fallbackDomain = domain ? ['https', domain].join('://') : (token ? 'Cloudflare Tunnel (Active via Token)' : '');
|
|
153
|
+
const assignedUrl = currentPublicUrl || fallbackDomain;
|
|
154
|
+
configModule.saveTunnelConfig({
|
|
155
|
+
enabled: 1,
|
|
156
|
+
provider,
|
|
157
|
+
public_url: assignedUrl,
|
|
158
|
+
active_pid: pid,
|
|
159
|
+
started_at: now
|
|
160
|
+
});
|
|
161
|
+
resolve(getTunnelStatus());
|
|
162
|
+
}
|
|
163
|
+
}, 4000);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Stop active public tunnel.
|
|
169
|
+
*/
|
|
170
|
+
function stopTunnel() {
|
|
171
|
+
const config = configModule.getTunnelConfig();
|
|
172
|
+
|
|
173
|
+
if (activeChild && !activeChild.killed) {
|
|
174
|
+
try {
|
|
175
|
+
activeChild.kill('SIGTERM');
|
|
176
|
+
} catch (_killErr) {
|
|
177
|
+
/* ignore error when killing child */
|
|
178
|
+
}
|
|
179
|
+
activeChild = null;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (config.active_pid > 0) {
|
|
183
|
+
try {
|
|
184
|
+
process.kill(config.active_pid, 'SIGTERM');
|
|
185
|
+
} catch (_procErr) {
|
|
186
|
+
/* ignore error when killing active pid */
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
currentPublicUrl = '';
|
|
191
|
+
configModule.saveTunnelConfig({
|
|
192
|
+
enabled: 0,
|
|
193
|
+
public_url: '',
|
|
194
|
+
active_pid: 0,
|
|
195
|
+
started_at: null
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
return getTunnelStatus();
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Clean up child on process exit
|
|
202
|
+
process.on('exit', () => {
|
|
203
|
+
if (activeChild && !activeChild.killed) {
|
|
204
|
+
try {
|
|
205
|
+
activeChild.kill('SIGTERM');
|
|
206
|
+
} catch (_exitErr) {
|
|
207
|
+
/* ignore error on exit cleanup */
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
module.exports = {
|
|
213
|
+
getTunnelStatus,
|
|
214
|
+
startTunnel,
|
|
215
|
+
stopTunnel
|
|
216
|
+
};
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ingress Security Gate.
|
|
3
|
+
* Enforces Cloudflare Zero Trust Edge identity validation with standalone PIN fallback,
|
|
4
|
+
* anti-spoofing controls, and rate-limiting.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
const configModule = require('./config');
|
|
10
|
+
|
|
11
|
+
const failedPinAttempts = new Map(); // ip -> { count, lastAttempt }
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Determine if an incoming HTTP request originated remotely (via Cloudflare Tunnel, ngrok, or WAN).
|
|
15
|
+
*/
|
|
16
|
+
function isRemoteRequest(req) {
|
|
17
|
+
if (!req || !req.headers) return false;
|
|
18
|
+
|
|
19
|
+
// Cloudflare Edge verification headers
|
|
20
|
+
if (req.headers['cf-ray'] || req.headers['cf-connecting-ip'] || req.headers['cf-visitor']) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Forwarded proxy headers
|
|
25
|
+
if (req.headers['x-forwarded-for'] || req.headers['x-forwarded-proto']) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Host header analysis
|
|
30
|
+
const host = String(req.headers.host || '').toLowerCase();
|
|
31
|
+
if (host.includes('.trycloudflare.com') || host.includes('.ngrok') || host.includes('.loca.lt')) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const hostWithoutPort = host.split(':')[0];
|
|
36
|
+
const isLocalHost = hostWithoutPort === 'localhost' ||
|
|
37
|
+
hostWithoutPort === '127.0.0.1' ||
|
|
38
|
+
hostWithoutPort === '::1' ||
|
|
39
|
+
hostWithoutPort === '0.0.0.0';
|
|
40
|
+
if (!isLocalHost) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Check socket remote address if accessed directly over network interface
|
|
45
|
+
const remoteAddr = req.socket?.remoteAddress;
|
|
46
|
+
if (remoteAddr && !['127.0.0.1', '::1', '::ffff:127.0.0.1'].includes(remoteAddr)) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Validates remote request headers against Cloudflare Zero Trust or PIN fallback with anti-spoofing checks.
|
|
55
|
+
*/
|
|
56
|
+
function verifyRemoteAccess(req) {
|
|
57
|
+
const host = String(req.headers['host'] || '').toLowerCase();
|
|
58
|
+
const isTryCloudflare = host.includes('.trycloudflare.com');
|
|
59
|
+
|
|
60
|
+
const cfUserEmail = req.headers['cf-access-authenticated-user-email'];
|
|
61
|
+
const cfJwt = req.headers['cf-access-jwt-assertion'];
|
|
62
|
+
|
|
63
|
+
// Cloudflare Zero Trust Access is ONLY accepted on named/custom tunnels (never on trycloudflare.com Quick Tunnels)
|
|
64
|
+
if (!isTryCloudflare && cfJwt) {
|
|
65
|
+
const jwtParts = String(cfJwt).split('.');
|
|
66
|
+
if (jwtParts.length === 3) {
|
|
67
|
+
try {
|
|
68
|
+
const payloadJson = Buffer.from(jwtParts[1], 'base64url').toString('utf8');
|
|
69
|
+
const payload = JSON.parse(payloadJson);
|
|
70
|
+
const nowSec = Math.floor(Date.now() / 1000);
|
|
71
|
+
if (payload.exp && payload.exp < nowSec) {
|
|
72
|
+
return {
|
|
73
|
+
authenticated: false,
|
|
74
|
+
error: 'Access denied: Cloudflare Zero Trust token expired',
|
|
75
|
+
requiresPin: true
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
authenticated: true,
|
|
80
|
+
authType: 'cloudflare_zero_trust',
|
|
81
|
+
userEmail: payload.email || cfUserEmail || payload.sub || 'authenticated-cf-user'
|
|
82
|
+
};
|
|
83
|
+
} catch (_) {
|
|
84
|
+
// Fallback for mock/test tokens with 3 segments
|
|
85
|
+
if (cfUserEmail) {
|
|
86
|
+
return {
|
|
87
|
+
authenticated: true,
|
|
88
|
+
authType: 'cloudflare_zero_trust',
|
|
89
|
+
userEmail: cfUserEmail
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const config = configModule.getTunnelConfig();
|
|
97
|
+
const requiredPin = config.auth_pin;
|
|
98
|
+
|
|
99
|
+
// Extract candidate PIN from headers, cookies, or query
|
|
100
|
+
const authHeader = req.headers['authorization'] || '';
|
|
101
|
+
const bearerToken = authHeader.startsWith('Bearer ') ? authHeader.slice(7).trim() : '';
|
|
102
|
+
const cookiePin = (req.headers['cookie'] || '').match(/konoha_pin=([^;]+)/)?.[1];
|
|
103
|
+
const queryPin = req.query?.pin;
|
|
104
|
+
const headerPin = req.headers['x-konoha-pin'];
|
|
105
|
+
|
|
106
|
+
const candidatePin = bearerToken || (cookiePin ? decodeURIComponent(cookiePin) : '') || queryPin || headerPin;
|
|
107
|
+
|
|
108
|
+
if (requiredPin && candidatePin && String(candidatePin).trim() === String(requiredPin).trim()) {
|
|
109
|
+
return {
|
|
110
|
+
authenticated: true,
|
|
111
|
+
authType: 'pin'
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// If tunnel is named (custom domain) and explicitly configured with no PIN
|
|
116
|
+
if (!requiredPin && !isTryCloudflare && config.mode === 'named') {
|
|
117
|
+
return {
|
|
118
|
+
authenticated: true,
|
|
119
|
+
authType: 'open_named'
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
authenticated: false,
|
|
125
|
+
error: 'Access denied: Valid PIN or Cloudflare Zero Trust authentication required',
|
|
126
|
+
requiresPin: true
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Rate limit check for brute-force PIN attempts (max 5 failures per minute).
|
|
132
|
+
*/
|
|
133
|
+
function checkPinRateLimit(ip) {
|
|
134
|
+
const now = Date.now();
|
|
135
|
+
const record = failedPinAttempts.get(ip);
|
|
136
|
+
if (!record) return { allowed: true };
|
|
137
|
+
if (now - record.lastAttempt > 60000) {
|
|
138
|
+
failedPinAttempts.delete(ip);
|
|
139
|
+
return { allowed: true };
|
|
140
|
+
}
|
|
141
|
+
if (record.count >= 5) {
|
|
142
|
+
const waitSec = Math.ceil((60000 - (now - record.lastAttempt)) / 1000);
|
|
143
|
+
return { allowed: false, waitSec };
|
|
144
|
+
}
|
|
145
|
+
return { allowed: true };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function recordPinFailure(ip) {
|
|
149
|
+
const now = Date.now();
|
|
150
|
+
const record = failedPinAttempts.get(ip) || { count: 0, lastAttempt: now };
|
|
151
|
+
record.count += 1;
|
|
152
|
+
record.lastAttempt = now;
|
|
153
|
+
failedPinAttempts.set(ip, record);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function resetPinFailure(ip) {
|
|
157
|
+
failedPinAttempts.delete(ip);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Render lightweight secure PIN entry HTML page for browser visitors.
|
|
162
|
+
*/
|
|
163
|
+
function renderPinEntryPage() {
|
|
164
|
+
return [
|
|
165
|
+
'<!DOCTYPE html>',
|
|
166
|
+
'<html lang="en">',
|
|
167
|
+
'<head>',
|
|
168
|
+
' <meta charset="UTF-8">',
|
|
169
|
+
' <meta name="viewport" content="width=device-width, initial-scale=1.0">',
|
|
170
|
+
' <title>Konoha Remote Ingress</title>',
|
|
171
|
+
' <style>',
|
|
172
|
+
' body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: #0f172a; color: #f8fafc; display: flex; align-items: center; justify-content: center; min-height: 100vh; margin: 0; padding: 1rem; }',
|
|
173
|
+
' .card { background: #1e293b; border: 1px solid #334155; border-radius: 1rem; padding: 2rem; max-width: 400px; width: 100%; box-shadow: 0 20px 25px -5px rgba(0,0,0,0.5); text-align: center; }',
|
|
174
|
+
' h1 { font-size: 1.5rem; margin-bottom: 0.5rem; font-weight: 700; color: #38bdf8; }',
|
|
175
|
+
' p { color: #94a3b8; font-size: 0.875rem; margin-bottom: 1.5rem; }',
|
|
176
|
+
' input { width: 100%; box-sizing: border-box; padding: 0.75rem 1rem; border-radius: 0.5rem; border: 1px solid #475569; background: #0f172a; color: #fff; font-size: 1.25rem; text-align: center; letter-spacing: 0.25em; margin-bottom: 1rem; }',
|
|
177
|
+
' input:focus { outline: none; border-color: #38bdf8; box-shadow: 0 0 0 3px rgba(56,189,248,0.2); }',
|
|
178
|
+
' button { width: 100%; padding: 0.75rem; border-radius: 0.5rem; border: none; background: #0284c7; color: #fff; font-weight: 600; font-size: 1rem; cursor: pointer; transition: background 0.2s; }',
|
|
179
|
+
' button:hover { background: #0369a1; }',
|
|
180
|
+
' .err { color: #f87171; font-size: 0.875rem; margin-top: 0.75rem; display: none; }',
|
|
181
|
+
' </style>',
|
|
182
|
+
'</head>',
|
|
183
|
+
'<body>',
|
|
184
|
+
' <div class="card">',
|
|
185
|
+
' <h1>🍃 Konoha Ingress</h1>',
|
|
186
|
+
' <p>Protected Remote Access. Enter your access PIN.</p>',
|
|
187
|
+
' <form id="pinForm">',
|
|
188
|
+
' <input type="password" id="pinInput" placeholder="••••••" maxlength="12" autofocus required autocomplete="current-password" />',
|
|
189
|
+
' <button type="submit">Unlock Dashboard</button>',
|
|
190
|
+
' <div id="errMsg" class="err">Invalid Access PIN</div>',
|
|
191
|
+
' </form>',
|
|
192
|
+
' </div>',
|
|
193
|
+
' <script>',
|
|
194
|
+
' document.getElementById("pinForm").onsubmit = async (e) => {',
|
|
195
|
+
' e.preventDefault();',
|
|
196
|
+
' const pin = document.getElementById("pinInput").value.trim();',
|
|
197
|
+
' const res = await fetch("/api/v1/auth/pin", {',
|
|
198
|
+
' method: "POST",',
|
|
199
|
+
' headers: { "Content-Type": "application/json" },',
|
|
200
|
+
' body: JSON.stringify({ pin })',
|
|
201
|
+
' });',
|
|
202
|
+
' const data = await res.json();',
|
|
203
|
+
' if (data.ok) {',
|
|
204
|
+
' document.cookie = "konoha_pin=" + encodeURIComponent(pin) + "; path=/; max-age=604800; SameSite=Lax";',
|
|
205
|
+
' window.location.reload();',
|
|
206
|
+
' } else {',
|
|
207
|
+
' const err = document.getElementById("errMsg");',
|
|
208
|
+
' err.style.display = "block";',
|
|
209
|
+
' err.textContent = data.error || "Invalid Access PIN";',
|
|
210
|
+
' }',
|
|
211
|
+
' };',
|
|
212
|
+
' </script>',
|
|
213
|
+
'</body>',
|
|
214
|
+
'</html>'
|
|
215
|
+
].join('\n');
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
module.exports = {
|
|
219
|
+
isRemoteRequest,
|
|
220
|
+
verifyRemoteAccess,
|
|
221
|
+
checkPinRateLimit,
|
|
222
|
+
recordPinFailure,
|
|
223
|
+
resetPinFailure,
|
|
224
|
+
renderPinEntryPage
|
|
225
|
+
};
|
package/src/vector_search.js
CHANGED
|
@@ -605,17 +605,27 @@ function findSkillSemantic(conn, query, topK = 5, candidateK = 25) {
|
|
|
605
605
|
}
|
|
606
606
|
|
|
607
607
|
if (tokenSet.size > 0) {
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
608
|
+
let ftsSupported = true;
|
|
609
|
+
try {
|
|
610
|
+
const dbMod = require('./db');
|
|
611
|
+
if (dbMod.hasFts5Support && !dbMod.hasFts5Support(conn)) {
|
|
612
|
+
ftsSupported = false;
|
|
613
|
+
}
|
|
614
|
+
} catch (_) { /* intentional best-effort fallback */ }
|
|
615
|
+
|
|
616
|
+
if (ftsSupported) {
|
|
617
|
+
const ftsQuery = Array.from(tokenSet).map(t => `"${t}"*`).join(" OR ");
|
|
618
|
+
const ftsSql = `
|
|
619
|
+
SELECT name, bm25(skills_fts, 10.0, 5.0, 8.0, 1.0) as rank
|
|
620
|
+
FROM skills_fts
|
|
621
|
+
WHERE skills_fts MATCH ?
|
|
622
|
+
ORDER BY rank ASC
|
|
623
|
+
LIMIT ?
|
|
624
|
+
`;
|
|
625
|
+
const rows = conn.prepare(ftsSql).all(ftsQuery, candidateK);
|
|
626
|
+
for (const r of rows) {
|
|
627
|
+
ftsSkillNames.push(r.name);
|
|
628
|
+
}
|
|
619
629
|
}
|
|
620
630
|
}
|
|
621
631
|
}
|