From 181f0db4aadf7b6411648ad1f12414b3c54831ef Mon Sep 17 00:00:00 2001 From: Thomas NOEL Date: Thu, 21 Mar 2013 15:16:11 +0100 Subject: [PATCH] [map] create login.html with geo locations --- virtualenv/bin/univnautes-update-map.sh | 66 ++++++++++++++++++++++ virtualenv/pffedportal/create_loginhtml.py | 4 +- 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100755 virtualenv/bin/univnautes-update-map.sh diff --git a/virtualenv/bin/univnautes-update-map.sh b/virtualenv/bin/univnautes-update-map.sh new file mode 100755 index 0000000..f6e82a8 --- /dev/null +++ b/virtualenv/bin/univnautes-update-map.sh @@ -0,0 +1,66 @@ +#!/bin/sh + +# lock to avoid concurrent updates +LOCK=/var/run/univnautes-update-map_in-progress.lock +if [ -r $LOCK ] +then + PID=`cat $LOCK` + ps waux | grep $PID | grep univnautes | grep -vq grep && exit +fi +unlock() { + rm -f $LOCK + exit +} +trap unlock INT TERM EXIT +echo $$ > $LOCK + +# config +. /usr/local/univnautes/etc/univnautes.conf + +log() { + logger -p local4.info -t update-map -- "$*" +} + +GEOURLS=/var/lib/univnautes/geourls +GEOLOCAL=/var/lib/univnautes/geolocal +LOGINHTML=/var/lib/univnautes/templates/login.html + +GEODIR=/var/lib/univnautes/geofiles +mkdir -p $GEODIR +GEOFILES="" + +n=1 +for url in `cat $GEOURLS | tr -d ` +do + GEOFILE=$GEODIR/$n + wget -q --no-check-certificate -O $GEOFILE $url + if [ $? -eq 0 ] + then + log "$url OK ($n)" + GEOFILES=$GEOFILES" "$GEOFILE + n=$(($n+1)) + else + log "cannot download $url" + fi +done + +if [ -r $GEOLOCAL ] +then + GEOFILES=$GEOFILES" "$GEOLOCAL +fi + +# virtualenv activation +VIRTUAL_ENV="/usr/local/univnautes" +export VIRTUAL_ENV +PATH="$VIRTUAL_ENV/bin:$PATH" +export PATH + +# create indexhtml +cd /usr/local/univnautes/pffedportal +if [ -r pffedportal.db ] +then + python ./create_loginhtml.py $GEOFILES 2>&1 > $LOGINHTML | logger -p local4.info -t update-map + log "geo-list of idp created" +fi + +exit 0 diff --git a/virtualenv/pffedportal/create_loginhtml.py b/virtualenv/pffedportal/create_loginhtml.py index aec7662..8d74cbb 100755 --- a/virtualenv/pffedportal/create_loginhtml.py +++ b/virtualenv/pffedportal/create_loginhtml.py @@ -29,7 +29,9 @@ def geo2idp(filename): print >> sys.stderr, 'reading %s: %s' % (filename, e) return {} f.close() - if not idp_list or not isinstance(idp_list, list): + if not idp_list: + return {} + if not isinstance(idp_list, list): print >> sys.stderr, '%s does not contain a list' % filename return {} for idp in idp_list: