Another wifi login
authorJoerg Jaspert <joerg@debian.org>
Fri, 3 Nov 2017 08:28:59 +0000 (09:28 +0100)
committerJoerg Jaspert <joerg@debian.org>
Fri, 3 Nov 2017 08:28:59 +0000 (09:28 +0100)
_posts/2017-11-03-more-wifi-login.md [new file with mode: 0644]

diff --git a/_posts/2017-11-03-more-wifi-login.md b/_posts/2017-11-03-more-wifi-login.md
new file mode 100644 (file)
index 0000000..1693ebf
--- /dev/null
@@ -0,0 +1,58 @@
+---
+layout: post
+title: "Automated wifi login, update 2"
+published: true
+categories:
+- tech
+tags:
+- wifi
+- network-manager
+- dispatcher.d
+- script
+- bash
+date: '2017-11-03 09:24:42 +0200'
+---
+Seems my blog lately just consist of updates to my automated login
+script for the ICE wifi... But I do hate the entirely useless "Click a
+button" crap, every day, twice. I've seen it once, now leave me alone,
+please.
+
+Updated script:
+{% highlight bash %}
+#!/bin/bash
+
+# (Some) docs at
+# https://wiki.ubuntuusers.de/NetworkManager/Dispatcher/
+
+IFACE=${1:-"none"}
+ACTION=${2:-"up"}
+
+TMPDIR=${TMPDIR:-"/tmp"}
+
+WGET="/usr/bin/wget"
+TIMEOUT="/usr/bin/timeout -k 20 15"
+
+
+case ${ACTION} in
+    up)
+        CONID=${CONNECTION_ID:-$(iwconfig $IFACE | grep ESSID | cut -d":" -f2 | sed 's/^[^"]*"\|"[^"]*$//g')}
+        if [[ ${CONID} == WIFIonICE ]]; then
+            REFERER="http://www.wifionice.de/de/"
+            LOGIN="http://www.wifionice.de/de/"
+            COOKIETMP=$(mktemp -p ${TMPDIR} nmwifionice.XXXXXXXXX)
+            trap "rm -f ${COOKIETMP}" EXIT TERM HUP INT QUIT
+            csrftoken=$(${TIMEOUT} ${WGET} -q -O - --keep-session-cookies --save-cookies=${COOKIETMP} --referer ${REFERER} ${LOGIN}  | grep -oP  'CSRFToken"\ value="\K[0-9a-z]+')
+            if [[ -z ${csrftoken} ]]; then
+                echo "CSRFToken is empty"
+                exit 0
+            fi
+            sleep 1
+            ${TIMEOUT} ${WGET} -q -O - --load-cookies=${COOKIETMP} --post-data="login=true&connect=connect&CSRFToken=${csrftoken}" --referer ${REFERER} ${LOGIN} >/dev/null
+        fi
+        ;;
+    *)
+        # We are not interested in this
+        :
+        ;;
+esac
+{% endhighlight %}