Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1073 lines
37 KiB

  1. '
  2. ' createwebsite.vbs: Configure IIS Websites for the SAK
  3. '
  4. ' Copyright (c) 2002 Microsoft Corporation
  5. '
  6. 'Constants
  7. const NS_IIS = "IIS://"
  8. const ADMIN_ID = 1
  9. const SHARES_ID = 2
  10. const ADMIN_SITE_NAME = "Administration"
  11. const SHARES_SITE_NAME = "Shares"
  12. const ADS_PROPERTY_UPDATE = 2
  13. 'registry keys
  14. const REGKEY_WEBFRAMEWORK = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ServerAppliance\WebFramework\"
  15. const CONST_TYPE_DWORD ="REG_DWORD"
  16. 'This array is messy, but a necessary evil. If a file is added to the Shares site, at it here
  17. Dim arrSharesFiles(95)
  18. arrSharesFiles(0) = "autoconfiglang.asp"
  19. arrSharesFiles(1) = "inc_accountsgroups.asp"
  20. arrSharesFiles(2) = "inc_base.asp"
  21. arrSharesFiles(3) = "inc_debug.asp"
  22. arrSharesFiles(4) = "inc_errorcode.asp"
  23. arrSharesFiles(5) = "inc_framework.asp"
  24. arrSharesFiles(6) = "inc_global.asp"
  25. arrSharesFiles(7) = "inc_global.js"
  26. arrSharesFiles(8) = "inc_pagekey.asp"
  27. arrSharesFiles(9) = "inc_registry.asp"
  28. arrSharesFiles(10) = "ots_taskview.js"
  29. arrSharesFiles(11) = "sh_alertdetails.asp"
  30. arrSharesFiles(12) = "sh_alertpanel.asp"
  31. arrSharesFiles(13) = "sh_defaultfooter.asp"
  32. arrSharesFiles(14) = "sh_fileupload.asp"
  33. arrSharesFiles(15) = "sh_page.asp"
  34. arrSharesFiles(16) = "sh_page.js"
  35. arrSharesFiles(17) = "sh_propfooter.asp"
  36. arrSharesFiles(18) = "sh_resourcepanel.asp"
  37. arrSharesFiles(19) = "sh_restarting.asp"
  38. arrSharesFiles(20) = "sh_statusbar.asp"
  39. arrSharesFiles(21) = "sh_statusdetails.asp"
  40. arrSharesFiles(22) = "sh_task.asp"
  41. arrSharesFiles(23) = "sh_task.js"
  42. arrSharesFiles(24) = "sh_taskframes.asp"
  43. arrSharesFiles(25) = "sh_tasks.asp"
  44. arrSharesFiles(26) = "sh_tree.asp"
  45. arrSharesFiles(27) = "sh_wizardfooter.asp"
  46. arrSharesFiles(28) = "style\mssastyles.css"
  47. arrSharesFiles(29) = "images\aboutbox_logo.gif"
  48. arrSharesFiles(30) = "images\alert.gif"
  49. arrSharesFiles(31) = "images\AlertEmailX32.gif"
  50. arrSharesFiles(32) = "images\alert_white.gif"
  51. arrSharesFiles(33) = "images\arrow_green.gif"
  52. arrSharesFiles(34) = "images\arrow_red.gif"
  53. arrSharesFiles(35) = "images\arrow_silver.gif"
  54. arrSharesFiles(36) = "images\arrow_yellow.gif"
  55. arrSharesFiles(37) = "images\BackupX32.gif"
  56. arrSharesFiles(38) = "images\book_closed.gif"
  57. arrSharesFiles(39) = "images\book_opened.gif"
  58. arrSharesFiles(40) = "images\book_page.gif"
  59. arrSharesFiles(41) = "images\butGreenArrow.gif"
  60. arrSharesFiles(42) = "images\butGreenArrowDisabled.gif"
  61. arrSharesFiles(43) = "images\butGreenArrowLeft.gif"
  62. arrSharesFiles(44) = "images\butGreenArrowLeftDisabled.gif"
  63. arrSharesFiles(45) = "images\butPageNextDisabled.gif"
  64. arrSharesFiles(46) = "images\butPageNextEnabled.gif"
  65. arrSharesFiles(47) = "images\butPagePreviousDisabled.gif"
  66. arrSharesFiles(48) = "images\butPagePreviousEnabled.gif"
  67. arrSharesFiles(49) = "images\butRedX.gif"
  68. arrSharesFiles(50) = "images\butRedXDisabled.gif"
  69. arrSharesFiles(51) = "images\butSearchDisabled.gif"
  70. arrSharesFiles(52) = "images\butSearchEnabled.gif"
  71. arrSharesFiles(53) = "images\butSortAscending.gif"
  72. arrSharesFiles(54) = "images\butSortDescending.gif"
  73. arrSharesFiles(55) = "images\CommunityX32.gif"
  74. arrSharesFiles(56) = "images\configure_32x32.gif"
  75. arrSharesFiles(57) = "images\critical_error.gif"
  76. arrSharesFiles(58) = "images\critical_errorX32.gif"
  77. arrSharesFiles(59) = "images\DateTimeX32.gif"
  78. arrSharesFiles(60) = "images\datetime_icon.gif"
  79. arrSharesFiles(61) = "images\dir.gif"
  80. arrSharesFiles(62) = "images\disks.gif"
  81. arrSharesFiles(63) = "images\disks_32x32.gif"
  82. arrSharesFiles(64) = "images\down.gif"
  83. arrSharesFiles(65) = "images\drive.gif"
  84. arrSharesFiles(66) = "images\EventLogX32.gif"
  85. arrSharesFiles(67) = "images\example_logo.gif"
  86. arrSharesFiles(68) = "images\file.gif"
  87. arrSharesFiles(69) = "images\folder.gif"
  88. arrSharesFiles(70) = "images\folder_32x32.gif"
  89. arrSharesFiles(71) = "images\green_arrow.gif"
  90. arrSharesFiles(72) = "images\help_32x32.gif"
  91. arrSharesFiles(73) = "images\information.gif"
  92. arrSharesFiles(74) = "images\maintenance.gif"
  93. arrSharesFiles(75) = "images\maintenance_32x32.gif"
  94. arrSharesFiles(76) = "images\network.gif"
  95. arrSharesFiles(77) = "images\network_32x32.gif"
  96. arrSharesFiles(78) = "images\node_close.gif"
  97. arrSharesFiles(79) = "images\node_open.gif"
  98. arrSharesFiles(80) = "images\oem_logo.gif"
  99. arrSharesFiles(81) = "images\OpenFolderX16.gif"
  100. arrSharesFiles(82) = "images\server.gif"
  101. arrSharesFiles(83) = "images\services.gif"
  102. arrSharesFiles(84) = "images\services_32x32.gif"
  103. arrSharesFiles(85) = "images\ShutdownX32.gif"
  104. arrSharesFiles(86) = "images\SoftwareUpdateX32.gif"
  105. arrSharesFiles(87) = "images\StatusBarBreak.gif"
  106. arrSharesFiles(88) = "images\TabSeparator.gif"
  107. arrSharesFiles(89) = "images\TerminalServiceX32.gif"
  108. arrSharesFiles(90) = "images\up.gif"
  109. arrSharesFiles(91) = "images\updir.gif"
  110. arrSharesFiles(92) = "images\users.gif"
  111. arrSharesFiles(93) = "images\users_32x32.gif"
  112. arrSharesFiles(94) = "images\winnte_logo.gif"
  113. arrSharesFiles(95) = "images\WinPwr_h_R.gif"
  114. Function CreateAdminSite
  115. Call CreateWebsite(ADMIN_ID)
  116. End Function
  117. Function CreateSharesSite
  118. Call CreateWebsite(SHARES_ID)
  119. End Function
  120. Function CreateWebsite(nType)
  121. On Error Resume Next
  122. Dim strSystemDir
  123. Dim strSystemDrive
  124. Set WshShell = CreateObject("WScript.Shell")
  125. strSystemDrive = WshShell.ExpandEnvironmentStrings("%SystemDrive%")
  126. Set objEnv = WshShell.Environment("Process")
  127. if (nType = ADMIN_ID) then
  128. Call CreateWebSrv( "localhost", ":8099:", ":8098:", ADMIN_SITE_NAME, objEnv("SYSTEMROOT") + "\system32\serverappliance\web", ADMIN_ID)
  129. Call WriteAdminServerRegistryEntries(WshShell)
  130. elseif (nType = SHARES_ID) then
  131. strSharesDir = GetSharesDirectory()
  132. ' Copy the files for the Shares site
  133. Call CopyFiles(strSharesDir)
  134. ' Create the website
  135. Call CreateWebSrv( "localhost", ":80:", ":443:", SHARES_SITE_NAME, strSharesDir, SHARES_ID)
  136. else
  137. 'Wscript.echo "Bad argument: " & nType
  138. end if
  139. Call UpdateMimeMap(nType)
  140. End Function
  141. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  142. ' Function WriteAdminServerRegistryEntries
  143. '
  144. ' Description:
  145. ' Writes the entries to the registry that will be used for the
  146. ' Administration web site ports
  147. '
  148. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  149. Function WriteAdminServerRegistryEntries(WshShell)
  150. On Error Resume Next
  151. WshShell.RegWrite REGKEY_WEBFRAMEWORK & "AdminPort", 8099, CONST_TYPE_DWORD
  152. WshShell.RegWrite REGKEY_WEBFRAMEWORK & "SSLAdminPort", 8098, CONST_TYPE_DWORD
  153. If Err.Number <> 0 Then
  154. Err.Clear
  155. End If
  156. End Function
  157. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  158. ' Function CreateTSWebVirtualDir
  159. '
  160. ' Description:
  161. ' Create a virtual directory for Terminal Server named 'tsweb' at
  162. ' %system32%\serverappliance\web\admin\tsweb
  163. '
  164. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  165. Function CreateTSWebVirtualDir(oAdminWebRoot, strWebDir)
  166. On Error Resume Next
  167. Set oTSWebDir = oAdminWebRoot.Create("IIsWebVirtualDir", "tsweb")
  168. Set WshShell = CreateObject("WScript.Shell")
  169. oTSWebDir.Path = strWebDir & "\admin\tsweb\"
  170. oTSWebDir.AccessRead = True
  171. oTSWebDir.AccessWrite = False
  172. oTSWebDir.AccessExecute = False
  173. oTSWebDir.AccessScript = False
  174. oTSWebDir.EnableDefaultDoc = False
  175. oTSWebDir.ContentIndexed = False
  176. oTSWebDir.SetInfo
  177. Set oTSWebDir = Nothing
  178. End Function
  179. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  180. ' Function CreateWebSrv
  181. '
  182. ' Parameters:
  183. ' sHost The name of the host of the server (ie. localhost)
  184. ' sServerBinding The port for non-secure connections
  185. ' sSecureBinding The SSL port
  186. ' sWebSrvName Name of the web site to be created (set as the ServerComment property)
  187. ' sPath Physical path to the root of the web site
  188. ' siteType ADMIN_ID or SHARES_ID
  189. '
  190. ' Description:
  191. ' Creates a website and sets the properties on the site according
  192. ' to what is necessary for Administration or Shares sites. There are
  193. ' small differences between settings on the sites. For example,
  194. ' SHARES_ID has a number of differences between the Administration sites.
  195. '
  196. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  197. Function CreateWebSrv(sHost , sServerBinding , sSecureBinding, sWebSrvName , sPath, siteType)
  198. On Error Resume Next
  199. g_sErrInfo = ""
  200. g_bCancel = False
  201. 'Wscript.echo "Creating " & sWebSrvName & " website at " & sPath
  202. Dim oWebSvc , oWebSrv , oWebRoot , oFs , iWebSrvNum , asServerBindings
  203. Dim strWebSiteRegValue : strWebSiteRegValue = REGKEY_WEBFRAMEWORK & sWebSrvName & "SiteID"
  204. asServerBindings = Array(0)
  205. asServerBindings(0) = sServerBinding
  206. If (sHost = "" Or asServerBindings(0) = "" Or sWebSrvName = "") Then
  207. g_sErrInfo = "A required parameter was passed incorrectly."
  208. CreateWebSrv = 1
  209. Exit Function
  210. End If
  211. '
  212. ' Check to see if the website already exists
  213. '
  214. Set WshShell = CreateObject("WScript.Shell")
  215. nSiteID = WshShell.RegRead(strWebSiteRegValue)
  216. If (nSiteID <> 0) Then
  217. Set oWebSite = GetObject(NS_IIS & sHost & "/w3svc/" & nSiteID)
  218. If Err.number = 0 Then
  219. 'The website already exists
  220. Exit Function
  221. End If
  222. Err.Clear
  223. End If
  224. Set oWebSvc = GetObject(NS_IIS & sHost & "/w3svc")
  225. 'Get the next available Web server name [number]
  226. iWebSrvNum = GetNextWebSrvNum(sHost)
  227. 'Create the web site
  228. Set oWebSrv = oWebSvc.Create("IIsWebServer", CStr(iWebSrvNum))
  229. If Err.Number <> 0 Then
  230. 'wscript.echo "Error creating website " & sWebSrvName & " at " & iWebSrvNum
  231. Exit Function
  232. End If
  233. '
  234. ' Set the settings for the new web site
  235. '
  236. oWebSrv.ServerSize = 1 '// fewer than 100k Or medium sized server
  237. '// Should I do this for the Admin sites??
  238. ' Set the non-secure port binding
  239. oWebSrv.ServerBindings = sServerBinding
  240. ' Set the SSL Port
  241. oWebSrv.SecureBindings = sSecureBinding
  242. ' Require the SSL Port
  243. oWebSrv.AccessSSL = True
  244. ' Other web site settings
  245. oWebSrv.AspEnableParentPaths = False
  246. oWebSrv.AspScriptLanguage = "VBScript"
  247. oWebSrv.DefaultDoc = "Default.asp"
  248. oWebSrv.ServerComment = sWebSrvName
  249. oWebSrv.AuthAnonymous = False
  250. If siteType = SHARES_ID Then
  251. oWebSrv.AuthBasic = False
  252. oWebSrv.AuthNTLM = True
  253. Else
  254. oWebSrv.AuthBasic = True
  255. oWebSrv.AuthNTLM = False
  256. End If
  257. oWebSrv.SetInfo
  258. '// Ensure physical Path exists
  259. Set oFs = CreateObject("Scripting.FileSystemObject")
  260. If Not (oFs.FolderExists(sPath)) Then
  261. Call oFs.CreateFolder(sPath)
  262. End If
  263. Set oWebRoot = oWebSrv.Create("IIsWebVirtualDir", "Root")
  264. oWebRoot.Path = sPath
  265. Set oFs = Nothing
  266. oWebRoot.AccessRead = True
  267. If (siteType = SHARES_ID) Then
  268. oWebRoot.AccessWrite = True
  269. Else
  270. oWebRoot.AccessWrite = False
  271. End If
  272. oWebRoot.AccessExecute = False
  273. oWebRoot.AccessScript = True
  274. oWebRoot.AppCreate (True)
  275. oWebRoot.AppFriendlyName = "Default Application"
  276. oWebRoot.SetInfo
  277. '
  278. ' If we're creating the Administration site, make the necessary
  279. ' adjustments to enable ASP globally
  280. ' and create a virtual dir for tsweb
  281. '
  282. If (siteType = ADMIN_ID) Then
  283. Call EnableASPForAllSites(sHost, WshShell)
  284. Call CreateTSWebVirtualDir(oWebRoot, sPath)
  285. End If
  286. Set oWebRoot = Nothing
  287. Set oWebSrv = Nothing
  288. Set oWebSvc = Nothing
  289. CreateWebSrv = iWebSrvNum
  290. Call WshShell.RegWrite(strWebSiteRegValue, iWebSrvNum, CONST_TYPE_DWORD)
  291. Exit Function
  292. ErrorHandler:
  293. g_sErrInfo = Err.Number - vbObjectError & ", " & Err.Description & ", " & Err.LastDllError
  294. CreateWebSrv = 1
  295. End Function
  296. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  297. ' Function EnableASPForAllSites
  298. '
  299. ' Parameters:
  300. ' sHost The name of the host of the server (ie. localhost)
  301. ' WshShell Shell object
  302. '
  303. ' Description:
  304. ' Add Remote Admin Tools to the list of Applications that use ASP
  305. '
  306. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  307. Function EnableASPForAllSites(sHost, WshShell)
  308. On Error Resume Next
  309. strProduct = Session.Property("CustomActionData")
  310. Set IIS = GetObject(NS_IIS & sHost & "/w3svc")
  311. '
  312. ' Detect if asp is currently in the list of ISAPIs
  313. '
  314. Dim bFound : bFound = False
  315. 'Search for Remote Admin Tools in ApplicationDependencies
  316. appDepend = IIS.ApplicationDependencies
  317. For i=0 To UBound(appDepend)
  318. If instr(1,appDepend(i),strProduct) > 0 Then
  319. 'ASP was already added to Remote Admin Tools
  320. bFound = True
  321. Exit For
  322. End If
  323. Next
  324. 'If Remote Admin Tools wasn't found in the dependencies on ASP, add it
  325. If Not bFound Then
  326. ' Add ASP as a dependency for Remote Admin Tools
  327. ReDim Preserve appDepend(UBound(appDepend)+1)
  328. appDepend(UBound(appDepend)) = strProduct & ";ASP"
  329. 'Save the entry back to the metabase
  330. IIS.ApplicationDependencies = appDepend
  331. IIS.SetInfo
  332. End If
  333. 'Now modify asp.dll to be allowed in WebSvcExtRestrictionList
  334. webExt = IIS.WebSvcExtRestrictionList
  335. strTurnedOn = "0"
  336. For i=0 To UBound(webExt)
  337. If instr(1,webExt(i),"asp.dll") > 0 Then
  338. If Left(webExt(i), 1) = "1" Then
  339. 'It's already on!
  340. Exit For
  341. End If
  342. 'ASP was already added to Remote Admin Tools
  343. webExt(i) = "1" & Right(webExt(i), Len(webExt(i))-1)
  344. 'Set the new Restriction list with ASP turned on
  345. IIS.WebSvcExtRestrictionList = webExt
  346. IIS.SetInfo
  347. strTurnedOn = "1"
  348. Exit For
  349. End If
  350. Next
  351. Dim strTurnAspOn : strTurnAspOn = REGKEY_WEBFRAMEWORK & "ASPWasEnabled"
  352. Call WshShell.RegWrite(strTurnAspOn, strTurnedOn)
  353. End Function
  354. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  355. ' Function DisableASPForAllSites
  356. '
  357. ' Parameters:
  358. ' sHost The name of the host of the server (ie. localhost)
  359. '
  360. ' Description:
  361. ' Remove Remote Admin Tools from the list of Applications that use ASP
  362. '
  363. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  364. Function DisableASPForAllSites(sHost)
  365. On Error Resume Next
  366. strProduct = Session.Property("CustomActionData")
  367. Set IIS = GetObject(NS_IIS & sHost & "/w3svc")
  368. '
  369. ' Remove Remote Admin Tools from list of dependencies on ASP
  370. '
  371. Dim bFound : bFound = False
  372. 'Search for Remote Admin Tools in ApplicationDependencies
  373. appDepend = IIS.ApplicationDependencies
  374. For i=0 To UBound(appDepend)
  375. If instr(1,appDepend(i),strProduct) > 0 Then
  376. 'Removing ASP dependency on Remote Admin Tools
  377. appDepend(i) = appDepend(UBound(appDepend))
  378. ReDim Preserve appDepend(UBound(appDepend)-1)
  379. IIS.ApplicationDependencies = appDepend
  380. IIS.SetInfo
  381. Exit For
  382. End If
  383. Next
  384. 'If we turned on ASP during install, turn it back off
  385. Dim strTurnAspOn : strTurnAspOn = REGKEY_WEBFRAMEWORK & "ASPWasEnabled"
  386. Set WshShell = CreateObject ("WScript.Shell")
  387. If WshShell.RegRead(strTurnAspOn) = "1" Then
  388. 'Search for ASP in WebSvcExtRestrictionList and turn it off
  389. webExt = IIS.WebSvcExtRestrictionList
  390. For i=0 To UBound(webExt)
  391. If instr(1,webExt(i),"asp.dll") > 0 Then
  392. If Left(webExt(i), 1) = "0" Then
  393. 'It's already off!
  394. Exit For
  395. End If
  396. webExt(i) = "0" & Right(webExt(i), Len(webExt(i))-1)
  397. 'Set the new Restriction list with ASP turned off
  398. IIS.WebSvcExtRestrictionList = webExt
  399. IIS.SetInfo
  400. Exit For
  401. End If
  402. Next
  403. End If
  404. WshShell.RegDelete(strTurnAspOn)
  405. End Function
  406. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  407. ' Function GetNextWebSrvNum
  408. '
  409. ' Parameters:
  410. ' sHost Localhost
  411. '
  412. ' Description:
  413. ' Searches for an available web site name, which will be of
  414. ' the form IIS://localhost/w3svc/1
  415. ' If 0 is returned, there was an error.
  416. ' It starts with a random number and increments it until it
  417. ' finds an available site
  418. '
  419. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  420. Function GetNextWebSrvNum( sHost )
  421. On Error Resume Next
  422. If (sHost = "") Then
  423. 'g_sErrInfo = "A required parameter was passed incorrectly."
  424. GetNextWebSrvNum = 0
  425. Exit Function
  426. End If
  427. Dim oWebSrv , iWebSrvNum, bContinue
  428. 'Start with a random site ID between 1 and 32000
  429. ' (The limiting number isn't really 32000, but we just need a big range)
  430. Randomize
  431. iWebSrvNum = CLng(32000 * Rnd + 1)
  432. bContinue = True
  433. '
  434. 'Try different site IDs until one is available
  435. ' (It is highly likely to succeed on the first try)
  436. '
  437. While bContinue
  438. Set oWebSrv = GetObject(NS_IIS & sHost & "/w3svc/" & iWebSrvNum)
  439. If Err.number <> 0 Then
  440. Err.Clear
  441. bContinue = False
  442. Else
  443. iWebSrvNum = iWebSrvNum + 1
  444. End If
  445. WEnd
  446. GetNextWebSrvNum = iWebSrvNum
  447. 'WScript.Echo "Site number: " & GetNextWebSrvNum
  448. End Function
  449. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  450. ' Function GetSharesDirectory
  451. '
  452. ' Description:
  453. ' Determines where the directory for the Shares web site will be
  454. ' ie. C:\SAShares
  455. ' It searches for the first available NTFS drive that is not the system
  456. ' drive. If there is not a drive besides the system drive, it will
  457. ' use the system drive.
  458. '
  459. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  460. Function GetSharesDirectory
  461. On Error Resume Next
  462. Dim WshShell, strSystemDrive
  463. Set WshShell = CreateObject("WScript.Shell")
  464. strWindowsDir = WshShell.ExpandEnvironmentStrings("%WinDir%")
  465. GetSharesDirectory = strWindowsDir & "\system32\ServerAppliance\SAShares"
  466. End Function
  467. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  468. ' Function CopyFiles
  469. '
  470. ' Description:
  471. ' This function copies the Shares Site files from the ServerAppliance
  472. ' Directory to the %systemdrive%\inetpub directory
  473. '
  474. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  475. Function CopyFiles(strTargetPath)
  476. On Error Resume Next
  477. Set oShell = CreateObject ("WScript.shell")
  478. Set objEnv = oShell.Environment("Process")
  479. strWebDir = objEnv("SYSTEMROOT") + "\system32\ServerAppliance\Web\Admin"
  480. 'The SAShares folder is created by the CreateFolder table and the ACLs are set
  481. ' to Administrators only, so we need to add User read/execute access
  482. Call AddUserReadACL(strTargetPath)
  483. Call oShell.Run("cmd.exe /C Mkdir " & strTargetPath & "\style",0, TRUE)
  484. Call oShell.Run("cmd.exe /C Mkdir " & strTargetPath & "\images",0, TRUE)
  485. strCopyCmd = "cmd.exe /C Copy " & strWebDir
  486. For i=0 To UBound(arrSharesFiles)
  487. Call oShell.Run(strCopyCmd & "\" & arrSharesFiles(i) & " " & strTargetPath & "\" & arrSharesFiles(i), 0, True)
  488. Next
  489. Call oShell.Run(strCopyCmd & "\Shares\sharessite.asp " & strTargetPath & "\default.asp",0, TRUE)
  490. Set oShell = Nothing
  491. End Function
  492. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  493. ' The administration web site needs to be deleted when the SAK is uninstalled.
  494. ' During uninstallation, all of the files at \winnt\system32\serverappliance\web
  495. ' directory are deleted, which is where the admin site points to. Therefore,
  496. ' there wouldn't be anything left for this web site to contain. Otherwise,
  497. ' an error would appear if the user went to the admin site in the IIS MMC snapin.
  498. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  499. Function DeleteAdminSite()
  500. On Error Resume Next
  501. DeleteSite(ADMIN_SITE_NAME)
  502. Call DisableASPForAllSites("localhost")
  503. End Function
  504. Function DeleteSharesSite()
  505. On Error Resume Next
  506. If DeleteSite(SHARES_SITE_NAME) Then
  507. 'If the Shares site was found and deleted, then delete the corresponding files
  508. Set oShell = CreateObject ("WScript.Shell")
  509. strSharesDir = GetSharesDirectory()
  510. strDeleteCmd = "cmd.exe /C del " & strSharesDir & "\"
  511. For i=0 To UBound(arrSharesFiles)
  512. Call oShell.Run(strDeleteCmd & arrSharesFiles(i), 0, True)
  513. Next
  514. Call oShell.Run(strDeleteCmd & "\default.asp",0, TRUE)
  515. Call oShell.Run(strDeleteCmd & "\SharesList.txt",0, TRUE)
  516. 'Attempt to remove directories will fail if they're not empty
  517. Call oShell.Run("cmd.exe /C rmdir " & strSharesDir & "\style", 0, TRUE)
  518. Call oShell.Run("cmd.exe /C rmdir " & strSharesDir & "\images", 0, TRUE)
  519. End If
  520. End Function
  521. Function StartDefaultSite()
  522. On Error Resume Next
  523. 'Restart the default site
  524. Set defaultSite = GetObject("IIS://localhost/w3svc/1")
  525. defaultSite.Start
  526. End Function
  527. Function DeleteSite(strSiteName)
  528. On Error Resume Next
  529. DeleteSite = False
  530. Set WshShell = CreateObject("WScript.Shell")
  531. Set webService = GetObject("IIS://localhost/w3svc")
  532. strWebSiteRegValue = REGKEY_WEBFRAMEWORK & strSiteName & "SiteID"
  533. nSiteID = WshShell.RegRead(strWebSiteRegValue)
  534. WshShell.RegDelete(strWebSiteRegValue)
  535. 'wscript.echo "Delete site: " & strSiteName & " at " & nSiteID
  536. If (nSiteID <> 0) Then
  537. Set oWebSite = GetObject(NS_IIS & "localhost/w3svc/" & nSiteID)
  538. If Err.number = 0 Then
  539. 'The website exists, so delete it
  540. webService.delete "IIsWebServer", oWebSite.Name
  541. DeleteSite = True
  542. End If
  543. End If
  544. End Function
  545. Function CreateServerIDProperty
  546. On Error Resume Next
  547. 'Create new ServerID property in the schema
  548. propName = "ServerID"
  549. '
  550. ' Check to see if the property already exists
  551. '
  552. Set prop = GetObject("IIS://localhost/schema/" & propName)
  553. If Err.Number = 0 Then
  554. 'wscript.echo "Property already exists: " & propName
  555. else
  556. 'wscript.echo "Property doesn't exist: " & propName
  557. '
  558. ' If the property doesn't exist, create it
  559. '
  560. Set schemaObj = GetObject("IIS://localhost/schema")
  561. Set newProp = schemaObj.Create("Property", propName)
  562. newProp.Syntax = "String"
  563. newProp.Default = ""
  564. newProp.SetInfo
  565. 'Link new property to the IIsWebServer class
  566. 'wscript.echo "Link to the IIsWebServer"
  567. Set webServerClass = GetObject("IIS://localhost/schema/IIsWebServer")
  568. Properties = webServerClass.OptionalProperties
  569. ReDim Preserve Properties(UBound(Properties) + 1)
  570. Properties(UBound(Properties)) = propName
  571. webServerClass.OptionalProperties = Properties
  572. webServerClass.SetInfo
  573. 'Link new property to the IIsFtpServer class
  574. 'wscript.echo "Link to the IIsFtpServer"
  575. Set ftpServerClass = GetObject("IIS://localhost/schema/IIsFtpServer")
  576. Properties = ftpServerClass.OptionalProperties
  577. ReDim Preserve Properties(UBound(Properties) + 1)
  578. Properties(UBound(Properties)) = propName
  579. ftpServerClass.OptionalProperties = Properties
  580. ftpServerClass.SetInfo
  581. '
  582. ' Flush the metabase and reload WMI so that this new
  583. ' property will appear through WMI calls.
  584. '
  585. 'wscript.echo "Flushing the metabase ..."
  586. set compObj = GetObject("IIS://localhost")
  587. compObj.SaveData()
  588. 'wscript.echo "Stopping winmgmt..."
  589. Set wShell = CreateObject ("WScript.shell")
  590. wShell.Run "net stop winmgmt /y",0, TRUE
  591. 'wscript.echo "Starting winmgmt..."
  592. wShell.Run "net start winmgmt",0, TRUE
  593. End If
  594. End Function
  595. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  596. ' DetectStoppedSites
  597. '
  598. ' Description:
  599. ' Detects whether the proper sites have been started as part
  600. ' of the installation process. In particular, the Administration
  601. ' and Shares sites are detected. The results are placed in the
  602. ' the registry as a REG_SZ called:
  603. ' HKLM\Software\Microsoft\ServerAppliance\WebFramework\StartSiteError
  604. ' It is then interpreted as a number, with each bit position
  605. ' representing whether a site is started.
  606. ' Bit 0 corresponds to the Administration site and
  607. ' Bit 1 corresponds to the Shares site.
  608. ' The caller of SaSetup.exe is responsible to interpret
  609. ' this registry entry and inform the user of errors.
  610. '
  611. ' History:
  612. ' travisn 23-JUL-2001 Created
  613. ' travisn 7-AUG-2001 Comments added
  614. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  615. Function DetectStoppedSites
  616. On Error Resume Next
  617. 'Declare and initialize variables
  618. Dim oWebSrv, badAdminServer, badSharesServer, nAdminSiteID, nSharesSiteID
  619. badAdminServer = 0
  620. badSharesServer = 0
  621. Set WshShell = CreateObject("WScript.Shell")
  622. nAdminSiteID = WshShell.RegRead(REGKEY_WEBFRAMEWORK & ADMIN_SITE_NAME & "SiteID")
  623. nSharesSiteID = WshShell.RegRead(REGKEY_WEBFRAMEWORK & SHARES_SITE_NAME & "SiteID")
  624. If (nAdminSiteID <> 0) Then
  625. Set oWebSrv = GetObject(NS_IIS & "localhost/w3svc/" & nAdminSiteID)
  626. '
  627. ' Detect if the ServerState property is one of these 2:
  628. ' MD_SERVER_STATE_STOPPING OR MD_SERVER_STATE_STOPPED
  629. '
  630. If ( oWebSrv.ServerState = 3 OR oWebSrv.ServerState = 4) Then
  631. ' Admin Site is NOT started. Set the appropriate variable to ON
  632. badAdminServer = 1
  633. End If
  634. End If
  635. If (nSharesSiteID <> 0) Then
  636. Set oWebSrv = GetObject(NS_IIS & "localhost/w3svc/" & nSharesSiteID)
  637. If ( oWebSrv.ServerState = 3 OR oWebSrv.ServerState = 4) Then
  638. ' Shares Site is NOT started. Set the appropriate variable to ON
  639. badSharesServer = 1
  640. End If
  641. End If
  642. '
  643. ' Convert the stopped site information into a single variable
  644. ' with bits representing whether a site is running
  645. ' Codes for stoppedSites:
  646. ' 1: Admin site is not started
  647. ' 2: Shares site is not started
  648. ' 3: Both Admin and Shares sites are not started
  649. '
  650. Dim stoppedSites
  651. stoppedSites = 0
  652. If badAdminServer = 1 Then
  653. stoppedSites = stoppedSites + 1
  654. End If
  655. If badSharesServer = 1 Then
  656. stoppedSites = stoppedSites + 2
  657. End If
  658. 'Write the value of stoppedSites to the registry
  659. Dim WshShell
  660. Set WshShell = CreateObject("WScript.Shell")
  661. WshShell.RegWrite REGKEY_WEBFRAMEWORK & "StartSiteError", stoppedSites
  662. End Function
  663. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  664. Function ShowAdminSiteError
  665. Call ShowSiteError(ADMIN_ID)
  666. End Function
  667. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  668. Function ShowSharesSiteError
  669. Call ShowSiteError(SHARES_ID)
  670. End Function
  671. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  672. ' ShowSiteError
  673. '
  674. ' Description:
  675. ' If errors were reported during setup to start the Administration
  676. ' or Shares site, this script will display error dialog
  677. ' boxes to indicate to the user that he needs to reconcile
  678. ' the problem.
  679. '
  680. ' This script should only be called if SaSetup.exe is run
  681. ' with the UI sequence enabled.
  682. '
  683. ' The results are read from theregistry as a REG_SZ called:
  684. ' HKLM\Software\Microsoft\ServerAppliance\WebFramework\StartSiteError
  685. ' It is then interpreted as a number, with each bit position
  686. ' representing whether a site is started.
  687. ' Bit 0 corresponds to the Administration site and
  688. ' Bit 1 corresponds to the Shares site.
  689. '
  690. ' History:
  691. ' travisn 7-JUL-2001 Created
  692. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  693. Function ShowSiteError(nSiteID)
  694. On Error Resume Next
  695. ' Declare variables to read from the registry
  696. Dim WshShell
  697. Dim errorMsg
  698. 'Read the value of the registry entry for errors
  699. Set WshShell = CreateObject("WScript.Shell")
  700. errorMsg = WshShell.RegRead(REGKEY_WEBFRAMEWORK & "StartSiteError")
  701. 'Display the Administration site error
  702. if errorMsg AND ADMIN_ID AND (nSiteID = ADMIN_ID) then
  703. Call DisplayWarning (Session.Property("CustomActionData"))
  704. end if
  705. 'Display the Shares site error
  706. if errorMsg AND SHARES_ID AND (nSiteID = SHARES_ID) then
  707. Call DisplayWarning (Session.Property("CustomActionData"))
  708. end if
  709. End Function
  710. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  711. Function DisplayWarning(strWarning)
  712. WARNING = &H02000000
  713. Set messageRecord = Session.Installer.CreateRecord(1)
  714. messageRecord.StringData(0) = "[1]"
  715. messageRecord.StringData(1) = strWarning
  716. Session.Message WARNING, messageRecord
  717. End Function
  718. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  719. ' StopDefaultSiteIfPristine
  720. '
  721. ' Description:
  722. ' Stop the default site if it is still in its pristine state
  723. ' It is considered to not be in its pristine state if
  724. ' 1) The web site uses the default document list
  725. ' (used when the filename is not specified in the URL)
  726. ' 2) iisstart.asp is in this default document list
  727. ' 3) iisstart.asp is the first file in the list that exists
  728. '
  729. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  730. Function StopDefaultSiteIfPristine
  731. On Error Resume Next
  732. const defaultFileName1 = "iisstart.asp"
  733. const defaultFileName2 = "iisstart.htm"
  734. Dim oWebSrv , iisLoc, isDefaultSite
  735. defaultSiteLoc = "IIS://localhost/w3svc/1"
  736. isDefaultSite = false
  737. Set siteRoot = GetObject(defaultSiteLoc & "/Root")
  738. '
  739. ' Take the default site and determine if it has been modified
  740. '
  741. ' Do a quick check to see if the default document list is being used and contains iisstart.asp
  742. If siteRoot.enableDefaultDoc Then
  743. Dim rootPath
  744. Dim defaultFileList
  745. rootPath = siteRoot.path & "\"
  746. 'Get the list of default files
  747. defaultFileList = Split(siteRoot.defaultDoc, ",")
  748. '
  749. ' Search the list of default files for the first file that actually exists.
  750. ' If the first one found is iisstart.asp, then it is determined to be the default site
  751. '
  752. Set oFs = CreateObject("Scripting.FileSystemObject")
  753. For Each defaultFile In defaultFileList
  754. If oFs.FileExists(rootPath & defaultFile) Then
  755. 'wscript.echo "File exists: " & defaultFile
  756. If (defaultFile = DefaultFileName1 Or defaultFile = DefaultFileName2) Then
  757. isDefaultSite = true
  758. Exit For
  759. Else
  760. ' The first file that exists was not iisstart.asp
  761. Exit Function
  762. End If
  763. Else
  764. 'wscript.echo "File does NOT exist: " & defaultFile
  765. End If
  766. Next
  767. Else
  768. 'wscript.echo "Default pages are turned off or do not include iisstart.asp"
  769. End If
  770. '
  771. ' If the web site is the default site then stop it
  772. '
  773. If ( isDefaultSite ) Then
  774. 'wscript.echo "Stop the default site"
  775. set defaultWebSite = GetObject(defaultSiteLoc)
  776. defaultWebSite.Stop
  777. 'This error is now reported in another place during setup
  778. if ( Err.Number <> 0 ) Then
  779. 'wscript.echo "Unable to stop default site"
  780. End If
  781. End If
  782. End Function
  783. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  784. ' Sub UpdateMimeMap
  785. '
  786. ' Parameters:
  787. ' siteType ADMIN_ID or SHARES_ID
  788. '
  789. ' Description:
  790. ' Updates the MIME map for the specified site to allow the appropriate
  791. ' types of files to be downloaded. Right now, that means adding the
  792. ' log file extensions for the administration web site. The shares
  793. ' site is not updated.
  794. '
  795. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  796. Sub UpdateMimeMap(siteType)
  797. On Error Resume Next
  798. Dim strRegKeySiteID
  799. If (siteType = ADMIN_ID) Then
  800. strRegKeySiteID = REGKEY_WEBFRAMEWORK & ADMIN_SITE_NAME & _
  801. "SiteID"
  802. Else
  803. ' We don't update the MIME Map for the shares site.
  804. Exit Sub
  805. ' strRegKeySiteID = REGKEY_WEBFRAMEWORK & SHARES_SITE_NAME & _
  806. ' "SiteID"
  807. End If
  808. '
  809. ' Get the IIsWebServer object for the admin site.
  810. '
  811. Dim WshShell
  812. Set WshShell = CreateObject("WScript.Shell")
  813. Dim nSiteID
  814. nSiteID = WshShell.RegRead(strRegKeySiteID)
  815. Dim oWebServer
  816. Set oWebServer = GetObject("IIS://localhost/w3svc/" & nSiteID)
  817. '
  818. ' Create the MimeMap objects.
  819. '
  820. Dim mmEVT
  821. Set mmEVT = CreateObject("MimeMap")
  822. mmEVT.Extension = ".evt"
  823. mmEVT.MimeType = "application/octet-stream"
  824. Dim mmCSV
  825. Set mmCSV = CreateObject("MimeMap")
  826. mmCSV.Extension = ".csv"
  827. mmCSV.MimeType = "text/plain"
  828. Dim mmLOG
  829. Set mmLOG = CreateObject("MimeMap")
  830. mmLOG.Extension = ".log"
  831. mmLOG.MimeType = "text/plain"
  832. '
  833. ' Add the new mappings.
  834. '
  835. Dim rgMimeMap
  836. rgMimeMap = oWebServer.GetEx("MimeMap")
  837. Dim bEVT: bEVT = True
  838. Dim bCSV: bCSV = True
  839. Dim bLOG: bLOG = True
  840. Dim nUBound: nUBound = UBound(rgMimeMap) + 3
  841. Dim oMapping
  842. For Each oMapping In rgMimeMap
  843. Select Case LCase(oMapping.Extension)
  844. Case ".evt"
  845. bEVT = False
  846. nUBound = nUBound - 1
  847. Case ".csv"
  848. bCSV = False
  849. nUBound = nUBound - 1
  850. Case ".log"
  851. bLOG = False
  852. nUBound = nUBound - 1
  853. End Select
  854. Next
  855. ReDim Preserve rgMimeMap(nUBound)
  856. If (bLOG) Then
  857. Set rgMimeMap(nUBound) = mmLOG
  858. nUBound = nUBound - 1
  859. End If
  860. If (bCSV) Then
  861. Set rgMimeMap(nUBound) = mmCSV
  862. nUBound = nUBound - 1
  863. End If
  864. If (bEVT) Then
  865. Set rgMimeMap(nUBound) = mmEVT
  866. nUBound = nUBound - 1
  867. End If
  868. '
  869. ' Commit the changes.
  870. '
  871. Call oWebServer.PutEx(ADS_PROPERTY_UPDATE, "MimeMap", rgMimeMap)
  872. Call oWebServer.SetInfo()
  873. End Sub
  874. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  875. ' Function AddUserReadACL
  876. '
  877. ' Description:
  878. ' Add User Read/Execute access to this folder
  879. '
  880. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  881. Function AddUserReadACL(strPath)
  882. On Error Resume Next
  883. Dim WshShell, strUserAccount, WmiConnection, oFs, objSid, caclsCommand
  884. Dim USERS_SID, OPTIONS, READ
  885. Set WshShell = CreateObject("WScript.Shell")
  886. ' Security ID definitions of the User account
  887. USERS_SID = "S-1-5-32-545"
  888. ' cacls constants
  889. OPTIONS = " /E /T /G " 'Edit ACL, All files in directory & subdirectories, Grant access
  890. READ = ":R" 'Read Access
  891. ' Get localized account name for changing permissions on the User account
  892. strWmiGetUser = "Win32_SID.SID=""" & USERS_SID & """"
  893. Set WmiConnection = GetWMIConnection()
  894. set objSid = WmiConnection.Get(strWmiGetUser)
  895. If Err.number <> 0 Then
  896. 'DisplayWarning "Failed to get WMI User: " & Err.number & ", " & Err.Description
  897. Exit Function
  898. End If
  899. strUserAccount = """" & objSid.AccountName & """"
  900. 'Run cacls to add Users to the folder
  901. Set oFs = CreateObject("Scripting.FileSystemObject")
  902. If oFs.FolderExists(strPath) Then
  903. caclsCommand = "cmd /C echo y|cacls " 'Automatically select Yes to overwrite the permissions
  904. WshShell.Run caclsCommand & strPath & OPTIONS & strUserAccount & READ, 0, True
  905. End If
  906. End Function
  907. '-------------------------------------------------------------------------
  908. 'Function name: GetWMIConnection
  909. 'Description: Serves in getting connected to the server
  910. 'Input Variables: None
  911. 'Output Variables: None
  912. 'Returns: Object -connection to the server object
  913. 'This will try to create an object and connect to wmi
  914. '-------------------------------------------------------------------------
  915. Function GetWMIConnection()
  916. Dim objLocator, objService
  917. Set objLocator = CreateObject("WbemScripting.SWbemLocator")
  918. Set objService = objLocator.ConnectServer()
  919. If Err.number = 0 Then
  920. Set GetWMIConnection = objService
  921. End If
  922. 'Set to nothing
  923. Set objLocator=Nothing
  924. Set objService=Nothing
  925. End Function