@kabmo-labs/kabmo 0.35.0 → 0.36.0
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/dist/client/index.html +1 -1
- package/dist/client/index.js +435 -432
- package/dist/client/static/js/{CsvGrid-0amzgtd7.js → CsvGrid-1h3bcak7.js} +2 -2
- package/dist/client/static/js/{DocxView-bxjhzxe9.js → DocxView-ndca8jch.js} +2 -2
- package/dist/client/static/js/{DrawioView-7s1yqsf4.js → DrawioView-kpzd6y0b.js} +2 -2
- package/dist/client/static/js/{ImageView-ycfbn66h.js → ImageView-79prn3dg.js} +1 -1
- package/dist/client/static/js/{LayoutWrapper-tw1q1x0g.js → LayoutWrapper-v2wn2sb2.js} +2 -2
- package/dist/client/static/js/{Modal-wqjactyd.js → Modal-99j0zz3z.js} +16 -16
- package/dist/client/static/js/{PdfView-x6dmtwvr.js → PdfView-2rjd87ay.js} +1 -1
- package/dist/client/static/js/{SessionsView-t85wq0me.js → SessionsView-t7f3s71b.js} +1 -1
- package/dist/client/static/js/{SheetView-n52nvz8s.js → SheetView-ehb976st.js} +13 -13
- package/dist/client/static/js/{SvgPreview-59z7syme.js → SvgPreview-de2bbba6.js} +1 -1
- package/dist/client/static/js/{abnfDiagram-O67JEVCF-91gnt049.js → abnfDiagram-O67JEVCF-nx9jzn7m.js} +1 -1
- package/dist/client/static/js/architecture-7GRP2DOG-aqft2erp.js +1 -0
- package/dist/client/static/js/{architectureDiagram-NJMV4G6O-5b9qtff2.js → architectureDiagram-NJMV4G6O-170v67rr.js} +3 -3
- package/dist/client/static/js/{astro-31cbyw7b.js → astro-80bs6hvg.js} +1 -1
- package/dist/client/static/js/bash-b3rwyg5p.js +1 -0
- package/dist/client/static/js/{blockDiagram-BEXU5L5S-6f23fjkn.js → blockDiagram-BEXU5L5S-16q285n1.js} +2 -2
- package/dist/client/static/js/{c4Diagram-YGBWAQC7-76t6d3am.js → c4Diagram-YGBWAQC7-rn3qt45h.js} +2 -2
- package/dist/client/static/js/{classDiagram-v2-NBCMYWYE-f9tb19xm.js → classDiagram-v2-NBCMYWYE-r26wg74e.js} +1 -1
- package/dist/client/static/js/{cose-bilkent-JH36ORCC-t6nwrbwj.js → cose-bilkent-JH36ORCC-82kwe7ha.js} +1 -1
- package/dist/client/static/js/cpp-y0t6mynx.js +1 -0
- package/dist/client/static/js/css-r2nhvzff.js +1 -0
- package/dist/client/static/js/cynefin-OW5HDTMX-v2sz60t6.js +1 -0
- package/dist/client/static/js/{cynefinDiagram-VND7K2PF-69gc244j.js → cynefinDiagram-VND7K2PF-tcxdn6pa.js} +1 -1
- package/dist/client/static/js/{dagre-6A5THRUB-54bry3ey.js → dagre-6A5THRUB-g833ata3.js} +2 -2
- package/dist/client/static/js/{diagram-22UHCM2B-gfkebye6.js → diagram-22UHCM2B-f1fq8xec.js} +3 -3
- package/dist/client/static/js/{diagram-3UASUU5V-a1mr319f.js → diagram-3UASUU5V-6j2w016f.js} +1 -1
- package/dist/client/static/js/{diagram-ATOU4E4O-tkyk0qbe.js → diagram-ATOU4E4O-6t2qxsk4.js} +3 -3
- package/dist/client/static/js/{diagram-CDSNMT55-np0hc9m2.js → diagram-CDSNMT55-7abar8s7.js} +2 -2
- package/dist/client/static/js/{diagram-MLGK6HIB-nh06fshp.js → diagram-MLGK6HIB-s68rgy16.js} +1 -1
- package/dist/client/static/js/{diagram-MPIPVDR6-27q2veks.js → diagram-MPIPVDR6-azgkm6w8.js} +1 -1
- package/dist/client/static/js/{dockerfile-4rtt6c0f.js → dockerfile-47e33kqa.js} +1 -1
- package/dist/client/static/js/{ebnfDiagram-ZINNZB2B-x9p9jqe8.js → ebnfDiagram-ZINNZB2B-esrjz750.js} +1 -1
- package/dist/client/static/js/{elk-276RUBZZ-fw7waks3.js → elk-276RUBZZ-fhr4b4jj.js} +1 -1
- package/dist/client/static/js/{erDiagram-OPXOYQCR-fdfgzr5d.js → erDiagram-OPXOYQCR-5r3fmdnz.js} +4 -4
- package/dist/client/static/js/{erlang-trjm07as.js → erlang-bh5cbm8m.js} +1 -1
- package/dist/client/static/js/eventmodeling-NTZA5JFV-8qbefe4m.js +1 -0
- package/dist/client/static/js/flowDiagram-KWPJA3E3-krsvgcq7.js +1 -0
- package/dist/client/static/js/{ganttDiagram-FUAMR5RP-2avbqgdr.js → ganttDiagram-FUAMR5RP-j4pf6rdn.js} +1 -1
- package/dist/client/static/js/gitGraph-4MIJSDKK-9bx1a38k.js +1 -0
- package/dist/client/static/js/{gitGraphDiagram-X574FWY7-9jmc0a3g.js → gitGraphDiagram-X574FWY7-x5epk0gr.js} +2 -2
- package/dist/client/static/js/graphql-xnpp5gn9.js +1 -0
- package/dist/client/static/js/{index-nb8tp4mj.js → index-0b1kwsam.js} +8 -8
- package/dist/client/static/js/{index-43qpbxjv.js → index-1y9r4frb.js} +2 -2
- package/dist/client/static/js/{index-8x9ecxb0.js → index-3kgrcaq1.js} +1 -1
- package/dist/client/static/js/{index-a628fg4m.js → index-3vdmwpbh.js} +2 -2
- package/dist/client/static/js/{index-jc1yagmk.js → index-3zc1b0dv.js} +2 -2
- package/dist/client/static/js/{index-ee2p07eg.js → index-40ve7zzv.js} +1 -1
- package/dist/client/static/js/{index-xxtsm2rb.js → index-44qrckd2.js} +2 -2
- package/dist/client/static/js/{index-qqz6bcdd.js → index-55pqvh82.js} +2 -2
- package/dist/client/static/js/{index-kdkfyrja.js → index-5kjpacvd.js} +2 -2
- package/dist/client/static/js/{index-t6c0pd43.js → index-5rzk1226.js} +2 -2
- package/dist/client/static/js/{index-jmxqefe3.js → index-60ceydzn.js} +1 -1
- package/dist/client/static/js/{index-ek2e773p.js → index-63c6t75t.js} +1 -1
- package/dist/client/static/js/{index-6f6cmcbq.js → index-63jbb4kf.js} +2 -2
- package/dist/client/static/js/{index-8f9x7ev8.js → index-6xzfta4b.js} +1 -1
- package/dist/client/static/js/{index-ncrenheb.js → index-75haaj8g.js} +125 -125
- package/dist/client/static/js/{index-4vybd9e7.js → index-7r1hw2gd.js} +1 -1
- package/dist/client/static/js/{index-y3ms153k.js → index-8cy3x2y8.js} +2 -2
- package/dist/client/static/js/{index-7ct7qrsp.js → index-8e15fzax.js} +2 -2
- package/dist/client/static/js/{index-rkn0bxxt.js → index-97t3mv1v.js} +1 -1
- package/dist/client/static/js/{index-tp7yb3bv.js → index-982jyfsb.js} +2 -2
- package/dist/client/static/js/{index-py2k8std.js → index-9gf8b73w.js} +2 -2
- package/dist/client/static/js/{index-pzbssnsc.js → index-af24nes6.js} +2 -2
- package/dist/client/static/js/{index-w5373tg1.js → index-b48p8d1j.js} +2 -2
- package/dist/client/static/js/{index-w7tpgt46.js → index-be6gevq8.js} +1 -1
- package/dist/client/static/js/index-c09a5s1n.js +12 -0
- package/dist/client/static/js/{index-7q02xnvq.js → index-c1j0xb0w.js} +1 -1
- package/dist/client/static/js/{index-vnw3hbeg.js → index-ctgefatv.js} +27 -27
- package/dist/client/static/js/{index-2v1nmxwr.js → index-d2km9egp.js} +5 -5
- package/dist/client/static/js/index-dh1vd0d9.js +1 -0
- package/dist/client/static/js/{index-zh2jj56s.js → index-dmgawfhw.js} +2 -2
- package/dist/client/static/js/{index-k7q01ye4.js → index-h1e1abpt.js} +2 -2
- package/dist/client/static/js/{index-0v34a7wf.js → index-htt8qxm3.js} +1 -1
- package/dist/client/static/js/{index-a8ffattk.js → index-k1xt92h4.js} +2 -2
- package/dist/client/static/js/{index-p16scjt7.js → index-ktvbsj6w.js} +2 -2
- package/dist/client/static/js/{index-b8s3xraa.js → index-ky0prc71.js} +5 -5
- package/dist/client/static/js/{index-xs1m0bpt.js → index-mm1rf116.js} +1 -1
- package/dist/client/static/js/index-nws03exw.js +2 -0
- package/dist/client/static/js/{index-rbgemjsp.js → index-pyx8n25s.js} +3 -3
- package/dist/client/static/js/{index-3ecsp1rx.js → index-q5t4sy22.js} +3 -3
- package/dist/client/static/js/{index-rv89xpaf.js → index-r8pckaqe.js} +2 -2
- package/dist/client/static/js/{index-fvc0x6nx.js → index-sar2ggde.js} +3 -3
- package/dist/client/static/js/{index-sdby39w4.js → index-skm6k5w2.js} +3 -3
- package/dist/client/static/js/{index-whbtxmwh.js → index-v5t761a1.js} +2 -2
- package/dist/client/static/js/{index-8mwragbj.js → index-v8qd8ypc.js} +2 -2
- package/dist/client/static/js/{index-1wjp16f0.js → index-vtbbfwx0.js} +2 -2
- package/dist/client/static/js/{index-vq6wts05.js → index-w3n97x4b.js} +2 -2
- package/dist/client/static/js/{index-mc4nefs7.js → index-ydvfc9td.js} +1 -1
- package/dist/client/static/js/{index-9ketbkh6.js → index-ye450a7z.js} +1 -1
- package/dist/client/static/js/{index-7smwzkvq.js → index-z6g74h7g.js} +2 -2
- package/dist/client/static/js/{index-yq39qbs1.js → index-zdtsvnpq.js} +2 -2
- package/dist/client/static/js/{index-pc6eg8h2.js → index-zp73zexp.js} +2 -2
- package/dist/client/static/js/{index-pnt0vc59.js → index-zvfvqvn9.js} +2 -2
- package/dist/client/static/js/info-A6RAGUB7-j51t7jhh.js +1 -0
- package/dist/client/static/js/{infoDiagram-VRGFBTTK-g2dky5xg.js → infoDiagram-VRGFBTTK-ktc8nb8g.js} +1 -1
- package/dist/client/static/js/ini-ygfyhprj.js +1 -0
- package/dist/client/static/js/{ishikawaDiagram-OU5B5YK6-exrcjwp1.js → ishikawaDiagram-OU5B5YK6-n3dk6227.js} +1 -1
- package/dist/client/static/js/java-gm49vw59.js +1 -0
- package/dist/client/static/js/{journeyDiagram-ZHPQQLJL-pn752qa5.js → journeyDiagram-ZHPQQLJL-f0p1h8qn.js} +2 -2
- package/dist/client/static/js/jsx-ksxw1byz.js +1 -0
- package/dist/client/static/js/{julia-evn99h2m.js → julia-73zjh2w6.js} +1 -1
- package/dist/client/static/js/{kanban-definition-PNTS6WVX-v8nvr373.js → kanban-definition-PNTS6WVX-7jdt7dv1.js} +1 -1
- package/dist/client/static/js/lua-53gzb9bx.js +1 -0
- package/dist/client/static/js/markdown-tk3cd3vs.js +1 -0
- package/dist/client/static/js/{mermaid.core-egzv89zv.js → mermaid.core-e8rzrjt9.js} +6 -6
- package/dist/client/static/js/{mindmap-definition-NLK3R4M7-t9njmv2w.js → mindmap-definition-NLK3R4M7-7shv6ge0.js} +2 -2
- package/dist/client/static/js/one-dark-pro-39bt34v9.js +1 -0
- package/dist/client/static/js/one-light-xec0sehr.js +1 -0
- package/dist/client/static/js/packet-AYTQ26CC-n83gfj2g.js +1 -0
- package/dist/client/static/js/{pegDiagram-GJSIUBJH-zhycy2b7.js → pegDiagram-GJSIUBJH-17ak2zx3.js} +1 -1
- package/dist/client/static/js/{perl-506fy8m8.js → perl-8z46dmze.js} +1 -1
- package/dist/client/static/js/{php-axtsvxck.js → php-6qvnp2t6.js} +1 -1
- package/dist/client/static/js/pie-WAS4IAKB-5c5pctwz.js +1 -0
- package/dist/client/static/js/{pieDiagram-5QR66LMP-sgctvma2.js → pieDiagram-5QR66LMP-at4x1g4q.js} +1 -1
- package/dist/client/static/js/properties-2tcybqjk.js +1 -0
- package/dist/client/static/js/python-qph3dntq.js +1 -0
- package/dist/client/static/js/{quadrantDiagram-O4NWA36T-kzzhdcph.js → quadrantDiagram-O4NWA36T-apzhwrn4.js} +1 -1
- package/dist/client/static/js/r-gd26x93y.js +1 -0
- package/dist/client/static/js/radar-RG4KPBEZ-52e5n99a.js +1 -0
- package/dist/client/static/js/railroad-74A4TZTK-44nqxxpy.js +1 -0
- package/dist/client/static/js/railroad-abnf-HS5TGJTU-25jxgwg7.js +1 -0
- package/dist/client/static/js/railroad-ebnf-LZEXJU2U-64pqpf2y.js +1 -0
- package/dist/client/static/js/railroad-peg-WCYAUIDC-0p5sxzpx.js +1 -0
- package/dist/client/static/js/{railroadDiagram-XR7U4H2S-nzjffwxm.js → railroadDiagram-XR7U4H2S-rw8cj5f3.js} +1 -1
- package/dist/client/static/js/{requirementDiagram-PLB6GJNP-tz4xxn4d.js → requirementDiagram-PLB6GJNP-qyrse7mb.js} +1 -1
- package/dist/client/static/js/{ruby-qp7zfk2m.js → ruby-qy8mhstq.js} +1 -1
- package/dist/client/static/js/{rust-fz913fvw.js → rust-fpshqnk0.js} +1 -1
- package/dist/client/static/js/{sankeyDiagram-IPEJSGJF-2wcb0xr6.js → sankeyDiagram-IPEJSGJF-254qr59q.js} +2 -2
- package/dist/client/static/js/{sass-gnk9vsyp.js → sass-kbwea482.js} +1 -1
- package/dist/client/static/js/{sequenceDiagram-PO4LG4MO-vqgebfns.js → sequenceDiagram-PO4LG4MO-y9xjxfc5.js} +5 -5
- package/dist/client/static/js/{sizeCapture-INFHLROL-xc314tes.js → sizeCapture-INFHLROL-sc5e60t3.js} +1 -1
- package/dist/client/static/js/{stateDiagram-v2-GCMORJYK-8bd9b1h8.js → stateDiagram-v2-GCMORJYK-r134s4xr.js} +2 -2
- package/dist/client/static/js/{svelte-brpgzrtv.js → svelte-mwtx07d9.js} +1 -1
- package/dist/client/static/js/{swimlanes-2SLR337P-t6hbdzcw.js → swimlanes-2SLR337P-xc7rbawt.js} +1 -1
- package/dist/client/static/js/swimlanesDiagram-TC7HE7FX-kdcdamkj.js +8 -0
- package/dist/client/static/js/{timeline-definition-EJHVYXUP-2txxasx5.js → timeline-definition-EJHVYXUP-cgjd8shk.js} +2 -2
- package/dist/client/static/js/treeView-Q6P3EWNA-8j14nnd1.js +1 -0
- package/dist/client/static/js/treemap-WGGIJYW6-esf993kk.js +1 -0
- package/dist/client/static/js/tsx-nm94hed6.js +1 -0
- package/dist/client/static/js/typescript-0s2t05jj.js +1 -0
- package/dist/client/static/js/{usecaseDiagram-POWQR4AR-3x353hn4.js → usecaseDiagram-POWQR4AR-9qsmjhm6.js} +2 -2
- package/dist/client/static/js/{vennDiagram-UO4OBE2U-cerpss8e.js → vennDiagram-UO4OBE2U-4grw9awx.js} +1 -1
- package/dist/client/static/js/{vue-apnkw9qy.js → vue-j8vb9d7r.js} +1 -1
- package/dist/client/static/js/wardley-WFR3VGLG-v4dxm2sb.js +1 -0
- package/dist/client/static/js/{wardleyDiagram-VNRHLVJA-cx6jfsbf.js → wardleyDiagram-VNRHLVJA-8gxy0wat.js} +1 -1
- package/dist/client/static/js/xml-0py2vkw7.js +1 -0
- package/dist/client/static/js/{xychartDiagram-PMCCYNJV-tgn23xj1.js → xychartDiagram-PMCCYNJV-5sh7tdrx.js} +2 -2
- package/dist/client/static/js/yaml-vghdz0f0.js +1 -0
- package/package.json +1 -1
- package/src/client/components/settings/categories/ConnectSettings.tsx +8 -1
- package/src/client/components/settings/categories/connect-settings/CloudflareConfig.test.tsx +84 -0
- package/src/client/components/settings/categories/connect-settings/CloudflareConfig.tsx +68 -0
- package/src/client/components/settings/categories/connect-settings/PairDialog.test.tsx +49 -49
- package/src/client/components/settings/categories/connect-settings/PairDialog.tsx +12 -8
- package/src/client/components/settings/categories/connect-settings/QrCode.tsx +19 -2
- package/src/client/hooks/connect/use-connect-status.ts +44 -19
- package/src/client/hooks/connect/use-pairing.ts +5 -0
- package/src/client/lib/notifications/watch.ts +4 -1
- package/src/server/lib/connect/cloudflared-config.server.ts +236 -0
- package/src/server/lib/connect/cloudflared-config.test.ts +245 -0
- package/src/server/lib/connect/cloudflared.lifecycle.test.ts +116 -15
- package/src/server/lib/connect/cloudflared.server.ts +53 -66
- package/src/server/lib/connect/pairing.server.ts +33 -0
- package/src/server/lib/connect/qr-png.server.test.ts +93 -0
- package/src/server/lib/connect/qr-png.server.ts +119 -0
- package/src/server/lib/connect/status.server.ts +10 -4
- package/src/server/routes/connect/index.ts +2 -0
- package/src/server/routes/connect/pair-qr.test.ts +72 -0
- package/src/server/routes/connect/pair-qr.ts +44 -0
- package/src/server/routes/connect/pair.ts +8 -2
- package/src/server/routes/connect/tunnels.test.ts +141 -0
- package/src/server/routes/connect/tunnels.ts +32 -7
- package/src/server/routes/notifications/stream.ts +11 -2
- package/src/shared/lib/connect/types.ts +7 -0
- package/dist/client/static/js/architecture-7GRP2DOG-bajpnvy7.js +0 -1
- package/dist/client/static/js/bash-0h36tk0k.js +0 -1
- package/dist/client/static/js/cpp-4wp9sy20.js +0 -1
- package/dist/client/static/js/css-c9nsbkh6.js +0 -1
- package/dist/client/static/js/cynefin-OW5HDTMX-8q9e90m8.js +0 -1
- package/dist/client/static/js/eventmodeling-NTZA5JFV-kn4hsm3p.js +0 -1
- package/dist/client/static/js/flowDiagram-KWPJA3E3-ah8cvps1.js +0 -1
- package/dist/client/static/js/gitGraph-4MIJSDKK-hvavh16n.js +0 -1
- package/dist/client/static/js/graphql-hbkmxsty.js +0 -1
- package/dist/client/static/js/index-btr2w8cq.js +0 -12
- package/dist/client/static/js/index-dfzrpy54.js +0 -2
- package/dist/client/static/js/index-sbd5e816.js +0 -1
- package/dist/client/static/js/info-A6RAGUB7-fmjz8qwg.js +0 -1
- package/dist/client/static/js/ini-72yrpvd4.js +0 -1
- package/dist/client/static/js/java-ab5tb2ra.js +0 -1
- package/dist/client/static/js/jsx-25zj9j3k.js +0 -1
- package/dist/client/static/js/lua-j5w0c9wm.js +0 -1
- package/dist/client/static/js/markdown-j6hn4377.js +0 -1
- package/dist/client/static/js/one-dark-pro-bm3r4js7.js +0 -1
- package/dist/client/static/js/one-light-e07dt7sy.js +0 -1
- package/dist/client/static/js/packet-AYTQ26CC-cwr6n1cm.js +0 -1
- package/dist/client/static/js/pie-WAS4IAKB-h1ebfzgt.js +0 -1
- package/dist/client/static/js/properties-q8njes42.js +0 -1
- package/dist/client/static/js/python-vqxc7181.js +0 -1
- package/dist/client/static/js/r-0k5eej8m.js +0 -1
- package/dist/client/static/js/radar-RG4KPBEZ-k7p1m364.js +0 -1
- package/dist/client/static/js/railroad-74A4TZTK-d08dw3t0.js +0 -1
- package/dist/client/static/js/railroad-abnf-HS5TGJTU-txnjycgk.js +0 -1
- package/dist/client/static/js/railroad-ebnf-LZEXJU2U-p0r3cv6w.js +0 -1
- package/dist/client/static/js/railroad-peg-WCYAUIDC-sryk900a.js +0 -1
- package/dist/client/static/js/swimlanesDiagram-TC7HE7FX-c1czc7kv.js +0 -8
- package/dist/client/static/js/treeView-Q6P3EWNA-77kj68p1.js +0 -1
- package/dist/client/static/js/treemap-WGGIJYW6-rw94xc82.js +0 -1
- package/dist/client/static/js/tsx-yd5wt250.js +0 -1
- package/dist/client/static/js/typescript-v7z7crfe.js +0 -1
- package/dist/client/static/js/wardley-WFR3VGLG-18xe4fhz.js +0 -1
- package/dist/client/static/js/xml-94fhzrfs.js +0 -1
- package/dist/client/static/js/yaml-s8af9rnw.js +0 -1
- package/src/client/components/settings/categories/connect-settings/qr-image.ts +0 -76
- package/src/server/lib/connect/cloudflared.server.test.ts +0 -65
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
* A real named tunnel needs an account, a domain and a credentials file, so the
|
|
10
10
|
* start path is unreachable on a machine that has none — which is exactly the
|
|
11
11
|
* path that would otherwise ship untested. The stand-in is a script that stays
|
|
12
|
-
* alive
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* alive and records its argv and the config it was handed: the start path must
|
|
13
|
+
* spawn `tunnel --config <runtime copy> run`, the copy must name THIS port, and
|
|
14
|
+
* the copy must be gone once the tunnel stops.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { afterEach, describe, expect, test } from 'bun:test';
|
|
@@ -32,25 +32,84 @@ const posixOnly = process.platform !== 'win32';
|
|
|
32
32
|
|
|
33
33
|
const dirs: string[] = [];
|
|
34
34
|
|
|
35
|
-
function
|
|
36
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'kabmo-cf-
|
|
35
|
+
function tempDir(): string {
|
|
36
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'kabmo-cf-'));
|
|
37
37
|
dirs.push(dir);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
return dir;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const CONFIG = [
|
|
42
|
+
'tunnel: 6ff42ae2-765d-4adf-8112-31c55c1551ef',
|
|
43
|
+
'credentials-file: /home/me/.cloudflared/6ff42ae2.json',
|
|
44
|
+
'',
|
|
45
|
+
'ingress:',
|
|
46
|
+
' - hostname: kabmo.example.com',
|
|
47
|
+
' service: http://localhost:3000',
|
|
48
|
+
' - service: http_status:404',
|
|
49
|
+
'',
|
|
50
|
+
].join('\n');
|
|
51
|
+
|
|
52
|
+
function writeConfig(text: string): string {
|
|
53
|
+
const file = path.join(tempDir(), 'config.yml');
|
|
54
|
+
fs.writeFileSync(file, text);
|
|
42
55
|
return file;
|
|
43
56
|
}
|
|
44
57
|
|
|
58
|
+
/** Stays alive until killed, like the real `tunnel run`, and records its argv. */
|
|
59
|
+
function fakeCloudflared(): { binary: string; argsFile: string; configFile: string } {
|
|
60
|
+
const dir = tempDir();
|
|
61
|
+
const binary = path.join(dir, 'cloudflared');
|
|
62
|
+
const argsFile = path.join(dir, 'args.txt');
|
|
63
|
+
const configFile = path.join(dir, 'handed-config.yml');
|
|
64
|
+
fs.writeFileSync(
|
|
65
|
+
binary,
|
|
66
|
+
[
|
|
67
|
+
'#!/bin/sh',
|
|
68
|
+
`args="${argsFile}"`,
|
|
69
|
+
`cfg="${configFile}"`,
|
|
70
|
+
': > "$args.tmp"',
|
|
71
|
+
'while [ $# -gt 0 ]; do',
|
|
72
|
+
' printf \'%s\\n\' "$1" >> "$args.tmp"',
|
|
73
|
+
' if [ "$1" = "--config" ]; then',
|
|
74
|
+
' shift',
|
|
75
|
+
' printf \'%s\\n\' "$1" >> "$args.tmp"',
|
|
76
|
+
' cp "$1" "$cfg" 2>/dev/null',
|
|
77
|
+
' fi',
|
|
78
|
+
' shift',
|
|
79
|
+
'done',
|
|
80
|
+
// Rename, so the reader never sees a half-written file.
|
|
81
|
+
'mv "$args.tmp" "$args"',
|
|
82
|
+
'exec sleep 30',
|
|
83
|
+
'',
|
|
84
|
+
].join('\n'),
|
|
85
|
+
);
|
|
86
|
+
fs.chmodSync(binary, 0o755);
|
|
87
|
+
return { binary, argsFile, configFile };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async function waitForFile(file: string): Promise<void> {
|
|
91
|
+
if (fs.existsSync(file)) return;
|
|
92
|
+
const signal = AbortSignal.timeout(2_000);
|
|
93
|
+
try {
|
|
94
|
+
for await (const event of fs.promises.watch(path.dirname(file), { signal })) {
|
|
95
|
+
void event;
|
|
96
|
+
if (fs.existsSync(file)) return;
|
|
97
|
+
}
|
|
98
|
+
} catch (error) {
|
|
99
|
+
if (signal.aborted) throw new Error(`Timed out waiting for ${file}`);
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
45
104
|
afterEach(() => {
|
|
46
105
|
for (const dir of dirs.splice(0)) fs.rmSync(dir, { recursive: true, force: true });
|
|
47
106
|
});
|
|
48
107
|
|
|
49
108
|
describe('cloudflared lifecycle', () => {
|
|
50
109
|
test.skipIf(!posixOnly)('starting records the public URL and reports the process alive', async () => {
|
|
51
|
-
const binary = fakeCloudflared();
|
|
110
|
+
const { binary } = fakeCloudflared();
|
|
52
111
|
const port = 39_101;
|
|
53
|
-
const outcome = await startCloudflared(binary,
|
|
112
|
+
const outcome = await startCloudflared(binary, writeConfig(CONFIG), 'kabmo.example.com', port);
|
|
54
113
|
|
|
55
114
|
expect(outcome.ok).toBe(true);
|
|
56
115
|
expect(outcome.url).toBe('https://kabmo.example.com');
|
|
@@ -62,11 +121,39 @@ describe('cloudflared lifecycle', () => {
|
|
|
62
121
|
expect(runningTunnelUrl(port)).toBeNull();
|
|
63
122
|
});
|
|
64
123
|
|
|
124
|
+
test.skipIf(!posixOnly)('runs a runtime copy pointed at this port, not the file on disk', async () => {
|
|
125
|
+
const { binary, argsFile, configFile } = fakeCloudflared();
|
|
126
|
+
const source = writeConfig(CONFIG);
|
|
127
|
+
const port = 39_105;
|
|
128
|
+
|
|
129
|
+
await startCloudflared(binary, source, 'kabmo.example.com', port);
|
|
130
|
+
await waitForFile(argsFile);
|
|
131
|
+
|
|
132
|
+
const args = fs.readFileSync(argsFile, 'utf8').trim().split('\n');
|
|
133
|
+
expect(args.slice(0, 2)).toEqual(['tunnel', '--config']);
|
|
134
|
+
const runtimePath = args[2];
|
|
135
|
+
expect(args.slice(3)).toEqual(['run']);
|
|
136
|
+
expect(args).not.toContain('--url');
|
|
137
|
+
expect(runtimePath).not.toBe(source);
|
|
138
|
+
expect(fs.existsSync(runtimePath)).toBe(true);
|
|
139
|
+
|
|
140
|
+
const handed = fs.readFileSync(configFile, 'utf8');
|
|
141
|
+
expect(handed).toContain(`service: http://127.0.0.1:${port}`);
|
|
142
|
+
expect(handed).not.toContain('http://localhost:3000');
|
|
143
|
+
expect(handed).toContain('credentials-file: /home/me/.cloudflared/6ff42ae2.json');
|
|
144
|
+
// The user's file is never modified.
|
|
145
|
+
expect(fs.readFileSync(source, 'utf8')).toBe(CONFIG);
|
|
146
|
+
|
|
147
|
+
stopCloudflared(port);
|
|
148
|
+
expect(fs.existsSync(path.dirname(runtimePath))).toBe(false);
|
|
149
|
+
});
|
|
150
|
+
|
|
65
151
|
test.skipIf(!posixOnly)('starting twice for one port reuses the running tunnel', async () => {
|
|
66
|
-
const binary = fakeCloudflared();
|
|
152
|
+
const { binary } = fakeCloudflared();
|
|
153
|
+
const config = writeConfig(CONFIG);
|
|
67
154
|
const port = 39_102;
|
|
68
|
-
await startCloudflared(binary,
|
|
69
|
-
const second = await startCloudflared(binary,
|
|
155
|
+
await startCloudflared(binary, config, 'a.example.com', port);
|
|
156
|
+
const second = await startCloudflared(binary, config, 'b.example.com', port);
|
|
70
157
|
|
|
71
158
|
// The second call must not spawn a second process, and must not claim a
|
|
72
159
|
// different hostname than the one actually running.
|
|
@@ -74,13 +161,27 @@ describe('cloudflared lifecycle', () => {
|
|
|
74
161
|
stopCloudflared(port);
|
|
75
162
|
});
|
|
76
163
|
|
|
164
|
+
test('a config with no ingress hostname is refused instead of spawned', async () => {
|
|
165
|
+
const { binary } = fakeCloudflared();
|
|
166
|
+
const outcome = await startCloudflared(
|
|
167
|
+
binary,
|
|
168
|
+
writeConfig('tunnel: t\ningress:\n - service: http_status:404\n'),
|
|
169
|
+
'x.example.com',
|
|
170
|
+
39_106,
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
expect(outcome.ok).toBe(false);
|
|
174
|
+
expect(outcome.reason).toContain('no ingress rule');
|
|
175
|
+
expect(cloudflaredAlive(39_106)).toBe(false);
|
|
176
|
+
});
|
|
177
|
+
|
|
77
178
|
test('stopping a tunnel that was never started is not an error', () => {
|
|
78
179
|
expect(stopCloudflared(39_103)).toEqual({ ok: true, reason: null });
|
|
79
180
|
expect(cloudflaredAlive(39_103)).toBe(false);
|
|
80
181
|
});
|
|
81
182
|
|
|
82
183
|
test('a binary that cannot be spawned reports the reason', async () => {
|
|
83
|
-
const outcome = await startCloudflared('/nonexistent/cloudflared',
|
|
184
|
+
const outcome = await startCloudflared('/nonexistent/cloudflared', writeConfig(CONFIG), 'x.example.com', 39_104);
|
|
84
185
|
expect(outcome.ok).toBe(false);
|
|
85
186
|
expect(outcome.reason).toBeTruthy();
|
|
86
187
|
expect(cloudflaredAlive(39_104)).toBe(false);
|
|
@@ -23,6 +23,10 @@
|
|
|
23
23
|
import fs from 'fs';
|
|
24
24
|
import os from 'os';
|
|
25
25
|
import path from 'path';
|
|
26
|
+
import {
|
|
27
|
+
deriveCloudflaredRunConfig,
|
|
28
|
+
readCloudflaredConfig,
|
|
29
|
+
} from '@/server/lib/connect/cloudflared-config.server';
|
|
26
30
|
import { which } from '@/server/lib/connect/run.server';
|
|
27
31
|
|
|
28
32
|
export interface CloudflaredPresence {
|
|
@@ -32,68 +36,9 @@ export interface CloudflaredPresence {
|
|
|
32
36
|
reason: string | null;
|
|
33
37
|
}
|
|
34
38
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
tunnel: string | null;
|
|
38
|
-
/** The first public hostname in the ingress list. */
|
|
39
|
-
hostname: string | null;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/** Where cloudflared looks for its config, honouring the documented override. */
|
|
43
|
-
export function cloudflaredConfigPath(): string {
|
|
44
|
-
const override = (Bun.env.CLOUDFLARED_CONFIG ?? '').trim();
|
|
45
|
-
if (override) return override;
|
|
46
|
-
return path.join(os.homedir(), '.cloudflared', 'config.yml');
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Read the two facts this page needs out of the YAML.
|
|
51
|
-
*
|
|
52
|
-
* A line scan rather than a YAML parser: the file is written by
|
|
53
|
-
* `cloudflared tunnel create` and by hand, and the only fields read here are a
|
|
54
|
-
* top-level `tunnel:` and the first `hostname:` under `ingress:`. Pulling in a
|
|
55
|
-
* parser for two scalars would be a dependency the rest of the server does not
|
|
56
|
-
* have, and a malformed file must degrade to "not configured" rather than throw.
|
|
57
|
-
*/
|
|
58
|
-
export function readCloudflaredConfig(file: string): CloudflaredConfig | null {
|
|
59
|
-
let text: string;
|
|
60
|
-
try {
|
|
61
|
-
text = fs.readFileSync(file, 'utf8');
|
|
62
|
-
} catch {
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
let tunnel: string | null = null;
|
|
67
|
-
let hostname: string | null = null;
|
|
68
|
-
let inIngress = false;
|
|
69
|
-
for (const rawLine of text.split('\n')) {
|
|
70
|
-
const line = rawLine.replace(/\s+#.*$/, '');
|
|
71
|
-
if (/^tunnel:\s*/.test(line)) {
|
|
72
|
-
tunnel = line.replace(/^tunnel:\s*/, '').trim().replace(/^["']|["']$/g, '') || null;
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
if (/^ingress:\s*$/.test(line)) {
|
|
76
|
-
inIngress = true;
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
if (inIngress && /^\S/.test(line)) {
|
|
80
|
-
// A new top-level key ends the ingress block.
|
|
81
|
-
inIngress = false;
|
|
82
|
-
}
|
|
83
|
-
if (inIngress && hostname === null) {
|
|
84
|
-
const match = /^\s*-\s*hostname:\s*(\S+)/.exec(line) ?? /^\s*hostname:\s*(\S+)/.exec(line);
|
|
85
|
-
if (match?.[1]) hostname = match[1].replace(/^["']|["']$/g, '');
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (!tunnel && !hostname) return null;
|
|
90
|
-
return { tunnel, hostname };
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/** Locate the binary and a usable config. */
|
|
94
|
-
export function findCloudflared(): CloudflaredPresence {
|
|
39
|
+
/** Locate the binary and read the config at `configPath`. */
|
|
40
|
+
export function findCloudflared(configPath: string): CloudflaredPresence {
|
|
95
41
|
const binary = which('cloudflared');
|
|
96
|
-
const configPath = cloudflaredConfigPath();
|
|
97
42
|
if (!binary) {
|
|
98
43
|
return {
|
|
99
44
|
binary: null,
|
|
@@ -122,6 +67,8 @@ export function findCloudflared(): CloudflaredPresence {
|
|
|
122
67
|
interface RunningTunnel {
|
|
123
68
|
proc: Bun.Subprocess<'ignore', 'ignore', 'pipe'>;
|
|
124
69
|
url: string;
|
|
70
|
+
/** The temporary directory holding the derived config. */
|
|
71
|
+
runtimeDir: string;
|
|
125
72
|
}
|
|
126
73
|
|
|
127
74
|
declare global {
|
|
@@ -134,6 +81,14 @@ function running(): Map<number, RunningTunnel> {
|
|
|
134
81
|
return globalThis.__kabmoCloudflared;
|
|
135
82
|
}
|
|
136
83
|
|
|
84
|
+
function removeRuntimeDir(dir: string): void {
|
|
85
|
+
try {
|
|
86
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
87
|
+
} catch {
|
|
88
|
+
// A directory the process cannot remove is not worth failing a stop over.
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
137
92
|
/** The public origin of a running tunnel for `port`, or null. */
|
|
138
93
|
export function runningTunnelUrl(port: number): string | null {
|
|
139
94
|
return running().get(port)?.url ?? null;
|
|
@@ -142,9 +97,9 @@ export function runningTunnelUrl(port: number): string | null {
|
|
|
142
97
|
/**
|
|
143
98
|
* Start the named tunnel for `port`.
|
|
144
99
|
*
|
|
145
|
-
*
|
|
146
|
-
* instance's port
|
|
147
|
-
*
|
|
100
|
+
* cloudflared runs a copy of the config whose ingress `service:` is this
|
|
101
|
+
* instance's port — see `deriveCloudflaredRunConfig` for why `--url` cannot do
|
|
102
|
+
* that job. The copy is deleted when the process exits or is stopped.
|
|
148
103
|
*/
|
|
149
104
|
export async function startCloudflared(
|
|
150
105
|
binary: string,
|
|
@@ -156,16 +111,46 @@ export async function startCloudflared(
|
|
|
156
111
|
return { ok: true, url: runningTunnelUrl(port), reason: null };
|
|
157
112
|
}
|
|
158
113
|
|
|
114
|
+
let text: string;
|
|
115
|
+
try {
|
|
116
|
+
text = fs.readFileSync(configPath, 'utf8');
|
|
117
|
+
} catch {
|
|
118
|
+
return { ok: false, url: null, reason: `Could not read the cloudflared config at ${configPath}.` };
|
|
119
|
+
}
|
|
120
|
+
const derived = deriveCloudflaredRunConfig(text, port);
|
|
121
|
+
if (!derived) {
|
|
122
|
+
return {
|
|
123
|
+
ok: false,
|
|
124
|
+
url: null,
|
|
125
|
+
reason: `The config at ${configPath} has no ingress rule with a hostname to point at port ${port}.`,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
let runtimeDir: string;
|
|
130
|
+
let runConfigPath: string;
|
|
131
|
+
try {
|
|
132
|
+
runtimeDir = fs.mkdtempSync(path.join(os.tmpdir(), 'kabmo-cloudflared-'));
|
|
133
|
+
runConfigPath = path.join(runtimeDir, 'config.yml');
|
|
134
|
+
fs.writeFileSync(runConfigPath, derived, { mode: 0o600 });
|
|
135
|
+
} catch (error) {
|
|
136
|
+
return {
|
|
137
|
+
ok: false,
|
|
138
|
+
url: null,
|
|
139
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
159
143
|
let proc: Bun.Subprocess<'ignore', 'ignore', 'pipe'>;
|
|
160
144
|
try {
|
|
161
145
|
proc = Bun.spawn({
|
|
162
|
-
cmd: [binary, 'tunnel', '--config',
|
|
146
|
+
cmd: [binary, 'tunnel', '--config', runConfigPath, 'run'],
|
|
163
147
|
stdin: 'ignore',
|
|
164
148
|
stdout: 'ignore',
|
|
165
149
|
stderr: 'pipe',
|
|
166
150
|
env: { ...Bun.env },
|
|
167
151
|
});
|
|
168
152
|
} catch (error) {
|
|
153
|
+
removeRuntimeDir(runtimeDir);
|
|
169
154
|
return {
|
|
170
155
|
ok: false,
|
|
171
156
|
url: null,
|
|
@@ -174,12 +159,13 @@ export async function startCloudflared(
|
|
|
174
159
|
}
|
|
175
160
|
|
|
176
161
|
const url = `https://${hostname}`;
|
|
177
|
-
running().set(port, { proc, url });
|
|
162
|
+
running().set(port, { proc, url, runtimeDir });
|
|
178
163
|
|
|
179
164
|
// The process is long-lived; a failure after this point is reported by the
|
|
180
165
|
// status read (the process is gone), not by this call.
|
|
181
166
|
proc.exited.then(() => {
|
|
182
167
|
running().delete(port);
|
|
168
|
+
removeRuntimeDir(runtimeDir);
|
|
183
169
|
});
|
|
184
170
|
|
|
185
171
|
return { ok: true, url, reason: null };
|
|
@@ -195,6 +181,7 @@ export function stopCloudflared(port: number): { ok: boolean; reason: string | n
|
|
|
195
181
|
// Already gone.
|
|
196
182
|
}
|
|
197
183
|
running().delete(port);
|
|
184
|
+
removeRuntimeDir(entry.runtimeDir);
|
|
198
185
|
return { ok: true, reason: null };
|
|
199
186
|
}
|
|
200
187
|
|
|
@@ -37,6 +37,16 @@ export interface PendingPairing {
|
|
|
37
37
|
secretHash: string;
|
|
38
38
|
candidates: ConnectCandidate[];
|
|
39
39
|
expiresAt: number;
|
|
40
|
+
/**
|
|
41
|
+
* The code as a downloadable PNG, drawn once when the code is minted.
|
|
42
|
+
*
|
|
43
|
+
* Held here because the download is an HTTP request from a shell's own
|
|
44
|
+
* download machinery (or the browser), which can only carry the session
|
|
45
|
+
* cookie — it cannot run the page's renderer. The secret is not stored in a
|
|
46
|
+
* form that can be replayed as a credential, and the bytes carry the same
|
|
47
|
+
* five-minute life as everything else in this entry.
|
|
48
|
+
*/
|
|
49
|
+
qrPng: Uint8Array | null;
|
|
40
50
|
}
|
|
41
51
|
|
|
42
52
|
declare global {
|
|
@@ -76,10 +86,33 @@ export function createPairing(candidates: ConnectCandidate[]): {
|
|
|
76
86
|
secretHash: hashSecret(secret),
|
|
77
87
|
candidates,
|
|
78
88
|
expiresAt,
|
|
89
|
+
qrPng: null,
|
|
79
90
|
});
|
|
80
91
|
return { pairingId, secret, expiresAt: new Date(expiresAt).toISOString() };
|
|
81
92
|
}
|
|
82
93
|
|
|
94
|
+
/**
|
|
95
|
+
* Attach the rendered PNG to a pending code.
|
|
96
|
+
*
|
|
97
|
+
* Separate from `createPairing` because the image encodes the browser link,
|
|
98
|
+
* which needs the secret that minting has just produced — the route is the only
|
|
99
|
+
* place that has both.
|
|
100
|
+
*/
|
|
101
|
+
export function attachPairingQr(pairingId: string, png: Uint8Array): void {
|
|
102
|
+
const entry = store().get(pairingId);
|
|
103
|
+
if (!entry) return;
|
|
104
|
+
entry.qrPng = png;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** The code's PNG, or null when it was never drawn, expired, or was used. */
|
|
108
|
+
export function pairingQr(pairingId: string): Uint8Array | null {
|
|
109
|
+
const now = Date.now();
|
|
110
|
+
sweep(now);
|
|
111
|
+
const entry = store().get(pairingId);
|
|
112
|
+
if (!entry || entry.expiresAt <= now) return null;
|
|
113
|
+
return entry.qrPng;
|
|
114
|
+
}
|
|
115
|
+
|
|
83
116
|
/**
|
|
84
117
|
* Consume a pairing, or answer why it cannot be consumed.
|
|
85
118
|
*
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The pairing QR as a PNG.
|
|
8
|
+
*
|
|
9
|
+
* Two properties decide whether a downloaded file is usable, and neither is
|
|
10
|
+
* visible in an assertion about "a file was produced":
|
|
11
|
+
*
|
|
12
|
+
* - **It is a real PNG.** The first attempt handed the user an SVG, which most
|
|
13
|
+
* image viewers refuse to open — the button looked like it worked and the file
|
|
14
|
+
* was unreadable.
|
|
15
|
+
* - **It still decodes.** The pixels are read back from the encoded bytes (IHDR,
|
|
16
|
+
* the inflate of IDAT, the packed 1-bit rows) and fed to the same `jsQR` the
|
|
17
|
+
* login screen uses. That is the decoder the scan path runs, not a restatement
|
|
18
|
+
* of the encoder.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { describe, expect, test } from 'bun:test';
|
|
22
|
+
import { inflateSync } from 'node:zlib';
|
|
23
|
+
import jsQR from 'jsqr';
|
|
24
|
+
import { qrPng } from '@/server/lib/connect/qr-png.server';
|
|
25
|
+
import { qrMatrix } from '@/server/lib/connect/qr.server';
|
|
26
|
+
|
|
27
|
+
const PAYLOAD = 'https://kabmo.example/pair#eyJwYWlyaW5nSWQiOiJhYmMifQ';
|
|
28
|
+
|
|
29
|
+
/** Read the encoded PNG back into RGBA, the way an image viewer would. */
|
|
30
|
+
function pixelsOf(png: Uint8Array): { data: Uint8ClampedArray; width: number; height: number } {
|
|
31
|
+
const view = new DataView(png.buffer, png.byteOffset, png.byteLength);
|
|
32
|
+
let offset = 8;
|
|
33
|
+
let width = 0;
|
|
34
|
+
let height = 0;
|
|
35
|
+
const idat: Uint8Array[] = [];
|
|
36
|
+
while (offset + 8 <= png.byteLength) {
|
|
37
|
+
const length = view.getUint32(offset);
|
|
38
|
+
const type = new TextDecoder().decode(png.subarray(offset + 4, offset + 8));
|
|
39
|
+
const data = png.subarray(offset + 8, offset + 8 + length);
|
|
40
|
+
if (type === 'IHDR') {
|
|
41
|
+
width = view.getUint32(offset + 8);
|
|
42
|
+
height = view.getUint32(offset + 12);
|
|
43
|
+
expect(data[8]).toBe(1); // bit depth
|
|
44
|
+
expect(data[9]).toBe(0); // greyscale
|
|
45
|
+
}
|
|
46
|
+
if (type === 'IDAT') idat.push(data);
|
|
47
|
+
offset += 12 + length;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const rowBytes = Math.ceil(width / 8);
|
|
51
|
+
const raw = inflateSync(Buffer.concat(idat));
|
|
52
|
+
const rgba = new Uint8ClampedArray(width * height * 4);
|
|
53
|
+
for (let y = 0; y < height; y += 1) {
|
|
54
|
+
const start = y * (rowBytes + 1);
|
|
55
|
+
expect(raw[start]).toBe(0); // filter: none
|
|
56
|
+
for (let x = 0; x < width; x += 1) {
|
|
57
|
+
const dark = (raw[start + 1 + (x >> 3)]! & (0x80 >> (x & 7))) === 0;
|
|
58
|
+
const value = dark ? 0 : 255;
|
|
59
|
+
const index = (y * width + x) * 4;
|
|
60
|
+
rgba[index] = value;
|
|
61
|
+
rgba[index + 1] = value;
|
|
62
|
+
rgba[index + 2] = value;
|
|
63
|
+
rgba[index + 3] = 255;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return { data: rgba, width, height };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
describe('pairing QR PNG', () => {
|
|
70
|
+
test('is a PNG whose pixels still decode to the payload', () => {
|
|
71
|
+
const matrix = qrMatrix(PAYLOAD);
|
|
72
|
+
const png = qrPng(matrix);
|
|
73
|
+
|
|
74
|
+
// The signature is what a viewer sniffs; a viewer that refuses the file says
|
|
75
|
+
// nothing about the pixels, so this is checked before decoding.
|
|
76
|
+
expect([...png.subarray(0, 8)]).toEqual([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
77
|
+
|
|
78
|
+
const { data, width, height } = pixelsOf(png);
|
|
79
|
+
// Four modules of quiet zone on each side, ten pixels per module.
|
|
80
|
+
expect(width).toBe((matrix.size + 8) * 10);
|
|
81
|
+
expect(height).toBe(width);
|
|
82
|
+
expect(jsQR(data, width, height)?.data).toBe(PAYLOAD);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('keeps a quiet zone, which is what a scanner needs to find the code at all', () => {
|
|
86
|
+
const png = qrPng(qrMatrix(PAYLOAD));
|
|
87
|
+
const { data, width } = pixelsOf(png);
|
|
88
|
+
// The first module starts at 40 px; the border must still be paper.
|
|
89
|
+
for (let x = 0; x < 40; x += 1) {
|
|
90
|
+
expect(data[(10 * width + x) * 4]).toBe(255);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The pairing QR as a PNG the user can open anywhere.
|
|
8
|
+
*
|
|
9
|
+
* The browser draws the code from the same matrix, but a SAVED code has to
|
|
10
|
+
* survive leaving the page: an SVG is unreadable to most image viewers and
|
|
11
|
+
* preview panes, so the file handed to the operating system is a raster PNG at
|
|
12
|
+
* an integer number of pixels per module. PNG is lossless, so the saved pixels
|
|
13
|
+
* are exactly the drawn ones — no resampling of module edges, which is what a
|
|
14
|
+
* binarizer cannot read.
|
|
15
|
+
*
|
|
16
|
+
* Written by hand rather than through an image library: the server already has
|
|
17
|
+
* the module matrix, and the encoding is a signature, three chunks and a zlib
|
|
18
|
+
* stream. `Bun.Image` can only START from an encoded image, so it would need a
|
|
19
|
+
* second format (a BMP) as an intermediate — two encoders for one picture.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { deflateSync } from 'node:zlib';
|
|
23
|
+
import type { QrMatrix } from '@/shared/lib/connect/types';
|
|
24
|
+
|
|
25
|
+
/** Four modules of margin, which is what a scanner requires. */
|
|
26
|
+
const QUIET_ZONE = 4;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Pixels per module in the saved file.
|
|
30
|
+
*
|
|
31
|
+
* A code shown on screen needs ~4 px per module for a camera to read it
|
|
32
|
+
* (`jsQR` failed on 3 px captures); a FILE is often uploaded from a device with
|
|
33
|
+
* no camera, so the margin is doubled — a larger file cannot be too small to
|
|
34
|
+
* scan.
|
|
35
|
+
*/
|
|
36
|
+
const MODULE_PX = 10;
|
|
37
|
+
|
|
38
|
+
const SIGNATURE = Uint8Array.of(0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a);
|
|
39
|
+
|
|
40
|
+
const CRC_TABLE = (() => {
|
|
41
|
+
const table = new Uint32Array(256);
|
|
42
|
+
for (let n = 0; n < 256; n += 1) {
|
|
43
|
+
let c = n;
|
|
44
|
+
for (let bit = 0; bit < 8; bit += 1) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
|
|
45
|
+
table[n] = c >>> 0;
|
|
46
|
+
}
|
|
47
|
+
return table;
|
|
48
|
+
})();
|
|
49
|
+
|
|
50
|
+
function crc32(bytes: Uint8Array): number {
|
|
51
|
+
let c = 0xffffffff;
|
|
52
|
+
for (const byte of bytes) c = (CRC_TABLE[(c ^ byte) & 0xff]! ^ (c >>> 8)) >>> 0;
|
|
53
|
+
return (c ^ 0xffffffff) >>> 0;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function chunk(type: string, data: Uint8Array): Uint8Array {
|
|
57
|
+
const typeBytes = new TextEncoder().encode(type);
|
|
58
|
+
const out = new Uint8Array(12 + data.length);
|
|
59
|
+
const view = new DataView(out.buffer);
|
|
60
|
+
view.setUint32(0, data.length);
|
|
61
|
+
out.set(typeBytes, 4);
|
|
62
|
+
out.set(data, 8);
|
|
63
|
+
view.setUint32(8 + data.length, crc32(out.subarray(4, 8 + data.length)));
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* A 1-bit greyscale PNG: white paper, black modules.
|
|
69
|
+
*
|
|
70
|
+
* 1 bit per pixel, not 8: the image is two colours, the packing keeps the file
|
|
71
|
+
* a few kilobytes, and nothing between here and the scanner resamples it.
|
|
72
|
+
*/
|
|
73
|
+
export function qrPng(matrix: QrMatrix): Uint8Array<ArrayBuffer> {
|
|
74
|
+
const span = matrix.size + QUIET_ZONE * 2;
|
|
75
|
+
const edge = span * MODULE_PX;
|
|
76
|
+
const rowBytes = Math.ceil(edge / 8);
|
|
77
|
+
// One filter byte per scanline, then the packed pixels.
|
|
78
|
+
const raw = new Uint8Array((rowBytes + 1) * edge);
|
|
79
|
+
for (let y = 0; y < edge; y += 1) {
|
|
80
|
+
const start = y * (rowBytes + 1);
|
|
81
|
+
raw[start] = 0; // filter: none
|
|
82
|
+
raw.fill(0xff, start + 1, start + 1 + rowBytes); // paper
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
for (let row = 0; row < matrix.size; row += 1) {
|
|
86
|
+
const line = matrix.rows[row] ?? '';
|
|
87
|
+
for (let column = 0; column < matrix.size; column += 1) {
|
|
88
|
+
if (line[column] !== '1') continue;
|
|
89
|
+
const top = (row + QUIET_ZONE) * MODULE_PX;
|
|
90
|
+
const left = (column + QUIET_ZONE) * MODULE_PX;
|
|
91
|
+
for (let y = top; y < top + MODULE_PX; y += 1) {
|
|
92
|
+
const offset = y * (rowBytes + 1) + 1;
|
|
93
|
+
for (let x = left; x < left + MODULE_PX; x += 1) {
|
|
94
|
+
raw[offset + (x >> 3)]! &= ~(0x80 >> (x & 7));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const header = new Uint8Array(13);
|
|
101
|
+
const view = new DataView(header.buffer);
|
|
102
|
+
view.setUint32(0, edge);
|
|
103
|
+
view.setUint32(4, edge);
|
|
104
|
+
header[8] = 1; // bit depth
|
|
105
|
+
header[9] = 0; // colour type: greyscale
|
|
106
|
+
header[10] = 0; // compression: deflate
|
|
107
|
+
header[11] = 0; // filter method: adaptive
|
|
108
|
+
header[12] = 0; // interlace: none
|
|
109
|
+
|
|
110
|
+
const parts = [SIGNATURE, chunk('IHDR', header), chunk('IDAT', deflateSync(raw)), chunk('IEND', new Uint8Array(0))];
|
|
111
|
+
const total = parts.reduce((sum, part) => sum + part.length, 0);
|
|
112
|
+
const out = new Uint8Array(total);
|
|
113
|
+
let offset = 0;
|
|
114
|
+
for (const part of parts) {
|
|
115
|
+
out.set(part, offset);
|
|
116
|
+
offset += part.length;
|
|
117
|
+
}
|
|
118
|
+
return out;
|
|
119
|
+
}
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
findCloudflared,
|
|
32
32
|
runningTunnelUrl,
|
|
33
33
|
} from '@/server/lib/connect/cloudflared.server';
|
|
34
|
+
import { resolveCloudflaredConfigPath } from '@/server/lib/connect/cloudflared-config.server';
|
|
34
35
|
import type {
|
|
35
36
|
ConnectAddress,
|
|
36
37
|
ConnectStatus,
|
|
@@ -112,8 +113,8 @@ async function tailscaleState(): Promise<{ tunnel: TunnelState; address: Connect
|
|
|
112
113
|
};
|
|
113
114
|
}
|
|
114
115
|
|
|
115
|
-
function cloudflareState(port: number): { tunnel: TunnelState; address: ConnectAddress | null } {
|
|
116
|
-
const presence = findCloudflared();
|
|
116
|
+
function cloudflareState(port: number, configPath: string): { tunnel: TunnelState; address: ConnectAddress | null } {
|
|
117
|
+
const presence = findCloudflared(configPath);
|
|
117
118
|
if (presence.reason || !presence.binary || !presence.configPath) {
|
|
118
119
|
const reason = presence.reason ?? 'cloudflared is not configured.';
|
|
119
120
|
return {
|
|
@@ -148,8 +149,12 @@ function cloudflareState(port: number): { tunnel: TunnelState; address: ConnectA
|
|
|
148
149
|
/** The whole page's payload. */
|
|
149
150
|
export async function connectStatus(): Promise<ConnectStatus> {
|
|
150
151
|
const port = currentPort();
|
|
151
|
-
const [tailscale, devices] = await Promise.all([
|
|
152
|
-
|
|
152
|
+
const [tailscale, devices, configPath] = await Promise.all([
|
|
153
|
+
tailscaleState(),
|
|
154
|
+
listPairedDevices(),
|
|
155
|
+
resolveCloudflaredConfigPath(),
|
|
156
|
+
]);
|
|
157
|
+
const cloudflare = cloudflareState(port, configPath);
|
|
153
158
|
|
|
154
159
|
const lanReachable = boundBeyondLoopback();
|
|
155
160
|
const lan: ConnectAddress[] = lanOrigins(port).map((url) => ({
|
|
@@ -172,6 +177,7 @@ export async function connectStatus(): Promise<ConnectStatus> {
|
|
|
172
177
|
version: pkg.version,
|
|
173
178
|
addresses,
|
|
174
179
|
tunnels: [tailscale.tunnel, cloudflare.tunnel],
|
|
180
|
+
cloudflareConfigPath: configPath,
|
|
175
181
|
devices,
|
|
176
182
|
};
|
|
177
183
|
}
|
|
@@ -3,6 +3,7 @@ import * as connectStatus from '@/server/routes/connect/status';
|
|
|
3
3
|
import * as connectTunnels from '@/server/routes/connect/tunnels';
|
|
4
4
|
import * as connectDevices from '@/server/routes/connect/devices';
|
|
5
5
|
import * as connectPair from '@/server/routes/connect/pair';
|
|
6
|
+
import * as connectPairQr from '@/server/routes/connect/pair-qr';
|
|
6
7
|
import * as connectPairPage from '@/server/routes/connect/pair-page';
|
|
7
8
|
|
|
8
9
|
export const connectBindings: HandlerBinding[] = [
|
|
@@ -10,6 +11,7 @@ export const connectBindings: HandlerBinding[] = [
|
|
|
10
11
|
...bindingsFor(connectTunnels, '/api/connect/tunnels'),
|
|
11
12
|
...bindingsFor(connectDevices, '/api/connect/devices'),
|
|
12
13
|
...bindingsFor(connectPair, '/api/connect/pair'),
|
|
14
|
+
...bindingsFor(connectPairQr, '/api/connect/pair/qr.png'),
|
|
13
15
|
...bindingsFor(connectPair, '/api/connect/pair/claim'),
|
|
14
16
|
...bindingsFor(connectPairPage, '/pair'),
|
|
15
17
|
];
|