Home About BC DR HA Support Training Download
You are here: Home/ Downloads/ Scripts/ Korn/ Functions/ Please Login or Register

-
Current Location
-

js
  Downloads
    Scripts
      Korn
        Functions
-
AIX Admin Methodology
Global Consolidation Project
All AIX admins should join
www.aixexpert.com


Join our LinkedIn Group
AIX Advanced Technical Experts
Contract Opportunities

www.LinkedIn.com

-
digg Digg this page
del.icio.us Post to del.icio.us
Slashdot Slashdot it!


LPAR Leasing
Lease an AIX / i5 LPAR
Reduce your costs

www.mtxia.com

Server Leasing
Lease a Server off-site
Reduce your costs

www.mtxia.com

Data Center Automation
Business Continuity and DR
Virtualization/Consolidation

www.mtxia.com

HMC Service
Hardware Management Console
Manage Remote AIX / i5 LPARs

www.siteox.com

Business Web Site Hosting
$3.99 / month includes Tools,
Shopping Cart, Site Builder

www.siteox.com

Disaster Recovery
Small Business Oriented
Off-Site Facilities

www.mtxia.com

IBM pSeries / iSeries
Reduce your Costs
Off-Site Server Hosting

www.mtxia.com

In an effort to make it more difficult for spammers to scrape email addresses from HTML pages, this technique of encoding the characters of an email address into their HEX code equivalent was created. These HEX codes are then imbedded into a javascript segment into the HTML page and are displayed as their ASCII characters when a browser executes the generated javascript segment.

The following shows the encoding of the example ANCHOR tag, email addresses, and descriptive text into HEX codes and javascript:

<A Href="info@mtxia.com">Mt Xia Information</A>

The above ANCHOR tag becomes:

<SCRIPT Language='javascript' Type='text/javascript'>document.writeln(unescape(''+
'%3C%61-%68%72%65%66%3D%22%6D%61%69%6C%74%6F%3A'+
'%69%6E%66%6F%40%6D%74%78%69%61%2E%63%6F%6D%22%3E'+
'%4D%74-%58%69%61-%49%6E%66%6F%72%6D%61%74%69'+
'%6F%6E%3C%2F%41%3E'))
</SCRIPT>



