1
0

obfuscate.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/bash
  2. # obfuscate.sh
  3. # obfuscate email addresses in XML/HTML
  4. # Script written (and slight perl modification) by Archaic <archaic AT linuxfromscratch D0T org>
  5. # Modified from "sed -i" to old style "sed -e" by Manuel Canales <manuel AT linuxfromscratch D0T org>
  6. # to prevent hangs on very long files, like nonckunked books.
  7. # Original Perl expression by Anderson Lizardo <lizardo AT linuxfromscratch D0T org>
  8. # Released under the GNU General Public License
  9. #
  10. # This script currently only seeks out mailto: addresses. If those same
  11. # addresses also appear in plaintext, we need to obfuscate those as well.
  12. #
  13. # This script was made for a very specific purpose so I was a bit lazy in
  14. # writing the regex's.
  15. #
  16. # Please send comments, enhancements, etc. to the above address
  17. #set -e # Bail on all errors
  18. # First, ensure that we are given a file to process
  19. # if [ $# -lt 1 ]; then
  20. # echo -e "\nYou must provide an input file."
  21. # exit 1
  22. # fi
  23. # Nothing like a backup plan!
  24. #cp "$1" "$1".bak
  25. for i in `grep -o '"mailto:.*@.*"' ${1} |sed -e 's|^"mailto:||' -e 's|"$||'`; do
  26. link=`echo $i | perl -pe 's/[^\n]/"\\\&#".ord($&)."\;"/ge'`
  27. plaintext=`echo $i | sed -e 's|@| AT |' -e 's|\.| D0T |g'`
  28. cp ${1}{,.tmp}
  29. sed -e "s|mailto:$i|mailto:$link|" \
  30. -e "s|$i|$plaintext|" ${1}.tmp > ${1}
  31. rm ${1}.tmp
  32. done
  33. #rm $FILE.tmp
  34. #exit 0