Skip to content
Snippets Groups Projects
Commit 3287f0f4 authored by nimrod's avatar nimrod
Browse files

- Corrected copyright notice.

- Removed debug function, instead debug messages are always sent using
logger directly.
parent 2f395c41
No related branches found
No related tags found
No related merge requests found
#!/bin/sh #!/bin/sh
set -eu
# The MIT License (MIT) # The MIT License (MIT)
# #
# Copyright (c) 2016 Adar Nimrod <nimrod@shore.co.il> # Copyright (c) 2017 Adar Nimrod <nimrod@shore.co.il>
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy # Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal # of this software and associated documentation files (the "Software"), to deal
...@@ -27,15 +26,13 @@ set -eu ...@@ -27,15 +26,13 @@ set -eu
# To install run: # To install run:
# sudo cp --preserve=mode train-wifi.sh /etc/NetworkManager/dispatcher.d/90trainwifi # sudo cp --preserve=mode train-wifi.sh /etc/NetworkManager/dispatcher.d/90trainwifi
set -eu
die () { die () {
echo $@ | logger logger -p user.err $@
exit 1 exit 1
} }
debug () {
[ -n ${DEBUG:+x} ] && echo $@ | logger
}
if [ $# -ne 2 ] if [ $# -ne 2 ]
then then
echo "Usage: $0 interface action" echo "Usage: $0 interface action"
...@@ -52,13 +49,13 @@ which logger > /dev/null || dir "Can't login to the train wifi, logger is not in ...@@ -52,13 +49,13 @@ which logger > /dev/null || dir "Can't login to the train wifi, logger is not in
if [ "$interface" = "ISRAEL-RAILWAYS" ] && [ "$action" = "up" ] if [ "$interface" = "ISRAEL-RAILWAYS" ] && [ "$action" = "up" ]
then then
redirect_url="$(curl --output /dev/null --silent --write-out '%{redirect_url}' http://google.com/)" redirect_url="$(curl --output /dev/null --silent --write-out '%{redirect_url}' http://google.com/)"
debug "Train wifi redirect url: $redirect_url" 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]*')"
debug "Train wifi login IP: $ip" logger -p user.debug "Train wifi login IP: $ip"
login_url="http://$ip/loginHandler.php?allowAccess=true" login_url="http://$ip/loginHandler.php?allowAccess=true"
debug "Train wifi login URL: $login_url" logger -p user.debug "Train wifi login URL: $login_url"
http_code="$(curl --output /dev/null --silent --write-out '%{http_code}' "$login_url")" http_code="$(curl --output /dev/null --silent --write-out '%{http_code}' "$login_url")"
debug "Train wifi login HTTP code: $http_code" logger -p user.debug "Train wifi login HTTP code: $http_code"
else else
debug "Interface isn't ISRAEL-RAILWAYS or action isn't up, not signing in to the train wifi." logger -p user.debug "Interface isn't ISRAEL-RAILWAYS or action isn't up, not signing in to the train wifi."
fi fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment