Skip to content

Commit ca5d795

Browse files
authored
Merge pull request #17 from OSDLabs/dev
Allow using multiple accounts! Fix #14
2 parents 7ced490 + 9fd095b commit ca5d795

4 files changed

Lines changed: 64 additions & 38 deletions

File tree

bitsnet

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,21 @@ while getopts "u:p:dhUof" o; do
3535
done
3636
if [[ "$f" == "1" ]]; then
3737
debug_msg "Forcing login attempt"
38-
force_login
3938
fi
4039

4140

42-
debug_msg "Username: $username"
4341
debug_msg "LoginURL: $login_url"
4442

4543

4644
# Check if already logged in
47-
debug_msg "Checking if already connected"
48-
if wget -qT 5 -t 1 --spider --no-check-certificate https://google.com
49-
then
50-
send_msg "Already logged into the BITSnet"
51-
exit
52-
fi
53-
54-
55-
# Check if username or password are empty
56-
debug_msg "Checking if username or password is empty"
57-
if [[ ("$username" == "") || ("$password" == "") ]]; then
58-
send_msg "Username or password empty"
59-
debug_msg "Exiting"
60-
exit
45+
if [[ "$f" != "1" ]]; then
46+
debug_msg "Checking if already connected"
47+
if wget -qT 5 -t 1 --spider --no-check-certificate https://google.com
48+
then
49+
send_msg "Already logged into the BITSnet"
50+
exit
51+
fi
6152
fi
62-
debug_msg "Not empty"
6353

6454

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

7161
# Exit if dev = 0
72-
if [[ "$dev" == "0" ]]; then
62+
if [[ "$f" == "0" && "$dev" == "0" ]]; then
7363
debug_msg "Exiting because dev is zero"
7464
send_msg "Network interface unknown."
7565
exit
@@ -85,14 +75,26 @@ if [[ "$dev" == "2" && "$(hostname -I)" != "10.20"* ]]; then
8575
debug_msg "Connected to wifi. Sending request to cisco router form"
8676
router_login
8777
fi
78+
8879
# Log into the ldap
8980
debug_msg "Logging into the LDAP"
90-
reply=$(ldap_login)
81+
i=1
82+
while [[ ! -z ${username[$i]} ]]
83+
do
84+
debug_msg "Trying with ID: ${username[$i]}"
85+
reply=$(ldap_login ${username[$i]} ${password[$i]})
86+
87+
# Extract reply
88+
reply=$(extract_msg $reply)
89+
90+
if [[ "$reply" == "You have successfully logged in" ]]; then
91+
break
92+
else
93+
debug_msg "$reply"
94+
fi
95+
((i++))
9196

92-
93-
# Extract reply
94-
debug_msg "Extracting reply"
95-
reply=$(extract_msg $reply)
97+
done
9698

9799

98100
# Display reply or send a notification

bitsnetrc

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
1-
# Set defaults here
2-
username='f2015022'
3-
password='myPass'
1+
#
2+
# This file is for the user configuration
3+
# Set some username and passwords according to you priority
4+
#
5+
# eg: if you have 2 IDs with 'ID1' being the most used,
6+
# then write this:
7+
#
8+
# username[1]='ID1'
9+
# password[1]='ID1_password'
10+
# username[2]='ID2'
11+
# password[2]='ID2_password'
12+
#
13+
# Use can use UNLIMITED ID and password combinations
14+
15+
username[1]='f2015022'
16+
password[1]='myPass'
17+
18+
username[2]='f2015023'
19+
password[2]='myPass2'
20+
21+
#
22+
# Configure features
23+
24+
# Always force login:
25+
# change to '1' to always use autologin
26+
f=0
27+
428
login_url='https://10.1.0.10:8090/httpclient.html'

install

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,49 @@
11
#!/bin/sh
22

3+
echo "Installing BITSnet Login"
4+
35
# Check if wget installed
6+
echo "Checking if wget installed"
47
if ! which wget > /dev/null ; then
58
echo "wget not installed"
69
exit
710
fi
811
# Check if git installed for update
12+
echo "Checking if git installed"
913
if ! which git > /dev/null ; then
1014
echo "git not installed"
1115
exit
1216
fi
1317
# Check if nmcli installed
18+
echo "Checking if nmcli installed"
1419
if ! which nmcli > /dev/null ; then
1520
echo "nmcli not installed"
1621
exit
1722
fi
1823

1924
# Copy config file to the right place
20-
if ! ls -a ~ | grep .bitsnetrc > /dev/null ; then
25+
if ! ls -a ~ | grep -x ".bitsnetrc" --quiet ; then
26+
echo "Copying bitsnetrc"
2127
cp ./bitsnetrc ~/.bitsnetrc
2228
fi
2329

2430
# Copy the script to executables
2531
if [ ! -d ~/.local/lib/bitsnet ]; then
2632
mkdir ~/.local/lib/bitsnet
2733
fi
34+
echo "Copying script"
2835
cp ./util.sh ~/.local/lib/bitsnet/util.sh
2936
cp ./bitsnet ~/.local/bin/bitsnet
3037

3138
# Create a desktop file
39+
echo "Creating app launcher"
3240
cp ./bitsnet.desktop ~/.local/share/applications/bitsnet.desktop
3341

3442
# Set to autostart
43+
echo "Setting up autologin"
3544
if [ ! -d ~/.config/autostart ]; then
3645
mkdir -p ~/.config/autostart
3746
fi
3847
ln -sf ~/.local/share/applications/bitsnet.desktop ~/.config/autostart/bitsnet.desktop
3948

40-
# Create a man page
41-
# To Be Done
49+
# TODO: Create a man page

util.sh

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,6 @@ function router_login() {
9999
}
100100

101101
function ldap_login() {
102-
reply=$(wget -qO- --no-check-certificate --post-data="mode=191&username=$username&password=$password" $login_url)
102+
reply=$(wget -qO- --no-check-certificate --post-data="mode=191&username=$1&password=$2" $login_url)
103103
echo $reply
104104
}
105-
106-
function force_login() {
107-
router_login
108-
reply=$(ldap_login)
109-
reply=$(extract_msg $reply)
110-
send_msg "$reply"
111-
exit
112-
}

0 commit comments

Comments
 (0)