0001-redirecting-user-after-login-to-a-specific-url-or-to.patch
usr/local/univnautes/sp/sp/pfconfigxml.py | ||
---|---|---|
121 | 121 |
tilesurl = tilesurl.text |
122 | 122 |
return tilesurl |
123 | 123 | |
124 |
def get_redirect_params(): |
|
125 |
sp = root().find('univnautes/sp') |
|
126 |
redirect_url = sp.find('redirect_url') |
|
127 |
if redirect_url is not None: |
|
128 |
redirect_url = redirect_url.text |
|
129 |
redirect_delay = sp.find('redirect_delay') |
|
130 |
if redirect_delay is not None: |
|
131 |
redirect_delay = redirect_delay.text or 0 |
|
132 |
return redirect_url, redirect_delay |
|
133 | ||
124 | 134 |
def get_sp(): |
125 | 135 |
sp = root().find('univnautes/sp') |
126 | 136 |
if sp is None: |
usr/local/univnautes/sp/sp/templates/base.html | ||
---|---|---|
3 | 3 |
<head> |
4 | 4 |
<meta charset="utf-8"/> |
5 | 5 |
<title>{% block page-title %}eduspot{% endblock %}</title> |
6 |
{% block meta %}{% endblock %} |
|
6 | 7 |
{% block js %}{% endblock %} |
7 | 8 |
{% block css %}{% endblock %} |
8 | 9 |
<link rel="stylesheet" type="text/css" media="all" href="{% static "univnautes/univnautes.css" %}" /> |
usr/local/univnautes/sp/sp/templates/homepage.html | ||
---|---|---|
1 | 1 |
{% extends "base.html" %} |
2 |
{% block meta %} |
|
3 |
{% if redirect_url %} <meta http-equiv="refresh" content="{{ redirect_delay }}; URL={{ redirect_url }}" />{% endif %} |
|
4 |
{% endblock %} |
|
2 | 5 |
{% load static %} |
3 | 6 | |
4 | 7 |
{% block content %} |
... | ... | |
28 | 31 |
avez maintenant accès au réseau. |
29 | 32 |
</h2> |
30 | 33 | |
34 |
{% if redirect_url %} |
|
35 |
<p>Vous allez être redirigé vers <a href="{{ redirect_url }}">{{ redirect_url }}</a>{% if redirect_delay %} dans |
|
36 |
{{ redirect_delay }} seconde(s) {% endif %}</p> |
|
37 |
{% endif %} |
|
38 | ||
31 | 39 |
<p> |
32 | 40 |
Après avoir utilisé cet accès, n'oubliez pas de fermer votre navigateur, afin |
33 | 41 |
que la session de connexion à votre établissement soit bien clôturée. |
usr/local/univnautes/sp/sp/urls.py | ||
---|---|---|
24 | 24 |
url(r'^proxymap/(?P<z>[0-9]+)/(?P<x>[0-9]+)/(?P<y>[0-9]+)\.png$', 'sp.views.proxymap'), |
25 | 25 |
url(r'^accounts/logout/', 'sp.views.logout', name='logout'), |
26 | 26 |
url(r'^accounts/logoutlogin/', 'django.contrib.auth.views.logout_then_login', name='django_logout_then_login'), |
27 |
url(r'^accounts/login/', 'sp.views.login', name='login'), |
|
27 | 28 |
url(r'^accounts/', include('django.contrib.auth.urls')), |
28 | 29 |
url(r'^authsaml2/', include('authentic2.authsaml2.urls')), |
29 | 30 |
) |
usr/local/univnautes/sp/sp/views.py | ||
---|---|---|
19 | 19 |
from django.conf import settings |
20 | 20 |
from django.views.generic.base import TemplateView |
21 | 21 |
from django.contrib.auth.decorators import login_required |
22 |
from django.contrib.auth.views import login as django_login |
|
23 |
from django.template import Template, Context |
|
22 | 24 |
import urllib2 |
23 | 25 |
from django.http import HttpResponse |
26 |
from django.utils.http import urlencode |
|
24 | 27 |
from django.shortcuts import redirect |
25 | 28 |
import subprocess |
26 | 29 | |
27 |
from .pfconfigxml import get_tilesurl |
|
28 | ||
30 |
from .pfconfigxml import get_tilesurl, get_redirect_params |
|
29 | 31 | |
30 | 32 |
class Homepage(TemplateView): |
31 | 33 |
'''Homepage View, displays a welcome message''' |
32 | 34 |
template_name = 'homepage.html' |
35 |
def get_context_data(self, *args, **kwargs): |
|
36 |
context = super(Homepage, self).get_context_data(*args, **kwargs) |
|
37 |
url, delay = get_redirect_params() |
|
38 |
if url == 'next_url': |
|
39 |
url = urllib2.unquote(self.request.COOKIES.get(url, '')) |
|
40 | ||
41 |
url = Template(url).render(Context(context)) |
|
42 |
context.update({'redirect_url': url, |
|
43 |
'redirect_delay': delay}) |
|
44 |
return context |
|
45 | ||
33 | 46 |
homepage = login_required(Homepage.as_view()) |
34 | 47 | |
48 |
def login(request): |
|
49 |
response = django_login(request) |
|
50 |
response.set_cookie('next_url', request.GET.get('next'), path='/') |
|
51 |
return response |
|
35 | 52 | |
36 | 53 |
def proxymap(request, z, x, y): |
37 | 54 |
tiles_url = get_tilesurl() or settings.PROXYMAP_URL |
usr/local/www/services_captiveportal_saml_sp.php | ||
---|---|---|
65 | 65 |
$pconfig['geolocations'] = base64_decode($a_sp['geolocations']); |
66 | 66 |
$pconfig['geoinitialbounds'] = $a_sp['geoinitialbounds']; |
67 | 67 |
$pconfig['tilesurl'] = $a_sp['tilesurl']; |
68 |
$pconfig['redirect_url'] = $a_sp['redirect_url']; |
|
69 |
$pconfig['redirect_delay'] = $a_sp['redirect_delay']; |
|
70 |
if($pconfig['redirect_url']!='next_url') |
|
71 |
$pconfig['defined_redirect_url'] = $a_sp['redirect_url']; |
|
68 | 72 | |
69 | 73 |
$pgtitle = array(gettext("Services"),gettext("Captive portal"), "SAML 2.0 Service provider"); |
70 | 74 |
$shortcut_section = "captiveportal"; |
... | ... | |
92 | 96 |
$a_sp['geolocations'] = base64_encode($pconfig['geolocations']); |
93 | 97 |
$a_sp['geoinitialbounds'] = $pconfig['geoinitialbounds']; |
94 | 98 |
$a_sp['tilesurl'] = $pconfig['tilesurl']; |
99 |
$a_sp['redirect_url'] = $pconfig['redirect_url']; |
|
100 |
$a_sp['redirect_delay'] = $pconfig['redirect_delay']; |
|
101 |
if ($a_sp['redirect_url'] == 'defined_redirect_url') |
|
102 |
$a_sp['redirect_url'] = $pconfig['defined_redirect_url']; |
|
103 |
else |
|
104 |
$pconfig['defined_redirect_url'] = ''; |
|
95 | 105 |
/* write config.xml */ |
96 | 106 |
write_config(); |
107 |
if ($a_sp['redirect_url'] != 'defined_redirect_url') |
|
97 | 108 | |
98 | 109 |
/* relaunch SP */ |
99 | 110 |
mwexec_bg("/usr/local/univnautes/sp/rc.sh restart"); |
... | ... | |
145 | 156 |
<?php endif; ?> |
146 | 157 |
</td> |
147 | 158 |
</tr> |
159 |
<tr> |
|
160 |
<td width="22%" valign="top" class="vncell"><?=gettext("After login redirect to"); ?></td> |
|
161 |
<td width="78%" class="vtable"> |
|
162 |
<table> |
|
163 |
<tr> |
|
164 |
<td><input type="radio" name="redirect_url" value="next_url" <?php if($pconfig['redirect_url']=='next_url') echo "checked";?> /> user requested url</td> |
|
165 |
</tr> |
|
166 |
<tr><td>or</td></tr> |
|
167 |
<tr> |
|
168 |
<td> |
|
169 |
<input type="radio" name="redirect_url" value="defined_redirect_url" <?php if ($pconfig['redirect_url'] && $pconfig['redirect_url']!='next_url') echo "checked";?> /> |
|
170 |
<input type="url" name="defined_redirect_url" value="<?=htmlspecialchars($pconfig['defined_redirect_url']);?>" /> <br /> |
|
171 |
<i><?=gettext("accepts variables in like in Django templates ('{{ varname }}')"); ?></i> |
|
172 |
</td> |
|
173 |
</tr> |
|
174 |
</table> |
|
175 |
</td> |
|
176 |
</tr> |
|
177 |
<tr> |
|
178 |
<td width="22%" valign="top" class="vncell"><?=gettext("Redirect delay"); ?></td> |
|
179 |
<td width="78%" class="vtable"> |
|
180 |
<input type="number" name="redirect_delay" min="0" max="60" value="<?=htmlspecialchars($pconfig['redirect_delay']);?>" /> seconds |
|
181 |
</td> |
|
182 |
</tr> |
|
148 | 183 | |
149 | 184 |
<tr> |
150 | 185 |
<td colspan="2" class="list" height="12"></td> |
151 |
- |