#!/usr/bin/ksh93
################################################################
#### Copyright 2007 By Dana French, All Rights Reserved
#################################################################
function usagemsg_email2hex {
  print -- "
Program: email2hex

Generate a javascript and HEX code representation of an
HTML Anchor HREF tag containing a \"mailto:\" email
address.  The generated javascript can then be imbedded
within an HTML document and the email addresses can only 
be viewed when processed by a browser.  This makes it much
more difficult to scrape email addresses from the source
code of an HTML document.

Usage: ${1##*/} [-?vV] -e 'emailAddress' -t 'Link Text String'
                 [-p 'Prepended Text'] [-s 'Suffix Text']

  Where:
    -e emailAddress = Email address to encode as HEX
    -t linkText     = HTML Link text string to encode as HEX
    -p PrependText  = Text string to prepend before the Anchor HREF Tag
    -s SuffixText   = Text string to attach to the end of the Anchor HREF Tag
    -v              = Verbose mode - displays email2hex function info
    -V              = Very Verbose Mode - debug output displayed

Author: Dana French (dfrench@mtxia.com)

Copyright 2007 By Dana French, All Rights Reserved

\"AutoContent\" enabled
"
}
################################################################
#### 
#### Description:
#### 
#### Generate a javascript and HEX code representation of an
#### HTML Anchor HREF tag containing a \"mailto:\" email
#### address.  The generated javascript can then be imbedded
#### within an HTML document and the email addresses cannot
#### be viewed or easily scraped from the pages.
#### 
#### Assumptions:
#### 
#### This script will probably not work with IBM's version of
#### ksh93 since IBM's ksh93 is about 7 years out of date.  You 
#### will need to download a recent version of ksh93 from
#### www.kornshell.com to run this script with IBM AIX.
#### 
#### Dependencies:
#### 
####     None
#### 
#### Products:
#### 
#### This script generates a snippit of HTML code as a SCRIPT
#### tag. The SCRIPT tag contains HEX code representations of
#### the email address and descriptions provided on the
#### command line of this shell script.
#### 
#### Configured Usage:
#### 
#### This script can be run as a function or from the command
#### line. A typical command line would appear as:
#### 
#### email2hex -e "info@mtxia.com" -t "Mt Xia Information" -p "For Info: "
#### 
#### Details:
#### 
################################################################
function mkascii
{
 typeset VAL='${CNT}'
 [[ "_${2}" != "_" && "_${2}" =  "_8" ]] && VAL='$( printf "%o" 0x${i}${j} )'
 [[ "_${2}" != "_" && "_${2}" = "_16" ]] && VAL='${i}${j}'
 nameref ASCII_TABLE=$1
 typeset CNT=0
 for i in 0 1 2 3 4 5 6 7 8 9 A B C D E F
 do
  for j in 0 1 2 3 4 5 6 7 8 9 A B C D E F
  do
   eval ASCII_TABLE[\\$(print -- $( printf "\\\0%o" 0x${i}${j} ) )]=\"${VAL}\" 2>/dev/null
   (( CNT = CNT + 1 ))
  done
 done
}
################################################################
function email2hex {
  typeset VERSION="1.0"
  typeset TRUE="1"
  typeset FALSE="0"
  typeset EXITCODE="0"
  typeset VERBOSE="${FALSE}"
  typeset VERYVERB="${FALSE}"
  typeset EMAIL=""
  typeset LINKTEXT=""
  typeset PREPTEXT=""
  typeset SUFFTEXT=""
  typeset MSG="<a href=\"mailto:${EMAIL}\">${LINKTEXT}</A>"
  typeset SCRIPT_TAGBEG="<SCRIPT Language='javascript' Type='text/javascript'>document.writeln(unescape(''+\n'"
  typeset SCRIPT_TAGEND="</SCRIPT>"
  typeset DENOM="16"
  typeset -A HEX
  typeset IDX

#### 
#### Process the command line options and arguments, saving
#### the values as appropriate.
#### 

  while getopts ":vVe:t:p:s:" OPTION
  do
      case "${OPTION}" in
          'e') EMAIL="${OPTARG}";;
          't') LINKTEXT="${OPTARG}";;
          'p') PREPTEXT="${OPTARG}";;
          's') SUFFTEXT="${OPTARG}";;
          'v') VERBOSE="${TRUE}";;
          'V') VERYVERB="${TRUE}";;
        [?:#]) usagemsg_email2hex "${0}" && return 1 ;;
      esac
  done
   
  shift $(( ${OPTIND} - 1 ))
  
  trap "usagemsg_email2hex ${0}" EXIT
  if [[ "_${EMAIL}" == "_" ]]
  then
      print -u 2 "# ERROR: Email address not specified"
      return 2
  fi
  if [[ "_${LINKTEXT}" == "_" ]]
  then
      print -u 2 "# ERROR: Link text not specified"
      return 3
  fi
  trap "-" EXIT
  
#### 
#### Display some program info and the command line arguments specified
#### if "VERBOSE" mode was specified.
#### 

  (( VERYVERB == TRUE )) && set -x
  (( VERBOSE  == TRUE )) && print -u 2 "# Version........: ${VERSION}"
  (( VERBOSE  == TRUE )) && print -u 2 "# Email Address..: ${EMAIL}"
  (( VERBOSE  == TRUE )) && print -u 2 "# Link Text......: ${LINKTEXT}"
  (( VERBOSE  == TRUE )) && print -u 2 "# Prepended Text.: ${PREPTEXT}"
  (( VERBOSE  == TRUE )) && print -u 2 "# Suffix Text....: ${SUFFTEXT}"

################################################################

  MSG="${PREPTEXT}<a href=\"mailto:${EMAIL}\">${LINKTEXT}</A>${SUFFTEXT}"
  mkascii HEX 16

  (( VERBOSE  == TRUE )) && print -u 2 "# HREF Anchor Tag: ${MSG}"

  for (( i=0; i<${#MSG}; ++i ))
  do
    PARS[i]="${MSG:i:1}"
  done  

#### The substitution operator with pattern replacement does not
#### seem to work under the cygwin implementation of ksh93.  The
#### above "for" loop was added to replace the following code.

#   IFS=$'|'
#   PARS=( ${MSG//(?)/|\1} )
#   unset PARS[0]
#   IFS=$' \t\n'

  (( VERBOSE  == TRUE )) && print -u 2 "# Parsed Array...: ${PARS[@]}"
  print -n -- "${SCRIPT_TAGBEG}"

  for IDX in "${!PARS[@]}"
  do
    (( VERBOSE  == TRUE )) && print -u 2 "# Char: ${PARS[IDX]}     HEX: ${HEX[${PARS[${IDX}]}]}"
    print -n -r -- "%${HEX[${PARS[${IDX}]}]}"
    (( ( IDX % DENOM ) == 0 )) && print -n -- "'+\n'"
  done

  print -- "'))\n${SCRIPT_TAGEND}"

  return 0
}
################################################################

email2hex "${@}"

-
Email Address Encoding
-
 


LPAR Leasing
Lease an AIX / i5 LPAR
Reduce your costs

www.mtxia.com

Server Leasing
Lease a Server off-site
Reduce your costs

www.mtxia.com

Data Center Automation
Business Continuity and DR
Virtualization/Consolidation

www.mtxia.com

HMC Service
Hardware Management Console
Manage Remote AIX / i5 LPARs

www.siteox.com

Business Web Site Hosting
$3.99 / month includes Tools,
Shopping Cart, Site Builder

www.siteox.com

FREE Domain Registration
included with Web Site Hosting
Tools, Social Networking, Blog

www.siteox.com

Disaster Recovery
Small Business Oriented
Off-Site Facilities

www.mtxia.com

IBM pSeries / iSeries
Reduce your Costs
Off-Site Server Hosting

www.mtxia.com