Created
March 4, 2022 18:11
-
-
Save XFY9326/44f83c0d8414d1096c767a639bc36aef to your computer and use it in GitHub Desktop.
'MeetInLeeds' Wi-Fi login script for 'University of Leeds'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
usage() { | |
if [ $1 == 1 ]; then | |
echo "MeetInLeeds Wi-Fi Login" | |
echo "Author: XFY9326" | |
echo "Website: https://xfy9326.github.io" | |
echo "" | |
fi | |
echo "Options:" | |
echo "-u\t\tUser name (Not full email address)" | |
echo "-p\t\tUser password" | |
} | |
while getopts u:p::h options; do | |
case "${options}" in | |
u) USER_NAME=${OPTARG};; | |
p) USER_PASSWORD=${OPTARG};; | |
h) usage 1; exit 0;; | |
\?) usage 0; exit 1;; | |
esac | |
done | |
if [ $OPTIND == 1 ]; then | |
usage 1 | |
exit 0 | |
fi | |
if [ "$USER_NAME" == "" ]; then | |
echo "Missing username!" | |
exit 2 | |
fi | |
if [ "$USER_PASSWORD" == "" ]; then | |
echo "Missing password!" | |
exit 3 | |
fi | |
echo "User: $USER_NAME" | |
USER_EMAIL="$USER_NAME%40leeds.ac.uk" | |
LOGIN_HOST="uolwrd.leeds.ac.uk" | |
CAPTIVE_PORTAL_REDIRECT="captive.apple.com" | |
LOGIN_SUCCESS_STR="login_success_noContent.html" | |
ALREADY_LOGIN_STR="wlan=MeetInLeeds&statusCode=1" | |
if curl --output /dev/null --head --insecure -s "$LOGIN_HOST"; then | |
echo "Start Login ... ..." | |
else | |
echo "Can't find login server!" | |
exit 5 | |
fi | |
LOGIN_RESULT=$(curl --insecure -s "https://$LOGIN_HOST/login.html" --data-raw "username=$USER_EMAIL&password=$USER_PASSWORD&buttonClicked=4&redirect_url=$CAPTIVE_PORTAL_REDIRECT&err_flag=0&info_flag=0&info_msg=0") | |
RESULT_SUCCESS=$(echo "$LOGIN_RESULT"|grep $LOGIN_SUCCESS_STR) | |
RESULT_ALREADY_LOGIN=$(echo "$LOGIN_RESULT"|grep $ALREADY_LOGIN_STR) | |
if [ "${RESULT_SUCCESS}"x != ""x ] ; then | |
echo "MeetInLeeds login success!" | |
exit 0 | |
elif [ "${RESULT_ALREADY_LOGIN}"x != ""x ] ; then | |
echo "MeetInLeeds already Login!" | |
exit 9 | |
else | |
echo "MeetInLeeds login failed!" | |
exit 10 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment