Initial check-in of install action scripts.
[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
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 & "\libexec\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   ScriptMaps = WebObj.ScriptMaps
82   'Check if exists
83   newScriptLine = ShibFileExtension & "," & ShibISAPIPath & ",1"
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
108   'Web Services Extension
109   Err = 0
110   WebSvcExts = WebObj.WebSvcExtRestrictionList
111   if (Err = 0) then
112   newWebSvcExtLine = "1," & ShibISAPIPath & ",1,ShibGroup,Shibboleth Web Service Extension"
113
114     existsFlag = "not_exist"
115     lineIndex = 0
116     for each line in WebSvcExts
117       lineArray = split(line,",")
118       if (lineArray(1) = ShibISAPIPath) then
119         existsFlag = "exists"
120         Exit For
121       end if
122       lineIndex = lineIndex + 1
123     next
124
125     if (existsFlag = "not_exist") then
126       redim preserve WebSvcExts(UBound(WebSvcExts)+1)
127       WebSvcExts(UBound(WebSVCExts)) = newWebSvcExtLine
128       WebObj.WebSvcExtRestrictionList = WebSvcExts
129       WebObj.SetInfo
130     else
131       'msgbox "Shibboleth Web Services Extension already exists: " & lineIndex
132       'We already warned user in dialog that this value would be updated
133       WebSvcExts(lineIndex) = newWebSvcExtLine
134       WebObj.WebSvcExtRestrictionList = WebSvcExts
135       WebObj.SetInfo
136     end if
137
138   end if
139
140 'final end if
141 end if