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.

615 lines
17 KiB

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