From f5b01fc2748867782b772888dc73b397bd109faf Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Wed, 18 Jul 2018 18:46:08 +0100 Subject: [PATCH] location: Add new location subdomain Signed-off-by: Michael Tremer --- Makefile.am | 7 +++ src/templates/geoip/index.html | 69 ------------------------------ src/templates/location/lookup.html | 41 ++++++++++++++++++ src/templates/modules/map.html | 21 +-------- src/web/__init__.py | 14 +++++- src/web/handlers.py | 20 --------- src/web/location.py | 19 ++++++++ 7 files changed, 81 insertions(+), 110 deletions(-) delete mode 100644 src/templates/geoip/index.html create mode 100644 src/templates/location/lookup.html create mode 100644 src/web/location.py diff --git a/Makefile.am b/Makefile.am index 9f4642b5..05e5dc1b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 index 72053e5c..00000000 --- a/src/templates/geoip/index.html +++ /dev/null @@ -1,69 +0,0 @@ -{% extends "../base.html" %} - -{% block title %}{{ _("GeoIP for %s") % addr }}{% end block %} - -{% block body %} -
-
-

{{ _("GeoIP for %s") % addr }}

- - {% if peer %} -
-
-
- {% if peer.asn %} -
{{ _("Autonomous System") }}
-
{{ peer.asn }}
- {% end %} - -
{{ _("Country") }}
-
- {% if peer.country_name %} - {{ peer.country_name }} ({{ peer.country }}) - {% else %} - {{ peer.country_name }} - {% end %} -
- - {% if peer.city %} -
{{ _("City") }}
-
{{ peer.city }}
- - {% if peer.postal_code %} -
{{ _("Postal Code") }}
-
{{ peer.postal_code }}
- {% end %} - {% end %} -
- - {% if mirrors %} -

{{ _("Preferred Mirrors") }}

- - - {% end %} -
- -
- {% module Map(peer.latitude, peer.longitude) %} -
-
- {% else %} -
-

{{ _("No GeoIP information could be found for the IP address '%s'.") % addr }}

-
- {% end %} -
-
- -{% end block %} diff --git a/src/templates/location/lookup.html b/src/templates/location/lookup.html new file mode 100644 index 00000000..862e95cf --- /dev/null +++ b/src/templates/location/lookup.html @@ -0,0 +1,41 @@ +{% extends "../base.html" %} + +{% block title %}{{ _("Location of %s") % address }}{% end block %} + +{% block content %} +

{{ _("Location of %s") % address }}

+ +
+
+
+ {% if peer and peer.latitude and peer.longitude %} +
+ {% module Map(peer.latitude, peer.longitude) %} +
+ {% end %} + +
+
+
{{ _("Country") }}
+
+ {% if peer %} + {% if peer.country_name %} + {{ peer.country_name }} ({{ peer.country }}) + {% else %} + {{ peer.country_name }} + {% end %} + {% else %} + {{ _("Unkown") }} + {% end %} +
+ + {% if peer and peer.asn %} +
{{ _("Autonomous System") }}
+
{{ peer.asn }}
+ {% end %} +
+
+
+
+
+{% end block %} diff --git a/src/templates/modules/map.html b/src/templates/modules/map.html index e62e23d4..84f8a98e 100644 --- a/src/templates/modules/map.html +++ b/src/templates/modules/map.html @@ -1,20 +1,3 @@ - -

- {{ _("View larger map") }} - - - © OpenStreetMap contributors, CC-BY-SA - - {% if latitude >= 0 %} - {{ latitude }} N, - {% else %} - {{ -latitude }} S, - {% end %} - {% if longitude >= 0 %} - {{ longitude }} E - {% else %} - {{ -longitude }} W - {% end %} - -

diff --git a/src/web/__init__.py b/src/web/__init__.py index 1c619adf..686bbd21 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -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 diff --git a/src/web/handlers.py b/src/web/handlers.py index b77335be..83ea9e21 100644 --- a/src/web/handlers.py +++ b/src/web/handlers.py @@ -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 index 00000000..e49ba233 --- /dev/null +++ b/src/web/location.py @@ -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) -- 2.39.2