Skip to content

Commit

Permalink
Merge pull request #13 from OSDLabs/dev
Browse files Browse the repository at this point in the history
Add option to logout
  • Loading branch information
utkarshme authored Feb 5, 2017
2 parents 3088bea + e41857b commit 30c89a3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Use terminal to issue this command: ```bitsnet```
Use specific username
-p PASSWORD
Specify a different password
-o
logout
-d
Turn debug on
-U
Expand Down
10 changes: 6 additions & 4 deletions bitsnet
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ source ~/.local/lib/bitsnet/util.sh
source ~/.bitsnetrc

# Parse arguments
while getopts "u:p:dhU" o; do
while getopts "u:p:dhUo" o; do
case "${o}" in
u)
username=${OPTARG}
Expand All @@ -23,6 +23,9 @@ while getopts "u:p:dhU" o; do
U)
update
;;
o)
logOut
;;
h | * | [?])
show_help
;;
Expand Down Expand Up @@ -86,12 +89,11 @@ if [[ "$dev" == "2" ]]; then
debug_msg "Connected to wifi. Sending request to cisco router form"
wget --post-data="username=$username&password=$password&loginAccept=1&buttonClicked=4&err_flag=0&info_flag=0&Submit=Submit&err_msg=&info_msg=&redirect_url=" https://20.20.2.11/login.html --no-check-certificate --quiet -O /dev/null
fi
reply=$(curl -ks -d "mode=191&username=$username&password=$password" $login_url)
reply=$(wget -qO- --no-check-certificate --post-data="mode=191&username=$username&password=$password" $login_url)

# Extract reply
debug_msg "Extracting reply"
reply="${reply##*\<message><\![CDATA[}"
reply=$(echo "$reply" | cut -d']' -f1)
reply=$(extract_msg $reply)


# Display reply or send a notification
Expand Down
5 changes: 3 additions & 2 deletions install
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/bin/sh

# Check if curl and wget installed
if ! which wget > /dev/null && which curl > /dev/null ; then
echo "wget or curl not installed $0"
if ! which wget > /dev/null ; then
echo "wget not installed"
exit
fi

# Copy config file to the right place
Expand Down
15 changes: 15 additions & 0 deletions util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ function show_help {
use specific username
-p PASSWORD
specify a different password
-o
logout
-d
turn debug on
-U
Expand All @@ -27,6 +29,12 @@ function debug_msg {
fi
}

function extract_msg {
reply="${reply##*\<message><\![CDATA[}"
reply=$(echo "$reply" | cut -d']' -f1)
echo $reply
}

function send_msg {
if [[ debug -eq 0 ]]; then
notify-send 'BITSnet' "$1" --icon=network-transmit
Expand All @@ -49,3 +57,10 @@ function update {
debug_msg "Exiting"
exit
}

function logOut() {
reply=$(wget -qO- --no-check-certificate --post-data="mode=193&username=$username&submit=Logout" $login_url)
reply=$(extract_msg $reply)
send_msg "$reply"
exit
}

0 comments on commit 30c89a3

Please sign in to comment.