Skip to content

Commit

Permalink
Implement option to use multiple accounts
Browse files Browse the repository at this point in the history
- Fix #14
- Make configuration file user-friendly
  • Loading branch information
coditva committed Feb 21, 2017
1 parent 172f469 commit eeff23d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 35 deletions.
48 changes: 25 additions & 23 deletions bitsnet
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,21 @@ while getopts "u:p:dhUof" o; do
done
if [[ "$f" == "1" ]]; then
debug_msg "Forcing login attempt"
force_login
fi


debug_msg "Username: $username"
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
send_msg "Username or password empty"
debug_msg "Exiting"
exit
if [[ "$f" != "1" ]]; then
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
fi
debug_msg "Not empty"


# Check if using wifi or ethernet
Expand All @@ -69,7 +59,7 @@ dev=$(get_device)
debug_msg "dev = $dev"

# Exit if dev = 0
if [[ "$dev" == "0" ]]; then
if [[ "$f" == "0" && "$dev" == "0" ]]; then
debug_msg "Exiting because dev is zero"
send_msg "Network interface unknown."
exit
Expand All @@ -85,14 +75,26 @@ if [[ "$dev" == "2" && "$(hostname -I)" != "10.20"* ]]; then
debug_msg "Connected to wifi. Sending request to cisco router form"
router_login
fi

# Log into the ldap
debug_msg "Logging into the LDAP"
reply=$(ldap_login)
i=1
while [[ ! -z ${username[$i]} ]]
do
debug_msg "Trying with ID: ${username[$i]}"
reply=$(ldap_login ${username[$i]} ${password[$i]})

# Extract reply
reply=$(extract_msg $reply)

if [[ "$reply" == "You have successfully logged in" ]]; then
break
else
debug_msg "$reply"
fi
((i++))


# Extract reply
debug_msg "Extracting reply"
reply=$(extract_msg $reply)
done


# Display reply or send a notification
Expand Down
30 changes: 27 additions & 3 deletions bitsnetrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
# Set defaults here
username='f2015022'
password='myPass'
#
# This file is for the user configuration
# Set some username and passwords according to you priority
#
# eg: if you have 2 IDs with 'ID1' being the most used,
# then write this:
#
# username[1]='ID1'
# password[1]='ID1_password'
# username[2]='ID2'
# password[2]='ID2_password'
#
# 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

login_url='https://10.1.0.10:8090/httpclient.html'
10 changes: 1 addition & 9 deletions util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,6 @@ function router_login() {
}

function ldap_login() {
reply=$(wget -qO- --no-check-certificate --post-data="mode=191&username=$username&password=$password" $login_url)
reply=$(wget -qO- --no-check-certificate --post-data="mode=191&username=$1&password=$2" $login_url)
echo $reply
}

function force_login() {
router_login
reply=$(ldap_login)
reply=$(extract_msg $reply)
send_msg "$reply"
exit
}

0 comments on commit eeff23d

Please sign in to comment.