Advertisement
JanRuusuvuori

neo-security-config.sh

Sep 24th, 2012
533
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.46 KB | None | 0 0
  1. #!/bin/bash
  2. if [ $# -lt 2 ]; then
  3.   echo "This script can be used to toggle admin security on and off in a ColdFusion 10 server instance."
  4.   echo ""
  5.   echo "Usage: $0 <cf_home> <admin_security>"
  6.   echo "where <cf_home> points to the root of a CF server instance, eg. /opt/coldfusion10/cfusion"
  7.   echo "      <admin_security> specifies the desired admin security state. Specify 'false' to turn it off, and 'true' for on. "
  8.   echo ""
  9.   exit
  10. fi
  11.  
  12. CF_HOME=$1
  13. ADMIN_SECURITY=$2
  14. XSL_FILE=/tmp/neo-security-config-$$.xsl
  15.  
  16. if [ ! -d "$CF_HOME" ]; then
  17.         echo "$CF_HOME doesn't seem to exist. Terminating."
  18.         exit 1
  19. fi
  20.  
  21. if [ "$ADMIN_SECURITY" != "false" ] && [ "$ADMIN_SECURITY" != "true" ]; then
  22.         echo "Invalid value for <admin_security>: $ADMIN_SECURITY. Please specify either 'true' or 'false'. "
  23.         exit 1
  24. fi
  25.  
  26. if [ ! -e $CF_HOME/lib/neo-security.xml.original ]; then
  27.         echo "Backing up original neo-security.xml to $CF_HOME/lib/neo-security.xml.original .."
  28.         cp $CF_HOME/lib/neo-security.xml $CF_HOME/lib/neo-security.xml.original
  29.         if [ $? != 0 ]; then
  30.           echo "cp failed with exit code $?. Terminating."
  31.           exit 1
  32.         fi
  33. else
  34.         echo "$CF_HOME/lib/neo-security.xml.original already exists."
  35. fi
  36.  
  37. echo "Writing XSL to $XSL_FILE .."
  38. cat > $XSL_FILE <<'EOXSL'
  39. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  40.   <xsl:output method="xml" omit-xml-declaration="yes" indent="yes" />
  41.   <xsl:param name="adminSecurityEnabled" />
  42.   <xsl:template match="/wddxPacket/data/struct[@type='coldfusion.server.ConfigMap']/var[@name='admin.security.enabled']/boolean/@value">
  43.     <xsl:attribute name="value">
  44.        <xsl:value-of select="$adminSecurityEnabled" />
  45.         </xsl:attribute>
  46.   </xsl:template>
  47.   <xsl:template match="@*|node()">
  48.     <xsl:copy>
  49.       <xsl:apply-templates select="@*|node()"/>
  50.     </xsl:copy>
  51.   </xsl:template>
  52. </xsl:stylesheet>
  53. EOXSL
  54. if [ $? != 0 ]; then
  55.   echo "Failed to write XSL template to $XSL_FILE. Terminating."
  56.   exit 1
  57. fi
  58.  
  59. echo "Modifying neo-security.xml .."
  60. xsltproc --stringparam adminSecurityEnabled $ADMIN_SECURITY $XSL_FILE $CF_HOME/lib/neo-security.xml.original > $CF_HOME/lib/neo-security.xml
  61. if [ $? != 0 ]; then
  62.   echo "xsltproc failed with exit code $?. Terminating."
  63.   exit 1
  64. fi
  65.  
  66. echo "Removing $XSL_FILE .."
  67. rm $XSL_FILE
  68. if [ $? != 0 ]; then
  69.   echo "rm failed with exit code $?. You may need to clean up manually."
  70.   exit 1
  71. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement