upload tomcat
[bottlenecks.git] / rubbos / app / tomcat-connectors-1.2.32-src / native / iis / isapi_install.vbs
1 '
2 ' Licensed to the Apache Software Foundation (ASF) under one or more
3 ' contributor license agreements.  See the NOTICE file distributed with
4 ' this work for additional information regarding copyright ownership.
5 ' The ASF licenses this file to You under the Apache License, Version 2.0
6 ' (the "License"); you may not use this file except in compliance with
7 ' the License.  You may obtain a copy of the License at
8 '
9 '     http://www.apache.org/licenses/LICENSE-2.0
10 '
11 ' Unless required by applicable law or agreed to in writing, software
12 ' distributed under the License is distributed on an "AS IS" BASIS,
13 ' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ' See the License for the specific language governing permissions and
15 ' limitations under the License.
16 '
17
18 ' =========================================================================
19 ' Description: Install script for Tomcat ISAPI redirector                              
20 ' Author:      Peter S. Horne <horneps@yahoo.com.au>                           
21 ' Version:     $Revision: 572120 $                                           
22 ' =========================================================================
23 '
24 ' This script automatically installs the tomcat isapi_redirector for use in
25 ' both out-of and in-process installations on IIS/Win2K. See the command line
26 ' usage section for usage instructions.
27
28 '
29 '  Check the command line
30 '
31 set args = wscript.arguments
32 if args.count <> 6 then 
33         info ""
34         info "Tomcat ISAPI Redirector Installation Utility"
35         info "usage: isapi_install <server> <fdir> <worker> <mount> <log> <level>"
36         info "  server: The Web Server Name (for example 'Default Web Site')"
37         info "  fdir:   the full path to the directory that contains the isapi filter"
38         info "  worker: Full path and file name of the worker properties file"
39         info "  mount:  Full path and file name of the worker mount properties file"
40         info "  log:    Full path and file name of the log file"
41         info "  level:  The log level emerg | info"
42         info "(Re-runs are ok and will change/reset settings)"
43         info ""
44         fail "Incorrect Arguments"
45 end if
46
47 ' Setup the args
48 serverName = args(0)
49 filterDir = args(1)
50 filterName = "jakarta"
51 filterLib = "\isapi_redirect.dll"
52 workerFile = args(2)
53 mountFile = args(3)
54 logFile = args(4)
55 logLevel = args(5)
56
57 '
58 ' Get a shell
59 '
60 dim shell
61 set shell = WScript.CreateObject("WScript.Shell")
62
63 '
64 ' Find the indicated server from all the servers in the service 
65 ' Note: they aren't all Web!
66 '
67 set service = GetObject("IIS://LocalHost/W3SVC" )
68 serverId = ""
69 for each thing in service
70          if thing.Class = "IIsWebServer" then
71                 if thing.ServerComment = serverName then 
72                         set server = thing
73                         serverId = thing.name
74                         exit for
75                 end if
76         end if
77 next
78 if serverId = "" then fail "Server " + serverName + " not found."
79 info "Found Server <" + serverName + "> at index [" + serverId + "]."
80
81 '
82 ' Stop everything to release any dlls - needed for a re-install
83 '
84 ' info "Stopping server <" + serverName + ">..."
85 ' server.stop
86 ' info "Done"
87
88 '
89 ' Get a handle to the filters for the server - we process all errors
90 '
91 On Error Resume Next
92 dim filters
93 set filters = GetObject("IIS://LocalHost/W3SVC/" + serverId + "/Filters")
94 if err then 
95         err.clear
96         info "Filters not found for server - creating"
97         set filters = server.create( "IIsFilters", "Filters" )
98         filters.setInfo
99         if err then fail "Error Creating Filters"
100 end if
101 info "Got Filters"
102
103 '
104 ' Create the filter - if it fails then delete it and try again
105 '
106 name = filterName
107 info "Creating Filter  - " + filterName
108 dim filter
109 set filter = filters.Create( "IISFilter", filterName )
110 if err then
111         err.clear
112         info "Filter exists - deleting"
113         filters.delete "IISFilter", filterName
114         if err then fail "Error Deleting Filter"
115         set filter = filters.Create( "IISFilter", filterName )
116         if err then fail "Error Creating Filter"
117 end if
118 info "Created Filter"
119
120 '
121 ' Set the filter info and save it
122 '
123 filter.FilterPath = filterDir + filterLib  
124 filter.FilterEnabled=true
125 filter.description = filterName
126 filter.notifyOrderHigh = true
127 filter.setInfo
128
129 '
130 ' Set the load order - only if it's not in the list already
131 '
132 on error goto 0
133 loadOrders = filters.FilterLoadOrder
134 list = Split( loadOrders, "," )
135 found = false
136 for each item in list
137         if Trim( item ) = filterName then found = true
138 next
139
140 if found = false then 
141         info "Filter is not in load order - adding now."
142         if len(loadOrders) <> 0  then loadOrders = loadOrders + ","
143         filters.FilterLoadOrder = loadOrders + filterName
144         filters.setInfo
145         info "Filter added."
146 else
147         info "Filter already exists in load order - no update required."
148 end if
149
150 '
151 ' Set the registry up
152
153 regRoot = "HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\Jakarta Isapi Redirector\1.0\"
154 err.clear
155 on error resume next
156 shell.RegDelete( regRoot )
157 if err then 
158         info "Entering Registry Information for the first time"
159 else 
160         info "Deleted existing Registry Setting"
161 end if
162
163 on error goto 0
164 info "Updating Registry"
165 shell.RegWrite regRoot + "extension_uri", "/jakarta/isapi_redirect.dll"
166 shell.RegWrite regRoot + "log_file", logFile
167 shell.RegWrite regRoot + "log_level", logLevel
168 shell.RegWrite regRoot + "worker_file", workerFile
169 shell.RegWrite regRoot + "worker_mount_file", mountFile
170 info "Registry Settings Created"
171
172 '
173 ' Finally, create the virtual directory matching th extension uri
174
175 on error goto 0
176 set root = GetObject( "IIS://LocalHost/W3SVC/" + serverID + "/ROOT" )
177 on error resume next
178 set vdir = root.Create("IISWebVirtualDir", filterName )
179 if err then
180         info "Directory exists - deleting"
181         on error resume next
182         root.delete "IISWebVirtualDir", filterName
183         root.setInfo
184         if err then fail "Error Deleting Directory"
185         set vdir = root.create("IISWebVirtualDir", filterName )
186         if err then fail "Error Creating Directory"
187 end if
188 info "Directory Created"
189
190 ' Set the directory information - make it an application directory
191 info "Setting Directory Information"
192 vdir.AppCreate2 1
193 vdir.AccessExecute = TRUE
194 vdir.AppFriendlyName = filterName
195 vdir.AccessRead = false
196 vdir.ContentIndexed = false
197 vdir.Path = filterDir
198 vdir.setInfo
199 if err then fail "Error saving new directory"
200 info "Directory Saved"
201 '
202 ' Re Start 
203 '
204 ' info "Starting server <" + serverName + ">..."
205 ' server.start
206 ' info "Done"
207
208 info "All done... Bye."
209 wscript.quit(0)
210
211
212 ' Helper function for snafus
213 '
214 function fail( message )
215         wscript.echo "E: " + message
216         wscript.quit(1)
217 end function
218
219 '
220 ' Helper function for info
221 '
222 function info( message )
223         wscript.echo " " + message
224 end function