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