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."),
}
}

View file

@ -15,6 +15,12 @@ mod set;
mod del;
#[path = "list.rs"]
mod list;
#[path = "request.rs"]
mod request;
#[path = "waiting.rs"]
mod waiting;
#[path = "approve.rs"]
mod approve;
pub struct HostServ {
pub uid: String,
@ -39,7 +45,11 @@ impl Service for HostServ {
Some("SET") => set::handle(me, from, args, ctx, net, db),
Some("DEL") => del::handle(me, from, args, ctx, net, db),
Some("LIST") => list::handle(me, from, ctx, db),
Some("HELP") | None => ctx.notice(me, from.uid, "HostServ gives you a vhost: \x02ON\x02 activates your assigned vhost, \x02OFF\x02 restores your normal host. Operators use \x02SET\x02 <account> <host>, \x02DEL\x02 <account> and \x02LIST\x02."),
Some("REQUEST") => request::handle(me, from, args, ctx, db),
Some("WAITING") => waiting::handle(me, from, ctx, db),
Some("ACTIVATE") | Some("APPROVE") => approve::handle(me, from, args, ctx, net, db, true),
Some("REJECT") => approve::handle(me, from, args, ctx, net, db, false),
Some("HELP") | None => ctx.notice(me, from.uid, "HostServ gives you a vhost: \x02ON\x02 activates your assigned vhost, \x02OFF\x02 restores your normal host, \x02REQUEST\x02 <host> asks for one. Operators use \x02SET\x02/\x02DEL\x02 <account>, \x02LIST\x02, and \x02WAITING\x02 + \x02ACTIVATE\x02/\x02REJECT\x02 <account> for requests."),
Some(other) => ctx.notice(me, from.uid, format!("I don't know the command \x02{other}\x02. Try \x02HELP\x02.")),
}
}

21
hostserv/src/request.rs Normal file
View file

@ -0,0 +1,21 @@
use fedserv_api::{Sender, ServiceCtx, Store};
// REQUEST <host>: ask for a vhost, to be approved by an operator.
pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db: &mut dyn Store) {
let Some(account) = from.account else {
ctx.notice(me, from.uid, "You need to identify to NickServ first.");
return;
};
let Some(&host) = args.get(1) else {
ctx.notice(me, from.uid, "Syntax: REQUEST <host>");
return;
};
if !super::valid_vhost(host) {
ctx.notice(me, from.uid, format!("\x02{host}\x02 isn't a valid host (letters, digits, hyphens and dots)."));
return;
}
match db.request_vhost(account, host) {
Ok(()) => ctx.notice(me, from.uid, format!("Requested vhost \x02{host}\x02 — an operator will review it.")),
Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."),
}
}

18
hostserv/src/waiting.rs Normal file
View file

@ -0,0 +1,18 @@
use fedserv_api::{Sender, ServiceCtx, Store};
// WAITING: pending vhost requests awaiting approval. Operators only.
pub fn handle(me: &str, from: &Sender, ctx: &mut ServiceCtx, db: &dyn Store) {
if !super::require_oper(me, from, ctx) {
return;
}
let requests = db.vhost_requests();
if requests.is_empty() {
ctx.notice(me, from.uid, "No vhost requests are waiting.");
return;
}
ctx.notice(me, from.uid, format!("Pending vhost requests ({}):", requests.len()));
for (account, host) in &requests {
ctx.notice(me, from.uid, format!(" \x02{account}\x02{host}"));
}
ctx.notice(me, from.uid, "Approve with \x02ACTIVATE\x02 <account> or turn down with \x02REJECT\x02 <account>.");
}