diff --git a/i2p2www/__init__.py b/i2p2www/__init__.py index 2427784310f50550820e9164d1981bbec316ce52..7fc864311dd12a1e587be0c7b6e594ceaac1f7d0 100644 --- a/i2p2www/__init__.py +++ b/i2p2www/__init__.py @@ -6,6 +6,11 @@ import os.path import os import fileinput import codecs +from random import randint +try: + import json +except ImportError: + import simplejson as json TEMPLATE_DIR = os.path.join(os.path.dirname(__file__), 'pages') @@ -14,6 +19,8 @@ STATIC_DIR = os.path.join(os.path.dirname(__file__), 'static') BLOG_DIR = os.path.join(os.path.dirname(__file__), 'blog') MEETINGS_DIR = os.path.join(os.path.dirname(__file__), 'meetings') +MIRRORS_FILE = os.path.join(TEMPLATE_DIR, 'downloads/mirrors') + app = application = Flask('i2p2www', template_folder=TEMPLATE_DIR, static_url_path='/_static', static_folder=STATIC_DIR) app.debug = bool(os.environ.get('APP_DEBUG', 'False')) babel = Babel(app) @@ -248,6 +255,26 @@ def meetings_show_rst(id): ################### # 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 + if 'protocol' not in obj: + continue + protocol=obj['protocol'] + if protocol not in ret: + ret[protocol]=[] + ret[protocol].append(obj) + return ret + # List of downloads @app.route('/<string:lang>/download') def downloads_list(): @@ -257,16 +284,29 @@ def downloads_list(): # Specific file downloader @app.route('/<string:lang>/download/<path:file>') def downloads_select(file): - # TODO: implement if (file == 'debian'): return render_template('downloads/debian.html') - pass + mirrors=read_mirrors() + obj=[] + for protocol in mirrors.keys(): + a={} + a['name']=protocol + a['mirrors']=mirrors[protocol] + for mirror in a['mirrors']: + mirror['url']=mirror['url'] % file + obj.append(a) + return render_template('downloads/select.html', mirrors=obj, file=file) @app.route('/download/<string:protocol>/any/<path:file>') -@app.route('/download/<string:protocol>/<string:mirror>/<path:file>') +@app.route('/download/<string:protocol>/<int:mirror>/<path:file>') def downloads_redirect(protocol, file, mirror=None): - # TODO: implement - pass + mirrors=read_mirrors() + if not protocol in mirrors: + abort(404) + mirrors=mirrors[protocol] + if mirror: + return redirect(mirrors[mirror]['url'] % file) + return redirect(mirrors[randint(0, len(mirrors) - 1)]['url'] % file) ##################### diff --git a/mirror.i2p2/mirrors b/i2p2www/pages/downloads/mirrors similarity index 53% rename from mirror.i2p2/mirrors rename to i2p2www/pages/downloads/mirrors index 5afeaf675e90ca7c730fa7c7937e7a075555244d..82ab9b31b44f027132067969ebf78f6f9399a8df 100644 --- a/mirror.i2p2/mirrors +++ b/i2p2www/pages/downloads/mirrors @@ -1,2 +1,3 @@ +{"url": "http://i2p.googlecode.com/files/%s", "org": "Google Code", "org_url": "http://code.google.com", "protocol": "http", "country": "us"} {"url": "http://golden.mtveurope.org/~yang/i2p_mirror/%s", "org": "VServer.si", "org_url": "http://www.vserver.si", "protocol": "http", "country": "lu"} -{"url": "http://a.mirror.geti2p.net/releases/current/%s", "org": "welterde", "protocol": "http", "country": "de"} \ No newline at end of file +{"url": "http://a.mirror.geti2p.net/releases/current/%s", "org": "welterde", "protocol": "http", "country": "de"} diff --git a/i2p2www/pages/downloads/select.html b/i2p2www/pages/downloads/select.html new file mode 100644 index 0000000000000000000000000000000000000000..3eaf46a911d75cb94b8b7b19959f997cc2acf2e1 --- /dev/null +++ b/i2p2www/pages/downloads/select.html @@ -0,0 +1,17 @@ +{% extends "global/layout.html" %} +{% block title %}Mirror selection{% endblock %} +{% block content %} +<h1>Mirror selection</h1> +<h2>File: /{{ file }}</h2> +{% for protocol in mirrors -%} +<div class="protocol"> + <h3>{{ protocol.name | upper }}</h3> + <ul> + <li><a href="{{ url_for('downloads_redirect', protocol=protocol.name, file=file) }}">Any mirror</a></li> + {% for mirror in protocol.mirrors -%} + <li><img src="{{ url_for('static', filename='images/'+mirror.country+'.png') }}" /> {% if mirror.org_url %}<a href="{{ mirror.org_url }}">{% endif %}{{ mirror.org }}{% if mirror.org_url %}</a>{% endif %} <a href="{{ url_for('downloads_redirect', protocol=protocol.name, file=file, mirror=loop.index-1) }}">[Download]</a></li> + {%- endfor %} + </ul> +</div> +{%- endfor %} +{% endblock %} diff --git a/mirror.i2p2/mirror.god b/mirror.god.old similarity index 100% rename from mirror.i2p2/mirror.god rename to mirror.god.old diff --git a/mirror.i2p2/app.py b/mirror.i2p2/app.py deleted file mode 100644 index 8c26e2375228e7b64d88a2303bdc6cd418ff9b4b..0000000000000000000000000000000000000000 --- a/mirror.i2p2/app.py +++ /dev/null @@ -1,80 +0,0 @@ -from flask import Flask, redirect, request, render_template, abort -from random import randint -from sys import argv -try: - import json -except ImportError: - import simplejson as json - - -# try to create an memcache client -if len(argv[3:]) > 0: - try: - try: - from cmemcache import Client - except ImportError: - from memcache import Client - client=Client(argv[3:]) - except ImportError: - client=None - -# create application -app=Flask(__name__) - -# extract domain -domain=argv[1] - -# extract port -port=int(argv[2]) - -def read_mirrors(): - file = open('mirrors', 'r') - dat = file.read() - file.close() - lines=dat.split('\n') - ret={} - for line in lines: - try: - obj=json.loads(line) - except ValueError: - pass - if 'protocol' not in obj: - continue - protocol=obj['protocol'] - if protocol not in ret: - ret[protocol]=[] - ret[protocol].append(obj) - return ret - - -@app.route('/') -def index(): - return redirect('http://www.%s/download' % domain) - -@app.route('/select/<path:f>') -def select(f): - mirrors=read_mirrors() - obj=[] - for protocol in mirrors.keys(): - a={} - a['name']=protocol.upper() - a['mirrors']=mirrors[protocol] - for mirror in a['mirrors']: - mirror['url']=mirror['url'] % f - obj.append(a) - return render_template('select.html', mirrors=obj, file=f, domain=domain) - -@app.route('/<protocol>/<path:f>') -def get(protocol, f): - mirrors=read_mirrors() - if not protocol in mirrors: - abort(404) - mirrors=mirrors[protocol] - return redirect(mirrors[randint(0, len(mirrors) - 1)]['url'] % f) - -@app.route('/<f>') -def old_get(f): - return redirect('http://i2p.googlecode.com/files/%s' % f) - -if __name__ == '__main__': - app.run(port=port) diff --git a/mirror.i2p2/static/images/i2plogo.png b/mirror.i2p2/static/images/i2plogo.png deleted file mode 100644 index f7beff26bac365f3b7a6fd6e2bbbe52ed5d61c32..0000000000000000000000000000000000000000 Binary files a/mirror.i2p2/static/images/i2plogo.png and /dev/null differ diff --git a/mirror.i2p2/static/style.css b/mirror.i2p2/static/style.css deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/mirror.i2p2/templates/select.html b/mirror.i2p2/templates/select.html deleted file mode 100644 index fc031ca1c10399e5e642c5432e7d20f8ad47d0f9..0000000000000000000000000000000000000000 --- a/mirror.i2p2/templates/select.html +++ /dev/null @@ -1,29 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" - "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" > - <head> - <title>I2P - Mirror selection - /{{ file }}</title> - <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}" type="text/css"> - </head> - <body> - <div class="logo"> - <a href="{{ domain }}" class="fade"><img src="{{ url_for('static', filename='images/i2plogo.png') }}" alt="I2P Logo" title="Invisible Internet Project (I2P)" /></a> - </div> - <div class="header"> - <h1>Mirror selection</h1> - <h2>File: /{{ file }}</h2> - </div> - {% for protocol in mirrors -%} - <div class="protocol"> - <h3>{{ protocol.name }}</h3> - <ul> - {% for mirror in protocol.mirrors -%} - <li><a href="{{ mirror.url }}">{{ mirror.url }}</a> {% if mirror.org_url %}<a href="{{ mirror.org_url }}">{% endif %}{{ mirror.org }}{% if mirror.org_url %}</a>{% endif %}</li> - {% endfor %} - </ul> - </div> - {%- endfor %} - </body> -</html> -