%@ Language=VBScript %> <% Option Explicit %> <% '------------------------------------------------------------------------- ' POP3 Mail Add-in - Domains - Lock ' Copyright (C) Microsoft Corporation. All rights reserved. '------------------------------------------------------------------------- %> <% '------------------------------------------------------------------------- ' Global Constants '------------------------------------------------------------------------- Dim SOURCE_FILE SOURCE_FILE = SA_GetScriptFileName() Const FLD_NAME = "fldName" '------------------------------------------------------------------------- ' Global Variables '------------------------------------------------------------------------- Dim g_page Dim g_rgFailures Dim g_nFailures g_nFailures = 0 Dim g_strLockFlag If (Request.QueryString(PARAM_LOCKFLAG).Count > 0) Then g_strLockFlag = UCase(Request.QueryString(PARAM_LOCKFLAG).Item(1)) ElseIf (Request.Form(PARAM_LOCKFLAG).Count > 0) Then g_strLockFlag = UCase(Request.Form(PARAM_LOCKFLAG).Item(1)) Else ' Default to locking g_strLockFlag = LOCKFLAG_LOCK End If '---------------------------------------------------------------------- ' Global Localized Strings '---------------------------------------------------------------------- Dim l_strPageTitle ' The title will only be shown in the case of an error, so always set ' the error title. If (LOCKFLAG_LOCK = g_strLockFlag) Then l_strPageTitle = GetLocString(RES_DLL_NAME, _ POP3_PAGETITLE_DOMAINS_LOCKERROR, _ "") Else l_strPageTitle = GetLocString(RES_DLL_NAME, _ POP3_PAGETITLE_DOMAINS_UNLOCKERROR, _ "") End If Dim l_strLockErrorPrompt l_strLockErrorPrompt = GetLocString(RES_DLL_NAME, _ POP3_PROMPT_DOMAINS_LOCKERROR, _ "") Dim l_strUnlockErrorPrompt l_strUnlockErrorPrompt = GetLocString(RES_DLL_NAME, _ POP3_PROMPT_DOMAINS_UNLOCKERROR, _ "") Dim l_strRetryPrompt l_strRetryPrompt = GetLocString(RES_DLL_NAME, _ POP3_PROMPT_DOMAINS_LOCKRETRY, _ "") '********************************************************************** '* E N T R Y P O I N T '********************************************************************** ' ' Attempt the operation. ' If (AtFirstYouSucceed(g_strLockFlag)) Then ' The operation succeeded and code has been output to redirect ' back to the caller. Response.End() Else ' The operation failed, so display the retry page. Call SA_CreatePage(l_strPageTitle, "", PT_PROPERTY, g_page) Call SA_ShowPage (g_page) End If '********************************************************************** '* H E L P E R S U B R O U T I N E S '********************************************************************** Function AtFirstYouSucceed(strLockFlag) On Error Resume Next AtFirstYouSucceed = false ' ' If this is the first time the page has been loaded, try to ' execute the request. Otherwise, we won't have the correct ' return URL, so let the normal page events handle the request. ' If (Request.Form(FLD_NAME).Count <> 0) Then Exit Function End If Dim rgDomainsTable rgDomainsTable = GetDomainList() If (Err.number <> 0) Then Call SA_SetErrMsg( HandleUnexpectedError() ) Exit Function End If Call LockDomains(rgDomainsTable, strLockFlag) If (g_nFailures = 0) Then ' ' The domains were successfully un/locked. Redirect back to ' the OTS. ' %> <% AtFirstYouSucceed = true End If End Function '--------------------------------------------------------------------- ' GetDomainList '--------------------------------------------------------------------- Function GetDomainList() Dim rgDomains ' ' First, check the form data. ' Dim iRow Dim nRows nRows = Request.Form(FLD_NAME).Count If (nRows <> 0) Then ReDim rgDomains(nRows, 0) ' ' Iterate over the form data. ' For iRow = 1 to nRows rgDomains(iRow, 0) = Request.Form(FLD_NAME).Item(iRow) Next Else ' ' Form data was empty -- try the OTS data. ' nRows = OTS_GetTableSelectionCount("") ReDim rgDomains(nRows, 0) For iRow = 1 to nRows If (Not OTS_GetTableSelection("", iRow, rgDomains(iRow, 0))) Then Call SA_TraceErrorOut(SOURCE_FILE, _ "Failed to get OTS selection.") Err.Raise(-1) End If Next End If GetDomainList = rgDomains End Function '--------------------------------------------------------------------- ' LockDomains '--------------------------------------------------------------------- Function LockDomains(rgDomainsTable, strLockFlag) On Error Resume Next Dim bLock If (LOCKFLAG_LOCK = strLockFlag) Then bLock = true Else bLock = false End If Dim oConfig Set oConfig = Server.CreateObject("P3Admin.P3Config") Dim colDomains Set colDomains = oConfig.Domains Dim nRows nRows = UBound(rgDomainsTable, 1) ' Create an array to hold the names of any domains that could ' not be un/locked. ReDim g_rgFailures(nRows, 0) g_nFailures = 0 ' ' Store the error to report at the end of this method. We don't ' want to stop processing, because the list of failures needs to ' be filled. ' Dim nErr nErr = Err.number Err.Clear() ' ' Iterate over the selected domains and un/lock them. ' Dim iRow For iRow = 1 to nRows colDomains.Item(rgDomainsTable(iRow, 0)).Lock = bLock If (Err.number <> 0) Then Call SA_TraceErrorOut(SOURCE_FILE, _ "Failed to lock domain " & rgDomainsTable(iRow, 0) & ": " & CStr(Hex(Err.number)) & ": " & Err.Description) Err.Clear() g_nFailures = g_nFailures + 1 g_rgFailures(g_nFailures, 0) = rgDomainsTable(iRow, 0) End If Next If (nErr <> 0) Then Call SA_SetErrMsg( HandleUnexpectedError() ) Exit Function End If End Function '--------------------------------------------------------------------- ' OutputNameList '--------------------------------------------------------------------- Sub OutputNameList(rgDomainsTable, nRows) ' ' Sort the names. ' Call SAQuickSort(rgDomainsTable, 1, nRows, 1, 0) ' ' Output the names in a bulleted list. ' Response.Write("