operserv: REHASH announces the reload in the log channel via DebugServ
All checks were successful
CI / check (push) Successful in 4m1s
All checks were successful
CI / check (push) Successful in 4m1s
This commit is contained in:
parent
64b675e61f
commit
e3b83f4a92
2 changed files with 62 additions and 16 deletions
|
|
@ -804,14 +804,23 @@ impl Engine {
|
|||
// keycard endpoint are NOT reloadable — they need a restart.
|
||||
pub fn rehash(&mut self, requester: &str, agent: &str) -> Vec<NetAction> {
|
||||
let path = self.config_path.clone();
|
||||
// Who ran it, for the DebugServ log-channel line (account, else nick).
|
||||
let oper = self
|
||||
.network
|
||||
.account_of(requester)
|
||||
.or_else(|| self.network.nick_of(requester))
|
||||
.unwrap_or("an operator")
|
||||
.to_string();
|
||||
let notice = |text: String| NetAction::Notice { from: agent.to_string(), to: requester.to_string(), text };
|
||||
let cfg = match crate::config::Config::load(&path) {
|
||||
Ok(cfg) => cfg,
|
||||
Err(e) => {
|
||||
return vec![NetAction::Notice {
|
||||
from: agent.to_string(),
|
||||
to: requester.to_string(),
|
||||
text: format!("REHASH failed: {e}. The running configuration is unchanged."),
|
||||
}];
|
||||
let mut out = Vec::new();
|
||||
if let Some(line) = self.feed("OPER", format!("\x02{oper}\x02 ran \x02REHASH\x02 · config.toml failed to parse, keeping the running config · {e}")) {
|
||||
out.push(line);
|
||||
}
|
||||
out.push(notice(format!("REHASH failed: {e}. The running configuration is unchanged.")));
|
||||
return out;
|
||||
}
|
||||
};
|
||||
let opers = cfg.opers();
|
||||
|
|
@ -828,17 +837,21 @@ impl Engine {
|
|||
if let Some(session) = &cfg.session {
|
||||
self.set_session_limit(session.limit());
|
||||
}
|
||||
let notice = |text: String| NetAction::Notice { from: agent.to_string(), to: requester.to_string(), text };
|
||||
vec![
|
||||
notice(format!("Configuration reloaded from \x02{path}\x02.")),
|
||||
notice(format!(
|
||||
"Applied: \x02{oper_count}\x02 oper(s), standard-replies \x02{}\x02, services channel \x02{}\x02, service oper-type \x02{}\x02.",
|
||||
if self.standard_replies { "on" } else { "off" },
|
||||
if self.services_channel.is_empty() { "(none)" } else { &self.services_channel },
|
||||
if self.service_oper_type.is_empty() { "(none)" } else { &self.service_oper_type },
|
||||
)),
|
||||
notice("Not reloadable (need a RESTART): server name/SID/protocol, uplink, service umodes, keycard.".to_string()),
|
||||
]
|
||||
let sr = if self.standard_replies { "on" } else { "off" };
|
||||
let chan = if self.services_channel.is_empty() { "(none)" } else { &self.services_channel };
|
||||
let opers_word = if oper_count == 1 { "oper" } else { "opers" };
|
||||
let mut out = Vec::new();
|
||||
// Announce it in the log channel so staff see who reloaded what, when.
|
||||
if let Some(line) = self.feed("OPER", format!("\x02{oper}\x02 reloaded the configuration live · \x02{oper_count}\x02 {opers_word} · standard-replies \x02{sr}\x02 · services \x02{chan}\x02 · no restart needed")) {
|
||||
out.push(line);
|
||||
}
|
||||
out.push(notice(format!("Configuration reloaded from \x02{path}\x02.")));
|
||||
out.push(notice(format!(
|
||||
"Applied: \x02{oper_count}\x02 oper(s), standard-replies \x02{sr}\x02, services channel \x02{chan}\x02, service oper-type \x02{}\x02.",
|
||||
if self.service_oper_type.is_empty() { "(none)" } else { &self.service_oper_type },
|
||||
)));
|
||||
out.push(notice("Not reloadable (need a RESTART): server name/SID/protocol, uplink, service umodes, keycard.".to_string()));
|
||||
out
|
||||
}
|
||||
|
||||
// A user arrived on (or changed to) a registered nick: if they aren't logged
|
||||
|
|
|
|||
|
|
@ -711,6 +711,39 @@
|
|||
assert!(b.iter().any(|x| matches!(x, NetAction::Notice { text, .. } if text.contains("admin"))), "{b:?}");
|
||||
}
|
||||
|
||||
// REHASH re-reads the file, applies the reloadable settings, and announces the
|
||||
// reload in the log channel as a DebugServ feed line.
|
||||
#[test]
|
||||
fn rehash_applies_config_and_announces_in_log_channel() {
|
||||
use echo_operserv::OperServ;
|
||||
let cfgpath = std::env::temp_dir().join("echo-rehash-fixture.toml");
|
||||
std::fs::write(&cfgpath, concat!(
|
||||
"[uplink]\nhost = \"127.0.0.1\"\nport = 7000\npassword = \"x\"\n\n",
|
||||
"[server]\nname = \"services.test\"\nsid = \"42S\"\ndescription = \"t\"\n",
|
||||
"standard_replies = true\nservices_channel = \"#svc\"\n\n",
|
||||
"[log]\nchannel = \"#services\"\n\n",
|
||||
"[[oper]]\naccount = \"reverse\"\nprivs = [\"admin\"]\n",
|
||||
)).unwrap();
|
||||
let path = std::env::temp_dir().join("echo-rehash-eng.jsonl");
|
||||
let _ = std::fs::remove_file(&path);
|
||||
let mut db = Db::open(&path, "test");
|
||||
db.scram_iterations = 4096;
|
||||
let mut e = Engine::new(vec![Box::new(OperServ { uid: "42SAAAAAH".into() })], db);
|
||||
e.set_sid("42S".into());
|
||||
e.set_config_path(cfgpath.to_string_lossy().to_string());
|
||||
e.set_debugserv_uid("42SAAAAAO");
|
||||
e.set_log_channel(Some("#services".to_string()));
|
||||
|
||||
let out = e.rehash("000AAAAAB", "42SAAAAAH");
|
||||
let feed = out.iter().find_map(|a| match a {
|
||||
NetAction::Privmsg { from, to, text } if from == "42SAAAAAO" && to == "#services" => Some(text.clone()),
|
||||
_ => None,
|
||||
}).expect("DebugServ announces the reload in the log channel");
|
||||
assert!(feed.contains("reloaded the configuration"), "{feed}");
|
||||
assert!(feed.contains("#svc"), "the reloaded services channel is applied and shown: {feed}");
|
||||
let _ = std::fs::remove_file(&cfgpath);
|
||||
}
|
||||
|
||||
// A login that finishes off the handle() path (the link layer's deferred
|
||||
// password/keycard verify) must still make echo's OWN account map authoritative.
|
||||
// Otherwise re-identifying an already-logged-in user after a services relink —
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue