Browse Source

Even more code changes to handle which interface we're using. Currently restricted to nmcli, but will add other control methods later.

master
Sean Todd 4 years ago
parent
commit
11cad7f40e
  1. 83
      BT_KeepAlive/Beta_KeepAlive.sh

83
BT_KeepAlive/Beta_KeepAlive.sh

@ -1,12 +1,18 @@
#!/bin/bash
#Identifies OS
if [ $# -eq 0 ]; then
ARG=false
else
NetInterface=$1
fi
#Identifies OS and installed programs
YUM_CMD=$(command -v yum)
APT_GET_CMD=$(command -v apt-get)
NM_AVAILABLE=$(command -v nmcli)
#OTHER_CMD=$(command -v <other installer>)
# Other Variables
ip=173.194.34.132 # google.com
essid=BTOpenzone
#All of the individual functions are up here!
@ -15,40 +21,30 @@ essid=BTOpenzone
ConnectifyMe(){
# Ping is 3 packets, Grep looks for total failure. This is to give BT some leeway for having shitty ping.
if ping -c 3 $ip | grep '100% packet loss\|Network is unreachable'
then
# Ping is 8 packets, Grep looks for total failure. This is to give BT some leeway for having shitty ping.
if ping -c 8 8.8.8.8 | grep '100% packet loss\|Network is unreachable'
then
echo "$(date "+%Y-%m-%d %H:%M:%S:") Connection down"
if iwconfig | grep "BTOpenzone"
then
curl 'https://www.btopenzone.com:8443/ante' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-gb,en;q=0.5' -H 'Connection: keep-alive' -H 'Cookie: JSESSIONID=716ri2hfsar64; __utma=171794931.404001753.1385254451.1385254451.1385254451.1; __utmb=171794931.3.10.1385254451; __utmc=171794931; __utmz=171794931.1385254451.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); s_cc=true; s_sq=%5B%5BB%5D%5D' -H 'Host: www.btopenzone.com:8443' -H 'Referer: https://www.btopenzone.com:8443/wpb' -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:25.0) Gecko/20100101 Firefox/25.0' -H 'Content-Type: application/x-www-form-urlencoded' --data "username=$username&password=$password&x=0&y=0&xhtmlLogon=https%3A%2F%2Fwww.btopenzone.com%3A8443%2Fante" > /dev/null
else
echo "Restarting Network Service"
#sudo nmcli nm enable false
#sudo nmcli nm enable true
nmcli nm wifi off
nmcli nm wifi on
# Disconnect onboard WLAN if my USB is plugged in.
nmcli dev disconnect iface wlan0
echo "Connecting to Access Point"
#nmcli dev wifi connect $essid
nmcli dev wifi connect $essid iface wlan1
fi
if [[ ! -z $NM_AVAILABLE ]]; then
if nmcli | grep "BTOpenzone"
then
curl 'https://www.btopenzone.com:8443/ante' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-gb,en;q=0.5' -H 'Connection: keep-alive' -H 'Cookie: JSESSIONID=716ri2hfsar64; __utma=171794931.404001753.1385254451.1385254451.1385254451.1; __utmb=171794931.3.10.1385254451; __utmc=171794931; __utmz=171794931.1385254451.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); s_cc=true; s_sq=%5B%5BB%5D%5D' -H 'Host: www.btopenzone.com:8443' -H 'Referer: https://www.btopenzone.com:8443/wpb' -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:25.0) Gecko/20100101 Firefox/25.0' -H 'Content-Type: application/x-www-form-urlencoded' --data "username=$username&password=$password&x=0&y=0&xhtmlLogon=https%3A%2F%2Fwww.btopenzone.com%3A8443%2Fante" > /dev/null
else
# Disconnect onboard WLAN if my USB is plugged in.
nmcli dev disconnect iface wlan{0..20} > /dev/null 2>&1
echo "Connecting to Access Point"
nmcli dev wifi connect $essid ifname $NetInterface
fi
else
:
fi
else
echo "$(date "+%Y-%m-%d %H:%M:%S:") Online"
sleep 3
else
echo "$(date "+%Y-%m-%d %H:%M:%S:") Online"
sleep 3
fi
fi
}
#<-------------------------------------------------------------------------------->#
@ -98,23 +94,27 @@ DecryptCheck
. ./userdata.dat #Read the settings file
username=$BTUsername #Put the settings
password=$BTPassword #In the scripts memory
NetInterface=$Interface
rm -f userdata.dat
done
}
#<-------------------------------------------------------------------------------->#
ConfigureMe(){
echo "There is no configuration file present. Obtaining necessary data now."
echo "Please enter the username used to log in to OpenZone."
read -p "(Replace the email address @ with %40): " NewUsername
if [ "$ARG" = false ]; then
read -p "Please enter the interface you would like to use: " NetInterface
fi
read -p "Please enter the username used to log in to OpenZone: " NewUsername
clear
read -sp "Please enter the password used to log in to OpenZone: " NewPassword
echo ""
echo "BTUsername="$NewUsername >> userdata.dat
echo "BTPassword="$NewPassword >> userdata.dat
echo "Interface="$NetInterface >> userdata.dat
. ./userdata.dat
username=$BTUsername
password=$BTPassword
NetInterface=$Interface
echo ""
}
#<-------------------------------------------------------------------------------->#
@ -146,7 +146,7 @@ dep-install(){
if [[ ! -z $YUM_CMD ]]; then
sudo yum -y install $PACKAGE > /dev/null
elif [[ ! -z $APT_GET_CMD ]]; then
sudo apt-get --yes --force-yes install curl $PACKAGE > /dev/null
sudo apt-get -y install curl $PACKAGE > /dev/null
# elif [[ ! -z $OTHER_CMD ]]; then
# $OTHER_CMD <proper arguments>
else
@ -157,8 +157,9 @@ dep-install(){
#<-------------------------------------------------------------------------------->#
#Dependency Check
dependson(){
if [hash $program 2>/dev/null]; then
:
program=$1
if [ -x "$(command -v $program)" ]; then
echo "$program is already installed!"
else
dep-install $1
fi
@ -169,9 +170,8 @@ if [hash $program 2>/dev/null]; then
dependson curl
dependson openssl
ConfigCheck
clear
#clear
# Our connectivity Loop
while [ 1 ]; do
@ -181,4 +181,3 @@ done
#<-------------------------------------------------------------------------------->#

Loading…
Cancel
Save