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.

508 lines
18 KiB

  1. <!-- #include virtual="/admin/shares/inc_shares.asp" -->
  2. <%
  3. '
  4. ' Copyright (c) Microsoft Corporation. All rights reserved.
  5. '
  6. '-------------------------------------------------------------------------
  7. ' Global Variables
  8. '-------------------------------------------------------------------------
  9. Dim G_strHost 'Host name
  10. Dim G_objHTTPService 'WMI server HTTP object
  11. Dim G_strAdminSiteID 'HTTP administration web site WMI name
  12. 'To hold source file name
  13. 'holds the web site name
  14. 'CONST CONST_ADMINISTRATOR ="Administration"
  15. G_strHost = GetSystemName() 'Get the system name
  16. Set G_objHTTPService = GetWMIConnection(CONST_WMI_IIS_NAMESPACE) 'get the WMI connection
  17. G_strAdminSiteID = GetWebSiteID(CONST_ADMINISTRATOR ) 'get the Web site ID
  18. '-------------------------------------------------------------------------
  19. ' Global Constants
  20. '-------------------------------------------------------------------------
  21. 'holds the number of rows to be displayed in OTS
  22. Const CONST_SHARES_PER_PAGE = 10
  23. 'Registry path for APPLETALK Volumes
  24. CONST CONST_REGISTRY_APPLETALK_PATH ="SYSTEM\CurrentControlSet\Services\MacFile\Parameters\Volumes"
  25. 'Registry path for Netware Volumes
  26. CONST CONST_REGISTRY_NETWARE_PATH ="SYSTEM\CurrentControlSet\Services\FPNW\Volumes"
  27. 'Registry path for NFS Exports
  28. CONST CONST_NFS_REGISTRY_PATH ="SOFTWARE\Microsoft\Server For NFS\CurrentVersion\exports"
  29. 'holds the web site name
  30. CONST CONST_ADMINISTRATOR ="Administration"
  31. ' Flag to toggle optional tracing output
  32. 'Const CONST_ENABLE_TRACING = TRUE
  33. '-------------------------------------------------------------------------
  34. ' Sub Routine name: GetCifsShares()
  35. ' Description: Gets Windows Shares from SA machine and Adds
  36. ' to Dictionary Object.
  37. ' Input Variables: objDict(dictionary object)
  38. ' Output Variables: None
  39. ' Returns: None
  40. ' Global Variables: in: L_WMICLASSINSTANCEFAILED_ERRORMESSAGE
  41. ' G_strHost
  42. '-------------------------------------------------------------------------
  43. Sub GetCifsShares(Byref objDict)
  44. Err.Clear
  45. On Error Resume Next
  46. Dim objShareObject 'hold Share object
  47. Dim strShare 'hold instance of share object
  48. Dim strQuery 'hold query string
  49. Dim strLanMan 'hold lanmanserver string
  50. Dim strDictValue 'hold string to pass it to Dictionary object
  51. strLanMan = "/lanmanserver"
  52. strQuery="SELECT name,path,description FROM Win32_SHARE"
  53. set objShareObject=GetObject("WinNT://" & G_strHost & "/LanmanServer")
  54. ' If instance of the wmi class is failed
  55. If Err.number <>0 then
  56. call SA_ServeFailurepage(L_WMICLASSINSTANCEFAILED_ERRORMESSAGE)
  57. end if
  58. for each strShare in objShareObject
  59. strDictValue = Mid( strShare.adspath, instr( UCASE( strShare.adspath ), UCASE( strLanMan ) ) + _
  60. len(strLanMan) + 1, len(strShare.adspath) - _
  61. instr( UCASE( strShare.adspath ), UCASE( strLanMan ) ) + len(strLanMan ) )
  62. ' Adding all windows shares to the Dictionary object one by one as "sharename &chr(1)& sharepath" as Key and "share description &chr(1)&share type" as a "Value"
  63. objDict.Add strDictValue & chr(1) & strShare.path , strShare.description & chr(1) &"W"
  64. next
  65. ' Destroying dynamically created objects
  66. set objShareObject = Nothing
  67. End Sub
  68. '----------------------------------------------------------------------------------------
  69. ' Sub Routine name: GetNfsShares()
  70. ' Description: gets all Nfs Shares from SA machine and adds to Dictionary Object
  71. ' Input Variables: objDict(dictionary object)
  72. ' Output Variables: None
  73. ' Returns: None
  74. ' Global Variables: in: CONST_NFS_REGISTRY_PATH - Registry path to access Nfs Shares
  75. '-----------------------------------------------------------------------------------------
  76. sub GetNfsShares(ByRef objDict)
  77. Err.Clear
  78. On Error Resume Next
  79. Dim objRegistryHandle 'hold Registry connection
  80. Dim intenumkey 'hold enum key value as INTEGER
  81. Dim strenumvalue 'hold enum key value as STRING
  82. Dim strenumstringval 'hold enum key value as STRING
  83. Dim strenumstringpath 'hold value of the registry key
  84. Dim nidx 'hold count
  85. Dim ObjConnection 'hold WMI connection object
  86. Dim strDictValue 'hold item of dictionary object
  87. Dim strShareString 'hold the share as STRING
  88. 'get the WMI connection
  89. set ObjConnection = getWMIConnection("Default")
  90. ' Check whether the service is installed on the machine or not
  91. if not IsServiceInstalled(ObjConnection,"nfssvc") then
  92. Exit sub
  93. end if
  94. ' Get the registry connection Object.
  95. set objRegistryHandle = RegConnection()
  96. ' RegEnumKey function gets the Subkeys in the given Key and Returns
  97. ' an array containing sub keys from registry
  98. intenumkey = RegEnumKey(objRegistryHandle,CONST_NFS_REGISTRY_PATH)
  99. For nidx= 0 to (ubound(intenumkey))
  100. ' RegEnumKeyValues function Gets the values in the given SubKey
  101. ' and Returns an array containing sub keys
  102. strenumvalue = RegEnumKeyValues(objRegistryHandle,CONST_NFS_REGISTRY_PATH & "\" & intenumkey(nidx))
  103. ' getRegkeyvalue function gets the value in the registry for a given
  104. ' value and returns the value of the requested key
  105. strenumstringpath = getRegkeyvalue(objRegistryHandle,CONST_NFS_REGISTRY_PATH & "\" & intenumkey(nidx),strenumvalue(0),CONST_STRING)
  106. strenumstringval = getRegkeyvalue(objRegistryHandle,CONST_NFS_REGISTRY_PATH & "\" & intenumkey(nidx),strenumvalue(1),CONST_STRING)
  107. strShareString=strenumstringval &chr(1) & strenumstringpath
  108. ' Checking for same share with share path is existing in dictionary object.
  109. if objDict.Exists(strShareString) then
  110. strDictValue= objDict.Item(strShareString) & " U" 'append 'U' to identify as NFS share
  111. objDict.Item(strShareString)= strDictValue
  112. else
  113. If strenumstringval <> "" then
  114. objDict.Add strShareString,chr(1) & "U"
  115. end if
  116. end if
  117. Next
  118. ' Destroying dynamically created objects
  119. set ObjConnection = Nothing
  120. set objRegistryHandle = Nothing
  121. End Sub
  122. '---------------------------------------------------------------------------
  123. 'Function name: IsServiceInstalled
  124. 'Description: checks whether the service is installed or not
  125. 'Input Variables: None
  126. 'Oupput Variables: returns true if service installed else false
  127. 'Returns: None
  128. 'GlobalVariables: in: L_WMICLASSINSTANCEFAILED_ERRORMESSAGE
  129. '---------------------------------------------------------------------------
  130. Function IsServiceInstalled(ObjWMI,strService)
  131. Err.Clear
  132. on error resume next
  133. Dim objService 'hold Service object
  134. Dim instService 'hold instance of Service object
  135. IsServiceInstalled = false
  136. 'get the instances of win32_service
  137. set objService = ObjWMI.Instancesof("win32_service")
  138. If Err.number <>0 then
  139. call SA_ServeFailurepage(L_WMICLASSINSTANCEFAILED_ERRORMESSAGE)
  140. end if
  141. for each instService in objService
  142. if ucase(instService.name) = ucase(strService) then
  143. IsServiceInstalled = true
  144. exit function
  145. end if
  146. next
  147. 'Destroying dynamically created objects
  148. set objService = Nothing
  149. End Function
  150. '-------------------------------------------------------------------------------------
  151. ' Sub Routine name: GetFtpShares
  152. ' Description: Gets Ftp Shares from SA machine and adds to Dictionary Object.
  153. ' Input Variables: objDict(dictionary object)
  154. ' Output Variables: None
  155. ' Returns: None
  156. ' Global Variables: in: L_WMICLASSINSTANCEFAILED_ERRORMESSAGE
  157. '-------------------------------------------------------------------------------------
  158. Sub GetFtpShares(ByRef objDict)
  159. Err.Clear
  160. on error resume next
  161. Dim objConnection 'hold Connection name
  162. Dim objFtpnames 'hold Ftp VirtualDir object
  163. Dim instFtpname 'hold instances of Ftp VirtualDir object
  164. Dim strShareString 'hold the share as STRING
  165. Dim strTemp 'hold temporary array of FTP name
  166. Dim strDictvalue 'hold item of dictionary object
  167. 'get the WMI connection
  168. set ObjConnection = getWMIConnection(CONST_WMI_IIS_NAMESPACE)
  169. 'get the ioncatnces of IIs_FtpVirtualDirSetting class
  170. Set objFtpnames = objConnection.InstancesOf(GetIISWMIProviderClassName("IIs_FtpVirtualDirSetting"))
  171. If Err.number <>0 then
  172. call SA_ServeFailurepage(L_WMICLASSINSTANCEFAILED_ERRORMESSAGE)
  173. end if
  174. ' Adding all Ftp shares to Dictionary Object.
  175. For Each instFtpname in objFtpnames
  176. strTemp=split(instFtpname.name,"/")
  177. ' Displaying only Root level ftp Shares
  178. if ubound(strTemp)=3 then
  179. strShareString=strTemp(ubound(strTemp))&chr(1)&instFtpname.path
  180. ' Checking whether the sharename with same path is existing in the dictionary object
  181. if objDict.Exists(strShareString) then
  182. if instr(objDict.item(strShareString),"F")=0 then
  183. strDictValue=objDict.Item(strShareString) & " F" 'append 'F' to identify FTP share
  184. objDict.Item(strShareString)= strDictValue
  185. end if
  186. else
  187. objDict.Add strShareString,chr(1)&"F"
  188. end if
  189. end if
  190. Next
  191. ' Destroying dynamically created objects
  192. set objConnection = Nothing
  193. set objFtpnames = Nothing
  194. End sub
  195. '-------------------------------------------------------------------------
  196. ' Sub Routine name: GetHttpShares
  197. ' Description: Gets Http Shares from localmachine and adds to
  198. ' Dictionary Object.
  199. ' Input Variables: objDict(dictionary object)
  200. ' Output Variables: None
  201. ' Returns: None
  202. ' Global Variables: in: L_WMICLASSINSTANCEFAILED_ERRORMESSAGE
  203. '-------------------------------------------------------------------------
  204. Sub GetHttpShares(ByRef objDict)
  205. Err.Clear
  206. On Error resume next
  207. Dim objConnection 'hold Connection name
  208. Dim objHttpnames 'hold virtual dir setting object
  209. Dim strShareString 'hold the share as STRING
  210. Dim strDictvalue 'hold item of dictionary object
  211. Dim strSiteName 'hold site name
  212. Dim objWebRoot 'hold ADSI connection to site
  213. Dim instWeb 'hold site instance
  214. 'get WMI Connection
  215. set ObjConnection = getWMIConnection(CONST_WMI_IIS_NAMESPACE)
  216. 'get the instances of IIs_WebVirtualDirSetting
  217. Set objHttpnames = objConnection.InstancesOf(GetIISWMIProviderClassName("IIs_WebVirtualDirSetting"))
  218. If Err.number <>0 then
  219. call SA_ServeFailurepage(L_WMICLASSINSTANCEFAILED_ERRORMESSAGE)
  220. end if
  221. 'Get Metabase name of "Shares" site
  222. strSiteName=GetSharesWebSiteName()
  223. 'Connect to IIS provider
  224. Set objWebRoot = GetObject( "IIS://" & request.servervariables("SERVER_NAME") & "/" & strSiteName & "/root")
  225. index = -1
  226. For Each instWeb in objWebRoot
  227. strShareString=instWeb.name & chr(1) & instWeb.path
  228. If objDict.Exists(strShareString) Then
  229. If instr(objDict.item(strShareString),"H")=0 Then
  230. strDictValue=objDict.Item(strShareString) & " H" 'append 'H' to identify HTTP/WebDAV share
  231. objDict.Item(strShareString)= strDictValue
  232. End If
  233. Else
  234. objDict.Add strShareString,chr(1)&"H"
  235. End If
  236. Next
  237. 'Destroying dynamically created objects
  238. set objConnection = Nothing
  239. set objHttpnames = Nothing
  240. Set objWebRoot = Nothing
  241. End sub
  242. '-------------------------------------------------------------------------
  243. ' Function name: GetSystemName()
  244. ' Description: gets the system name
  245. ' Input Variables: None
  246. ' Output Variables: None
  247. ' Returns: Computer name
  248. ' Global Variables: None
  249. '-------------------------------------------------------------------------
  250. Function GetSystemName()
  251. On Error Resume Next
  252. Err.Clear
  253. Dim WinNTSysInfo ' hold WinNT system object
  254. Set WinNTSysInfo = CreateObject("WinNTSystemInfo")
  255. GetSystemName = WinNTSysInfo.ComputerName 'get the computer name
  256. ' Destroying dynamically created objects
  257. Set WinNTSysInfo =Nothing
  258. End Function
  259. '-------------------------------------------------------------------------
  260. ' Function name: GetWebSiteID
  261. ' Description: Get web site name
  262. ' Input Variables: strWebSiteNamee
  263. ' Output Variables: None
  264. ' Returns: website name
  265. ' Global Variables: IN:G_objHTTPService
  266. '-------------------------------------------------------------------------
  267. Function GetWebSiteID( strWebSiteName )
  268. On Error Resume Next
  269. Err.Clear
  270. Dim strWMIpath 'hold query string for WMI
  271. Dim objSiteCollection 'hold Sites collection
  272. Dim objSite 'hold Site instance
  273. 'Build the query for WMI
  274. strWMIpath = "select * from " & GetIISWMIProviderClassName("IIs_WebServerSetting") & " where servercomment =" & chr(34) & strWebSiteName & chr(34)
  275. set objSiteCollection = G_objHTTPService.ExecQuery(strWMIpath)
  276. for each objSite in objSiteCollection
  277. GetWebSiteID = objSite.Name
  278. Exit For
  279. Next
  280. 'Destroying dynamically created object
  281. set objSiteCollection = Nothing
  282. End Function
  283. '-------------------------------------------------------------------------
  284. ' Function name: FolderExists()
  285. ' Description: Validating the folder exists or not.
  286. ' Input Variables: strShareName
  287. ' Output Variables: None
  288. ' Returns: True/False
  289. ' Global Variables: None
  290. '-------------------------------------------------------------------------
  291. Function FolderExists( strShareName )
  292. Dim objFso 'hold filesystem object
  293. FolderExists = False
  294. Set objFso = Server.CreateObject( "Scripting.FileSystemObject")
  295. If objFso.FolderExists( strShareName ) Then
  296. FolderExists = True
  297. End if
  298. ' Destroying dynamically created objects
  299. Set objFso = Nothing
  300. End Function
  301. '-------------------------------------------------------------------------
  302. ' Sub Routine name: GetNetWareShares
  303. ' Description: Gets All NetWare Shares from local machine and
  304. ' adds to Dictionary Object
  305. ' Input Variables: objDict(dictionary object)
  306. ' Output Variables: objDict
  307. ' Returns: None
  308. ' Global Variables: in:
  309. ' CONST_REGISTRY_NETWARE_PATH holds registry path for Netware
  310. '-------------------------------------------------------------------------
  311. sub GetNetWareShares(ByRef objDict)
  312. Err.Clear
  313. On Error Resume Next
  314. Dim objRegistryHandle 'hold Registry connection
  315. Dim intenumkey 'hold enum key value as INTEGER
  316. Dim strenumvalue 'hold enum key value as STRING
  317. Dim strenumstringpath 'hold value of the registry key
  318. Dim nidx 'hold count
  319. Dim ObjConnection 'hold Connection to WMI
  320. Dim strDictValue 'hold string value of dictionary object
  321. Dim strShareString 'hold the share as STRING
  322. set ObjConnection = getWMIConnection("Default") 'gets WMI connection
  323. ' Check whether the Netware service is installed on the machine or not
  324. if not IsServiceInstalled(ObjConnection,"FPNW") then
  325. Exit sub
  326. end if
  327. ' Get the registry connection Object
  328. set objRegistryHandle = RegConnection()
  329. ' RegEnumKey function gets the Subkeys in the given Key and Returns
  330. ' an array containing sub keys from registry
  331. intenumkey = RegEnumKeyValues(objRegistryHandle,CONST_REGISTRY_NETWARE_PATH)
  332. For nidx= 0 to (ubound(intenumkey))
  333. strenumstringpath = getRegkeyvalue(objRegistryHandle,CONST_REGISTRY_NETWARE_PATH,intenumkey(nidx),CONST_MULTISTRING)
  334. If ubound(strenumstringpath)>= 2 then
  335. strShareString= trim(intenumkey(nidx)) & chr(1) & Mid(trim(strenumstringpath(1)),6)
  336. Else
  337. strShareString= trim(intenumkey(nidx)) &chr(1) & Mid(trim(strenumstringpath(0)),6)
  338. End if
  339. if objDict.Exists(strShareString) then
  340. strDictValue= objDict.Item(strShareString) & " N" 'append 'N' for Netware shares
  341. objDict.Item(strShareString)= strDictValue
  342. else
  343. If strShareString <> "" then
  344. objDict.Add strShareString,chr(1) & "N"
  345. end if
  346. end if
  347. Next
  348. ' Destroying dynamically created objects
  349. set ObjConnection = Nothing
  350. set objRegistryHandle = Nothing
  351. End Sub
  352. '-------------------------------------------------------------------------
  353. ' Sub Routine name: GetAppleTalkShares
  354. ' Description: Gets all AppleTalk Shares from SA machine and
  355. ' adds to Dictionary Object
  356. ' Input Variables: objDict(dictionary object)
  357. ' Output Variables: objDict
  358. ' Returns: None
  359. ' Global Variables: in: CONST_REGISTRY_APPLETALK_PATH - Registry path to access Appletalk Shares
  360. '-------------------------------------------------------------------------
  361. sub GetAppleTalkShares(ByRef objDict)
  362. Err.Clear
  363. On Error Resume Next
  364. Dim objRegistryHandle 'hold Registry connection
  365. Dim intenumkey 'hold enum key value as INTEGER
  366. Dim strenumvalue 'hold enum key value as STRING
  367. Dim strenumstringval 'hold enum key value as STRING
  368. Dim strenumstringpath 'hold value of the registry key
  369. Dim nidx 'hold count
  370. Dim ObjConnection 'hold WMI connection object
  371. Dim strDictValue 'hold string value of dictionary object
  372. Dim strShareString 'hold the share as STRING
  373. set ObjConnection = getWMIConnection("Default") 'gets the WMI connection
  374. ' Check whether the service is installed on the machine or not
  375. if not IsServiceInstalled(ObjConnection,"MacFile") then
  376. Exit sub
  377. end if
  378. ' Get the registry connection Object.
  379. set objRegistryHandle = RegConnection()
  380. ' RegEnumKey function gets the Subkeys in the given Key and Returns
  381. ' an array containing sub keys from registry
  382. intenumkey = RegEnumKeyValues(objRegistryHandle,CONST_REGISTRY_APPLETALK_PATH)
  383. For nidx= 0 to (ubound(intenumkey))
  384. strenumstringpath = getRegkeyvalue(objRegistryHandle,CONST_REGISTRY_APPLETALK_PATH,intenumkey(nidx),CONST_MULTISTRING)
  385. strShareString= trim(intenumkey(nidx)) & chr(1) & Mid(trim(strenumstringpath(3)),6)
  386. if objDict.Exists(strShareString) then
  387. strDictValue= objDict.Item(strShareString) & " A" 'append 'A' to identify APPLETALK share
  388. objDict.Item(strShareString)= strDictValue
  389. else
  390. If strShareString <> "" then
  391. objDict.Add strShareString,chr(1) & "A"
  392. end if
  393. end if
  394. Next
  395. ' Destroying dynamically created objects
  396. set ObjConnection=Nothing
  397. set objRegistryHandle=Nothing
  398. End Sub
  399. %>