Last active
February 5, 2023 14:29
-
-
Save cubercsl/c23b30a7ac800e051643357630761ca5 to your computer and use it in GitHub Desktop.
ECNU Connect Internet CLI
This file contains hidden or 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/bash | |
# Connect ECNU Internet via command line | |
# Author: cubercsl <2014cais01 at gmail dot com> | |
# Licensed under Do What The F*ck You Want To Public License (WTFPL) | |
set -eo pipefail | |
usage() { | |
echo "connect-internet [-f file | username [password]]" | |
exit 1 | |
} | |
[ $# -ge 3 ] && usage | |
if [[ "$1" == "-f" ]]; then | |
if [ -f "$2" ] && [ -r "$2" ]; then | |
. $2 | |
password=$(echo $password | base64 -d) | |
else | |
usage | |
fi | |
else | |
username=${1:-$ECNU_USERNAME} | |
# not recommanded | |
password=${2:-$ECNU_PASSWORD} | |
fi | |
[[ "$username" == "" ]] && read -p 'Username: ' username | |
[[ "$password" == "" ]] && read -sp 'Password: ' password && echo "" | |
data="action=login&username=${username}&password=${password}&ac_id=1&ajax=1" | |
auth_url="https://login.ecnu.edu.cn/include/auth_action.php" | |
# Temporarily fix TLS handshake failed "dh key too small" since openssl upgrade | |
# See: https://bugs.launchpad.net/ubuntu/+source/openssl/+bug/1864689 | |
curl --ciphers 'DEFAULT:@SECLEVEL=1' \ | |
-d $data $auth_url && echo "" | |
#vim: set ts=4 sw=4 et: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment