<commit_before>mount "C:\" "@SYSDRIVE@\mountedfs" 

# Workaround because of CLNT-3978; uncomment when fixed
# from clean when (not host has os:windows7 and not host has os:windows8.1)
# from spoonbrew/iis7-base:9 when host has os:windows7
# from spoonbrew/iis8-base:5 when host has os:windows8.1

from clean when host has os:windowsxp
from clean when host has os:windowsvista
from clean when host has os:windows10
from spoonbrew/iis7-base:10 when host has os:windows7
from spoonbrew/iis8-base:6 when host has os:windows8.1
from spoonbrew/iis8-base:6 when host has os:windows8

workdir @SYSDRIVE@
setworkdir @SYSDRIVE@

cmd title IIS Server
meta name = "iis-server"

require privilege:admin, architecture:current

# Greeting message
# Check if user wants to proceed with IIS import
batch cmd
  echo. 
  echo.  Internet Information Services (IIS) for Windows Server is a flexible, secure and manageable Web server for hosting anything on the Web. From media streaming to web applications, IIS's scalable and open architecture is ready to handle the most demanding tasks.
  echo. 
  echo.  Website URL: http://www.iis.net/
  echo.  Support URL: http://forums.iis.net/
  echo.
  echo.  Init Script Source: https://github.com/spoonapps/spoonme/blob/master/iis/import.me
  echo.
  echo.
  echo.  CAUTION! This script will import files and settings from your computer into a Spoon container.
  echo.  CAUTION! Please make sure you set the container to private mode for sensitive data or production environments.
  echo.
  set /P spoonPrompt=" Please enter 'ok' to continue or 'cancel' to abort: "
  if /I "%spoonPrompt%"=="ok" (
  echo.
  echo.  Script will now import Internet Information Services from this computer...
  ping localhost -n 5 > nul
  ) else (
  echo.
  echo.
  echo.  ERROR: User has aborted the import script.
  echo.
  echo.
  exit /b 1
  )

# Check if IIS is installed
batch cmd
  echo.  Checking if IIS is installed...
  
  if not exist C:\mountedfs\windows\system32\inetsrv\InetMgr.exe if not exist C:\mountedfs\windows\syswow64\inetsrv\InetMgr.exe (
  echo.
  echo.
  echo   ERROR: IIS does not appear to be installed on this machine. Please install and try again.
  echo.
  echo.
  exit /b 1
  )
  
