Skip to content

Commit

Permalink
Shift everything to util instead of main script
Browse files Browse the repository at this point in the history
  • Loading branch information
coditva committed Feb 10, 2017
1 parent 30c89a3 commit 1d983b3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 21 deletions.
31 changes: 11 additions & 20 deletions bitsnet
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ while getopts "u:p:dhUo" o; do
update
;;
o)
logOut
log_out
;;
h | * | [?])
show_help
Expand All @@ -48,23 +48,11 @@ debug_msg "Not empty"


# Check if using wifi or ethernet
devInfo="$(nmcli dev | grep " connected" | cut -d " " -f1)"
debug_msg ""
debug_msg "Checking device info"
debug_msg "devInfo = $devInfo"
if [[ $devInfo == "en"* ]]; then
# ethernet
dev=1
elif [[ $devInfo == "wl"* ]]; then
# wifi
dev=2
else
# unknown
dev=0
fi
dev=$(get_device)
debug_msg "dev = $dev"


# Exit if dev = 0
if [[ "$dev" == "0" ]]; then
debug_msg "Exiting because dev is zero"
Expand All @@ -73,23 +61,26 @@ fi


# Check if already logged in
# Doesnt matter for now as a request takes lesser time


# Select correct login page according to IP
# and load corresponding login_url
debug_msg ""
debug_msg "Selecting login url"
debug_msg "Using url: $login_url"
# Nothing to do here for now


# Login
debug_msg ""
debug_msg "Logging in"
if [[ "$dev" == "2" ]]; then
if [[ "$dev" == "2" && "$(hostname -I)" != "10.20"* ]]; then
# Log into the router
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
router_login
fi
reply=$(wget -qO- --no-check-certificate --post-data="mode=191&username=$username&password=$password" $login_url)
# Log into the ldap
debug_msg "Logging into the LDAP"
reply=$(ldap_login)


# Extract reply
debug_msg "Extracting reply"
Expand Down
30 changes: 29 additions & 1 deletion util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,37 @@ function update {
exit
}

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

function get_device {
devInfo="$(nmcli dev | grep " connected" | cut -d " " -f1)"
if [[ $devInfo == "en"* ]]; then
# ethernet
dev=1
elif [[ $devInfo == "wl"* ]]; then
# wifi
dev=2
elif [[ $devInfo == "virbr"* ]]; then
# virtual bridge
dev=3
else
# unknown
dev=0
fi

echo "$dev"
}

function router_login() {
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
}

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

0 comments on commit 1d983b3

Please sign in to comment.