Commit c1e77410 authored by nimrod's avatar nimrod
Browse files

Merge branch 'master' of cgit:/srv/git/rcfiles

parents 8f0510bd 41f79440
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -6,9 +6,12 @@
    empty-commit = commit --allow-empty
	exec = "!exec "
    ff = merge --no-edit --ff-only master
    forget = reset --mixed HEAD~1
    forget-hard = reset --hard HEAD~1
    merg = merge --no-edit
    posh = push --set-upstream origin HEAD
    pul = pull --progress
    pull-force = !git fetch && git reset --hard "$(git rev-parse --abbrev-ref --symbolic-full-name @{u})"
    push-force = push --force-with-lease
    root = rev-parse --show-toplevel
    serve-git = !git daemon --reuseaddr --verbose  --base-path=. --export-all ./.git
+52 −5
Original line number Diff line number Diff line
#!/bin/sh
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.
# Requires: cURL, sh, awk, logger.
# 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"
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
    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