# Copy files
# Export encryption keys into a protable format, so that IIS runs on different machines
# Check for .NET 3.5 or 4
batch cmd
  echo.  Copying IIS binaries...
  echo.
  xcopy /s/e/h/i "C:\mountedfs\windows\system32\inetsrv" "C:\windows\system32\inetsrv"
  xcopy /s/e/h/i "C:\mountedfs\windows\syswow64\inetsrv" "C:\windows\syswow64\inetsrv"
  cmd /c c:\iis-init\setup.cmd
  
  echo. 
  echo.  Checking for Microsoft .NET Framework...
  echo. 
  if exist "%windir%\microsoft.net\framework64\v2.0.50727\aspnet_regiis.exe" (
  echo.  Found %windir%\microsoft.net\framework64\v2.0.50727\aspnet_regiis.exe.
  pushd "%windir%\microsoft.net\framework64\v2.0.50727"
  ) else (
  if exist "%windir%\microsoft.net\framework\v2.0.50727\aspnet_regiis.exe" (
  echo.  Found %windir%\microsoft.net\framework\v2.0.50727\aspnet_regiis.exe.
  pushd "%windir%\microsoft.net\framework\v2.0.50727"
  ) else (
  if exist "%windir%\microsoft.net\framework64\v4.0.30319\aspnet_regiis.exe" (
  echo.  Found %windir%\microsoft.net\framework64\v4.0.30319\aspnet_regiis.exe.
  pushd "%windir%\microsoft.net\framework64\v4.0.30319"
  ) else (
  if exist "%windir%\microsoft.net\framework\v4.0.30319\aspnet_regiis.exe" (
  echo.  Found %windir%\microsoft.net\framework\v4.0.30319\aspnet_regiis.exe.
  pushd "%windir%\microsoft.net\framework\v4.0.30319"
  ) else (
  echo.
  echo.
  echo  ERROR: .NET Framework 3.5 or 4 is not detected. Please install framework or add the microsoft/dotnet image from the Spoon hub and try again.
  echo.
  echo.
  exit /b 1
  )
  )    
  )
  )
  
  echo. 
  echo.  Exporting IIS keys to a portable format...
  echo. 
  xcopy /h "C:\mountedfs\programdata\microsoft\Crypto\RSA\MachineKeys\6de9cb26d2b98c01ec4e9e8b34824aa2*" "C:\programdata\microsoft\crypto\rsa\machinekeys\"
  xcopy /h "C:\mountedfs\programdata\microsoft\Crypto\RSA\MachineKeys\76944fb33636aeddb9590521c2e8815a*" "C:\programdata\microsoft\crypto\rsa\machinekeys\"
  xcopy /h "C:\mountedfs\programdata\microsoft\Crypto\RSA\MachineKeys\7a436fe806e483969f48a894af2fe9a1*" "C:\programdata\microsoft\crypto\rsa\machinekeys\"
  xcopy /h "C:\mountedfs\programdata\microsoft\Crypto\RSA\MachineKeys\bedbf0b4da5f8061b6444baedf4c00b1*" "C:\programdata\microsoft\crypto\rsa\machinekeys\"
  xcopy /h "C:\mountedfs\programdata\microsoft\Crypto\RSA\MachineKeys\c2319c42033a5ca7f44e731bfd3fa2b5*" "C:\programdata\microsoft\crypto\rsa\machinekeys\"
  xcopy /h "C:\mountedfs\programdata\microsoft\Crypto\RSA\MachineKeys\d6d986f09a1ee04e24c949879fdb506c*" "C:\programdata\microsoft\crypto\rsa\machinekeys\"

  aspnet_regiis.exe -px "iisConfigurationKey" "C:\iis-init\iisConfigurationKey.xml" -pri
  aspnet_regiis.exe -px "iisWasKey" "C:\iis-init\iisWasKey.xml" -pri
  aspnet_regiis.exe -px "WMSvc Certificate Key Container" "C:\iis-init\WMSvcCertificateKeyContainer.xml" -pri
  aspnet_regiis.exe -px "NetFrameworkConfigurationKey" "C:\iis-init\NetFrameworkConfigurationKey.xml" -pri
  aspnet_regiis.exe -px "Microsoft Internet Information Server" "C:\iis-init\MicrosoftInternetInformationServer.xml"
  aspnet_regiis.exe -px "MS IIS DCOM Server" "C:\iis-init\MSIISDCOMServer.xml"
  popd
  
  echo. 
  echo.  Cleaning up IIS keys...
  del "%PROGRAMDATA%\Microsoft\Crypto\RSA\MachineKeys\76944fb33636aeddb9590521c2e8815a*" /Q/A 1> nul 2> nul
  del "%PROGRAMDATA%\microsoft\Crypto\RSA\MachineKeys\6de9cb26d2b98c01ec4e9e8b34824aa2*" /Q/A 1> nul 2> nul
  del "%PROGRAMDATA%\microsoft\Crypto\RSA\MachineKeys\7a436fe806e483969f48a894af2fe9a1*" /Q/A 1> nul 2> nul
  del "%PROGRAMDATA%\microsoft\Crypto\RSA\MachineKeys\bedbf0b4da5f8061b6444baedf4c00b1*" /Q/A 1> nul 2> nul
  del "%PROGRAMDATA%\microsoft\Crypto\RSA\MachineKeys\c2319c42033a5ca7f44e731bfd3fa2b5*" /Q/A 1> nul 2> nul
  del "%PROGRAMDATA%\microsoft\Crypto\RSA\MachineKeys\d6d986f09a1ee04e24c949879fdb506c*"  /Q/A 1> nul 2> nul

# Final message
echo " "  
echo "  Script has finished importing Internet Information Services (IIS)!"
echo " "
echo "  1) The default port for IIS is 80. If you already have a server listening to that port, you can:"
echo "     a. Use the route add statement to redirect the virtual port 80 to a different native port, such as 8081."
echo "        Spoon (344a393e) C:\> route add tcp,udp 8081:80"
echo "     b. Start a virtual command prompt and change the default port using IIS Manager."
echo "        Spoon (344a393e) C:\> cmd"<commit_msg>CLNT-3995 - re-gen machine keys during iis harvest<commit_after>mount "C:\" "@SYSDRIVE@\mountedfs" 

