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.

384 lines
10 KiB

  1. <%@ Language=VBScript %>
  2. <% Option Explicit %>
  3. <%
  4. '-------------------------------------------------------------------------
  5. ' POP3 Mail Add-in - Mailboxes - Lock
  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 FLD_NAME = "fldName"
  19. '-------------------------------------------------------------------------
  20. ' Global Variables
  21. '-------------------------------------------------------------------------
  22. Dim g_page
  23. Dim g_rgFailures
  24. Dim g_nFailures
  25. g_nFailures = 0
  26. Dim g_strLockFlag
  27. If (Request.QueryString(PARAM_LOCKFLAG).Count > 0) Then
  28. g_strLockFlag = UCase(Request.QueryString(PARAM_LOCKFLAG).Item(1))
  29. ElseIf (Request.Form(PARAM_LOCKFLAG).Count > 0) Then
  30. g_strLockFlag = UCase(Request.Form(PARAM_LOCKFLAG).Item(1))
  31. Else
  32. ' Default to locking
  33. g_strLockFlag = LOCKFLAG_LOCK
  34. End If
  35. Dim g_strDomainName
  36. g_strDomainName = GetDomainName()
  37. '----------------------------------------------------------------------
  38. ' Global Localized Strings
  39. '----------------------------------------------------------------------
  40. Dim l_strPageTitle
  41. ' The title will only be shown in the case of an error, so always set
  42. ' the error title.
  43. If (LOCKFLAG_LOCK = g_strLockFlag) Then
  44. l_strPageTitle = GetLocString(RES_DLL_NAME, _
  45. POP3_PAGETITLE_MAILBOXES_LOCKERROR, _
  46. "")
  47. Else
  48. l_strPageTitle = GetLocString(RES_DLL_NAME, _
  49. POP3_PAGETITLE_MAILBOXES_UNLOCKERROR, _
  50. "")
  51. End If
  52. Dim l_strLockErrorPrompt
  53. l_strLockErrorPrompt = GetLocString(RES_DLL_NAME, _
  54. POP3_PROMPT_MAILBOXES_LOCKERROR, _
  55. "")
  56. Dim l_strUnlockErrorPrompt
  57. l_strUnlockErrorPrompt = GetLocString(RES_DLL_NAME, _
  58. POP3_PROMPT_MAILBOXES_UNLOCKERROR, _
  59. "")
  60. Dim l_strRetryPrompt
  61. l_strRetryPrompt = GetLocString(RES_DLL_NAME, _
  62. POP3_PROMPT_MAILBOXES_LOCKRETRY, _
  63. "")
  64. '**********************************************************************
  65. '* E N T R Y P O I N T
  66. '**********************************************************************
  67. '
  68. ' Attempt the operation.
  69. '
  70. If (AtFirstYouSucceed(g_strLockFlag)) Then
  71. ' The operation succeeded and code has been output to redirect
  72. ' back to the caller.
  73. Response.End()
  74. Else
  75. ' The operation failed, so display the retry page.
  76. Call SA_CreatePage(l_strPageTitle, "", PT_PROPERTY, g_page)
  77. Call SA_ShowPage (g_page)
  78. End If
  79. '**********************************************************************
  80. '* H E L P E R S U B R O U T I N E S
  81. '**********************************************************************
  82. Function AtFirstYouSucceed(strLockFlag)
  83. On Error Resume Next
  84. AtFirstYouSucceed = false
  85. '
  86. ' If this is the first time the page has been loaded, try to
  87. ' execute the request. Otherwise, we won't have the correct
  88. ' return URL, so let the normal page events handle the request.
  89. '
  90. If (Request.Form(FLD_NAME).Count <> 0) Then
  91. Exit Function
  92. End If
  93. Dim rgMailboxesTable
  94. rgMailboxesTable = GetMailboxList()
  95. If (Err.number <> 0) Then
  96. Call SA_SetErrMsg( HandleUnexpectedError() )
  97. Exit Function
  98. End If
  99. Call LockMailboxes(g_strDomainName, rgMailboxesTable, strLockFlag)
  100. If (g_nFailures = 0) Then
  101. '
  102. ' The mailboxes were successfully un/locked. Redirect back to
  103. ' the OTS.
  104. '
  105. %>
  106. <SCRIPT LANGUAGE="Javascript" FOR="window" EVENT="onload">
  107. try
  108. {
  109. // Hide the footer to avoid "Action Cancelled" page from briefly displaying.
  110. top.document.getElementsByTagName("frameset").item(0).rows = "*,0";
  111. top.location.href = "<%=Server.HTMLEncode(Request.QueryString("ReturnURL").Item(1))%>";
  112. }
  113. catch(e)
  114. {
  115. // Nothing we can do.
  116. }
  117. </SCRIPT>
  118. <%
  119. AtFirstYouSucceed = true
  120. End If
  121. End Function
  122. '---------------------------------------------------------------------
  123. ' GetMailboxList
  124. '---------------------------------------------------------------------
  125. Function GetMailboxList()
  126. Dim rgMailboxes
  127. '
  128. ' First, check the form data.
  129. '
  130. Dim iRow
  131. Dim nRows
  132. nRows = Request.Form(FLD_NAME).Count
  133. If (nRows <> 0) Then
  134. ReDim rgMailboxes(nRows, 0)
  135. '
  136. ' Iterate over the form data.
  137. '
  138. For iRow = 1 to nRows
  139. rgMailboxes(iRow, 0) = Request.Form(FLD_NAME).Item(iRow)
  140. Next
  141. Else
  142. '
  143. ' Form data was empty -- try the OTS data.
  144. '
  145. nRows = OTS_GetTableSelectionCount("")
  146. ReDim rgMailboxes(nRows, 0)
  147. For iRow = 1 to nRows
  148. If (Not OTS_GetTableSelection("", iRow, rgMailboxes(iRow, 0))) Then
  149. Call SA_TraceErrorOut(SOURCE_FILE, _
  150. "Failed to get OTS selection.")
  151. Err.Raise(-1)
  152. End If
  153. Next
  154. End If
  155. GetMailboxList = rgMailboxes
  156. End Function
  157. '---------------------------------------------------------------------
  158. ' LockMailboxes
  159. '---------------------------------------------------------------------
  160. Function LockMailboxes(strDomainName, rgMailboxesTable, strLockFlag)
  161. On Error Resume Next
  162. Dim bLock
  163. If (LOCKFLAG_LOCK = strLockFlag) Then
  164. bLock = true
  165. Else
  166. bLock = false
  167. End If
  168. Dim oConfig
  169. Set oConfig = Server.CreateObject("P3Admin.P3Config")
  170. Dim oDomain
  171. Set oDomain = oConfig.Domains.Item(strDomainName)
  172. Dim colMailboxes
  173. Set colMailboxes = oDomain.Users
  174. Dim nRows
  175. nRows = UBound(rgMailboxesTable, 1)
  176. ' Create an array to hold the names of any mailboxes that could
  177. ' not be un/locked.
  178. ReDim g_rgFailures(nRows, 0)
  179. g_nFailures = 0
  180. '
  181. ' Store the error to report at the end of this method. We don't
  182. ' want to stop processing, because the list of failures needs to
  183. ' be filled.
  184. '
  185. Dim nErr
  186. nErr = Err.number
  187. Err.Clear()
  188. '
  189. ' Iterate over the selected mailboxes and un/lock them.
  190. '
  191. Dim iRow
  192. For iRow = 1 to nRows
  193. colMailboxes.Item(rgMailboxesTable(iRow, 0)).Lock = bLock
  194. If (Err.number <> 0) Then
  195. If (nErr = 0) Then
  196. Call SA_SetErrMsg( HandleUnexpectedError() )
  197. End If
  198. g_nFailures = g_nFailures + 1
  199. g_rgFailures(g_nFailures, 0) = rgMailboxesTable(iRow, 0)
  200. End If
  201. Next
  202. If (nErr <> 0) Then
  203. Call SA_SetErrMsg( HandleUnexpectedError() )
  204. Exit Function
  205. End If
  206. End Function
  207. '---------------------------------------------------------------------
  208. ' OutputNameList
  209. '---------------------------------------------------------------------
  210. Sub OutputNameList(rgMailboxesTable, nRows)
  211. '
  212. ' Sort the names.
  213. '
  214. Call SAQuickSort(rgMailboxesTable, 1, nRows, 1, 0)
  215. '
  216. ' Output the names in a bulleted list.
  217. '
  218. Response.Write("<UL>" & vbCrLf)
  219. Dim strAddress
  220. Dim iRow
  221. For iRow = 1 to nRows
  222. strAddress = rgMailboxesTable(iRow, 0) & "@" & g_strDomainName
  223. %>
  224. <LI><%=Server.HTMLEncode(strAddress)%></LI>
  225. <INPUT TYPE="hidden" NAME="<%=FLD_NAME%>"
  226. VALUE="<%=Server.HTMLEncode(rgMailboxesTable(iRow, 0))%>">
  227. <%
  228. Next
  229. Response.Write("</UL>" & vbCrLf)
  230. End Sub
  231. '---------------------------------------------------------------------
  232. ' ServeCommonJavaScript
  233. '---------------------------------------------------------------------
  234. Function ServeCommonJavaScript()
  235. %>
  236. <script language="JavaScript" src="../inc_global.js">
  237. </script>
  238. <script language="JavaScript">
  239. function Init(){}
  240. function ValidatePage(){return true;}
  241. function SetData(){}
  242. </script>
  243. <%
  244. End Function
  245. '**********************************************************************
  246. '* E V E N T H A N D L E R S
  247. '**********************************************************************
  248. '---------------------------------------------------------------------
  249. ' OnInitPage
  250. '---------------------------------------------------------------------
  251. Public Function OnInitPage(ByRef PageIn, ByRef EventArg)
  252. OnInitPage = TRUE
  253. End Function
  254. '---------------------------------------------------------------------
  255. ' OnServePropertyPage
  256. '---------------------------------------------------------------------
  257. Public Function OnServePropertyPage(ByRef PageIn, ByRef EventArg)
  258. On Error Resume Next
  259. Session(SESSION_POP3DOMAINNAME) = g_strDomainName
  260. OnServePropertyPage = TRUE
  261. Dim rgMailboxesTable
  262. '
  263. ' Emit Javascript functions required by Web Framework
  264. Call ServeCommonJavaScript()
  265. %>
  266. <INPUT TYPE="hidden" NAME="<%=PARAM_LOCKFLAG%>" VALUE="<%=g_strLockFlag%>">
  267. <%
  268. If (g_nFailures < 1) Then
  269. Call SA_TraceErrorOut(SOURCE_FILE, _
  270. "Page was loaded even though no mailboxes failed!")
  271. End If
  272. '
  273. ' Output the error prompt and sorted list of failed mailboxes.
  274. '
  275. If (g_strLockFlag = LOCKFLAG_LOCK) Then
  276. Response.Write(l_strLockErrorPrompt & "<BR>" & vbCrLf)
  277. Else
  278. Response.Write(l_strUnlockErrorPrompt & "<BR>" & vbCrLf)
  279. End If
  280. Call OutputNameList(g_rgFailures, g_nFailures)
  281. Response.Write("<BR>" & l_strRetryPrompt & vbCrLf)
  282. OnServePropertyPage = TRUE
  283. If (Err.number <> 0) Then
  284. Call SA_SetErrMsg( HandleUnexpectedError() )
  285. End If
  286. End Function
  287. '---------------------------------------------------------------------
  288. ' OnPostBackPage
  289. '---------------------------------------------------------------------
  290. Public Function OnPostBackPage(ByRef PageIn, ByRef EventArg)
  291. OnPostBackPage = TRUE
  292. End Function
  293. '---------------------------------------------------------------------
  294. ' OnSubmitPage
  295. '---------------------------------------------------------------------
  296. Public Function OnSubmitPage(ByRef PageIn, ByRef EventArg)
  297. On Error Resume Next
  298. OnSubmitPage = FALSE
  299. Dim rgMailboxesTable
  300. rgMailboxesTable = GetMailboxList()
  301. Call LockMailboxes(g_strDomainName, rgMailboxesTable, g_strLockFlag)
  302. If (g_nFailures > 0) Then
  303. OnSubmitPage = FALSE
  304. Else
  305. OnSubmitPage = TRUE
  306. End If
  307. End Function
  308. '---------------------------------------------------------------------
  309. ' OnClosePage
  310. '---------------------------------------------------------------------
  311. Public Function OnClosePage(ByRef PageIn, ByRef EventArg)
  312. OnClosePage = TRUE
  313. End Function
  314. %>