]> git.ipfire.org Git - ipfire.org.git/commitdiff
location: Add new location subdomain
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 18 Jul 2018 17:46:08 +0000 (18:46 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 18 Jul 2018 17:46:08 +0000 (18:46 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/templates/geoip/index.html [deleted file]
src/templates/location/lookup.html [new file with mode: 0644]
src/templates/modules/map.html
src/web/__init__.py
src/web/handlers.py
src/web/location.py [new file with mode: 0644]

index 9f4642b5cc36aa608b9a3f6df9106f1f13c15683..05e5dc1b472483f81d1866123e7098f94e96b8dd 100644 (file)
@@ -87,6 +87,7 @@ web_PYTHON = \
        src/web/handlers_mirrors.py \
        src/web/handlers_nopaste.py \
        src/web/handlers_talk.py \
+       src/web/location.py \
        src/web/ui_modules.py
 
 webdir = $(backenddir)/web
@@ -125,7 +126,13 @@ templates_blog_modules_DATA = \
 
 templates_blog_modulesdir = $(templates_blogdir)/modules
 
+templates_location_DATA = \
+       src/templates/location/lookup.html
+
+templates_locationdir = $(templatesdir)/location
+
 templates_modules_DATA = \
+       src/templates/modules/map.html \
        src/templates/modules/menu.html
 
 templates_modulesdir = $(templatesdir)/modules
diff --git a/src/templates/geoip/index.html b/src/templates/geoip/index.html
deleted file mode 100644 (file)
index 72053e5..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-{% extends "../base.html" %}
-
-{% block title %}{{ _("GeoIP for %s") % addr }}{% end block %}
-
-{% block body %}
-<div class="container">
-       <section class="features-content col-12">
-               <h2 class="display-2 text-center">{{ _("GeoIP for %s") % addr }}</h2>
-               
-               {% if peer %}
-                       <div class="row">
-                               <div class="col-lg-4 col-md-4">
-                                       <dl>
-                                               {% if peer.asn %}
-                                                       <dt>{{ _("Autonomous System") }}</dt>
-                                                       <dd>{{ peer.asn }}</dd>
-                                               {% end %}
-       
-                                               <dt>{{ _("Country") }}</dt>
-                                               <dd>
-                                                       {% if peer.country_name %}
-                                                               {{ peer.country_name }} ({{ peer.country }})
-                                                       {% else %}
-                                                               {{ peer.country_name }}
-                                                       {% end %}
-                                               </dd>
-       
-                                               {% if peer.city %}
-                                                       <dt>{{ _("City") }}</dt>
-                                                       <dd>{{ peer.city }}</dd>
-       
-                                                       {% if peer.postal_code %}
-                                                               <dt>{{ _("Postal Code") }}</dt>
-                                                               <dd>{{ peer.postal_code }}</dd>
-                                                       {% end %}
-                                               {% end %}
-                                       </dl>
-       
-                                       {% if mirrors %}
-                                               <h4>{{ _("Preferred Mirrors") }}</h4>
-       
-                                               <ul>
-                                                       {% for mirror in mirrors %}
-                                                               <li>
-                                                                       <a href="https://mirrors.ipfire.org/mirror/{{ mirror.hostname }}">
-                                                                               {{ mirror.hostname }}
-                                                                       </a>
-                                                                       <span class="pull-right">
-                                                                               {{ _("%.0f km") % mirror.distance_to(peer) }}
-                                                                       </span>
-                                                               </li>
-                                                       {% end %}
-                                               </ul>
-                                       {% end %}
-                               </div>
-       
-                               <div class="col-lg-8 col-md-8">
-                                       {% module Map(peer.latitude, peer.longitude) %}
-                               </div>
-                       </div>
-               {% else %}
-                       <div class="alert alert-info">
-                               <p>{{ _("No GeoIP information could be found for the IP address '%s'.") % addr }}</p>
-                       </div>
-               {% end %}
-       </section>
-</div>
-
-{% end block %}
diff --git a/src/templates/location/lookup.html b/src/templates/location/lookup.html
new file mode 100644 (file)
index 0000000..862e95c
--- /dev/null
@@ -0,0 +1,41 @@
+{% extends "../base.html" %}
+
+{% block title %}{{ _("Location of %s") % address }}{% end block %}
+
+{% block content %}
+       <h1 class="text-center mt-5 mb-5">{{ _("Location of %s") % address }}</h1>
+
+       <div class="row justify-content-center">
+               <div class="col-12 col-md-6">
+                       <div class="card">
+                               {% if peer and peer.latitude and peer.longitude %}
+                                       <div class="card-img-top">
+                                               {% module Map(peer.latitude, peer.longitude) %}
+                                       </div>
+                               {% end %}
+
+                               <div class="card-body">
+                                       <dl>
+                                               <dt>{{ _("Country") }}</dt>
+                                               <dd>
+                                                       {% if peer %}
+                                                               {% if peer.country_name %}
+                                                                       {{ peer.country_name }} ({{ peer.country }})
+                                                               {% else %}
+                                                                       {{ peer.country_name }}
+                                                               {% end %}
+                                                       {% else %}
+                                                               <span class="text-muted">{{ _("Unkown") }}</span>
+                                                       {% end %}
+                                               </dd>
+
+                                               {% if peer and peer.asn %}
+                                                       <dt>{{ _("Autonomous System") }}</dt>
+                                                       <dd>{{ peer.asn }}</dd>
+                                               {% end %}
+                                       </dl>
+                               </div>
+                       </div>
+               </div>
+       </div>
+{% end block %}
index e62e23d4871ae2e7e32868bbe6c5e444fbabe333..84f8a98e4dab44c3eabca3e81cb0b98dbcdf0199 100644 (file)
@@ -1,20 +1,3 @@
-<iframe width="100%" height="500" frameborder="0" scrolling="no" marginheight="0" marginwidth="0"
-       src="https://www.openstreetmap.org/export/embed.html?bbox={{ longitude - 4 }},{{ latitude - 4 }},{{ longitude + 4 }},{{ latitude + 4 }}&amp;layer=mapquest&amp;marker={{ latitude }},{{ longitude }}" style="border: 1px solid black">
+<iframe width="100%" height="400" frameborder="0" scrolling="no" marginheight="0" marginwidth="0"
+       src="https://www.openstreetmap.org/export/embed.html?bbox={{ longitude - 4 }},{{ latitude - 4 }},{{ longitude + 4 }},{{ latitude + 4 }}&amp;layer=mapquest&amp;marker={{ latitude }},{{ longitude }}">
 </iframe>
-<p>
-       <a href="https://www.openstreetmap.org/?lat={{ latitude }}&amp;lon={{ longitude }}&amp;zoom=8&amp;layers=M&amp;mlat={{ latitude }}&amp;mlon={{ longitude }}" target="_blank">{{ _("View larger map") }}</a>
-       -
-       &copy; <a href="https://www.openstreetmap.org/" target="_blank">OpenStreetMap</a> contributors, CC-BY-SA
-       <span class="pull-right">
-               {% if latitude >= 0 %}
-                       {{ latitude }} N,
-               {% else %}
-                       {{ -latitude }} S,
-               {% end %}
-               {% if longitude >= 0 %}
-                       {{ longitude }} E
-               {% else %}
-                       {{ -longitude }} W
-               {% end %}
-       </span>
-</p>
index 1c619adfbea7bae991901409d1cf987c3ddce0b6..686bbd21da62bd2d80d244a41e755a977e6dcda5 100644 (file)
@@ -12,6 +12,7 @@ from handlers import *
 from ui_modules import *
 
 from . import blog
+from . import location
 
 BASEDIR = os.path.join(os.path.dirname(__file__), "..")
 
@@ -39,11 +40,15 @@ class Application(tornado.web.Application):
                                "format_month_name" : self.format_month_name,
                        },
                        "ui_modules" : {
+                               # Blog
                                "BlogHistoryNavigation": blog.HistoryNavigationModule,
                                "BlogList"             : blog.ListModule,
                                "BlogPost"             : blog.PostModule,
                                "BlogPosts"            : blog.PostsModule,
 
+                               # Location
+                               "Map"                  : MapModule,
+
                                # Old modules
                                "Advertisement"        : AdvertisementModule,
                                "DonationBox"          : DonationBoxModule,
@@ -51,7 +56,6 @@ class Application(tornado.web.Application):
                                "DonationInputBox"     : DonationInputBoxModule,
                                "DownloadButton"       : DownloadButtonModule,
                                "LanguageName"         : LanguageNameModule,
-                               "Map"                  : MapModule,
                                "Menu"                 : MenuModule,
                                "MirrorItem"           : MirrorItemModule,
                                "MirrorsTable"         : MirrorsTableModule,
@@ -226,9 +230,15 @@ class Application(tornado.web.Application):
                        (r"/view/(.*)", NopasteViewHandler),
                ] + authentication_handlers)
 
