]> git.ipfire.org Git - ipfire.org.git/blame - src/web/handlers_mirrors.py
web: Rename base module
[ipfire.org.git] / src / web / handlers_mirrors.py
CommitLineData
940227cb
MT
1#!/usr/bin/python
2
3import socket
4import tornado.web
5
124a8404 6from . import base
940227cb 7
124a8404 8class MirrorIndexHandler(base.BaseHandler):
940227cb 9 def get(self):
9068dba1
MT
10 ip_addr = self.get_argument("addr", None)
11 if not ip_addr:
12 ip_addr = self.get_remote_ip()
13
14 location = self.geoip.get_location(ip_addr)
940227cb 15
0673d1b0 16 # Get a list of all mirrors.
9068dba1 17 mirrors = self.mirrors.get_all()
0673d1b0
MT
18
19 # Choose the preferred ones by their location.
9068dba1 20 preferred_mirrors = mirrors.get_for_location(location)
0673d1b0
MT
21
22 self.render("mirrors.html",
9068dba1 23 preferred_mirrors=preferred_mirrors, mirrors=mirrors)
940227cb
MT
24
25
124a8404 26class MirrorItemHandler(base.BaseHandler):
9068dba1
MT
27 def get(self, what):
28 mirror = self.mirrors.get_by_hostname(what)
940227cb 29 if not mirror:
8fbb75cf 30 mirror = self.mirrors.get(what)
940227cb 31
9068dba1
MT
32 if not mirror:
33 raise tornado.web.HTTPError(404, what)
34
35 ip_addr = self.get_argument("addr", None)
36 if not ip_addr:
37 ip_addr = self.get_remote_ip()
38 client_location = self.geoip.get_location(ip_addr)
119f55d7
MT
39
40 client_distance = mirror.distance_to(client_location, ignore_preference=True)
119f55d7 41
9068dba1 42 self.render("mirrors-item.html", item=mirror, client_distance=client_distance)
940227cb
MT
43
44
124a8404 45class MirrorHandler(base.BaseHandler):
940227cb
MT
46 def get(self):
47 self.redirect("mirrors/all")
48
49
124a8404 50class MirrorAllHandler(base.BaseHandler):
940227cb
MT
51 def get(self):
52 self.render("downloads-mirrors.html", mirrors=self.mirrors.list())
53
54
124a8404 55class MirrorDetailHandler(base.BaseHandler):
940227cb
MT
56 def get(self, id):
57 self.render("download-mirror-detail.html", mirror=self.mirrors.get(id))