diff --git a/README.md b/README.md index 796b8bd..0cd35eb 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 @@ -19,16 +27,18 @@ 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 Display help ``` -# How to install +## How to install Fire up a terminal and issue these commands: ``` @@ -43,9 +53,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 diff --git a/bitsnet b/bitsnet index 55636a6..96b3f65 100755 --- a/bitsnet +++ b/bitsnet @@ -1,6 +1,5 @@ #!/bin/bash - # Load util functions source ~/.local/lib/bitsnet/util.sh @@ -8,7 +7,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,21 +25,37 @@ 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" -debug_msg "Password: $password" debug_msg "LoginURL: $login_url" +# 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 @@ -56,22 +71,15 @@ 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 -# Doesnt matter for now as a request takes lesser time - - -# 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/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 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 c6b93b6..46a96ae 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 @@ -67,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 @@ -92,3 +98,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 +}