diff --git a/Rocket.toml b/Rocket.toml index b43ee39..cc67c7d 100644 --- a/Rocket.toml +++ b/Rocket.toml @@ -1,5 +1,6 @@ [default] template_dir = "static/html" +ip_header = "Proxy-Real-IP" [debug] address = "127.0.0.1" diff --git a/src/main.rs b/src/main.rs index 8100949..00d45ad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,16 @@ use rocket::form::Form; use rocket_dyn_templates::{Template, context}; use rocket::fs::FileServer; +use std::net::{IpAddr, Ipv4Addr}; + + +fn ip_to_ipv4(ip: IpAddr) -> Option { + if let IpAddr::V4(v4_addr) = ip { + Some(v4_addr) + } else { + None + } +} #[derive(FromForm)] struct LoginData { @@ -25,8 +35,17 @@ fn login(login_data: Form) -> Template { } #[get("/")] -fn index() -> Template { - Template::render("index", context! {}) +fn index(ip: IpAddr) -> Template { + if let Some(ipv4) = ip_to_ipv4(ip) { + if ipv4.is_private() { + Template::render("private_index", context! {}) + } else { + Template::render("index", context! {}) + } + } else { + Template::render("index", context! {}) + } + } #[launch] diff --git a/static/html/private_index.html.tera b/static/html/private_index.html.tera new file mode 100644 index 0000000..6166027 --- /dev/null +++ b/static/html/private_index.html.tera @@ -0,0 +1,49 @@ + + + + + + EnglerLabs + + + + + + + +
+
+
+ + + + +