summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTyler Murphy <tylermurphy534@gmail.com>2023-01-29 00:35:06 -0500
committerTyler Murphy <tylermurphy534@gmail.com>2023-01-29 00:35:06 -0500
commit7805c730e8ead9cd421f45d4720fd7f4062675e6 (patch)
treea46ec6de28c688f7961e6327e075925a8f50071c /src
parentreverse proxy ip checking (diff)
downloadxssbook-7805c730e8ead9cd421f45d4720fd7f4062675e6.tar.gz
xssbook-7805c730e8ead9cd421f45d4720fd7f4062675e6.tar.bz2
xssbook-7805c730e8ead9cd421f45d4720fd7f4062675e6.zip
no mass rerendering html plus logging fix
Diffstat (limited to 'src')
-rw-r--r--src/api/pages.rs14
-rw-r--r--src/console.rs5
-rw-r--r--src/main.rs15
-rw-r--r--src/types/extract.rs5
4 files changed, 14 insertions, 25 deletions
diff --git a/src/api/pages.rs b/src/api/pages.rs
index 4661b91..9149744 100644
--- a/src/api/pages.rs
+++ b/src/api/pages.rs
@@ -6,10 +6,10 @@ use axum::{
use crate::{
console,
- types::{extract::AuthorizedUser, http::ResponseCode},
+ types::{extract::{AuthorizedUser, Log}, http::ResponseCode},
};
-async fn root(user: Option<AuthorizedUser>) -> Response {
+async fn root(user: Option<AuthorizedUser>, _: Log) -> Response {
if user.is_some() {
Redirect::to("/home").into_response()
} else {
@@ -17,7 +17,7 @@ async fn root(user: Option<AuthorizedUser>) -> Response {
}
}
-async fn login(user: Option<AuthorizedUser>) -> Response {
+async fn login(user: Option<AuthorizedUser>, _: Log) -> Response {
if user.is_some() {
Redirect::to("/home").into_response()
} else {
@@ -25,7 +25,7 @@ async fn login(user: Option<AuthorizedUser>) -> Response {
}
}
-async fn home(user: Option<AuthorizedUser>) -> Response {
+async fn home(user: Option<AuthorizedUser>, _: Log) -> Response {
if user.is_none() {
Redirect::to("/login").into_response()
} else {
@@ -33,7 +33,7 @@ async fn home(user: Option<AuthorizedUser>) -> Response {
}
}
-async fn people(user: Option<AuthorizedUser>) -> Response {
+async fn people(user: Option<AuthorizedUser>, _: Log) -> Response {
if user.is_none() {
Redirect::to("/login").into_response()
} else {
@@ -41,7 +41,7 @@ async fn people(user: Option<AuthorizedUser>) -> Response {
}
}
-async fn profile(user: Option<AuthorizedUser>) -> Response {
+async fn profile(user: Option<AuthorizedUser>, _: Log) -> Response {
if user.is_none() {
Redirect::to("/login").into_response()
} else {
@@ -53,7 +53,7 @@ async fn console() -> Response {
console::generate().await
}
-async fn wordpress() -> Response {
+async fn wordpress(_: Log) -> Response {
ResponseCode::ImATeapot.text("Hello i am a teapot owo")
}
diff --git a/src/console.rs b/src/console.rs
index 14324fa..eb78c6a 100644
--- a/src/console.rs
+++ b/src/console.rs
@@ -45,10 +45,7 @@ lazy_static! {
}
pub async fn log(ip: IpAddr, method: Method, uri: Uri, path: Option<String>, body: Option<String>) {
- if uri.to_string().starts_with("/console") {
- return;
- }
-
+
let path = path.unwrap_or_default();
let body = body.unwrap_or_default();
diff --git a/src/main.rs b/src/main.rs
index cd137b9..20627d7 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,11 +1,11 @@
use axum::{
body::HttpBody,
- extract::ConnectInfo,
http::{Request, StatusCode},
middleware::{self, Next},
response::Response,
Extension, RequestExt, Router,
};
+use axum_client_ip::ClientIp;
use std::{net::SocketAddr, process::exit};
use tower_cookies::CookieManagerLayer;
use tracing::{error, info, metadata::LevelFilter};
@@ -40,18 +40,11 @@ async fn log<B>(mut req: Request<B>, next: Next<B>) -> Response
where
B: Send + Sync + 'static + HttpBody,
{
- let Ok(ConnectInfo(info)) = req.extract_parts::<ConnectInfo<SocketAddr>>().await else {
+ let Ok(ClientIp(ip)) = req.extract_parts::<ClientIp>().await else {
return next.run(req).await
};
- console::log(
- info.ip(),
- req.method().clone(),
- req.uri().clone(),
- None,
- None,
- )
- .await;
+ console::log(ip, req.method().clone(), req.uri().clone(), None, None).await;
next.run(req).await
}
@@ -80,9 +73,9 @@ async fn main() {
let app = Router::new()
.fallback(not_found)
- .nest("/", pages::router())
.layer(middleware::from_fn(log))
.layer(middleware::from_fn(serve))
+ .nest("/", pages::router())
.nest(
"/api/auth",
auth::router().layer(Extension(RouterURI("/api/auth"))),
diff --git a/src/types/extract.rs b/src/types/extract.rs
index e79aa7a..4d92a3b 100644
--- a/src/types/extract.rs
+++ b/src/types/extract.rs
@@ -85,10 +85,9 @@ where
type Rejection = Response;
async fn from_request(req: Request<B>, state: &S) -> Result<Self> {
-
let body = match parse_body(req, state).await {
Ok(body) => body,
- Err(err) => return Err(err)
+ Err(err) => return Err(err),
};
let Ok(value) = serde_json::from_str::<T>(&body) else {
@@ -128,7 +127,7 @@ where
B: HttpBody + Sync + Send + 'static,
B::Data: Send,
B::Error: Into<BoxError>,
- S: Send + Sync
+ S: Send + Sync,
{
let Ok(ClientIp(ip)) = req.extract_parts::<ClientIp>().await else {
tracing::error!("Failed to read client ip");