1
0
mirror of https://github.com/r4sas/py-i2phosts synced 2025-01-10 06:47:58 +00:00
py-i2phosts/web/jump/views.py

46 lines
1.2 KiB
Python
Raw Normal View History

import re
from django.shortcuts import render_to_response
2010-10-17 18:18:39 +00:00
from django.core.exceptions import ValidationError
from web.postkey.models import i2phost
from web.lib.validation import validate_hostname
from web import settings
2010-10-17 18:18:39 +00:00
def jumper(request, host):
2010-10-17 18:18:39 +00:00
"""Actually do jumps."""
try:
hostname = validate_hostname(host)
2010-10-17 18:18:39 +00:00
except ValidationError, e:
return render_to_response('jump-error.html', {
'title': settings.SITE_NAME,
'error': e,
})
2010-10-17 18:18:39 +00:00
try:
key = i2phost.objects.get(name=hostname, activated=True).b64hash
except i2phost.DoesNotExist:
return render_to_response('jump-unknown.html', {
'title': settings.SITE_NAME,
})
# begin forming url
url = 'http://' + hostname
# get params from requst string, e.g. from 'example.i2p/smth/1?a=b&c=d' get 'smth/1?a=b&c=d'
pattern = host + r'/(.+)'
m = re.search(pattern, request.get_full_path())
if m:
params = m.group(1)
url += '/' + params
# determine how we should pass i2paddresshelper
# http://zzz.i2p/oldnews.html#jump
if params.find('?') == -1:
suffix = '?'
else:
suffix = '&'
url += suffix + 'i2paddresshelper=' + key
else:
url += '/?i2paddresshelper=' + key
return render_to_response('jump.html', {
'title': settings.SITE_NAME,
'url': url,
})