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.

376 lines
10 KiB

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