Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # A bash script for automatic fetching ECAS case history.
- #
- #
- #
- # DISCLAIMER:
- #
- #
- # !!! YOU USE THIS SCRIPT AT YOUR OWN RISK !!!
- #
- # I have tried it and it works for me, but I don't guarantee
- # that it will work for you!
- #
- # Moreover, I am not responsible if it breaks your system,
- # removes the website access to your application status,
- # locks you out completely and/or in any way gets you in trouble with CIC,
- # authorities or anybody else.
- #
- # You are responsible for any and all consequences of using this script!
- #
- #
- # AGAIN:
- #
- # !!! YOU USE THIS SCRIPT AT YOUR OWN RISK !!!
- #
- #
- #
- #
- # Requirements: curl, awk, grep, sed, cut.
- #
- # First, make sure to configure the script!
- #
- # Be very careful filling out all the details,
- # any extra spaces WILL prevent it from working properly!
- #
- #
- # CONFIGURATION
- #
- # Country code.
- # To get this code, go to: https://services3.cic.gc.ca/ecas/authenticate.do?app=ecas
- # Open the page source and find your country's name - the code will be right above it.
- # For example: <option value="461">United States of America</option>
- # So for the USA you should use 461 code.
- COUNTRY="461"
- # The type of the identifier:
- # 1 - Client ID Number / Unique Client Identifier
- # 2 - Receipt Number (IMM 5401)
- # 3 - Application Number / Case Number
- # 4 - Record of Landing Number
- # 5 - Permanent Resident Card Number
- # 6 - Citizenship Receipt Number
- # 7 - Citizenship File Number / Group Number
- # 8 - Confirmation of Permanent Residence Number
- ID_TYPE="1"
- # Identifier of that type (so the UCI number if '1' above, etc.)
- ID="12345678"
- # Surname/Family Name:
- SURNAME="Surname"
- # Date of birth (in YYYY-MM-DD format):
- DOB="2015-11-30"
- # Set this to '1' to mark the fact that you finished configuring this script:
- CONFIGURED="0"
- #
- # END-OF-CONFIGURATION
- #
- # (Don't change anything below this line!!!)
- #
- if [ ! "${CONFIGURED}" = "1" ]; then
- echo
- echo "Please configure the script first!"
- echo
- exit 1
- fi
- function showError()
- {
- echo
- echo "There was an error: $1"
- echo "Make sure that all the details and identifiers are correct "
- echo "and that you can access the data using regular browser!"
- echo
- }
- URL="https://services3.cic.gc.ca/ecas"
- COOKIE=$( curl -v "${URL}/authenticate.do?app=ecas" 2>&1 |
- grep 'Set-Cookie: ' | cut -d ' ' -f 3 )
- if [ "${COOKIE}" = "" ]; then
- showError "Could not read the session cookie"
- exit 1
- fi
- AUTH_DATA="lang=&_page=_target0&app=ecas"
- AUTH_DATA="${AUTH_DATA}&identifierType=${ID_TYPE}"
- AUTH_DATA="${AUTH_DATA}&identifier=${ID}"
- AUTH_DATA="${AUTH_DATA}&surname=${SURNAME}"
- AUTH_DATA="${AUTH_DATA}&dateOfBirth=${DOB}"
- AUTH_DATA="${AUTH_DATA}&countryOfBirth=${COUNTRY}"
- AUTH_DATA="${AUTH_DATA}&_submit=Continue"
- curl "${URL}/authenticate.do" -H "Cookie: ${COOKIE}" \
- -H 'Content-Type: application/x-www-form-urlencoded' --data "${AUTH_DATA}"
- CASE_LIST=$( curl "${URL}/viewcasestatus.do?app=ecas" \
- -H "Cookie: ${COOKIE}" 2>/dev/null )
- CASE_PREFIX='<a href="viewcasehistory.do?id='
- CASE_IDS=$( echo "${CASE_LIST}" | grep "${CASE_PREFIX}" | cut -d '=' -f 3 | cut -d '&' -f 1 )
- if [ "${CASE_IDS}" = "" ]; then
- showError "Could not get the list of case IDs - most likely the authentication failed"
- exit 1
- fi
- for CID in ${CASE_IDS}; do
- C_STATUS=$( echo "${CASE_LIST}" | grep "${CASE_PREFIX}${CID}" |
- cut -d '>' -f 2-99 | sed 's|</b>|-|g' | sed 's|<[^>]*>||g' )
- C_NAME=$( echo "${CASE_LIST}" | grep -B 4 "${CASE_PREFIX}${CID}" |
- head -n 2 | sed 'N;s/\n/ /' | awk '{$2=$2};1' )
- DATA=$( curl \
- "${URL}/viewcasehistory.do?id=${CID}&type=citCases&source=db&app=ecas&lang=en" \
- -H "Cookie: ${COOKIE}" 2>/dev/null )
- DATA_OK=$( echo "${DATA}" | grep '<li class="margin-bottom-medium">' |
- sed 's|.*<li class="margin-bottom-medium">|* |' | sed 's|</b>|-|g' | sed 's|<[^>]*>||g' )
- echo
- echo "Case ${CID}; Name: ${C_NAME}; Status: ${C_STATUS}"
- if [ "${DATA_OK}" = "" ]; then
- showError "Could not parse the details of case ${CID}"
- else
- ENTR=$( echo "${DATA_OK}" | wc -l )
- echo
- echo "History (${ENTR} entries):"
- echo
- echo "${DATA_OK}"
- echo
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement