From b68aa56ab554c206c92c99fdc553a3638ae293d5 Mon Sep 17 00:00:00 2001
From: Adar Nimrod <nimrod@shore.co.il>
Date: Tue, 7 Mar 2017 08:20:24 +0200
Subject: [PATCH] - Correct finding of login URL.

---
 Documents/train-wifi.sh | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/Documents/train-wifi.sh b/Documents/train-wifi.sh
index 51130b3..b19bf6a 100755
--- a/Documents/train-wifi.sh
+++ b/Documents/train-wifi.sh
@@ -53,9 +53,12 @@ if [ "$interface" = "ISRAEL-RAILWAYS" ] && [ "$action" = "up" ]
 then
     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"
+    login_ip="$(echo "$redirect_url" | grep --only-matching '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*')"
+    debug "Train wifi login IP: $ip"
+    login_url="http://$ip/loginHandler.php?allowAccess=true"
+    debug "Train wifi login URL: $login_url"
+    http_code="$(curl --output /dev/null --silent --write-out '%{http_code}' "$login_url")"
+    debug "Train wifi login HTTP code: $http_code"
 else
     debug "Interface isn't ISRAEL-RAILWAYS or action isn't up, not signing in to the train wifi."
 fi
-- 
GitLab