remove ip log

main
overlisted 1 month ago
parent 688db64970
commit 53774803bd
Signed by: me
GPG Key ID: 1ACCDCC0429C9737
  1. 47
      src/fairings/ip_log.rs
  2. 4
      src/fairings/mod.rs
  3. 1
      src/main.rs

@ -1,47 +0,0 @@
//! cry about it
use std::net;
use super::prelude::*;
struct IpLogger;
#[async_trait]
impl Fairing for IpLogger {
fn info(&self) -> Info {
Info {
kind: Kind::Request,
name: "IP Logger",
}
}
async fn on_request(&self, req: &mut rocket::Request<'_>, _data: &mut rocket::Data<'_>) {
let db = Db::get_one(req.rocket()).await.unwrap();
let path = req.uri().path().to_string();
let option = if let Some(value) = req.headers().get_one("X-Real-IP") {
value.parse::<net::IpAddr>().ok()
} else if let Some(addr) = req.remote() {
Some(addr.ip())
} else {
None
};
if let Some(addr) = option {
db.run(move |conn| {
diesel::insert_into(schema::ip_log::table)
.values((
schema::ip_log::addr.eq(ipnetwork::IpNetwork::from(addr)),
schema::ip_log::path.eq(path),
))
.execute(conn)
})
.await
.ok();
}
}
}
pub fn fairing() -> impl Fairing {
IpLogger
}

@ -3,9 +3,7 @@ mod prelude;
mod db;
mod frontend;
mod handlebars;
mod ip_log;
pub use self::handlebars::fairing as handlebars;
pub use db::fairing as db;
pub use frontend::fairing as frontend;
pub use self::handlebars::fairing as handlebars;
pub use ip_log::fairing as ip_log;

@ -13,7 +13,6 @@ mod guards;
fn rocket() -> _ {
rocket::build()
.attach(fairings::db())
.attach(fairings::ip_log())
.attach(fairings::handlebars())
.attach(fairings::frontend())
}

Loading…
Cancel
Save