Skip to content
Snippets Groups Projects
Commit 22b9a344 authored by nimrod's avatar nimrod
Browse files

- The interface is passed, not the connection.

parent 6d69bd54
No related branches found
No related tags found
No related merge requests found
......@@ -22,7 +22,7 @@
# SOFTWARE.
# Logs in to the Israeli train's wifi.
# Requires: cURL, sh, awk, logger.
# Requires: cURL, sh, awk, logger, nmcli.
# To install run:
# sudo cp --preserve=mode train-wifi.sh /etc/NetworkManager/dispatcher.d/90trainwifi
......@@ -33,6 +33,15 @@ die () {
exit 1
}
iswifi () {
# TODO: Check if a network interface is passed.
[ "$(nmcli --terse --fields GENERAL.TYPE device show $1 | awk -F: '{print $2}')" = 'wifi' ]
}
wifi_connection () {
nmcli --terse --fields GENERAL.CONNECTION device show $1 | awk -F: '{print $2}'
}
if [ $# -ne 2 ]
then
echo "Usage: $0 interface action"
......@@ -44,18 +53,19 @@ fi
which curl > /dev/null || die "Can't login to the train wifi, cURL is not installed."
which awk > /dev/null || die "Can't login to the train wifi, awk is not installed."
which logger > /dev/null || dir "Can't login to the train wifi, logger is not installed."
which logger > /dev/null || die "Can't login to the train wifi, logger is not installed."
which nmcli > /dev/null || die "Can't login to the train wifi, nmcli is not installed."
[ "$action" = 'up' ] || die "Can't login to the train wifi, action $action isn't up."
iswifi "$interface" || die "Can't login to the train wifi, interface $interface isn't wifi."
connection="$(wifi_connection $interface)"
[ "$connection" = "ISRAEL-RAILWAYS" ] || die "Can't login to the train wifi, wifi network $connection isn't ISRAEL-RAILWAYS."
if [ "$interface" = "ISRAEL-RAILWAYS" ] && [ "$action" = "up" ]
then
redirect_url="$(curl --output /dev/null --silent --write-out '%{redirect_url}' http://google.com/)"
logger -p user.debug "Train wifi redirect url: $redirect_url"
login_ip="$(echo "$redirect_url" | grep --only-matching '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*')"
login_ip="$(echo "$redirect_url" | grep --only-matching '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*')" || die "Can't login to the train wifi, redirect URL doesn't contain an IP."
logger -p user.debug "Train wifi login IP: $ip"
login_url="http://$ip/loginHandler.php?allowAccess=true"
logger -p user.debug "Train wifi login URL: $login_url"
http_code="$(curl --output /dev/null --silent --write-out '%{http_code}' "$login_url")"
logger -p user.debug "Train wifi login HTTP code: $http_code"
else
logger -p user.debug "Interface isn't ISRAEL-RAILWAYS or action isn't up, not signing in to the train wifi."
fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment