From d1ae281249724cd7cad7aa8bd47fc4b5f0614653 Mon Sep 17 00:00:00 2001 From: UTkarsh Date: Mon, 6 Feb 2017 03:52:01 +0530 Subject: [PATCH 1/7] Update readme to include features --- README.md | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 796b8bd..de4f569 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,16 @@ This is a script for logging into the Captive Portal at BITS Goa +## Features -# Usage +- Save your username and password once and login with ease +- Logout if necessary +- Use CLI or App +- Use another username and password temporarily when out of data +- Update from the CLI with single command +- Easy install script + +## Usage Use the installed app from launcher @@ -28,7 +36,7 @@ Use terminal to issue this command: ```bitsnet``` Display help ``` -# How to install +## How to install Fire up a terminal and issue these commands: ``` @@ -43,9 +51,9 @@ cd BitsnetLogin You can now login via terminal (```bitsnet```) or by launching the app -# Author +## Author UTkarsh Maheshwari, **OSDLabs** -# License +## License GPL version 3 From 0f2b16badcfa60d4204625179988ac2b9b2c410e Mon Sep 17 00:00:00 2001 From: UTkarsh Date: Sat, 11 Feb 2017 11:59:29 +0530 Subject: [PATCH 2/7] Check if logged out and connected to bitsnet - The commit is not publish ready. - Need to be tested with Hostel Wifi --- bitsnet | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/bitsnet b/bitsnet index 34dfe16..e86b0b3 100755 --- a/bitsnet +++ b/bitsnet @@ -32,15 +32,37 @@ while getopts "u:p:dhUo" o; do esac done + debug_msg "Username: $username" debug_msg "Password: $password" debug_msg "LoginURL: $login_url" +# Check if using bitsnet +# This is being implemented by sending a spider request to the local LMS server +debug_msg "Checking if connected to bitsnet" +if ! wget -qT 5 -t 1 --spider --no-check-certificate http://photon.bits-goa.ac.in +then + send_msg "Not connected to bitsnet" + exit +else + debug_msg "Connected to bitsnet" +fi + + +# Check if already logged in +debug_msg "Checking if already connected" +if wget -qT 5 -t 1 --spider --no-check-certificate https://google.com +then + send_msg "Already logged into the BITSnet" + exit +fi + + # Check if username or password are empty debug_msg "Checking if username or password is empty" if [[ ("$username" == "") || ("$password" == "") ]]; then - reply="Username or password empty" + send_msg "Username or password empty" debug_msg "Exiting" exit fi @@ -68,13 +90,11 @@ debug_msg "dev = $dev" # Exit if dev = 0 if [[ "$dev" == "0" ]]; then debug_msg "Exiting because dev is zero" + send_msg "Network interface unknown." exit fi -# Check if already logged in - - # Select correct login page according to IP # and load corresponding login_url debug_msg "" From 8cbb4b0647d82730281678dbba4eb1177b42c435 Mon Sep 17 00:00:00 2001 From: UTkarsh Date: Sat, 11 Feb 2017 12:11:30 +0530 Subject: [PATCH 3/7] Add option to force login - Sends request to both pages - No checks are performed --- README.md | 4 +++- bitsnet | 9 ++++++++- util.sh | 10 ++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index de4f569..0cd35eb 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,11 @@ Use terminal to issue this command: ```bitsnet``` -p PASSWORD Specify a different password -o - logout + Logout -d Turn debug on + -f + Force login attempt -U Update program -h diff --git a/bitsnet b/bitsnet index 9089413..b8c5e07 100755 --- a/bitsnet +++ b/bitsnet @@ -8,7 +8,7 @@ source ~/.local/lib/bitsnet/util.sh source ~/.bitsnetrc # Parse arguments -while getopts "u:p:dhUo" o; do +while getopts "u:p:dhUof" o; do case "${o}" in u) username=${OPTARG} @@ -26,11 +26,18 @@ while getopts "u:p:dhUo" o; do o) log_out ;; + f) + f=1 + ;; h | * | [?]) show_help ;; esac done +if [[ "$f" == "1" ]]; then + debug_msg "Forcing login attempt" + force_login +fi debug_msg "Username: $username" diff --git a/util.sh b/util.sh index c6b93b6..6906c54 100644 --- a/util.sh +++ b/util.sh @@ -16,6 +16,8 @@ function show_help { logout -d turn debug on + -f + force login attempt -U update -h @@ -92,3 +94,11 @@ function ldap_login() { reply=$(wget -qO- --no-check-certificate --post-data="mode=191&username=$username&password=$password" $login_url) echo $reply } + +function force_login() { + router_login + reply=$(ldap_login) + reply=$(extract_msg $reply) + send_msg "$reply" + exit +} From 739ebab981d39082ad17e95274ca67b1a62113ae Mon Sep 17 00:00:00 2001 From: UTkarsh Date: Sat, 11 Feb 2017 12:21:51 +0530 Subject: [PATCH 4/7] Add 'captive' and 'portal' keywords --- bitsnet.desktop | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bitsnet.desktop b/bitsnet.desktop index 773b70b..22ed00d 100644 --- a/bitsnet.desktop +++ b/bitsnet.desktop @@ -1,7 +1,7 @@ [Desktop Entry] Name=BITSnet Login Comment=Log into the BITSnet with ease! -Keywords=bitsnet;login;cyberroam +Keywords=bitsnet;login;cyberroam;captive;portal; Exec=bitsnet Icon=network-transmit Terminal=false From b57dad7c4d5dce8c62ea27633cd74fc4bb2f458c Mon Sep 17 00:00:00 2001 From: UTkarsh Date: Sun, 12 Feb 2017 15:15:11 +0530 Subject: [PATCH 5/7] Remove checking connection to bitsnet - The first login form for the wifi (the cisco one), stops from any request from the LMS server. The checking service is at hold for now. --- bitsnet | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/bitsnet b/bitsnet index b8c5e07..50cd6e5 100755 --- a/bitsnet +++ b/bitsnet @@ -45,18 +45,6 @@ debug_msg "Password: $password" debug_msg "LoginURL: $login_url" -# Check if using bitsnet -# This is being implemented by sending a spider request to the local LMS server -debug_msg "Checking if connected to bitsnet" -if ! wget -qT 5 -t 1 --spider --no-check-certificate http://photon.bits-goa.ac.in -then - send_msg "Not connected to bitsnet" - exit -else - debug_msg "Connected to bitsnet" -fi - - # Check if already logged in debug_msg "Checking if already connected" if wget -qT 5 -t 1 --spider --no-check-certificate https://google.com From 443b03cdebbaa973e6698e06b1f22f0b334d1a6b Mon Sep 17 00:00:00 2001 From: UTkarsh Date: Wed, 15 Feb 2017 17:54:46 +0530 Subject: [PATCH 6/7] Dont show password in debugging --- bitsnet | 1 - 1 file changed, 1 deletion(-) diff --git a/bitsnet b/bitsnet index 50cd6e5..de4d6ea 100755 --- a/bitsnet +++ b/bitsnet @@ -41,7 +41,6 @@ fi debug_msg "Username: $username" -debug_msg "Password: $password" debug_msg "LoginURL: $login_url" From d9f95bba5ab71cfb84d9bdc4d0a2499d9d6da015 Mon Sep 17 00:00:00 2001 From: UTkarsh Date: Mon, 20 Feb 2017 12:03:56 +0530 Subject: [PATCH 7/7] Improve device selection and dependency check --- bitsnet | 7 +------ install | 12 +++++++++++- util.sh | 4 ++++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/bitsnet b/bitsnet index de4d6ea..96b3f65 100755 --- a/bitsnet +++ b/bitsnet @@ -1,6 +1,5 @@ #!/bin/bash - # Load util functions source ~/.local/lib/bitsnet/util.sh @@ -77,14 +76,10 @@ if [[ "$dev" == "0" ]]; then fi -# Select correct login page according to IP -# and load corresponding login_url -# Nothing to do here for now - - # Login debug_msg "" debug_msg "Logging in" +# If dev is wifi and IP is not library IP if [[ "$dev" == "2" && "$(hostname -I)" != "10.20"* ]]; then # Log into the router debug_msg "Connected to wifi. Sending request to cisco router form" diff --git a/install b/install index fc8af6e..c648d69 100755 --- a/install +++ b/install @@ -1,10 +1,20 @@ #!/bin/sh -# Check if curl and wget installed +# Check if wget installed if ! which wget > /dev/null ; then echo "wget not installed" exit fi +# Check if git installed for update +if ! which git > /dev/null ; then + echo "git not installed" + exit +fi +# Check if nmcli installed +if ! which nmcli > /dev/null ; then + echo "nmcli not installed" + exit +fi # Copy config file to the right place if ! which bitsnet > /dev/null ; then diff --git a/util.sh b/util.sh index 6906c54..46a96ae 100644 --- a/util.sh +++ b/util.sh @@ -69,6 +69,10 @@ function log_out { function get_device { devInfo="$(nmcli dev | grep " connected" | cut -d " " -f1)" + if [[ $devInfo == "virbr"* ]]; then + # If the connection is through a virtual bridge, select the next device + devInfo=$(echo "$devInfo" | sed 1,1d) + fi; if [[ $devInfo == "en"* ]]; then # ethernet dev=1