src/web/handlers_admin.py \
src/web/handlers_base.py \
src/web/handlers_boot.py \
- src/web/handlers_download.py \
src/web/handlers_fireinfo.py \
src/web/handlers_iuse.py \
src/web/handlers_mirrors.py \
# downloads.ipfire.org
self.add_handlers(r"downloads?(\.dev)?\.ipfire\.org", [
- (r"/(iso|torrent)/(.*)", DownloadCompatHandler),
- (r"/(.*)", DownloadFileHandler),
+ (r"/", tornado.web.RedirectHandler, { "url" : "https://www.ipfire.org/" }),
+ (r"/(.*)", download.FileHandler),
])
# mirrors.ipfire.org
#!/usr/bin/python
+import random
import tornado.web
from . import handlers_base as base
self.render("download/release.html", release=release)
+class FileHandler(base.BaseHandler):
+ def prepare(self):
+ self.set_header("Pragma", "no-cache")
+
+ def head(self, filename):
+ self.redirect_to_mirror(filename)
+
+ def get(self, filename):
+ self.redirect_to_mirror(filename, log_download=True)
+
+ def find_mirror(self, filename):
+ exists = self.mirrors.file_exists(filename)
+ if not exists:
+ raise tornado.web.HTTPError(404, "File not found: %s" % filename)
+
+ # Find mirrors located near to the user.
+ # If we have not found any, we use a random one.
+ remote_location = self.get_remote_location()
+
+ if remote_location:
+ mirrors = self.mirrors.get_for_location(remote_location, filename=filename)
+
+ if mirrors:
+ return random.choice(mirrors)
+
+ return self.mirrors.get_random(filename=filename)
+
+ def redirect_to_mirror(self, filename, log_download=False):
+ # Find a random mirror.
+ mirror = self.find_mirror(filename)
+
+ # Construct the redirection URL.
+ download_url = mirror.build_url(filename)
+
+ # Redirect the request.
+ self.redirect(download_url)
+
+ if not log_download:
+ return
+
+ remote_location = self.get_remote_location()
+ if remote_location:
+ country_code = remote_location.country
+ else:
+ country_code = None
+
+ self.db.execute("INSERT INTO log_download(filename, mirror, country_code) \
+ VALUES(%s, %s, %s)", filename, mirror.id, country_code)
+
+
class ButtonModule(ui_modules.UIModule):
def render(self, release):
for arch in release.arches:
from handlers_admin import *
from handlers_base import *
from handlers_boot import *
-from handlers_download import *
from handlers_fireinfo import *
from handlers_iuse import *
from handlers_mirrors import *
+++ /dev/null
-#!/usr/bin/python
-
-import random
-import tornado.web
-
-from handlers_base import *
-
-class DownloadFileHandler(BaseHandler):
- def prepare(self):
- self.set_header("Pragma", "no-cache")
-
- def head(self, filename):
- self.redirect_to_mirror(filename)
-
- def get(self, filename):
- self.redirect_to_mirror(filename, log_download=True)
-
- def find_mirror(self, filename):
- exists = self.mirrors.file_exists(filename)
- if not exists:
- raise tornado.web.HTTPError(404, "File not found: %s" % filename)
-
- # Find mirrors located near to the user.
- # If we have not found any, we use a random one.
- remote_location = self.get_remote_location()
-
- if remote_location:
- mirrors = self.mirrors.get_for_location(remote_location, filename=filename)
-
- if mirrors:
- return random.choice(mirrors)
-
- return self.mirrors.get_random(filename=filename)
-
- def redirect_to_mirror(self, filename, log_download=False):
- # Find a random mirror.
- mirror = self.find_mirror(filename)
-
- # Construct the redirection URL.
- download_url = mirror.build_url(filename)
-
- # Redirect the request.
- self.redirect(download_url)
-
- if not log_download:
- return
-
- remote_location = self.get_remote_location()
- if remote_location:
- country_code = remote_location.country
- else:
- country_code = None
-
- self.db.execute("INSERT INTO log_download(filename, mirror, country_code) \
- VALUES(%s, %s, %s)", filename, mirror.id, country_code)
-
-
-class DownloadCompatHandler(BaseHandler):
- def get(self, path, url):
- for filename in self.mirrors.get_all_files():
- if not filename.endswith("/%s" % url):
- continue
-
- self.redirect("/%s" % filename)
- return
-
- raise tornado.web.HTTPError(404)