1 parent
052a27bc48
commit
528017b0e6
36 files changed
+3394
-216
No files matched your search
+15
-5
@@ -14,7 +14,7 @@ use axum::extract::{ConnectInfo, Request, State as AxState};
|
||||
use axum::http::{Method, StatusCode};
|
||||
use axum::middleware::{self, Next};
|
||||
use axum::response::{IntoResponse, Response};
|
||||
use axum::routing::{get, post, put};
|
||||
use axum::routing::{delete, get, post, put};
|
||||
use axum::{Json, Router};
|
||||
use std::net::SocketAddr;
|
||||
|
||||
@@ -91,7 +91,7 @@ async fn api_guard(
|
||||
let Some(user) = auth::session_user(&state, req.headers()).await else {
|
||||
return ApiError(StatusCode::UNAUTHORIZED, "login required".into()).into_response();
|
||||
};
|
||||
let viewer_ok = path == "/api/logout" || path == "/api/me/password";
|
||||
let viewer_ok = path == "/api/logout" || path == "/api/me/password" || path == "/api/me/prefs";
|
||||
if mutating && user.role != "admin" && !viewer_ok {
|
||||
return ApiError::forbidden().into_response();
|
||||
}
|
||||
@@ -147,11 +147,11 @@ async fn request_log(
|
||||
|| path == "/healthz"
|
||||
|| path == "/metrics";
|
||||
if status.is_client_error() || status.is_server_error() {
|
||||
tracing::warn!(target: "access", "{ip} {method} {path}{query} → {} ({ms} ms) · {ua}", status.as_u16());
|
||||
tracing::warn!(target: "access", "{ip} {method} {path}{query} status {} ({ms} ms) · {ua}", status.as_u16());
|
||||
} else if noisy {
|
||||
tracing::debug!(target: "access", "{ip} {method} {path}{query} → {} ({ms} ms) · {ua}", status.as_u16());
|
||||
tracing::debug!(target: "access", "{ip} {method} {path}{query} status {} ({ms} ms) · {ua}", status.as_u16());
|
||||
} else {
|
||||
tracing::info!(target: "access", "{ip} {method} {path}{query} → {} ({ms} ms) · {ua}", status.as_u16());
|
||||
tracing::info!(target: "access", "{ip} {method} {path}{query} status {} ({ms} ms) · {ua}", status.as_u16());
|
||||
}
|
||||
res
|
||||
}
|
||||
@@ -173,6 +173,16 @@ pub fn router(state: State) -> Router {
|
||||
.route("/api/logout", post(api::logout))
|
||||
.route("/api/me", get(api::me))
|
||||
.route("/api/me/password", post(api::change_password))
|
||||
.route("/api/me/prefs", get(api::my_prefs).put(api::save_my_prefs))
|
||||
.route("/api/me/sessions", get(api::my_sessions))
|
||||
.route("/api/me/sessions/others", post(api::end_other_sessions))
|
||||
.route("/api/me/sessions/{id}", delete(api::end_session))
|
||||
.route("/api/backup/database", get(api::backup_download))
|
||||
.route("/api/signal/hold", post(api::signal_hold))
|
||||
.route(
|
||||
"/api/stats/viewing",
|
||||
get(api::viewing_stats).delete(api::viewing_stats_clear),
|
||||
)
|
||||
.route("/api/status", get(api::status))
|
||||
.route("/api/stats", get(api::stats))
|
||||
.route("/api/logs", get(api::logs))
|
||||
|
||||
Reference in new issue
Block a user