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.

460 lines
15 KiB

  1. <%@ Language=VBScript %>
  2. <% Option Explicit %>
  3. <%
  4. '---------------------------------------------------------------------
  5. ' share_delete.asp : Deletes the selected share
  6. '
  7. ' Copyright (c) Microsoft Corporation. All rights reserved.
  8. '
  9. ' Date Description
  10. ' 23-01-2001 Created date
  11. ' 19-03-2001 Modified date
  12. '---------------------------------------------------------------------
  13. %>
  14. <!-- #include virtual="/admin/inc_framework.asp" -->
  15. <!-- #include file="loc_shares.asp" -->
  16. <!-- #include file="inc_shares.asp" -->
  17. <%
  18. '---------------------------------------------------------------------
  19. ' Global Variables
  20. '---------------------------------------------------------------------
  21. Dim rc ' return code for SA_CreatePage
  22. Dim page ' the page object
  23. Dim G_ShareType ' hold share type
  24. Dim G_strShareNames ' concatenated string of shares to be deleted
  25. Dim G_strFolderPath ' concatenated string of sharePaths
  26. Dim SOURCE_FILE ' the source file name used while Tracing
  27. ' get the source file name to use while Tracing
  28. SOURCE_FILE = SA_GetScriptFileName()
  29. ' Create a Property Page
  30. rc = SA_CreatePage(L_SHARETASKTITLE_DELETE_TEXT, "", PT_PROPERTY, page )
  31. If rc = SA_NO_ERROR Then
  32. ' show the page
  33. Call SA_ShowPage(page)
  34. End If
  35. '-------------------------------------------------------------------------
  36. ' Function: OnInitPage()
  37. ' Description: Called to signal first time processing for this page.
  38. ' Used to do first time initialization tasks
  39. ' Input Variables: PageIn,EventArg
  40. ' Output Variables: PageIn,EventArg
  41. ' Returns: True/False
  42. ' Global Variables: None
  43. ' Functions Called: GetOTSTableValues()
  44. '-------------------------------------------------------------------------
  45. Public Function OnInitPage(ByRef PageIn, ByRef EventArg)
  46. Call SA_TraceOut(SOURCE_FILE, "OnInitPage")
  47. Call GetOTSTableValues()
  48. OnInitPage = TRUE
  49. End Function
  50. '-------------------------------------------------------------------------
  51. ' Function: OnServePropertyPage()
  52. ' Description: Called when the page needs to be served.
  53. ' Input Variables: PageIn,EventArg
  54. ' Output Variables: PageIn,EventArg
  55. ' Returns: True/False
  56. ' Global Variables: None
  57. ' Functions Called: ServeCommonJavaScript()
  58. ' ServePageUI()
  59. '-------------------------------------------------------------------------
  60. Public Function OnServePropertyPage(ByRef PageIn, ByRef EventArg)
  61. Call SA_TraceOut(SOURCE_FILE, "OnServePropertyPage")
  62. ' Emit Functions required by Web Framework
  63. Call ServeCommonJavaScript()
  64. 'Emit UI for this page
  65. Call ServePageUI()
  66. OnServePropertyPage = True
  67. End Function
  68. '-------------------------------------------------------------------------
  69. ' Function: OnPostBackPage()
  70. ' Description: Called to signal that the page has been posted-back.
  71. ' Input Variables: PageIn,EventArg
  72. ' Output Variables: PageIn,EventArg
  73. ' Returns: True/False
  74. ' Global Variables: G_strShareNames - concatenated string of share names
  75. ' to be deleted
  76. ' G_ShareType - the type of share to be deleted
  77. '-------------------------------------------------------------------------
  78. Public Function OnPostBackPage(ByRef PageIn, ByRef EventArg)
  79. Call SA_TraceOut(SOURCE_FILE, "OnPostBackPage")
  80. 'Get share name from the hidden values of form
  81. G_strShareNames = Request.Form("hdnShareNames")
  82. 'Get share type from the hidden values of form
  83. G_ShareType = Request.Form("hdnShareType")
  84. G_strFolderPath=UnEscapeChars(Request.Form("hdnsharePath"))
  85. OnPostBackPage = TRUE
  86. End Function
  87. '-------------------------------------------------------------------------
  88. ' Function: OnSubmitPage()
  89. ' Description: Called when the page has been submitted for processing.
  90. ' Used to process the submit request.
  91. ' Input Variables: PageIn,EventArg
  92. ' Output Variables: PageIn,EventArg
  93. ' Returns: True/False
  94. ' Global Variables: G_ShareType
  95. ' G_strFolderPath
  96. ' Functions called: DeleteShare()
  97. '-------------------------------------------------------------------------
  98. Public Function OnSubmitPage(ByRef PageIn, ByRef EventArg)
  99. Call SA_TraceOut(SOURCE_FILE, "OnSubmitPage")
  100. 'Delete the share on submit
  101. OnSubmitPage= DeleteShare()
  102. End Function
  103. '-------------------------------------------------------------------------
  104. ' Function: OnClosePage()
  105. ' Description: Called when the page is about to be closed.
  106. ' Input Variables: PageIn,EventArg
  107. ' Output Variables: PageIn,EventArg
  108. ' Returns: True/False
  109. ' Global Variables: None
  110. '-------------------------------------------------------------------------
  111. Public Function OnClosePage(ByRef PageIn, ByRef EventArg)
  112. Call SA_TraceOut(SOURCE_FILE, "OnClosePage")
  113. OnClosePage = TRUE
  114. End Function
  115. '-------------------------------------------------------------------------
  116. 'Function name: DeleteShare
  117. 'Description: Serves in deleting the selected share
  118. 'Input Variables: None
  119. 'Output Variables: None
  120. 'Returns: True if share is deleted else False
  121. 'Global Variables: F_*,L_*
  122. ' CONST_WMI_IIS_NAMESPACE
  123. ' CONST_WMI_WIN32_NAMESPACE
  124. '-------------------------------------------------------------------------
  125. Function DeleteShare()
  126. Err.Clear
  127. On Error Resume Next
  128. Dim objDefaultConnection 'hold WMI WIN32Namespace Connection object
  129. Dim objIISConnection 'hold WMI IISNamespace Connection object
  130. Dim objRegistryConnection 'hold registry connection
  131. Dim strSuccessfulDelete 'Shares successfully delete
  132. Dim strUnSuccessfulDelete 'Shares unsuccessfully deleted
  133. Dim arrShareNames
  134. Dim arrShareTypes
  135. Dim arrTotalErrors
  136. Dim strErrorMessage
  137. Dim nCount
  138. Dim strShareTypesFailed
  139. Dim strShareTypesSuccessful
  140. Dim arrPathMessage
  141. Dim arrShareFailOrSuccess
  142. Dim strSuccessMessage
  143. Dim nUpperBound
  144. Dim arrShareFailed
  145. Dim arrShareSuccess
  146. Dim arrVarReplacementStrings(1)
  147. Const CONST_HTTP = "H"
  148. Const CONST_FTP = "F"
  149. Const CONST_CIFS = "W"
  150. Const CONST_NFS = "U"
  151. Const CONST_APPLETALK = "A"
  152. Const CONST_SUCCESS = "S"
  153. Const CONST_FAIL = "F"
  154. Const CONST_SEPARATE = "*"
  155. DeleteShare = FALSE 'Initialize it to false
  156. Call SA_TraceOut(SOURCE_FILE, "DeleteShare()")
  157. 'Getting connected to CIMV2 namespace
  158. Set objDefaultConnection =getWMIConnection(CONST_WMI_WIN32_NAMESPACE)
  159. 'Getting connected to Registry
  160. Set objRegistryConnection =RegConnection()
  161. 'Getting connected to MicrosoftIISv1 namespace
  162. Set objIISConnection =getWMIConnection(CONST_WMI_IIS_NAMESPACE)
  163. arrShareNames = split(G_strShareNames,chr(1))
  164. arrShareTypes = split(G_ShareType,chr(1))
  165. strErrorMessage = ""
  166. arrPathMessage=split(G_strFolderPath,chr(1))
  167. nUpperBound = ubound(arrShareNames) - 1
  168. Redim arrTotalErrors(nUpperBound)
  169. For nCount=0 to nUpperBound
  170. '
  171. ' Delete a share even its folder is not exist anymore
  172. If false Then 'isPathExisting(arrPathMessage(nCount)) then
  173. 'arrTotalErrors(nCount)=UnEscapeChars(arrShareNames(nCount))& " "
  174. Else
  175. 'If share type is "H" i.e HTTP share
  176. strShareTypesFailed = ""
  177. If Instr(arrShareTypes(nCount),CONST_HTTP)<> 0 then
  178. If not deleteShareHttp( objIISConnection ,UnEscapeChars(arrShareNames(nCount)) )then
  179. Call SA_TraceOut(SOURCE_FILE, "Unable to delete Http Share")
  180. strShareTypesFailed = strShareTypesFailed & CONST_HTTP & " "
  181. Else
  182. strShareTypesSuccessful = strShareTypesSuccessful & CONST_HTTP & " "
  183. End If
  184. End if
  185. 'If share type is "F" i.e FTP share
  186. If Instr(arrShareTypes(nCount),CONST_FTP)<> 0 then
  187. If not deleteShareftp( objIISConnection ,UnEscapeChars(arrShareNames(nCount)) ) then
  188. call SA_TraceOut(SOURCE_FILE, "Unable to delete FTP Share")
  189. strShareTypesFailed = strShareTypesFailed & CONST_FTP & " "
  190. Else
  191. strShareTypesSuccessful = strShareTypesSuccessful & CONST_FTP & " "
  192. End If
  193. End if
  194. 'If share type is "W" i.e Windows share
  195. If Instr(arrShareTypes(nCount),CONST_CIFS)<> 0 then
  196. If not deleteShareCIFS (objDefaultConnection ,UnEscapeChars(arrShareNames(nCount)) )then
  197. Call SA_TraceOut(SOURCE_FILE, "Unable to delete Windows Share")
  198. strShareTypesFailed = strShareTypesFailed & CONST_CIFS & " "
  199. Else
  200. strShareTypesSuccessful = strShareTypesSuccessful & CONST_CIFS & " "
  201. End If
  202. End if
  203. 'If share type is "U" i.e Unix share
  204. If Instr(arrShareTypes(nCount),CONST_NFS)<> 0 then
  205. If not deleteShareNFS (UnEscapeChars(arrShareNames(nCount)) )then
  206. Call SA_TraceOut(SOURCE_FILE, "Unable to delete Unix Share")
  207. strShareTypesFailed = strShareTypesFailed & CONST_NFS & " "
  208. Else
  209. strShareTypesSuccessful = strShareTypesSuccessful & CONST_NFS & " "
  210. End If
  211. End if
  212. 'If share type is "A" i.e Appletalk share
  213. If Instr(arrShareTypes(nCount),CONST_APPLETALK)<> 0 then
  214. If not deleteShareAppleTalk(UnEscapeChars(arrShareNames(nCount)))then
  215. Call SA_TraceOut(SOURCE_FILE, "Unable to delete Appletalk Share")
  216. strShareTypesFailed = strShareTypesFailed & CONST_APPLETALK & " "
  217. Else
  218. strShareTypesSuccessful = strShareTypesSuccessful & CONST_APPLETALK & " "
  219. End If
  220. End if
  221. If strShareTypesFailed <> "" Then
  222. arrTotalErrors(nCount) = CONST_FAIL & Chr(1) & arrShareNames(nCount)& "( "& strShareTypesFailed &") "
  223. End If
  224. If strShareTypesSuccessful <> "" Then
  225. arrTotalErrors(nCount) = arrTotalErrors(nCount) & CONST_SEPARATE & CONST_SUCCESS & Chr(1) & arrShareNames(nCount) & "( "& strShareTypesSuccessful &") "
  226. End If
  227. End If
  228. Next
  229. For nCount = 0 to ubound(arrTotalErrors)
  230. arrShareFailOrSuccess = Split(arrTotalErrors(nCount),CONST_SEPARATE)
  231. arrShareFailed = Split(arrShareFailOrSuccess(0),chr(1))
  232. arrShareSuccess = Split(arrShareFailOrSuccess(1),chr(1))
  233. If arrShareFailed(0) = CONST_FAIL Then
  234. strErrorMessage = strErrorMessage & arrShareFailed(1) & "<BR>"
  235. End If
  236. If arrShareSuccess(0) = CONST_SUCCESS Then
  237. strSuccessMessage = strSuccessMessage & arrShareSuccess(1) & "<BR>"
  238. End If
  239. Next
  240. If trim(strSuccessMessage) <> "" Then
  241. arrVarReplacementStrings(0) = strSuccessMessage
  242. strSuccessMessage = SA_GetLocString("foldermsg.dll","403A00CF",arrVarReplacementStrings)
  243. End If
  244. If trim(strErrorMessage) <> "" Then
  245. arrVarReplacementStrings(0) = strErrorMessage
  246. strErrorMessage = SA_GetLocString("foldermsg.dll","403A00D0",arrVarReplacementStrings)
  247. End If
  248. If trim(strErrorMessage) <> "" And trim(strSuccessMessage) <> "" Then
  249. Set objDefaultConnection = Nothing
  250. Set objRegistryConnection = Nothing
  251. Set objIISConnection = Nothing
  252. SA_ServeFailurePage strSuccessMessage & strErrorMessage
  253. Else
  254. If trim(strErrorMessage) <> "" And trim(strSuccessMessage) = "" Then
  255. Set objDefaultConnection = Nothing
  256. Set objRegistryConnection = Nothing
  257. Set objIISConnection = Nothing
  258. SA_ServeFailurePage strErrorMessage
  259. End If
  260. End If
  261. Set objDefaultConnection = Nothing
  262. Set objRegistryConnection = Nothing
  263. Set objIISConnection = Nothing
  264. DeleteShare = TRUE
  265. End function
  266. '-------------------------------------------------------------------------
  267. 'Subroutine name: GetOTSTableValues
  268. 'Description: Get the names of the folders selected
  269. 'Input Variables: None
  270. 'Output Variables: None
  271. 'Returns: None
  272. 'Global Variables:
  273. '-------------------------------------------------------------------------
  274. Sub GetOTSTableValues()
  275. Dim arrShares 'hold array of shares
  276. Dim nCount
  277. Dim itemCount
  278. Dim itemKey
  279. itemCount = OTS_GetTableSelectionCount("")
  280. For nCount = 1 to itemCount
  281. If ( OTS_GetTableSelection("", nCount, itemKey) ) Then
  282. arrShares = split(itemKey,chr(1))
  283. G_strShareNames = G_strShareNames & UnEscapeChars(arrShares(0)) & chr(1)
  284. G_strFolderPath=UnEscapeChars(G_strFolderPath) & arrShares(1)& chr(1)
  285. G_ShareType=G_ShareType & arrShares(2) & chr(1) 'get the share type
  286. End If
  287. Next
  288. End Sub
  289. '-------------------------------------------------------------------------
  290. 'Function: ServeCommonJavaScript
  291. 'Description: Serves in initializing the values,setting the form
  292. ' data and validating the form values
  293. 'Input Variables: None
  294. 'Output Variables: None
  295. 'Returns: None
  296. 'Global Variables: None
  297. '-------------------------------------------------------------------------
  298. Function ServeCommonJavaScript()
  299. %>
  300. <script language="JavaScript">
  301. // Init Function
  302. function Init()
  303. {
  304. document.frmTask.action = location.href;
  305. }
  306. // ValidatePage Function
  307. // Returns: True if the page is OK, false if error(s) exist.
  308. function ValidatePage()
  309. {
  310. return true;
  311. }
  312. // SetData Function
  313. // This function must be included or a javascript runtime error will occur.
  314. function SetData()
  315. {
  316. return true;
  317. }
  318. </script>
  319. <%
  320. End Function
  321. '-------------------------------------------------------------------------
  322. 'Function: ServePageUI
  323. 'Description: Serves User Interface for the page
  324. 'Input Variables: None
  325. 'Output Variables: None
  326. 'Returns: None
  327. 'Global Variables: F_*,G_*,L_*
  328. '-------------------------------------------------------------------------
  329. Function ServePageUI()
  330. Call SA_TraceOut(SOURCE_FILE, "ServePageUI")
  331. Dim arrShareNames
  332. Dim nCount
  333. Dim arrVarReplacementStrings(1)
  334. Const CONST_DECIMAL="."
  335. %>
  336. <table border="0" cellspacing="0" cellpadding="0" >
  337. <%
  338. G_strShareNames = Replace(G_strShareNames,"\","")
  339. arrShareNames = split(G_strShareNames,chr(1))
  340. If ubound(arrShareNames) > 1 Then
  341. %>
  342. <tr>
  343. <td class="TasksBody">
  344. <%=L_DELETESHARECONFIRM_TEXT%><br><br>
  345. <%
  346. For nCount=0 to ubound(arrShareNames)
  347. %>
  348. <b> <%=UnEscapeChars(arrShareNames(nCount))%></b><br>
  349. <%
  350. Next
  351. %>
  352. <%=L_THESEFOLDERS_NOLONGER_TEXT%>
  353. </td>
  354. </tr>
  355. <tr>
  356. <td class="TasksBody">
  357. <%=L_AREYOUSUREDELETE_FOLDERS_TEXT%>
  358. </td>
  359. </tr>
  360. <%
  361. Else
  362. arrVarReplacementStrings(0) = arrShareNames(0)
  363. %>
  364. <tr>
  365. <td class="TasksBody">
  366. <%=SA_GetLocString("foldermsg.dll","403A00CB",arrVarReplacementStrings)%>
  367. </td>
  368. </tr>
  369. <tr>
  370. <td class="TasksBody">
  371. <%=L_AREYOUSUREDELETE_FOLDER_TEXT%>
  372. </td>
  373. </tr>
  374. <%
  375. End If
  376. %>
  377. </table>
  378. <input type="hidden" name="hdnShareNames" value="<%=server.HTMLEncode(G_strShareNames) %>">
  379. <input type="hidden" name="hdnShareType" value="<%=server.HTMLEncode(G_ShareType) %>">
  380. <input type="hidden" name="hdnsharePath" value="<%=server.HTMLEncode(G_strFolderPath) %>">
  381. <%
  382. End Function
  383. %>