@@ -106,8 +106,10 @@ impl Console {
|
||||
| ReadlineEvent::Line(string) => self.clone().handle(string).await,
|
||||
| ReadlineEvent::Interrupted => continue,
|
||||
| ReadlineEvent::Eof => break,
|
||||
| ReadlineEvent::Quit =>
|
||||
self.server.shutdown().unwrap_or_else(error::default_log),
|
||||
| ReadlineEvent::Quit => self
|
||||
.server
|
||||
.shutdown()
|
||||
.unwrap_or_else(error::default_log),
|
||||
},
|
||||
| Err(error) => match error {
|
||||
| ReadlineError::Closed => break,
|
||||
@@ -135,7 +137,11 @@ impl Console {
|
||||
|
||||
let (abort, abort_reg) = AbortHandle::new_pair();
|
||||
let future = Abortable::new(future, abort_reg);
|
||||
_ = self.input_abort.lock().expect("locked").insert(abort);
|
||||
_ = self
|
||||
.input_abort
|
||||
.lock()
|
||||
.expect("locked")
|
||||
.insert(abort);
|
||||
defer! {{
|
||||
_ = self.input_abort.lock().expect("locked").take();
|
||||
}}
|
||||
@@ -158,7 +164,11 @@ impl Console {
|
||||
|
||||
let (abort, abort_reg) = AbortHandle::new_pair();
|
||||
let future = Abortable::new(future, abort_reg);
|
||||
_ = self.command_abort.lock().expect("locked").insert(abort);
|
||||
_ = self
|
||||
.command_abort
|
||||
.lock()
|
||||
.expect("locked")
|
||||
.insert(abort);
|
||||
defer! {{
|
||||
_ = self.command_abort.lock().expect("locked").take();
|
||||
}}
|
||||
|
||||
@@ -8,7 +8,12 @@ pub(super) const SIGNAL: &str = "SIGUSR2";
|
||||
#[implement(super::Service)]
|
||||
pub(super) async fn console_auto_start(&self) {
|
||||
#[cfg(feature = "console")]
|
||||
if self.services.server.config.admin_console_automatic {
|
||||
if self
|
||||
.services
|
||||
.server
|
||||
.config
|
||||
.admin_console_automatic
|
||||
{
|
||||
// Allow more of the startup sequence to execute before spawning
|
||||
tokio::task::yield_now().await;
|
||||
self.console.start().await;
|
||||
@@ -32,7 +37,12 @@ pub(super) async fn startup_execute(&self) -> Result {
|
||||
let smoketest = self.services.server.config.test.contains("smoke");
|
||||
|
||||
// When true, errors are ignored and startup continues.
|
||||
let errors = !smoketest && self.services.server.config.admin_execute_errors_ignore;
|
||||
let errors = !smoketest
|
||||
&& self
|
||||
.services
|
||||
.server
|
||||
.config
|
||||
.admin_execute_errors_ignore;
|
||||
|
||||
//TODO: remove this after run-states are broadcast
|
||||
sleep(Duration::from_millis(500)).await;
|
||||
@@ -65,10 +75,19 @@ pub(super) async fn startup_execute(&self) -> Result {
|
||||
#[implement(super::Service)]
|
||||
pub(super) async fn signal_execute(&self) -> Result {
|
||||
// List of comamnds to execute
|
||||
let commands = self.services.server.config.admin_signal_execute.clone();
|
||||
let commands = self
|
||||
.services
|
||||
.server
|
||||
.config
|
||||
.admin_signal_execute
|
||||
.clone();
|
||||
|
||||
// When true, errors are ignored and execution continues.
|
||||
let ignore_errors = self.services.server.config.admin_execute_errors_ignore;
|
||||
let ignore_errors = self
|
||||
.services
|
||||
.server
|
||||
.config
|
||||
.admin_execute_errors_ignore;
|
||||
|
||||
for (i, command) in commands.iter().enumerate() {
|
||||
if let Err(e) = self.execute_command(i, command.clone()).await {
|
||||
|
||||
@@ -30,7 +30,12 @@ pub async fn make_user_admin(&self, user_id: &UserId) -> Result {
|
||||
|
||||
let state_lock = self.services.state.mutex.lock(&room_id).await;
|
||||
|
||||
if self.services.state_cache.is_joined(user_id, &room_id).await {
|
||||
if self
|
||||
.services
|
||||
.state_cache
|
||||
.is_joined(user_id, &room_id)
|
||||
.await
|
||||
{
|
||||
return Err!(debug_warn!("User is already joined in the admin room"));
|
||||
}
|
||||
if self
|
||||
@@ -106,7 +111,9 @@ pub async fn make_user_admin(&self, user_id: &UserId) -> Result {
|
||||
room_power_levels
|
||||
.users
|
||||
.insert(server_user.into(), 69420.into());
|
||||
room_power_levels.users.insert(user_id.into(), 100.into());
|
||||
room_power_levels
|
||||
.users
|
||||
.insert(user_id.into(), 100.into());
|
||||
|
||||
self.services
|
||||
.timeline
|
||||
@@ -119,9 +126,17 @@ pub async fn make_user_admin(&self, user_id: &UserId) -> Result {
|
||||
.await?;
|
||||
|
||||
// Set room tag
|
||||
let room_tag = self.services.server.config.admin_room_tag.as_str();
|
||||
let room_tag = self
|
||||
.services
|
||||
.server
|
||||
.config
|
||||
.admin_room_tag
|
||||
.as_str();
|
||||
if !room_tag.is_empty() {
|
||||
if let Err(e) = self.set_room_tag(&room_id, user_id, room_tag).await {
|
||||
if let Err(e) = self
|
||||
.set_room_tag(&room_id, user_id, room_tag)
|
||||
.await
|
||||
{
|
||||
error!(?room_id, ?user_id, ?room_tag, "Failed to set tag for admin grant: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,7 +260,12 @@ impl Service {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
let Ok(pdu) = self.services.timeline.get_pdu(&in_reply_to.event_id).await else {
|
||||
let Ok(pdu) = self
|
||||
.services
|
||||
.timeline
|
||||
.get_pdu(&in_reply_to.event_id)
|
||||
.await
|
||||
else {
|
||||
error!(
|
||||
event_id = ?in_reply_to.event_id,
|
||||
"Missing admin command in_reply_to event"
|
||||
@@ -327,7 +332,10 @@ impl Service {
|
||||
pub async fn is_admin_command(&self, pdu: &PduEvent, body: &str) -> bool {
|
||||
// Server-side command-escape with public echo
|
||||
let is_escape = body.starts_with('\\');
|
||||
let is_public_escape = is_escape && body.trim_start_matches('\\').starts_with("!admin");
|
||||
let is_public_escape = is_escape
|
||||
&& body
|
||||
.trim_start_matches('\\')
|
||||
.starts_with("!admin");
|
||||
|
||||
// Admin command with public echo (in admin room)
|
||||
let server_user = &self.services.globals.server_user;
|
||||
@@ -361,7 +369,12 @@ impl Service {
|
||||
|
||||
// This will evaluate to false if the emergency password is set up so that
|
||||
// the administrator can execute commands as the server user
|
||||
let emergency_password_set = self.services.server.config.emergency_password.is_some();
|
||||
let emergency_password_set = self
|
||||
.services
|
||||
.server
|
||||
.config
|
||||
.emergency_password
|
||||
.is_some();
|
||||
let from_server = pdu.sender == *server_user && !emergency_password_set;
|
||||
if from_server && self.is_admin_room(&pdu.room_id).await {
|
||||
return false;
|
||||
@@ -382,7 +395,11 @@ impl Service {
|
||||
/// Sets the self-reference to crate::Services which will provide context to
|
||||
/// the admin commands.
|
||||
pub(super) fn set_services(&self, services: Option<&Arc<crate::Services>>) {
|
||||
let receiver = &mut *self.services.services.write().expect("locked for writing");
|
||||
let receiver = &mut *self
|
||||
.services
|
||||
.services
|
||||
.write()
|
||||
.expect("locked for writing");
|
||||
let weak = services.map(Arc::downgrade);
|
||||
*receiver = weak;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user