From: Michael Tremer Date: Mon, 8 Jun 2020 16:27:39 +0000 (+0000) Subject: location: Redesign index page X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7b05edde25e708236bdb30b0ce385e2208eb0e28;p=ipfire.org.git location: Redesign index page Signed-off-by: Michael Tremer --- diff --git a/src/backend/base.py b/src/backend/base.py index bc8041af..c1d4cbb1 100644 --- a/src/backend/base.py +++ b/src/backend/base.py @@ -2,6 +2,7 @@ import configparser import io +import location import ssl import tempfile import tornado.httpclient @@ -172,6 +173,10 @@ class Backend(object): def messages(self): return messages.Messages(self) + @lazy_property + def location(self): + return location.Database("/var/lib/location/database.db") + @lazy_property def ratelimiter(self): return ratelimit.RateLimiter(self) diff --git a/src/backend/util.py b/src/backend/util.py index 18bcbe3d..f7182c89 100644 --- a/src/backend/util.py +++ b/src/backend/util.py @@ -39,9 +39,6 @@ BLACKLISTS = ( "zen.spamhaus.org", ) -# Open location database -db = location.Database("/var/lib/location/database.db") - class Address(Object): def init(self, address): self.address = ipaddress.ip_address(address) @@ -58,7 +55,7 @@ class Address(Object): @lazy_property def network(self): - return db.lookup("%s" % self.address) + return self.backend.location.lookup("%s" % self.address) @property def country_code(self): @@ -70,6 +67,11 @@ class Address(Object): if self.network: return self.network.asn + @lazy_property + def autonomous_system(self): + if self.asn: + return self.backend.location.get_as(self.asn) + # Blacklist def _make_blacklist_rr(self, blacklist): diff --git a/src/templates/location/index.html b/src/templates/location/index.html index 97e8399e..511393b9 100644 --- a/src/templates/location/index.html +++ b/src/templates/location/index.html @@ -9,27 +9,25 @@ {% block container %}
-
-
- - -

{{ address }}

-
- -
-

{{ _("Hey you!") }}

- -
{{ _("You are visiting us from") }}
- -
-
{{ _("Country") }}
-
- {{ format_country_name(address.country_code) if address.country_code else _("N/A") }} -
- -
{{ _("Network") }}
-
{{ address.asn or _("Unknown") }}
-
+
+
+

+ {{ _("Hey, %s!" % address) }} +

+ + {% if address.country_code %} +
+

+ +

+ {{ _("You are visiting from %s") % format_country_name(address.country_code) }} +

+
+ {% end %} + + + {{ _("Show Me More") }} +
diff --git a/src/templates/location/lookup.html b/src/templates/location/lookup.html index 3aeb3ca7..63cb3c83 100644 --- a/src/templates/location/lookup.html +++ b/src/templates/location/lookup.html @@ -13,10 +13,8 @@ {% end %} - {% if address.asn %} -
{{ _("Autonomous System") }}
-
{{ format_asn(address.asn) }}
- {% end %} +
{{ _("Autonomous System") }}
+
{{ address.autonomous_system or _("N/A") }}
diff --git a/src/web/location.py b/src/web/location.py index 3ba5fcf1..06d26b40 100644 --- a/src/web/location.py +++ b/src/web/location.py @@ -6,6 +6,7 @@ import tornado.web from .. import util +from . import auth from . import base class IndexHandler(auth.CacheMixin, base.BaseHandler):