+               # location.ipfire.org
+               self.add_handlers(r"location(\.dev)?\.ipfire\.org", [
+                       (r"/", location.IndexHandler),
+                       (r"/lookup/(.+)", location.LookupHandler),
+               ])
+
                # geoip.ipfire.org
                self.add_handlers(r"geoip(\.dev)?\.ipfire\.org", [
-                       (r"/", GeoIPHandler),
+                       (r"/", tornado.web.RedirectHandler, { "url" : "https://location.ipfire.org/" }),
                ])
 
                # talk.ipfire.org
index b77335bec0be082d3c24decd53b9a72f173b2531..83ea9e210d612441a169ce224eccff2e42db838c 100644 (file)
@@ -54,26 +54,6 @@ class IndexHandler(BaseHandler):
                        latest_release=latest_release,
                        fireinfo_country=self.fireinfo.get_random_country_penetration())
 
-class GeoIPHandler(BaseHandler):
-       def get_address(self):
-               addr = self.get_argument("addr", None)
-
-               if not addr:
-                       addr = self.get_remote_ip()
-
-               return addr
-
-       def get(self):
-               addr = self.get_address()
-
-               peer = self.geoip.get_all(addr)
-               if peer:
-                       peer["country_name"] = self.geoip.get_country_name(peer.country)
-
-               mirrors = self.mirrors.get_for_location(peer)
-
-               self.render("geoip/index.html", addr=addr, peer=peer, mirrors=mirrors)
-
 
 class DonateHandler(BaseHandler):
        def get(self):
diff --git a/src/web/location.py b/src/web/location.py
new file mode 100644 (file)
index 0000000..e49ba23
--- /dev/null
@@ -0,0 +1,19 @@
+
+#!/usr/bin/python
+
+import tornado.web
+
+import handlers_base as base
+
+class IndexHandler(base.BaseHandler):
+       def get(self):
+               self.redirect("/lookup/%s" % self.get_remote_ip())
+
+
+class LookupHandler(base.BaseHandler):
+       def get(self, address):
+               peer = self.geoip.get_all(address)
+               if peer:
+                       peer["country_name"] = self.geoip.get_country_name(peer.country)
+
+               self.render("location/lookup.html", address=address, peer=peer)