-
Notifications
You must be signed in to change notification settings - Fork 0
/
alliance_connector.sh
executable file
·51 lines (45 loc) · 1.65 KB
/
alliance_connector.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
if [ ! -f config.cfg ]; then
echo "Config file not found! Please make sure you have copied 'config.cfg.template' into 'config.cfg' and filled your user credentials."
exit
fi
source config.cfg
# Check if Curl or Wget is available
if [[ $(which curl | which wget) ]]
then
if [[ $(which wget) ]]
then
# Using wget
LOGIN_CHECK="wget -qO- \"http://$ALLIANCE_IP/0/wl/cklogin\""
LOGIN="wget --user-agent=Mozilla/5.0 --post-data \"login=1&user=$ALLIANCE_USER&pass=$ALLIANCE_PASS\" -q --no-check-certificate \"http://$ALLIANCE_IP/0/wl/\""
LOGOUT="wget --user-agent=Mozilla/5.0 --post-data \"logout=Click+here+to+logout\" -q --no-check-certificate \"http://$ALLIANCE_IP/0/up/\""
else
# Using curl
LOGIN_CHECK="curl -s \"http://$ALLIANCE_IP/0/wl/cklogin\""
LOGIN="curl --data \"login=1&user=$ALLIANCE_USER&pass=$ALLIANCE_PASS\" \"http://$ALLIANCE_IP/0/wl/\""
LOGOUT="curl --data \"logout=Click+here+to+logout\" \"http://$ALLIANCE_IP/0/up/\""
fi
else
echo "Cannot find wget or curl. Please install one of them."
exit
fi
echo "Checking login status..."
if [[ $(eval $LOGIN_CHECK) == "yes" ]]
then
echo "You are already logged in."
if [[ "$(ping -c 1 -t 5 8.8.8.8 | grep '100% packet loss' )" != "" ]]; then
echo "Internet isn't present, logging you out"
eval $LOGOUT
else
echo "Internet is present"
exit 1
fi
fi
echo "Trying to login..."
eval $LOGIN
if [[ $(eval $LOGIN_CHECK) == "yes" ]]
then
echo "Login successful."
else
echo "Couldn't login. Please check your user details in config.cfg file or your network connection."
fi