]> git.ipfire.org Git - ipfire.org.git/blame - webapp/handlers_mirrors.py
Major update of the webapp.
[ipfire.org.git] / webapp / handlers_mirrors.py
CommitLineData
940227cb
MT
1#!/usr/bin/python
2
3import socket
4import tornado.web
5
6from handlers_base import *
7
8class MirrorIndexHandler(BaseHandler):
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
26class MirrorItemHandler(BaseHandler):
9068dba1
MT
27 def get(self, what):
28 mirror = self.mirrors.get_by_hostname(what)
940227cb 29 if not mirror:
9068dba1 30 mirror = self.mirrors.get(id)
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
45class MirrorHandler(BaseHandler):
46 def get(self):
47 self.redirect("mirrors/all")
48
49
50class MirrorAllHandler(BaseHandler):
51 def get(self):
52 self.render("downloads-mirrors.html", mirrors=self.mirrors.list())
53
54
55class MirrorDetailHandler(BaseHandler):
56 def get(self, id):
57 self.render("download-mirror-detail.html", mirror=self.mirrors.get(id))
0a003782
MT
58
59
60class MirrorListPakfire2Handler(BaseHandler):
61 def get(self):
62 suffix = self.get_argument("suffix", "")
bd17b7d1 63 development = self.get_argument("development", None)
0a003782
MT
64
65 self.set_header("Content-Type", "text/plain")
66
bd17b7d1
MT
67 # Get all mirror servers that are currently up.
68 mirrors = self.mirrors.get_all_up()
0a003782
MT
69
70 lines = []
71 for m in mirrors:
9068dba1 72 if not m.mirrorlist:
bd17b7d1
MT
73 continue
74
75 # Skip all non-development mirrors
76 # if we run in development mode.
77 if development and not m.development:
0a003782
MT
78 continue
79
9068dba1 80 path = [m.path, "pakfire2"]
0a003782
MT
81
82 if suffix:
83 path.append(suffix)
84
85 path = "/".join(path)
86
87 # Remove double slashes.
88 path = path.replace("//", "/")
89
90 # Remove leading slash.
91 if path.startswith("/"):
92 path = path[1:]
93
94 # Remove trailing slash.
95 if path.endswith("/"):
96 path = path[:-1]
97
98 line = ("HTTP", m.hostname, path, "")
99 lines.append(";".join(line))
100
101 self.finish("\r\n".join(lines))