This is a story of how Linux has once again improved my life just a little. I recently started commuting on Utah’s Frontrunner Train. It’s a wonderful service. The train includes tables, power outlets, even bathrooms. Most importantly, there’s onboard wifi which makes it perfect for working while I’m on my way in. Every day however I would have to accept some terms and conditions on the network’s captive portal. In about 5 minutes I was able to come up with a little hack to never have to launch a browser and click that button again.
First, I launched the Chrome dev tools and watched the network tab to see what needs to be sent to the train’s router to allow access. After hitting submit I saw it:
(Insert screenshot here)
After that I used the extremely handy “copy as cURL” command and ran it in my terminal
(Insert screenshot here)
It works! Now for the important part: A NetworkManager dispatcher script. Dispatcher will automatically run scripts when you connect to a network. With some trial and error I was able to write a script that checks if I’ve connected to the train’s wifi, wait until it hears a response from the portal, then sends the login curl command. Now every day I can just sit down, open my laptop, and get to work.
#!/bin/bash
# Make sure the scipt is only ran on the proper network
# Run nmcli con show to get the UUID
UTA_UUID="1156e2e5-e242-4e4b-9186-5f53f90c4815"
ACTIVE_UUID=$(nmcli -t -f UUID,TYPE conn show --active | grep wireless | cut -d':' -f1)
if [[ "$ACTIVE_UUID" == "$UTA_UUID" ]]; then
# Hold off until the portal is actually responding to us
wget -q --tries=10 uta.mobilitie.com -O /dev/null
# If was successful then send the curl we grabbed earlier
# I was able to strip most flags from the copied curl command
if [[ $? -eq 0 ]]; then
curl 'https://uta.mobilitie.com/login' \
--data-raw 'username=8c-c8-4b-7f-f6-09&password=mac123&dst=https%3a%2f%2frideuta.com' \
--compressed \
-o /dev/null \
-s
echo "Successfully connected"
else
echo "Connection failed"
fi
fi