Last active
July 26, 2018 15:59
-
-
Save rafaelfelix/5613539 to your computer and use it in GitHub Desktop.
Revisions
-
rafaelfelix revised this gist
Jul 2, 2014 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -78,7 +78,7 @@ fi AKAMAI_BASEURL='https://control.akamai.com' AKAMAI_LOGIN_ACTION=${AKAMAI_BASEURL}'/EdgeAuth/asyncUserLogin' AKAMAI_VERIFYIP_ACTION=${AKAMAI_BASEURL}'/partner-tools/rest/tools/v1.0/verifycdnip' CURL_COOKIE_JAR=$(create_tempfile) ENCODED_USR=$(rawurlencode $AKAMAI_USERNAME) @@ -96,7 +96,7 @@ curl -s -H 'Content-type: application/x-www-form-urlencoded' \ # request IP info IP_INFO=$(curl -s -H 'Content-type: application/x-www-form-urlencoded' \ -b $CURL_COOKIE_JAR \ "${AKAMAI_VERIFYIP_ACTION}?ip=${IP_ADDR}") # TODO: Better error handling if [ $? -ne 0 ]; then @@ -108,4 +108,4 @@ fi rm -f ${CURL_COOKIE_JAR} echo $IP_INFO exit 0 -
rafaelfelix created this gist
May 20, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,111 @@ #!/bin/bash # # Issue request to Akamai tool verifyAkamaiIpInternal to check if # the given IP address belongs to Akamai # ## defining helper functions first # show usage show_usage() { echo "usage: $0 -i <IP_ADDR> -u <AKAMAI_USERNAME> -p <AKAMAI_PASSWORD>" } # creates a temporary file (using an OS-aware way) create_tempfile() { local OS=$(uname -s) local TMP_FILENAME="" case $OS in Darwin) TMP_FILENAME=$(mktemp -t a) ;; Linux|*) TMP_FILENAME=$(mktemp) ;; esac echo $TMP_FILENAME } # helper function to encode url data (see http://stackoverflow.com/questions/296536/urlencode-from-a-bash-script) rawurlencode() { local string="${1}" local strlen=${#string} local encoded="" for (( pos=0 ; pos<strlen ; pos++ )); do c=${string:$pos:1} case "$c" in [-_.~a-zA-Z0-9] ) o="${c}" ;; * ) printf -v o '%%%02x' "'$c" esac encoded+="${o}" done echo "${encoded}" # You can either set a return variable (FASTER) REPLY="${encoded}" #+or echo the result (EASIER)... or both... :p } ## MAIN # ARGS parse while getopts ":i:u:p:" opt; do case $opt in i) IP_ADDR=$OPTARG ;; u) AKAMAI_USERNAME=$OPTARG ;; p) AKAMAI_PASSWORD=$OPTARG ;; ?) show_usage exit 1 ;; :) echo "Option -$OPTARG requires an argument." >&2 show_usage exit 1 ;; esac done # test for required args if [ -z $IP_ADDR ] || [ -z $AKAMAI_USERNAME ] || [ -z $AKAMAI_PASSWORD ]; then show_usage exit 1 fi AKAMAI_BASEURL='https://control.akamai.com' AKAMAI_LOGIN_ACTION=${AKAMAI_BASEURL}'/EdgeAuth/asyncUserLogin' AKAMAI_VERIFYIP_ACTION=${AKAMAI_BASEURL}'/partner-tools/verifyAkamaiIpInternal.action' CURL_COOKIE_JAR=$(create_tempfile) ENCODED_USR=$(rawurlencode $AKAMAI_USERNAME) ENCODED_PWD=$(rawurlencode $AKAMAI_PASSWORD) # get TARGET_URL hash from Akamai TARGET_URL_HASH=$(curl -s -I "${AKAMAI_VERIFYIP_ACTION}" | grep TARGET_URL | awk -FTARGET_URL= '{print $2}') # auth curl -s -H 'Content-type: application/x-www-form-urlencoded' \ -c $CURL_COOKIE_JAR \ -d "username=${ENCODED_USR}&password=${ENCODED_PWD}&TARGET_URL=${TARGET_URL_HASH}" \ ${AKAMAI_LOGIN_ACTION} # request IP info IP_INFO=$(curl -s -H 'Content-type: application/x-www-form-urlencoded' \ -b $CURL_COOKIE_JAR \ "${AKAMAI_VERIFYIP_ACTION}?akamaiIp=${IP_ADDR}") # TODO: Better error handling if [ $? -ne 0 ]; then echo 'ERROR' exit $? fi # removes cookie jar file rm -f ${CURL_COOKIE_JAR} echo $IP_INFO exit 0