get client ip on upload action
This commit is contained in:
parent
6f9ef9be69
commit
dd4fc52c98
|
@ -383,6 +383,7 @@ dependencies = [
|
||||||
"toml",
|
"toml",
|
||||||
"urlencoding 2.1.3",
|
"urlencoding 2.1.3",
|
||||||
"warp",
|
"warp",
|
||||||
|
"warp-real-ip",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1077,6 +1078,15 @@ dependencies = [
|
||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rfc7239"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "087317b3cf7eb481f13bd9025d729324b7cd068d6f470e2d76d049e191f5ba47"
|
||||||
|
dependencies = [
|
||||||
|
"uncased",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustc-demangle"
|
name = "rustc-demangle"
|
||||||
version = "0.1.23"
|
version = "0.1.23"
|
||||||
|
@ -1548,6 +1558,15 @@ version = "1.17.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
|
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "uncased"
|
||||||
|
version = "0.9.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9b9bc53168a4be7402ab86c3aad243a84dd7381d09be0eddc81280c1da95ca68"
|
||||||
|
dependencies = [
|
||||||
|
"version_check",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicase"
|
name = "unicase"
|
||||||
version = "2.7.0"
|
version = "2.7.0"
|
||||||
|
@ -1689,6 +1708,16 @@ dependencies = [
|
||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "warp-real-ip"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "22f23ff9f07b19eab4161057a2378cede84d618d3553cb01fe2111bee684003b"
|
||||||
|
dependencies = [
|
||||||
|
"rfc7239",
|
||||||
|
"warp",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasi"
|
name = "wasi"
|
||||||
version = "0.11.0+wasi-snapshot-preview1"
|
version = "0.11.0+wasi-snapshot-preview1"
|
||||||
|
|
|
@ -27,6 +27,7 @@ tokio = { version = "1.32.0", features = ["rt", "macros", "rt-multi-thread"] }
|
||||||
toml = "0.8.2"
|
toml = "0.8.2"
|
||||||
urlencoding = "2.1.3"
|
urlencoding = "2.1.3"
|
||||||
warp = "0.3.6"
|
warp = "0.3.6"
|
||||||
|
warp-real-ip = "0.2.0"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
opt-level = 'z'
|
opt-level = 'z'
|
||||||
|
|
|
@ -3,13 +3,14 @@
|
||||||
forms.rs - All the forms
|
forms.rs - All the forms
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::{collections::HashMap, net::IpAddr};
|
||||||
|
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
use warp::{Filter, reply::{Reply, json, with_status, html}, reject::Rejection, filters::multipart::FormData, http::StatusCode};
|
use warp::{Filter, reply::{Reply, json, with_status, html}, reject::Rejection, filters::multipart::FormData, http::StatusCode};
|
||||||
use futures_util::TryStreamExt;
|
use futures_util::TryStreamExt;
|
||||||
use bytes::BufMut;
|
use bytes::BufMut;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
use warp_real_ip::real_ip;
|
||||||
|
|
||||||
use crate::files::{File, lookup::LookupKind, DeleteMode};
|
use crate::files::{File, lookup::LookupKind, DeleteMode};
|
||||||
|
|
||||||
|
@ -145,7 +146,7 @@ fn bad_req_html(data: String) -> Box<dyn Reply> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn upload(form: FormData, state: SharedState) -> Result<Box<dyn Reply>, Rejection> {
|
pub async fn upload(form: FormData, _ip: Option<IpAddr>, state: SharedState) -> Result<Box<dyn Reply>, Rejection> {
|
||||||
|
|
||||||
if ! state.config.files.allow_uploads {
|
if ! state.config.files.allow_uploads {
|
||||||
return Ok(
|
return Ok(
|
||||||
|
@ -251,6 +252,7 @@ pub async fn upload(form: FormData, state: SharedState) -> Result<Box<dyn Reply>
|
||||||
pub fn get_routes(state: SharedState) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
|
pub fn get_routes(state: SharedState) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
|
||||||
warp::post()
|
warp::post()
|
||||||
.and(warp::multipart::form())
|
.and(warp::multipart::form())
|
||||||
|
.and(real_ip(vec![state.env.proxy_addr]))
|
||||||
.and(
|
.and(
|
||||||
warp::any().map(move || state.clone())
|
warp::any().map(move || state.clone())
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue