mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-05-26 20:49:55 +00:00
7e4071c117
**Does not yet work!** Currently, state resolution does not correctly resolve conflicting states. Everything else appears to work as expected, so stateres will be fixed soon, then we should be clear for takeoff. Also: a lot of things currently accept a nullable room ID that really just don't need to. This will need tidying up before merge. Some authentication checks have also been disabled temporarily but nothing important. A lot of things are tagged with `TODO(hydra)`, those need resolving before merge. External contributors should PR to the `hydra/public` branch, *not* ` main`. --- This PR should be squash merged. Reviewed-on: https://forgejo.ellis.link/continuwuation/continuwuity/pulls/943 Co-authored-by: nexy7574 <git@nexy7574.co.uk> Co-committed-by: nexy7574 <git@nexy7574.co.uk>
156 lines
4.0 KiB
Rust
156 lines
4.0 KiB
Rust
mod ban;
|
|
mod forget;
|
|
mod invite;
|
|
mod join;
|
|
mod kick;
|
|
mod knock;
|
|
mod leave;
|
|
mod members;
|
|
mod unban;
|
|
|
|
use std::net::IpAddr;
|
|
|
|
use axum::extract::State;
|
|
use conduwuit::{Err, Result, warn};
|
|
use futures::{FutureExt, StreamExt};
|
|
use ruma::{OwnedRoomId, RoomId, ServerName, UserId, api::client::membership::joined_rooms};
|
|
use service::Services;
|
|
|
|
pub(crate) use self::{
|
|
ban::ban_user_route,
|
|
forget::forget_room_route,
|
|
invite::{invite_helper, invite_user_route},
|
|
join::{join_room_by_id_or_alias_route, join_room_by_id_route},
|
|
kick::kick_user_route,
|
|
knock::knock_room_route,
|
|
leave::leave_room_route,
|
|
members::{get_member_events_route, joined_members_route},
|
|
unban::unban_user_route,
|
|
};
|
|
pub use self::{
|
|
join::join_room_by_id_helper,
|
|
leave::{leave_all_rooms, leave_room, remote_leave_room},
|
|
};
|
|
use crate::{Ruma, client::full_user_deactivate};
|
|
|
|
/// # `POST /_matrix/client/r0/joined_rooms`
|
|
///
|
|
/// Lists all rooms the user has joined.
|
|
pub(crate) async fn joined_rooms_route(
|
|
State(services): State<crate::State>,
|
|
body: Ruma<joined_rooms::v3::Request>,
|
|
) -> Result<joined_rooms::v3::Response> {
|
|
Ok(joined_rooms::v3::Response {
|
|
joined_rooms: services
|
|
.rooms
|
|
.state_cache
|
|
.rooms_joined(body.sender_user())
|
|
.map(ToOwned::to_owned)
|
|
.collect()
|
|
.await,
|
|
})
|
|
}
|
|
|
|
/// Checks if the room is banned in any way possible and the sender user is not
|
|
/// an admin.
|
|
///
|
|
/// Performs automatic deactivation if `auto_deactivate_banned_room_attempts` is
|
|
/// enabled
|
|
#[tracing::instrument(skip(services))]
|
|
pub(crate) async fn banned_room_check(
|
|
services: &Services,
|
|
user_id: &UserId,
|
|
room_id: Option<&RoomId>,
|
|
server_name: Option<&ServerName>,
|
|
client_ip: IpAddr,
|
|
) -> Result {
|
|
if services.users.is_admin(user_id).await {
|
|
return Ok(());
|
|
}
|
|
|
|
if let Some(room_id) = room_id {
|
|
let room_banned = services.rooms.metadata.is_banned(room_id).await;
|
|
let server_banned = room_id.server_name().is_some_and(|server_name| {
|
|
services.moderation.is_remote_server_forbidden(server_name)
|
|
});
|
|
if room_banned || server_banned {
|
|
warn!(
|
|
"User {user_id} who is not an admin attempted to send an invite for or \
|
|
attempted to join a banned room or banned room server name: {room_id}"
|
|
);
|
|
|
|
if services.server.config.auto_deactivate_banned_room_attempts {
|
|
warn!(
|
|
"Automatically deactivating user {user_id} due to attempted banned room join"
|
|
);
|
|
|
|
if services.server.config.admin_room_notices {
|
|
services
|
|
.admin
|
|
.send_text(&format!(
|
|
"Automatically deactivating user {user_id} due to attempted banned \
|
|
room join from IP {client_ip}"
|
|
))
|
|
.await;
|
|
}
|
|
|
|
let all_joined_rooms: Vec<OwnedRoomId> = services
|
|
.rooms
|
|
.state_cache
|
|
.rooms_joined(user_id)
|
|
.map(Into::into)
|
|
.collect()
|
|
.await;
|
|
|
|
full_user_deactivate(services, user_id, &all_joined_rooms)
|
|
.boxed()
|
|
.await?;
|
|
}
|
|
return Err!(Request(Forbidden("This room is banned on this homeserver.")));
|
|
}
|
|
} else if let Some(server_name) = server_name {
|
|
if services
|
|
.config
|
|
.forbidden_remote_server_names
|
|
.is_match(server_name.host())
|
|
{
|
|
warn!(
|
|
"User {user_id} who is not an admin tried joining a room which has the server \
|
|
name {server_name} that is globally forbidden. Rejecting.",
|
|
);
|
|
|
|
if services.server.config.auto_deactivate_banned_room_attempts {
|
|
warn!(
|
|
"Automatically deactivating user {user_id} due to attempted banned room join"
|
|
);
|
|
|
|
if services.server.config.admin_room_notices {
|
|
services
|
|
.admin
|
|
.send_text(&format!(
|
|
"Automatically deactivating user {user_id} due to attempted banned \
|
|
room join from IP {client_ip}"
|
|
))
|
|
.await;
|
|
}
|
|
|
|
let all_joined_rooms: Vec<OwnedRoomId> = services
|
|
.rooms
|
|
.state_cache
|
|
.rooms_joined(user_id)
|
|
.map(Into::into)
|
|
.collect()
|
|
.await;
|
|
|
|
full_user_deactivate(services, user_id, &all_joined_rooms)
|
|
.boxed()
|
|
.await?;
|
|
}
|
|
|
|
return Err!(Request(Forbidden("This remote server is banned on this homeserver.")));
|
|
}
|
|
}
|
|
|
|
Ok(())
|
|
}
|