Compare commits
2 Commits
c1220cac79
...
dd4fc52c98
Author | SHA1 | Date |
---|---|---|
blek | dd4fc52c98 | |
blek | 6f9ef9be69 |
|
@ -383,6 +383,7 @@ dependencies = [
|
|||
"toml",
|
||||
"urlencoding 2.1.3",
|
||||
"warp",
|
||||
"warp-real-ip",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1077,6 +1078,15 @@ dependencies = [
|
|||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rfc7239"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "087317b3cf7eb481f13bd9025d729324b7cd068d6f470e2d76d049e191f5ba47"
|
||||
dependencies = [
|
||||
"uncased",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-demangle"
|
||||
version = "0.1.23"
|
||||
|
@ -1548,6 +1558,15 @@ version = "1.17.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
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]]
|
||||
name = "unicase"
|
||||
version = "2.7.0"
|
||||
|
@ -1689,6 +1708,16 @@ dependencies = [
|
|||
"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]]
|
||||
name = "wasi"
|
||||
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"
|
||||
urlencoding = "2.1.3"
|
||||
warp = "0.3.6"
|
||||
warp-real-ip = "0.2.0"
|
||||
|
||||
[profile.release]
|
||||
opt-level = 'z'
|
||||
|
|
|
@ -45,6 +45,7 @@ pub fn loadenv() -> Result<Env, Box<dyn std::error::Error>> {
|
|||
let env_var = get_var::<&str, String>("PROXY_IP")?;
|
||||
|
||||
let ip = env_var.parse::<IpAddr>();
|
||||
let ret =
|
||||
if let Ok(ip) = ip {
|
||||
if ip == IpAddr::from([127, 0, 0, 1]) {
|
||||
log::warn!("Proxy address is 127.0.0.1. No proxy will be trusted")
|
||||
|
@ -56,6 +57,13 @@ pub fn loadenv() -> Result<Env, Box<dyn std::error::Error>> {
|
|||
}
|
||||
ip
|
||||
} else {
|
||||
let mut env_var = env_var;
|
||||
|
||||
// add port if not added
|
||||
if env_var.split(":").collect::<Vec<&str>>().len() == 1 {
|
||||
env_var.push_str(":80");
|
||||
}
|
||||
|
||||
let sock = env_var.to_socket_addrs();
|
||||
if let Err(err) = sock {
|
||||
return Err(format!("Can't resolve {env_var}: {:?}", err).into());
|
||||
|
@ -64,8 +72,15 @@ pub fn loadenv() -> Result<Env, Box<dyn std::error::Error>> {
|
|||
if addrs.len() == 0 {
|
||||
return Err(format!("{env_var} resolved to nothing").into());
|
||||
}
|
||||
addrs.next().unwrap().ip()
|
||||
let addr = addrs.next().unwrap().ip();
|
||||
addr
|
||||
};
|
||||
#[cfg(debug_assertions)] {
|
||||
if ret != IpAddr::from([ 127, 0, 0, 1 ]) {
|
||||
log::debug!("Proxy ip is {}", ret)
|
||||
}
|
||||
}
|
||||
ret
|
||||
},
|
||||
redis: Redis {
|
||||
pass: get_var("REDIS_PASS")?,
|
||||
|
|
|
@ -3,13 +3,14 @@
|
|||
forms.rs - All the forms
|
||||
*/
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::{collections::HashMap, net::IpAddr};
|
||||
|
||||
use askama::Template;
|
||||
use warp::{Filter, reply::{Reply, json, with_status, html}, reject::Rejection, filters::multipart::FormData, http::StatusCode};
|
||||
use futures_util::TryStreamExt;
|
||||
use bytes::BufMut;
|
||||
use serde::Serialize;
|
||||
use warp_real_ip::real_ip;
|
||||
|
||||
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 {
|
||||
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 {
|
||||
warp::post()
|
||||
.and(warp::multipart::form())
|
||||
.and(real_ip(vec![state.env.proxy_addr]))
|
||||
.and(
|
||||
warp::any().map(move || state.clone())
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue