77810bb2a9ee6c7d9e3ebf6750f22f00090c9216
[shibboleth/cpp-sp.git] / msi / scripts / shib_uninstall_isapi_filter.vbs-wix
1 Sub DeleteISAPIFilters(IISPath,dllPath)\r
2 \r
3   Dim filter, FiltersObj, LoadOrder, FilterArray, FilterItem\r
4 \r
5   Set FiltersObj = GetObject(IISPath & "/Filters")\r
6   LoadOrder = FiltersObj.FilterLoadOrder\r
7 \r
8   for each filter in FiltersObj\r
9     if (filter.Class = "IIsFilter") then\r
10       if (filter.FilterPath = dllPath) then\r
11 \r
12         'Delete the found filter here\r
13         'If there's anything to potentially delete...\r
14         if (LoadOrder <> "") then\r
15           FilterArray = split(LoadOrder,",")\r
16           LoadOrder = ""\r
17           for each FilterItem in FilterArray\r
18             if (FilterItem <> filter.Name) then\r
19               LoadOrder = LoadOrder & FilterItem & ","\r
20             end if\r
21           next\r
22           'Remove trailing comma if any filters were kept\r
23           if (LoadOrder <> "") then\r
24             LoadOrder = mid(LoadOrder,1,len(LoadOrder)-1)\r
25           end if\r
26 \r
27           'Set the Load Order to the new shibboleth-less order\r
28           if (FiltersObj.FilterLoadOrder <> LoadOrder) then\r
29             FiltersObj.FilterLoadOrder = LoadOrder\r
30             FiltersObj.SetInfo\r
31           end if\r
32         end if\r
33 \r
34         'Delete the actual IISFilter object\r
35         FiltersObj.Delete "IIsFilter",filter.Name\r
36 \r
37       end if\r
38     end if\r
39   next\r
40 \r
41 End Sub\r
42 \r
43 \r
44 Sub DeleteFileExtensions(siteObj, dllPath)\r
45 \r
46 Dim ScriptMaps, newScriptMaps\r
47 Dim line, lineArray, lineIndex\r
48 Dim fileExtension\r
49 Dim existsFlag\r
50 \r
51   ScriptMaps = siteObj.ScriptMaps\r
52   redim newScriptMaps(0)\r
53   lineIndex = 0\r
54   'copy each entry from the old ScriptMaps to newScriptMaps\r
55   'unless it is for dllPath\r
56   for each line in ScriptMaps\r
57     lineArray = split(line,",")\r
58     if (lineArray(1) <> dllPath) then\r
59       redim preserve newScriptMaps(lineIndex)\r
60       newScriptMaps(lineIndex) = line\r
61       lineIndex = lineIndex + 1\r
62     else\r
63       existsFlag = "exists"\r
64     end if\r
65   next\r
66   'If we found dllPath, then use the newScriptMaps instead\r
67   if (existsFlag = "exists") then\r
68     siteObj.ScriptMaps = newScriptMaps\r
69     siteObj.SetInfo\r
70   end if\r
71 \r
72 End Sub\r
73 \r
74 \r
75 '*** Begin Main Code ***\r
76 Dim WebObj\r
77 Dim InstallDir\r
78 Dim FileSystemObj\r
79 Dim ShibISAPIPath\r
80 Dim site, siteObj, sitePath, LogFile\r
81 \r
82 ' First of all look for the FileExtension\r
83 Set WshShell = CreateObject("WScript.Shell")\r
84 \r
85 'Get the INSTALLDIR value via CustomActionData\r
86 InstallDir = Session.Property("CustomActionData")\r
87 \r
88 Set FileSystemObj = CreateObject("Scripting.FileSystemObject")\r
89 \r
90 'Set LogFile = FileSystemObj.OpenTextFile(InstallDir & "\var\log\shibboleth\Installer.log", 8, true)\r
91 \r
92 On Error Resume Next\r
93 regValue = WshShell.RegRead("HKLM\SOFTWARE\Shibboleth\FileExtension")\r
94 if (Err = 0) then\r
95 \r
96  ' If (LogFile) then\r
97   '   LogFile.WriteLine "Uninstall IIS plugin - upgrade detected by uninstall script, skipping"\r
98   'End If\r
99   ' Registry key is still there - this is an upgrade, so exit\r
100 \r
101 else \r
102   ' Key is gone - a pure uninstall\r
103   'If (LogFile) then\r
104    '  LogFile.WriteLine "Uninstall IIS plugin"\r
105   'End If\r
106  \r
107   'Don't show errors, we'll handle anything important\r
108   On Error Resume Next\r
109 \r
110   'Attempt to get W3SVC.  If failure, end script (e.g. IIS isn't available)\r
111   Set WebObj = GetObject("IIS://LocalHost/W3SVC")\r
112   if (Err = 0) then\r
113 \r
114     'Remove all trailing backslashes to normalize\r
115     do while (mid(InstallDir,Len(InstallDir),1) = "\")\r
116       InstallDir = mid(InstallDir,1,Len(InstallDir)-1)\r
117     loop\r
118     ShibISAPIPath = InstallDir & "\lib\shibboleth\isapi_shib.dll"\r
119 \r
120     'Delete ISAPI Filter\r
121     'First do the master service\r
122     DeleteISAPIFilters "IIS://LocalHost/W3SVC",ShibISAPIPath\r
123     'Now do the websites\r
124     for each site in WebObj\r
125       if (site.Class = "IIsWebServer") then\r
126         sitePath = "IIS://LocalHost/W3SVC/" & site.Name\r
127         DeleteISAPIFilters sitePath,ShibISAPIPath\r
128       end if\r
129     next\r
130 \r
131     'Delete File Extensions\r
132     'First do the master service\r
133     DeleteFileExtensions WebObj,ShibISAPIPath\r
134     'Now do the websites\r
135     for each site in WebObj\r
136       if (site.Class = "IIsWebServer") then\r
137         set siteObj = GetObject("IIS://LocalHost/W3SVC/" & site.Name & "/ROOT")\r
138         DeleteFileExtensions siteObj,ShibISAPIPath\r
139       end if\r
140     next\r
141 \r
142     'Delete Web Services Extension (universal, no need to do for each site)\r
143     WebObj.DeleteExtensionFileRecord ShibISAPIPath\r
144   ' Got the IIS Object\r
145   End If\r
146 ' Sense whether this is an upgrade\r
147 end if