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

- I may have gone a little overboard with this one.

parent f4c069c8
Branches
No related tags found
No related merge requests found
#!/bin/sh #!/bin/sh
set -eu set -eu
# The MIT License (MIT)
#
# Copyright (c) 2016 Adar Nimrod <nimrod@shore.co.il>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# Logs in to the Israeli train's wifi. # Logs in to the Israeli train's wifi.
# Requires: cURL, sh, awk, logger.
# To install run: # To install run:
# sudo cp --preserve=mode "$HOME/Documents/train-wifi.sh" "/etc/NetworkManager/dispatcher.d/90trainwifi" # sudo cp --preserve=mode train-wifi.sh /etc/NetworkManager/dispatcher.d/90trainwifi
die () {
echo $@ | logger
exit 1
}
debug () {
[ -n ${DEBUG:+x} ] && echo $@ | logger
}
if [ $# -ne 2 ]
then
echo "Usage: $0 interface action"
exit 1
else
interface="$1" interface="$1"
status="$2" action="$2"
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."
if [ "$interface" = "ISRAEL-RAILWAYS" ] && [ "$status" = "up" ] if [ "$interface" = "ISRAEL-RAILWAYS" ] && [ "$action" = "up" ]
then then
curl http://10.5.4.1/loginHandler.php?allowAccess=true redirect_url="$(curl --output /dev/null --silent --write-out '%{redirect_url}' http://google.com/)"
debug "Train wifi redirect url: $redirect_url"
login_url="$(echo "$redirect_url" | awk -F\? '{printf("%s?allowAccess=true", $1)}' )"
debug "Train wifi login url: $login_url"
curl "$login_url"
else
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