mirror of
https://github.com/girlbossceo/conduwuit.git
synced 2025-03-14 18:55:37 +00:00
eliminate references to services.globals.config
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
7c6b8b132a
commit
5be07ebc0f
26 changed files with 116 additions and 114 deletions
|
@ -170,7 +170,7 @@ pub(super) async fn get_remote_pdu_list(
|
|||
server: Box<ServerName>,
|
||||
force: bool,
|
||||
) -> Result<RoomMessageEventContent> {
|
||||
if !self.services.globals.config.allow_federation {
|
||||
if !self.services.server.config.allow_federation {
|
||||
return Ok(RoomMessageEventContent::text_plain(
|
||||
"Federation is disabled on this homeserver.",
|
||||
));
|
||||
|
@ -235,7 +235,7 @@ pub(super) async fn get_remote_pdu(
|
|||
event_id: Box<EventId>,
|
||||
server: Box<ServerName>,
|
||||
) -> Result<RoomMessageEventContent> {
|
||||
if !self.services.globals.config.allow_federation {
|
||||
if !self.services.server.config.allow_federation {
|
||||
return Ok(RoomMessageEventContent::text_plain(
|
||||
"Federation is disabled on this homeserver.",
|
||||
));
|
||||
|
@ -419,7 +419,7 @@ pub(super) async fn change_log_level(
|
|||
let handles = &["console"];
|
||||
|
||||
if reset {
|
||||
let old_filter_layer = match EnvFilter::try_new(&self.services.globals.config.log) {
|
||||
let old_filter_layer = match EnvFilter::try_new(&self.services.server.config.log) {
|
||||
| Ok(s) => s,
|
||||
| Err(e) => {
|
||||
return Ok(RoomMessageEventContent::text_plain(format!(
|
||||
|
@ -438,7 +438,7 @@ pub(super) async fn change_log_level(
|
|||
| Ok(()) => {
|
||||
return Ok(RoomMessageEventContent::text_plain(format!(
|
||||
"Successfully changed log level back to config value {}",
|
||||
self.services.globals.config.log
|
||||
self.services.server.config.log
|
||||
)));
|
||||
},
|
||||
| Err(e) => {
|
||||
|
@ -554,7 +554,7 @@ pub(super) async fn first_pdu_in_room(
|
|||
.services
|
||||
.rooms
|
||||
.state_cache
|
||||
.server_in_room(&self.services.globals.config.server_name, &room_id)
|
||||
.server_in_room(&self.services.server.config.server_name, &room_id)
|
||||
.await
|
||||
{
|
||||
return Ok(RoomMessageEventContent::text_plain(
|
||||
|
@ -583,7 +583,7 @@ pub(super) async fn latest_pdu_in_room(
|
|||
.services
|
||||
.rooms
|
||||
.state_cache
|
||||
.server_in_room(&self.services.globals.config.server_name, &room_id)
|
||||
.server_in_room(&self.services.server.config.server_name, &room_id)
|
||||
.await
|
||||
{
|
||||
return Ok(RoomMessageEventContent::text_plain(
|
||||
|
@ -613,7 +613,7 @@ pub(super) async fn force_set_room_state_from_server(
|
|||
.services
|
||||
.rooms
|
||||
.state_cache
|
||||
.server_in_room(&self.services.globals.config.server_name, &room_id)
|
||||
.server_in_room(&self.services.server.config.server_name, &room_id)
|
||||
.await
|
||||
{
|
||||
return Ok(RoomMessageEventContent::text_plain(
|
||||
|
@ -818,13 +818,13 @@ pub(super) async fn resolve_true_destination(
|
|||
server_name: Box<ServerName>,
|
||||
no_cache: bool,
|
||||
) -> Result<RoomMessageEventContent> {
|
||||
if !self.services.globals.config.allow_federation {
|
||||
if !self.services.server.config.allow_federation {
|
||||
return Ok(RoomMessageEventContent::text_plain(
|
||||
"Federation is disabled on this homeserver.",
|
||||
));
|
||||
}
|
||||
|
||||
if server_name == self.services.globals.config.server_name {
|
||||
if server_name == self.services.server.config.server_name {
|
||||
return Ok(RoomMessageEventContent::text_plain(
|
||||
"Not allowed to send federation requests to ourselves. Please use `get-pdu` for \
|
||||
fetching local PDUs.",
|
||||
|
|
|
@ -92,7 +92,7 @@ pub(super) async fn remote_user_in_rooms(
|
|||
&self,
|
||||
user_id: Box<UserId>,
|
||||
) -> Result<RoomMessageEventContent> {
|
||||
if user_id.server_name() == self.services.globals.config.server_name {
|
||||
if user_id.server_name() == self.services.server.config.server_name {
|
||||
return Ok(RoomMessageEventContent::text_plain(
|
||||
"User belongs to our server, please use `list-joined-rooms` user admin command \
|
||||
instead.",
|
||||
|
|
|
@ -83,12 +83,12 @@ pub(super) async fn create_user(
|
|||
// content is set to the user's display name with a space before it
|
||||
if !self
|
||||
.services
|
||||
.globals
|
||||
.server
|
||||
.config
|
||||
.new_user_displayname_suffix
|
||||
.is_empty()
|
||||
{
|
||||
write!(displayname, " {}", self.services.globals.config.new_user_displayname_suffix)
|
||||
write!(displayname, " {}", self.services.server.config.new_user_displayname_suffix)
|
||||
.expect("should be able to write to string buffer");
|
||||
}
|
||||
|
||||
|
@ -114,8 +114,8 @@ pub(super) async fn create_user(
|
|||
)
|
||||
.await?;
|
||||
|
||||
if !self.services.globals.config.auto_join_rooms.is_empty() {
|
||||
for room in &self.services.globals.config.auto_join_rooms {
|
||||
if !self.services.server.config.auto_join_rooms.is_empty() {
|
||||
for room in &self.services.server.config.auto_join_rooms {
|
||||
let Ok(room_id) = self.services.rooms.alias.resolve(room).await else {
|
||||
error!(%user_id, "Failed to resolve room alias to room ID when attempting to auto join {room}, skipping");
|
||||
continue;
|
||||
|
|
|
@ -299,7 +299,7 @@ pub(crate) async fn register_route(
|
|||
if !services.globals.new_user_displayname_suffix().is_empty()
|
||||
&& body.appservice_info.is_none()
|
||||
{
|
||||
write!(displayname, " {}", services.globals.config.new_user_displayname_suffix)
|
||||
write!(displayname, " {}", services.server.config.new_user_displayname_suffix)
|
||||
.expect("should be able to write to string buffer");
|
||||
}
|
||||
|
||||
|
@ -365,7 +365,7 @@ pub(crate) async fn register_route(
|
|||
\"{device_display_name}\""
|
||||
);
|
||||
|
||||
if services.globals.config.admin_room_notices {
|
||||
if services.server.config.admin_room_notices {
|
||||
services
|
||||
.admin
|
||||
.send_message(RoomMessageEventContent::notice_plain(format!(
|
||||
|
@ -378,7 +378,7 @@ pub(crate) async fn register_route(
|
|||
} else {
|
||||
info!("New user \"{user_id}\" registered on this server.");
|
||||
|
||||
if services.globals.config.admin_room_notices {
|
||||
if services.server.config.admin_room_notices {
|
||||
services
|
||||
.admin
|
||||
.send_message(RoomMessageEventContent::notice_plain(format!(
|
||||
|
@ -395,7 +395,7 @@ pub(crate) async fn register_route(
|
|||
info!("New guest user \"{user_id}\" registered on this server.");
|
||||
|
||||
if !device_display_name.is_empty() {
|
||||
if services.globals.config.admin_room_notices {
|
||||
if services.server.config.admin_room_notices {
|
||||
services
|
||||
.admin
|
||||
.send_message(RoomMessageEventContent::notice_plain(format!(
|
||||
|
@ -407,7 +407,7 @@ pub(crate) async fn register_route(
|
|||
}
|
||||
} else {
|
||||
#[allow(clippy::collapsible_else_if)]
|
||||
if services.globals.config.admin_room_notices {
|
||||
if services.server.config.admin_room_notices {
|
||||
services
|
||||
.admin
|
||||
.send_message(RoomMessageEventContent::notice_plain(format!(
|
||||
|
@ -438,10 +438,10 @@ pub(crate) async fn register_route(
|
|||
}
|
||||
|
||||
if body.appservice_info.is_none()
|
||||
&& !services.globals.config.auto_join_rooms.is_empty()
|
||||
&& !services.server.config.auto_join_rooms.is_empty()
|
||||
&& (services.globals.allow_guests_auto_join_rooms() || !is_guest)
|
||||
{
|
||||
for room in &services.globals.config.auto_join_rooms {
|
||||
for room in &services.server.config.auto_join_rooms {
|
||||
let Ok(room_id) = services.rooms.alias.resolve(room).await else {
|
||||
error!(
|
||||
"Failed to resolve room alias to room ID when attempting to auto join \
|
||||
|
@ -570,7 +570,7 @@ pub(crate) async fn change_password_route(
|
|||
|
||||
info!("User {sender_user} changed their password.");
|
||||
|
||||
if services.globals.config.admin_room_notices {
|
||||
if services.server.config.admin_room_notices {
|
||||
services
|
||||
.admin
|
||||
.send_message(RoomMessageEventContent::notice_plain(format!(
|
||||
|
@ -673,7 +673,7 @@ pub(crate) async fn deactivate_route(
|
|||
|
||||
info!("User {sender_user} deactivated their account.");
|
||||
|
||||
if services.globals.config.admin_room_notices {
|
||||
if services.server.config.admin_room_notices {
|
||||
services
|
||||
.admin
|
||||
.send_message(RoomMessageEventContent::notice_plain(format!(
|
||||
|
|
|
@ -152,7 +152,7 @@ pub(crate) async fn set_room_visibility_route(
|
|||
|
||||
match &body.visibility {
|
||||
| room::Visibility::Public => {
|
||||
if services.globals.config.lockdown_public_room_directory
|
||||
if services.server.config.lockdown_public_room_directory
|
||||
&& !services.users.is_admin(sender_user).await
|
||||
&& body.appservice_info.is_none()
|
||||
{
|
||||
|
@ -162,7 +162,7 @@ pub(crate) async fn set_room_visibility_route(
|
|||
body.room_id
|
||||
);
|
||||
|
||||
if services.globals.config.admin_room_notices {
|
||||
if services.server.config.admin_room_notices {
|
||||
services
|
||||
.admin
|
||||
.send_text(&format!(
|
||||
|
@ -181,7 +181,7 @@ pub(crate) async fn set_room_visibility_route(
|
|||
|
||||
services.rooms.directory.set_public(&body.room_id);
|
||||
|
||||
if services.globals.config.admin_room_notices {
|
||||
if services.server.config.admin_room_notices {
|
||||
services
|
||||
.admin
|
||||
.send_text(&format!(
|
||||
|
|
|
@ -31,7 +31,7 @@ pub(crate) async fn get_media_config_route(
|
|||
_body: Ruma<get_media_config::v1::Request>,
|
||||
) -> Result<get_media_config::v1::Response> {
|
||||
Ok(get_media_config::v1::Response {
|
||||
upload_size: ruma_from_usize(services.globals.config.max_request_size),
|
||||
upload_size: ruma_from_usize(services.server.config.max_request_size),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ pub(crate) async fn get_media_config_legacy_route(
|
|||
_body: Ruma<get_media_config::v3::Request>,
|
||||
) -> Result<get_media_config::v3::Response> {
|
||||
Ok(get_media_config::v3::Response {
|
||||
upload_size: ruma_from_usize(services.globals.config.max_request_size),
|
||||
upload_size: ruma_from_usize(services.server.config.max_request_size),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ async fn banned_room_check(
|
|||
if let Some(room_id) = room_id {
|
||||
if services.rooms.metadata.is_banned(room_id).await
|
||||
|| services
|
||||
.globals
|
||||
.server
|
||||
.config
|
||||
.forbidden_remote_server_names
|
||||
.contains(&room_id.server_name().unwrap().to_owned())
|
||||
|
@ -81,12 +81,12 @@ async fn banned_room_check(
|
|||
attempted to join a banned room or banned room server name: {room_id}"
|
||||
);
|
||||
|
||||
if services.globals.config.auto_deactivate_banned_room_attempts {
|
||||
if services.server.config.auto_deactivate_banned_room_attempts {
|
||||
warn!(
|
||||
"Automatically deactivating user {user_id} due to attempted banned room join"
|
||||
);
|
||||
|
||||
if services.globals.config.admin_room_notices {
|
||||
if services.server.config.admin_room_notices {
|
||||
services
|
||||
.admin
|
||||
.send_message(RoomMessageEventContent::text_plain(format!(
|
||||
|
@ -112,7 +112,7 @@ async fn banned_room_check(
|
|||
}
|
||||
} else if let Some(server_name) = server_name {
|
||||
if services
|
||||
.globals
|
||||
.server
|
||||
.config
|
||||
.forbidden_remote_server_names
|
||||
.contains(&server_name.to_owned())
|
||||
|
@ -122,12 +122,12 @@ async fn banned_room_check(
|
|||
name {server_name} that is globally forbidden. Rejecting.",
|
||||
);
|
||||
|
||||
if services.globals.config.auto_deactivate_banned_room_attempts {
|
||||
if services.server.config.auto_deactivate_banned_room_attempts {
|
||||
warn!(
|
||||
"Automatically deactivating user {user_id} due to attempted banned room join"
|
||||
);
|
||||
|
||||
if services.globals.config.admin_room_notices {
|
||||
if services.server.config.admin_room_notices {
|
||||
services
|
||||
.admin
|
||||
.send_message(RoomMessageEventContent::text_plain(format!(
|
||||
|
|
|
@ -37,7 +37,7 @@ pub(crate) async fn create_openid_token_route(
|
|||
Ok(account::request_openid_token::v3::Response {
|
||||
access_token,
|
||||
token_type: TokenType::Bearer,
|
||||
matrix_server_name: services.globals.config.server_name.clone(),
|
||||
matrix_server_name: services.server.config.server_name.clone(),
|
||||
expires_in: Duration::from_secs(expires_in),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ pub(crate) async fn report_room_route(
|
|||
if !services
|
||||
.rooms
|
||||
.state_cache
|
||||
.server_in_room(&services.globals.config.server_name, &body.room_id)
|
||||
.server_in_room(&services.server.config.server_name, &body.room_id)
|
||||
.await
|
||||
{
|
||||
return Err!(Request(NotFound(
|
||||
|
|
|
@ -71,7 +71,7 @@ pub(crate) async fn create_room_route(
|
|||
let room_id: OwnedRoomId = if let Some(custom_room_id) = &body.room_id {
|
||||
custom_room_id_check(&services, custom_room_id)?
|
||||
} else {
|
||||
RoomId::new(&services.globals.config.server_name)
|
||||
RoomId::new(&services.server.config.server_name)
|
||||
};
|
||||
|
||||
// check if room ID doesn't already exist instead of erroring on auth check
|
||||
|
@ -83,7 +83,7 @@ pub(crate) async fn create_room_route(
|
|||
}
|
||||
|
||||
if body.visibility == room::Visibility::Public
|
||||
&& services.globals.config.lockdown_public_room_directory
|
||||
&& services.server.config.lockdown_public_room_directory
|
||||
&& !services.users.is_admin(sender_user).await
|
||||
&& body.appservice_info.is_none()
|
||||
{
|
||||
|
@ -93,7 +93,7 @@ pub(crate) async fn create_room_route(
|
|||
&room_id
|
||||
);
|
||||
|
||||
if services.globals.config.admin_room_notices {
|
||||
if services.server.config.admin_room_notices {
|
||||
services
|
||||
.admin
|
||||
.send_text(&format!(
|
||||
|
@ -450,7 +450,7 @@ pub(crate) async fn create_room_route(
|
|||
if body.visibility == room::Visibility::Public {
|
||||
services.rooms.directory.set_public(&room_id);
|
||||
|
||||
if services.globals.config.admin_room_notices {
|
||||
if services.server.config.admin_room_notices {
|
||||
services
|
||||
.admin
|
||||
.send_text(&format!(
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use axum::extract::State;
|
||||
use conduwuit::Err;
|
||||
use conduwuit::{utils::math::Tried, Err};
|
||||
use ruma::api::client::typing::create_typing_event;
|
||||
|
||||
use crate::{utils, Result, Ruma};
|
||||
|
@ -31,17 +31,15 @@ pub(crate) async fn create_typing_event_route(
|
|||
let duration = utils::clamp(
|
||||
duration.as_millis().try_into().unwrap_or(u64::MAX),
|
||||
services
|
||||
.globals
|
||||
.server
|
||||
.config
|
||||
.typing_client_timeout_min_s
|
||||
.checked_mul(1000)
|
||||
.unwrap(),
|
||||
.try_mul(1000)?,
|
||||
services
|
||||
.globals
|
||||
.server
|
||||
.config
|
||||
.typing_client_timeout_max_s
|
||||
.checked_mul(1000)
|
||||
.unwrap(),
|
||||
.try_mul(1000)?,
|
||||
);
|
||||
services
|
||||
.rooms
|
||||
|
|
|
@ -38,7 +38,7 @@ pub(crate) async fn turn_server_route(
|
|||
let user = body.sender_user.unwrap_or_else(|| {
|
||||
UserId::parse_with_server_name(
|
||||
utils::random_string(RANDOM_USER_ID_LENGTH).to_lowercase(),
|
||||
&services.globals.config.server_name,
|
||||
&services.server.config.server_name,
|
||||
)
|
||||
.unwrap()
|
||||
});
|
||||
|
|
|
@ -71,7 +71,7 @@ pub(super) async fn auth(
|
|||
match metadata {
|
||||
| &get_public_rooms::v3::Request::METADATA => {
|
||||
if !services
|
||||
.globals
|
||||
.server
|
||||
.config
|
||||
.allow_public_room_directory_without_auth
|
||||
{
|
||||
|
@ -94,7 +94,7 @@ pub(super) async fn auth(
|
|||
| &get_display_name::v3::Request::METADATA
|
||||
| &get_avatar_url::v3::Request::METADATA
|
||||
| &get_timezone_key::unstable::Request::METADATA => {
|
||||
if services.globals.config.require_auth_for_profile_requests {
|
||||
if services.server.config.require_auth_for_profile_requests {
|
||||
match token {
|
||||
| Token::Appservice(_) | Token::User(_) => {
|
||||
// we should have validated the token above
|
||||
|
@ -127,7 +127,7 @@ pub(super) async fn auth(
|
|||
}),
|
||||
| (AuthScheme::AccessToken, Token::None) => match metadata {
|
||||
| &get_turn_server_info::v3::Request::METADATA => {
|
||||
if services.globals.config.turn_allow_guests {
|
||||
if services.server.config.turn_allow_guests {
|
||||
Ok(Auth {
|
||||
origin: None,
|
||||
sender_user: None,
|
||||
|
|
|
@ -32,7 +32,7 @@ pub(super) async fn from(
|
|||
let query = serde_html_form::from_str(query)
|
||||
.map_err(|e| err!(Request(Unknown("Failed to read query parameters: {e}"))))?;
|
||||
|
||||
let max_body_size = services.globals.config.max_request_size;
|
||||
let max_body_size = services.server.config.max_request_size;
|
||||
|
||||
let body = axum::body::to_bytes(body, max_body_size)
|
||||
.await
|
||||
|
|
|
@ -37,7 +37,7 @@ pub(crate) async fn create_invite_route(
|
|||
|
||||
if let Some(server) = body.room_id.server_name() {
|
||||
if services
|
||||
.globals
|
||||
.server
|
||||
.config
|
||||
.forbidden_remote_server_names
|
||||
.contains(&server.to_owned())
|
||||
|
@ -47,7 +47,7 @@ pub(crate) async fn create_invite_route(
|
|||
}
|
||||
|
||||
if services
|
||||
.globals
|
||||
.server
|
||||
.config
|
||||
.forbidden_remote_server_names
|
||||
.contains(body.origin())
|
||||
|
|
|
@ -42,7 +42,7 @@ pub(crate) async fn create_join_event_template_route(
|
|||
.await?;
|
||||
|
||||
if services
|
||||
.globals
|
||||
.server
|
||||
.config
|
||||
.forbidden_remote_server_names
|
||||
.contains(body.origin())
|
||||
|
@ -59,7 +59,7 @@ pub(crate) async fn create_join_event_template_route(
|
|||
|
||||
if let Some(server) = body.room_id.server_name() {
|
||||
if services
|
||||
.globals
|
||||
.server
|
||||
.config
|
||||
.forbidden_remote_server_names
|
||||
.contains(&server.to_owned())
|
||||
|
|
|
@ -34,7 +34,7 @@ pub(crate) async fn create_knock_event_template_route(
|
|||
.await?;
|
||||
|
||||
if services
|
||||
.globals
|
||||
.server
|
||||
.config
|
||||
.forbidden_remote_server_names
|
||||
.contains(body.origin())
|
||||
|
@ -51,7 +51,7 @@ pub(crate) async fn create_knock_event_template_route(
|
|||
|
||||
if let Some(server) = body.room_id.server_name() {
|
||||
if services
|
||||
.globals
|
||||
.server
|
||||
.config
|
||||
.forbidden_remote_server_names
|
||||
.contains(&server.to_owned())
|
||||
|
|
|
@ -20,7 +20,7 @@ pub(crate) async fn get_public_rooms_filtered_route(
|
|||
body: Ruma<get_public_rooms_filtered::v1::Request>,
|
||||
) -> Result<get_public_rooms_filtered::v1::Response> {
|
||||
if !services
|
||||
.globals
|
||||
.server
|
||||
.config
|
||||
.allow_public_room_directory_over_federation
|
||||
{
|
||||
|
|
|
@ -63,7 +63,7 @@ pub(crate) async fn get_profile_information_route(
|
|||
body: Ruma<get_profile_information::v1::Request>,
|
||||
) -> Result<get_profile_information::v1::Response> {
|
||||
if !services
|
||||
.globals
|
||||
.server
|
||||
.config
|
||||
.allow_inbound_profile_lookup_federation_requests
|
||||
{
|
||||
|
|
|
@ -309,7 +309,7 @@ async fn handle_edu_typing(
|
|||
origin: &ServerName,
|
||||
typing: TypingContent,
|
||||
) {
|
||||
if !services.globals.config.allow_incoming_typing {
|
||||
if !services.server.config.allow_incoming_typing {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -344,7 +344,7 @@ async fn handle_edu_typing(
|
|||
if typing.typing {
|
||||
let timeout = utils::millis_since_unix_epoch().saturating_add(
|
||||
services
|
||||
.globals
|
||||
.server
|
||||
.config
|
||||
.typing_federation_timeout_s
|
||||
.saturating_mul(1000),
|
||||
|
|
|
@ -268,7 +268,7 @@ pub(crate) async fn create_join_event_v1_route(
|
|||
body: Ruma<create_join_event::v1::Request>,
|
||||
) -> Result<create_join_event::v1::Response> {
|
||||
if services
|
||||
.globals
|
||||
.server
|
||||
.config
|
||||
.forbidden_remote_server_names
|
||||
.contains(body.origin())
|
||||
|
@ -284,7 +284,7 @@ pub(crate) async fn create_join_event_v1_route(
|
|||
|
||||
if let Some(server) = body.room_id.server_name() {
|
||||
if services
|
||||
.globals
|
||||
.server
|
||||
.config
|
||||
.forbidden_remote_server_names
|
||||
.contains(&server.to_owned())
|
||||
|
@ -316,7 +316,7 @@ pub(crate) async fn create_join_event_v2_route(
|
|||
body: Ruma<create_join_event::v2::Request>,
|
||||
) -> Result<create_join_event::v2::Response> {
|
||||
if services
|
||||
.globals
|
||||
.server
|
||||
.config
|
||||
.forbidden_remote_server_names
|
||||
.contains(body.origin())
|
||||
|
@ -326,7 +326,7 @@ pub(crate) async fn create_join_event_v2_route(
|
|||
|
||||
if let Some(server) = body.room_id.server_name() {
|
||||
if services
|
||||
.globals
|
||||
.server
|
||||
.config
|
||||
.forbidden_remote_server_names
|
||||
.contains(&server.to_owned())
|
||||
|
|
|
@ -22,7 +22,7 @@ pub(crate) async fn create_knock_event_v1_route(
|
|||
body: Ruma<send_knock::v1::Request>,
|
||||
) -> Result<send_knock::v1::Response> {
|
||||
if services
|
||||
.globals
|
||||
.server
|
||||
.config
|
||||
.forbidden_remote_server_names
|
||||
.contains(body.origin())
|
||||
|
@ -38,7 +38,7 @@ pub(crate) async fn create_knock_event_v1_route(
|
|||
|
||||
if let Some(server) = body.room_id.server_name() {
|
||||
if services
|
||||
.globals
|
||||
.server
|
||||
.config
|
||||
.forbidden_remote_server_names
|
||||
.contains(&server.to_owned())
|
||||
|
|
|
@ -338,7 +338,7 @@ impl Service {
|
|||
}
|
||||
|
||||
// Check if server-side command-escape is disabled by configuration
|
||||
if is_public_escape && !self.services.globals.config.admin_escape_commands {
|
||||
if is_public_escape && !self.services.server.config.admin_escape_commands {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ use std::{
|
|||
time::Instant,
|
||||
};
|
||||
|
||||
use conduwuit::{error, utils::bytes::pretty, Config, Result};
|
||||
use conduwuit::{error, utils::bytes::pretty, Result, Server};
|
||||
use data::Data;
|
||||
use regex::RegexSet;
|
||||
use ruma::{OwnedEventId, OwnedRoomAliasId, OwnedServerName, OwnedUserId, ServerName, UserId};
|
||||
|
@ -16,8 +16,8 @@ use crate::service;
|
|||
|
||||
pub struct Service {
|
||||
pub db: Data,
|
||||
server: Arc<Server>,
|
||||
|
||||
pub config: Config,
|
||||
pub bad_event_ratelimiter: Arc<RwLock<HashMap<OwnedEventId, RateLimitState>>>,
|
||||
pub server_user: OwnedUserId,
|
||||
pub admin_alias: OwnedRoomAliasId,
|
||||
|
@ -57,9 +57,9 @@ impl crate::Service for Service {
|
|||
},
|
||||
);
|
||||
|
||||
let mut s = Self {
|
||||
Ok(Arc::new(Self {
|
||||
db,
|
||||
config: config.clone(),
|
||||
server: args.server.clone(),
|
||||
bad_event_ratelimiter: Arc::new(RwLock::new(HashMap::new())),
|
||||
admin_alias: OwnedRoomAliasId::try_from(format!("#admins:{}", &config.server_name))
|
||||
.expect("#admins:server_name is valid alias name"),
|
||||
|
@ -70,9 +70,7 @@ impl crate::Service for Service {
|
|||
.expect("@conduit:server_name is valid"),
|
||||
turn_secret,
|
||||
registration_token,
|
||||
};
|
||||
|
||||
Ok(Arc::new(s))
|
||||
}))
|
||||
}
|
||||
|
||||
fn memory_usage(&self, out: &mut dyn Write) -> Result {
|
||||
|
@ -109,93 +107,97 @@ impl Service {
|
|||
pub fn current_count(&self) -> Result<u64> { Ok(self.db.current_count()) }
|
||||
|
||||
#[inline]
|
||||
pub fn server_name(&self) -> &ServerName { self.config.server_name.as_ref() }
|
||||
pub fn server_name(&self) -> &ServerName { self.server.config.server_name.as_ref() }
|
||||
|
||||
pub fn allow_registration(&self) -> bool { self.config.allow_registration }
|
||||
pub fn allow_registration(&self) -> bool { self.server.config.allow_registration }
|
||||
|
||||
pub fn allow_guest_registration(&self) -> bool { self.config.allow_guest_registration }
|
||||
pub fn allow_guest_registration(&self) -> bool { self.server.config.allow_guest_registration }
|
||||
|
||||
pub fn allow_guests_auto_join_rooms(&self) -> bool {
|
||||
self.config.allow_guests_auto_join_rooms
|
||||
self.server.config.allow_guests_auto_join_rooms
|
||||
}
|
||||
|
||||
pub fn log_guest_registrations(&self) -> bool { self.config.log_guest_registrations }
|
||||
pub fn log_guest_registrations(&self) -> bool { self.server.config.log_guest_registrations }
|
||||
|
||||
pub fn allow_encryption(&self) -> bool { self.config.allow_encryption }
|
||||
pub fn allow_encryption(&self) -> bool { self.server.config.allow_encryption }
|
||||
|
||||
pub fn allow_federation(&self) -> bool { self.config.allow_federation }
|
||||
pub fn allow_federation(&self) -> bool { self.server.config.allow_federation }
|
||||
|
||||
pub fn allow_public_room_directory_over_federation(&self) -> bool {
|
||||
self.config.allow_public_room_directory_over_federation
|
||||
self.server
|
||||
.config
|
||||
.allow_public_room_directory_over_federation
|
||||
}
|
||||
|
||||
pub fn allow_device_name_federation(&self) -> bool {
|
||||
self.config.allow_device_name_federation
|
||||
self.server.config.allow_device_name_federation
|
||||
}
|
||||
|
||||
pub fn allow_room_creation(&self) -> bool { self.config.allow_room_creation }
|
||||
pub fn allow_room_creation(&self) -> bool { self.server.config.allow_room_creation }
|
||||
|
||||
pub fn new_user_displayname_suffix(&self) -> &String {
|
||||
&self.config.new_user_displayname_suffix
|
||||
&self.server.config.new_user_displayname_suffix
|
||||
}
|
||||
|
||||
pub fn allow_check_for_updates(&self) -> bool { self.config.allow_check_for_updates }
|
||||
pub fn allow_check_for_updates(&self) -> bool { self.server.config.allow_check_for_updates }
|
||||
|
||||
pub fn trusted_servers(&self) -> &[OwnedServerName] { &self.config.trusted_servers }
|
||||
pub fn trusted_servers(&self) -> &[OwnedServerName] { &self.server.config.trusted_servers }
|
||||
|
||||
pub fn turn_password(&self) -> &String { &self.config.turn_password }
|
||||
pub fn turn_password(&self) -> &String { &self.server.config.turn_password }
|
||||
|
||||
pub fn turn_ttl(&self) -> u64 { self.config.turn_ttl }
|
||||
pub fn turn_ttl(&self) -> u64 { self.server.config.turn_ttl }
|
||||
|
||||
pub fn turn_uris(&self) -> &[String] { &self.config.turn_uris }
|
||||
pub fn turn_uris(&self) -> &[String] { &self.server.config.turn_uris }
|
||||
|
||||
pub fn turn_username(&self) -> &String { &self.config.turn_username }
|
||||
pub fn turn_username(&self) -> &String { &self.server.config.turn_username }
|
||||
|
||||
pub fn notification_push_path(&self) -> &String { &self.config.notification_push_path }
|
||||
pub fn notification_push_path(&self) -> &String { &self.server.config.notification_push_path }
|
||||
|
||||
pub fn emergency_password(&self) -> &Option<String> { &self.config.emergency_password }
|
||||
pub fn emergency_password(&self) -> &Option<String> { &self.server.config.emergency_password }
|
||||
|
||||
pub fn url_preview_domain_contains_allowlist(&self) -> &Vec<String> {
|
||||
&self.config.url_preview_domain_contains_allowlist
|
||||
&self.server.config.url_preview_domain_contains_allowlist
|
||||
}
|
||||
|
||||
pub fn url_preview_domain_explicit_allowlist(&self) -> &Vec<String> {
|
||||
&self.config.url_preview_domain_explicit_allowlist
|
||||
&self.server.config.url_preview_domain_explicit_allowlist
|
||||
}
|
||||
|
||||
pub fn url_preview_domain_explicit_denylist(&self) -> &Vec<String> {
|
||||
&self.config.url_preview_domain_explicit_denylist
|
||||
&self.server.config.url_preview_domain_explicit_denylist
|
||||
}
|
||||
|
||||
pub fn url_preview_url_contains_allowlist(&self) -> &Vec<String> {
|
||||
&self.config.url_preview_url_contains_allowlist
|
||||
&self.server.config.url_preview_url_contains_allowlist
|
||||
}
|
||||
|
||||
pub fn url_preview_max_spider_size(&self) -> usize { self.config.url_preview_max_spider_size }
|
||||
pub fn url_preview_max_spider_size(&self) -> usize {
|
||||
self.server.config.url_preview_max_spider_size
|
||||
}
|
||||
|
||||
pub fn url_preview_check_root_domain(&self) -> bool {
|
||||
self.config.url_preview_check_root_domain
|
||||
self.server.config.url_preview_check_root_domain
|
||||
}
|
||||
|
||||
pub fn forbidden_alias_names(&self) -> &RegexSet { &self.config.forbidden_alias_names }
|
||||
pub fn forbidden_alias_names(&self) -> &RegexSet { &self.server.config.forbidden_alias_names }
|
||||
|
||||
pub fn forbidden_usernames(&self) -> &RegexSet { &self.config.forbidden_usernames }
|
||||
pub fn forbidden_usernames(&self) -> &RegexSet { &self.server.config.forbidden_usernames }
|
||||
|
||||
pub fn allow_local_presence(&self) -> bool { self.config.allow_local_presence }
|
||||
pub fn allow_local_presence(&self) -> bool { self.server.config.allow_local_presence }
|
||||
|
||||
pub fn allow_incoming_presence(&self) -> bool { self.config.allow_incoming_presence }
|
||||
pub fn allow_incoming_presence(&self) -> bool { self.server.config.allow_incoming_presence }
|
||||
|
||||
pub fn allow_outgoing_presence(&self) -> bool { self.config.allow_outgoing_presence }
|
||||
pub fn allow_outgoing_presence(&self) -> bool { self.server.config.allow_outgoing_presence }
|
||||
|
||||
pub fn allow_incoming_read_receipts(&self) -> bool {
|
||||
self.config.allow_incoming_read_receipts
|
||||
self.server.config.allow_incoming_read_receipts
|
||||
}
|
||||
|
||||
pub fn allow_outgoing_read_receipts(&self) -> bool {
|
||||
self.config.allow_outgoing_read_receipts
|
||||
self.server.config.allow_outgoing_read_receipts
|
||||
}
|
||||
|
||||
pub fn block_non_admin_invites(&self) -> bool { self.config.block_non_admin_invites }
|
||||
pub fn block_non_admin_invites(&self) -> bool { self.server.config.block_non_admin_invites }
|
||||
|
||||
/// checks if `user_id` is local to us via server_name comparison
|
||||
#[inline]
|
||||
|
@ -205,7 +207,7 @@ impl Service {
|
|||
|
||||
#[inline]
|
||||
pub fn server_is_ours(&self, server_name: &ServerName) -> bool {
|
||||
server_name == self.config.server_name
|
||||
server_name == self.server.config.server_name
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
@ -5,7 +5,7 @@ use std::sync::Arc;
|
|||
use conduwuit::{
|
||||
err,
|
||||
utils::{stream::TryIgnore, ReadyExt},
|
||||
Err, Result,
|
||||
Err, Result, Server,
|
||||
};
|
||||
use database::{Deserialized, Ignore, Interfix, Map};
|
||||
use futures::{Stream, StreamExt, TryFutureExt};
|
||||
|
@ -31,6 +31,7 @@ struct Data {
|
|||
}
|
||||
|
||||
struct Services {
|
||||
server: Arc<Server>,
|
||||
admin: Dep<admin::Service>,
|
||||
appservice: Dep<appservice::Service>,
|
||||
globals: Dep<globals::Service>,
|
||||
|
@ -47,6 +48,7 @@ impl crate::Service for Service {
|
|||
aliasid_alias: args.db["aliasid_alias"].clone(),
|
||||
},
|
||||
services: Services {
|
||||
server: args.server.clone(),
|
||||
admin: args.depend::<admin::Service>("admin"),
|
||||
appservice: args.depend::<appservice::Service>("appservice"),
|
||||
globals: args.depend::<globals::Service>("globals"),
|
||||
|
@ -146,9 +148,9 @@ impl Service {
|
|||
let server_name = room_alias.server_name();
|
||||
let server_is_ours = self.services.globals.server_is_ours(server_name);
|
||||
let servers_contains_ours = || {
|
||||
servers.as_ref().is_some_and(|servers| {
|
||||
servers.contains(&self.services.globals.config.server_name)
|
||||
})
|
||||
servers
|
||||
.as_ref()
|
||||
.is_some_and(|servers| servers.contains(&self.services.server.config.server_name))
|
||||
};
|
||||
|
||||
if !server_is_ours && !servers_contains_ours() {
|
||||
|
|
Loading…
Add table
Reference in a new issue