Skip to content
Snippets Groups Projects
Verified Commit 7d88d584 authored by Volkor Barbarian Warrior's avatar Volkor Barbarian Warrior
Browse files

fix up ip logging

parent 4a10b817
No related branches found
No related tags found
No related merge requests found
......@@ -14,6 +14,7 @@ use salvo::{
use tracing::{error, info, warn};
use crate::db;
use crate::handlers::guess_ip;
use crate::{
handlers::{render_template, Generic, TemplateEnum},
keys::{
......@@ -81,7 +82,7 @@ pub async fn admin(req: &mut Request, res: &mut Response, depot: &mut Depot) {
info!(
"[{:?} - {:?}] User attempted to view '/admin' without a valid master key. Blocking.",
headers[HOST].to_str().unwrap(),
remote_addr
guess_ip(&headers, remote_addr)
);
let template_filename = "error.html";
let template = TemplateEnum::Generic(Generic {
......
......@@ -5,7 +5,7 @@ use salvo::{
use tracing::{debug, error, info};
use crate::{
handlers::{is_browser, render_template, Generic, TemplateEnum},
handlers::{guess_ip, is_browser, render_template, Generic, TemplateEnum},
keys::{self, db_keys},
SQLITE,
};
......@@ -49,7 +49,7 @@ pub async fn require_auth(res: &mut Response, req: &mut Request, depot: &mut Dep
info!(
"[{:?} - {:?}] Attempted Access of authorised endpoint. Blocking.",
headers[HOST].to_str().unwrap(),
remote_addr
guess_ip(headers, remote_addr)
);
// Key is not Present. Failing.
if is_user_web {
......@@ -85,7 +85,7 @@ pub async fn require_auth(res: &mut Response, req: &mut Request, depot: &mut Dep
info!(
"[{:?} - {:?}] Attempted File upload with revoked API Key. Blocking.",
headers[HOST].to_str().unwrap(),
remote_addr
guess_ip(headers, remote_addr)
);
// Check if the upload came from the web
if is_user_web {
......@@ -128,7 +128,7 @@ pub async fn require_auth(res: &mut Response, req: &mut Request, depot: &mut Dep
info!(
"[{:?} - {:?}] Attempted Access with an invalid API Key ({}). Blocking.",
headers[HOST].to_str().unwrap(),
remote_addr,
guess_ip(headers, remote_addr),
token.expect("Somehow failed to unwrap token.")
);
// Check if the upload came from the web
......
......@@ -4,7 +4,7 @@ use salvo::{
};
use tracing::{debug, error, info};
use crate::{db, engine, keys::Key, SQLITE};
use crate::{db, engine, handlers::guess_ip, keys::Key, SQLITE};
/// Endpoint for deleting files.
///
......@@ -62,7 +62,7 @@ pub async fn delete_file(req: &mut Request, res: &mut Response, depot: &mut Depo
info!(
"[{:?} - {:?}] User deleted file '{}'",
headers[HOST].to_str().unwrap(),
remote_addr,
guess_ip(&headers, remote_addr),
filename
);
......
......@@ -2,7 +2,7 @@ use salvo::{handler, hyper::header::HOST, prelude::StatusCode, Request, Response
use std::path::PathBuf;
use tracing::{debug, info};
use crate::handlers::{render_template, Generic, TemplateEnum};
use crate::handlers::{guess_ip, render_template, Generic, TemplateEnum};
/// This file handles (heh) the main index page for the application.
#[handler]
......@@ -14,7 +14,7 @@ pub async fn index(req: &mut Request, res: &mut Response) {
info!(
"[{:?} - {:?}] New Request: /",
headers[HOST].to_str().unwrap(),
remote_addr
guess_ip(headers, remote_addr)
);
// Renders the template based on `/templates/$host/upload.html`
......
......@@ -16,7 +16,7 @@ use tracing::{debug, error, info, warn};
use crate::{
db::{self, FileCheckResult},
engine,
handlers::{add_undeleted_file, check_file_exists, render_template},
handlers::{add_undeleted_file, check_file_exists, guess_ip, render_template},
CONFIG, SQLITE,
};
......@@ -35,7 +35,7 @@ pub async fn render_file(req: &mut Request, res: &mut Response, headers: HeaderM
info!(
"[{:?} - {:?}] New View on file '{}'",
headers[HOST].to_str().unwrap(),
remote_addr,
guess_ip(&headers, remote_addr),
filename
);
......@@ -59,7 +59,7 @@ pub async fn render_file(req: &mut Request, res: &mut Response, headers: HeaderM
info!(
"[{:?} - {:?}] Setting mimetype of '{}' to safe fallback (text/plain)",
headers[HOST].to_str().unwrap(),
remote_addr,
guess_ip(&headers, remote_addr),
filename
);
mimetype = String::from("text/plain"); // If there is a match, change the mimetype to text/plain
......@@ -191,7 +191,7 @@ pub async fn serve_file(req: &mut Request, res: &mut Response) {
info!(
"[{:?} - {:?}] Missing file '{}' re-added correctly.",
headers[HOST].to_str().unwrap(),
remote_addr,
guess_ip(&headers, remote_addr),
filename
);
// Now we can render the file!
......@@ -217,7 +217,7 @@ pub async fn serve_file(req: &mut Request, res: &mut Response) {
error!(
"[{:?} - {:?}] Error while finding file '{}' in the database: {}",
headers[HOST].to_str().unwrap(),
remote_addr,
guess_ip(&headers, remote_addr),
filename,
err
);
......
......@@ -38,7 +38,7 @@ pub async fn serve_static(req: &mut Request, res: &mut Response) {
info!(
"[{:?} - {:?}] New Request: /services",
headers[HOST].to_str().unwrap(),
remote_addr
guess_ip(headers, remote_addr)
);
// Create the template from the generic.
......@@ -63,7 +63,7 @@ pub async fn serve_static(req: &mut Request, res: &mut Response) {
info!(
"[{:?} - {:?}] New Request: /about",
headers[HOST].to_str().unwrap(),
remote_addr
guess_ip(headers, remote_addr)
);
// Create the template from the generic.
......@@ -88,7 +88,7 @@ pub async fn serve_static(req: &mut Request, res: &mut Response) {
info!(
"[{:?} - {:?}] New Request: /faq",
headers[HOST].to_str().unwrap(),
remote_addr
guess_ip(headers, remote_addr)
);
// Create the template from the generic.
......@@ -113,7 +113,7 @@ pub async fn serve_static(req: &mut Request, res: &mut Response) {
info!(
"[{:?} - {:?}] New Request: /dmca",
headers[HOST].to_str().unwrap(),
remote_addr
guess_ip(headers, remote_addr)
);
// Create the template from the generic.
......@@ -138,7 +138,7 @@ pub async fn serve_static(req: &mut Request, res: &mut Response) {
info!(
"[{:?} - {:?}] New Request: /welcome",
headers[HOST].to_str().unwrap(),
remote_addr
guess_ip(headers, remote_addr)
);
// Create the template from the generic.
......@@ -163,7 +163,7 @@ pub async fn serve_static(req: &mut Request, res: &mut Response) {
info!(
"[{:?} - {:?}] New Request: /czb",
headers[HOST].to_str().unwrap(),
remote_addr
guess_ip(headers, remote_addr)
);
// Create the template from the generic.
......@@ -188,7 +188,7 @@ pub async fn serve_static(req: &mut Request, res: &mut Response) {
info!(
"[{:?} - {:?}] New Request: /qr",
headers[HOST].to_str().unwrap(),
remote_addr
guess_ip(headers, remote_addr)
);
// Setup the Sqlite pool stuff for later
let sqlconn = SQLITE.get().unwrap();
......@@ -202,7 +202,7 @@ pub async fn serve_static(req: &mut Request, res: &mut Response) {
error!(
"[{:?} - {:?}] Error when adding QR Code scan to the database",
headers[HOST].to_str().unwrap(),
remote_addr
guess_ip(&headers, remote_addr)
);
}
......@@ -228,7 +228,7 @@ pub async fn serve_static(req: &mut Request, res: &mut Response) {
warn!(
"[{:?} - {:?}] Bad Request Received: {}",
headers[HOST].to_str().unwrap(),
remote_addr,
guess_ip(headers, remote_addr),
e
);
// TODO: Nice Render page
......
......@@ -84,7 +84,7 @@ pub async fn upload(req: &mut Request, res: &mut Response, depot: &mut Depot) {
info!(
"[{:?} - {:?}] Validating mimetype for file '{}'",
headers[HOST].to_str().unwrap(),
remote_addr,
guess_ip(headers, remote_addr),
filename.to_str().unwrap_or("")
);
// Check if the mimetype is banned, and render the error pages.
......@@ -114,7 +114,7 @@ pub async fn upload(req: &mut Request, res: &mut Response, depot: &mut Depot) {
info!(
"[{:?} - {:?}] Bypassing Mimetype check for non-Normal-ranked user.",
headers[HOST].to_str().unwrap(),
remote_addr
guess_ip(headers, remote_addr)
);
}
......@@ -192,7 +192,7 @@ pub async fn upload(req: &mut Request, res: &mut Response, depot: &mut Depot) {
headers[HOST].to_str().unwrap(),
filename,
&key.uuid,
remote_addr
guess_ip(headers, remote_addr)
);
let fileurl = format!(
"{}://{}/{}",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment