Fix path to DLL.
[shibboleth/sp.git] / msi / scripts / shib_install_isapi_filter.vbs
1 Dim FiltersObj
2 Dim FilterObj
3 Dim LoadOrder
4 Dim FilterName
5 Dim FilterPath
6 Dim FilterDesc
7 Dim WebObj, WebSite, WebSiteRoot
8 Dim existsFlag
9 Dim ScriptMaps
10 Dim newScriptLine
11 Dim line, lineArray, lineIndex
12 Dim WebSvcExts
13 Dim newWebSvcExtLine
14 Dim customData, msiProperties, InstallDir, ShibFileExtension
15
16 On Error Resume Next
17 Set WebObj = GetObject("IIS://LocalHost/W3SVC")
18 if (Err = 0) then
19
20   'Get the INSTALLDIR and SHIB_FILE_EXTENSION values via CustomActionData
21   customData = Session.Property("CustomActionData")
22   msiProperties = split(customData,";@;")
23   InstallDir = msiProperties(0)
24   ShibFileExtension = msiProperties(1)
25
26   'Remove all trailing backslashes to normalize
27   do while (mid(InstallDir,Len(InstallDir),1) = "\")
28     InstallDir = mid(InstallDir,1,Len(InstallDir)-1)
29   loop
30   ShibISAPIPath = InstallDir & "\lib\shibboleth\isapi_shib.dll"
31   'Make sure ShibFileExtension is in proper format
32   'First, strip any preceding periods
33   do while (mid(ShibFileExtension,1,1) = ".")
34     ShibFileExtension = mid(ShibFileExtension,2,Len(ShibFileExtension)-1)
35   loop
36   'If there is nothing left (or was nothing to begin with), use the default
37   if (ShibFileExtension = "") then
38     ShibFileExtension = ".sso"
39   else
40     'Add preceding period
41     ShibFileExtension = "." & ShibFileExtension
42   end if
43
44   'Specify other ISAPI Filter details
45   FilterName = "Shibboleth"
46   FilterPath = ShibISAPIPath
47   FilterDesc = ""
48
49   Set FiltersObj = GetObject("IIS://LocalHost/W3SVC/Filters")
50   LoadOrder = FiltersObj.FilterLoadOrder
51   'Check to see if 'Shibboleth' is already sequenced
52   existsFlag = "not_exist"
53   lineArray = split(LoadOrder, ",")
54   for each line in lineArray
55     if (line = FilterName) then
56       existsFlag = "exists"
57     end if
58   next
59   if (existsFlag = "not_exist") then
60     If LoadOrder <> "" Then
61       LoadOrder = LoadOrder & ","
62     End If
63     LoadOrder = LoadOrder & FilterName
64     FiltersObj.FilterLoadOrder = LoadOrder
65     FiltersObj.SetInfo
66   else
67     'msgbox "Shib Filter already sequenced"
68   end if
69
70   Set FilterObj = FiltersObj.Create("IIsFilter", FilterName)
71   If (Err <> 0) then
72     'Open existing filter for updating
73     Err = 0
74     Set FilterObj = GetObject("IIS://LocalHost/W3SVC/Filters/" & FilterName)
75   End If
76   FilterObj.FilterPath = FilterPath
77   FilterObj.FilterDescription = FilterDesc
78   FilterObj.SetInfo
79
80   'Create file extension mapping to ISAPI filter
81   newScriptLine = ShibFileExtension & "," & ShibISAPIPath & ",1"
82   ScriptMaps = WebObj.ScriptMaps
83   'Check if exists
84   existsFlag = "not_exist"
85   lineIndex = 0
86   for each line in ScriptMaps
87     lineArray = split(line,",")
88     if (lineArray(0) = ShibFileExtension) then
89       existsFlag = "exists"
90       Exit For
91     end if
92     lineIndex = lineIndex + 1
93   next
94   if (existsFlag = "not_exist") then
95     redim preserve ScriptMaps(UBound(ScriptMaps)+1)
96     ScriptMaps(UBound(ScriptMaps)) = newScriptLine
97     WebObj.ScriptMaps = ScriptMaps
98     WebObj.SetInfo
99   else
100     'msgbox ".sso already exists: " & lineIndex
101     'We already warned user in dialog that this value would be updated
102     ScriptMaps(lineIndex) = newScriptLine
103     WebObj.ScriptMaps = ScriptMaps
104     WebObj.SetInfo
105   end if
106
107   'Create file extension mapping to filter on each web site root
108   For Each WebSite in WebObj
109     Set WebSiteRoot = GetObject(WebSite.ADsPath & "/ROOT")
110     if (Err = 0) then
111       ScriptMaps = WebSiteRoot.ScriptMaps
112       'Check if exists
113       existsFlag = "not_exist"
114       lineIndex = 0
115       for each line in ScriptMaps
116         lineArray = split(line,",")
117         if (lineArray(0) = ShibFileExtension) then
118           existsFlag = "exists"
119           Exit For
120         end if
121         lineIndex = lineIndex + 1
122       next
123       if (existsFlag = "not_exist") then
124         redim preserve ScriptMaps(UBound(ScriptMaps)+1)
125         ScriptMaps(UBound(ScriptMaps)) = newScriptLine
126         WebSiteRoot.ScriptMaps = ScriptMaps
127         WebSiteRoot.SetInfo
128       else
129         'msgbox ".sso already exists: " & lineIndex
130         'We already warned user in dialog that this value would be updated
131         ScriptMaps(lineIndex) = newScriptLine
132         WebSiteRoot.ScriptMaps = ScriptMaps
133         WebSiteRoot.SetInfo
134       end if
135     End If
136   Next
137
138
139   'Web Services Extension
140   Err = 0
141   WebSvcExts = WebObj.WebSvcExtRestrictionList
142   if (Err = 0) then
143     newWebSvcExtLine = "1," & ShibISAPIPath & ",1,ShibGroup,Shibboleth Web Service Extension"
144
145     existsFlag = "not_exist"
146     lineIndex = 0
147     for each line in WebSvcExts
148       lineArray = split(line,",")
149       if (lineArray(1) = ShibISAPIPath) then
150         existsFlag = "exists"
151         Exit For
152       end if
153       lineIndex = lineIndex + 1
154     next
155
156     if (existsFlag = "not_exist") then
157       redim preserve WebSvcExts(UBound(WebSvcExts)+1)
158       WebSvcExts(UBound(WebSVCExts)) = newWebSvcExtLine
159       WebObj.WebSvcExtRestrictionList = WebSvcExts
160       WebObj.SetInfo
161     else
162       'msgbox "Shibboleth Web Services Extension already exists: " & lineIndex
163       'We already warned user in dialog that this value would be updated
164       WebSvcExts(lineIndex) = newWebSvcExtLine
165       WebObj.WebSvcExtRestrictionList = WebSvcExts
166       WebObj.SetInfo
167     end if
168
169   end if
170
171 'final end if
172 end if