]> git.ipfire.org Git - ipfire.org.git/commitdiff
location: Redesign index page
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 8 Jun 2020 16:27:39 +0000 (16:27 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 8 Jun 2020 16:27:39 +0000 (16:27 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/backend/base.py
src/backend/util.py
src/templates/location/index.html
src/templates/location/lookup.html
src/web/location.py

index bc8041af91c8ca095242523f4a273506418ee9d1..c1d4cbb174d4b64300f2eea45250eda81b4cb5bf 100644 (file)
@@ -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)
index 18bcbe3d9240a9463badfeace991c31d752692bd..f7182c896f0378a6d4d0d14eadf24c4377400c75 100644 (file)
@@ -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):
index 97e8399e3dad7a34bc4415639ae8b374aecbd7fe..511393b96d9a04385463c749c9f5a58588cf67be 100644 (file)
@@ -9,27 +9,25 @@
 {% block container %}
        <header class="cover">
                <div class="container d-flex h-100 align-items-center">
-                       <div class="row flex-fill">
-                               <div class="col-12 col-md-6 my-5 text-center">
-                                       <i class="fas fa-globe-europe fa-10x py-5"></i>
-
-                                       <h3>{{ address }}</h3>
-                               </div>
-
-                               <div class="col-12 col-md-6 align-self-center px-3">
-                                       <h1 class="display-1">{{ _("Hey you!") }}</h1>
-
-                                       <h6>{{ _("You are visiting us from") }}</h6>
-
-                                       <dl class="row">
-                                               <dt class="col-sm-3">{{ _("Country") }}</dt>
-                                               <dd class="col-sm-9">
-                                                       {{ format_country_name(address.country_code) if address.country_code else _("N/A") }}
-                                               </dd>
-
-                                               <dt class="col-sm-3">{{ _("Network") }}</dt>
-                                               <dd class="col-sm-9">{{ address.asn or _("Unknown") }}</dd>
-                                       </dl>
+                       <div class="row flex-fill justify-content-center">
+                               <div class="col-12 col-lg-6 text-center">
+                                       <h1 class="mb-5">
+                                               {{ _("Hey, %s!" % address) }}
+                                       </h1>
+
+                                       {% if address.country_code %}
+                                               <div class="my-5">
+                                                       <h1 class="display-4 flag-icon flag-icon-{{ address.country_code.lower() }}"></h1>
+
+                                                       <p class="lead">
+                                                               {{ _("You are visiting from %s") % format_country_name(address.country_code) }}
+                                                       </p>
+                                               </div>
+                                       {% end %}
+
+                                       <a class="btn btn-light btn-block" href="/lookup/{{ address }}">
+                                               {{ _("Show Me More") }}
+                                       </a>
                                </div>
                        </div>
                </div>
index 3aeb3ca743caaffe0cea13a70bc9c666514f0f21..63cb3c83f7c2e7cba0580de072344cab09f61cd2 100644 (file)
                                        </dd>
                                {% end %}
 
-                               {% if address.asn %}
-                                       <dt>{{ _("Autonomous System") }}</dt>
-                                       <dd>{{ format_asn(address.asn) }}</dd>
-                               {% end %}
+                               <dt>{{ _("Autonomous System") }}</dt>
+                               <dd>{{ address.autonomous_system or _("N/A") }}</dd>
                        </dl>
 
                        <a class="btn btn-light btn-block" href="/lookup/{{ address }}/blacklists">
index 3ba5fcf176ce222ca742a1cb9e076a7da685c1c4..06d26b40683a8d64da135b763306684d40b9c2ac 100644 (file)
@@ -6,6 +6,7 @@ import tornado.web
 
 from .. import util
 
+from . import auth
 from . import base
 
 class IndexHandler(auth.CacheMixin, base.BaseHandler):