2024-07-22 22:24:17 +00:00
|
|
|
use clap::Parser;
|
2024-12-14 21:58:01 -05:00
|
|
|
use conduwuit::Result;
|
2024-07-22 22:24:17 +00:00
|
|
|
|
|
|
|
|
use crate::{
|
2026-01-06 11:13:11 -05:00
|
|
|
appservice::{self, AppserviceCommand},
|
|
|
|
|
check::{self, CheckCommand},
|
|
|
|
|
context::Context,
|
|
|
|
|
debug::{self, DebugCommand},
|
|
|
|
|
federation::{self, FederationCommand},
|
|
|
|
|
media::{self, MediaCommand},
|
|
|
|
|
query::{self, QueryCommand},
|
|
|
|
|
room::{self, RoomCommand},
|
|
|
|
|
server::{self, ServerCommand},
|
|
|
|
|
token::{self, TokenCommand},
|
|
|
|
|
user::{self, UserCommand},
|
2024-07-22 22:24:17 +00:00
|
|
|
};
|
|
|
|
|
|
2024-07-24 00:13:03 +00:00
|
|
|
#[derive(Debug, Parser)]
|
2025-06-24 23:16:48 +01:00
|
|
|
#[command(name = conduwuit_core::name(), version = conduwuit_core::version())]
|
2025-05-24 00:28:09 +01:00
|
|
|
pub enum AdminCommand {
|
2024-07-22 22:24:17 +00:00
|
|
|
#[command(subcommand)]
|
2026-01-12 10:47:19 -05:00
|
|
|
/// Commands for managing appservices
|
2024-07-22 22:24:17 +00:00
|
|
|
Appservices(AppserviceCommand),
|
|
|
|
|
|
|
|
|
|
#[command(subcommand)]
|
2026-01-12 10:47:19 -05:00
|
|
|
/// Commands for managing local users
|
2024-07-22 22:24:17 +00:00
|
|
|
Users(UserCommand),
|
|
|
|
|
|
2026-01-06 11:13:11 -05:00
|
|
|
#[command(subcommand)]
|
2026-01-12 10:47:19 -05:00
|
|
|
/// Commands for managing registration tokens
|
2026-01-06 11:26:05 -05:00
|
|
|
Token(TokenCommand),
|
2026-01-06 11:13:11 -05:00
|
|
|
|
2024-07-22 22:24:17 +00:00
|
|
|
#[command(subcommand)]
|
2026-01-12 10:47:19 -05:00
|
|
|
/// Commands for managing rooms
|
2024-07-22 22:24:17 +00:00
|
|
|
Rooms(RoomCommand),
|
|
|
|
|
|
|
|
|
|
#[command(subcommand)]
|
2026-01-12 10:47:19 -05:00
|
|
|
/// Commands for managing federation
|
2024-07-22 22:24:17 +00:00
|
|
|
Federation(FederationCommand),
|
|
|
|
|
|
|
|
|
|
#[command(subcommand)]
|
2026-01-12 10:47:19 -05:00
|
|
|
/// Commands for managing the server
|
2024-07-22 22:24:17 +00:00
|
|
|
Server(ServerCommand),
|
|
|
|
|
|
|
|
|
|
#[command(subcommand)]
|
2026-01-12 10:47:19 -05:00
|
|
|
/// Commands for managing media
|
2024-07-22 22:24:17 +00:00
|
|
|
Media(MediaCommand),
|
|
|
|
|
|
|
|
|
|
#[command(subcommand)]
|
2026-01-12 10:47:19 -05:00
|
|
|
/// Commands for checking integrity
|
2024-07-22 22:24:17 +00:00
|
|
|
Check(CheckCommand),
|
|
|
|
|
|
|
|
|
|
#[command(subcommand)]
|
2026-01-12 10:47:19 -05:00
|
|
|
/// Commands for debugging things
|
2024-07-22 22:24:17 +00:00
|
|
|
Debug(DebugCommand),
|
|
|
|
|
|
|
|
|
|
#[command(subcommand)]
|
2026-01-12 10:47:19 -05:00
|
|
|
/// Low-level queries for database getters and iterators
|
2024-07-22 22:24:17 +00:00
|
|
|
Query(QueryCommand),
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-04 03:04:37 +00:00
|
|
|
#[tracing::instrument(skip_all, name = "command", level = "info")]
|
2025-04-06 23:41:58 +00:00
|
|
|
pub(super) async fn process(command: AdminCommand, context: &Context<'_>) -> Result {
|
2024-07-27 00:11:41 +00:00
|
|
|
use AdminCommand::*;
|
2024-07-22 22:24:17 +00:00
|
|
|
|
2025-01-04 16:57:07 +00:00
|
|
|
match command {
|
2025-12-30 23:24:06 -05:00
|
|
|
| Appservices(command) => {
|
|
|
|
|
// appservice commands are all restricted
|
|
|
|
|
context.bail_restricted()?;
|
|
|
|
|
appservice::process(command, context).await
|
|
|
|
|
},
|
2025-04-06 23:41:58 +00:00
|
|
|
| Media(command) => media::process(command, context).await,
|
2025-12-30 23:24:06 -05:00
|
|
|
| Users(command) => {
|
|
|
|
|
// user commands are all restricted
|
|
|
|
|
context.bail_restricted()?;
|
|
|
|
|
user::process(command, context).await
|
|
|
|
|
},
|
2026-01-06 11:26:05 -05:00
|
|
|
| Token(command) => {
|
2026-01-06 11:13:11 -05:00
|
|
|
// token commands are all restricted
|
|
|
|
|
context.bail_restricted()?;
|
|
|
|
|
token::process(command, context).await
|
|
|
|
|
},
|
2025-04-06 23:41:58 +00:00
|
|
|
| Rooms(command) => room::process(command, context).await,
|
|
|
|
|
| Federation(command) => federation::process(command, context).await,
|
|
|
|
|
| Server(command) => server::process(command, context).await,
|
|
|
|
|
| Debug(command) => debug::process(command, context).await,
|
2025-12-30 23:24:06 -05:00
|
|
|
| Query(command) => {
|
|
|
|
|
// query commands are all restricted
|
|
|
|
|
context.bail_restricted()?;
|
|
|
|
|
query::process(command, context).await
|
|
|
|
|
},
|
2025-04-06 23:41:58 +00:00
|
|
|
| Check(command) => check::process(command, context).await,
|
2025-02-25 18:38:12 +00:00
|
|
|
}
|
2024-07-22 22:24:17 +00:00
|
|
|
}
|