Skip to content

Commit

Permalink
Merge pull request #20 from OSDLabs/dev
Browse files Browse the repository at this point in the history
- Install app as a full application
- Make notifications transient
- Fix error in quiet mode
- Fix error with -u and -p options
- Refactor
  • Loading branch information
utkarshme authored Apr 5, 2017
2 parents 72929a5 + ad1954a commit b5fef81
Show file tree
Hide file tree
Showing 6 changed files with 285 additions and 83 deletions.
18 changes: 6 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,22 @@ Use terminal to issue this command: ```bitsnet```
```

## How to install
Fire up a terminal and issue these commands:
- Fire up a terminal and issue these commands:
```
git clone https://github.com/OSDLabs/BitsnetLogin
cd BitsnetLogin
```
- Open the bitsnetrc file and specify your username and password
- Save and close
NOTE: You'll need to use this command if upgrading from version 1.x.x:
```
rm ~/.bitsnetrc
```
- Install the application:
```
./install
```
You can now login via terminal (```bitsnet```) or by launching the app
- You can now login via terminal (`bitsnet`) or by launching the app from launcher
- Run `man bitsnet` or `bitsnet -h` for help

NOTE: You'll need to use this command if upgrading from version 1.x.x: `rm ~/.bitsnetrc`

## Suggestion, comments or complaints
You can add your suggestions, complaints or any bugs you find [here](https://github.com/OSDLabs/BitsnetLogin/issues).

## Author
[UTkarsh Maheshwari](https://github.com/UtkarshMe),
[UTkarsh Maheshwari](https://github.com/UtkarshMe),
**[OSDLabs](https://github.com/OSDLabs)**

## License
Expand Down
110 changes: 95 additions & 15 deletions bitsnet
Original file line number Diff line number Diff line change
@@ -1,19 +1,70 @@
#!/bin/bash

#
# bitsnet
# Script for logging into the bitsnet
#


#
# Load util functions
source ~/.local/lib/bitsnet/util.sh
#
if ! source /usr/lib/bitsnet/util.sh > /dev/null
then
# not found
echo "Could not load util file"
echo "Reinstall program"

notify-send 'BITSnet' "Please reinstall program" \
--icon=network-transmit --hint=int:transient:1
exit 1
fi


#
# Add a configuration file
source ~/.bitsnetrc
#
if ! grep -s "username\[1\]" ~/.bitsnetrc > /dev/null
then
# not found
echo "No bitsnetrc found"

# create a new bitsnetrc file from the sample file
echo -n "Creating a bitsnetrc file... "
if ! cp /etc/bitsnet/bitsnetrc ~/.bitsnetrc
then
echo "failed"
exit 1
else
echo "done"
fi
else
source ~/.bitsnetrc
fi


#
# check if we can find at least one pair of credentials
#
if [[ ${username[1]} == "" ]]
then
echo "Please add credentials to ~/.bitsnetrc"
notify-send 'BITSnet' "Please add credentials to ~/.bitsnetrc" \
--icon=network-transmit --hint=int:transient:1
exit 1
fi


#
# Parse arguments
#
while getopts "u:p:dhUofwq" o; do
case "${o}" in
u)
username=${OPTARG}
username[1]=${OPTARG}
;;
p)
password=${OPTARG}
password[1]=${OPTARG}
;;
d)
debug=1
Expand All @@ -37,59 +88,83 @@ while getopts "u:p:dhUofwq" o; do
;;
h | * | [?])
show_help
exit 1
;;
esac
done


#
# check if login is forced
#
if [[ "$f" == "1" ]]; then
debug_msg "Forcing login attempt"
fi


#
# display login url for debugging
#
debug_msg "LoginURL: $login_url"


# Check if already logged in
#
# Check and exit if already logged in
#
if [[ "$f" != "1" ]]; then
debug_msg "Checking if already connected"
if wget -qT 5 -t 1 --spider --no-check-certificate https://google.com
if wget -qT 5 -t 1 --spider --no-check-certificate https://google.com -O /dev/null
then
send_msg "Already logged into the BITSnet"
exit
exit 0
fi
fi


# Check if using wifi or ethernet
#
# Get device info
#
debug_msg ""
debug_msg "Checking device info"
dev=$(get_device)
debug_msg "dev = $dev"


#
# Exit if dev = 0
#
if [[ "$f" == "0" && "$dev" == "0" ]]; then
debug_msg "Exiting because dev is zero"
send_msg "Network interface unknown."
exit
exit 1
fi


# Log into Cisco Hostel Wifi router if dev = 2
#
# Log into Cisco Hostel Wifi router if dev = 2 and IP is not of library
#
if [[ "$dev" == "2" && "$(hostname -I)" != "10.20"* ]]; then
cisco=1
debug_msg "Connected to hostel wifi"
fi


# Login
#
# Login to the Cisco hostel wifi router
#
debug_msg ""
debug_msg "Logging in"
# If dev is wifi and IP is not library IP
if [[ $cisco == "1" ]]; then
# Log into the router
debug_msg "Connected to wifi. Sending request to cisco router form"
debug_msg "Sending request to cisco router form"
router_login
fi


#
# Log into the ldap
# All ID in the username array from bitsnetrc file are tried
# exit when successful login
#
debug_msg "Logging into the LDAP"
i=1
while [[ ! -z ${username[$i]} ]]
Expand All @@ -100,6 +175,7 @@ do
# Extract reply
reply=$(extract_msg $reply)

# if logged in, get out
if [[ "$reply" == "You have successfully logged in" ]]; then
break
else
Expand All @@ -110,13 +186,17 @@ do
done


#
# Display reply or send a notification
#
debug_msg ""
send_msg "$reply"
debug_msg "Reply sent"


#
# Exit
#
debug_msg ""
debug_msg "Exiting"
exit
exit 0
Binary file added bitsnet.1.gz
Binary file not shown.
23 changes: 16 additions & 7 deletions bitsnetrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#
# This file is for the user configuration
# Set some username and passwords according to you priority
# Uncomment lines to activate
#
# Set some usernames and passwords according to your priority
# eg: if you have 2 IDs with 'ID1' being the most used,
# then write this:
#
Expand All @@ -12,17 +13,25 @@
#
# Use can use UNLIMITED ID and password combinations

username[1]='f2015022'
password[1]='myPass'

username[2]='f2015023'
password[2]='myPass2'

#
# Configure features

# Always force login:
# change to '1' to always use autologin
f=0

# Always use debug mode:
# change to '1' to always use debug mode
debug=0

# Always force login to hostel wifi router:
# change to '1' to always send login request to hostel router
cisco=0

# Quiet mode
# change to '1' to never send notification on login
quiet=0


# Change to custom login url if required
login_url='https://10.1.0.10:8090/httpclient.html'
Loading

0 comments on commit b5fef81

Please sign in to comment.