<project name="bootstrapPluginsIIS7Uninstall" default="validateAntCall" basedir=".">

   <!--
# IBM Confidential OCO Source Material
# 5639-D57, 5630-A36, 5630-A37, 5724-D18 (C) COPYRIGHT International Business Machines Corp. 1997, 2009
# The source code for this program is not published or otherwise divested
# of its trade secrets, irrespective of what has been deposited with the
# U.S. Copyright Office.
   -->
   

<!-- Need to NOT indent these lines.  Updates webserver specific logfile -->    
   <!-- 
   ***************************************************************************
   TARGET: updateLogFile
   Log statement to webserver uninstall log
   ***************************************************************************
   -->      
<target name="updateLogFile"
        description="Update webserver specific logfile">
<property name="CRLF" value="&#13;&#10;"/>                        
<echo file="${install.log}" append="true">${stringToAppend}${CRLF}</echo>
</target>
   
   <!-- 
   ***************************************************************************
   TARGET: updateLogFile
   Log statement to webserver uninstall log and stdout
   ***************************************************************************
   -->      
    <target name="logBoth">
       <echo>${logStatement}</echo>
        <antcall target="updateLogFile">
           <param name="stringToAppend" value="${logStatement}"/>
        </antcall>            
    </target>    

   <!-- 
   ***************************************************************************
   TARGET: logStartupProperties
   Log startup properties to the uninstall log
   ***************************************************************************
   -->      
    <target name="logStartupProperties"
            description="Log properties passed to script">
        <property name="install.log" value="${PLUGIN_HOME}\logs\unconfig\uninstallIIS7Plugin.log"/> 
        <mkdir dir="${PLUGIN_HOME}\logs\unconfig"/>
        <touch file="${install.log}"/>
        <tstamp>
           <format property="timestamp" pattern="MM/dd/yyyy hh:mm aa"/>
        </tstamp>
        <antcall target="updateLogFile">
           <param name="stringToAppend" value=" "/>
        </antcall>        
        <antcall target="updateLogFile">
           <param name="stringToAppend" value="************************************************************"/>
        </antcall>        
        
        <antcall target="updateLogFile">
           <param name="stringToAppend" value="** Uninstall IIS7 Webserver Plugin ${timestamp}"/>
        </antcall>     
        
        <antcall target="updateLogFile">
           <param name="stringToAppend" value="************************************************************"/>
        </antcall>        
       
        <antcall target="updateLogFile">
           <param name="stringToAppend" value="PLUGIN_HOME = ${PLUGIN_HOME}"/>
        </antcall>   
          
        <antcall target="updateLogFile">
           <param name="stringToAppend" value="OS_NAME = ${OS_NAME}"/>
        </antcall>     
        
        <antcall target="updateLogFile">
           <param name="stringToAppend" value="WEBSERVER_TYPE = ${WEBSERVER_TYPE}"/>
        </antcall>     
        
        <antcall target="updateLogFile">
           <param name="stringToAppend" value="PLUGIN_UNCONFIGURE_IIS7 = ${PLUGIN_CONFIGURE_IIS7}"/>
        </antcall>     
        
        
    </target>
    <!--
    **************************************************************************
    TARGET: Usage
    Displays usage information
    **************************************************************************
    -->
    <target name="Usage" if="CMDLINE_CFG"
            description="Display usage information">       
      	<echo message="Usage: -ant -f IIS7UnInstall.ant [[option=optionValue]..]"/>
      	<echo message=""/>
      	<echo message="Valid Options"/>
        <echo message="============="/>
      	<echo message="-DPLUGIN_HOME=pluginDirectory"/>
        <echo message="    required - the location of the plugin home directory"/>
        <echo message="      (ie, c:\Program Files\IBM\WebSphere\Plugins)"/>
                                                            
    </target>                
    <!--
    ***************************************************************************
    TARGET: bootstrapPluginsIIS7Uninstall
    This is the main target
    ***************************************************************************
    -->      
    <target name="bootstrapPluginsIIS7Uninstall"
        description="Uninstall IIS7  Plugin"
        depends="logStartupProperties">
        
        <antcall target="logBoth">
           <param name="logStatement" value="Uninstalling IIS 7 plugin"/>
        </antcall>
        
        <antcall target="logBoth">
           <param name="logStatement" value="Removing sePlugins"/>
        </antcall>
        
        <exec dir="${PLUGIN_HOME}/bin" executable="${PLUGIN_HOME}/bin/configureIIS.exe" 
              failonerror="true"
              output="${PLUGIN_HOME}/logs/unconfig/uninstallIIS7Plugin.log">
              <arg value="&quot;-remove&quot; &quot;sePlugins&quot;"/>	
        </exec> 
       
        
        <!-- Commented out because we don't set these within the 99SBootStrapPluginsIIS7.ant script. 
              Leaving them here in case we need to add back.
        <antcall target="logBoth">
           <param name="logStatement" value="Removing iisWASPlugin isapi filter"/>
        </antcall>
        
        <exec dir="." executable="cmd"
              failonerror="true"
              output="${PLUGIN_HOME}/logs/unconfig/IIS7_adjustAppPool.log">
              <arg value="/c %systemroot%\system32\inetsrv\appcmd apppool set /apppool.name:DefaultAppPool /enable32BitAppOnWin64:false"/>
        </exec>         
        
        <exec dir="." executable="cmd"
              failonerror="true"
              output="${PLUGIN_HOME}/logs/unconfig/uninstallIIS7Plugin_ISAPIFilter.log">
              <arg value="/c %systemroot%\system32\inetsrv\appcmd unlock config /section:system.webServer/isapiFilters"/>
        </exec>         
        
        <exec dir="." executable="cmd"
              failonerror="true"
              output="${PLUGIN_HOME}/logs/unconfig/uninstallIIS7Plugin_ISAPIFilter.log">
              <arg value="/c %systemroot%\system32\inetsrv\appcmd set config &quot;Default Web Site&quot; /section:isapiFilters /-[name='iisWASPlugin']"/>
        </exec>         
        
        <exec dir="." executable="cmd"
              failonerror="true"
              output="${PLUGIN_HOME}/logs/unconfig/uninstallIIS7Plugin_ISAPIFilter.log">
              <arg value="/c %systemroot%\system32\inetsrv\appcmd lock config /section:system.webServer/isapiFilters"/>
        </exec>         
        
        <antcall target="logBoth">
           <param name="logStatement" value="Removing WASPlugin isapiCgiRestriction"/>
        </antcall>
        
        <exec dir="." executable="cmd"
              failonerror="true"
              output="${PLUGIN_HOME}/logs/unconfig/uninstallIIS7Plugin_ISAPIRest.log">
              <arg value="/c %systemroot%\system32\inetsrv\appcmd set config /section:isapiCgiRestriction /-&quot;[path='${PLUGIN_HOME}${separatorFile}bin${separatorFile}IIS_${WEBSERVER_NAME}\iisWASPlugin_http.dll', allowed='True', description='WASPlugin']&quot;"/>
        </exec> -->
        
        <antcall target="logBoth">
           <param name="logStatement" value="Uninstall complete"/>
        </antcall>
    </target>
    
    <!--
    **************************************************************************
    TARGET: validateAntCall
    This is the main target. Check that all required config options are present.         
    If all required config options are present set IIS7Target to 
    bootstrapPluginsIIS7Uninstall. Otherwise set IIS7Target to "Usage" so the usage 
    information can be displayed
    ***************************************************************************
    -->
    <target name="validateAntCall"
        description="UnConfigure Plugin">
        
        <condition property="ValidOptions">                   
           <and>                                            
              <equals arg1="${PLUGIN_CONFIGURE_IIS7}" arg2="TRUE" trim="true" casesensitive="false"/>
              <isset property="OS_NAME"/>
              <isset property="PLUGIN_HOME"/>        
              <isset property="WEBSERVER_TYPE"/> 
              <equals arg1="${WEBSERVER_TYPE}" arg2="IIS" trim="true"/>            
           </and>                                           
        </condition>
	
        <condition property="IHSTarget" value="bootstrapPluginsIIS7Uninstall">
           <istrue value="${ValidOptions}"/>
        </condition>
        
        <condition property="IHSTarget" value="Usage">
              <isfalse value="${ValidOptions}"/>
        </condition>
        
        <antcall target="${IHSTarget}"/>  
        
    </target>
    
</project>