# Workaround because of CLNT-3978; uncomment when fixed
# from clean when (not host has os:windows7 and not host has os:windows8.1)
# from spoonbrew/iis7-base:9 when host has os:windows7
# from spoonbrew/iis8-base:5 when host has os:windows8.1

from clean when host has os:windowsxp
from clean when host has os:windowsvista
from clean when host has os:windows10
from spoonbrew/iis7-base:10 when host has os:windows7
from spoonbrew/iis8-base:6 when host has os:windows8.1
from spoonbrew/iis8-base:6 when host has os:windows8
using python

workdir @SYSDRIVE@
setworkdir @SYSDRIVE@

cmd title IIS Server
meta name = "iis-server"

require privilege:admin, architecture:current

# Greeting message
# Check if user wants to proceed with IIS import
batch cmd
  echo. 
  echo.  Internet Information Services (IIS) for Windows Server is a flexible, secure and manageable Web server for hosting anything on the Web. From media streaming to web applications, IIS's scalable and open architecture is ready to handle the most demanding tasks.
  echo. 
  echo.  Website URL: http://www.iis.net/
  echo.  Support URL: http://forums.iis.net/
  echo.
  echo.  Init Script Source: https://github.com/spoonapps/spoonme/blob/master/iis/import.me
  echo.
  echo.
  echo.  CAUTION! This script will import files and settings from your computer into a Spoon container.
  echo.  CAUTION! Please make sure you set the container to private mode for sensitive data or production environments.
  echo.
  set /P spoonPrompt=" Please enter 'ok' to continue or 'cancel' to abort: "
  if /I "%spoonPrompt%"=="ok" (
  echo.
  echo.  Script will now import Internet Information Services from this computer...
  ping localhost -n 5 > nul
  ) else (
  echo.
  echo.
  echo.  ERROR: User has aborted the import script.
  echo.
  echo.
  exit /b 1
  )

# Check if IIS is installed
batch cmd
  echo.  Checking if IIS is installed...
  
  if not exist C:\mountedfs\windows\system32\inetsrv\InetMgr.exe if not exist C:\mountedfs\windows\syswow64\inetsrv\InetMgr.exe (
  echo.
  echo.
  echo   ERROR: IIS does not appear to be installed on this machine. Please install and try again.
  echo.
  echo.
  exit /b 1
  )

# create helper python script to remove configProtectedData section of applicationHost.config
batch cmd
  echo import xml.etree.ElementTree as xml > c:\iis-init\trim.py
  echo configFile = r"C:\Windows\sysnative\inetsrv\config\applicationHost.config" >> c:\iis-init\trim.py
  echo tempFile = r"C:\Windows\sysnative\inetsrv\config\applicationHost.config.temp" >> c:\iis-init\trim.py
  echo tree = xml.parse(configFile) >> c:\iis-init\trim.py
  echo data = tree.find('configProtectedData') >> c:\iis-init\trim.py
  echo data.clear() >> c:\iis-init\trim.py
  echo tree.write(tempFile) >> c:\iis-init\trim.py
  echo temp = open(tempFile, "r") >> c:\iis-init\trim.py
  echo final = open(configFile, "w") >> c:\iis-init\trim.py
  echo final.writelines(temp.readlines()) >> c:\iis-init\trim.py
  echo temp.close() >> c:\iis-init\trim.py
  echo final.close() >> c:\iis-init\trim.py

