Skip to content

Instantly share code, notes, and snippets.

@Embraser01
Last active September 20, 2018 07:54
Show Gist options
  • Save Embraser01/ce56f689fc75171c7ba5a52d16c6def4 to your computer and use it in GitHub Desktop.
Save Embraser01/ce56f689fc75171c7ba5a52d16c6def4 to your computer and use it in GitHub Desktop.
Script to log at INSA Lyon

Usage

  1. Edit script to set your USERNAME.
  2. Set PASSWORD variable or be asked every time 😃

Configure to be launch at startup

Windows

  1. Install the Ubuntu sub-system (available in the Windows Store)
  2. After that, make sure curl is installed
  3. Add this command in the Task Scheduler (fr: Planificateur de tache) bash -c 'bash /mnt/r/Documents/_INSA/INSA_Login.sh'

Linux

It should be even simpler, go look on the internet 😉

#!/bin/bash
# Get the redirect URL
# Because INSA have done some stupid configuration,
# You must use a non existing DNS in order to get it working
TEST_URL='http://insa.fr/'
NEW_LOCATION_URL=$(curl -Ls -o /dev/null -w %{url_effective} ${TEST_URL})
HOSTNAME=$(echo ${NEW_LOCATION_URL} | awk -F/ '{print $3}')
if [ "$TEST_URL" == "$NEW_LOCATION_URL" ]
then
echo "Already logged in!"
exit 0
fi
# Get the IP from DHCP configuration
IP=$(ip route list | \
grep default | \
grep -E -o -m 1 '10.44.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)')
USERNAME='xxxxxxx@insa-lyon.fr'
# Choose one of each option (ask every time or have the password saved as plain text)
read -s -p "Enter password for $USERNAME: " PASSWORD
#PASSWORD=''
RES=$(curl ${CURL_OPTION} --data "auth_user=${USERNAME}&auth_pass=${PASSWORD}&accept=Login" \
--resolve "${HOSTNAME}:${IP}" -s -o /dev/null -w "%{http_code}" ${NEW_LOCATION_URL})
if [ "$RES" -eq "200" ]
then
echo "Logged in, enjoy!"
exit 0
else
echo "Error while login in, got status code '${RES}'"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment