Living in Denmark, on the opposite side of Jutland to my partner, I travel on DSB trains relatively often. Something that has mildly annoyed me for a while has been the captive portal login that DSB’s WiFi insists on using. I’ve found it even more annoying since switching to LibreWolf as I haven’t been able to get captive portal detection working with it, meaning I have to briefly open Firefox just to log in to the network.
I decided to automate the process. The following script,
/etc/NetworkManager/dispatcher.d/dsb-login, runs whenever a
NetworkManager event occurs. It checks if the event was for the correct
interface being brought up, and whether the SSID matches DSB’s onboard
WiFi. At first I thought a POST request to
https://dsbwifi.dk/login.php would do it, but it appears
that you need to first be redirected to the captive portal login page
before that POST request actually does anything.
#!/bin/bash
iface=$1
event=$2
if [[ "$iface" != "wlan0" || "$event" != "up" ]]; then
exit 0
fi
ssid=$(iw wlan0 info | grep ssid | cut -d' ' -f 2)
if [[ "$ssid" = ".DSB_Wi-Fi" ]]; then
curl -L http://neverssl.com
curl -L -X POST https://dsbwifi.dk/login.php
fiI’ve tested the script a couple of times now, randomizing my MAC address every time, and it appears to be working reliably.