bostr/bostr_cli.js
Yonle ce0533cc6e RELEASE: 2.0.8
Small and useful improvements and a little bit touch on moderations.

- Improvements on receiving new events in save mode (a.k.a. pause_on_limit)

Firewall / moderation things:
- A way to block an event owner's pubkey to have the event published
  into your bouncer. Useful to stop annoying actors to abuse your
  bouncer or in moderated nostr relay.

- Ability to block an IP address to connect into the bouncer's websocket.
  Useful to stop scrappers to constantly dig in your bouncer

I am not going to focus much on moderation however. So please bear in mind
that if you ask too much to add moderation stuffs into bostr, It will be
an different project. Because that's not what the goal of this project
for.

As of now i am still focusing to improve the save mode (pause_on_limit).

Signed-off-by: Yonle <yonle@lecturify.net>
2024-03-01 12:04:05 +07:00

90 lines
2.9 KiB
JavaScript
Executable File

#!/usr/bin/env node
"use strict";
const { version } = require("./package.json");
const { nip19 } = require("nostr-tools")
const fs = require("fs");
const cluster = require("cluster");
const argv = process.argv.slice(2);
if (cluster.isPrimary) console.log(`Bostr ${version}\n`);
function showHelp() {
console.log(
"Usage: bostr [command] (argv)\n" +
"Available command:\n" +
" makeconf [conffile] - Make config file\n" +
" checkconf [conffile] - Check config file\n" +
" start [conffile] - Run bostr with specified config\n" +
" hexconverter [nip19] - Convert NIP-19 string to hex\n" +
" help - Show this help text\n\n" +
"Software is licensed under BSD-3-Clause\n" +
"https://github.com/Yonle/bostr"
);
}
function readPath(p) {
return p.startsWith("/") ? p : process.cwd() + "/" + p;
}
switch (argv[0]) {
case "makeconf":
if (!argv[1]) return console.log("Usage: bostr makeconf [conffile]");
if (fs.existsSync(argv[1])) {
console.error("The specified config already exists.");
return process.exit(8);
}
fs.copyFileSync(__dirname + "/config.js.example", argv[1]);
console.log(`Succesfully copied example config file into ${argv[1]}`);
console.log(`Edit ${argv[1]} with your editor and start with the following command:`);
console.log(` $ bostr start ${argv[1]}\n`);
break;
case "checkconf": {
if (!argv[1]) return console.log("Usage: bostr checkconf [conffile]");
if (!fs.existsSync(argv[1])) {
console.error("Config not exists.");
return process.exit(254);
}
const masterConf = Object.keys(require("./config.js.example"));
const currentConf = Object.keys(require(readPath(argv[1])));
const unknown = currentConf.filter(i => !masterConf.includes(i))
const missing = masterConf.filter(i => !currentConf.includes(i))
if (unknown.length) console.log("Unknown Field:\n- " + unknown.join("\n- "));
if (missing.length) {
console.log("Missing Field:\n- " + missing.join("\n- "));
console.log("\nPlease check your config and recheck again.");
return process.exit(1);
} else {
console.log("\nNo config changes needed.");
}
break;
}
case "start":
if (!argv[1]) return console.log("Usage: bostr start [conffile]");
if (!fs.existsSync(argv[1])) {
console.error("Config not exists.");
return process.exit(254);
}
process.env.BOSTR_CONFIG_PATH = readPath(argv[1]);
require("./index.js");
break;
case "hexconverter":
if (!argv[1]) return console.log("Usage: bostr hexconverter [npub|nsec|....] ....");
for (const i of argv.slice(1)) {
console.log(nip19.decode(i).data);
}
break;
default:
if (argv[0] && (argv[0] !== "help")) {
console.error("Unrecognized command:", argv[0]);
return process.exit(100)
}
showHelp();
process.exit(1);
break;
}