Browse Source

Add jumpservice implementation

pull/1/head
Hidden Z 14 years ago
parent
commit
d7dce40818
  1. 8
      web/jump/urls.py
  2. 25
      web/jump/views.py
  3. 1
      web/urls.py

8
web/jump/urls.py

@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
from django.conf.urls.defaults import *
urlpatterns = patterns('web.jump.views',
(r'^error/', 'error'),
(r'^unknown/', 'unknown'),
(r'^(.+)', 'jumper'),
)

25
web/jump/views.py

@ -0,0 +1,25 @@ @@ -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.')

1
web/urls.py

@ -6,6 +6,7 @@ admin.autodiscover() @@ -6,6 +6,7 @@ admin.autodiscover()
urlpatterns = patterns('',
(r'^postkey/', include('web.postkey.urls')),
(r'^jump/', include('web.jump.urls')),
# Example:
# (r'^web/', include('web.foo.urls')),

Loading…
Cancel
Save