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.

1618 lines
52 KiB

  1. <%
  2. '-------------------------------------------------------------------------
  3. ' inc_shares.asp: common file for shares pages
  4. '
  5. ' Copyright (c) Microsoft Corporation. All rights reserved.
  6. '
  7. ' Date Description
  8. ' 14 Nov 2001 Creation Date
  9. ' 17 March 2001 Modified Date
  10. '-------------------------------------------------------------------------
  11. '-----------------------------------------------------------------------
  12. 'Global Variables
  13. '-----------------------------------------------------------------------
  14. Const CONST_NFSSHARE = "NFS SHARE" 'Constant for NFS Share
  15. Const CONST_APPLETALKSHARE = "APPLETALK SHARE" 'Constant for AppleTalk
  16. 'share
  17. Const CONST_OTHERERROR = -100
  18. Const CONST_DUPLICATEERROR = -1
  19. Const CONST_NOERROR = 0
  20. '-------------------------------------------------------------------------
  21. 'Function name: CifsNewShare
  22. 'Description: Creating a new CIFS share
  23. 'Input Variables: In:objWmiService - WMI Object
  24. ' In:strShareName - Name of the share to be created
  25. ' In:strSharePath - Path of the share to be created
  26. ' In:strComment - Description of the share to be
  27. ' created
  28. 'Output Variables: None
  29. 'Returns: True - Incase share created successfully
  30. ' False - Incase Flase If Not Implemented)
  31. ' Function used is IsValidWMIInstance
  32. '--------------------------------------------------------------------------
  33. Function CifsNewShare(objWmiService, strShareName,strSharePath,strComment)
  34. Err.Clear
  35. On Error Resume Next
  36. Dim objCifsShare 'Object to get the Instance of Win32_Share
  37. Dim objInParam 'Object to give input parameters for the
  38. 'create method of Win32_Share
  39. Dim objOutParams 'Object to capture results of the create
  40. 'method of Win32_Share
  41. Dim StrUniqueCifsShareName 'Creation of an appropriate string to check
  42. 'if valid instance
  43. CifsNewShare = CONST_OTHERERROR
  44. StrUniqueCifsShareName = "name=" & chr(34) & Cstr(strShareName) & chr(34)
  45. If IsValidWMIInstance(objWmiService,"Win32_Share",StrUniqueCifsShareName)Then
  46. 'Implies Share already Exists
  47. CifsNewShare = CONST_DUPLICATEERROR
  48. Exit Function
  49. End If
  50. Set objCifsShare=objWmiService.get("Win32_Share")
  51. If Err.number <> 0 Then
  52. SA_SetErrMsg L_SHAREWMICONNECTIONFAILED_ERRORMESSAGE
  53. Exit Function
  54. end if
  55. Set objInParam = objCifsShare.Methods_("Create").InParameters.SpawnInstance_()
  56. If Err.number <> 0 Then
  57. Exit Function
  58. End if
  59. objInParam.Properties_.Item("Description") = cstr(strComment)
  60. objInParam.Properties_.Item("Name") = cstr(strSharename)
  61. objInParam.Properties_.Item("Path") = cstr(strSharePath)
  62. objInParam.Properties_.Item("MaximumAllowed")=4294967295
  63. objInParam.Properties_.Item("Type") = 0
  64. Set objOutParams = objCifsShare.ExecMethod_("Create", objInParam)
  65. If objOutParams.ReturnValue <> 0 Then
  66. Exit Function
  67. end if
  68. CifsNewShare = CONST_NOERROR
  69. 'Clean objects
  70. Set objCifsShare =nothing
  71. Set objInParam =nothing
  72. Set objOutParams =nothing
  73. End function
  74. '-------------------------------------------------------------------------
  75. 'Function name: FtpNewShare
  76. 'Description: Creating a New ftp Share
  77. 'Input Variables: In:objWmiService
  78. ' In:strShareName
  79. ' In:strSharePath
  80. ' In:strComment
  81. 'Output Variables: None
  82. 'Returns: True If share successfully created
  83. ' Flase If share not created
  84. ' Function used is IsValidWMIInstance
  85. '--------------------------------------------------------------------------
  86. Function FtpNewShare(objWmiService, strShareName, strSharePath)
  87. Err.Clear
  88. On Error Resume Next
  89. Dim objFtpCon
  90. Dim objFtpInstance
  91. Dim objFtpConNew
  92. Dim strTempSharename
  93. Dim strUniqueFtpshareName
  94. 'Error other than the same share name
  95. FtpNewShare = CONST_OTHERERROR
  96. strUniqueFtpshareName = "name=" & chr(34) & "MSFTPSVC/1/ROOT/" & cstr(strShareName) & chr(34)
  97. if IsValidWMIInstance(objWmiService, GetIISWMIProviderClassName("IIs_FtpVirtualDir"),strUniqueFtpshareName) then
  98. FtpNewShare = CONST_DUPLICATEERROR
  99. Exit Function
  100. end if
  101. Set objFtpCon = objWmiService.get(GetIISWMIProviderClassName("IIs_FtpVirtualDir"))
  102. If Err.number <> 0 Then
  103. SA_SetErrMsg L_SHAREWMICONNECTIONFAILED_ERRORMESSAGE
  104. Exit Function
  105. End If
  106. Set objFtpInstance = objFtpCon.SpawnInstance_()
  107. If Err.number <> 0 Then
  108. Exit Function
  109. End If
  110. objFtpInstance.Name = "MSFTPSVC/1/ROOT/" & cstr(strShareName)
  111. If Err.number <> 0 then
  112. Exit Function
  113. End If
  114. objFtpInstance.Put_()
  115. If Err.number <> 0 then
  116. Exit Function
  117. End If
  118. strTempSharename = GetIISWMIProviderClassName("IIs_FtpVirtualDirSetting") & ".name=" & chr(34) & "MSFTPSVC/1/ROOT/" & cstr(strShareName) & chr(34)
  119. Set objFtpConNew = objWmiService.get(strTempSharename)
  120. If Err.number <> 0 then
  121. Exit Function
  122. End If
  123. objFtpConNew.path = cstr(strSharePath)
  124. If Err.number <> 0 then
  125. Exit Function
  126. End If
  127. objFtpConNew.Put_()
  128. If Err.number <> 0 then
  129. Exit Function
  130. End If
  131. FtpNewShare = CONST_NOERROR
  132. 'Clean Objects
  133. set objFtpConNew = nothing
  134. Set objFtpInstance=nothing
  135. set objFtpCon = nothing
  136. End function
  137. '-------------------------------------------------------------------------
  138. 'Function name: HttpNewShare
  139. 'Description: Creating a new http Share
  140. 'Input Variables: In:strShareName
  141. ' In:strSharePath
  142. 'Output Variables: None
  143. 'Returns: CONST_NOERROR - If share successfully created
  144. ' CONST_DUPLICATEERROR,CONST_OTHERERROR - If share creation failed Flase
  145. ' Function used is IsValidWMIInstance,
  146. '--------------------------------------------------------------------------
  147. Function httpnewshare(objWmiService, strShareName,strSharePath)
  148. Err.Clear
  149. On Error Resume Next
  150. ' objWmiService is not used as ADSI is being used
  151. Dim objHttpCon ' to get the Shares Site
  152. Dim objHtpInstance ' to create the new Virtual Directory
  153. Dim strHttpShareName ' to form the Query for getting the required object
  154. Dim strSiteName ' to get the Site Name for the shares (example:w3svc/10)
  155. Const ERR_DUPLICATE_HTTPSHARE = &H800700B7 ' to check for duplicate share name
  156. 'Error other than the same share name
  157. httpnewshare = CONST_OTHERERROR
  158. ' get the site number belonging to the "Shares" Site
  159. ' Example: W3SVC/10
  160. strSiteName=GetSharesWebSiteName()
  161. ' form the query to get the Shares Site object
  162. ' Example: IIS://CompName/W3SVC/10/Root
  163. strHttpShareName = "IIS://" & GetComputerName() & "/" & strSiteName & "/Root"
  164. ' Get the Object where the share needs to be created
  165. Set objHttpCon = GetObject(strHttpShareName)
  166. If Err.number <> 0 Then
  167. Err.Clear
  168. Exit Function
  169. End If
  170. ' Create the new Virtual Directory share
  171. Set objHtpInstance = objHttpCon.Create("IIsWebVirtualDir", strShareName)
  172. If Err.number <> 0 then
  173. If Err.number = ERR_DUPLICATE_HTTPSHARE Then
  174. httpnewshare = CONST_DUPLICATEERROR ' duplicate share name
  175. End If
  176. Err.Clear
  177. Exit Function
  178. End If
  179. objHtpInstance.EnableDirBrowsing=True
  180. objHtpInstance.AccessNoRemoteScript=True
  181. objHtpInstance.EnableDefaultDoc=False
  182. ' Set the share path
  183. objHtpInstance.Put "path", cstr(strSharePath)
  184. If Err.number <> 0 then
  185. Err.Clear
  186. Exit Function
  187. End If
  188. ' bring the changes to effect
  189. objHtpInstance.SetInfo
  190. If Err.number <> 0 then
  191. Err.Clear
  192. Exit Function
  193. End If
  194. ' return 0 to indicate no errors
  195. httpnewshare = CONST_NOERROR
  196. 'clean Objects
  197. Set objHttpCon = nothing
  198. Set objhtpInstance = nothing
  199. End function
  200. '-------------------------------------------------------------------------
  201. 'Function name: IsValidWMIInstance
  202. 'Description: Checks the instance for validness.
  203. 'Input Variables: objService - object to WMI
  204. ' strClassName - WMI class name
  205. ' strPropertyName - Property name of the class
  206. '
  207. 'Output Variables: None
  208. 'Returns: Returns true on Valid Instance ,
  209. ' False on invalid and also on Error
  210. ' Checks whether the given instance is valid in WMI.Returns true on valid
  211. ' false on invalid or Error.
  212. '-------------------------------------------------------------------------
  213. Function IsValidWMIInstance(objService,strClassName,strPropertyName)
  214. Err.Clear
  215. On Error Resume Next
  216. Dim strInstancePath
  217. Dim objInstance
  218. strInstancePath = strClassName & "." & strPropertyName
  219. Set objInstance = objservice.Get(strInstancePath)
  220. if NOT isObject(objInstance) or Err.number <> 0 Then
  221. IsValidWMIInstance = FALSE
  222. Err.Clear
  223. Else
  224. IsValidWMIInstance = TRUE
  225. End If
  226. 'clean objects
  227. Set objInstance=nothing
  228. End Function
  229. '-------------------------------------------------------------------------
  230. 'Function name: deleteShareCIFS
  231. 'Description: Serves in Deleting the cifs share
  232. 'Input Variables: objWmiService
  233. ' In:strShareName 'sharename
  234. 'Output Variables: None
  235. 'Returns: ( True/False)
  236. '
  237. 'Function's used are IsValidWMIInstance
  238. '-------------------------------------------------------------------------
  239. Function deleteShareCIFS(objWmiService, strShareName)
  240. Err.Clear
  241. On Error Resume Next
  242. Dim objFileServer
  243. Dim strServerName
  244. Dim StrUniqueCifsShareName
  245. deleteShareCIFS = FALSE
  246. StrUniqueCifsShareName = "name=" & chr(34) & cstr(strShareName) & chr(34)
  247. if not IsValidWMIInstance(objWmiService,"Win32_Share",StrUniqueCifsShareName) then
  248. Exit Function
  249. End if
  250. strServerName = GetComputerName()
  251. Set objFileServer = GetObject("WinNT://" & strServerName & "/lanmanserver")
  252. If Err.Number <> 0 then
  253. Err.clear
  254. Exit Function
  255. end if
  256. objFileServer.Delete "Fileshare", strShareName
  257. If Err.Number <> 0 then
  258. Err.clear
  259. Exit Function
  260. end if
  261. deleteShareCIFS = TRUE
  262. 'Clean objects
  263. Set objFileServer= Nothing
  264. End function
  265. '-------------------------------------------------------------------------
  266. 'Function name: deleteShareNFS
  267. 'Description: Serves in Deleting the NFS share
  268. 'Input Variables: In:objRegConn
  269. ' In:strShareName 'sharename
  270. 'Output Variables: None
  271. 'Returns: ( True/False)
  272. '-------------------------------------------------------------------------
  273. Function deleteShareNFS(strShareName)
  274. Err.Clear
  275. On Error Resume Next
  276. Dim strCommand
  277. deleteShareNFS = False
  278. strCommand=strShareName & " /DELETE"
  279. If SharesAtCmdLine(strCommand,CONST_NFSSHARE) = "True" Then
  280. deleteShareNFS=True
  281. Exit Function
  282. End If
  283. End Function
  284. '-------------------------------------------------------------------------
  285. 'Function name: deleteShareHTTP
  286. 'Description: Serves in Deleting the http share
  287. 'Input Variables: In:objWmiService
  288. ' In:strShareName 'sharename
  289. 'Output Variables: None
  290. 'Returns: ( True/False)
  291. '
  292. ' Function's used are IsValidWMIInstance
  293. '-------------------------------------------------------------------------
  294. Function deleteShareHTTP(objWmiService, strShareName)
  295. Err.Clear
  296. on error resume next
  297. Dim strQuery
  298. Dim objHttp
  299. Dim strSiteName
  300. deleteShareHTTP = FALSE
  301. strSiteName=GetSharesWebSiteName()
  302. strQuery = "name=" & chr(34) & strSiteName & "/ROOT/" & cstr(strShareName) & chr(34)
  303. if not IsValidWMIInstance(objWmiService,GetIISWMIProviderClassName("IIs_WebVirtualDir"),strQuery) then
  304. Exit Function
  305. End if
  306. strQuery = GetIISWMIProviderClassName("IIs_WebVirtualDir") & "." & strQuery
  307. Set objHttp = objWmiService.Get(strQuery)
  308. If Err.Number <> 0 then
  309. Err.clear
  310. Exit Function
  311. end if
  312. objHttp.Delete_()
  313. If Err.Number <> 0 then
  314. Err.clear
  315. Exit Function
  316. end if
  317. deleteShareHTTP = TRUE
  318. 'clean objects
  319. Set objHttp = nothing
  320. End function
  321. '-------------------------------------------------------------------------
  322. 'Function name: deleteShareFTP
  323. 'Description: Serves in Deleting the FTP share
  324. 'Input Variables: 'In:objWmiService
  325. 'In:strShareName 'sharename
  326. 'Output Variables: None
  327. 'Returns: ( True/False)
  328. ' Function's used are IsValidWMIInstance
  329. '-------------------------------------------------------------------------
  330. Function deleteShareFTP(objWmiService, strShareName)
  331. Err.Clear
  332. on error resume next
  333. Dim strQuery
  334. Dim objFtp
  335. deleteShareFTP = FALSE
  336. strQuery = "Name=" & Chr(34) & "MSFTPSVC/1/ROOT/"& strShareName & Chr(34)
  337. if not IsValidWMIInstance(objWmiService,GetIISWMIProviderClassName("IIs_FtpVirtualDir"),strQuery) then
  338. Exit Function
  339. End if
  340. strQuery = GetIISWMIProviderClassName("IIS_FtpVirtualDir") & "." & strQuery
  341. Set objFtp = objWmiService.Get(strQuery)
  342. If Err.Number <> 0 then
  343. Err.clear
  344. Exit Function
  345. end if
  346. objFtp.Delete_()
  347. If Err.Number <> 0 then
  348. Err.clear
  349. Exit Function
  350. End If
  351. deleteShareFTP = TRUE
  352. 'clean Objects
  353. Set objFtp =nothing
  354. End function
  355. '-------------------------------------------------------------------------
  356. 'Function name: deleteShareAppleTalk
  357. 'Description: Serves in Deleting the APPLETALK share
  358. 'Input Variables: In:strShareName 'sharename
  359. 'Output Variables: None
  360. 'Returns: ( True/False)
  361. '-------------------------------------------------------------------------
  362. Function deleteShareAppleTalk(strShareName)
  363. Err.Clear
  364. On Error Resume Next
  365. Dim strCommand
  366. deleteShareAppleTalk = False
  367. strCommand = "VOLUME /REMOVE /NAME:" & """" & strShareName & """"
  368. If SharesAtCmdLine(strCommand,CONST_APPLETALKSHARE) = "False" Then
  369. Exit Function
  370. End If
  371. deleteShareAppleTalk = True
  372. End Function
  373. '-------------------------------------------------------------------------
  374. 'Function name: CreateNFSShare
  375. 'Description: Creating the NewNFSShare
  376. 'Input Variables: strShareName , strSharePath , strPerm
  377. 'Output Variables: None
  378. 'Returns: CONST_NOERROR
  379. ' CONST_DUPLICATEERROR -same share name
  380. ' CONST_OTHERERROR -other error
  381. 'Made use of registry related functions
  382. '--------------------------------------------------------------------------
  383. Function CreateNFSShare(ByVal strShareName ,ByVal strSharePath , ByVal strPerm)
  384. Err.Clear
  385. On Error Resume Next
  386. Dim strCommand
  387. if instrrev(strSharePath,"\") = len(strSharePath) then
  388. strSharePath = left(strSharePath,len(strSharePath)-1)
  389. end if
  390. 'Forming the command line to execute at command prompt
  391. If strPerm = "" then
  392. strCommand=strShareName & "=" & Chr(34) & strSharePath & Chr(34)
  393. else
  394. strCommand=strShareName & "=" & Chr(34) & strSharePath & Chr(34) & " -o " & strPerm
  395. end if
  396. ' Comment out the following line after 2.01
  397. ' SA_TraceOut "inc_shares.asp", "CreateNFSShare: " & strCommand
  398. If SharesAtCmdLine(strCommand,CONST_NFSSHARE) = "False" Then
  399. CreateNFSShare = False
  400. Exit Function
  401. End If
  402. CreateNFSShare = True
  403. End Function
  404. '-------------------------------------------------------------------------
  405. 'Function name: CreateAppleTalkShare
  406. 'Description: Creating a new AppleTalk Share
  407. 'Input Variables: strShareName , strSharePath , strPerm
  408. 'Output Variables: None
  409. 'Returns: True/ False
  410. '
  411. 'Made use of registry related functions
  412. '--------------------------------------------------------------------------
  413. Function CreateAppleTalkShare(byval strShareName ,byval strSharePath , byval strCommand)
  414. Err.Clear
  415. On Error Resume Next
  416. If SharesAtCmdLine(strCommand,CONST_APPLETALKSHARE) = "False" Then
  417. CreateAppleTalkShare = False
  418. End If
  419. CreateAppleTalkShare=True
  420. End Function
  421. '-------------------------------------------------------------------------
  422. 'Function name: UpdateAppleTalkShare
  423. 'Description: Setting the properties of AppleTalk share
  424. 'Input Variables: strCommand
  425. 'Output Variables: None
  426. 'Returns: True/False
  427. 'To update the properties of AppleTalk share
  428. '--------------------------------------------------------------------------
  429. Function UpdateAppleTalkShare(byval strCommand)
  430. Err.Clear
  431. On Error Resume Next
  432. If SharesAtCmdLine(strCommand,CONST_APPLETALKSHARE) = "False" Then
  433. UpdateAppleTalkShare = False
  434. End If
  435. UpdateAppleTalkShare=True
  436. End Function
  437. '-------------------------------------------------------------------------
  438. 'Function name: updateCIFSShareInfo
  439. 'Description: updating the changes of CIFSShare
  440. 'Input Variables: None
  441. 'Output Variables: None
  442. 'Returns: (True / Flase )
  443. 'Global Variables: In:objWmiService
  444. ' In:strNewSharename 'share name
  445. ' In:strNewSharePath 'share path
  446. ' In:F_strNewDescription 'share description
  447. '-------------------------------------------------------------------------
  448. Function updateCIFSshareInfo(objWmiService, strShareName,strShareNewname,strNewSharePath,strNewDescription)
  449. Err.Clear
  450. on error resume next
  451. if not deleteShareCIFS(objWmiService, strShareName) then
  452. updateCIFSshareInfo = false
  453. end if
  454. if CifsNewShare(objWmiService,strShareNewname,strNewSharePath,"") then
  455. updateCIFSshareInfo = true
  456. else
  457. CifsNewShare objWmiService, strSharename,F_strSharePath,""
  458. end if
  459. end function
  460. '-------------------------------------------------------------------------
  461. 'Function name: isServiceInstalled
  462. 'Description:helper Function to chek whether the Service is installed
  463. 'Input Variables: objService - object to WMI
  464. ' strServiceName - Service name
  465. 'Output Variables: None
  466. 'Returns: (True/Flase)
  467. 'GlobalVariables: None
  468. '-------------------------------------------------------------------------
  469. Function isServiceInstalled(ObjWMI,strServiceName)
  470. Err.clear
  471. on error resume next
  472. Dim strService
  473. Dim strInstancePath
  474. Dim objInstance
  475. Dim instance
  476. Const CONST_SERVICERUNNING = "Running"
  477. Const CONST_SERVICESTOPPED = "Stopped"
  478. strService = "name=""" & strServiceName & """"
  479. strInstancePath = "Win32_Service" & "." & strService
  480. Set objInstance = ObjWMI.Get(strInstancePath)
  481. If NOT isObject(objInstance) or Err.number <> 0 Then
  482. isServiceInstalled = FALSE
  483. Exit Function
  484. Else
  485. If UCase(objInstance.State) = UCase(CONST_SERVICERUNNING) Then
  486. isServiceInstalled = TRUE
  487. Exit Function
  488. Else
  489. If UCase(objInstance.State) = UCase(CONST_SERVICESTOPPED) Then
  490. isServiceInstalled = FALSE
  491. Exit Function
  492. End If
  493. End If
  494. End If
  495. End Function
  496. '-------------------------------------------------------------------------
  497. ' Function name: GetSharesWebSiteName()
  498. ' Description: Serves in gettting the name of the "Shares" web site
  499. ' Input Variables: None
  500. ' Output Variables: None
  501. ' Returns: Name of the "Shares" web site
  502. ' Global Variables: in: G_strUrl - Return URL to folders and shares tab
  503. ' in: L_WMICLASSINSTANCEFAILED_ERRORMESSAGE
  504. '-------------------------------------------------------------------------
  505. Function GetSharesWebSiteName
  506. Err.Clear
  507. on error resume next
  508. Dim objConnection
  509. Dim strQuery
  510. Dim objHttpname,objHttpnames
  511. Const WEBSITE_FOR_SHARES="Shares"
  512. 'XPE only has one website
  513. If CONST_OSNAME_XPE = GetServerOSName() Then
  514. 'WMI query
  515. strQuery = "Select * from " & GetIISWMIProviderClassName("IIs_WebServerSetting") & " where Name =" & chr(34) & GetCurrentWebsiteName() & chr(34)
  516. Else
  517. strQuery = "Select * from " & GetIISWMIProviderClassName("IIs_WebServerSetting") & " where ServerComment=" & chr(34) & WEBSITE_FOR_SHARES & chr(34)
  518. End If
  519. set ObjConnection = getWMIConnection(CONST_WMI_IIS_NAMESPACE)
  520. Set objHttpnames = objConnection.ExecQuery(strQuery)
  521. If Err.number <> 0 then
  522. Call SA_ServeFailurepageEx(L_WMICLASSINSTANCEFAILED_ERRORMESSAGE,mstrReturnURL)
  523. end if
  524. For each objHttpname in objHttpnames
  525. GetSharesWebSiteName = objHttpname.Name
  526. Exit For
  527. Next
  528. Set objHttpnames = Nothing
  529. set ObjConnection = Nothing
  530. End Function
  531. '-------------------------------------------------------------------------
  532. ' Function name: SetDontLogProp
  533. ' Description: Serves in setting the DontLog property of the created share
  534. ' Input Variables: In:strShareName -name of the Ftp share to be created
  535. ' In:nDontLog -Integer value which will set True/False
  536. ' Output Variables: None
  537. ' Returns: TRUE/FALSE on success/Failure
  538. ' Global Variables: None
  539. '-------------------------------------------------------------------------
  540. Function SetDontLogProp(strShareName, nDontLog)
  541. Err.Clear
  542. On Error Resume Next
  543. Dim objVirtualDirectory
  544. Set objVirtualDirectory=GetObject("IIS://" & getComputerName() & "/MSFTPSVC/1/ROOT/" & strShareName)
  545. If CBool(CInt(nDontLog)) Then
  546. objVirtualDirectory.DontLog=FALSE
  547. Else
  548. objVirtualDirectory.DontLog=TRUE
  549. End If
  550. objVirtualDirectory.SetInfo
  551. 'Set to nothing
  552. Set objVirtualDirectory=Nothing
  553. If Err.number <> 0 Then
  554. SetDontLogProp=TRUE
  555. Exit Function
  556. End IF
  557. SetDontLogProp=FALSE
  558. End Function
  559. '-------------------------------------------------------------------------
  560. ' Function name: LaunchProcess
  561. ' Description: Setting the launch process
  562. ' Input Variables: strCommand,strCurDir
  563. ' Output Variables: None
  564. ' Returns: TRUE/FALSE on Success/Failure
  565. ' Global Variables: None
  566. '-------------------------------------------------------------------------
  567. Function LaunchProcess(strCommand, strCurDir)
  568. Err.Clear
  569. On error Resume Next
  570. Dim objService,objClass,objProc,objProcStartup
  571. Dim nPID
  572. Set objService = getWMIConnection(CONST_WMI_WIN32_NAMESPACE)
  573. Set objClass = objService.Get("Win32_ProcessStartup")
  574. Set objProcStartup = objClass.SpawnInstance_()
  575. objProcStartup.ShowWindow = 2
  576. Set objProc = objService.Get("Win32_Process")
  577. '
  578. ' Start the process
  579. Call SA_TraceOut("INC_SHARES", "Invoking objProc.Create(" & strCommand & ", " & strCurDir & ", ...)")
  580. Call objProc.Create(strCommand, strCurDir, objProcStartup,nPID)
  581. '
  582. ' Check for startup error
  583. If Err.number <> 0 Then
  584. LaunchProcess = Err.Number
  585. Exit function
  586. End If
  587. '
  588. ' Wait for process to complete.
  589. '
  590. Call SA_TraceOut("INC_SHARES", "Waiting for process " & nPID & " to complete")
  591. Const TIME_TO_SLEEP = 200 ' Sleep 2/10 second
  592. Dim bProcessIsBusy ' Process is busy boolean flag
  593. Dim iTimeOutCounter ' Timeout counter
  594. iTimeOutCounter = 50 ' Upper limit on our patience is 10 seconds, we are a hasty bunch.
  595. bProcessIsBusy = TRUE
  596. '
  597. ' While our process is still busy OR the Timeout counter has NOT expired
  598. '
  599. while ( bProcessIsBusy AND iTimeOutCounter > 0 )
  600. bProcessIsBusy = FALSE ' Assume process is done
  601. iTimeOutCounter = iTimeOutCounter - 1 ' Decrement time-out
  602. '
  603. ' Query the active processes to see if the process we
  604. ' spawned is still active.
  605. Dim oProcesses
  606. Dim oProcess
  607. Set oProcesses = objService.ExecQuery("Select * from Win32_Process where processId=" & nPID)
  608. For each oProcess in oProcesses
  609. '
  610. ' Found our process, it's still busy
  611. bProcessIsBusy = TRUE
  612. Next
  613. Set oProcesses = Nothing
  614. '
  615. ' Check for any errors, this should never happen. If it does we trace an error and continue. The
  616. ' time-out will break us out of this loop.
  617. If ( Err.Number <> 0 ) Then
  618. Call SA_TraceOut("INC_SHARES", "Unexpected error querying Win32_Process, error: " & Hex(Err.Number) & " " & Err.Description)
  619. End If
  620. If ( bProcessIsBusy ) Then
  621. Call SA_TraceOut("INC_SHARES", "Count down for process " & nPID & " is " & iTimeOutCounter)
  622. Call SA_Sleep(TIME_TO_SLEEP)
  623. End If
  624. WEnd
  625. LaunchProcess = 0 ' We have no way of knowing the process exit code with the Win32_Process interface
  626. 'clean up
  627. Set objProc = Nothing
  628. Set objProcStartup = Nothing
  629. Set objClass = Nothing
  630. Set objService = Nothing
  631. End Function
  632. '-------------------------------------------------------------------------
  633. ' Function name: SharesAtCmdLine
  634. ' Description: Creation/Deletion of Shares thru Cmd line
  635. ' Input Variables: strCommand, strShareType
  636. ' Output Variables: None
  637. ' Returns: TRUE/FALSE on success/Failure
  638. ' Global Variables: None
  639. ' Forming the Command Line command and launching the command line utility
  640. ' for NFS, APPLETALK
  641. '-------------------------------------------------------------------------
  642. Function SharesAtCmdLine(strCommand,strShareType)
  643. Err.clear
  644. On Error Resume Next
  645. Dim strCurDir
  646. Dim returnValue
  647. Dim blnReturnFlag
  648. 'initialize
  649. blnReturnFlag = "True"
  650. strCurDir=GetSystemPath()
  651. If UCase(strShareType) = UCASE(CONST_NFSSHARE) Then
  652. strCurDir = Left(strCurDir,3)
  653. strCommand = "cmd.exe /c " & "nfsshare.exe " & strCommand
  654. End If
  655. If UCase(strShareType) = UCASE(CONST_APPLETALKSHARE) Then
  656. strCommand= "cmd.exe /c " & "macfile.exe " & strCommand
  657. End If
  658. ' Comment out the following line after 2.01
  659. ' SA_TraceOut "inc_shares.asp", "SharesAtCommandLine: " & strCommand
  660. returnValue = LaunchProcess(strCommand, strCurDir)
  661. If returnValue <> 0 Then
  662. blnReturnFlag = "False"
  663. SharesAtCmdLine=blnReturnFlag
  664. Exit Function
  665. End If
  666. SharesAtCmdLine=blnReturnFlag
  667. End Function
  668. '-------------------------------------------------------------------------
  669. 'Function name: ServetoListBox
  670. 'Description: Serve the <OPTION> HTML code
  671. 'Input Variables: String containing values to be displayed as <Option> values
  672. 'Output Variables: None
  673. 'Returns: None
  674. '-------------------------------------------------------------------------
  675. Function ServetoListBox(strInput)
  676. Err.Clear
  677. On Error Resume Next
  678. Dim arrInput
  679. Dim nIndex
  680. Dim arrTemp
  681. arrInput = split(strInput,chr(1))
  682. for nIndex = 1 to ubound(arrInput)
  683. if instr(arrInput(nIndex),chr(2)) = 0 then
  684. Response.write "<OPTION VALUE='" & arrInput(nIndex) &"'> " _
  685. & arrInput(nIndex) &"</OPTION>"
  686. else
  687. arrTemp = split(arrInput(nIndex),chr(2))
  688. Response.write "<OPTION VALUE='" & arrTemp(0) &"'> " _
  689. & arrTemp(1) &"</OPTION>"
  690. end if
  691. next
  692. End Function
  693. '-------------------------------------------------------------------------
  694. 'Function name: buildSpaces
  695. 'Description: Helper function to return String with nbsps which
  696. ' act as spaces in the list box
  697. 'Input Variables: nSpacesCount - Number of spaces
  698. '
  699. 'Output Variables: None
  700. 'Returns: spacesstring -Returns the nbsp string
  701. '-------------------------------------------------------------------------
  702. Function buildSpaces(nSpacesCount)
  703. Err.Clear
  704. On Error Resume Next
  705. Dim i , strSpace
  706. strSpace="&nbsp;"
  707. 'Forming a string with the count send as parameter
  708. For i=1 To nSpacesCount
  709. strSpace=strSpace & "&nbsp;"
  710. Next
  711. buildSpaces=strSpace
  712. End Function
  713. '-------------------------------------------------------------------------
  714. 'Function name: isValidInstance
  715. 'Description: Checks the instance for valid ness.
  716. 'Input Variables: objService - object to WMI
  717. ' strClassName - WMI class name
  718. ' strPropertyName - Property name of the class
  719. '
  720. 'Output Variables: None
  721. 'Returns: Returns true on Valid Instance ,
  722. ' False on invalid and also on Error
  723. ' Checks whether the given instance is valid in WMI.Returns true on valid
  724. ' false on invalid or Error.
  725. '-------------------------------------------------------------------------
  726. Function isValidInstance(objService,strClassName,strPropertyName)
  727. Err.Clear
  728. On Error Resume Next
  729. Dim strInstancePath
  730. Dim objInstance
  731. On Error Resume Next
  732. strInstancePath = strClassName & "." & strPropertyName
  733. Set objInstance = objservice.Get(strInstancePath)
  734. if NOT isObject(objInstance) or Err.number <> 0 Then
  735. isValidInstance = FALSE
  736. Err.Clear
  737. Else
  738. isValidInstance = TRUE
  739. End If
  740. End Function
  741. '-------------------------------------------------------------------------
  742. 'Function: GetSystemPath()
  743. 'Description: To get the Operating System path
  744. 'Input Variables: None
  745. 'Output Variables: None
  746. 'Returns: Operating system path
  747. 'Global Variables: None
  748. '-------------------------------------------------------------------------
  749. Function GetSystemPath()
  750. On Error Resume Next
  751. Err.Clear
  752. Dim objOS 'Create instance of Win32_OperatingSystem
  753. Dim objOSInstance
  754. Dim strSystemPath 'OS path
  755. Dim objConnection 'Connection to WMI
  756. Dim strQuery 'Query string
  757. strQuery = "Select * from Win32_OperatingSystem"
  758. 'Connection to WMI
  759. set objConnection = getWMIConnection(CONST_WMI_WIN32_NAMESPACE)
  760. 'Error message incase faield to connect to WMI
  761. If Err.number<>0 then
  762. Call SA_ServeFailurePageEx(L_FAILEDTOGETWMICONNECTION_ERRORMESSAGE,mstrReturnURL)
  763. GetSystemPath=""
  764. Exit Function
  765. End if
  766. 'Execute Query
  767. Set objOS = objConnection.ExecQuery(strQuery)
  768. 'Get OS installed path
  769. For Each objOSInstance in objOS
  770. strSystemPath = objOSInstance.SystemDirectory
  771. Next
  772. Set objOS = Nothing
  773. Set objOSInstance = Nothing
  774. Set objConnection = Nothing
  775. GetSystemPath = strSystemPath
  776. End Function
  777. '---------------------CIFS Common Functuion -----------------------------------
  778. '-------------------------------------------------------------------------
  779. ' Function name: checkradio
  780. ' Description: gets the CIFS properties from system
  781. ' Input Variables: intMaxValue - Userlimit value
  782. ' intCheck - radio button value(y/n)
  783. ' Output Variables: None
  784. ' Return Values: True on sucess, False on error (and error msg
  785. ' will be set by SA_SetErrMsg)
  786. ' Global Variables:
  787. ' Out: F_nUserLimit - Allow user Limit value( + ve integer)
  788. ' Out: F_strUserlimitcheck_n - Allow users radio status value
  789. ' Out: F_strUserlimitcheck_y - Allow users radio status value
  790. ' Out: F_strUservaluedisable - Allow user textbox status value
  791. ' Out: F_strAllowUsersData -,seperated string of allowuser flag and value
  792. ' Sets the CIFS Allow maximum option radio buttons values .and updates F_strAllowUsersData
  793. ' used while setting the property
  794. '-------------------------------------------------------------------------
  795. Function checkradio(intMaxValue,intCheck)
  796. On Error Resume Next
  797. Err.Clear
  798. F_nUserLimit=intMaxValue
  799. if intCheck="n" then
  800. F_strUserlimitcheck_n="CHECKED"
  801. F_strUservaluedisable = ""
  802. F_strAllowUsersData ="n" & "," & intMaxValue
  803. else
  804. F_strUserlimitcheck_y="CHECKED"
  805. F_strUservaluedisable ="DISABLED"
  806. F_strAllowUsersData ="y" & ","
  807. end if
  808. End Function
  809. '-------------------------------------------------------------------------
  810. ' Function name: SetTrustee
  811. ' Description: returns Trustee object with user,domain and SID object
  812. ' Input Variables: strDomain - Domain name
  813. ' strName - User name
  814. ' objSID - SID object
  815. ' Output Variables: None
  816. ' Return Values: Return Trustee object
  817. ' Global Variables: In: L_DACLOBJECT_ERRORMESSAGE
  818. ' Creates Trustee object on error of creation it displays error using SA_SetErrMsg()
  819. '-------------------------------------------------------------------------
  820. Function SetTrustee(strDomain, strName, objSID)
  821. Err.Clear
  822. On Error Resume Next
  823. Dim objTrustee
  824. Set objTrustee = GetObject("Winmgmts:" & SA_GetWMIConnectionAttributes() & "!root/cimv2:Win32_Trustee").SpawnInstance_
  825. If Err.number <> 0 Then
  826. SA_SetErrMsg L_DACLOBJECT_ERRORMESSAGE & "(" & Err.Number & ")"
  827. Exit Function
  828. End If
  829. objTrustee.Domain = strDomain
  830. objTrustee.Name = strName
  831. objTrustee.Properties_.Item("SID") = objSID
  832. Set SetTrustee = objTrustee
  833. End Function
  834. '-------------------------------------------------------------------------
  835. ' Function name: SetACE
  836. ' Description: returns ACE object with AccessMask, AceFlags,
  837. ' AceType, Trustee object set.
  838. ' Input Variables: nAccessMask - accessmask value
  839. ' nAceFlags - ace flag value
  840. ' nAceType - ace type( allow-0 or deny-1)
  841. ' objTrustee - trustee object
  842. ' Output Variables: None
  843. ' Return Values: Return ACE object
  844. ' Global Variables: In: L_ACEOBJECT_ERRORMESSAGE
  845. ' Creates ACE object on error of creation it displays error using SA_SetErrMsg()
  846. '-------------------------------------------------------------------------
  847. Function SetACE(nAccessMask, nAceFlags, nAceType, objTrustee)
  848. On Error Resume Next
  849. Err.clear
  850. Dim objACE
  851. Set objACE = GetObject("Winmgmts:" & SA_GetWMIConnectionAttributes() & "!root/cimv2:Win32_Ace").SpawnInstance_
  852. If Err.number <> 0 Then
  853. SA_SetErrMsg L_ACEOBJECT_ERRORMESSAGE & "(" & Err.Number & ")"
  854. Exit Function
  855. End If
  856. objACE.Properties_.Item("AccessMask") = nAccessMask
  857. objACE.Properties_.Item("AceFlags") = nAceFlags
  858. objACE.Properties_.Item("AceType") = nAceType
  859. objACE.Properties_.Item("Trustee") = objTrustee
  860. Set SetACE = objACE
  861. End Function
  862. '-------------------------------------------------------------------------
  863. ' Function name: getsidvalue
  864. ' Description: returns SID value in string format
  865. ' Input Variables: strDomain - Domain name
  866. ' strUsername - User name
  867. ' Output Variables: None
  868. ' Return Values: SID value in string format
  869. ' Global Variables: In: L_SIDOBJECT_ERRORMESSAGE
  870. ' In: G_objService - object of WMI service
  871. ' returns SID value in string format on error of creation it displays error using SA_SetErrMsg()
  872. '-------------------------------------------------------------------------
  873. Function getsidvalue(strUsername,strDomain)
  874. Err.Clear
  875. On Error Resume Next
  876. Dim objSID
  877. Dim objInstance
  878. Dim strSID
  879. Dim strComputerName
  880. strComputerName = chr(34) & GetComputerName() & chr(34)
  881. strUsername = chr(34) & strUsername & chr(34)
  882. strDomain = chr(34) & strDomain & chr(34)
  883. Set objInstance = G_objService.Get("Win32_Account.Domain="& strDomain & ",Name="&strUsername)
  884. '
  885. ' In GetSystemAccount() (inc_accountsgroups.asp), NT Authority is used as the domain name.
  886. ' However, in XPE, NT Authority is not queryable thru WMI (not a valid domain name).
  887. ' To minimize the change, we still keep the NT Authority as the domain name, but when query
  888. ' for a Win32_Account object fails, we check whether the domain name is NT Authority,
  889. ' if it is, we try to use the computername as the domain name and do a WMI query again.
  890. ' The same is true for the domain name "Builtin".
  891. '
  892. ' Also in XPE, the "Everyone" domain is not "" anymore, but the computername.
  893. '
  894. if (Not IsObject(objInstance)) Then
  895. if (strDomain = chr(34) & getNTAuthorityDomainName(G_objService) & chr(34)) or _
  896. (strDomain = chr(34) & getBuiltinDomainName(G_objService) & chr(34)) or _
  897. (strDomain = chr(34) & "" & chr(34)) Then
  898. ' Clean the error caused by invalid domain name of NT Authority or Builtin
  899. if Err.number <> 0 Then
  900. Err.Clear
  901. End If
  902. Set objInstance = G_objService.Get("Win32_Account.Domain="& strComputerName & ",Name="&strUsername)
  903. End If
  904. End If
  905. strSID = objInstance.SID
  906. strSID = chr(34) & strSID & chr(34)
  907. Set objSID = G_objService.Get("Win32_SID.SID="&strSID)
  908. If Err.number <> 0 Then
  909. SA_SetErrMsg L_SIDOBJECT_ERRORMESSAGE & "(" & Err.Number & ")"
  910. Exit Function
  911. End If
  912. getsidvalue= objSID.BinaryRepresentation
  913. End Function
  914. '-------------------------------------------------------------------------
  915. ' Function name: getBinarySIDforstirngSID
  916. ' Description: returns SID value in Binary Representation
  917. ' Input Variables: strSID - SID value in string format
  918. ' Output Variables: None
  919. ' Return Values: SID value in Binary format
  920. ' Global Variables: In: L_SIDOBJECT_ERRORMESSAGE
  921. ' In: G_objService - object of WMI service
  922. ' returns SID value in Binary format on error of creation it displays error using SA_SetErrMsg()
  923. '-------------------------------------------------------------------------
  924. Function getBinarySIDforstirngSID(strSID)
  925. On Error Resume Next
  926. Err.Clear
  927. Dim objSID
  928. strSID = chr(34) & strSID & chr(34)
  929. Set objSID = G_objService.Get("Win32_SID.SID=" & strSID)
  930. If Err.number <> 0 Then
  931. SA_SetErrMsg L_SIDOBJECT_ERRORMESSAGE & "(" & Err.Number & ")"
  932. Exit Function
  933. End If
  934. getBinarySIDforstirngSID= objSID.BinaryRepresentation
  935. End Function
  936. '-------------------------------------------------------------------------
  937. ' Function name: getShareCacheProp
  938. ' Description: gets the CIFS share cache properties from registry.
  939. ' Input Variables: strShareName - CIFS sharename
  940. ' Output Variables: None
  941. ' Return Values: Folder cache option value
  942. ' returns Folder cache option value.
  943. '-------------------------------------------------------------------------
  944. Function getShareCacheProp(strShareName)
  945. Err.Clear
  946. On Error Resume next
  947. Dim G_objCIFSRegistry
  948. Dim strPath
  949. Dim arrControllist
  950. Dim strCSCFlag
  951. set G_objCIFSRegistry = RegConnection()
  952. strPath = "SYSTEM\CurrentControlSet\Services\lanmanserver\Shares"
  953. arrControllist = getRegkeyvalue(G_objCIFSRegistry,strPath,strShareName,CONST_MULTISTRING)
  954. if instr(arrControllist(0),"CSCFlags") > 0 then
  955. strCSCFlag = split(arrControllist(0),"=")
  956. getShareCacheProp = strCSCFlag(1)
  957. else
  958. getShareCacheProp = "0"
  959. End If
  960. End Function
  961. '-------------------------------------------------------------------------
  962. ' Function name: setShareCacheProp
  963. ' Description: sets the CIFS cache properties into registry.
  964. ' Input Variables: strShareName - CIFS share name
  965. ' nCacheOption - Folder cache option value
  966. ' Output Variables: None
  967. ' Return Values: True on success false on failure
  968. ' Global Variables: in: L_FAILEDTOSETCACHEOPTION_ERRORMESSAGE
  969. ' sets the CIFS cache properties into registry. on Error sets error message
  970. ' using SA_SetErrMsg()
  971. '-------------------------------------------------------------------------
  972. Function setShareCacheProp(strShareName,nCacheOption)
  973. on Error Resume next
  974. Err.Clear
  975. Dim objCache
  976. Const CONST_CIFS_CACHE_DISABLE = &H00000030
  977. Const CONST_CIFS_CACHE_MANUAL_DOCS = &H00000000
  978. Const CONST_CIFS_CACHE_AUTO_PROGRAMS = &H00000020
  979. Const CONST_CIFS_CACHE_AUTO_DOCS = &H00000010
  980. Set objCache = CreateObject("ShareSetInfo.ShareInfo")
  981. Select Case nCacheOption
  982. case 16
  983. call objCache.SetShareInfo(strShareName, CONST_CIFS_CACHE_AUTO_DOCS)
  984. case 32
  985. call objCache.SetShareInfo(strShareName, CONST_CIFS_CACHE_AUTO_PROGRAMS)
  986. case 48
  987. call objCache.SetShareInfo(strShareName, CONST_CIFS_CACHE_DISABLE)
  988. Case Else
  989. call objCache.SetShareInfo(strShareName, CONST_CIFS_CACHE_MANUAL_DOCS)
  990. End Select
  991. if Err.number <> 0 then
  992. SA_SetErrMsg L_FAILEDTOSETCACHEOPTION_ERRORMESSAGE & "(" & Err.Number & ")"
  993. setShareCacheProp = false
  994. Exit Function
  995. End If
  996. setShareCacheProp = true
  997. End Function
  998. '-------------------------------------------------------------------------
  999. ' Function name: restartServerService
  1000. ' Description: stops and starts the 'Server' service
  1001. ' Input Variables: None.
  1002. ' Output Variables: None.
  1003. ' Return Values: True on success false on failure
  1004. ' Global Variables: in: G_objService - object to WMI Service
  1005. ' In: L_FAILEDSTART_ERRORMESSAGE
  1006. ' In: L_FAILEDTOGETOBJECT_ERRORMESSAGE
  1007. ' In: L_FAILEDTOSETCACHEOPTION_ERRORMESSAGE
  1008. ' stops 3 services(Distributed filesystem service,Computer Browser service
  1009. ' Server service and Starts Server service. on Error sets error message
  1010. ' using SA_SetErrMsg()
  1011. '-------------------------------------------------------------------------
  1012. Function restartServerService()
  1013. Err.Clear
  1014. On Error Resume next
  1015. Dim objRPCServer
  1016. Dim objDFSServer
  1017. Dim objBROWSERServer
  1018. Set objRPCServer = G_objService.get("Win32_Service.Name=" & chr(34) & "lanmanserver" & chr(34))
  1019. if Err.number <>0 then
  1020. SA_SetErrMsg L_FAILEDTOGETOBJECT_ERRORMESSAGE & "(" & Err.Number & ")"
  1021. restartServerService = false
  1022. Exit function
  1023. End If
  1024. set objDFSServer = G_objService.get("Win32_Service.Name=" & chr(34) & "Dfs" & chr(34))
  1025. if Err.number <>0 then
  1026. SA_SetErrMsg L_FAILEDTOGETOBJECT_ERRORMESSAGE & "(" & Err.Number & ")"
  1027. restartServerService = false
  1028. Exit function
  1029. End If
  1030. set objBROWSERServer = G_objService.get("Win32_Service.Name=" & chr(34) & "Browser" & chr(34))
  1031. if Err.number <>0 then
  1032. SA_SetErrMsg L_FAILEDTOGETOBJECT_ERRORMESSAGE & "(" & Err.Number & ")"
  1033. restartServerService = false
  1034. Exit function
  1035. End If
  1036. 'stopping the server service
  1037. objDFSServer.ExecMethod_ "StopService",null,0,null
  1038. if Err.number <>0 then
  1039. SA_SetErrMsg L_FAILEDTOSTOP_DFSSERVICE_ERRORMESSAGE & "(" & Err.Number & ")"
  1040. restartServerService = false
  1041. Exit function
  1042. End If
  1043. objBROWSERServer.ExecMethod_ "StopService",null,0,null
  1044. if Err.number <>0 then
  1045. SA_SetErrMsg L_FAILEDTOSTOP_BROWSERSERVICE_ERRORMESSAGE & "(" & Err.Number & ")"
  1046. restartServerService = false
  1047. Exit function
  1048. End If
  1049. objRPCServer.ExecMethod_ "StopService",null,0,null
  1050. if Err.number <>0 then
  1051. SA_SetErrMsg L_FAILEDTOSTOP_SERVERSERVICE_ERRORMESSAGE & "(" & Err.Number & ")"
  1052. restartServerService = false
  1053. Exit function
  1054. End If
  1055. 'starting the service
  1056. objDFSServer.ExecMethod_ "StartService",null,0,null
  1057. if Err.number <>0 then
  1058. SA_SetErrMsg L_FAILEDSTART_ERRORMESSAGE & "(" & Err.Number & ")"
  1059. restartServerService = false
  1060. Exit function
  1061. End If
  1062. objBROWSERServer.ExecMethod_ "StartService",null,0,null
  1063. if Err.number <>0 then
  1064. SA_SetErrMsg L_FAILEDSTART_ERRORMESSAGE & "(" & Err.Number & ")"
  1065. restartServerService = false
  1066. Exit function
  1067. End If
  1068. objRPCServer.ExecMethod_ "StartService",null,0,null
  1069. if Err.number <>0 then
  1070. SA_SetErrMsg L_FAILEDSTART_ERRORMESSAGE & "(" & Err.Number & ")"
  1071. restartServerService = false
  1072. Exit function
  1073. End If
  1074. Set objRPCServer =Nothing
  1075. restartServerService = True
  1076. End Function
  1077. '---------------------End CIFS Common Functuions -------------------------------
  1078. '---------------------FTP Common Functuions -----------------------------------
  1079. '-------------------------------------------------------------------------
  1080. ' Function name: GetFTPShareObject
  1081. ' Description: Serves in getting the share object
  1082. ' If any error, calls Call SA_ServeFailurePageExand never returns
  1083. ' This is a support function for SetFTPshareProp and
  1084. ' FTPOnInitPage
  1085. ' Input Variables: None
  1086. ' Output Variables: None
  1087. ' Returns: the FTP Share Object from WMI
  1088. ' (for getting or setting the properties for the share)
  1089. ' Global Variables:
  1090. ' In: L_* - Localization content(form label text)
  1091. ' In: F_strShareName - the name of the share
  1092. ' (comes from the previous page)
  1093. '-------------------------------------------------------------------------
  1094. Function GetFTPShareObject()
  1095. Err.Clear
  1096. On Error Resume Next
  1097. Dim objFTPShare ' the share object for which properties are read/changed
  1098. Dim objService ' the service object to get wmi connection
  1099. Dim strQuery ' the path of the object to be obtained
  1100. ' build the query to get the object
  1101. ' example for share object: "MSFTPSVC/1/ROOT/myVirtualDir")
  1102. strQuery = GetIISWMIProviderClassName("IIs_FtpVirtualDirSetting") & ".Name=" & Chr(34) & CONST_FTPWMIPATH & F_strShareName & Chr(34)
  1103. ' get the wmi connection first
  1104. Set objService = GetWMIConnection(CONST_WMI_IIS_NAMESPACE)
  1105. If Err.Number <> 0 then
  1106. Call SA_ServeFailurePageEx (L_SHAREWMICONNECTIONFAILED_ERRORMESSAGE ,mstrReturnURL)
  1107. Set objService = Nothing
  1108. Exit Function
  1109. End If
  1110. ' get the required shared object
  1111. Set objFTPShare = objService.Get(strQuery)
  1112. If Err.Number <> 0 Then
  1113. ' the share is removed/renamed
  1114. Call SA_ServeFailurePageEx (L_SHARE_NOT_FOUND_ERRORMESSAGE, mstrReturnURL)
  1115. Set objFTPShare = Nothing
  1116. Set objService = Nothing
  1117. Exit Function
  1118. End If
  1119. ' set the return value
  1120. Set getFTPShareObject = objFTPShare
  1121. ' clean up
  1122. Set objFTPShare = Nothing
  1123. Set objService = Nothing
  1124. End Function
  1125. '---------------------End of FTP Common Functuions -----------------------------------
  1126. '--------------------- HTTP Common Functuions -----------------------------------
  1127. '-------------------------------------------------------------------------
  1128. ' Function name: getHTTPShareObject
  1129. ' Description: Serves in getting the share object
  1130. ' If any error, calls Call SA_ServeFailurePageExand never returns
  1131. ' This is a support function for SetHTTPshareProp and
  1132. ' HTTPOnInitPage
  1133. ' Input Variables: None
  1134. ' Output Variables: None
  1135. ' Returns: the HTTP Share Object from ADSI(for getting or setting the properties for the share)
  1136. ' Global Variables: In: L_* - Localization content(form label text)
  1137. ' In: F_strShareName - the name of the share
  1138. ' (comes from the previous page)
  1139. '-------------------------------------------------------------------------
  1140. Function getHTTPShareObject()
  1141. Err.Clear
  1142. On Error Resume Next
  1143. Dim objHTTPShare ' the share object for which properties are read/changed
  1144. Dim strQuery ' the path of the object to be obtained
  1145. Dim strSiteName ' the "Shares" Site name (example: w3svc/10)
  1146. strSiteName=GetSharesWebSiteName()
  1147. ' build the query to get the object
  1148. ' example for share object: "IIS://CompName/w3svc/10/Root")
  1149. strQuery = CONST_IIS & GetComputerName() & "/" & strSiteName & CONST_ROOT & F_strShareName
  1150. ' get the required shared object
  1151. Set objHTTPShare = GetObject(strQuery)
  1152. If Err.Number <> 0 then
  1153. Call SA_ServeFailurepageEx(L_SHARE_NOT_FOUND_ERRORMESSAGE,mstrReturnURL)
  1154. Exit Function
  1155. End If
  1156. ' set the return value
  1157. Set getHTTPShareObject = objHTTPShare
  1158. ' clean up
  1159. Set objHTTPShare = Nothing
  1160. End Function
  1161. '--------------------- END OF HTTP Common Functuions -----------------------------------
  1162. '--------------------- General Common Functuions -----------------------------------
  1163. '-------------------------------------------------------------------------
  1164. 'Function name: ShowErrorMessage
  1165. 'Description: to display error messages accordingly(either
  1166. ' duplicate share name/share name not valid)
  1167. 'Input Variables: arrStr
  1168. 'Output Variables: None
  1169. 'Returns: Error message
  1170. 'Global Variables: None
  1171. ' in:L_(*)
  1172. '--------------------------------------------------------------------------
  1173. Function ShowErrorMessage(arrStr)
  1174. Err.Clear
  1175. on error resume next
  1176. Dim strErrMsg 'var to store the Error message
  1177. strErrMsg = L_SHARESTATUS_ERRORMESSAGE & "<I>" &arrStr(0)&"</I>" & "<BR>"
  1178. ShowErrorMessage = strErrMsg
  1179. End Function
  1180. '-------------------------------------------------------------------------
  1181. 'Function name: ShowError
  1182. 'Description: to display error withred color
  1183. 'Input Variables: strMsg
  1184. 'Output Variables: None
  1185. 'Returns: (True / Flase )
  1186. 'Global Variables: None
  1187. '--------------------------------------------------------------------------
  1188. Function ShowErrorinRed(strMsg)
  1189. Err.Clear
  1190. On Error Resume Next
  1191. 'displays error withred color
  1192. Response.write "<font color='red'>" & strMsg & "*</font>"
  1193. End Function
  1194. '-------------------------------------------------------------------------
  1195. 'Function name: SelectCheckBox
  1196. 'Description: to display the check box
  1197. 'Input Variables: strCheckBoxName,blnCheck,blnDisabled
  1198. 'Output Variables: None
  1199. 'Returns: (True / Flase )
  1200. 'Global Variables: None
  1201. '--------------------------------------------------------------------------
  1202. Function SelectCheckBox(strCheckBoxName,blnCheck,blnDisabled)
  1203. Err.Clear
  1204. On Error Resume Next
  1205. Dim strCheckBox 'to hold HTML contents
  1206. strCheckBox = "<input type='checkbox' class='FormCheckBox' value='" & strCheckBoxName &"' name='clients'"
  1207. 'to display the checkbox as checked
  1208. If blnCheck Then
  1209. strCheckBox = strCheckBox & "checked"
  1210. End If
  1211. 'to display the checkbox as disabled
  1212. If blnDisabled Then
  1213. strCheckBox = strCheckBox & " disabled"
  1214. End If
  1215. 'displaying the checkbox and it's calling disabledescription function
  1216. 'on click event
  1217. strCheckBox = strCheckBox &" >"
  1218. response.write strCheckBox
  1219. End Function
  1220. '-------------------------------------------------------------------------
  1221. 'Function name: FrameErrorMessage
  1222. 'Description: to frame error messages to display error messages
  1223. ' accordingly(either duplicate share name/share name not valid)
  1224. 'Input Variables: arrStr,nRetVal,strShareType
  1225. 'Output Variables: arrStr
  1226. 'Returns: Error messages
  1227. 'Global Variables: None
  1228. '--------------------------------------------------------------------------
  1229. Function FrameErrorMessage( arrStr,nRetVal,strShareType)
  1230. Err.Clear
  1231. On Error Resume Next
  1232. Select Case nRetVal
  1233. Case -100 'case other than duplicate share
  1234. arrStr(0) = arrStr(0) & strShareType
  1235. Case -1 'case for duplicate share name
  1236. arrStr(1) = arrStr(1)& strShareType
  1237. End select
  1238. End Function
  1239. '--------------------- General Common Functions -----------------------------------
  1240. '-------------------------------------------------------------------------
  1241. 'Function: GetSystemDrive()
  1242. 'Description: To get the Operating System Drive
  1243. 'Input Variables: None
  1244. 'Output Variables: None
  1245. 'Returns: Operating system Drive
  1246. 'Global Variables: None
  1247. '-------------------------------------------------------------------------
  1248. Function GetSystemDrive
  1249. Err.Clear
  1250. On Error Resume Next
  1251. Dim objFso
  1252. GetSystemDrive = "C:"
  1253. Set objFso = Server.CreateObject("Scripting.FileSystemObject")
  1254. If Err.Number <> 0 Then
  1255. SA_TraceOut "GetSystemDrive", "failed to call CreateObject"
  1256. Exit Function
  1257. End If
  1258. GetSystemDrive = objFso.GetSpecialFolder(0).Drive
  1259. If Err.Number <> 0 Then
  1260. SA_TraceOut "GetSystemDrive", "failed to call GetSpecialFolder"
  1261. Exit Function
  1262. End If
  1263. End Function
  1264. Function Ping(ByVal sIP)
  1265. on error resume next
  1266. err.Clear()
  1267. Dim oHelper
  1268. Ping = FALSE
  1269. Set oHelper = CreateObject("ComHelper.NetworkTools")
  1270. if ( Err.Number <> 0 ) Then
  1271. Call SA_TraceOut("INC_SHARES", "Error creating ComHelper.NetworkTools object, error: " + CStr(Hex(Err.Number)))
  1272. Exit Function
  1273. End If
  1274. Ping = oHelper.Ping(sIP)
  1275. if ( Err.Number <> 0 ) Then
  1276. Ping = FALSE
  1277. Call SA_TraceOut("INC_SHARES", "oHelper.Ping(), error: " + CStr(Hex(Err.Number)) + " " + Err.Description)
  1278. Exit Function
  1279. End If
  1280. if ( Ping > 0 ) Then
  1281. Ping = TRUE
  1282. End If
  1283. Set oHelper = Nothing
  1284. End Function
  1285. '-------------------------------------------------------------------------
  1286. 'Function name: isPathExisting
  1287. 'Description: checks for the directory existing
  1288. 'Input Variables: strDirectoryPath
  1289. 'Output Variables: None
  1290. 'Returns: (True / Flase )
  1291. 'Global Variables: None
  1292. ' True ->If Implemented properly
  1293. ' False->If Not Implemented
  1294. '--------------------------------------------------------------------------
  1295. Function isPathExisting(strDirectoryPath)
  1296. Err.Clear
  1297. On Error Resume Next
  1298. Dim objFSO 'to create filesystemobject instance
  1299. isPathExisting = true
  1300. 'get the filesystemobject instance
  1301. Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
  1302. 'Checks for existence of the given path
  1303. If NOT objFSO.FolderExists(strDirectoryPath) Then
  1304. 'Checks if the given path is drive only
  1305. If NOT objFSO.DriveExists(strDirectoryPath) Then
  1306. isPathExisting = False
  1307. Exit Function
  1308. End if
  1309. End If
  1310. 'clean the object
  1311. Set objFSO = nothing
  1312. End Function
  1313. %>