mirror of
https://github.com/r4sas/py-i2phosts
synced 2025-03-10 12:21:11 +00:00
Add jumpservice implementation
This commit is contained in:
parent
2858ba6084
commit
d7dce40818
8
web/jump/urls.py
Normal file
8
web/jump/urls.py
Normal file
@ -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
Normal file
25
web/jump/views.py
Normal file
@ -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.')
|
@ -6,6 +6,7 @@ admin.autodiscover()
|
|||||||
|
|
||||||
urlpatterns = patterns('',
|
urlpatterns = patterns('',
|
||||||
(r'^postkey/', include('web.postkey.urls')),
|
(r'^postkey/', include('web.postkey.urls')),
|
||||||
|
(r'^jump/', include('web.jump.urls')),
|
||||||
# Example:
|
# Example:
|
||||||
# (r'^web/', include('web.foo.urls')),
|
# (r'^web/', include('web.foo.urls')),
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user