src/backend/database.py \
src/backend/decorators.py \
src/backend/fireinfo.py \
- src/backend/geoip.py \
src/backend/hwdata.py \
src/backend/iuse.py \
src/backend/memcached.py \
src/backend/nopaste.py \
src/backend/ratelimit.py \
src/backend/releases.py \
+ src/backend/resolver.py \
src/backend/settings.py \
src/backend/talk.py \
src/backend/tweets.py \
from . import blog
from . import campaigns
from . import database
-from . import geoip
from . import fireinfo
from . import iuse
from . import memcached
from . import nopaste
from . import ratelimit
from . import releases
+from . import resolver
from . import settings
from . import talk
from . import tweets
+from . import util
from . import wiki
from . import zeiterfassung
from .decorators import *
# Initialize backend modules.
self.accounts = accounts.Accounts(self)
- self.geoip = geoip.GeoIP(self)
self.fireinfo = fireinfo.Fireinfo(self)
self.iuse = iuse.IUse(self)
self.mirrors = mirrors.Mirrors(self)
"scan-files" : self.releases.scan_files,
"send-message" : self.messages.send_cli,
"send-all-messages" : self.messages.queue.send_all,
- "test-blacklist" : self.geoip.test_blacklist,
"test-ldap" : self.accounts.test_ldap,
"tweet" : self.tweets.tweet,
"update-blog-feeds" : self.blog.update_feeds,
def ratelimiter(self):
return ratelimit.RateLimiter(self)
+ @lazy_property
+ def resolver(self):
+ return resolver.Resolver(tries=2, timeout=2, domains=[])
+
@lazy_property
def tweets(self):
return tweets.Tweets(self)
import logging
import re
+from . import countries
from . import database
from . import hwdata
from . import util
"11" : N_("Signal processing controller"),
"ff" : N_("Unassigned class"),
},
-
+
"usb" : {
"00" : N_("Unclassified"),
"01" : N_("Multimedia"),
def time_updated(self):
return self.data.time_updated
- def updated(self, profile_parser=None, location=None, when=None):
+ def updated(self, profile_parser=None, country_code=None, when=None):
valid = self.settings.get_int("fireinfo_profile_days_valid", 14)
self.db.execute("UPDATE fireinfo_profiles \
profile_parser.processor_bogomips,
)
- if location:
- self.set_location(location)
+ if country_code:
+ self.set_country_code(country_code)
self.log_profile_update()
# Location
- def get_location(self):
+ @property
+ def location(self):
if not hasattr(self, "_location"):
res = self.db.get("SELECT location FROM fireinfo_profiles_locations \
WHERE profile_id = %s", self.id)
return self._location
- def set_location(self, location):
- if self.location == location:
+ def set_country_code(self, country_code):
+ if self.location == country_code:
return
self.db.execute("DELETE FROM fireinfo_profiles_locations \
WHERE profile_id = %s", self.id)
self.db.execute("INSERT INTO fireinfo_profiles_locations(profile_id, location) \
- VALUES(%s, %s)", self.id, location)
+ VALUES(%s, %s)", self.id, country_code)
- self._location = location
-
- location = property(get_location, set_location)
+ self._location = country_code
@property
def location_string(self):
- return self.geoip.get_country_name(self.location)
+ return countries.get_name(self.location)
# Devices
self._kernel_id = None
return self._kernel_id
-
+
def set_kernel_id(self, kernel_id):
if self.kernel_id == kernel_id:
return
else:
self.db.execute("COMMIT")
- def _handle_profile(self, public_id, profile_blob, location=None, when=None):
+ def _handle_profile(self, public_id, profile_blob, country_code=None, when=None):
private_id = profile_blob.get("private_id", None)
assert private_id
if profile:
# Check if the profile has changed. If so, update the data.
if profile_parser.equals(profile):
- profile.updated(profile_parser, location=location, when=when)
+ profile.updated(profile_parser, country_code=country_code, when=when)
return
# If it does not match, we assume that it is expired and
profile = self.fireinfo.create_profile(public_id, private_id, when=when)
profile.parse(profile_parser)
- if location:
- profile.set_location(location)
+ if country_code:
+ profile.set_country_code(country_code)
return profile
+++ /dev/null
-#!/usr/bin/python
-
-import ipaddress
-import logging
-import pycares
-import re
-import socket
-import tornado.gen
-import tornado.platform.caresresolver
-
-from . import countries
-
-from .decorators import *
-from .misc import Object
-
-# These lists are used to block access to the webapp
-BLOCKLISTS = (
- "sbl.spamhaus.org",
- "xbl.spamhaus.org",
-)
-
-BLACKLISTS = (
- "b.barracudacentral.org",
- "bl.spamcop.net",
- "bl.blocklist.de",
- "cbl.abuseat.org",
- "dnsbl-1.uceprotect.net",
- "dnsbl-2.uceprotect.net",
- "dnsbl-3.uceprotect.net",
- "dnsbl.abuse.ch",
- "ix.dnsbl.manitu.net",
- "pbl.spamhaus.org",
- "sbl.spamhaus.org",
- "xbl.spamhaus.org",
- "zen.spamhaus.org",
-)
-
-class Resolver(tornado.platform.caresresolver.CaresResolver):
- def initialize(self, **kwargs):
- super().initialize()
-
- # Overwrite Channel
- self.channel = pycares.Channel(sock_state_cb=self._sock_state_cb, **kwargs)
-
- async def query(self, name, type=pycares.QUERY_TYPE_A):
- # Create a new Future
- fut = tornado.gen.Future()
-
- # Perform the query
- self.channel.query(name, type, lambda result, error: fut.set_result((result, error)))
-
- # Wait for the response
- result, error = await fut
-
- # Handle any errors
- if error:
- # NXDOMAIN
- if error == pycares.errno.ARES_ENOTFOUND:
- return
-
- # Ignore responses with no data
- elif error == pycares.errno.ARES_ENODATA:
- return
-
- raise IOError(
- "C-Ares returned error %s: %s while resolving %s"
- % (error, pycares.errno.strerror(error), name)
- )
-
- # Return the result
- return result
-
-
-class GeoIP(Object):
- @lazy_property
- def resolver(self):
- return Resolver(tries=2, timeout=2, domains=[])
-
- def lookup(self, address):
- return Address(self.backend, address)
-
- def guess_address_family(self, addr):
- if ":" in addr:
- return 6
-
- return 4
-
- def get_country(self, addr):
- ret = self.get_all(addr)
-
- if ret:
- return ret.country
-
- def get_location(self, addr):
- query = "SELECT * FROM geoip \
- WHERE %s BETWEEN start_ip AND end_ip LIMIT 1"
-
- return self.db.get(query, addr)
-
- def get_asn(self, addr):
- query = "SELECT asn FROM geoip_asn \
- WHERE %s BETWEEN start_ip AND end_ip LIMIT 1"
-
- ret = self.db.get(query, addr)
-
- if ret:
- return ret.asn
-
- def get_all(self, addr):
- location = self.get_location(addr)
-
- if location:
- location["asn"] = self.get_asn(addr)
-
- return location
-
- _countries = {
- "A1" : "Anonymous Proxy",
- "A2" : "Satellite Provider",
- "AP" : "Asia/Pacific Region",
- "EU" : "Europe",
- }
-
- def get_country_name(self, code):
- return countries.get_name(code)
-
- async def test_blacklist(self, address):
- address = self.lookup(address)
-
- # Determne blacklist status
- status = await address.is_blacklisted()
-
- print("Blacklist status for %s: %s" % (address, status))
-
-
-class Address(Object):
- def init(self, address):
- self.address = ipaddress.ip_address(address)
-
- def __str__(self):
- return "%s" % self.address
-
- @property
- def family(self):
- if isinstance(self.address, ipaddress.IPv6Address):
- return socket.AF_INET6
- elif isinstance(self.address, ipaddress.IPv4Address):
- return socket.AF_INET
-
- # Blacklist
-
- def _make_blacklist_rr(self, blacklist):
- if self.family == socket.AF_INET6:
- octets = list(self.address.exploded.replace(":", ""))
- elif self.family == socket.AF_INET:
- octets = str(self.address).split(".")
- else:
- raise NotImplementedError("Unknown IP protocol")
-
- # Reverse the list
- octets.reverse()
-
- # Append suffix
- octets.append(blacklist)
-
- return ".".join(octets)
-
- async def _resolve_blacklist(self, blacklist):
- return_code = None
-
- # Get resource record name
- rr = self._make_blacklist_rr(blacklist)
-
- # Get query type from IP protocol version
- if self.family == socket.AF_INET6:
- type = pycares.QUERY_TYPE_AAAA
- elif self.family == socket.AF_INET:
- type = pycares.QUERY_TYPE_A
- else:
- raise NotImplementedError("Unknown IP protocol")
-
- # Run query
- try:
- res = await self.backend.geoip.resolver.query(rr, type=type)
- except IOError as e:
- logging.warning(e)
-
- return return_code, "%s" % e
-
- # Not found
- if not res:
- logging.debug("%s is not blacklisted on %s" % (self, blacklist))
- return return_code, None
-
- # Extract return code from DNS response
- for row in res:
- return_code = row.host
- break
-
- # If the IP address is on a blacklist, we will try to fetch the TXT record
- reason = await self.backend.geoip.resolver.query(rr, type=pycares.QUERY_TYPE_TXT)
-
- # Log result
- logging.debug("%s is blacklisted on %s: %s" % (self, blacklist, reason or "N/A"))
-
- # Take the first reason
- if reason:
- for i in reason:
- return return_code, i.text
-
- # Blocked, but no reason
- return return_code, None
-
- async def get_blacklists(self):
- blacklists = { bl : self._resolve_blacklist(bl) for bl in BLACKLISTS }
-
- return blacklists
-
- async def is_blacklisted(self):
- logging.debug("Checking if %s is blacklisted..." % self)
-
- # Perform checks
- blacklists = { bl : self._resolve_blacklist(bl) for bl in BLOCKLISTS }
-
- # If we are blacklisted on one list, this one is screwed
- for bl in blacklists:
- code, message = await blacklists[bl]
-
- logging.debug("Response from %s is: %s (%s)" % (bl, code, message))
-
- # Exclude matches on SBLCSS
- if bl == "sbl.spamhaus.org" and code == "127.0.0.3":
- continue
-
- # Consider the host blocked for any non-zero return code
- if code:
- return True
import urllib.parse
from . import countries
+from . import util
from .misc import Object
from .decorators import *
if isinstance(other, self.__class__):
return self.hostname < other.hostname
+ def __hash__(self):
+ return self.id
+
@lazy_property
def url(self):
url = "%s://%s" % ("https" if self.supports_https else "http", self.hostname)
def hostname(self):
return self.data.hostname
+ @lazy_property
+ def address(self):
+ """
+ Returns the stored address
+ """
+ if self.data.address:
+ return util.Address(self.backend, self.data.address)
+
@property
def path(self):
return self.data.path
def supports_https(self):
return self.data.supports_https
- @property
- def address(self):
- for addr in self.addresses4:
- return addr
-
- for addr in self.addresses6:
- return addr
-
@property
def owner(self):
return self.data.owner
- @lazy_property
- def location(self):
- return self.geoip.get_location(self.address)
-
- @property
- def latitude(self):
- if self.location:
- return self.location.latitude
-
@property
- def longitude(self):
- if self.location:
- return self.location.longitude
-
- @lazy_property
def country(self):
return iso3166.countries.get(self.country_code)
@property
def country_code(self):
- return self.data.country_code
+ if self.data.country_code:
+ return self.data.country_code
- @property
- def country_name(self):
- return self.geoip.get_country_name(self.country_code)
+ if self.address:
+ return self.address.country_code
@property
def zone(self):
return countries.get_zone(self.country_name)
- @lazy_property
+ @property
def asn(self):
- return self.geoip.get_asn(self.address)
+ if self.address:
+ return self.address.asn
@property
def filelist(self):
logging.debug("Running check for mirror %s" % self.hostname)
self.db.execute("UPDATE mirrors SET address = %s WHERE id = %s",
- self.address, self.id)
+ await self.resolve(), self.id)
success = await self.check_timestamp()
if success:
def mirrorlist(self):
return self.data.get("mirrorlist", False)
- @lazy_property
- def addresses(self):
- addrinfo = socket.getaddrinfo(self.hostname, 0, socket.AF_UNSPEC, socket.SOCK_STREAM)
-
- ret = []
- for family, socktype, proto, canonname, address in addrinfo:
- if family == socket.AF_INET:
- address, port = address
- elif family == socket.AF_INET6:
- address, port, flowid, scopeid = address
- ret.append((family, address))
+ async def resolve(self):
+ """
+ Returns a single IP address of this mirror
+ """
+ addresses = await self.backend.resolver.resolve(self.hostname, 0)
- return ret
+ # Return the first address
+ for family, address in addresses:
+ host, port = address
- @property
- def addresses6(self):
- return [address for family, address in self.addresses if family == socket.AF_INET6]
-
- @property
- def addresses4(self):
- return [address for family, address in self.addresses if family == socket.AF_INET]
+ return host
def fireinfo(self):
return self.backend.fireinfo
- @property
- def geoip(self):
- return self.backend.geoip
-
@property
def iuse(self):
return self.backend.iuse
def memcache(self):
return self.backend.memcache
- @property
- def planet(self):
- return self.backend.planet
-
@property
def settings(self):
return self.backend.settings
--- /dev/null
+#!/usr/bin/python
+
+import ipaddress
+import pycares
+import tornado.gen
+import tornado.platform.caresresolver
+
+class Resolver(tornado.platform.caresresolver.CaresResolver):
+ def initialize(self, **kwargs):
+ super().initialize()
+
+ # Overwrite Channel
+ self.channel = pycares.Channel(sock_state_cb=self._sock_state_cb, **kwargs)
+
+ async def query(self, name, type=pycares.QUERY_TYPE_A):
+ # Create a new Future
+ fut = tornado.gen.Future()
+
+ # Perform the query
+ self.channel.query(name, type, lambda result, error: fut.set_result((result, error)))
+
+ # Wait for the response
+ result, error = await fut
+
+ # Handle any errors
+ if error:
+ # NXDOMAIN
+ if error == pycares.errno.ARES_ENOTFOUND:
+ return
+
+ # Ignore responses with no data
+ elif error == pycares.errno.ARES_ENODATA:
+ return
+
+ raise IOError(
+ "C-Ares returned error %s: %s while resolving %s"
+ % (error, pycares.errno.strerror(error), name)
+ )
+
+ # Return the result
+ return result
import PIL.ImageFilter
import PIL.ImageOps
import io
+import ipaddress
+import location
import logging
+import pycares
import random
import re
+import socket
import string
import unicodedata
+from .decorators import *
+from .misc import Object
+
+# These lists are used to block access to the webapp
+BLOCKLISTS = (
+ "sbl.spamhaus.org",
+ "xbl.spamhaus.org",
+)
+
+BLACKLISTS = (
+ "b.barracudacentral.org",
+ "bl.spamcop.net",
+ "bl.blocklist.de",
+ "cbl.abuseat.org",
+ "dnsbl-1.uceprotect.net",
+ "dnsbl-2.uceprotect.net",
+ "dnsbl-3.uceprotect.net",
+ "dnsbl.abuse.ch",
+ "ix.dnsbl.manitu.net",
+ "pbl.spamhaus.org",
+ "sbl.spamhaus.org",
+ "xbl.spamhaus.org",
+ "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)
+
+ def __str__(self):
+ return "%s" % self.address
+
+ @property
+ def family(self):
+ if isinstance(self.address, ipaddress.IPv6Address):
+ return socket.AF_INET6
+ elif isinstance(self.address, ipaddress.IPv4Address):
+ return socket.AF_INET
+
+ @lazy_property
+ def network(self):
+ return db.lookup("%s" % self.address)
+
+ @property
+ def country_code(self):
+ if self.network:
+ return self.network.country_code
+
+ @lazy_property
+ def asn(self):
+ if self.network:
+ return self.network.asn
+
+ # Blacklist
+
+ def _make_blacklist_rr(self, blacklist):
+ if self.family == socket.AF_INET6:
+ octets = list(self.address.exploded.replace(":", ""))
+ elif self.family == socket.AF_INET:
+ octets = str(self.address).split(".")
+ else:
+ raise NotImplementedError("Unknown IP protocol")
+
+ # Reverse the list
+ octets.reverse()
+
+ # Append suffix
+ octets.append(blacklist)
+
+ return ".".join(octets)
+
+ async def _resolve_blacklist(self, blacklist):
+ return_code = None
+
+ # Get resource record name
+ rr = self._make_blacklist_rr(blacklist)
+
+ # Get query type from IP protocol version
+ if self.family == socket.AF_INET6:
+ type = pycares.QUERY_TYPE_AAAA
+ elif self.family == socket.AF_INET:
+ type = pycares.QUERY_TYPE_A
+ else:
+ raise NotImplementedError("Unknown IP protocol")
+
+ # Run query
+ try:
+ res = await self.backend.resolver.query(rr, type=type)
+ except IOError as e:
+ logging.warning(e)
+
+ return return_code, "%s" % e
+
+ # Not found
+ if not res:
+ logging.debug("%s is not blacklisted on %s" % (self, blacklist))
+ return return_code, None
+
+ # Extract return code from DNS response
+ for row in res:
+ return_code = row.host
+ break
+
+ # If the IP address is on a blacklist, we will try to fetch the TXT record
+ reason = await self.backend.resolver.query(rr, type=pycares.QUERY_TYPE_TXT)
+
+ # Log result
+ logging.debug("%s is blacklisted on %s: %s" % (self, blacklist, reason or "N/A"))
+
+ # Take the first reason
+ if reason:
+ for i in reason:
+ return return_code, i.text
+
+ # Blocked, but no reason
+ return return_code, None
+
+ async def get_blacklists(self):
+ blacklists = { bl : await self._resolve_blacklist(bl) for bl in BLACKLISTS }
+
+ return blacklists
+
+ async def is_blacklisted(self):
+ logging.debug("Checking if %s is blacklisted..." % self)
+
+ # Perform checks
+ blacklists = { bl : self._resolve_blacklist(bl) for bl in BLOCKLISTS }
+
+ # If we are blacklisted on one list, this one is screwed
+ for bl in blacklists:
+ code, message = await blacklists[bl]
+
+ logging.debug("Response from %s is: %s (%s)" % (bl, code, message))
+
+ # Exclude matches on SBLCSS
+ if bl == "sbl.spamhaus.org" and code == "127.0.0.3":
+ continue
+
+ # Consider the host blocked for any non-zero return code
+ if code:
+ return True
+
+def format_asn(asn):
+ network = db.get_as(asn)
+
+ if network:
+ return "%s" % network
+
+ return "AS%s" % asn
+
def format_size(s, max_unit=None):
units = ("B", "kB", "MB", "GB", "TB")
<div class="col-12 col-md-6 my-5 text-center">
<i class="fas fa-globe-europe fa-10x py-5"></i>
- <h3>2001:678:b28::</h3>
+ <h3>{{Â address }}</h3>
</div>
<div class="col-12 col-md-6 align-self-center px-3">
<dl class="row">
<dt class="col-sm-3">{{ _("Country") }}</dt>
- <dd class="col-sm-9">Germany</dd>
+ <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">AS204867 - Lightning Wire Labs GmbH</dd>
+ <dd class="col-sm-9">{{Â address.asn or _("Unknown") }}</dd>
</dl>
</div>
</div>
{% end %}
<div class="card mb-4">
- {% 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 address.country_code %}
+ <dt>{{ _("Country") }}</dt>
+ <dd>
+ {{ format_country_name(address.country_code) }}
+ </dd>
+ {% end %}
- {% if peer and peer.asn %}
+ {% if address.asn %}
<dt>{{ _("Autonomous System") }}</dt>
- <dd>{{ peer.asn }}</dd>
+ <dd>{{ format_asn(address.asn) }}</dd>
{% end %}
</dl>
<div class="row justify-content-center">
<div class="col-12 col-md-6">
<div class="card mb-4">
- {% if mirror.latitude and mirror.longitude %}
- <div class="card-img-top">
- {% module Map(mirror.latitude, mirror.longitude) %}
- </div>
- {% end %}
+ {# <div class="card-img-top">
+ {% module Map() %}
+ </div> #}
<div class="card-body">
<dl class="mb-0">
{% if mirror.asn %}
<dt>{{ _("Autonomous System") }}</dt>
- <dd>{{ mirror.asn }}</dd>
+ <dd>{{ format_asn(mirror.asn) }}</dd>
{% end %}
<dt>{{ _("Country") }}</dt>
- <dd>{{ mirror.country_name }}</dd>
+ <dd>{{ mirror.country.name }}</dd>
</dl>
</div>
import ipfire
import ipfire.countries
+from .. import util
from .handlers import *
# UI Methods
"ui_methods" : {
+ "format_asn" : self.format_asn,
"format_country_name" : self.format_country_name,
"format_language_name" : self.format_language_name,
"format_month_name" : self.format_month_name,
])
# blog.ipfire.org
- self.add_handlers(r"blog(\.dev)?\.ipfire\.org", [
+ self.add_handlers(r"blog\.ipfire\.org", [
(r"/", blog.IndexHandler),
(r"/authors/(\w+)", blog.AuthorHandler),
(r"/compose", blog.ComposeHandler),
] + authentication_handlers)
# downloads.ipfire.org
- self.add_handlers(r"downloads?(\.dev)?\.ipfire\.org", [
+ self.add_handlers(r"downloads?\.ipfire\.org", [
(r"/", tornado.web.RedirectHandler, { "url" : "https://www.ipfire.org/" }),
(r"/release/(.*)", download.ReleaseRedirectHandler),
(r"/(.*)", download.FileHandler),
])
# mirrors.ipfire.org
- self.add_handlers(r"mirrors(\.dev)?\.ipfire\.org", [
+ self.add_handlers(r"^mirrors\.ipfire\.org", [
(r"/", mirrors.IndexHandler),
(r"/mirrors/(.*)", mirrors.MirrorHandler),
])
# planet.ipfire.org
- self.add_handlers(r"planet(\.dev)?\.ipfire\.org", [
+ self.add_handlers(r"planet\.ipfire\.org", [
(r"/", tornado.web.RedirectHandler, { "url" : "https://blog.ipfire.org/" }),
(r"/post/([A-Za-z0-9_-]+)", handlers.PlanetPostHandler),
(r"/user/([a-z0-9_-]+)", handlers.PlanetUserHandler),
])
# fireinfo.ipfire.org
- self.add_handlers(r"fireinfo(\.dev)?\.ipfire\.org", [
+ self.add_handlers(r"fireinfo\.ipfire\.org", [
(r"/", fireinfo.IndexHandler),
# Admin
] + authentication_handlers)
# i-use.ipfire.org
- self.add_handlers(r"i-use(\.dev)?\.ipfire\.org", [
+ self.add_handlers(r"i-use\.ipfire\.org", [
(r"/", tornado.web.RedirectHandler, { "url" : "https://www.ipfire.org/" }),
(r"/profile/([a-f0-9]{40})/([0-9]+).png", iuse.ImageHandler),
])
])
# nopaste.ipfire.org
- self.add_handlers(r"nopaste(\.dev)?\.ipfire\.org", [
+ self.add_handlers(r"nopaste\.ipfire\.org", [
(r"/", nopaste.CreateHandler),
(r"/raw/(.*)", nopaste.RawHandler),
(r"/view/(.*)", nopaste.ViewHandler),
] + authentication_handlers)
# location.ipfire.org
- self.add_handlers(r"location(\.dev)?\.ipfire\.org", [
+ self.add_handlers(r"location\.ipfire\.org", [
(r"/", location.IndexHandler),
(r"/how\-to\-use", StaticHandler, { "template" : "../location/how-to-use.html" }),
(r"/lookup/(.+)/blacklists", location.BlacklistsHandler),
])
# geoip.ipfire.org
- self.add_handlers(r"geoip(\.dev)?\.ipfire\.org", [
+ self.add_handlers(r"geoip\.ipfire\.org", [
(r"/", tornado.web.RedirectHandler, { "url" : "https://location.ipfire.org/" }),
])
# talk.ipfire.org
- self.add_handlers(r"talk(\.dev)?\.ipfire\.org", [
+ self.add_handlers(r"talk\.ipfire\.org", [
(r"/", tornado.web.RedirectHandler, { "url" : "https://people.ipfire.org/" }),
])
# people.ipfire.org
- self.add_handlers(r"people(\.dev)?\.ipfire\.org", [
+ self.add_handlers(r"people\.ipfire\.org", [
(r"/", people.IndexHandler),
(r"/activate/([a-z_][a-z0-9_-]{0,31})/(\w+)", auth.ActivateHandler),
(r"/conferences", people.ConferencesHandler),
] + authentication_handlers)
# wiki.ipfire.org
- self.add_handlers(r"wiki(\.dev)?\.ipfire\.org",
+ self.add_handlers(r"wiki\.ipfire\.org",
authentication_handlers + [
# Actions
logging.info("Successfully initialied application")
+ def format_asn(self, handler, asn):
+ return util.format_asn(asn)
+
def format_country_name(self, handler, country_code):
return ipfire.countries.get_name(country_code)
return remote_ips.pop()
@lazy_property
- def remote(self):
+ def current_address(self):
address = self.get_remote_ip()
if address:
- return self.backend.geoip.lookup(address)
+ return util.Address(self.backend, address)
@lazy_property
def current_country_code(self):
- remote_ip = self.get_remote_ip()
-
- if remote_ip:
- return self.backend.geoip.get_country(remote_ip)
-
- def get_remote_location(self):
- if not hasattr(self, "__remote_location"):
- remote_ip = self.get_remote_ip()
-
- self.__remote_location = self.geoip.get_location(remote_ip)
-
- return self.__remote_location
+ if self.current_address:
+ return self.current_address.country_code
def get_argument_int(self, *args, **kwargs):
arg = self.get_argument(*args, **kwargs)
def releases(self):
return self.backend.releases
- @property
- def geoip(self):
- return self.backend.geoip
-
@property
def talk(self):
return self.backend.talk
class DonateHandler(base.BaseHandler):
def get(self):
- location = self.get_remote_location()
-
- if location:
- country = location.country
- else:
- country = None
+ country = self.current_country_code
# Get defaults
first_name = self.get_argument("first_name", None)
profile_blob = self.get_profile_blob()
#self.check_profile_blob(profile_blob)
- # Get location
- location = self.get_remote_location()
- if location:
- location = location.country
-
# Handle the profile.
with self.db.transaction():
try:
- self.fireinfo.handle_profile(public_id, profile_blob, location=location)
+ self.fireinfo.handle_profile(public_id, profile_blob,
+ country_code=self.current_country_code)
except fireinfo.ProfileParserError as e:
raise tornado.web.HTTPError(400, "Could not parse profile: %s" % e)
import logging
import tornado.web
+from .. import util
+
from . import base
class IndexHandler(base.BaseHandler):
def get(self):
- self.render("location/index.html")
+ self.render("location/index.html", address=self.current_address)
class LookupHandler(base.BaseHandler):
async def get(self, address):
- peer = self.geoip.get_all(address)
- if peer:
- peer["country_name"] = self.geoip.get_country_name(peer.country)
-
# Lookup address
- address = self.geoip.lookup(address)
+ address = util.Address(self.backend, address)
# Lookup blacklists
is_blacklisted = await address.is_blacklisted()
self.render("location/lookup.html",
- address=address, is_blacklisted=is_blacklisted, peer=peer)
+ address=address, is_blacklisted=is_blacklisted)
class BlacklistsHandler(base.BaseHandler):
async def get(self, address):
- peer = self.geoip.get_all(address)
-
# Lookup address
- address = self.geoip.lookup(address)
+ address = util.Address(self.backend, address)
# Lookup blacklists
blacklists = await address.get_blacklists()