Implement almost all previous features

This commit is contained in:
Lennart
2025-06-08 19:38:33 +02:00
parent 95889e3df1
commit 00eb43f048
41 changed files with 906 additions and 916 deletions

View File

@@ -1,14 +1,20 @@
use axum::Router;
use axum::response::Redirect;
use axum::routing::get;
use axum::extract::Request;
use axum::response::{Redirect, Response};
use axum::routing::{any, get};
use rustical_caldav::caldav_router;
use rustical_carddav::carddav_router;
use rustical_frontend::nextcloud_login::NextcloudFlows;
use rustical_frontend::nextcloud_login::{NextcloudFlows, nextcloud_login_router};
use rustical_frontend::{FrontendConfig, frontend_router};
use rustical_oidc::OidcConfig;
use rustical_store::auth::AuthenticationProvider;
use rustical_store::{AddressbookStore, CalendarStore, SubscriptionStore};
use std::sync::Arc;
use std::time::Duration;
use tower_http::classify::ServerErrorsFailureClass;
use tower_http::trace::TraceLayer;
use tower_sessions::MemoryStore;
use tracing::Span;
use crate::config::NextcloudLoginConfig;
@@ -45,13 +51,14 @@ pub fn make_app<AS: AddressbookStore, CS: CalendarStore, S: SubscriptionStore>(
)
.route(
"/.well-known/caldav",
get(async || Redirect::permanent("/caldav")),
any(async || Redirect::permanent("/caldav")),
)
.route(
"/.well-known/carddav",
get(async || Redirect::permanent("/caldav")),
any(async || Redirect::permanent("/caldav")),
);
let session_store = MemoryStore::default();
if frontend_config.enabled {
router = router
.nest(
@@ -62,21 +69,42 @@ pub fn make_app<AS: AddressbookStore, CS: CalendarStore, S: SubscriptionStore>(
addr_store.clone(),
frontend_config,
oidc_config,
session_store.clone(),
),
)
.route("/", get(async || Redirect::to("/frontend")));
}
router
if nextcloud_login_config.enabled {
router = router.nest(
"/index.php/login/v2",
nextcloud_login_router(
nextcloud_flows_state,
auth_provider.clone(),
session_store.clone(),
),
);
}
router.layer(
TraceLayer::new_for_http()
.make_span_with(|request: &Request| {
tracing::debug_span!(
"http-request",
status_code = tracing::field::Empty,
otel.name =
tracing::field::display(format!("{} {}", request.method(), request.uri())),
)
})
.on_request(|_req: &Request, _span: &Span| {})
.on_response(|response: &Response, _latency: Duration, span: &Span| {
span.record("status_code", tracing::field::display(response.status()));
// if nextcloud_login_config.enabled {
// app = app.configure(|cfg| {
// configure_nextcloud_login(
// cfg,
// nextcloud_flows_state,
// auth_provider.clone(),
// frontend_config.secret_key,
// )
// });
// }
tracing::debug!("response generated")
})
.on_failure(
|_error: ServerErrorsFailureClass, _latency: Duration, _span: &Span| {
tracing::error!("something went wrong")
},
),
)
}

View File

@@ -3,7 +3,7 @@ use clap::{Parser, ValueEnum};
use password_hash::PasswordHasher;
use pbkdf2::Params;
use rand::rngs::OsRng;
use rustical_frontend::{FrontendConfig, generate_frontend_secret};
use rustical_frontend::FrontendConfig;
use crate::config::{
Config, DataStoreConfig, DavPushConfig, HttpConfig, SqliteDataStoreConfig, TracingConfig,
@@ -23,7 +23,6 @@ pub fn cmd_gen_config(_args: GenConfigArgs) -> anyhow::Result<()> {
}),
tracing: TracingConfig::default(),
frontend: FrontendConfig {
secret_key: generate_frontend_secret(),
enabled: true,
allow_password_login: true,
},

View File

@@ -1,6 +1,8 @@
use crate::config::Config;
use anyhow::Result;
use app::make_app;
use axum::ServiceExt;
use axum::extract::Request;
use clap::{Parser, Subcommand};
use commands::principals::{PrincipalsArgs, cmd_principals};
use commands::{cmd_gen_config, cmd_pwhash};
@@ -18,6 +20,8 @@ use rustical_store_sqlite::{SqliteStore, create_db_pool};
use setup_tracing::setup_tracing;
use std::sync::Arc;
use tokio::sync::mpsc::Receiver;
use tower::Layer;
use tower_http::normalize_path::NormalizePathLayer;
mod app;
mod commands;
@@ -113,6 +117,9 @@ async fn main() -> Result<()> {
config.nextcloud_login.clone(),
nextcloud_flows.clone(),
);
let app = ServiceExt::<Request>::into_make_service(
NormalizePathLayer::trim_trailing_slash().layer(app),
);
let listener = tokio::net::TcpListener::bind(&format!(
"{}:{}",