1
0
mirror of https://github.com/r4sas/py-i2phosts synced 2025-01-24 21:45:08 +00:00
py-i2phosts/web/jump/views.py
Hidden Z 3230f07160 web/jump/views.py: fix redirects
Accessing invalid or unknown hostnames always caused a redirect loop.
2010-10-24 07:08:37 +00:00

26 lines
793 B
Python

from django.shortcuts import redirect
from django.core.exceptions import ValidationError
from django.http import HttpResponse
from web.postkey.models import i2phost
from web.lib.validation import validate_hostname
def jumper(request, data):
"""Actually do jumps."""
try:
hostname = validate_hostname(data)
except ValidationError, e:
return redirect('/jump/error/')
try:
key = i2phost.objects.get(name=hostname, activated=True).b64hash
except i2phost.DoesNotExist:
return redirect('/jump/unknown/')
url = 'http://' + hostname + '/?i2paddresshelper=' + key
return redirect(url, permanent=True)
def error(request):
return HttpResponse('You are trying to access an invalid hostname.')
def unknown(request):
return HttpResponse('You are trying to access an unknown hostname.')