summaryrefslogtreecommitdiffstats
path: root/virtualenv/pffedportal
diff options
context:
space:
mode:
authorThomas NOEL <tnoel@entrouvert.com>2013-03-21 11:13:28 (GMT)
committerThomas NOEL <tnoel@entrouvert.com>2013-03-21 11:13:28 (GMT)
commit822c6289308e67f926265cd84f2f14a975564988 (patch)
treedba1025c4c762b0212dd4cab69544057de438997 /virtualenv/pffedportal
parent19d9a08a80c78f4ba78391a03de0526e95bcfede (diff)
downloadunivnautes-old-822c6289308e67f926265cd84f2f14a975564988.zip
univnautes-old-822c6289308e67f926265cd84f2f14a975564988.tar.gz
univnautes-old-822c6289308e67f926265cd84f2f14a975564988.tar.bz2
pffedportal: create_loginhtml.py script
Diffstat (limited to 'virtualenv/pffedportal')
-rwxr-xr-xvirtualenv/pffedportal/create_loginhtml.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/virtualenv/pffedportal/create_loginhtml.py b/virtualenv/pffedportal/create_loginhtml.py
new file mode 100755
index 0000000..aec7662
--- /dev/null
+++ b/virtualenv/pffedportal/create_loginhtml.py
@@ -0,0 +1,62 @@
+#!/usr/bin/env python
+
+'''
+output a merge of idp + geo informations from discojuice
+'''
+
+# initialise django environnement for pffedportal
+# (the script is launched into the pffedportal directory)
+import os
+os.environ['DJANGO_SETTINGS_MODULE'] = "settings"
+
+from authentic2.saml.common import get_idp_list_sorted
+import sys
+import json
+import math
+import urllib
+
+def geo2idp(filename):
+ idps = {}
+ try:
+ f = open(filename)
+ except IOError, e:
+ print >> sys.stderr, e
+ return {}
+ try:
+ idp_list = json.load(f)
+ except ValueError, e:
+ f.close()
+ print >> sys.stderr, 'reading %s: %s' % (filename, e)
+ return {}
+ f.close()
+ if not idp_list or not isinstance(idp_list, list):
+ print >> sys.stderr, '%s does not contain a list' % filename
+ return {}
+ for idp in idp_list:
+ try:
+ idps[idp['entityID']] = idp
+ except Exception, e:
+ print >> sys.stderr, 'bad geo information in %s (%s)' % (filename, idp)
+ return idps
+
+geo_idps = {}
+for geofile in sys.argv[1:]:
+ geo_idps.update(geo2idp(geofile))
+
+
+print """{% extends "login0.html" %}
+{% block idps %}
+"""
+n = 0
+for idp in get_idp_list_sorted():
+ n += 1
+ entity_id = idp['entity_id']
+ name = idp['name']
+ geo = geo_idps.get(entity_id, {}).get('geo', { 'lat': 47.0 + 2.0*math.sin(n), 'lon': 2.5 + 3.0*math.cos(n) })
+ href = '/sso?' + urllib.urlencode([('entity_id', entity_id)])
+ li = u'<li><a href="%s" class="idplink" data-lat="%s" data-lon="%s" data-entityid="%s" data-filtertext="%s">%s</a></li>' % \
+ (href, geo['lat'], geo['lon'], entity_id, name, name)
+ print li.encode("utf-8")
+
+print "{% endblock %}"
+