# Copy files
# Export encryption keys into a protable format, so that IIS runs on different machines
# Check for .NET 3.5 or 4
batch cmd
  echo.  Copying IIS binaries...
  echo.
  xcopy /s/e/h/i "C:\mountedfs\windows\system32\inetsrv" "C:\windows\system32\inetsrv"
  xcopy /s/e/h/i "C:\mountedfs\windows\syswow64\inetsrv" "C:\windows\syswow64\inetsrv"
  cmd /c c:\iis-init\setup.cmd
  
  echo. 
  echo.  Checking for Microsoft .NET Framework...
  echo. 
  if exist "%windir%\microsoft.net\framework64\v2.0.50727\aspnet_regiis.exe" (
  echo.  Found %windir%\microsoft.net\framework64\v2.0.50727\aspnet_regiis.exe.
  pushd "%windir%\microsoft.net\framework64\v2.0.50727"
  ) else (
  if exist "%windir%\microsoft.net\framework\v2.0.50727\aspnet_regiis.exe" (
  echo.  Found %windir%\microsoft.net\framework\v2.0.50727\aspnet_regiis.exe.
  pushd "%windir%\microsoft.net\framework\v2.0.50727"
  ) else (
  if exist "%windir%\microsoft.net\framework64\v4.0.30319\aspnet_regiis.exe" (
  echo.  Found %windir%\microsoft.net\framework64\v4.0.30319\aspnet_regiis.exe.
  pushd "%windir%\microsoft.net\framework64\v4.0.30319"
  ) else (
  if exist "%windir%\microsoft.net\framework\v4.0.30319\aspnet_regiis.exe" (
  echo.  Found %windir%\microsoft.net\framework\v4.0.30319\aspnet_regiis.exe.
  pushd "%windir%\microsoft.net\framework\v4.0.30319"
  ) else (
  echo.
  echo.
  echo  ERROR: .NET Framework 3.5 or 4 is not detected. Please install framework or add the microsoft/dotnet image from the Spoon hub and try again.
  echo.
  echo.
  exit /b 1
  )
  )    
  )
  )
  
  echo. 
  echo.  Exporting IIS keys to a portable format...
  echo. 
  python c:\iis-init\trim.py
  %windir%\system32\inetsrv\iissetup.exe /install SharedLibraries

  aspnet_regiis.exe -px "iisConfigurationKey" "C:\iis-init\iisConfigurationKey.xml" -pri
  aspnet_regiis.exe -px "iisWasKey" "C:\iis-init\iisWasKey.xml" -pri
  aspnet_regiis.exe -px "WMSvc Certificate Key Container" "C:\iis-init\WMSvcCertificateKeyContainer.xml" -pri
  aspnet_regiis.exe -px "NetFrameworkConfigurationKey" "C:\iis-init\NetFrameworkConfigurationKey.xml" -pri
  aspnet_regiis.exe -px "Microsoft Internet Information Server" "C:\iis-init\MicrosoftInternetInformationServer.xml"
  aspnet_regiis.exe -px "MS IIS DCOM Server" "C:\iis-init\MSIISDCOMServer.xml"
  popd
  
  echo. 
  echo.  Cleaning up IIS keys...
  del "%PROGRAMDATA%\Microsoft\Crypto\RSA\MachineKeys\76944fb33636aeddb9590521c2e8815a*" /Q/A 1> nul 2> nul
  del "%PROGRAMDATA%\microsoft\Crypto\RSA\MachineKeys\6de9cb26d2b98c01ec4e9e8b34824aa2*" /Q/A 1> nul 2> nul
  del "%PROGRAMDATA%\microsoft\Crypto\RSA\MachineKeys\7a436fe806e483969f48a894af2fe9a1*" /Q/A 1> nul 2> nul
  del "%PROGRAMDATA%\microsoft\Crypto\RSA\MachineKeys\<KEY>1*" /Q/A 1> nul 2> nul
  del "%PROGRAMDATA%\microsoft\Crypto\RSA\MachineKeys\c2319c42033a5ca7f44e731bfd3fa2b5*" /Q/A 1> nul 2> nul
  del "%PROGRAMDATA%\microsoft\Crypto\RSA\MachineKeys\<KEY>*"  /Q/A 1> nul 2> nul

# Final message
echo " "  
echo "  Script has finished importing Internet Information Services (IIS)!"
echo " "
echo "  1) The default port for IIS is 80. If you already have a server listening to that port, you can:"
echo "     a. Use the route add statement to redirect the virtual port 80 to a different native port, such as 8081."
echo "        Spoon (344a393e) C:\> route add tcp,udp 8081:80"
echo "     b. Start a virtual command prompt and change the default port using IIS Manager."
echo "        Spoon (344a393e) C:\> cmd"
{'fraction_non_alphanumeric': 0.11329453556042628, 'fraction_numerical': 0.05177235280779986, 'mean_word_length': 3.7976794778825234, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 58, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 15}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6364925', 'n_tokens_mistral': 5326, 'n_tokens_neox': 4775, 'n_words': 1253}