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.

605 lines
21 KiB

  1. <%
  2. '---------------------------------------------------------------------
  3. ' inc_quotas.asp: Common functions used in Quota related Pages
  4. '
  5. ' Copyright (c) Microsoft Corporation. All rights reserved.
  6. '
  7. ' Date Description
  8. ' 15-Mar-01 Creation date
  9. '---------------------------------------------------------------------
  10. '---------------------------------------------------------------------
  11. ' Global Constants
  12. '---------------------------------------------------------------------
  13. ' Do not limit the disk usage. (For "No Limit" the value = -1)
  14. Const CONST_NO_LIMIT = -1
  15. ' the first radio selected in the gui ("Do no limit disk usage")
  16. Const CONST_RADIO_DONOT_LIMIT_DISKUSAGE = 1
  17. DIM L_KB_TEXT
  18. DIM L_MB_TEXT
  19. DIM L_GB_TEXT
  20. DIM L_TB_TEXT
  21. DIM L_PB_TEXT
  22. DIM L_EB_TEXT
  23. DIM L_BYTES_TEXT
  24. L_KB_TEXT = GetLocString("diskmsg.dll", "402003E8", "")
  25. L_MB_TEXT = GetLocString("diskmsg.dll", "402003E9", "")
  26. L_GB_TEXT = GetLocString("diskmsg.dll", "402003EA", "")
  27. L_TB_TEXT = GetLocString("diskmsg.dll", "402003EB", "")
  28. L_PB_TEXT = GetLocString("diskmsg.dll", "402003EC", "")
  29. L_EB_TEXT = GetLocString("diskmsg.dll", "402003ED", "")
  30. L_BYTES_TEXT = GetLocString("diskmsg.dll", "402003EE", "")
  31. '---------------------------------------------------------------------
  32. ' Function name: setUnits
  33. ' Description: to display the units as DropdownListBox values
  34. ' Input Variables: strGivenUnits - units to select in the DropdownListBox
  35. ' Output Variables: None
  36. ' Returns: None
  37. ' Global Variables: None
  38. ' Side Effects: Outputs OPTION HTML code to client
  39. '
  40. ' The list of units are displayed as DropdownListBox values with the
  41. ' given units as the selected value
  42. '---------------------------------------------------------------------
  43. Function setUnits(strGivenUnits)
  44. Dim arrUnits ' the array of units to be displayed
  45. Dim i ' to loop
  46. Dim strSelectedText ' to assign if the Units is Selected
  47. ' Only KB,MB,GB,TB,PB,EB Units needs to be displayed
  48. arrUnits = Array(L_KB_TEXT, L_MB_TEXT, L_GB_TEXT, L_TB_TEXT, L_PB_TEXT, L_EB_TEXT)
  49. Dim iUnitValue
  50. iUnitValue = 1024
  51. For i = 0 to UBound(arrUnits)
  52. If UCase(strGivenUnits) = UCase(arrUnits(i)) Then
  53. ' if the given units match, select it
  54. strSelectedText = "SELECTED" ' localization not required
  55. Else
  56. strSelectedText = ""
  57. End If
  58. ' output the OPTION HTML
  59. Response.Write "<OPTION VALUE=" & (CStr(arrUnits(i))) & " " & strSelectedText & ">" & arrUnits(i) &"</OPTION>"
  60. iUnitValue = iUnitValue * 1024
  61. Next
  62. End Function
  63. '---------------------------------------------------------------------
  64. ' Function name: ChangeToText
  65. ' Description: to convert value of limit in Bytes to String
  66. ' Input Variables: Bytes - the size in Bytes
  67. ' Output Variables: None
  68. ' Returns: String equivalent, of the limit value in bytes
  69. ' Global Variables: None
  70. '---------------------------------------------------------------------
  71. Function ChangeToText(Bytes)
  72. 'Example: Input = 1024
  73. ' Output = 1 KB
  74. Dim Units ' the array of units
  75. Dim i ' to loop
  76. ' initialize the array with possible values of units
  77. Units = Array(L_BYTES_TEXT, L_KB_TEXT, L_MB_TEXT, L_GB_TEXT, L_TB_TEXT, L_PB_TEXT, L_EB_TEXT)
  78. For i = 0 To UBound(Units)
  79. If Bytes < (2 ^ ( (i+1) * 10 )) Then
  80. ChangeToText = Int((Bytes /( 2^(i*10))) * 100) / 100 & " " & Units(i)
  81. ' The Int(X * 100) /100 above is to take the two decimal
  82. ' places only (if any) without rounding any value
  83. Exit For
  84. End If
  85. Next
  86. End Function
  87. '---------------------------------------------------------------------
  88. ' Function name: ChangeToFloat
  89. ' Description: to convert size in string to Bytes
  90. ' Input Variables: Bytes - value of limit
  91. ' userUnits - units in which limit is specified
  92. ' Output Variables: None
  93. ' Returns: limit value in bytes
  94. ' Global Variables: None
  95. '---------------------------------------------------------------------
  96. Function ChangeToFloat(Bytes,userUnits)
  97. 'Example: Input = 1, KB
  98. ' Output = 1024
  99. Dim Units ' the array of units
  100. Dim i ' to loop
  101. ' initialize the array with possible values of Units
  102. Units = Array(L_KB_TEXT, L_MB_TEXT, L_GB_TEXT, L_TB_TEXT, L_PB_TEXT, L_EB_TEXT)
  103. For i = 0 to UBound(Units)
  104. If UCase(Units(i)) = UCase(userUnits) Then
  105. ' if units match, convert to byte equivalent
  106. ChangeToFloat = CDbl((Bytes *( 2^((i+1)*10))))
  107. Exit For
  108. End If
  109. Next
  110. End Function
  111. '---------------------------------------------------------------------
  112. ' Function name: getThresholdSizeForDefault
  113. ' Description: to get default Warning Limit for the quota object
  114. ' Input Variables: objQuotas - the quota object
  115. ' Output Variables: None
  116. ' Returns: Default thresholdSize for the quota
  117. ' Global Variables: None
  118. ' Functions Called: getLimitFromText
  119. '
  120. ' The quota object is initialized for the required volume before being
  121. ' passed here.This returns the default WarningLimit for the volume.
  122. '---------------------------------------------------------------------
  123. Function getThresholdSizeForDefault(objQuotas)
  124. On Error Resume Next
  125. Err.Clear
  126. Dim nThresholdSize ' the thresholdSize to return
  127. Dim strTemp
  128. If objQuotas.DefaultQuotaThreshold = CONST_NO_LIMIT Then
  129. ' No Warning Limit is set. The text contains "No Limit"
  130. nThresholdSize = L_NOLIMIT_TEXT
  131. Else
  132. ' some limit is set(say, 1 KB). Get the size part from this(say, 1)
  133. ' Following did not localize
  134. 'nThresholdSize = getLimitFromText(objQuotas.DefaultQuotaThresholdText)
  135. ' first convert bytes to text.
  136. strTemp = ChangeToText(objQuotas.DefaultQuotaThreshold)
  137. ' get the size (number) portion
  138. nThresholdSize = getLimitFromText(strTemp)
  139. End If
  140. ' return the Warning Limit
  141. getThresholdSizeForDefault = nThresholdSize
  142. End Function
  143. '---------------------------------------------------------------------
  144. ' Function name: getThresholdSizeUnitsForDefault
  145. ' Description: to get default WarningLimit Units for the quota object
  146. ' Input Variables: objQuotas - the quota object
  147. ' Output Variables: None
  148. ' Returns: Default thresholdSize Units for the quota
  149. ' Global Variables: None
  150. ' Functions Called: getUnitsFromText
  151. '
  152. ' The quota object is initialized for the required volume before being
  153. ' passed here.This returns the default WarningLimit Units for the volume.
  154. '---------------------------------------------------------------------
  155. Function getThresholdSizeUnitsForDefault(objQuotas)
  156. On Error Resume Next
  157. Err.Clear
  158. Dim strThresholdUnits ' the thresholdSize Units to return
  159. Dim strTemp
  160. If objQuotas.DefaultQuotaThreshold = CONST_NO_LIMIT Then
  161. ' No warning limit is set. Return KB for default display
  162. strThresholdUnits = L_KB_TEXT
  163. Else
  164. ' some limit is set(say, 1 KB). Get the units part from this(say, KB)
  165. ' Following did not localize
  166. 'strThresholdUnits = getUnitsFromText(objQuotas.DefaultQuotaThresholdText)
  167. ' first convert bytes to text.
  168. strTemp = ChangeToText(objQuotas.DefaultQuotaThreshold)
  169. ' get the units portion
  170. strThresholdUnits = getUnitsFromText(strTemp)
  171. End If
  172. ' return the WarningLimit units
  173. getThresholdSizeUnitsForDefault = strThresholdUnits
  174. End Function
  175. '---------------------------------------------------------------------
  176. ' Function name: getLimitSizeForDefault
  177. ' Description: to get default Disk Limit for the quota object
  178. ' Input Variables: objQuotas - the quota object
  179. ' Output Variables: None
  180. ' Returns: Default Disk Limit for the quota
  181. ' Global Variables: None
  182. ' Functions Called: getLimitFromText, ChangeToText
  183. '
  184. ' The quota object is initialized for the required volume before being
  185. ' passed here.This returns the default QuotaLimit for the volume.
  186. '---------------------------------------------------------------------
  187. Function getLimitSizeForDefault(objQuotas)
  188. On Error Resume Next
  189. Err.Clear
  190. Dim strLimitSize ' the disk limit to return
  191. Dim strTemp ' for temporary storage
  192. If objQuotas.DefaultQuotaLimit = CONST_NO_LIMIT Then
  193. ' No Disk Limit is set. The text contains "No Limit"
  194. strLimitSize = L_NOLIMIT_TEXT
  195. Else
  196. ' some limit is set(say, 1 KB). Get the size part from this(say, 1)
  197. ' first convert bytes to text.
  198. strTemp = ChangeToText(objQuotas.DefaultQuotaLimit)
  199. ' get the numeric value of the size
  200. strLimitSize = getLimitFromText(strTemp)
  201. End If
  202. ' return the limit size
  203. getLimitSizeForDefault = strLimitSize
  204. End Function
  205. '---------------------------------------------------------------------
  206. ' Function name: getLimitUnitsForDefault
  207. ' Description: to get default QuotaLimit Units for the quota object
  208. ' Input Variables: objQuotas - the quota object
  209. ' Output Variables: None
  210. ' Returns: Default QuotaLimit Units for the quota
  211. ' Global Variables: None
  212. ' Functions Called: getUnitsFromText, ChangeToText
  213. '
  214. ' The quota object is initialized for the required volume before being
  215. ' passed here.This returns the default QuotaLimit Units for the volume.
  216. '---------------------------------------------------------------------
  217. Function getLimitUnitsForDefault(objQuotas)
  218. On Error Resume Next
  219. Err.Clear
  220. Dim strLimitUnits ' the QuotaLimit Units to return
  221. Dim strTemp
  222. If objQuotas.DefaultQuotaLimit = CONST_NO_LIMIT Then
  223. ' No Disk Limit is set. Return KB for default display
  224. strLimitUnits = L_KB_TEXT
  225. Else
  226. ' some limit is set(say, 1 KB). Get the units part from this(say, KB)
  227. strTemp = ChangeToText(objQuotas.DefaultQuotaLimit)
  228. strLimitUnits = getUnitsFromText(strTemp)
  229. End If
  230. ' return the units
  231. getLimitUnitsForDefault = strLimitUnits
  232. End Function
  233. '---------------------------------------------------------------------
  234. ' Function name: getQuotaLimitRadioForDefault
  235. ' Description: to get default QuotaLimit settings
  236. ' Input Variables: objQuotas - the quota object
  237. ' Output Variables: None
  238. ' Returns: 1 - if disk limit is NOT set
  239. ' 2 - if some limit is set for disk usage
  240. ' Global Variables: None
  241. '
  242. ' The quota object is initialized for the required volume before being
  243. ' passed here. The return value corresponds to radio button in the gui
  244. '---------------------------------------------------------------------
  245. Function getQuotaLimitRadioForDefault(objQuotas)
  246. On Error Resume Next
  247. Err.Clear
  248. Dim nRadioToCheck ' the radio button to be CHECKED
  249. If ((objQuotas.DefaultQuotaThreshold = CONST_NO_LIMIT) AND (objQuotas.DefaultQuotaLimit = CONST_NO_LIMIT)) Then
  250. ' DiskLimit and WarningLimit is NOT set. Select the first radio
  251. nRadioToCheck = 1
  252. Else
  253. ' some limit is set. Select the second radio
  254. nRadioToCheck = 2
  255. End If
  256. ' return the selected radio value
  257. getQuotaLimitRadioForDefault = nRadioToCheck
  258. End Function
  259. '---------------------------------------------------------------------
  260. ' Function name: setUserQuotaLimit
  261. ' Description: to set the QuotaLimit settings for the user
  262. ' Input Variables: objQuotaUser - the quota object
  263. ' nDiskLimit - the limit value to be set
  264. ' strUnits - the units value for the limit
  265. ' Output Variables: None
  266. ' Returns: True if set , else False
  267. ' Global Variables: None
  268. ' Functions Called: ChangeToFloat
  269. '---------------------------------------------------------------------
  270. Function setUserQuotaLimit(ByRef objQuotaUser, nDiskLimit, strUnits)
  271. On Error Resume Next
  272. Err.Clear
  273. Dim nDiskLimitToSet ' the limit to be set ( calculated in bytes)
  274. If CDbl(nDiskLimit) <> CDbl(CONST_NO_LIMIT) Then
  275. 'Added 0.001 round the value of disk Limit
  276. nDiskLimitToSet = ChangeToFloat(nDiskLimit + 0.001, strUnits)
  277. If nDiskLimitToSet < 1024 Then
  278. nDiskLimitToSet = 1024 ' must be minimum of 1 KB
  279. End if
  280. Else
  281. nDiskLimitToSet = nDiskLimit
  282. End If
  283. ' set the quota limit for the user quota (value is set in Bytes)
  284. objQuotaUser.QuotaLimit = nDiskLimitToSet
  285. If Err.number <> 0 Then
  286. setUserQuotaLimit = FALSE
  287. Else
  288. setUserQuotaLimit = TRUE
  289. End If
  290. End Function
  291. '---------------------------------------------------------------------
  292. ' Function name: setUserThreshold
  293. ' Description: to set the WarningLimit settings for the userQuota
  294. ' Input Variables: objQuotaUser - the quota object
  295. ' nThresholdLimit - the WarningLimit value to be set
  296. ' strUnits - the units value for the WarningLimit
  297. ' Output Variables: None
  298. ' Returns: True if set , else False
  299. ' Global Variables: None
  300. ' Functions Called: ChangeToFloat
  301. '---------------------------------------------------------------------
  302. Function setUserThreshold(ByRef objQuotaUser, nThresholdLimit, strUnits)
  303. On Error Resume Next
  304. Err.Clear
  305. Dim nThresholdLimitToSet ' the warning limit to set
  306. If CDbl(nThresholdLimit) <> CDbl(CONST_NO_LIMIT) Then
  307. 'Added 0.001 round the value of Warning Limit
  308. nThresholdLimitToSet = ChangeToFloat( nThresholdLimit + 0.001, strUnits )
  309. If nThresholdLimitToSet < 1024 Then
  310. nThresholdLimitToSet = 1024 ' must be minimum of 1 KB
  311. End if
  312. Else
  313. nThresholdLimitToSet = nThresholdLimit
  314. End If
  315. ' set the warning limit to the user Quota (value is set in Bytes)
  316. objQuotaUser.QuotaThreshold = nThresholdLimitToSet
  317. If Err.number <> 0 Then
  318. setUserThreshold = FALSE
  319. Else
  320. setUserThreshold = TRUE
  321. End If
  322. End Function
  323. '---------------------------------------------------------------------
  324. ' Function name: getLimitFromText
  325. ' Description: to get limit size from Text String
  326. ' Input Variables: strValue - the size in string (say, 1 KB)
  327. ' Output Variables: None
  328. ' Returns: The limit size
  329. ' Global Variables: None
  330. ' Functions Called: isValidUnit
  331. '---------------------------------------------------------------------
  332. Function getLimitFromText(strValue)
  333. ' Example: Input: 1 KB
  334. ' Output: 1
  335. Call SA_TraceOut(SA_GetScriptFileName(), "Entering getLimitFromText("+strValue+")")
  336. Dim arrLimit ' to store split values of the input string
  337. Dim nLimit ' the limit value ( to be returned )
  338. Dim strUnits ' the limit units
  339. ' split the input string into two with Space as delimiter
  340. arrLimit = Split(Trim(strValue)," ",2)
  341. nLimit = CDbl(arrLimit(0)) ' the first element is Limit Size
  342. strUnits = CStr(arrLimit(1)) ' the second element is Limit Units
  343. ' verify if the Units are valid (must not be Bytes)
  344. If isValidUnit(strUnits) Then
  345. If Trim(UCase(strUnits)) = L_KB_TEXT AND nLimit < 1 Then
  346. ' limit value is in Bytes. Minimum display units is KB.
  347. ' Hence, return 1
  348. nLimit = 1
  349. End If
  350. Else
  351. ' Units is in Bytes, Return 1
  352. nLimit = 1
  353. End If
  354. ' return the limit value
  355. getLimitFromText = nLimit
  356. End Function
  357. '---------------------------------------------------------------------
  358. ' Function name: getUnitsFromText
  359. ' Description: to get limit size Units from Text String
  360. ' Input Variables: strValue - the size in string (say, 1 KB)
  361. ' Output Variables: None
  362. ' Returns: The limit size Units
  363. ' Global Variables: None
  364. ' Functions Called: isValidUnit
  365. '---------------------------------------------------------------------
  366. Function getUnitsFromText(strValue)
  367. ' Example: Input: 1 KB
  368. ' Output: KB
  369. Call SA_TraceOut(SA_GetScriptFileName(), "Entering getUnitsFromText("+strValue+")")
  370. Dim arrLimit ' to store split values of the input string
  371. Dim strUnits ' the limit units ( to be returned )
  372. ' split the input string into two with Space as delimiter
  373. arrLimit = Split(Trim(strValue)," ",2)
  374. strUnits = CStr(arrLimit(1)) ' the second element contains the units
  375. ' verify if the Units are valid (must not be Bytes)
  376. If NOT (isValidUnit(strUnits)) Then
  377. ' Units is NOT valid.(is in Bytes).Return KB
  378. strUnits = L_KB_TEXT
  379. End If
  380. getUnitsFromText = strUnits
  381. End Function
  382. '---------------------------------------------------------------------
  383. ' Function name: isValidUnit
  384. ' Description: to verify if the given units are valid (allowed units)
  385. ' Input Variables: strUnits - the units to validate (say, KB)
  386. ' Output Variables: None
  387. ' Returns: True - if the given units is permitted
  388. ' False - if the given units are NOT permitted
  389. ' Global Variables: None
  390. '---------------------------------------------------------------------
  391. Function isValidUnit(strUnits)
  392. Call SA_TraceOut(SA_GetScriptFileName(), "Entering isValidUnit("+strUnits+")")
  393. Dim Units ' the array of permitted units
  394. Dim i ' to loop
  395. ' initialize the array with set of permitted units
  396. Units = Array(L_KB_TEXT, L_MB_TEXT, L_GB_TEXT, L_TB_TEXT, L_PB_TEXT, L_EB_TEXT)
  397. ' initialize the return value to False
  398. isValidUnit = False
  399. ' loop to validate the given units
  400. For i = 0 to UBound(Units)
  401. If UCase(strUnits) = UCase(Units(i)) Then
  402. ' the given value is permitted, return True
  403. isValidUnit = True
  404. End If
  405. Next
  406. End Function
  407. '---------------------------------------------------------------------
  408. ' Function name: getVolumeLabelForDrive
  409. ' Description: to get the volume label for the given drive
  410. ' Input Variables: strDriveLetter - the drive letter
  411. ' Output Variables: None
  412. ' Returns: The volume label for the given drive.
  413. ' Returns "Local Disk", if label is empty
  414. ' Global Variables: L_(*) - localization variables
  415. '---------------------------------------------------------------------
  416. Function getVolumeLabelForDrive(strDriveLetter)
  417. On Error Resume Next
  418. Dim objWMIService ' the wmi service object
  419. Dim strWMIQuery ' the query to be executed
  420. Dim objDrive ' the drive object obtained as a result of the query
  421. Dim strVolumeLabel ' the value to be returned
  422. ' initialization
  423. strVolumeLabel = ""
  424. ' get the WMI connection
  425. Set objWMIService = GetWMIConnection(CONST_WMI_WIN32_NAMESPACE)
  426. ' prepare the query.
  427. strWMIQuery = "Win32_LogicalDisk.DeviceID=" & Chr(34) & strDriveLetter & Chr(34)
  428. ' execute the query
  429. Set objDrive = objWMIService.Get(strWMIQuery)
  430. If Err.number <> 0 Then
  431. Set objDrive = Nothing
  432. Set objWMIService = Nothing
  433. Call SA_ServeFailurePage(L_VALUES_NOT_RETRIEVED_ERRORMESSAGE)
  434. End If
  435. ' get the volume label
  436. strVolumeLabel = objDrive.VolumeName
  437. If Len(Trim(strVolumeLabel)) = 0 Then
  438. ' if volume label is empty, assign "Local Disk"
  439. strVolumeLabel = L_LOCAL_DISK_TEXT
  440. End If
  441. getVolumeLabelForDrive = strVolumeLabel
  442. ' free objects
  443. Set objDrive = Nothing
  444. Set objWMIService = Nothing
  445. End Function
  446. Public Function ConvertQuotaValueToUnits(ByVal lValue)
  447. Dim strTemp
  448. If ( NOT IsNumeric(lValue)) Then
  449. Call SA_TraceOut(SA_GetScriptFileName(), "ConvertQuotaValueToUnits recieved invalid numeric parameter: " + CStr(lValue))
  450. End If
  451. 'strTemp = ChangeToText(lValue)
  452. 'ConvertQuotaValueToUnits = getUnitsFromText(strTemp)
  453. ConvertQuotaValueToUnits = ChangeToText(lValue)
  454. End Function
  455. '-------------------------------------------------------------------------
  456. 'Function name: getAdministratorsGroupName
  457. 'Description: get Administrators Group Name
  458. 'Input Variables:
  459. 'Output Variables: None
  460. 'Returns: string of Admin Group Name
  461. '-------------------------------------------------------------------------
  462. function getAdministratorsGroupName()
  463. On Error Resume Next
  464. Err.Clear
  465. Dim objService
  466. Dim strWelKnownSid
  467. Dim objSid
  468. Set objService = GetWMIConnection(CONST_WMI_WIN32_NAMESPACE)
  469. strWelKnownSid = "S-1-5-32-544"
  470. set objSid = objService.Get("Win32_SID.SID=""" & strWelKnownSid & """")
  471. getAdministratorsGroupName = objSid.ReferencedDomainName & "\" & objSid.AccountName
  472. set objSid = nothing
  473. If Err.number <> 0 Then
  474. getAdministratorsGroupName = ""
  475. SA_TraceOut "quota_prop.asp", "Failed to get the administrators group name"
  476. End If
  477. End function
  478. '-------------------------------------------------------------------------
  479. 'Function name: IsUserInAdministratorsGroup
  480. 'Description: check if user is in local admin group
  481. 'Input Variables: username
  482. 'Output Variables: None
  483. 'Returns: true if user is in local admin group; false otherwise
  484. '-------------------------------------------------------------------------
  485. function IsUserInAdministratorsGroup(UserName)
  486. On Error Resume Next
  487. Err.Clear
  488. ' check if the user is in admin group
  489. if UCASE(UserName) = UCASE(getAdministratorsGroupName()) Then
  490. IsUserInAdministratorsGroup = true
  491. Else
  492. IsUserInAdministratorsGroup = false
  493. End If
  494. If Err.number <> 0 Then
  495. IsUserInAdministratorsGroup = false
  496. SA_TraceOut "quota_prop.asp", "Failed in IsUserInAdministratorsGroup"
  497. End If
  498. End function
  499. %>