HostServ: temporary vhosts (expiry)

SET <account> <host> [duration] assigns a vhost that lapses after the
duration (e.g. 30d); a Vhost carries an optional expiry and the store hides
an expired one lazily (like a suspension), so it stops applying on identify/
ON without a sweep. LIST flags temporary vhosts.
This commit is contained in:
Jean Chevronnet 2026-07-13 22:53:04 +00:00
parent 87bad7fbcc
commit 271e06fa77
No known key found for this signature in database
8 changed files with 81 additions and 28 deletions

View file

@ -1,13 +1,14 @@
use fedserv_api::{NetView, Sender, ServiceCtx, Store};
use fedserv_api::{parse_duration, NetView, Sender, ServiceCtx, Store};
// SET <account> <host>: assign a vhost to an account, applying it at once to any
// online sessions. Operators only.
// SET <account> <host> [duration]: assign a vhost to an account, applying it at
// once to online sessions. An optional duration (e.g. 30d) makes it temporary.
// Operators only.
pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, net: &dyn NetView, db: &mut dyn Store) {
if !super::require_oper(me, from, ctx) {
return;
}
let (Some(&account), Some(&host)) = (args.get(1), args.get(2)) else {
ctx.notice(me, from.uid, "Syntax: SET <account> <host>");
ctx.notice(me, from.uid, "Syntax: SET <account> <host> [duration]");
return;
};
if !super::valid_vhost(host) {
@ -18,12 +19,14 @@ pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, net:
ctx.notice(me, from.uid, format!("\x02{account}\x02 isn't registered."));
return;
}
match db.set_vhost(account, host, from.nick) {
let ttl = args.get(3).and_then(|s| parse_duration(s));
match db.set_vhost(account, host, from.nick, ttl) {
Ok(()) => {
for uid in net.uids_logged_into(account) {
ctx.apply_vhost(&uid, host);
}
ctx.notice(me, from.uid, format!("Vhost \x02{host}\x02 assigned to \x02{account}\x02."));
let when = args.get(3).filter(|_| ttl.is_some()).map(|d| format!(" (expires in {d})")).unwrap_or_default();
ctx.notice(me, from.uid, format!("Vhost \x02{host}\x02 assigned to \x02{account}\x02{when}."));
}
Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."),
}