mirror of https://github.com/r4sas/py-i2phosts
Hidden Z
14 years ago
3 changed files with 34 additions and 0 deletions
@ -0,0 +1,8 @@ |
|||||||
|
from django.conf.urls.defaults import * |
||||||
|
|
||||||
|
urlpatterns = patterns('web.jump.views', |
||||||
|
(r'^error/', 'error'), |
||||||
|
(r'^unknown/', 'unknown'), |
||||||
|
(r'^(.+)', 'jumper'), |
||||||
|
|
||||||
|
) |
@ -0,0 +1,25 @@ |
|||||||
|
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('error/') |
||||||
|
try: |
||||||
|
key = i2phost.objects.get(name=hostname, activated=True).b64hash |
||||||
|
except i2phost.DoesNotExist: |
||||||
|
return redirect('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.') |
Loading…
Reference in new issue