HostServ: vhost request/approval flow

REQUEST <host> records a pending vhost (typed Option<PendingVhost> on the
account, VhostRequested/VhostRequestCleared events); operators review with
WAITING and either ACTIVATE (assign + apply to online sessions) or REJECT
(clear it). Host validation and the operator gate are shared with SET.
This commit is contained in:
Jean Chevronnet 2026-07-13 21:30:58 +00:00
parent 1227e26b95
commit 1edf250952
No known key found for this signature in database
8 changed files with 217 additions and 4 deletions

38
hostserv/src/approve.rs Normal file
View file

@ -0,0 +1,38 @@
use fedserv_api::{NetView, Sender, ServiceCtx, Store};
// ACTIVATE <account> / REJECT <account>: approve a pending vhost request (setting
// and applying it) or turn it down. Operators only.
pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, net: &dyn NetView, db: &mut dyn Store, activate: bool) {
if !super::require_oper(me, from, ctx) {
return;
}
let Some(&account) = args.get(1) else {
let syntax = if activate { "Syntax: ACTIVATE <account>" } else { "Syntax: REJECT <account>" };
ctx.notice(me, from.uid, syntax);
return;
};
let host = match db.take_vhost_request(account) {
Ok(Some(h)) => h,
Ok(None) => {
ctx.notice(me, from.uid, format!("\x02{account}\x02 has no pending vhost request."));
return;
}
Err(_) => {
ctx.notice(me, from.uid, format!("\x02{account}\x02 isn't registered."));
return;
}
};
if !activate {
ctx.notice(me, from.uid, format!("Rejected \x02{account}\x02's vhost request."));
return;
}
match db.set_vhost(account, &host, from.nick) {
Ok(()) => {
for uid in net.uids_logged_into(account) {
ctx.set_host(&uid, &host);
}
ctx.notice(me, from.uid, format!("Activated vhost \x02{host}\x02 for \x02{account}\x02."));
}
Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."),
}
}