2013-07-03 11:54:53 +00:00
|
|
|
from flask import abort, redirect, render_template
|
2012-12-19 12:52:05 +00:00
|
|
|
try:
|
|
|
|
import json
|
|
|
|
except ImportError:
|
|
|
|
import simplejson as json
|
|
|
|
from random import randint
|
|
|
|
|
|
|
|
from i2p2www import CURRENT_I2P_VERSION, MIRRORS_FILE
|
|
|
|
|
2013-07-03 11:54:53 +00:00
|
|
|
DEFAULT_MIRROR = {
|
2014-02-02 15:52:05 +00:00
|
|
|
'protocol': 'https',
|
|
|
|
'domain': 'download.i2p2.de',
|
2014-03-24 21:27:56 +00:00
|
|
|
'org': 'sigterm.no',
|
2014-03-24 21:25:31 +00:00
|
|
|
'country': 'no',
|
2013-07-03 11:54:53 +00:00
|
|
|
}
|
|
|
|
|
2012-12-19 12:52:05 +00:00
|
|
|
|
|
|
|
###################
|
|
|
|
# Download handlers
|
|
|
|
|
|
|
|
# Read in mirrors from file
|
|
|
|
def read_mirrors():
|
|
|
|
file = open(MIRRORS_FILE, 'r')
|
|
|
|
dat = file.read()
|
|
|
|
file.close()
|
|
|
|
lines=dat.split('\n')
|
|
|
|
ret={}
|
|
|
|
for line in lines:
|
|
|
|
try:
|
|
|
|
obj=json.loads(line)
|
|
|
|
except ValueError:
|
|
|
|
continue
|
2013-07-03 11:54:53 +00:00
|
|
|
if 'protocol' not in obj or 'domain' not in obj or 'path' not in obj:
|
2012-12-19 12:52:05 +00:00
|
|
|
continue
|
|
|
|
protocol=obj['protocol']
|
2013-07-03 11:54:53 +00:00
|
|
|
domain=obj['domain']
|
|
|
|
path=obj['path']
|
|
|
|
obj['url']='%s://%s%s' % (protocol, domain, path)
|
2012-12-19 12:52:05 +00:00
|
|
|
if protocol not in ret:
|
2013-07-03 11:54:53 +00:00
|
|
|
ret[protocol]={}
|
|
|
|
ret[protocol][domain]=obj
|
2012-12-19 12:52:05 +00:00
|
|
|
return ret
|
|
|
|
|
|
|
|
# List of downloads
|
|
|
|
def downloads_list():
|
|
|
|
# TODO: read mirror list or list of available files
|
2013-07-03 11:54:53 +00:00
|
|
|
return render_template('downloads/list.html', def_mirror=DEFAULT_MIRROR)
|
2012-12-19 12:52:05 +00:00
|
|
|
|
2013-07-18 04:40:31 +00:00
|
|
|
# Debian-specific page
|
|
|
|
def downloads_debian():
|
|
|
|
return render_template('downloads/debian.html')
|
|
|
|
|
2012-12-19 12:52:05 +00:00
|
|
|
# Specific file downloader
|
2013-06-04 09:36:42 +00:00
|
|
|
def downloads_select(version, file):
|
2012-12-19 12:52:05 +00:00
|
|
|
mirrors=read_mirrors()
|
|
|
|
obj=[]
|
|
|
|
for protocol in mirrors.keys():
|
|
|
|
a={}
|
|
|
|
a['name']=protocol
|
|
|
|
a['mirrors']=mirrors[protocol]
|
|
|
|
obj.append(a)
|
2013-06-04 09:36:42 +00:00
|
|
|
return render_template('downloads/select.html', mirrors=obj, version=version, file=file)
|
2012-12-19 12:52:05 +00:00
|
|
|
|
2013-07-03 11:54:53 +00:00
|
|
|
def downloads_redirect(version, protocol, domain, file):
|
2012-12-19 12:52:05 +00:00
|
|
|
mirrors=read_mirrors()
|
|
|
|
if not protocol in mirrors:
|
|
|
|
abort(404)
|
|
|
|
mirrors=mirrors[protocol]
|
|
|
|
data = {
|
2013-06-04 09:36:42 +00:00
|
|
|
'version': version,
|
2012-12-19 12:52:05 +00:00
|
|
|
'file': file,
|
|
|
|
}
|
2013-07-03 11:54:53 +00:00
|
|
|
if domain:
|
|
|
|
if not domain in mirrors:
|
|
|
|
abort(404)
|
2014-01-09 17:41:11 +00:00
|
|
|
return render_template('downloads/redirect.html',
|
|
|
|
version=version, protocol=protocol, domain=domain, file=file,
|
|
|
|
url=mirrors[domain]['url'] % data)
|
2013-08-30 13:27:39 +00:00
|
|
|
randomain = mirrors.keys()[randint(0, len(mirrors) - 1)]
|
2014-01-09 17:41:11 +00:00
|
|
|
return render_template('downloads/redirect.html',
|
|
|
|
version=version, protocol=protocol, domain=domain, file=file,
|
|
|
|
url=mirrors[randomain]['url'] % data)
|