2023-02-16 21:44:00 +01:00
|
|
|
use actix_web::{dev::ConnectionInfo, get, routes, web, HttpRequest, HttpResponse, Responder};
|
2023-02-08 22:14:57 +01:00
|
|
|
use askama::Template;
|
|
|
|
|
|
|
|
use crate::config::Config;
|
|
|
|
|
|
|
|
#[routes]
|
|
|
|
#[get("/.well-known/security.txt")]
|
|
|
|
#[get("/security.txt")]
|
|
|
|
pub async fn security(req: HttpRequest, config: web::Data<Config>) -> impl Responder {
|
2023-02-16 21:44:00 +01:00
|
|
|
HttpResponse::Ok().body(get_security(
|
|
|
|
config.get_ref().clone(),
|
|
|
|
req.connection_info().to_owned(),
|
|
|
|
))
|
2023-02-08 22:14:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Template)]
|
|
|
|
#[template(path = "../templates/security.txt")]
|
|
|
|
struct SecurityTemplate {
|
|
|
|
contact: String,
|
|
|
|
pref_lang: String,
|
|
|
|
url: String,
|
|
|
|
}
|
|
|
|
|
2023-02-16 21:44:00 +01:00
|
|
|
fn get_security(config: Config, info: ConnectionInfo) -> String {
|
2023-02-08 22:14:57 +01:00
|
|
|
let data = SecurityTemplate {
|
|
|
|
contact: config.mail.unwrap_or_default(),
|
|
|
|
pref_lang: config.lang.unwrap_or_default(),
|
2023-02-16 22:20:38 +01:00
|
|
|
url: format!(
|
|
|
|
"{}://{}/.well-known/security.txt",
|
|
|
|
info.scheme(),
|
|
|
|
info.host()
|
|
|
|
),
|
2023-02-08 22:14:57 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
data.render().unwrap()
|
|
|
|
}
|
2023-02-08 22:22:20 +01:00
|
|
|
|
|
|
|
#[get("/humans.txt")]
|
|
|
|
pub async fn humans() -> impl Responder {
|
2023-02-09 12:01:35 +01:00
|
|
|
// TODO, see https://humanstxt.org/humans.txt
|
2023-02-08 22:22:20 +01:00
|
|
|
actix_web::web::Redirect::to("/")
|
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/robots.txt")]
|
|
|
|
pub async fn robots() -> impl Responder {
|
2023-02-09 12:01:35 +01:00
|
|
|
HttpResponse::Ok().body(get_robots())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_robots() -> String {
|
|
|
|
// TODO, see https://www.robotstxt.org/orig.html
|
|
|
|
"User-agent: * Allow: /".to_string()
|
2023-02-08 22:22:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/sitemap.xml")]
|
|
|
|
pub async fn sitemap() -> impl Responder {
|
|
|
|
// TODO
|
|
|
|
actix_web::web::Redirect::to("/")
|
|
|
|
}
|