Merge commit '2.5.0' into moonshot-packaging-fixes
[shibboleth/sp.git] / msi / scripts / shib_install_isapi_filter.vbs-wix
diff --git a/msi/scripts/shib_install_isapi_filter.vbs-wix b/msi/scripts/shib_install_isapi_filter.vbs-wix
new file mode 100644 (file)
index 0000000..375a97c
--- /dev/null
@@ -0,0 +1,180 @@
+Dim FilterObj\r
+Dim LoadOrder\r
+Dim FilterName\r
+Dim FilterPath\r
+Dim FilterDesc\r
+Dim WebObj, WebSite, WebSiteRoot\r
+Dim existsFlag\r
+Dim ScriptMaps\r
+Dim newScriptLine\r
+Dim line, lineArray, lineIndex\r
+Dim WebSvcExts\r
+Dim FileSystemObj\r
+Dim newWebSvcExtLine\r
+Dim customData, msiProperties, InstallDir, ShibFileExtension, LogFile\r
+\r
+'Get the INSTALLDIR and SHIB_FILE_EXTENSION values via CustomActionData\r
+customData = Session.Property("CustomActionData")\r
+msiProperties = split(customData,";@;")\r
+InstallDir= msiProperties(0)\r
+ShibISAPIPath = msiProperties(1)\r
+ShibFileExtension = msiProperties(2)\r
+\r
+Set FileSystemObj = CreateObject("Scripting.FileSystemObject")\r
+\r
+Set LogFile = FileSystemObj.OpenTextFile(InstallDir & "\var\log\shibboleth\Installer.log", 8, true)\r
+\r
+LogFile.WriteLine "Configure IIS plugin DLL " & ShibISAPIPath & ", Extension = " & ShibFileExtension\r
+\r
+On Error Resume Next\r
+Set WebObj = GetObject("IIS://LocalHost/W3SVC")\r
+if (Err = 0) then\r
+\r
+  'Remove all trailing backslashes to normalize\r
+  do while (mid(InstallDir,Len(InstallDir),1) = "\")\r
+    InstallDir = mid(InstallDir,1,Len(InstallDir)-1)\r
+  loop\r
+  ' ShibISAPIPath = InstallDir & "\lib\shibboleth\isapi_shib.dll"\r
+  'Make sure ShibFileExtension is in proper format\r
+  'First, strip any preceding periods\r
+  do while (mid(ShibFileExtension,1,1) = ".")\r
+    ShibFileExtension = mid(ShibFileExtension,2,Len(ShibFileExtension)-1)\r
+  loop\r
+  'If there is nothing left (or was nothing to begin with), use the default\r
+  if (ShibFileExtension = "") then\r
+    ShibFileExtension = ".sso"\r
+  else\r
+    'Add preceding period\r
+    ShibFileExtension = "." & ShibFileExtension\r
+  end if\r
+\r
+  'Specify other ISAPI Filter details\r
+  FilterName = "Shibboleth"\r
+  FilterPath = ShibISAPIPath\r
+  FilterDesc = ""\r
+\r
+  Set FiltersObj = GetObject("IIS://LocalHost/W3SVC/Filters")\r
+  LoadOrder = FiltersObj.FilterLoadOrder\r
+  'Check to see if 'Shibboleth' is already sequenced\r
+  existsFlag = "not_exist"\r
+  lineArray = split(LoadOrder, ",")\r
+  for each line in lineArray\r
+    if (line = FilterName) then\r
+      existsFlag = "exists"\r
+    end if\r
+  next\r
+  if (existsFlag = "not_exist") then\r
+    If LoadOrder <> "" Then\r
+      LoadOrder = LoadOrder & ","\r
+    End If\r
+    LoadOrder = LoadOrder & FilterName\r
+    FiltersObj.FilterLoadOrder = LoadOrder\r
+    FiltersObj.SetInfo\r
+  else\r
+    'msgbox "Shib Filter already sequenced"\r
+  end if\r
+\r
+  Set FilterObj = FiltersObj.Create("IIsFilter", FilterName)\r
+  If (Err <> 0) then\r
+    'Open existing filter for updating\r
+    Err = 0\r
+    Set FilterObj = GetObject("IIS://LocalHost/W3SVC/Filters/" & FilterName)\r
+  End If\r
+  FilterObj.FilterPath = FilterPath\r
+  FilterObj.FilterDescription = FilterDesc\r
+  FilterObj.SetInfo\r
+\r
+  'Create file extension mapping to ISAPI filter\r
+  newScriptLine = ShibFileExtension & "," & ShibISAPIPath & ",1"\r
+  ScriptMaps = WebObj.ScriptMaps\r
+  'Check if exists\r
+  existsFlag = "not_exist"\r
+  lineIndex = 0\r
+  for each line in ScriptMaps\r
+    lineArray = split(line,",")\r
+    if (lineArray(0) = ShibFileExtension) then\r
+      existsFlag = "exists"\r
+      Exit For\r
+    end if\r
+    lineIndex = lineIndex + 1\r
+  next\r
+  if (existsFlag = "not_exist") then\r
+    redim preserve ScriptMaps(UBound(ScriptMaps)+1)\r
+    ScriptMaps(UBound(ScriptMaps)) = newScriptLine\r
+    WebObj.ScriptMaps = ScriptMaps\r
+    WebObj.SetInfo\r
+  else\r
+    'msgbox ".sso already exists: " & lineIndex\r
+    'We already warned user in dialog that this value would be updated\r
+    ScriptMaps(lineIndex) = newScriptLine\r
+    WebObj.ScriptMaps = ScriptMaps\r
+    WebObj.SetInfo\r
+  end if\r
+\r
+  'Create file extension mapping to filter on each web site root\r
+  For Each WebSite in WebObj\r
+    Set WebSiteRoot = GetObject(WebSite.ADsPath & "/ROOT")\r
+    if (Err = 0) then\r
+      ScriptMaps = WebSiteRoot.ScriptMaps\r
+      'Check if exists\r
+      existsFlag = "not_exist"\r
+      lineIndex = 0\r
+      for each line in ScriptMaps\r
+        lineArray = split(line,",")\r
+        if (lineArray(0) = ShibFileExtension) then\r
+          existsFlag = "exists"\r
+          Exit For\r
+        end if\r
+        lineIndex = lineIndex + 1\r
+      next\r
+      if (existsFlag = "not_exist") then\r
+        redim preserve ScriptMaps(UBound(ScriptMaps)+1)\r
+        ScriptMaps(UBound(ScriptMaps)) = newScriptLine\r
+        WebSiteRoot.ScriptMaps = ScriptMaps\r
+        WebSiteRoot.SetInfo\r
+      else\r
+        'msgbox ".sso already exists: " & lineIndex\r
+        'We already warned user in dialog that this value would be updated\r
+        ScriptMaps(lineIndex) = newScriptLine\r
+        WebSiteRoot.ScriptMaps = ScriptMaps\r
+        WebSiteRoot.SetInfo\r
+      end if\r
+    End If\r
+  Next\r
+\r
+\r
+  'Web Services Extension\r
+  Err = 0\r
+  WebSvcExts = WebObj.WebSvcExtRestrictionList\r
+  if (Err = 0) then\r
+    newWebSvcExtLine = "1," & ShibISAPIPath & ",1,ShibGroup,Shibboleth Web Service Extension"\r
+\r
+    existsFlag = "not_exist"\r
+    lineIndex = 0\r
+    for each line in WebSvcExts\r
+      lineArray = split(line,",")\r
+      if (lineArray(1) = ShibISAPIPath) then\r
+        existsFlag = "exists"\r
+        Exit For\r
+      end if\r
+      lineIndex = lineIndex + 1\r
+    next\r
+\r
+    if (existsFlag = "not_exist") then\r
+      redim preserve WebSvcExts(UBound(WebSvcExts)+1)\r
+      WebSvcExts(UBound(WebSVCExts)) = newWebSvcExtLine\r
+      WebObj.WebSvcExtRestrictionList = WebSvcExts\r
+      WebObj.SetInfo\r
+    else\r
+      'msgbox "Shibboleth Web Services Extension already exists: " & lineIndex\r
+      'We already warned user in dialog that this value would be updated\r
+      WebSvcExts(lineIndex) = newWebSvcExtLine\r
+      WebObj.WebSvcExtRestrictionList = WebSvcExts\r
+      WebObj.SetInfo\r
+    end if\r
+\r
+  end if\r
+else\r
+   LogFile.WriteLine "  Could not locate IIS adaptor"\r
+'final end if\r
+end if
\ No newline at end of file