diff --git a/README.md b/README.md index 1429981..8622aa2 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,11 @@ # echoip-slatecave -This is a service inspired by ifconfig.co, but built from scratch with a more useful feature set (in rust !!1!). +This is a service inspired by ifconfig.co, but built from scratch with a more useful feature set. It is Licensed under the AGPL-v3 license. + + ## Building Simply run `cargo build` after cloning. The binary should be called `target/debug/echoip-slatecave`. @@ -63,10 +65,16 @@ In addition to that the following fields are accessible from inside the template The templates are covered by the AGPL as well, please share them with your users if you modified them. -### GeoLite2 database +### Geolocation databases For geolocation to work you need a MaxMind format database, for full functionality you need the GeoLite2-ASN and GeoLite2-City databses. Unfortunately you have to sign up with [MaxMind](https://maxmind.com) to obtain them. Once you have a license key there is a helper script in [contrib/maxmind-download.sh](contrib/maxmind-download.sh) that helps you with keeping the databse updated. +As an alternative to MaxMind there is also [DB-IP who offer their free databases without a login](https://db-ip.com/db/lite.php). You want the City and ASN databases in mmdb format. + +**Don't forget to set the atttribution in the template configuration appropriately.** + +See the file `templates/extra.toml`. + Since v1.0 echoip-slatecave reloads the databses when it rececieves a `USR1` signal. ## Security Considerations diff --git a/src/main.rs b/src/main.rs index 6e4f73f..4400199 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,6 +32,7 @@ use tokio::task; use std::collections::HashMap; use std::net::IpAddr; +use std::net::SocketAddr; use std::sync::Arc; use std::sync::LazyLock; @@ -121,7 +122,7 @@ struct CliArgs { #[arg(short, long)] config: Option, #[arg(short, long)] - listen_on: Option, + listen_on: Option, #[arg(short, long)] template_location: Option, #[arg(short,long)] @@ -243,7 +244,7 @@ async fn main() { } } - let listen_on = config.server.listen_on; + let listen_on = cli_args.listen_on.unwrap_or(config.server.listen_on); let ip_header = config.server.ip_header.clone(); // Initialize shared state diff --git a/templates/extra.toml b/templates/extra.toml index b2dd8ed..1d22886 100644 --- a/templates/extra.toml +++ b/templates/extra.toml @@ -21,6 +21,13 @@ display_icon = "/icon_64.png" v4_url="http://v4.localhost:3000/" v6_url="http://v6.localhost:3000/" +# Geolocation Attribution for MaxMind +#geo_attribution_html="The Geolocation and ASN information is provided by the GeoLite2 database created by MaxMind." + +# Geolocation Attribution for DB-IP +#geo_attribution_html="The Geolocation and ASN information is provided by DB-IP." + + [404] # configure the 404 page, this is available for other pages too! # Use the template name as the section name. diff --git a/templates/ip.html b/templates/ip.html index b7c75a0..6e22cbc 100644 --- a/templates/ip.html +++ b/templates/ip.html @@ -34,43 +34,44 @@ {% if r.location %}

Geolocation

-
- {{ helper::place_dl(place=r.location.continent, label="Continent") }} - {{ helper::place_dl(place=r.location.country, label="Country") }} - {% if r.location.country.iso_code | default(value="") != r.location.registered_country.iso_code | default(value="") %} - {{ helper::place_dl(place=r.location.registered_country, label="Registered in") }} - {% endif %} - {% if r.location.country.iso_code | default(value="") != r.location.represented_country.iso_code | default(value="")%} - {{ helper::place_dl(place=r.location.represented_country, label="Represents") }} - {% endif %} - {% if r.location.subdivisions %} - {% for sd in r.location.subdivisions %} - {{ helper::place_dl(place=sd, label="Subdivision", iso_code_prefix=r.location.country.iso_code|default(value="")) }} - {% endfor %} - {% endif %} - {{ helper::place_dl(place=r.location.city, label="City") }} - {% if r.location.postal_code %} -
Postal Code
-
{{r.location.postal_code}}
- {% endif %} - {% if r.location.time_zone %} -
Timezone
-
{{r.location.time_zone}}
- {% endif %} - {% if r.location.accuracy %} -
Accuracy
-
~{{r.location.accuracy}}km
- {% endif %} - {% if r.location.coordinates %} -
Coordinates
-
lat: {{r.location.coordinates.lat}}, lon: {{r.location.coordinates.lon}}
- {% endif %} -
- -

- The GeoIP and ASN information is provided by the GeoLite2 database created by - MaxMind. -

+ {% if extra.geo_attribution_html %} +
+ {{ helper::place_dl(place=r.location.continent, label="Continent") }} + {{ helper::place_dl(place=r.location.country, label="Country") }} + {% if r.location.country.iso_code | default(value="") != r.location.registered_country.iso_code | default(value="") %} + {{ helper::place_dl(place=r.location.registered_country, label="Registered in") }} + {% endif %} + {% if r.location.country.iso_code | default(value="") != r.location.represented_country.iso_code | default(value="")%} + {{ helper::place_dl(place=r.location.represented_country, label="Represents") }} + {% endif %} + {% if r.location.subdivisions %} + {% for sd in r.location.subdivisions %} + {{ helper::place_dl(place=sd, label="Subdivision", iso_code_prefix=r.location.country.iso_code|default(value="")) }} + {% endfor %} + {% endif %} + {{ helper::place_dl(place=r.location.city, label="City") }} + {% if r.location.postal_code %} +
Postal Code
+
{{r.location.postal_code}}
+ {% endif %} + {% if r.location.time_zone %} +
Timezone
+
{{r.location.time_zone}}
+ {% endif %} + {% if r.location.accuracy %} +
Accuracy
+
~{{r.location.accuracy}}km
+ {% endif %} + {% if r.location.coordinates %} +
Coordinates
+
lat: {{r.location.coordinates.lat}}, lon: {{r.location.coordinates.lon}}
+ {% endif %} +
+

{{extra.geo_attribution_html | safe}}

+ {% else %} +

Please configure the geo_attribution_html key in the template extra configuration!

+

The geolocation information will then become visible.

+ {% endif %}
{% endif %} {% block extra_content %}{% endblock %} diff --git a/templates/ip.txt b/templates/ip.txt index bb40bbb..2f3736c 100644 --- a/templates/ip.txt +++ b/templates/ip.txt @@ -59,7 +59,7 @@ lat: {{r.location.coordinates.lat}}, lon: {{r.location.coordinates.lon}} => {{ links::map_link(lat=r.location.coordinates.lat, lon=r.location.coordinates.lon)}} {%- endif %} -The GeoIP and ASN information is provided by the GeoLite2 database created by MaxMind. +{{ extra.geo_attribution_html | default(value="Please configure the geo_attribution_html key in the template extra configuration.") | striptags }} {% endif -%} {%- block extra_content %}{% endblock -%}