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.

524 lines
19 KiB

  1. <%@ Language=VBScript %>
  2. <% Option Explicit %>
  3. <%
  4. '-------------------------------------------------------------------------
  5. ' quota_delete.asp: delete a selected quota entry
  6. '
  7. ' Copyright (c) Microsoft Corporation. All rights reserved.
  8. '
  9. ' Date Description
  10. ' 17-Jan-01 Creation date
  11. ' 15-Mar-01 Ported to 2.0
  12. '-------------------------------------------------------------------------
  13. %>
  14. <!-- #include virtual = "/admin/inc_framework.asp" -->
  15. <!-- #include file = "loc_quotas.asp" -->
  16. <!-- #include file = "inc_quotas.asp" -->
  17. <%
  18. '-------------------------------------------------------------------------
  19. ' Global Variables
  20. '-------------------------------------------------------------------------
  21. Dim SOURCE_FILE ' the source file name used while Tracing
  22. SOURCE_FILE = SA_GetScriptFileName()
  23. Const QUOTAUSER_TOKEN = "*" ' localization not required
  24. Const QUOTAUSER_DELETED = 0 ' return value of function if success
  25. Const QUOTAUSER_NOT_DELETED = 1 ' return value if quota entry not deleted
  26. Const QUOTAUSER_NOT_FOUND = 2 ' return value if quota entry not found
  27. Dim L_TOTAL_ERROR_ERRORMESSAGE ' this error message is formed dynamically
  28. Dim L_MULTIPLE_DELETE_TEXT
  29. Dim L_SINGLE_DELETE_TEXT
  30. '-------------------------------------------------------------------------
  31. ' Global Form Variables
  32. '-------------------------------------------------------------------------
  33. Dim F_strVolName ' volume the quota is on
  34. Dim F_strUserList ' the concatenated list of users
  35. '======================================================
  36. ' Entry point
  37. '======================================================
  38. Dim page
  39. Dim aPageTitle(2)
  40. aPageTitle(0) = L_BROWSERCAPTION_QUOTADELETE_TEXT
  41. aPageTitle(1) = L_PAGETITLE_QUOTADELETE_TEXT
  42. '
  43. ' Create a Property Page
  44. Call SA_CreatePage( aPageTitle, "", PT_PROPERTY, page )
  45. '
  46. ' Serve the page
  47. Call SA_ShowPage( page )
  48. '======================================================
  49. ' Web Framework Event Handlers
  50. '======================================================
  51. '---------------------------------------------------------------------
  52. ' Function name: OnInitPage
  53. ' Description: Called to signal first time processing for this page
  54. ' Input Variables: Out: PageIn
  55. ' Out: EventArg
  56. ' Output Variables: None
  57. ' Return Values: TRUE to indicate initialization was successful.
  58. ' FALSE to indicate errors. Returning FALSE will
  59. ' cause the page to be abandoned.
  60. ' Global Variables: Out: F_strVolName - volume on which quota user is set
  61. '
  62. ' Used to do first time initialization tasks.
  63. '---------------------------------------------------------------------
  64. Public Function OnInitPage(ByRef PageIn, ByRef EventArg)
  65. Call SA_TraceOut(SOURCE_FILE, "OnInitPage")
  66. Dim iCount ' to get the list of users selected
  67. Dim sValue ' to get the OTS selected values
  68. Dim i ' to loop
  69. ' initialize the list to empty
  70. F_strUserList = ""
  71. ' get the count of users selected
  72. iCount = OTS_GetTableSelectionCount("QuotaUsers")
  73. For i = 1 to iCount
  74. ' get the list of users selected
  75. Call OTS_GetTableSelection("QuotaUsers", i, sValue )
  76. ' concatenate with the token
  77. F_strUserList = F_strUserList & sValue & QUOTAUSER_TOKEN
  78. Next
  79. ' If list empty, form is submitted, get from hidden variable
  80. If F_strUserList = "" Then
  81. F_strUserList = Request.Form("userList")
  82. End If
  83. F_strUserList = UnescapeChars(F_strUserList)
  84. sValue = ""
  85. ' get the volume name from the parent OTS
  86. Call OTS_GetTableSelection("", 1, sValue )
  87. F_strVolName = sValue
  88. ' check if user and volume info is obtained
  89. If ((Len(Trim(F_strUserList)) = 0) OR (Len(Trim(F_strVolName)) = 0)) Then
  90. ' both user name and volume information are required to proceed
  91. OnInitPage = FALSE
  92. Exit Function
  93. End If
  94. OnInitPage = TRUE
  95. End Function
  96. '---------------------------------------------------------------------
  97. ' Function name: OnServePropertyPage
  98. ' Description: Called when the page needs to be served
  99. ' Input Variables: Out: PageIn
  100. ' Out: EventArg
  101. ' Output Variables: None
  102. ' Return Values: TRUE to indicate no problems occured. FALSE to
  103. ' indicate errors. Returning FALSE will cause the
  104. ' page to be abandoned.
  105. ' Global Variables: In: F_strVolname - the volume user quota is on
  106. ' In: L_(*) - localized display strings
  107. '
  108. ' The UI is served here.
  109. '---------------------------------------------------------------------
  110. Public Function OnServePropertyPage(ByRef PageIn, ByRef EventArg)
  111. Call SA_TraceOut(SOURCE_FILE, "OnServePropertyPage")
  112. '
  113. ' Emit Javascript functions required by Web Framework
  114. Call ServeCommonJavaScript()
  115. Dim arrUsersToDelete ' array of users to be deleted
  116. Dim i ' to loop
  117. Dim strVolumeLabel ' volume label to be displayed in the message
  118. ' split the concatenated list into an array
  119. arrUsersToDelete = Split(F_strUserList,QUOTAUSER_TOKEN)
  120. %>
  121. <table border="0" cellspacing="0" cellpadding="0">
  122. <tr>
  123. <td class="TasksBody">
  124. <%
  125. ' get the volume label
  126. strVolumeLabel = getVolumeLabelForDrive(F_strVolname)
  127. ' append the volume name to the message
  128. Dim arrVarReplacementStringsMultiple(2)
  129. arrVarReplacementStringsMultiple(0) = strVolumeLabel
  130. arrVarReplacementStringsMultiple(1) = F_strVolname
  131. L_MULTIPLE_DELETE_TEXT = SA_GetLocString("diskmsg.dll", "403E0080", arrVarReplacementStringsMultiple)
  132. ' append the user name and volume name to the message
  133. Dim arrVarReplacementStringsSingle(3)
  134. arrVarReplacementStringsSingle(0) = arrUsersToDelete(0)
  135. arrVarReplacementStringsSingle(1) = strVolumeLabel
  136. arrVarReplacementStringsSingle(2) = F_strVolname
  137. L_SINGLE_DELETE_TEXT = SA_GetLocString("diskmsg.dll", "403E0081", arrVarReplacementStringsSingle)
  138. If ((isArray(arrUsersToDelete)) AND (UBound(arrUsersToDelete)-1) >= 1) Then
  139. ' multiple user entries are specified
  140. Response.Write L_MULTIPLE_DELETE_TEXT
  141. Else
  142. ' single user deletion specified
  143. Response.Write L_SINGLE_DELETE_TEXT
  144. End If
  145. %>
  146. <br>
  147. </td>
  148. </tr>
  149. <tr>
  150. <td class="TasksBody">
  151. <%
  152. If ((isArray(arrUsersToDelete)) AND (UBound(arrUsersToDelete)-1) >= 1) Then
  153. ' multiple users specified
  154. For i = 0 To (UBound(arrUsersToDelete)-1)
  155. Response.Write arrUsersToDelete(i) & "<br>"
  156. Next
  157. Response.Write "<br>"
  158. Response.Write L_MULTIPLE_DELETECONFIRM_TEXT
  159. Else
  160. ' single user entry specified
  161. Response.Write "<br>"
  162. Response.Write L_SINGLE_DELETECONFIRM_TEXT
  163. End If
  164. %>
  165. </td>
  166. </tr>
  167. </table>
  168. <input type="hidden" name="volume" value="<%=Server.HTMLEncode(F_strVolname)%>">
  169. <input type="hidden" name="userList" value="<%=Server.HTMLEncode(F_strUserList)%>">
  170. <%
  171. OnServePropertyPage = TRUE
  172. End Function
  173. '---------------------------------------------------------------------
  174. ' Function name: OnPostBackPage
  175. ' Description: Called to signal that the page has been posted-back
  176. ' Input Variables: Out: PageIn
  177. ' Out: EventArg
  178. ' Output Variables: None
  179. ' Return Values: TRUE to indicate success. FALSE to indicate errors.
  180. ' Returning FALSE will cause the page to be abandoned.
  181. ' Global Variables: Out: F_strVolName - the volume user quota is on
  182. ' Collect the form data vales.
  183. '---------------------------------------------------------------------
  184. Public Function OnPostBackPage(ByRef PageIn, ByRef EventArg)
  185. Call SA_TraceOut(SOURCE_FILE, "OnPostBackPage")
  186. F_strVolName = Request.Form("volume")
  187. F_strUserList = Request.Form("userList")
  188. F_strUserList = UnescapeChars(F_strUserList)
  189. OnPostBackPage = TRUE
  190. End Function
  191. '---------------------------------------------------------------------
  192. ' Function name: OnSubmitPage
  193. ' Description: To process the submit request
  194. ' Input Variables: Out: PageIn
  195. ' Out: EventArg
  196. ' Output Variables: None
  197. ' Return Values: TRUE if the submit was successful, FALSE to indicate error(s).
  198. ' Returning FALSE will cause the page to be served again using
  199. ' a call to OnServePropertyPage.
  200. ' Returning FALSE will display error message.
  201. ' Global Variables: None
  202. ' Functions Called: deleteAllGivenUserQuota
  203. '
  204. ' Delete quota entry for the given user
  205. '---------------------------------------------------------------------
  206. Public Function OnSubmitPage(ByRef PageIn, ByRef EventArg)
  207. Call SA_TraceOut(SOURCE_FILE, "OnSubmitPage")
  208. ' call function to delete the user quota
  209. OnSubmitPage = deleteAllGivenUserQuota() ' True/False
  210. End Function
  211. '---------------------------------------------------------------------
  212. ' Function name: OnClosePage
  213. ' Description: to perform clean-up processing
  214. ' Input Variables: Out: PageIn
  215. ' Out: EventArg
  216. ' Output Variables: None
  217. ' Return Values: TRUE to allow close, FALSE to prevent close. Returning FALSE
  218. ' will result in a call to OnServePropertyPage.
  219. ' Global Variables: None
  220. '
  221. ' Called when the page is about to be closed.
  222. '---------------------------------------------------------------------
  223. Public Function OnClosePage(ByRef PageIn, ByRef EventArg)
  224. Call SA_TraceOut(SOURCE_FILE, "OnClosePage")
  225. ' no processing required here. Return True
  226. OnClosePage = TRUE
  227. End Function
  228. '======================================================
  229. ' Private Functions
  230. '======================================================
  231. '---------------------------------------------------------------------
  232. ' Function name: ServeCommonJavaScript
  233. ' Description: Serve JavaScript that is required for this page type
  234. ' Input Variables: None
  235. ' Output Variables: None
  236. ' Return Values: None
  237. ' Global Variables: L_(*) - Error messages displayed on the client side
  238. '
  239. ' This contains the Client-Side script required for the page.
  240. '---------------------------------------------------------------------
  241. Function ServeCommonJavaScript()
  242. %>
  243. <script language="JavaScript" src="<%=m_VirtualRoot%>inc_global.js">
  244. </script>
  245. <script language="JavaScript">
  246. //
  247. // Microsoft Server Appliance Web Framework Support Functions
  248. // Copyright (c) Microsoft Corporation. All rights reserved.
  249. //
  250. // to perform first time initialization in the page.Framework function.
  251. function Init()
  252. {
  253. // no initializations required in this page
  254. }
  255. // to validate user input. Framework function.
  256. // Returns: True if the page is OK, false if error(s) exist.
  257. // Returning false will cause the submit to abort.
  258. function ValidatePage()
  259. {
  260. return true;
  261. }
  262. // to update the hidden variables, Framework function.
  263. function SetData()
  264. {
  265. // no hidden variables to update
  266. }
  267. </script>
  268. <%
  269. End Function
  270. '---------------------------------------------------------------------
  271. ' Function name: deleteAllGivenUserQuota
  272. ' Description: to delete the given quota entries
  273. ' Input Variables: None
  274. ' Output Variables: None
  275. ' Returns: True - if quota entries are deleted sucessfully
  276. ' False - if error(s) occur in deletion
  277. ' Global Variables: In: F_strVolName - volume on which quota is set
  278. ' In: F_strUserList - the concatenated list of user list
  279. ' In: L_(*) - localization content
  280. '
  281. ' Failure page is displayed if ANY of the entries could not be deleted
  282. '---------------------------------------------------------------------
  283. Function deleteAllGivenUserQuota()
  284. On Error Resume Next
  285. Err.Clear
  286. Dim objQuotas ' the Quotas object
  287. Dim arrUsersToDelete ' the list of users to be deleted
  288. Dim strListSuccess ' the concatenated list of Successful deletions
  289. Dim strListNotFound ' the concatenated list of not found users
  290. Dim strListFailure ' the concatenated list of Failed Deletions
  291. Dim blnSuccess ' the Final return value for this function
  292. Dim blnDeleteUser ' boolean result for each user quota deletion
  293. Dim i ' to loop
  294. ' create the quota object and initialize for the required Volume
  295. Set objQuotas = CreateObject("Microsoft.DiskQuota.1")
  296. objQuotas.Initialize F_strVolName & "\", 1
  297. objQuotas.UserNameResolution = 1 'wait for names
  298. If Err.number <> 0 Then
  299. ' cannot proceed. Display failure page.
  300. Call SA_ServeFailurePage(L_OBJECTNOTCREATED_ERRORMESSAGE)
  301. End If
  302. ' initialize the success and failure list
  303. strListSuccess = ""
  304. strListNotFound = ""
  305. strListFailure = ""
  306. blnSuccess = TRUE ' initialize the final return value to TRUE
  307. ' split the concatenated list of users
  308. arrUsersToDelete = Split(F_strUserList,QUOTAUSER_TOKEN)
  309. If isArray(arrUsersToDelete) Then
  310. ' loop for each user
  311. For i = 0 To (UBound(arrUsersToDelete)-1)
  312. 'If user is in Admin group, we won't call deleteQuotaEntry. It's
  313. 'an issue in Microsoft.DiskQuota.1 object method DeleteUser. If you
  314. 'try to delete administrators group by calling that method, it will
  315. 'set the quota warning limit to -2 bytes.
  316. if Not IsUserInAdministratorsGroup(arrUsersToDelete(i)) Then
  317. blnDeleteUser = deleteQuotaEntry(objQuotas,arrUsersToDelete(i))
  318. Else
  319. blnDeleteUser = QUOTAUSER_NOT_DELETED
  320. End If
  321. If (blnDeleteUser = QUOTAUSER_DELETED ) Then
  322. ' the user is deleted. Add to success list
  323. strListSuccess = strListSuccess & arrUsersToDelete(i) & QUOTAUSER_TOKEN
  324. Else
  325. ' make the value False, even if one deletion fails
  326. blnSuccess = FALSE
  327. If (blnDeleteUser = QUOTAUSER_NOT_FOUND ) Then
  328. ' the user could not be deleted. Add to Failure list
  329. strListNotFound = strListNotFound & arrUsersToDelete(i) & QUOTAUSER_TOKEN
  330. Else
  331. strListFailure = strListFailure & arrUsersToDelete(i) & QUOTAUSER_TOKEN
  332. End If
  333. End If
  334. Next ' user quota to be deleted
  335. Else
  336. ' not an array. unexpected error
  337. Call SA_ServeFailurePage(L_USERS_NOT_RETRIEVED_ERRORMESSAGE)
  338. End If
  339. Set objQuotas = Nothing
  340. ' check the Final return value
  341. If (blnSuccess = FALSE) Then
  342. ' deletion of atleast one user failed
  343. ' initizlize the value to empty
  344. L_TOTAL_ERROR_ERRORMESSAGE = ""
  345. If Len(Trim(strListSuccess)) > 0 Then
  346. ' some users are successfully deleted
  347. L_TOTAL_ERROR_ERRORMESSAGE = L_DELETED_USERQUOTAS_ERRORMESSAGE & "<br>"
  348. L_TOTAL_ERROR_ERRORMESSAGE = L_TOTAL_ERROR_ERRORMESSAGE & getAsListFromString(strListSuccess)
  349. End If
  350. If Len(Trim(strListNotFound)) > 0 Then
  351. ' form the list of users who could not be deleted, as user not found
  352. L_TOTAL_ERROR_ERRORMESSAGE = L_TOTAL_ERROR_ERRORMESSAGE & "<br>" & L_FAILED_DELETE_ERRORMESSAGE & "<br>"
  353. L_TOTAL_ERROR_ERRORMESSAGE = L_TOTAL_ERROR_ERRORMESSAGE & getAsListFromString(strListNotFound)
  354. End If
  355. If Len(Trim(strListFailure)) > 0 Then
  356. ' form the list of users who could not be deleted, as disk space needs to be freed
  357. L_TOTAL_ERROR_ERRORMESSAGE = L_TOTAL_ERROR_ERRORMESSAGE & "<br>" & L_FAILED_DELETE_FREEDISK_ERRORMESSAGE & "<br>"
  358. L_TOTAL_ERROR_ERRORMESSAGE = L_TOTAL_ERROR_ERRORMESSAGE & getAsListFromString(strListFailure)
  359. L_TOTAL_ERROR_ERRORMESSAGE = L_TOTAL_ERROR_ERRORMESSAGE & "<br>" & L_TAKE_OWNERSHIP_ERRORMESSAGE
  360. End If
  361. ' call the failure page to display the successful and failed deletions
  362. Call SA_ServeFailurePage(L_TOTAL_ERROR_ERRORMESSAGE)
  363. End If
  364. deleteAllGivenUserQuota = blnSuccess
  365. End Function
  366. '---------------------------------------------------------------------
  367. ' Function name: getAsListFromString
  368. ' Description: to get the users as list (appended with breaks)
  369. ' Input Variables: strConcatenatedList - the concatenated list of users
  370. ' Output Variables: None
  371. ' Returns: The list of users seperated by <br>
  372. ' Global Variables: None
  373. '
  374. ' Example: Input = UserA*UserB* Output= UserA & "<br>" & UserB & "<br>"
  375. '---------------------------------------------------------------------
  376. Function getAsListFromString(strConcatenatedList)
  377. Dim arrUserList ' the array of users obtained after "Split"
  378. Dim strListToReturn ' the return list of users
  379. Dim i ' to loop
  380. ' initialize the return value
  381. strListToReturn = ""
  382. ' Split the given concatenated list of users
  383. arrUserList = Split(strConcatenatedList,QUOTAUSER_TOKEN)
  384. If (isArray(arrUserList)) Then
  385. For i = 0 To (UBound(arrUserList)-1)
  386. ' form the list of users by appending the breaks
  387. strListToReturn = strListToReturn & arrUserList(i) & "<br>"
  388. Next
  389. Else
  390. ' split did not result in array. Return empty
  391. strListToReturn = ""
  392. End If
  393. getAsListFromString = strListToReturn
  394. End Function
  395. '---------------------------------------------------------------------
  396. ' Function name: deleteQuotaEntry
  397. ' Description: to delete the quota entry for the user
  398. ' Input Variables: objQuotas - the Quotas object
  399. ' strUser - the user to be deleted
  400. ' Output Variables: None
  401. ' Returns: QUOTAUSER_DELETED - if successfully deleted
  402. ' QUOTAUSER_NOT_DELETED - if deletion fails
  403. ' QUOTAUSER_NOT_FOUND - if user is not found
  404. ' Global Variables: None
  405. '
  406. ' This function is called for each user specified to be deleted
  407. '---------------------------------------------------------------------
  408. Function deleteQuotaEntry(objQuotas, strUser)
  409. On Error Resume Next
  410. Err.Clear
  411. Dim objUser ' the user to be deleted
  412. Dim blnUserFound ' boolean to check if user is existing
  413. ' check if quota entry for the user is present
  414. blnUserFound = False
  415. For Each objUser In objQuotas
  416. If LCase(Trim(strUser)) = LCase(Trim(objUser.LogonName)) Then
  417. ' user is found
  418. blnUserFound = True
  419. End If
  420. Next
  421. ' return False if user is NOT found
  422. If NOT blnUserFound Then
  423. deleteQuotaEntry = QUOTAUSER_NOT_FOUND
  424. ' set the locally declared objects to Nothing
  425. Set objUser = Nothing
  426. ' exit the function
  427. Exit Function
  428. End If
  429. ' find the user to be deleted
  430. Set objUser = objQuotas.FindUser( strUser )
  431. ' delete the user
  432. objQuotas.DeleteUser( objUser )
  433. If Err.Number <> 0 Then
  434. ' delete failed
  435. deleteQuotaEntry = QUOTAUSER_NOT_DELETED
  436. Set objUser = Nothing
  437. Err.Clear ' stop further error propagation
  438. Exit Function
  439. End IF
  440. ' return true
  441. deleteQuotaEntry = QUOTAUSER_DELETED
  442. ' set the locally declared objects to Nothing
  443. Set objUser = Nothing
  444. End Function
  445. %>