All checks were successful
Build and Test / account (push) Successful in 7m48s
Basically I removed all the warnings, removed some old APIs no longer in use, added cert verification to DB, im just cool like that.
79 lines
No EOL
2 KiB
Rust
79 lines
No EOL
2 KiB
Rust
use std::{env, io};
|
|
use std::collections::HashSet;
|
|
use once_cell::sync::Lazy;
|
|
use rocket::fs::NamedFile;
|
|
use rocket::{get, Request};
|
|
use rocket::http::Status;
|
|
use rocket::request::{FromRequest, Outcome};
|
|
use rocket::response::content::RawXml;
|
|
use tokio::fs::try_exists;
|
|
use tokio::sync::RwLock;
|
|
use tonic::async_trait;
|
|
use crate::dsresponse::Ds;
|
|
|
|
pub static EVIL_AGREEMENT_THING: Lazy<RwLock<HashSet<String>>> = Lazy::new(|| Default::default());
|
|
|
|
pub struct CFIP(pub String);
|
|
|
|
#[async_trait]
|
|
impl<'r> FromRequest<'r> for CFIP{
|
|
type Error = ();
|
|
|
|
async fn from_request(request: &'r Request<'_>) -> Outcome<Self, Self::Error> {
|
|
match request.headers().get("CF-Connecting-IP").next(){
|
|
Some(v) => Outcome::Success(Self(v.to_owned())),
|
|
None => Outcome::Error((Status::ImATeapot, ()))
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
#[get("/v1/api/content/agreements/Nintendo-Network-EULA/<lang>/@latest")]
|
|
pub async fn get_agreement(lang: &str, ip: CFIP) -> io::Result<Ds<RawXml<NamedFile>>>{
|
|
|
|
|
|
let base_path = {
|
|
// if this crashes then something is wrong with the server setup so crashing here is fine imo
|
|
let mut path = env::current_dir().unwrap();
|
|
|
|
path.push("res");
|
|
path.push("agreement");
|
|
|
|
path
|
|
};
|
|
|
|
if EVIL_AGREEMENT_THING.read().await.contains(&ip.0) {
|
|
let path = {
|
|
let mut path = base_path;
|
|
|
|
path.push("EVIL.xml");
|
|
|
|
path
|
|
};
|
|
|
|
Ok(Ds(RawXml(NamedFile::open(&path).await?)))
|
|
} else {
|
|
let requested_file_path = {
|
|
let mut path = base_path.clone();
|
|
|
|
path.push(format!("{}.xml", lang));
|
|
|
|
path
|
|
};
|
|
|
|
|
|
if try_exists(&requested_file_path).await.is_ok_and(|v| v == true) {
|
|
Ok(Ds(RawXml(NamedFile::open(&requested_file_path).await?)))
|
|
} else {
|
|
let fallback_path = {
|
|
let mut path = base_path;
|
|
|
|
path.push("DEFAULT.xml");
|
|
|
|
path
|
|
};
|
|
|
|
Ok(Ds(RawXml(NamedFile::open(&fallback_path).await?)))
|
|
}
|
|
}
|
|
} |