2015-06-22 22:35:08 +00:00
|
|
|
from flask import abort, redirect, render_template, request
|
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 = {
|
2021-06-26 10:06:17 -04:00
|
|
|
"net": "clearnet",
|
|
|
|
"protocol": "https",
|
2021-08-24 19:09:52 -04:00
|
|
|
"domain": "download.i2p2.de",
|
2021-08-24 19:11:20 -04:00
|
|
|
"path": "/releases/%(version)s/%(file)s",
|
2021-08-24 19:09:52 -04:00
|
|
|
"org": "i2p2.de",
|
|
|
|
"org_url": "https://download.i2p2.de",
|
2021-08-24 19:11:20 -04:00
|
|
|
"country": "de",
|
2013-07-03 11:54:53 +00:00
|
|
|
}
|
|
|
|
|
2021-06-26 10:06:17 -04:00
|
|
|
#{
|
|
|
|
# 'net': 'clearnet',
|
|
|
|
# 'protocol': 'https',
|
|
|
|
# 'domain': 'download.i2p2.de',
|
|
|
|
# 'org': 'sigterm.no',
|
|
|
|
# 'country': 'no',
|
|
|
|
#}
|
|
|
|
|
2015-06-22 22:35:08 +00:00
|
|
|
DEFAULT_I2P_MIRROR = {
|
2015-06-24 12:19:51 +00:00
|
|
|
'net': 'i2p',
|
2015-06-22 22:35:08 +00:00
|
|
|
'protocol': 'http',
|
2021-02-19 23:11:01 -05:00
|
|
|
'domain': 'mgp6yzdxeoqds3wucnbhfrdgpjjyqbiqjdwcfezpul3or7bzm4ga.b32.i2p',
|
|
|
|
'org': 'eyedeekay.github.io',
|
2015-06-22 22:35:08 +00:00
|
|
|
'country': 'i2p',
|
|
|
|
}
|
|
|
|
|
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
|
2015-06-24 12:19:51 +00:00
|
|
|
net=obj['net']
|
2012-12-19 12:52:05 +00:00
|
|
|
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)
|
2015-06-24 12:19:51 +00:00
|
|
|
if net not in ret:
|
|
|
|
ret[net]={}
|
|
|
|
if protocol not in ret[net]:
|
|
|
|
ret[net][protocol]={}
|
|
|
|
ret[net][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
|
2015-06-22 22:35:08 +00:00
|
|
|
if request.headers.get('X-I2P-Desthash') and not request.headers.get('X-Forwarded-Server'):
|
|
|
|
def_mirror = DEFAULT_I2P_MIRROR
|
|
|
|
else:
|
|
|
|
def_mirror = DEFAULT_MIRROR
|
|
|
|
return render_template('downloads/list.html', def_mirror=def_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')
|
|
|
|
|
2020-10-05 12:35:07 -04:00
|
|
|
# Windows-specific page
|
|
|
|
def downloads_windows():
|
|
|
|
return render_template('downloads/windows.html')
|
|
|
|
|
2021-07-05 13:27:52 -04:00
|
|
|
# Docker-specific page
|
|
|
|
def downloads_docker():
|
|
|
|
return render_template('downloads/docker.html')
|
|
|
|
|
2019-01-13 19:37:44 +00:00
|
|
|
# Firefox-specific page
|
|
|
|
def downloads_firefox():
|
2019-01-17 16:51:13 +00:00
|
|
|
# TODO: read mirror list or list of available files
|
|
|
|
if request.headers.get('X-I2P-Desthash') and not request.headers.get('X-Forwarded-Server'):
|
|
|
|
def_mirror = DEFAULT_I2P_MIRROR
|
|
|
|
else:
|
|
|
|
def_mirror = DEFAULT_MIRROR
|
|
|
|
return render_template('downloads/firefox.html', def_mirror=def_mirror)
|
2019-01-13 19:37:44 +00:00
|
|
|
|
2019-02-11 20:55:09 +00:00
|
|
|
# The Lab
|
|
|
|
def downloads_lab():
|
|
|
|
return render_template('downloads/lab.html')
|
|
|
|
|
2020-01-31 18:46:51 +00:00
|
|
|
def downloads_config():
|
|
|
|
return render_template('downloads/config.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=[]
|
2015-06-24 12:19:51 +00:00
|
|
|
for net in mirrors.keys():
|
2012-12-19 12:52:05 +00:00
|
|
|
a={}
|
2015-06-24 12:19:51 +00:00
|
|
|
a['key']=net
|
|
|
|
a['name']=net
|
|
|
|
a['protocols']=[]
|
|
|
|
for protocol in mirrors[net].keys():
|
|
|
|
b={}
|
|
|
|
b['key']=protocol
|
|
|
|
b['name']=protocol
|
|
|
|
b['domains']=mirrors[net][protocol]
|
|
|
|
a['protocols'].append(b)
|
2012-12-19 12:52:05 +00:00
|
|
|
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
|
|
|
|
2015-06-24 12:19:51 +00:00
|
|
|
def downloads_redirect(version, net, protocol, domain, file):
|
2012-12-19 12:52:05 +00:00
|
|
|
mirrors=read_mirrors()
|
2015-06-24 12:19:51 +00:00
|
|
|
if not net in mirrors:
|
2012-12-19 12:52:05 +00:00
|
|
|
abort(404)
|
2015-06-24 12:19:51 +00:00
|
|
|
mirrors=mirrors[net]
|
2012-12-19 12:52:05 +00:00
|
|
|
data = {
|
2013-06-04 09:36:42 +00:00
|
|
|
'version': version,
|
2012-12-19 12:52:05 +00:00
|
|
|
'file': file,
|
|
|
|
}
|
2015-06-24 12:19:51 +00:00
|
|
|
|
|
|
|
if not protocol:
|
2015-06-24 12:20:50 +00:00
|
|
|
protocol = mirrors.keys()[randint(0, len(mirrors) - 1)]
|
2015-06-24 12:19:51 +00:00
|
|
|
if not protocol in mirrors:
|
|
|
|
abort(404)
|
|
|
|
mirrors=mirrors[protocol]
|
|
|
|
|
|
|
|
if not domain:
|
|
|
|
domain = mirrors.keys()[randint(0, len(mirrors) - 1)]
|
|
|
|
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,
|
2015-06-24 12:19:51 +00:00
|
|
|
url=mirrors[domain]['url'] % data)
|