Skip to content

Commit

Permalink
Merge pull request #15 from OSDLabs/dev
Browse files Browse the repository at this point in the history
Improve device checking and minor changes
  • Loading branch information
utkarshme authored Feb 20, 2017
2 parents 1d983b3 + d9f95bb commit 6e7625c
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 20 deletions.
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
```
Expand All @@ -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
34 changes: 21 additions & 13 deletions bitsnet
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#!/bin/bash


# Load util functions
source ~/.local/lib/bitsnet/util.sh

# Add a configuration file
source ~/.bitsnetrc

# Parse arguments
while getopts "u:p:dhUo" o; do
while getopts "u:p:dhUof" o; do
case "${o}" in
u)
username=${OPTARG}
Expand All @@ -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
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion bitsnet.desktop
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 11 additions & 1 deletion install
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 14 additions & 0 deletions util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ function show_help {
logout
-d
turn debug on
-f
force login attempt
-U
update
-h
Expand Down Expand Up @@ -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
Expand All @@ -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
}

0 comments on commit 6e7625c

Please sign in to comment.