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.

637 lines
17 KiB

  1. <%@ Language=VBScript %>
  2. <% Option Explicit %>
  3. <%
  4. '-------------------------------------------------------------------------
  5. ' POP3 Mail Add-in - Mailboxes
  6. ' Copyright (C) Microsoft Corporation. All rights reserved.
  7. '-------------------------------------------------------------------------
  8. %>
  9. <!-- #include virtual="/admin/inc_framework.asp" -->
  10. <!-- #include virtual="/admin/ots_main.asp" -->
  11. <!-- #include file="p3cminc.asp" -->
  12. <%
  13. '-------------------------------------------------------------------------
  14. ' Global Constants
  15. '-------------------------------------------------------------------------
  16. Dim SOURCE_FILE
  17. SOURCE_FILE = SA_GetScriptFileName()
  18. Const ROWS_PER_PAGE = 100
  19. Const COL_LOCK_ID = 3
  20. '-------------------------------------------------------------------------
  21. ' Global Variables
  22. '-------------------------------------------------------------------------
  23. ' Sorting variables
  24. Dim g_iSortCol
  25. Dim g_sSortSequence
  26. ' Searching variables
  27. Dim g_bSearchChanged
  28. Dim g_iSearchCol
  29. Dim g_sSearchColValue
  30. g_sSearchColValue = ""
  31. ' Paging variables
  32. Dim g_bPagingInitialized
  33. Dim g_sPageAction
  34. Dim g_iPageMin
  35. Dim g_iPageMax
  36. Dim g_iPageCurrent
  37. ' Other variables
  38. Dim g_page
  39. Dim g_strDomainName
  40. g_strDomainName = GetDomainName()
  41. '----------------------------------------------------------------------
  42. ' Global Localized Strings
  43. '----------------------------------------------------------------------
  44. Dim l_strPageTitle
  45. l_strPageTitle = GetLocString(RES_DLL_NAME, _
  46. POP3_PAGETITLE_MAILBOXES, _
  47. Array(g_strDomainName))
  48. Dim l_strTableCaption
  49. l_strTableCaption = GetLocString(RES_DLL_NAME, _
  50. POP3_TABLECAPTION_MAILBOXES, _
  51. "")
  52. Dim l_strTasks
  53. l_strTasks = GetLocString(RES_DLL_NAME, _
  54. POP3_TASKS, _
  55. "")
  56. ' Tasks
  57. Dim l_strTaskNew
  58. l_strTaskNew = GetLocString(RES_DLL_NAME, _
  59. POP3_TASK_MAILBOXES_NEW, _
  60. "")
  61. Dim l_strTaskNewCaption
  62. l_strTaskNewCaption = GetLocString(RES_DLL_NAME, _
  63. POP3_TASKCAPTION_MAILBOXES_NEW, _
  64. "")
  65. Dim l_strTaskDelete
  66. l_strTaskDelete = GetLocString(RES_DLL_NAME, _
  67. POP3_TASK_MAILBOXES_DELETE, _
  68. "")
  69. Dim l_strTaskDeleteCaption
  70. l_strTaskDeleteCaption = GetLocString(RES_DLL_NAME, _
  71. POP3_TASKCAPTION_MAILBOXES_DELETE, _
  72. "")
  73. Dim l_strTaskLock
  74. l_strTaskLock = GetLocString(RES_DLL_NAME, _
  75. POP3_TASK_MAILBOXES_LOCK, _
  76. "")
  77. Dim l_strTaskLockCaption
  78. l_strTaskLockCaption = GetLocString(RES_DLL_NAME, _
  79. POP3_TASKCAPTION_MAILBOXES_LOCK, _
  80. "")
  81. Dim l_strTaskUnlock
  82. l_strTaskUnlock = GetLocString(RES_DLL_NAME, _
  83. POP3_TASK_MAILBOXES_UNLOCK, _
  84. "")
  85. Dim l_strTaskUnlockCaption
  86. l_strTaskUnlockCaption = GetLocString(RES_DLL_NAME, _
  87. POP3_TASKCAPTION_MAILBOXES_UNLOCK, _
  88. "")
  89. ' Column headers
  90. Dim l_strColName
  91. l_strColName = GetLocString(RES_DLL_NAME, _
  92. POP3_COL_MAILBOX_NAME, _
  93. "")
  94. Dim l_strColSize
  95. l_strColSize = GetLocString(RES_DLL_NAME, _
  96. POP3_COL_MAILBOX_SIZE, _
  97. "")
  98. Dim l_strColMessages
  99. l_strColMessages = GetLocString(RES_DLL_NAME, _
  100. POP3_COL_MAILBOX_MESSAGES, _
  101. "")
  102. Dim l_strColLocked
  103. l_strColLocked = GetLocString(RES_DLL_NAME, _
  104. POP3_COL_MAILBOX_LOCKED, _
  105. "")
  106. Dim l_strLockedYes
  107. l_strLockedYes = GetLocString(RES_DLL_NAME, _
  108. POP3_MAILBOX_LOCKED_YES, _
  109. "")
  110. Dim l_strLockedNo
  111. l_strLockedNo = GetLocString(RES_DLL_NAME, _
  112. POP3_MAILBOX_LOCKED_NO, _
  113. "")
  114. Dim l_strUnitMB
  115. l_strUnitMB = GetLocString(RES_DLL_NAME, _
  116. POP3_FACTOR_MB, _
  117. "")
  118. Dim l_strUnitKB
  119. l_strUnitKB = GetLocString(RES_DLL_NAME, _
  120. POP3_FACTOR_KB, _
  121. "")
  122. '**********************************************************************
  123. '* E N T R Y P O I N T
  124. '**********************************************************************
  125. Call SA_CreatePage(l_strPageTitle, "", PT_AREA, g_page)
  126. Call SA_ShowPage (g_page)
  127. '**********************************************************************
  128. '* H E L P E R S U B R O U T I N E S
  129. '**********************************************************************
  130. '----------------------------------------------------------------------
  131. ' CreateTasks
  132. '----------------------------------------------------------------------
  133. Sub CreateTasks( _
  134. ByRef table _
  135. )
  136. Call OTS_SetTableTasksTitle(table, l_strTasks)
  137. '
  138. ' New
  139. Dim strNewURL
  140. strNewURL = "mail/p3mbnew.asp"
  141. Call SA_MungeURL(strNewURL, "tab1", GetTab1())
  142. Call SA_MungeURL(strNewURL, "tab2", GetTab2())
  143. Call SA_MungeURL(strNewURL, PARAM_DOMAINNAME, g_strDomainName)
  144. Call OTS_AddTableTask(table, OTS_CreateTaskEx(l_strTaskNew, _
  145. l_strTaskNewCaption, _
  146. strNewURL,_
  147. OTS_PT_PROPERTY,_
  148. "OTS_TaskAlways"))
  149. '
  150. ' Delete
  151. Dim strDeleteURL
  152. strDeleteURL = "mail/p3mbdel.asp"
  153. Call SA_MungeURL(strDeleteURL, "tab1", GetTab1())
  154. Call SA_MungeURL(strDeleteURL, "tab2", GetTab2())
  155. Call SA_MungeURL(strDeleteURL, PARAM_DOMAINNAME, g_strDomainName)
  156. Call OTS_AddTableTask(table, OTS_CreateTaskEx(l_strTaskDelete, _
  157. l_strTaskDeleteCaption, _
  158. strDeleteURL,_
  159. OTS_PT_PROPERTY,_
  160. "OTS_TaskAny"))
  161. '
  162. ' Lock
  163. Dim strLockURL
  164. strLockURL = "mail/p3mblock.asp"
  165. Call SA_MungeURL(strLockURL, "tab1", GetTab1())
  166. Call SA_MungeURL(strLockURL, "tab2", GetTab2())
  167. Call SA_MungeURL(strLockURL, PARAM_DOMAINNAME, g_strDomainName)
  168. Call SA_MungeURL(strLockURL, PARAM_LOCKFLAG, LOCKFLAG_LOCK)
  169. Call OTS_AddTableTask(table, OTS_CreateTaskEx(l_strTaskLock, _
  170. l_strTaskLockCaption, _
  171. strLockURL,_
  172. OTS_PT_PROPERTY,_
  173. "SomeMailboxesAreUnlocked"))
  174. '
  175. ' Unlock
  176. Dim strUnlockURL
  177. strUnlockURL = "mail/p3mblock.asp"
  178. Call SA_MungeURL(strUnlockURL, "tab1", GetTab1())
  179. Call SA_MungeURL(strUnlockURL, "tab2", GetTab2())
  180. Call SA_MungeURL(strUnlockURL, PARAM_DOMAINNAME, g_strDomainName)
  181. Call SA_MungeURL(strUnlockURL, PARAM_LOCKFLAG, LOCKFLAG_UNLOCK)
  182. Call OTS_AddTableTask(table, OTS_CreateTaskEx(l_strTaskUnlock, _
  183. l_strTaskUnlockCaption, _
  184. strUnlockURL,_
  185. OTS_PT_PROPERTY,_
  186. "SomeMailboxesAreLocked"))
  187. End Sub
  188. '---------------------------------------------------------------------
  189. ' CreateColumns
  190. '---------------------------------------------------------------------
  191. Sub CreateColumns( _
  192. ByRef table _
  193. )
  194. Dim colFlags
  195. '
  196. ' Add the columns
  197. '
  198. colFlags = (OTS_COL_SEARCH OR OTS_COL_SORT OR OTS_COL_KEY)
  199. Call OTS_AddTableColumn(table, OTS_CreateColumnEx(l_strColName, "left", colFlags, 0))
  200. colFlags = (OTS_COL_SORT)
  201. Call OTS_AddTableColumn(table, OTS_CreateColumnEx(l_strColSize, "left nowrap", colFlags, 0))
  202. Call OTS_AddTableColumn(table, OTS_CreateColumnEx(l_strColMessages, "left nowrap", colFlags, 0))
  203. colFlags = (OTS_COL_SEARCH OR OTS_COL_SORT)
  204. Call OTS_AddTableColumn(table, OTS_CreateColumnEx(l_strColLocked, "left nowrap", colFlags, 0))
  205. colFlags = (OTS_COL_HIDDEN)
  206. Call OTS_AddTableColumn(table, OTS_CreateColumnEx("colRawSize", "", colFlags, 0))
  207. Call OTS_AddTableColumn(table, OTS_CreateColumnEx("colRawMessages", "", colFlags, 0))
  208. End Sub
  209. '---------------------------------------------------------------------
  210. ' FillTable
  211. '---------------------------------------------------------------------
  212. Sub FillTable( _
  213. ByRef table _
  214. )
  215. On Error Resume Next
  216. Err.Clear()
  217. '
  218. ' Setup the paging variables
  219. Dim nApplicableRows ' Number of rows we've seen so far that
  220. ' meet the search criteria.
  221. nApplicableRows = 0
  222. Dim nRowsAdded ' Number of applicable rows that have
  223. ' actually been added to the table.
  224. nRowsAdded = 0
  225. Dim iLowerLimit ' Exclusive
  226. iLowerLimit = ( g_iPageCurrent - 1 ) * ROWS_PER_PAGE
  227. '
  228. ' Get the POP3 Config object
  229. Dim oConfig
  230. Set oConfig = Server.CreateObject("P3Admin.P3Config")
  231. Dim oDomain
  232. Set oDomain = oConfig.Domains.Item(g_strDomainName)
  233. If Err.Number <> 0 Then
  234. Call SA_SetErrMsg( HandleUnexpectedError() )
  235. Call OTS_EnablePaging(table, false)
  236. Exit Sub
  237. End If
  238. '
  239. ' Add the mailboxes to the table.
  240. Dim oMailbox
  241. Dim row
  242. For Each oMailbox In oDomain.Users
  243. '
  244. ' Construct the row
  245. row = ConstructRow(oMailbox)
  246. '
  247. ' Verify the row meets the search and paging criteria and add it to
  248. ' the table.
  249. If (RowMeetsSearchCriteria(row)) Then
  250. nApplicableRows = nApplicableRows + 1
  251. If ( nApplicableRows > iLowerLimit And _
  252. nRowsAdded < ROWS_PER_PAGE ) Then
  253. nRowsAdded = nRowsAdded + 1
  254. Call OTS_AddTableRow(table, row)
  255. End If ' If: The row is on the current page.
  256. End If ' If: The row meets the search criteria.
  257. Next
  258. '
  259. ' Configure paging if necessary
  260. If (nApplicableRows > ROWS_PER_PAGE) Then
  261. Call OTS_EnablePaging(table, true)
  262. If (Not g_bPagingInitialized) Then
  263. g_iPageMin = 1
  264. g_iPageMax = Int(nApplicableRows / ROWS_PER_PAGE)
  265. If ((nApplicableRows MOD ROWS_PER_PAGE) > 0) Then
  266. g_iPageMax = g_iPageMax + 1
  267. End If
  268. g_iPageCurrent = 1
  269. Call OTS_SetPagingRange(table, _
  270. g_iPageMin, _
  271. g_iPageMax, _
  272. g_iPageCurrent)
  273. End If
  274. End If
  275. End Sub
  276. '---------------------------------------------------------------------
  277. ' RowMeetsSearchCriteria
  278. '---------------------------------------------------------------------
  279. Function RowMeetsSearchCriteria( _
  280. row _
  281. )
  282. If ( g_sSearchColValue = "" ) Then
  283. RowMeetsSearchCriteria = true
  284. Else
  285. Dim posMatch
  286. posMatch = InStr(1, row(g_iSearchCol), g_sSearchColValue, 1)
  287. If ( IsNull(posMatch) Or posMatch = 0 ) Then
  288. RowMeetsSearchCriteria = false
  289. Else
  290. RowMeetsSearchCriteria = true
  291. End If
  292. End If
  293. End Function
  294. '---------------------------------------------------------------------
  295. ' ConstructRow
  296. '---------------------------------------------------------------------
  297. Function ConstructRow( _
  298. oMailbox _
  299. )
  300. Dim strLock
  301. If (oMailbox.Lock) Then
  302. strLock = l_strLockedYes
  303. Else
  304. strLock = l_strLockedNo
  305. End If
  306. Dim nBytes
  307. Dim nFactor
  308. oMailbox.GetMessageDiskUsage nBytes, nFactor
  309. Dim nSize
  310. Dim strUnit
  311. nSize = CalculateDiskUsage(nBytes, nFactor, false)
  312. if ( nSize < 1 ) Then
  313. nSize = CalculateDiskUsage(nBytes, nFactor, true) ' Calculate to KB instead of MB
  314. strUnit = l_strUnitKB
  315. Else
  316. strUnit = l_strUnitMB
  317. End If
  318. ConstructRow = Array(oMailbox.Name, _
  319. FormatNumber(nSize, 0) & strUnit, _
  320. FormatNumber(oMailbox.MessageCount, 0), _
  321. strLock, _
  322. GetSortableNumber(nSize), _
  323. GetSortableNumber(oMailbox.MessageCount))
  324. End Function
  325. '---------------------------------------------------------------------
  326. ' ServeClientTableData
  327. '---------------------------------------------------------------------
  328. Function ServeClientTableData(rgRows)
  329. '
  330. ' Get the POP3 Config object
  331. Dim oConfig
  332. Set oConfig = Server.CreateObject("P3Admin.P3Config")
  333. Dim oDomain
  334. Set oDomain = oConfig.Domains.Item(g_strDomainName)
  335. '
  336. ' Output the beginning of the client script block that will contain
  337. ' the array to track which items can be deleted.
  338. Response.Write("<SCRIPT LANGUAGE=""Javascript"">" & vbCrLf)
  339. Response.Write("var g_rgMailboxLocked = new Array();" & vbCrLf)
  340. If ( oDomain.Lock ) Then
  341. Response.Write("var g_bIsDomainLocked = true ;" & vbCrLf)
  342. Else
  343. Response.Write("var g_bIsDomainLocked = false ;" & vbCrLf)
  344. End If
  345. Dim nRows
  346. nRows = UBound(rgRows)
  347. Dim iRow
  348. For iRow = 0 To nRows - 1
  349. If (l_strLockedYes = rgRows(iRow)(COL_LOCK_ID)) Then
  350. Response.Write("g_rgMailboxLocked[" & iRow & "] = true;" & vbCrLf)
  351. Else
  352. Response.Write("g_rgMailboxLocked[" & iRow & "] = false;" & vbCrLf)
  353. End If
  354. Next
  355. '
  356. ' Close the client script block.
  357. Response.Write("</SCRIPT>" & vbCrLf)
  358. End Function
  359. '**********************************************************************
  360. '* E V E N T H A N D L E R S
  361. '**********************************************************************
  362. '----------------------------------------------------------------------
  363. ' OnInitPage
  364. '----------------------------------------------------------------------
  365. Public Function OnInitPage( _
  366. ByRef PageIn, _
  367. ByRef EventArg _
  368. )
  369. ' Initially, sort by name
  370. g_iSortCol = 0
  371. g_sSortSequence = "A"
  372. g_bPagingInitialized = FALSE
  373. g_iPageCurrent = 1
  374. OnInitPage = TRUE
  375. End Function
  376. '----------------------------------------------------------------------
  377. ' OnServeAreaPage
  378. '----------------------------------------------------------------------
  379. Public Function OnServeAreaPage( _
  380. ByRef PageIn, _
  381. ByRef EventArg _
  382. )
  383. Session("PKey_Count") = 0
  384. Session(SESSION_POP3DOMAINNAME) = g_strDomainName
  385. Dim table
  386. table = OTS_CreateTable("", l_strTableCaption)
  387. Call OTS_SetTableMultiSelection(table, true)
  388. '
  389. ' If the search criteria changed then we need to recompute the
  390. ' paging range
  391. If ( TRUE = g_bSearchChanged ) Then
  392. g_bPagingInitialized = FALSE
  393. g_iPageCurrent = 1
  394. End If
  395. Call CreateColumns (table)
  396. Call CreateTasks (table)
  397. Call FillTable (table)
  398. Call OTS_SortTable (table, g_iSortCol, g_sSortSequence, SA_RESERVED)
  399. Call OTS_ServeTable(table)
  400. Dim rgRows
  401. Call OTS_GetTableRows(table, rgRows)
  402. If (IsArray(rgRows)) Then
  403. Call ServeClientTableData(rgRows)
  404. End If
  405. Call ServeClientTaskFunctions()
  406. OnServeAreaPage = TRUE
  407. End Function
  408. '----------------------------------------------------------------------
  409. ' OnSortNotify()
  410. '----------------------------------------------------------------------
  411. Public Function OnSortNotify( _
  412. ByRef PageIn, _
  413. ByRef EventArg, _
  414. ByVal sortCol, _
  415. ByVal sortSeq _
  416. )
  417. g_iSortCol = sortCol
  418. g_sSortSequence = sortSeq
  419. If (g_iSortCol = 1) Then
  420. g_iSortCol = 4
  421. ElseIf (g_iSortCol = 2) Then
  422. g_iSortCol = 5
  423. End If
  424. OnSortNotify = TRUE
  425. End Function
  426. '----------------------------------------------------------------------
  427. ' OnSearchNotify()
  428. '----------------------------------------------------------------------
  429. Public Function OnSearchNotify( _
  430. ByRef PageIn, _
  431. ByRef EventArg, _
  432. ByRef sItem, _
  433. ByRef sValue _
  434. )
  435. OnSearchNotify = TRUE
  436. If SA_IsChangeEvent(EventArg) Then
  437. g_bSearchChanged = TRUE
  438. ElseIf SA_IsPostBackEvent(EventArg) Then
  439. g_bSearchChanged = FALSE
  440. End If
  441. g_iSearchCol = Int(sItem)
  442. g_sSearchColValue = CStr(sValue)
  443. End Function
  444. '----------------------------------------------------------------------
  445. ' OnPagingNotify()
  446. '----------------------------------------------------------------------
  447. Public Function OnPagingNotify( _
  448. ByRef PageIn, _
  449. ByRef EventArg, _
  450. ByVal sPageAction, _
  451. ByVal iPageMin, _
  452. ByVal iPageMax, _
  453. ByVal iPageCurrent _
  454. )
  455. OnPagingNotify = TRUE
  456. g_bPagingInitialized = true
  457. g_iPageMin = iPageMin
  458. g_iPageMax = iPageMax
  459. g_iPageCurrent = iPageCurrent
  460. End Function
  461. '----------------------------------------------------------------------
  462. ' ServeClientTaskFunctions()
  463. '----------------------------------------------------------------------
  464. Public Sub ServeClientTaskFunctions()
  465. %>
  466. <SCRIPT LANGUAGE="Javascript">
  467. var g_bSomeMailboxesAreLocked = false;
  468. function SomeMailboxesAreLocked(sMessage, iTaskNo, iItemNo)
  469. {
  470. var rc = true;
  471. if(sMessage.toLowerCase() == OTS_MESSAGE_BEGIN)
  472. {
  473. g_bSomeMailboxesAreLocked = false;
  474. }
  475. else if(sMessage.toLowerCase() == OTS_MESSAGE_ITEM)
  476. {
  477. //
  478. // See if this domain is locked.
  479. //
  480. if ( g_rgMailboxLocked[iItemNo] )
  481. {
  482. g_bSomeMailboxesAreLocked = true;
  483. // No need to continue, because we have at least one locked domain.
  484. rc = false;
  485. }
  486. }
  487. else if(sMessage.toLowerCase() == OTS_MESSAGE_END)
  488. {
  489. if(g_bSomeMailboxesAreLocked)
  490. {
  491. OTS_SetTaskEnabled(iTaskNo, true);
  492. }
  493. else
  494. {
  495. OTS_SetTaskEnabled(iTaskNo, false);
  496. }
  497. if ( g_bIsDomainLocked ) // If the domain is locked, don't allow mailboxes to be unlocked.
  498. {
  499. OTS_SetTaskEnabled ( iTaskNo, false ) ;
  500. }
  501. }
  502. return rc;
  503. }
  504. var g_bSomeMailboxesAreUnlocked = false;
  505. function SomeMailboxesAreUnlocked(sMessage, iTaskNo, iItemNo)
  506. {
  507. var rc = true;
  508. if(sMessage.toLowerCase() == OTS_MESSAGE_BEGIN)
  509. {
  510. g_bSomeMailboxesAreUnlocked = false;
  511. }
  512. else if(sMessage.toLowerCase() == OTS_MESSAGE_ITEM)
  513. {
  514. //
  515. // See if this domain is locked.
  516. //
  517. if(!g_rgMailboxLocked[iItemNo])
  518. {
  519. g_bSomeMailboxesAreUnlocked = true;
  520. // No need to continue, because we have at least one unlocked domain.
  521. rc = false;
  522. }
  523. }
  524. else if(sMessage.toLowerCase() == OTS_MESSAGE_END)
  525. {
  526. if(g_bSomeMailboxesAreUnlocked)
  527. {
  528. OTS_SetTaskEnabled(iTaskNo, true);
  529. }
  530. else
  531. {
  532. OTS_SetTaskEnabled(iTaskNo, false);
  533. }
  534. }
  535. return rc;
  536. }
  537. </SCRIPT>
  538. <%
  539. End Sub
  540. %>