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.

530 lines
16 KiB

  1. <%@ Language=VBScript %>
  2. <% Option Explicit %>
  3. <%
  4. '-------------------------------------------------------------------------
  5. ' folder_delete.asp: deletes the selected folder(s)
  6. '
  7. ' Copyright (c) Microsoft Corporation. All rights reserved.
  8. '
  9. ' Date Description
  10. ' 17-Jan-2001 Creation date
  11. ' 21-Mar-2001 Modification date
  12. '-------------------------------------------------------------------------
  13. %>
  14. <!-- #include virtual="/admin/inc_framework.asp" -->
  15. <!-- #include file="loc_folder.asp"-->
  16. <!-- #include file="inc_folders.asp"-->
  17. <%
  18. '-------------------------------------------------------------------------
  19. ' Global Variables
  20. '-------------------------------------------------------------------------
  21. Dim rc 'Page variable
  22. Dim page 'Page variable
  23. Dim G_strFolders 'List of all folders selected
  24. Dim F_ParentFolder
  25. Dim G_objService 'WMI connection
  26. '======================================================
  27. ' Entry point
  28. '======================================================
  29. set G_objService = getWMIConnection(CONST_WMI_WIN32_NAMESPACE)
  30. ' Create a Property Page
  31. rc = SA_CreatePage( L_TASKTITLE_DELETE_TEXT, "", PT_PROPERTY, page )
  32. If rc = 0 then
  33. ' Serve the page
  34. SA_ShowPage( page )
  35. End If
  36. '======================================================
  37. ' Web Framework Event Handlers
  38. '======================================================
  39. '-------------------------------------------------------------------------
  40. 'Function name: OnInitPage
  41. 'Description: Called to signal first time processing for this page. Use this method
  42. ' to do first time initialization tasks.
  43. 'Input Variables: PageIn,EventArg
  44. 'Output Variables: PageIn,EventArg
  45. 'Returns: TRUE to indicate initialization was successful. FALSE to indicate
  46. ' errors. Returning FALSE will cause the page to be abandoned.
  47. 'Global Variables: Out:F_ParentFolder
  48. ' In:None
  49. '-------------------------------------------------------------------------
  50. Public Function OnInitPage(ByRef PageIn, ByRef EventArg)
  51. Call GetOTSTableValues
  52. F_ParentFolder = Request.QueryString("parent")
  53. Call SA_MungeURL(mstrReturnURL, "PKey", F_ParentFolder)
  54. OnInitPage = True
  55. End Function
  56. '-------------------------------------------------------------------------
  57. 'Function name: OnServePropertyPage
  58. 'Description: Called when the page needs to be served. Use this method to
  59. ' serve content.
  60. 'Input Variables: None
  61. 'Output Variables: None
  62. 'Returns: TRUE to indicate initialization was successful. FALSE to indicate
  63. ' errors. Returning FALSE will cause the page to be abandoned.
  64. 'Global Variables: Out:None
  65. ' In:None
  66. '-------------------------------------------------------------------------
  67. Public Function OnServePropertyPage(ByRef PageIn, ByRef EventArg)
  68. ' Emit Javascript functions required by Web Framework
  69. Call ServeCommonJavaScript()
  70. Call ConfirmMessage()
  71. OnServePropertyPage = TRUE
  72. End Function
  73. '-------------------------------------------------------------------------
  74. 'Function name: OnPostBackPage
  75. 'Description: Called to signal that the page has been posted-back. A post-back
  76. ' occurs in tabbed property pages and wizards as the user navigates
  77. ' through pages. It is differentiated from a Submit or Close operation
  78. ' in that the user is still working with the page.
  79. 'Input Variables: None
  80. 'Output Variables: None
  81. 'Returns: TRUE to indicate initialization was successful. FALSE to indicate
  82. ' errors. Returning FALSE will cause the page to be abandoned.
  83. 'Global Variables: Out:None
  84. ' In:None
  85. '-------------------------------------------------------------------------
  86. Public Function OnPostBackPage(ByRef PageIn, ByRef EventArg)
  87. ' Get Folder name from previous form
  88. G_strFolders = Request.Form("hdnFolderName")
  89. OnPostBackPage = TRUE
  90. End Function
  91. '-------------------------------------------------------------------------
  92. 'Function name: OnSubmitPage
  93. 'Description: Called when the page has been submitted for processing. Use
  94. ' this method to process the submit request.
  95. 'Input Variables: None
  96. 'Output Variables: None
  97. 'Returns: TRUE if the submit was successful, FALSE to indicate error(s).
  98. ' Returning FALSE will cause the page to be served again using
  99. ' a call to OnServePropertyPage.
  100. 'Global Variables: Out:None
  101. ' In:None
  102. '-------------------------------------------------------------------------
  103. Public Function OnSubmitPage(ByRef PageIn, ByRef EventArg)
  104. OnSubmitPage = DeleteFolder()
  105. End Function
  106. '-------------------------------------------------------------------------
  107. 'Function name: OnClosePage
  108. 'Description: Called when the page is about to be closed. Use this method
  109. ' to perform clean-up processing.
  110. 'Input Variables: None
  111. 'Output Variables: None
  112. 'Returns: TRUE to allow close, FALSE to prevent close. Returning FALSE
  113. ' will result in a call to OnServePropertyPage.
  114. 'Global Variables: Out:None
  115. ' In:None
  116. '-------------------------------------------------------------------------
  117. Public Function OnClosePage(ByRef PageIn, ByRef EventArg)
  118. OnClosePage = TRUE
  119. End Function
  120. '======================================================
  121. ' Private Functions
  122. '======================================================
  123. '-------------------------------------------------------------------------
  124. 'Function: ServeCommonJavaScript
  125. 'Description: Serves in initializing the values,setting the form
  126. ' data and validating the form values
  127. 'Input Variables: None
  128. 'Output Variables: None
  129. 'Returns: None
  130. 'Global Variables: None
  131. '-------------------------------------------------------------------------
  132. Function ServeCommonJavaScript()
  133. %>
  134. <script language="JavaScript" src="<%=m_VirtualRoot%>inc_global.js">
  135. </script>
  136. <script language="JavaScript">
  137. //
  138. // Microsoft Server Appliance Web Framework Support Functions
  139. // Copyright (c) Microsoft Corporation. All rights reserved.
  140. //
  141. // Init Function
  142. // -----------
  143. // This function is called by the Web Framework to allow the page
  144. // to perform first time initialization.
  145. //
  146. // This function must be included or a javascript runtime error will occur.
  147. //
  148. function Init()
  149. {
  150. }
  151. // ValidatePage Function
  152. // ------------------
  153. // This function is called by the Web Framework as part of the
  154. // submit processing. Use this function to validate user input. Returning
  155. // false will cause the submit to abort.
  156. //
  157. // This function must be included or a javascript runtime error will occur.
  158. //
  159. // Returns: True if the page is OK, false if error(s) exist.
  160. function ValidatePage()
  161. {
  162. return true;
  163. }
  164. // SetData Function
  165. // --------------
  166. // This function is called by the Web Framework and is called
  167. // only if ValidatePage returned a success (true) code. Typically you would
  168. // modify hidden form fields at this point.
  169. //
  170. // This function must be included or a javascript runtime error will occur.
  171. //
  172. function SetData()
  173. {
  174. }
  175. </script>
  176. <%
  177. End Function
  178. '-------------------------------------------------------------------------
  179. 'Subroutine name: ConfirmMessage
  180. 'Description: Serves in displaying the confirm message
  181. 'Input Variables: None
  182. 'Output Variables: None
  183. 'Returns: GetFolder true/false and F_FolderExists true/false
  184. 'Global Variables: In:G_strFolders
  185. ' In:L_DELETECONFIRM_TEXT, L_CONTINUE_TEXT
  186. '
  187. '-------------------------------------------------------------------------
  188. Sub ConfirmMessage
  189. Err.Clear
  190. On Error Resume Next
  191. Dim arrFolderNames
  192. Dim nCount
  193. Dim objFolder
  194. Dim ObjSubFold
  195. Dim bFolder_exists_flag
  196. Dim bDel_msg_flag
  197. Set objFolder=CreateObject("Scripting.Filesystemobject") 'Getting the File system Object
  198. If Err.number <>0 Then
  199. SA_SetErrMsg L_FILESYSTEMOBJECTNOTCREATED_ERRORMESSAGE & "(" & Hex(Err.Number) & ")"
  200. Exit Sub
  201. End If
  202. arrFolderNames = Split(G_strFolders,chr(1))
  203. %>
  204. <table border="0" cellspacing="0" cellpadding="0">
  205. <%
  206. Dim nShrcnt 'Shared folders Count
  207. bFolder_exists_flag=False
  208. bDel_msg_flag=False
  209. For nCount = 0 to ubound(arrFolderNames) - 1
  210. Set ObjSubFold = objFolder.GetFolder(arrFolderNames(nCount))
  211. If objFolder.FolderExists(arrFolderNames(nCount)) Then 'Checking for the folder
  212. bFolder_exists_flag=True
  213. If bDel_msg_flag=False Then 'Display del confirm msg one time
  214. %>
  215. <tr>
  216. <td class="TasksBody" colspan="5">
  217. <%=L_DELETEFOLDERCONFIRM_TEXT%>
  218. </td>
  219. </tr>
  220. <tr>
  221. <td class="TasksBody" colspan="5">&nbsp;
  222. </td>
  223. </tr>
  224. <tr>
  225. <td class="TasksBody" style="border-bottom: #000000 1px solid;">
  226. <%=L_PATH_TEXT%>
  227. </td>
  228. <td width="10"></td>
  229. <td class="TasksBody" style="border-bottom: #000000 1px solid;">
  230. <%=L_ATTRIBUTE_TEXT%>
  231. </td>
  232. <td width="10"></td>
  233. <td class="TasksBody" style="border-bottom: #000000 1px solid;">
  234. <%=L_SHARED_TEXT%>
  235. </td>
  236. </tr>
  237. <% End If
  238. arrFolderNames(nCount) = replace(arrFolderNames(nCount),"/","\")
  239. nShrcnt=nCount+1
  240. If (ObjSubFold.Attributes AND 1) Then 'If Readonly
  241. %>
  242. <tr>
  243. <%If arrFolderNames(nShrcnt) <> "" Then %>
  244. <td class="TasksBody"><%=arrFolderNames(nCount)%></td>
  245. <td width="10"></td>
  246. <td class="TasksBody"> <%=L_READ_ONLY_TEXT%></td>
  247. <td width="10"></td>
  248. <td class="TasksBody"> <%=arrFolderNames(nShrcnt)%></td>
  249. <%Else%>
  250. <td class="TasksBody"><%=arrFolderNames(nCount)%></td>
  251. <td width="10"></td>
  252. <td class="TasksBody"><%=L_READ_ONLY_TEXT%></td>
  253. <td width="10"></td>
  254. <td class="TasksBody"></td>
  255. <%End If %>
  256. </tr>
  257. <%
  258. Else
  259. %>
  260. <tr>
  261. <td class="TasksBody"><%=arrFolderNames(nCount)%></td>
  262. <td width="10"></td>
  263. <td class="TasksBody"></td>
  264. <td width="10"></td>
  265. <td class="TasksBody"><%=arrFolderNames(nShrcnt)%></td>
  266. </tr>
  267. <%
  268. End If
  269. bDel_msg_flag=True 'Make the flag true to not display the del confirm msg 2nd time
  270. End If
  271. Next
  272. If bFolder_exists_flag=False Then 'If no folders exists
  273. %> </tr>
  274. <tr>
  275. <td class="TasksBody">
  276. <%=L_FOLDER_NOTEXISTS_TEXT%>
  277. </td>
  278. </tr>
  279. <% End If %>
  280. <tr>
  281. <td class="TasksBody">
  282. &nbsp;
  283. </td>
  284. </tr>
  285. <tr>
  286. <td class="TasksBody">
  287. <%= L_CONTINUE_TEXT %>
  288. </td>
  289. </tr>
  290. </table>
  291. <input type="hidden" name="hdnFolderName" value="<%=Server.HTMLEncode(G_strFolders)%>">
  292. <%
  293. End Sub
  294. '-------------------------------------------------------------------------
  295. 'Subroutine name: GetOTSTableValues
  296. 'Description: Get the names of the folders selected
  297. 'Input Variables: None
  298. 'Output Variables: None
  299. 'Returns: None
  300. 'Global Variables: Out:G_strFolders
  301. '-------------------------------------------------------------------------
  302. Sub GetOTSTableValues()
  303. Dim nCount
  304. Dim itemCount
  305. Dim itemKey
  306. Dim arrPKey
  307. itemCount = OTS_GetTableSelectionCount("")
  308. G_strFolders = ""
  309. For nCount = 1 to itemCount
  310. If ( OTS_GetTableSelection("", nCount, itemKey) ) Then
  311. arrPKey = split(itemKey, chr(1))
  312. G_strFolders = G_strFolders & arrPKey(0) & chr(1) & arrPKey(2) & chr(1)
  313. G_strFolders=UnescapeChars(G_strFolders)
  314. End If
  315. Next
  316. End Sub
  317. '-------------------------------------------------------------------------
  318. 'Function name: DeleteFolder
  319. 'Description: Serves in Delete the Folder
  320. 'Input Variables: None
  321. 'Output Variables: None
  322. 'Returns: None
  323. 'Global Variables: Out:F_Folder_name
  324. ' In:L_FILESYSTEMOBJECTNOTCREATED_ERRORMESSAGE
  325. ' L_NOTABLETODELETETHEFOLDER_ERRORMESSAGE
  326. '-------------------------------------------------------------------------
  327. Function DeleteFolder()
  328. Err.Clear
  329. On Error Resume Next
  330. Dim objFold
  331. Dim arrFolderNames
  332. Dim nCount
  333. Dim strDeleteFlag
  334. Dim strDeletedFolder
  335. Dim strUnabletoDelete
  336. Dim strServeFailureMessage
  337. Dim strDeleteFolder
  338. Dim strDelFolder
  339. DeleteFolder=False
  340. strDeleteFlag = ""
  341. strDeleteFolder=""
  342. Set objFold=Server.CreateObject("Scripting.Filesystemobject")'Getting the Object
  343. If Err.number <> 0 Then
  344. SA_SetErrMsg L_FILESYSTEMOBJECTNOTCREATED_ERRORMESSAGE &_
  345. "(" & Hex(Err.Number) & ")"
  346. Set objFold = nothing
  347. Exit Function
  348. End If
  349. arrFolderNames = split(G_strFolders,chr(1))
  350. 'strDeletedFolder = L_DELETED_MESSAGE
  351. strUnabletoDelete = ""
  352. For nCount = 0 to ubound(arrFolderNames) - 1
  353. If objFold.FolderExists(arrFolderNames(nCount)) then
  354. arrFolderNames(nCount)=replace(arrFolderNames(nCount),"/","\")
  355. objFold.DeleteFolder arrFolderNames(nCount),True
  356. If Err.number <> 0 then
  357. Err.Clear
  358. strDeleteFlag = "Yes"
  359. strUnabletoDelete = strUnabletoDelete & "<br>" & arrFolderNames(nCount)
  360. Else
  361. strDeleteFolder= strDeleteFolder & "<br>" & arrFolderNames(nCount)
  362. End If
  363. ' Delete all the shares associated with the folder deleted
  364. Call DeleteAssociatedShares( G_objService, arrFolderNames(nCount))
  365. Else
  366. arrFolderNames(nCount)=replace(arrFolderNames(nCount),"/","\")
  367. strUnabletoDelete = strUnabletoDelete & "<br>" & arrFolderNames(nCount)
  368. strDeleteFlag = "Yes"
  369. End If
  370. nCount=nCount+1
  371. Next
  372. Dim arrVarReplacementStringsUnDelete(1)
  373. Dim arrVarReplacementStringsDelete(1)
  374. If strDeleteFolder <> "" then
  375. strDelFolder = strDeletedFolder & "<br>" & strDeleteFolder
  376. 'append the Folder names to the message
  377. arrVarReplacementStringsDelete(0) = strDelFolder
  378. strDelFolder = SA_GetLocString("foldermsg.dll", "403A00C6", arrVarReplacementStringsDelete)
  379. End If
  380. If strUnabletoDelete <> "" Then
  381. 'append the Folder names to the message
  382. arrVarReplacementStringsUnDelete(0) = strUnabletoDelete
  383. strUnabletoDelete = SA_GetLocString("foldermsg.dll", "403A00C5", arrVarReplacementStringsUnDelete)
  384. End If
  385. strServeFailureMessage = strDelFolder & "<br><br>" & strUnabletoDelete
  386. 'If not able to delete the folder
  387. If strDeleteFlag = "Yes" then
  388. Set objFold = nothing
  389. Call SA_ServeFailurePageEx(strServeFailureMessage, mstrReturnURL)
  390. Exit Function
  391. Else
  392. DeleteFolder=True
  393. End If
  394. If Err.number <> 0 Then
  395. SA_SetErrMsg L_NOTABLETODELETETHEFOLDER_ERRORMESSAGE & "(" & Hex(Err.Number) & ")"
  396. Set objFold = nothing
  397. Exit Function
  398. Else
  399. DeleteFolder=True
  400. End If
  401. Set objFold = nothing
  402. End Function
  403. '-------------------------------------------------------------------------
  404. 'Function name: DeleteAssociatedShares
  405. 'Description: Serves in Delete the shares associated with the give folder
  406. 'Input Variables: objService, strFolder
  407. 'Output Variables: None
  408. 'Returns: Boolean, return True if success
  409. 'Global Variables: None
  410. '-------------------------------------------------------------------------
  411. Function DeleteAssociatedShares( objService, strFolder)
  412. Err.Clear
  413. On Error Resume Next
  414. Dim objShares
  415. Dim objShare
  416. DeleteAssociatedShares = false
  417. 'Get all windows shares from WMI
  418. Set objShares = objService.InstancesOf("Win32_Share")
  419. If Err.number <> 0 Then
  420. SA_TraceOut "Folder_delete.asp", "DeleteAssociatedShares(): Get Win32_Share error"
  421. Exit Function
  422. end if
  423. 'Check each shares
  424. for each objShare in objShares
  425. 'If the shares is associated with the deleted folder, delete it
  426. If Ucase(objShare.Path) = Ucase(strFolder) Then
  427. If not deleteShareCIFS(objService, objShare.Name) then
  428. Call SA_TraceOut("Folder_delete.asp", "DeleteAssociatedShares(): Unable to delete Windows Share")
  429. Exit Function
  430. End If
  431. End If
  432. Next
  433. DeleteAssociatedShares = true
  434. End Function
  435. %>