1
|
# -*- coding: utf-8 -*-
|
2
|
#
|
3
|
# UnivNautes
|
4
|
# Copyright (C) 2014 Entr'ouvert
|
5
|
#
|
6
|
# This program is free software: you can redistribute it and/or modify it under
|
7
|
# the terms of the GNU Affero General Public License as published by the Free
|
8
|
# Software Foundation, either version 3 of the License, or (at your option) any
|
9
|
# later version.
|
10
|
#
|
11
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
12
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
13
|
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
14
|
# details.
|
15
|
#
|
16
|
# You should have received a copy of the GNU Affero General Public License
|
17
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
|
19
|
from django.conf import settings
|
20
|
from django.views.generic.base import TemplateView
|
21
|
from django.contrib.auth.decorators import login_required
|
22
|
import urllib2
|
23
|
from django.http import HttpResponse
|
24
|
from django.shortcuts import redirect
|
25
|
import subprocess
|
26
|
|
27
|
|
28
|
class Homepage(TemplateView):
|
29
|
'''Homepage View, displays a welcome message'''
|
30
|
template_name = 'homepage.html'
|
31
|
homepage = login_required(Homepage.as_view())
|
32
|
|
33
|
|
34
|
def proxymap(request, z, x, y):
|
35
|
url = settings.PROXYMAP_URL % { 'z': int(z), 'x': int(x), 'y': int(y) }
|
36
|
downstream_request = urllib2.Request(url)
|
37
|
page = urllib2.urlopen(downstream_request)
|
38
|
return HttpResponse(page, page.info().getheader('Content-Type'))
|
39
|
|
40
|
def logout(request):
|
41
|
# 1. disconnect from the captive portal
|
42
|
cmd = [ c % {
|
43
|
'cpzone': request.META.get('HTTP_X_PFSENSE_CPZONE') or '',
|
44
|
'ip': request.META['REMOTE_ADDR'],
|
45
|
} for c in settings.UNIVNAUTES_CP_DISCONNECT_CMD ]
|
46
|
p = subprocess.call(cmd)
|
47
|
# 2. disconnect from django
|
48
|
return redirect('django_logout_then_login')
|
49
|
|