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.

469 lines
14 KiB

  1. '-------------------------------------------------------------------------
  2. 'Global Variables
  3. '-------------------------------------------------------------------------
  4. Dim G_ADMIN_PORT
  5. Dim G_HTTP
  6. Dim G_IIS
  7. Dim G_HOST
  8. Dim G_ADMIN_NAME
  9. Dim G_SHARES_WEBSITEID
  10. Dim G_SHARES_NAME
  11. Dim G_objHTTPService 'WMI server HTTP object
  12. Dim G_nNICCount 'NIC count
  13. Dim G_objService 'WMI server HTTP object
  14. Dim G_ADMIN_WEBSITEID 'HTTP administration web site WMI name
  15. Dim strComputerName
  16. Const WMI_IIS_NAMESPACE = "root\MicrosoftIISv1" 'constant to connect to WMI
  17. G_ADMIN_PORT = "0"
  18. G_ADMIN_NAME = "Administration"
  19. G_SHARES_NAME = "Shares"
  20. G_HTTP = "http://"
  21. G_IIS = "IIS://"
  22. G_HOST = GetSystemName()
  23. G_SHARES_WEBSITEID = "0"
  24. Set G_objHTTPService = GetWMIConnection(WMI_IIS_NAMESPACE)
  25. Set G_objService = GetWMIConnection("Default")
  26. G_SHARES_WEBSITEID = GetWebSiteID( G_SHARES_NAME )
  27. G_ADMIN_WEBSITEID = GetWebSiteID( G_ADMIN_NAME )
  28. G_ADMIN_PORT = GetAdminPortNumber()
  29. Dim strSharesFolder
  30. Set oFileSystemObject = CreateObject("Scripting.FileSystemObject")
  31. strSharesFolder = GetSharesWebSitePath("Shares")
  32. strSharesFolder = "c:\inetpub\shares"
  33. Set oDefaultHTMFile = oFileSystemObject.CreateTextFile( strSharesFolder + "\default.asp", True)
  34. oDefaultHTMFile.WriteLine( chr(60) & chr(37) )
  35. oDefaultHTMFile.WriteLine( "Dim strServerName " )
  36. oDefaultHTMFile.WriteLine( "Dim WinNTSysInfo " )
  37. oDefaultHTMFile.WriteLine( "Set WinNTSysInfo = CreateObject(""WinNTSystemInfo"") " )
  38. oDefaultHTMFile.WriteLine( "strServerName = UCASE( WinNTSysInfo.ComputerName ) " )
  39. oDefaultHTMFile.WriteLine( chr(37) & chr(62) )
  40. '-------------------------------------------------------------------------
  41. 'Start of localization content
  42. '-------------------------------------------------------------------------
  43. Dim L_HEADER
  44. Dim L_FOOTER
  45. Dim objLocMgr
  46. Dim varReplace
  47. varReplace = ""
  48. Set objLocMgr = CreateObject("ServerAppliance.localizationmanager")
  49. L_HEADER = GetLocString("httpsh.dll", "40300001", "")
  50. L_FOOTER = GetLocString("httpsh.dll", "40300002", "")
  51. set objLocMgr = nothing
  52. '-------------------------------------------------------------------------
  53. 'End of localization content
  54. '-------------------------------------------------------------------------
  55. oDefaultHTMFile.WriteLine("<body marginWidth =0 marginHeight=0 topmargin=0 LEFTMARGIN=0>" )
  56. oDefaultHTMFile.WriteLine("<table width='100%' height='100%' cellspacing=0 cellpadding=0 border=0>" )
  57. oDefaultHTMFile.WriteLine("<tr style='BACKGROUND-COLOR: #000000;" )
  58. oDefaultHTMFile.WriteLine("COLOR: #ffffff;FONT-FAMILY: Arial;FONT-SIZE: 12pt;FONT-WEIGHT: bold;TEXT-DECORATION: none;'> <td align=left> <img src=OEM_LOGO.gif></td>" )
  59. oDefaultHTMFile.WriteLine("<td>" + "<" & "% = strServerName" & "%" & ">" + "</td><td align=right><img src=WinPwr_h_R.gif></td></tr>" )
  60. oDefaultHTMFile.WriteLine("<tr width='100%' height='100%' style='PADDING-LEFT: 15px;PADDING-RIGHT: 15px;'> <td valign=top width='30%'><img src=folder.gif><br><BR><BR>" )
  61. urlHTTPSAdmin = G_HTTPS + "<" & "% = strServerName" & "%" & ">" + ":" + G_SHARES_PORT
  62. 'oDefaultHTMFile.Writeline( "<div style='PADDING-BOTTOM: 7px;PADDING-LEFT: 7px;PADDING-RIGHT: 0px;PADDING-TOP: 0px;'>" )
  63. 'oDefaultHTMFile.Writeline( "<a style='COLOR: #000000;FONT-FAMILY: tahoma,arial,verdana,sans-serif;FONT-SIZE: 9pt;' HREF=" +urlHTTPSAdmin + ">" + L_HTTPS_FOOTER + " </a> </div" & " " & L_HTTPS_RECOMENDED )
  64. 'oDefaultHTMFile.WriteLine("<BR>")
  65. urlAdmin = G_HTTP + "<" & "% = strServerName" & "%" & ">" + ":" + G_ADMIN_PORT
  66. oDefaultHTMFile.Writeline( "<div style='PADDING-BOTTOM: 7px;PADDING-LEFT: 7px;PADDING-RIGHT: 0px;PADDING-TOP: 0px;'>" )
  67. oDefaultHTMFile.Writeline( "<a style='COLOR: #000000;FONT-FAMILY: tahoma,arial,verdana,sans-serif;FONT-SIZE: 9pt;' HREF=" + urlAdmin + ">" + L_FOOTER + " </a> </div>" )
  68. oDefaultHTMFile.WriteLine("</td><td colspan=2 valign=top width='70%'><br>" )
  69. oDefaultHTMFile.WriteLine("<div style='font-family:arial,verdana,sans-serif;font-size:11pt;font-weight: bold;'>" )
  70. oDefaultHTMFile.WriteLine( L_HEADER + " " + "<" & "% = strServerName" & "%" & ">" + "</H2>" )
  71. oDefaultHTMFile.WriteLine("</div>")
  72. Dim oWebVirtDir
  73. Dim oWebRoot
  74. Dim index
  75. Dim urlAdmin, i, urlHTTPSAdmin
  76. Dim arrVroots()
  77. ReDim arrVroots(5000, 1 )
  78. Set oWebRoot = GetObject( "IIS://" & G_HOST & "/" & G_SHARES_WEBSITEID & "/root")
  79. index = -1
  80. For Each oWebVirtDir in oWebRoot
  81. index = index + 1
  82. arrVroots( index, 0 ) = oWebVirtDir.Name
  83. Next
  84. 'Call QuickSort( arrVroots, 0, index, 1, 0 )
  85. If Index = -1 Then
  86. oDefaultHTMFile.Writeline( "<div style='FONT-FAMILY: tahoma,arial,verdana,sans-serif;FONT-SIZE: 9pt;'")
  87. oDefaultHTMFile.Writeline( "Empty: There are no shares to list " )
  88. oDefaultHTMFile.Writeline( "</div>" )
  89. End If
  90. For i = 0 To index
  91. oDefaultHTMFile.Writeline( "<div style='PADDING-BOTTOM: 7px;PADDING-LEFT: 7px;PADDING-RIGHT: 0px;PADDING-TOP: 0px;'>")
  92. oDefaultHTMFile.Writeline("<a style='COLOR: #000000;FONT-FAMILY: tahoma,arial,verdana,sans-serif;FONT-SIZE: 9pt;' HREF=" + chr(34) + arrVroots( i, 0 ) + chr(34) + " > " + arrVroots( i, 0 ) + "</a></div>" )
  93. 'oDefaultHTMFile.WriteLine("</div>")
  94. Next
  95. oDefaultHTMFile.WriteLine("</td></tr></table></body>")
  96. 'oDefaultHTMFile.WriteLine("<BR>")
  97. 'urlHTTPSAdmin = G_HTTPS + G_HOST + ":" + G_SHARES_PORT
  98. 'oDefaultHTMFile.Writeline( "<a HREF=" +urlHTTPSAdmin + ">" + L_HTTPS_FOOTER + " </a> " & " " & L_HTTPS_RECOMENDED )
  99. 'oDefaultHTMFile.WriteLine("<BR>")
  100. 'urlAdmin = G_HTTP + G_HOST + ":" + G_ADMIN_PORT
  101. 'oDefaultHTMFile.Writeline( "<a HREF=" + urlAdmin + ">" + L_FOOTER + " </a> " )
  102. oDefaultHTMFile.Close
  103. '----------------------------------------------------------------------------
  104. '
  105. ' Function : QuickSort
  106. '
  107. ' Synopsis : sorts elements in alphabetical order
  108. '
  109. '
  110. ' Returns : localized string
  111. '
  112. '----------------------------------------------------------------------------
  113. Sub QuickSort(arrData, iLow, iHigh)
  114. Dim iTmpLow, iTmpHigh, iTmpMid, vTempVal(2), vTmpHold(2)
  115. iTmpLow = iLow
  116. iTmpHigh = iHigh
  117. If iHigh <= iLow Then Exit Sub
  118. iTmpMid = (iLow + iHigh) \ 2
  119. vTempVal(0) = arrData(iTmpMid, 0)
  120. 'vTempVal(1) = arrData(iTmpMid, 1)
  121. Do While (iTmpLow <= iTmpHigh)
  122. Do While (arrData(iTmpLow, 0) < vTempVal(0) And iTmpLow < iHigh)
  123. iTmpLow = iTmpLow + 1
  124. Loop
  125. Do While (vTempVal(0) < arrData(iTmpHigh, 0) And iTmpHigh > iLow)
  126. iTmpHigh = iTmpHigh - 1
  127. Loop
  128. If (iTmpLow <= iTmpHigh) Then
  129. vTmpHold(0) = arrData(iTmpLow, 0)
  130. 'vTmpHold(1) = arrData(iTmpLow, 1)
  131. arrData(iTmpLow, 0) = arrData(iTmpHigh, 0)
  132. 'arrData(iTmpLow, 1) = arrData(iTmpHigh, 1)
  133. arrData(iTmpHigh, 0) = vTmpHold(0)
  134. 'arrData(iTmpHigh, 1) = vTmpHold(1)
  135. iTmpLow = iTmpLow + 1
  136. iTmpHigh = iTmpHigh - 1
  137. End If
  138. Loop
  139. If (iLow < iTmpHigh) Then
  140. QuickSort arrData, iLow, iTmpHigh
  141. End If
  142. If (iTmpLow < iHigh) Then
  143. QuickSort arrData, iTmpLow, iHigh
  144. End If
  145. End Sub
  146. '----------------------------------------------------------------------------
  147. '
  148. ' Function : GetLocString
  149. '
  150. ' Synopsis : Gets localized string from resource dll
  151. '
  152. ' Arguments: SourceFile(IN) - resource dll name
  153. ' ResourceID(IN) - resource id in hex
  154. ' ReplacementStrings(IN) - parameters to replace in string
  155. '
  156. ' Returns : localized string
  157. '
  158. '----------------------------------------------------------------------------
  159. Function GetLocString(SourceFile, ResourceID, ReplacementStrings)
  160. ' returns localized string
  161. '
  162. Dim objLocMgr
  163. Dim varReplacementStrings
  164. ' prep inputs
  165. If Left(ResourceID, 2) <> "&H" Then
  166. ResourceID = "&H" & ResourceID
  167. End If
  168. If Trim(SourceFile) = "" Then
  169. SourceFile = "svrapp"
  170. End If
  171. If (Not IsArray(ReplacementStrings)) Then
  172. ReplacementStrings = varReplacementStrings
  173. End If
  174. ' call Localization Manager
  175. Set objLocMgr = CreateObject("ServerAppliance.LocalizationManager")
  176. If ( IsObject(objLocMgr) ) Then
  177. Err.Clear
  178. '
  179. ' Disable error trapping
  180. '
  181. 'on error resume next
  182. '
  183. ' Get the string, do not hault for any errors
  184. GetLocString = objLocMgr.GetString(SourceFile, ResourceID, ReplacementStrings)
  185. Set objLocMgr = Nothing
  186. Dim errorCode
  187. Dim errorDesc
  188. errorCode = Err.Number
  189. errorDesc = Err.description
  190. Err.Clear
  191. '
  192. ' Check errors
  193. '
  194. If errorCode <> 0 Then
  195. Dim strErrorDescription
  196. strErrorDescription = "ISSUE: String not found. Source:" + CStr(SourceFile) + " ResID:" + CStr(ResourceID)
  197. GetLocString = strErrorDescription
  198. End If
  199. Else
  200. GetLocString = "ISSUE: Localization string not found. Source:" + CStr(SourceFile) + " ResID:" + CStr(ResourceID)
  201. Err.Clear
  202. End If
  203. End Function
  204. '-------------------------------------------------------------------------
  205. 'Function name: GetSharesWebSite
  206. 'Description: gets admin website name
  207. 'Input Variables:
  208. 'Output Variables: None
  209. 'Returns: String-Website name
  210. '-------------------------------------------------------------------------
  211. Function GetWebSiteID( strWebSiteName )
  212. 'On Error Resume Next
  213. Err.Clear
  214. Dim strMangedSiteName
  215. Dim strWMIpath
  216. Dim objSiteCollection
  217. Dim objSite
  218. strWMIpath = "select * from IIs_WebServerSetting where servercomment =" & chr(34) & strWebSiteName & chr(34)
  219. set objSiteCollection = G_objHTTPService.ExecQuery(strWMIpath)
  220. for each objSite in objSiteCollection
  221. GetWebSiteID = objSite.Name
  222. Exit For
  223. Next
  224. End Function
  225. '-------------------------------------------------------------------------
  226. 'Function name: GetWMIConnection
  227. 'Description: Serves in getting connected to the server
  228. 'Input Variables: strNamespace
  229. 'Output Variables: None
  230. 'Returns: Object -connection to the server object
  231. 'Global Variables: In -L_WMICONNECTIONFAILED_ERRORMESSAGE -Localized strings
  232. 'This will try to create an object and connect to wmi if fails shows failure
  233. 'page
  234. '-------------------------------------------------------------------------
  235. Function GetWMIConnection(strNamespace)
  236. Err.Clear
  237. Dim objLocator
  238. Dim objService
  239. Set objLocator = CreateObject("WbemScripting.SWbemLocator")
  240. If strNamespace = "" OR strNamespace="default" OR strNamespace="DEFAULT" OR strNamespace="Default" Then
  241. Set objService = objLocator.ConnectServer
  242. Else
  243. Set objService = objLocator.ConnectServer(".",strNamespace )
  244. End if
  245. 'If Err.number <> 0 Then
  246. ' ServeFailurePage L_WMICONNECTIONFAILED_ERRORMESSAGE & "(" & Err.Number & ")"
  247. ' Else
  248. Set GetWMIConnection = objService
  249. 'End If
  250. 'Set to nothing
  251. Set objLocator=Nothing
  252. Set objService=Nothing
  253. End Function
  254. '-------------------------------------------------------------------------
  255. 'Function name: GetAdminPortNumber()
  256. 'Output Variables: None
  257. 'page
  258. '-------------------------------------------------------------------------
  259. Function GetAdminPortNumber()
  260. 'On Error Resume Next
  261. Dim ObjNACCollection
  262. Dim Objinst
  263. Dim objIPArray
  264. Dim strIPProp,strIPArray
  265. Dim arrWinsSrv
  266. Dim arrIPAdd,arrPort
  267. Dim strIPList
  268. GetAdminPortNumber = "8111"
  269. 'Getting the IIS_WEB Server Setting instance
  270. Set ObjNACCollection = G_objHTTPService.ExecQuery("Select * from IIs_WebServerSetting where Name=" & Chr(34)& G_ADMIN_WEBSITEID & Chr(34))
  271. Dim nIPCount
  272. For each Objinst in ObjNACCollection
  273. For nIPCount = 0 to ubound(Objinst.ServerBindings)
  274. strIPArray = Objinst.ServerBindings(nIPCount)
  275. 'split the strIPArray array to get the IP address and port
  276. arrWinsSrv = split(strIPArray,":")
  277. arrIPAdd = arrWinsSrv(0)
  278. arrPort = arrWinsSrv(1)
  279. GetAdminPortNumber = arrWinsSrv(1)
  280. Next
  281. Next
  282. End Function
  283. '-------------------------------------------------------------------------
  284. 'Function name: GetSharesWebSitePath
  285. 'Description: gets admin website path
  286. 'Input Variables:
  287. 'Output Variables: None
  288. 'Returns: String-Website path
  289. '-------------------------------------------------------------------------
  290. Function GetSharesWebSitePath( strWebSiteName )
  291. 'On Error Resume Next
  292. 'Err.Clear
  293. Dim strSiteName
  294. Dim strMangedSiteName
  295. Dim strWMIpath
  296. Dim objSiteCollection
  297. Dim objSite
  298. Dim objWMI
  299. Dim objHttpname
  300. Dim objHttpnames
  301. Dim str1
  302. 'set ObjWMI = getWMIConnection("root\MicrosoftIISv1")
  303. 'Set objHttpnames = objWMI.InstancesOf("IIs_WebVirtualDirSetting")
  304. 'strSiteName=GetWebSiteID( G_SHARES_NAME )
  305. 'msgbox strSiteName
  306. ' Adding all Http shares to Dictionary object
  307. 'For Each objHttpname in objHttpnames
  308. ' msgbox objHttpname.name
  309. 'str1=split(objHttpname.name,"/")
  310. ' To get http shares from only "Shares" web site
  311. 'If Mid(objHttpname.name,1,7)=strSiteName Then
  312. ' GetSharesWebSitePath = objHttpname.path
  313. ' msgbox objHttpname.path
  314. ' Exit For
  315. ' 'end if
  316. 'Next
  317. End Function
  318. Function GetSystemName()
  319. Dim WinNTSysInfo
  320. Set WinNTSysInfo = CreateObject("WinNTSystemInfo")
  321. GetSystemName = WinNTSysInfo.ComputerName
  322. End Function
  323. Function GetWebSiteID( strWebSiteName )
  324. 'On Error Resume Next
  325. Err.Clear
  326. Dim strMangedSiteName
  327. Dim strWMIpath
  328. Dim objSiteCollection
  329. Dim objSite
  330. strWMIpath = "select * from IIs_WebServerSetting where servercomment =" & chr(34) & strWebSiteName & chr(34)
  331. set objSiteCollection = G_objHTTPService.ExecQuery(strWMIpath)
  332. for each objSite in objSiteCollection
  333. GetWebSiteID = objSite.Name
  334. Exit For
  335. Next
  336. End Function