2023-04-11 10:03:22 +02:00
|
|
|
use crate::{config::Config, template::Infos};
|
2023-02-16 21:44:00 +01:00
|
|
|
use actix_web::{dev::ConnectionInfo, get, routes, web, HttpRequest, HttpResponse, Responder};
|
2023-04-11 10:45:25 +02:00
|
|
|
use cached::proc_macro::once;
|
2023-04-09 19:02:06 +02:00
|
|
|
use ramhorns::Content;
|
2023-02-08 22:14:57 +01:00
|
|
|
|
|
|
|
#[routes]
|
|
|
|
#[get("/.well-known/security.txt")]
|
|
|
|
#[get("/security.txt")]
|
|
|
|
pub async fn security(req: HttpRequest, config: web::Data<Config>) -> impl Responder {
|
2023-04-20 15:43:25 +02:00
|
|
|
HttpResponse::Ok().body(build_securitytxt(
|
2023-04-24 12:18:21 +02:00
|
|
|
config.get_ref().to_owned(),
|
2023-02-16 21:44:00 +01:00
|
|
|
req.connection_info().to_owned(),
|
|
|
|
))
|
2023-02-08 22:14:57 +01:00
|
|
|
}
|
|
|
|
|
2023-04-09 19:02:06 +02:00
|
|
|
#[derive(Content)]
|
2023-02-08 22:14:57 +01:00
|
|
|
struct SecurityTemplate {
|
|
|
|
contact: String,
|
|
|
|
pref_lang: String,
|
|
|
|
url: String,
|
|
|
|
}
|
|
|
|
|
2023-04-11 10:45:25 +02:00
|
|
|
#[once(time = 60)]
|
2023-04-20 15:43:25 +02:00
|
|
|
fn build_securitytxt(config: Config, info: ConnectionInfo) -> String {
|
2023-04-09 19:26:20 +02:00
|
|
|
config.tmpl.render(
|
2023-04-09 19:02:06 +02:00
|
|
|
"security.txt",
|
|
|
|
SecurityTemplate {
|
|
|
|
contact: config.fc.mail.unwrap_or_default(),
|
|
|
|
pref_lang: config.fc.lang.unwrap_or_default(),
|
|
|
|
url: format!(
|
|
|
|
"{}://{}/.well-known/security.txt",
|
|
|
|
info.scheme(),
|
|
|
|
info.host()
|
|
|
|
),
|
|
|
|
},
|
2023-04-11 10:03:22 +02:00
|
|
|
Infos::default(),
|
2023-04-09 19:02:06 +02:00
|
|
|
)
|
2023-02-08 22:14:57 +01:00
|
|
|
}
|
2023-02-08 22:22:20 +01:00
|
|
|
|
|
|
|
#[get("/humans.txt")]
|
2023-04-28 12:19:46 +02:00
|
|
|
pub async fn humans(config: web::Data<Config>) -> impl Responder {
|
|
|
|
HttpResponse::Ok().body(build_humanstxt(config.get_ref().to_owned()))
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Content)]
|
|
|
|
struct HumansTemplate {
|
|
|
|
contact: String,
|
|
|
|
lang: String,
|
|
|
|
name: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[once(time = 60)]
|
|
|
|
fn build_humanstxt(config: Config) -> String {
|
|
|
|
config.tmpl.render(
|
|
|
|
"humans.txt",
|
|
|
|
HumansTemplate {
|
|
|
|
contact: config.fc.mail.unwrap_or_default(),
|
|
|
|
lang: config.fc.lang.unwrap_or_default(),
|
2023-04-28 12:49:48 +02:00
|
|
|
name: config.fc.fullname.unwrap_or_default(),
|
2023-04-28 12:19:46 +02:00
|
|
|
},
|
|
|
|
Infos::default(),
|
|
|
|
)
|
2023-02-08 22:22:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/robots.txt")]
|
|
|
|
pub async fn robots() -> impl Responder {
|
2023-04-20 15:43:25 +02:00
|
|
|
HttpResponse::Ok().body(build_robotstxt())
|
2023-02-09 12:01:35 +01:00
|
|
|
}
|
|
|
|
|
2023-04-11 10:45:25 +02:00
|
|
|
#[once(time = 60)]
|
2023-04-20 15:43:25 +02:00
|
|
|
fn build_robotstxt() -> String {
|
2023-04-26 12:07:46 +02:00
|
|
|
"User-agent: * Allow: /".into()
|
2023-02-08 22:22:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/sitemap.xml")]
|
|
|
|
pub async fn sitemap() -> impl Responder {
|
|
|
|
// TODO
|
|
|
|
actix_web::web::Redirect::to("/")
|
|
|
|
}
|