Add geoip data and 451 handler

This commit is contained in:
jude 2025-02-08 19:28:00 +00:00
parent 7ac69b59af
commit 70d3bb6a36
5 changed files with 12700 additions and 0 deletions

View File

@ -59,6 +59,7 @@ assets = [
["reminder-dashboard/dist/index.html", "lib/reminder-rs/static/index.html", "644"], ["reminder-dashboard/dist/index.html", "lib/reminder-rs/static/index.html", "644"],
["conf/default.env", "etc/reminder-rs/config.env", "600"], ["conf/default.env", "etc/reminder-rs/config.env", "600"],
["conf/Rocket.toml", "etc/reminder-rs/Rocket.toml", "600"], ["conf/Rocket.toml", "etc/reminder-rs/Rocket.toml", "600"],
["conf/geo-asn-country-ipv4.csv", "etc/reminder-rs/geo-asn-country-ipv4.csv", "600"],
# ["nginx/reminder-rs", "etc/nginx/sites-available/reminder-rs", "755"] # ["nginx/reminder-rs", "etc/nginx/sites-available/reminder-rs", "755"]
] ]
conf-files = [ conf-files = [

12676
conf/gb-ipv4.csv Normal file

File diff suppressed because it is too large Load Diff

View File

@ -29,6 +29,12 @@ pub(crate) async fn not_found() -> Template {
Template::render("errors/404", &map) Template::render("errors/404", &map)
} }
#[catch(451)]
pub(crate) async fn legal_reasons() -> Template {
let map: HashMap<String, String> = HashMap::new();
Template::render("errors/451", &map)
}
#[catch(413)] #[catch(413)]
pub(crate) async fn payload_too_large() -> JsonValue { pub(crate) async fn payload_too_large() -> JsonValue {
json!({"error": "Data too large.", "errors": ["Data too large."]}) json!({"error": "Data too large.", "errors": ["Data too large."]})

View File

@ -107,6 +107,12 @@ pub async fn initialize(
env::var("PATREON_GUILD_ID").expect("`PATREON_GUILD_ID' not supplied"); env::var("PATREON_GUILD_ID").expect("`PATREON_GUILD_ID' not supplied");
} }
info!("Loading GB IP list");
let lower_bounds: Vec<u32> = vec![];
let upper_bounds: Vec<u32> = vec![];
let mut reader = csv::Reader::from_path("gb-ipv4.csv");
info!("Done!"); info!("Done!");
let oauth2_client = BasicClient::new( let oauth2_client = BasicClient::new(
@ -131,6 +137,7 @@ pub async fn initialize(
catchers::not_authorized, catchers::not_authorized,
catchers::forbidden, catchers::forbidden,
catchers::not_found, catchers::not_found,
catchers::legal_reasons,
catchers::internal_server_error, catchers::internal_server_error,
catchers::unprocessable_entity, catchers::unprocessable_entity,
catchers::payload_too_large, catchers::payload_too_large,

View File

@ -0,0 +1,10 @@
{% extends "base" %}
{% block init %}
{% set title = "451 Unavailable due to legal reasons" %}
{% set show_contact = True %}
{% set page_title = "Unavailable in this region" %}
{% set page_subtitle = "This service is unavailable in the UK due to the Online Safety Act. Consider using a VPN to access this service." %}
{% endblock %}