]> git.ipfire.org Git - people/shoehn/ipfire.org.git/blob - webapp/handlers_mirrors.py
netboot: Allow booting multiple architectures
[people/shoehn/ipfire.org.git] / webapp / handlers_mirrors.py
1 #!/usr/bin/python
2
3 import socket
4 import tornado.web
5
6 from handlers_base import *
7
8 class MirrorIndexHandler(BaseHandler):
9 def get(self):
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)
15
16 # Get a list of all mirrors.
17 mirrors = self.mirrors.get_all()
18
19 # Choose the preferred ones by their location.
20 preferred_mirrors = mirrors.get_for_location(location)
21
22 self.render("mirrors.html",
23 preferred_mirrors=preferred_mirrors, mirrors=mirrors)
24
25
26 class MirrorItemHandler(BaseHandler):
27 def get(self, what):
28 mirror = self.mirrors.get_by_hostname(what)
29 if not mirror:
30 mirror = self.mirrors.get(id)
31
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)
39
40 client_distance = mirror.distance_to(client_location, ignore_preference=True)
41
42 self.render("mirrors-item.html", item=mirror, client_distance=client_distance)
43
44
45 class MirrorHandler(BaseHandler):
46 def get(self):
47 self.redirect("mirrors/all")
48
49
50 class MirrorAllHandler(BaseHandler):
51 def get(self):
52 self.render("downloads-mirrors.html", mirrors=self.mirrors.list())
53
54
55 class MirrorDetailHandler(BaseHandler):
56 def get(self, id):
57 self.render("download-mirror-detail.html", mirror=self.mirrors.get(id))
58
59
60 class MirrorListPakfire2Handler(BaseHandler):
61 def get(self):
62 suffix = self.get_argument("suffix", "")
63 development = self.get_argument("development", None)
64
65 self.set_header("Content-Type", "text/plain")
66
67 # Get all mirror servers that are currently up.
68 mirrors = self.mirrors.get_all_up()
69
70 lines = []
71 for m in mirrors:
72 if not m.mirrorlist:
73 continue
74
75 # Skip all non-development mirrors
76 # if we run in development mode.
77 if development and not m.development:
78 continue
79
80 path = [m.path, "pakfire2"]
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))