OperServ: add SET READONLY lockdown
All checks were successful
CI / check (push) Successful in 3m31s

This commit is contained in:
Jean Chevronnet 2026-07-16 01:05:48 +00:00
parent b2442f85e6
commit 0027decdb7
No known key found for this signature in database
8 changed files with 112 additions and 2 deletions

View file

@ -39,6 +39,8 @@ mod logsearch;
mod defcon;
#[path = "shutdown.rs"]
mod shutdown;
#[path = "set.rs"]
mod set;
pub struct OperServ {
pub uid: String,
@ -90,6 +92,7 @@ impl Service for OperServ {
Some(cmd) if cmd.eq_ignore_ascii_case("CHANKILL") => chankill::handle(me, from, args, ctx, net, db),
Some(cmd) if cmd.eq_ignore_ascii_case("LOGSEARCH") => logsearch::handle(me, from, args, ctx, net),
Some(cmd) if cmd.eq_ignore_ascii_case("DEFCON") => defcon::handle(me, from, args, ctx, db),
Some(cmd) if cmd.eq_ignore_ascii_case("SET") => set::handle(me, from, args, ctx, db),
Some(cmd) if cmd.eq_ignore_ascii_case("SHUTDOWN") => shutdown::handle(me, from, false, args, ctx),
Some(cmd) if cmd.eq_ignore_ascii_case("RESTART") => shutdown::handle(me, from, true, args, ctx),
Some(cmd) if cmd.eq_ignore_ascii_case("HELP") => echo_api::help(me, from, ctx, BLURB, TOPICS, args.get(1).copied()),
@ -125,6 +128,7 @@ const TOPICS: &[HelpEntry] = &[
HelpEntry { cmd: "JUPE", summary: "jupe a server name", detail: "Syntax: \x02JUPE <server.name> [reason] | JUPE DEL <server.name> | JUPE LIST\x02\nBlocks a server name from linking." },
HelpEntry { cmd: "LOGSEARCH", summary: "search the action log", detail: "Syntax: \x02LOGSEARCH [pattern]\x02\nSearches the incident and action log." },
HelpEntry { cmd: "DEFCON", summary: "network defence level", detail: "Syntax: \x02DEFCON [1-5]\x02\nShows or sets the network defence level (5 = normal, 1 = lockdown)." },
HelpEntry { cmd: "SET", summary: "services-wide settings", detail: "Syntax: \x02SET READONLY {ON|OFF}\x02\nToggles read-only lockdown: while on, no registrations or changes are accepted." },
HelpEntry { cmd: "SHUTDOWN", summary: "stop services", detail: "Syntax: \x02SHUTDOWN [reason]\x02\nStops the services process. It stays down until restarted." },
HelpEntry { cmd: "RESTART", summary: "restart services", detail: "Syntax: \x02RESTART [reason]\x02\nRestarts the services process (a supervisor respawns it)." },
];

View file

@ -0,0 +1,35 @@
use echo_api::{Priv, Sender, ServiceCtx, Store};
// SET READONLY {ON|OFF}: put services into (or out of) read-only lockdown.
// While on, no new registrations or changes are accepted; existing data and
// gossip replication keep working. Admin-only. No argument reports the state.
pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db: &mut dyn Store) {
if !from.privs.has(Priv::Admin) {
ctx.notice(me, from.uid, "Access denied — SET is for services operators.");
return;
}
match args.get(1).map(|s| s.to_ascii_uppercase()).as_deref() {
Some("READONLY") => {
let Some(on) = args.get(2).and_then(|s| parse_toggle(s)) else {
let state = if db.readonly() { "ON" } else { "OFF" };
ctx.notice(me, from.uid, format!("READONLY is currently \x02{state}\x02. Syntax: SET READONLY {{ON|OFF}}"));
return;
};
db.set_readonly(on);
if on {
ctx.notice(me, from.uid, "Services are now \x02read-only\x02 — no changes will be accepted.");
} else {
ctx.notice(me, from.uid, "Services are no longer read-only.");
}
}
_ => ctx.notice(me, from.uid, "Syntax: SET READONLY {ON|OFF}"),
}
}
fn parse_toggle(s: &str) -> Option<bool> {
match s.to_ascii_uppercase().as_str() {
"ON" | "TRUE" | "YES" => Some(true),
"OFF" | "FALSE" | "NO" => Some(false),
_ => None,
}
}