From 5c20c18c5b2b88ac747c1fd721c53c8bf0e3ae1e Mon Sep 17 00:00:00 2001 From: UTkarsh Date: Mon, 6 Feb 2017 03:16:47 +0530 Subject: [PATCH 1/2] Reduce dependencies - Remove curl as a dependency - Only wget required --- bitsnet | 2 +- install | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/bitsnet b/bitsnet index b433630..540d4f5 100755 --- a/bitsnet +++ b/bitsnet @@ -86,7 +86,7 @@ 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" diff --git a/install b/install index dbde764..fc8af6e 100755 --- a/install +++ b/install @@ -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 From e41857bef655619b7b911717a28d6eb1b32ea2b6 Mon Sep 17 00:00:00 2001 From: UTkarsh Date: Mon, 6 Feb 2017 03:34:08 +0530 Subject: [PATCH 2/2] Add option to logout --- README.md | 2 ++ bitsnet | 8 +++++--- util.sh | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8939881..796b8bd 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/bitsnet b/bitsnet index 540d4f5..34dfe16 100755 --- a/bitsnet +++ b/bitsnet @@ -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} @@ -23,6 +23,9 @@ while getopts "u:p:dhU" o; do U) update ;; + o) + logOut + ;; h | * | [?]) show_help ;; @@ -90,8 +93,7 @@ reply=$(wget -qO- --no-check-certificate --post-data="mode=191&username=$usernam # Extract reply debug_msg "Extracting reply" -reply="${reply##*\<\![CDATA[}" -reply=$(echo "$reply" | cut -d']' -f1) +reply=$(extract_msg $reply) # Display reply or send a notification diff --git a/util.sh b/util.sh index fa3674a..3cc0516 100644 --- a/util.sh +++ b/util.sh @@ -12,6 +12,8 @@ function show_help { use specific username -p PASSWORD specify a different password + -o + logout -d turn debug on -U @@ -27,6 +29,12 @@ function debug_msg { fi } +function extract_msg { + reply="${reply##*\<\![CDATA[}" + reply=$(echo "$reply" | cut -d']' -f1) + echo $reply +} + function send_msg { if [[ debug -eq 0 ]]; then notify-send 'BITSnet' "$1" --icon=network-transmit @@ -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 +}