Files
dark-lord/scripts/onion-status.cjs
drjones e0a4a20862 Tor ops: launch UI, onion list/health scripts, systemd installer, README glow-up
- Replace fake-site footer with dark-web launch CTA; fix HubChatter inside AppProviders (client crash)
- Add /launch, DEPLOY.md, onions:list|status|health, list-onion-urls, install-systemd, onion-status
- start.sh CYBERLUX_PREPARE_ONLY; copy pass on satellite pages; Navbar launch link
- README: operator cheat sheet, phone Tor note, systemd via install-systemd.sh

Made-with: Cursor
2026-04-15 22:12:44 -07:00

110 lines
3.1 KiB
JavaScript

#!/usr/bin/env node
/**
* Lists every Tor hidden-service hostname + nginx loopback URL, and checks
* that each loopback port returns HTTP (proves nginx → Next are up for that vhost).
*
* node scripts/onion-status.cjs
* npm run onions:status
*
* Reading /var/lib/tor/*/hostname usually requires sudo:
* sudo node scripts/onion-status.cjs
*/
"use strict";
const fs = require("fs");
const http = require("http");
const path = require("path");
const REPO = path.join(__dirname, "..");
const jsonPath = path.join(__dirname, "onion-nodes.json");
const data = JSON.parse(fs.readFileSync(jsonPath, "utf8"));
function readOnionHost(torDir) {
const f = path.join("/var/lib/tor", torDir, "hostname");
try {
return fs.readFileSync(f, "utf8").trim();
} catch (e) {
if (e.code === "EACCES" || e.code === "EPERM") {
return "(hostname file exists but not readable — try: sudo node scripts/onion-status.cjs)";
}
if (e.code === "ENOENT") {
return "(no hostname yet — is Tor running?)";
}
return `(${e.message})`;
}
}
function checkLocalPort(port) {
return new Promise((resolve) => {
const req = http.request(
{
hostname: "127.0.0.1",
port,
path: "/",
method: "GET",
timeout: 6000,
headers: { Connection: "close", Host: "127.0.0.1" },
},
(res) => {
res.resume();
resolve(res.statusCode || 0);
},
);
req.on("error", () => resolve(0));
req.on("timeout", () => {
req.destroy();
resolve(0);
});
req.end();
});
}
async function main() {
const rows = [];
for (const n of data.nodes) {
const onion = readOnionHost(n.torDir);
const httpCode = await checkLocalPort(n.port);
const ok = httpCode >= 200 && httpCode < 500;
rows.push({
torDir: n.torDir,
port: n.port,
kind: n.kind,
onion,
httpCode,
ok,
});
}
console.log("");
console.log("CyberLux — onion URLs (from /var/lib/tor/*/hostname) + loopback health");
console.log("─".repeat(100));
let bad = 0;
for (const r of rows) {
const url =
r.onion.startsWith("(") || r.onion.includes("not readable")
? r.onion
: `http://${r.onion}`;
const local = `http://127.0.0.1:${r.port}/`;
const status =
r.httpCode === 0 ? "DOWN/timeout" : `HTTP ${r.httpCode}`;
if (!r.ok) bad++;
console.log(`${r.torDir.padEnd(28)} ${String(r.kind).padEnd(12)} ${String(r.port).padEnd(5)} ${status.padEnd(14)} ${url}`);
console.log(`${"".padEnd(28)} ${"".padEnd(12)} ${"".padEnd(5)} loopback: ${local}`);
console.log("");
}
console.log("─".repeat(100));
if (bad > 0) {
console.log(`${bad} loopback vhost(s) did not return OK HTTP — ensure: systemctl status nginx tor; systemctl status cyberlux`);
process.exit(1);
}
console.log("✓ All loopback nginx vhosts responded (Tor .onion forwarding uses these ports).");
console.log(" To test via the Tor network use Tor Browser (not curl from clearnet).");
process.exit(0);
}
main().catch((e) => {
console.error(e);
process.exit(2);
});