mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2025-07-05 14:45:48 +02:00
Compare commits
6 commits
abb0aa50da
...
9eb1d098bd
Author | SHA1 | Date | |
---|---|---|---|
|
9eb1d098bd | ||
|
843ffa0ab9 | ||
|
015fb4e8e1 | ||
|
bd67c581c9 | ||
|
2ccbd7d60b | ||
|
60960c6e09 |
13 changed files with 179 additions and 33 deletions
|
@ -19,11 +19,20 @@ outputs:
|
|||
rustc_version:
|
||||
description: The rustc version installed
|
||||
value: ${{ steps.rustc-version.outputs.version }}
|
||||
rustup_version:
|
||||
description: The rustup version installed
|
||||
value: ${{ steps.rustup-version.outputs.version }}
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Check if rustup is already installed
|
||||
shell: bash
|
||||
id: rustup-version
|
||||
run: |
|
||||
echo "version=$(rustup --version)" >> $GITHUB_OUTPUT
|
||||
- name: Cache rustup toolchains
|
||||
if: steps.rustup-version.outputs.version == ''
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: |
|
||||
|
@ -33,6 +42,7 @@ runs:
|
|||
# Requires repo to be cloned if toolchain is not specified
|
||||
key: ${{ runner.os }}-rustup-${{ inputs.toolchain || hashFiles('**/rust-toolchain.toml') }}
|
||||
- name: Install Rust toolchain
|
||||
if: steps.rustup-version.outputs.version == ''
|
||||
shell: bash
|
||||
run: |
|
||||
if ! command -v rustup &> /dev/null ; then
|
||||
|
|
|
@ -57,7 +57,6 @@ jobs:
|
|||
|
||||
build-image:
|
||||
runs-on: dind
|
||||
container: ghcr.io/catthehacker/ubuntu:act-latest
|
||||
needs: define-variables
|
||||
permissions:
|
||||
contents: read
|
||||
|
@ -211,7 +210,6 @@ jobs:
|
|||
|
||||
merge:
|
||||
runs-on: dind
|
||||
container: ghcr.io/catthehacker/ubuntu:act-latest
|
||||
needs: [define-variables, build-image]
|
||||
steps:
|
||||
- name: Download digests
|
||||
|
|
12
Cargo.lock
generated
12
Cargo.lock
generated
|
@ -794,6 +794,7 @@ dependencies = [
|
|||
"tokio-metrics",
|
||||
"tracing",
|
||||
"tracing-flame",
|
||||
"tracing-journald",
|
||||
"tracing-opentelemetry",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
@ -5067,6 +5068,17 @@ dependencies = [
|
|||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-journald"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc0b4143302cf1022dac868d521e36e8b27691f72c84b3311750d5188ebba657"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"tracing-core",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-log"
|
||||
version = "0.2.0"
|
||||
|
|
|
@ -213,6 +213,8 @@ default-features = false
|
|||
version = "0.3.19"
|
||||
default-features = false
|
||||
features = ["env-filter", "std", "tracing", "tracing-log", "ansi", "fmt"]
|
||||
[workspace.dependencies.tracing-journald]
|
||||
version = "0.3.1"
|
||||
[workspace.dependencies.tracing-core]
|
||||
version = "0.1.33"
|
||||
default-features = false
|
||||
|
|
|
@ -16,6 +16,10 @@ DeviceAllow=char-tty
|
|||
StandardInput=tty-force
|
||||
StandardOutput=tty
|
||||
StandardError=journal+console
|
||||
|
||||
Environment="CONTINUWUITY_LOG_TO_JOURNALD=1"
|
||||
Environment="CONTINUWUITY_JOURNALD_IDENTIFIER=%N"
|
||||
|
||||
TTYReset=yes
|
||||
# uncomment to allow buffer to be cleared every restart
|
||||
TTYVTDisallocate=no
|
||||
|
|
|
@ -660,6 +660,15 @@
|
|||
#
|
||||
#log_thread_ids = false
|
||||
|
||||
# Enable journald logging on Unix platforms
|
||||
#
|
||||
#log_to_journald = false
|
||||
|
||||
# The syslog identifier to use with journald logging
|
||||
# Only used when journald logging is enabled
|
||||
#
|
||||
#journald_identifier = "conduwuit"
|
||||
|
||||
# OpenID token expiration/TTL in seconds.
|
||||
#
|
||||
# These are the OpenID tokens that are primarily used for Matrix account
|
||||
|
@ -1641,19 +1650,29 @@
|
|||
#
|
||||
#server =
|
||||
|
||||
# This item is undocumented. Please contribute documentation for it.
|
||||
# URL to a support page for the server, which will be served as part of
|
||||
# the MSC1929 server support endpoint at /.well-known/matrix/support.
|
||||
# Will be included alongside any contact information
|
||||
#
|
||||
#support_page =
|
||||
|
||||
# This item is undocumented. Please contribute documentation for it.
|
||||
# Role string for server support contacts, to be served as part of the
|
||||
# MSC1929 server support endpoint at /.well-known/matrix/support.
|
||||
#
|
||||
#support_role =
|
||||
#support_role = "m.role.admin"
|
||||
|
||||
# This item is undocumented. Please contribute documentation for it.
|
||||
# Email address for server support contacts, to be served as part of the
|
||||
# MSC1929 server support endpoint.
|
||||
# This will be used along with support_mxid if specified.
|
||||
#
|
||||
#support_email =
|
||||
|
||||
# This item is undocumented. Please contribute documentation for it.
|
||||
# Matrix ID for server support contacts, to be served as part of the
|
||||
# MSC1929 server support endpoint.
|
||||
# This will be used along with support_email if specified.
|
||||
#
|
||||
# If no email or mxid is specified, all of the server's admins will be
|
||||
# listed.
|
||||
#
|
||||
#support_mxid =
|
||||
|
||||
|
|
3
debian/conduwuit.service
vendored
3
debian/conduwuit.service
vendored
|
@ -14,6 +14,9 @@ Type=notify
|
|||
|
||||
Environment="CONTINUWUITY_CONFIG=/etc/conduwuit/conduwuit.toml"
|
||||
|
||||
Environment="CONTINUWUITY_LOG_TO_JOURNALD=1"
|
||||
Environment="CONTINUWUITY_JOURNALD_IDENTIFIER=%N"
|
||||
|
||||
ExecStart=/usr/sbin/conduwuit
|
||||
|
||||
ReadWritePaths=/var/lib/conduwuit /etc/conduwuit
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use axum::{Json, extract::State, response::IntoResponse};
|
||||
use conduwuit::{Error, Result};
|
||||
use futures::StreamExt;
|
||||
use ruma::api::client::{
|
||||
discovery::{
|
||||
discover_homeserver::{self, HomeserverInfo, SlidingSyncProxyInfo},
|
||||
|
@ -17,7 +18,7 @@ pub(crate) async fn well_known_client(
|
|||
State(services): State<crate::State>,
|
||||
_body: Ruma<discover_homeserver::Request>,
|
||||
) -> Result<discover_homeserver::Response> {
|
||||
let client_url = match services.server.config.well_known.client.as_ref() {
|
||||
let client_url = match services.config.well_known.client.as_ref() {
|
||||
| Some(url) => url.to_string(),
|
||||
| None => return Err(Error::BadRequest(ErrorKind::NotFound, "Not found.")),
|
||||
};
|
||||
|
@ -33,44 +34,63 @@ pub(crate) async fn well_known_client(
|
|||
/// # `GET /.well-known/matrix/support`
|
||||
///
|
||||
/// Server support contact and support page of a homeserver's domain.
|
||||
/// Implements MSC1929 for server discovery.
|
||||
/// If no configuration is set, uses admin users as contacts.
|
||||
pub(crate) async fn well_known_support(
|
||||
State(services): State<crate::State>,
|
||||
_body: Ruma<discover_support::Request>,
|
||||
) -> Result<discover_support::Response> {
|
||||
let support_page = services
|
||||
.server
|
||||
.config
|
||||
.well_known
|
||||
.support_page
|
||||
.as_ref()
|
||||
.map(ToString::to_string);
|
||||
|
||||
let role = services.server.config.well_known.support_role.clone();
|
||||
|
||||
// support page or role must be either defined for this to be valid
|
||||
if support_page.is_none() && role.is_none() {
|
||||
return Err(Error::BadRequest(ErrorKind::NotFound, "Not found."));
|
||||
}
|
||||
|
||||
let email_address = services.server.config.well_known.support_email.clone();
|
||||
let matrix_id = services.server.config.well_known.support_mxid.clone();
|
||||
|
||||
// if a role is specified, an email address or matrix id is required
|
||||
if role.is_some() && (email_address.is_none() && matrix_id.is_none()) {
|
||||
return Err(Error::BadRequest(ErrorKind::NotFound, "Not found."));
|
||||
}
|
||||
let email_address = services.config.well_known.support_email.clone();
|
||||
let matrix_id = services.config.well_known.support_mxid.clone();
|
||||
|
||||
// TODO: support defining multiple contacts in the config
|
||||
let mut contacts: Vec<Contact> = vec![];
|
||||
|
||||
if let Some(role) = role {
|
||||
let contact = Contact { role, email_address, matrix_id };
|
||||
let role_value = services
|
||||
.config
|
||||
.well_known
|
||||
.support_role
|
||||
.clone()
|
||||
.unwrap_or_else(|| "m.role.admin".to_owned().into());
|
||||
|
||||
contacts.push(contact);
|
||||
// Add configured contact if at least one contact method is specified
|
||||
if email_address.is_some() || matrix_id.is_some() {
|
||||
contacts.push(Contact {
|
||||
role: role_value.clone(),
|
||||
email_address: email_address.clone(),
|
||||
matrix_id: matrix_id.clone(),
|
||||
});
|
||||
}
|
||||
|
||||
// Try to add admin users as contacts if no contacts are configured
|
||||
if contacts.is_empty() {
|
||||
if let Ok(admin_room) = services.admin.get_admin_room().await {
|
||||
let admin_users = services.rooms.state_cache.room_members(&admin_room);
|
||||
let mut stream = admin_users;
|
||||
|
||||
while let Some(user_id) = stream.next().await {
|
||||
// Skip server user
|
||||
if *user_id == services.globals.server_user {
|
||||
break;
|
||||
}
|
||||
contacts.push(Contact {
|
||||
role: role_value.clone(),
|
||||
email_address: None,
|
||||
matrix_id: Some(user_id.to_owned()),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// support page or role+contacts must be either defined for this to be valid
|
||||
if contacts.is_empty() && support_page.is_none() {
|
||||
// No admin room, no configured contacts, and no support page
|
||||
return Err(Error::BadRequest(ErrorKind::NotFound, "Not found."));
|
||||
}
|
||||
|
||||
|
@ -84,9 +104,9 @@ pub(crate) async fn well_known_support(
|
|||
pub(crate) async fn syncv3_client_server_json(
|
||||
State(services): State<crate::State>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
let server_url = match services.server.config.well_known.client.as_ref() {
|
||||
let server_url = match services.config.well_known.client.as_ref() {
|
||||
| Some(url) => url.to_string(),
|
||||
| None => match services.server.config.well_known.server.as_ref() {
|
||||
| None => match services.config.well_known.server.as_ref() {
|
||||
| Some(url) => url.to_string(),
|
||||
| None => return Err(Error::BadRequest(ErrorKind::NotFound, "Not found.")),
|
||||
},
|
||||
|
|
|
@ -795,6 +795,24 @@ pub struct Config {
|
|||
#[serde(default)]
|
||||
pub log_thread_ids: bool,
|
||||
|
||||
/// Enable journald logging on Unix platforms
|
||||
///
|
||||
/// When enabled, log output will be sent to the systemd journal
|
||||
/// This is only supported on Unix platforms
|
||||
///
|
||||
/// default: false
|
||||
#[cfg(target_family = "unix")]
|
||||
#[serde(default)]
|
||||
pub log_to_journald: bool,
|
||||
|
||||
/// The syslog identifier to use with journald logging
|
||||
///
|
||||
/// Only used when journald logging is enabled
|
||||
///
|
||||
/// Defaults to the binary name
|
||||
#[cfg(target_family = "unix")]
|
||||
pub journald_identifier: Option<String>,
|
||||
|
||||
/// OpenID token expiration/TTL in seconds.
|
||||
///
|
||||
/// These are the OpenID tokens that are primarily used for Matrix account
|
||||
|
@ -1897,12 +1915,28 @@ pub struct WellKnownConfig {
|
|||
/// example: "matrix.example.com:443"
|
||||
pub server: Option<OwnedServerName>,
|
||||
|
||||
/// URL to a support page for the server, which will be served as part of
|
||||
/// the MSC1929 server support endpoint at /.well-known/matrix/support.
|
||||
/// Will be included alongside any contact information
|
||||
pub support_page: Option<Url>,
|
||||
|
||||
/// Role string for server support contacts, to be served as part of the
|
||||
/// MSC1929 server support endpoint at /.well-known/matrix/support.
|
||||
///
|
||||
/// default: "m.role.admin"
|
||||
pub support_role: Option<ContactRole>,
|
||||
|
||||
/// Email address for server support contacts, to be served as part of the
|
||||
/// MSC1929 server support endpoint.
|
||||
/// This will be used along with support_mxid if specified.
|
||||
pub support_email: Option<String>,
|
||||
|
||||
/// Matrix ID for server support contacts, to be served as part of the
|
||||
/// MSC1929 server support endpoint.
|
||||
/// This will be used along with support_email if specified.
|
||||
///
|
||||
/// If no email or mxid is specified, all of the server's admins will be
|
||||
/// listed.
|
||||
pub support_mxid: Option<OwnedUserId>,
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,10 @@ pub use ::toml;
|
|||
pub use ::tracing;
|
||||
pub use config::Config;
|
||||
pub use error::Error;
|
||||
pub use info::{rustc_flags_capture, version, version::version};
|
||||
pub use info::{
|
||||
rustc_flags_capture, version,
|
||||
version::{name, version},
|
||||
};
|
||||
pub use matrix::{Event, EventTypeExt, PduCount, PduEvent, PduId, RoomVersion, pdu, state_res};
|
||||
pub use server::Server;
|
||||
pub use utils::{ctor, dtor, implement, result, result::Result};
|
||||
|
|
|
@ -43,6 +43,7 @@ default = [
|
|||
"io_uring",
|
||||
"jemalloc",
|
||||
"jemalloc_conf",
|
||||
"journald",
|
||||
"media_thumbnail",
|
||||
"release_max_log_level",
|
||||
"systemd",
|
||||
|
@ -130,6 +131,11 @@ sentry_telemetry = [
|
|||
systemd = [
|
||||
"conduwuit-router/systemd",
|
||||
]
|
||||
journald = [ # This is a stub on non-unix platforms
|
||||
"dep:tracing-journald",
|
||||
]
|
||||
|
||||
|
||||
# enable the tokio_console server ncompatible with release_max_log_level
|
||||
tokio_console = [
|
||||
"dep:console-subscriber",
|
||||
|
@ -183,6 +189,7 @@ tracing-opentelemetry.optional = true
|
|||
tracing-opentelemetry.workspace = true
|
||||
tracing-subscriber.workspace = true
|
||||
tracing.workspace = true
|
||||
tracing-journald = { workspace = true, optional = true }
|
||||
|
||||
[target.'cfg(all(not(target_env = "msvc"), target_os = "linux"))'.dependencies]
|
||||
hardened_malloc-rs.workspace = true
|
||||
|
|
|
@ -15,7 +15,7 @@ use conduwuit_core::{
|
|||
#[clap(
|
||||
about,
|
||||
long_about = None,
|
||||
name = "conduwuit",
|
||||
name = conduwuit_core::name(),
|
||||
version = conduwuit_core::version(),
|
||||
)]
|
||||
pub(crate) struct Args {
|
||||
|
|
|
@ -43,6 +43,15 @@ pub(crate) fn init(
|
|||
.with(console_layer.with_filter(console_reload_filter))
|
||||
.with(cap_layer);
|
||||
|
||||
// If journald logging is enabled on Unix platforms, create a separate
|
||||
// subscriber for it
|
||||
#[cfg(all(target_family = "unix", feature = "journald"))]
|
||||
if config.log_to_journald {
|
||||
if let Err(e) = init_journald_logging(config) {
|
||||
eprintln!("Failed to initialize journald logging: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "sentry_telemetry")]
|
||||
let subscriber = {
|
||||
let sentry_filter = EnvFilter::try_new(&config.sentry_filter)
|
||||
|
@ -122,6 +131,28 @@ pub(crate) fn init(
|
|||
Ok(ret)
|
||||
}
|
||||
|
||||
#[cfg(all(target_family = "unix", feature = "journald"))]
|
||||
fn init_journald_logging(config: &Config) -> Result<()> {
|
||||
use tracing_journald::Layer as JournaldLayer;
|
||||
|
||||
let journald_filter =
|
||||
EnvFilter::try_new(&config.log).map_err(|e| err!(Config("log", "{e}.")))?;
|
||||
|
||||
let mut journald_layer = JournaldLayer::new()
|
||||
.map_err(|e| err!(Config("journald", "Failed to initialize journald layer: {e}.")))?;
|
||||
|
||||
if let Some(ref identifier) = config.journald_identifier {
|
||||
journald_layer = journald_layer.with_syslog_identifier(identifier.to_owned());
|
||||
}
|
||||
|
||||
let journald_subscriber =
|
||||
Registry::default().with(journald_layer.with_filter(journald_filter));
|
||||
|
||||
let _guard = tracing::subscriber::set_default(journald_subscriber);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn tokio_console_enabled(config: &Config) -> (bool, &'static str) {
|
||||
if !cfg!(all(feature = "tokio_console", tokio_unstable)) {
|
||||
return (false, "");
|
||||
|
@ -141,7 +172,10 @@ fn tokio_console_enabled(config: &Config) -> (bool, &'static str) {
|
|||
(true, "")
|
||||
}
|
||||
|
||||
fn set_global_default<S: SubscriberExt + Send + Sync>(subscriber: S) {
|
||||
fn set_global_default<S>(subscriber: S)
|
||||
where
|
||||
S: tracing::Subscriber + Send + Sync + 'static,
|
||||
{
|
||||
tracing::subscriber::set_global_default(subscriber)
|
||||
.expect("the global default tracing subscriber failed to be initialized");
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue