home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 March / CHIPCD_3_98.iso / software / testsoft / exchange / webdata / usa / lib / logon.inc < prev    next >
Text File  |  1997-08-25  |  5KB  |  158 lines

  1. <!--#include file="getrend.inc" -->
  2. <%
  3. '!--Microsoft Outlook Web Access-->
  4. '!--Logon.inc - Logon functions-->
  5. '!--Copyright (c) Microsoft Corporation 1993-1997. All rights reserved.-->
  6.  
  7. '=======================
  8. ' AuthenticateUser
  9. ' Ensures user is authenticated
  10. '
  11. '=======================
  12. Public Function BAuthenticateUser
  13.     On Error Resume Next
  14.  
  15.     BAuthenticateUser = False
  16.  
  17.     bstrAT = Request.ServerVariables("AUTH_TYPE")
  18.  
  19.     If InStr(1, bstrAuthTypesAccepted, bstrAT, vbTextCompare) < 2 Then
  20.         Response.Buffer = TRUE
  21.         Response.Status = ("401 Unauthorized")
  22.         Response.End
  23.     Else
  24.         BAuthenticateUser = True
  25.     End If
  26.  
  27. End Function
  28.  
  29.  
  30. '=======================
  31. ' AccountDisabled
  32. ' Checks account property PR_EMS_AB_PROTOCOL_SETTINGS
  33. '
  34. '=======================
  35. Private Function BAccountDisabled(objOMSession)
  36.     On Error Resume Next
  37.  
  38.     'HTTP assumed to be enabled if property doesn't exist, or isn't found
  39.     BAccountDisabled = False
  40.  
  41.     aProtocols = objOMSession.CurrentUser.Fields(&H81B6101F)
  42.     For Each strProtocol in aProtocols
  43.         If InStr(1, strProtocol, "HTTP", vbTextCompare) Then
  44.             If "0" = Mid( strProtocol, 6, 1) Then
  45.                 BAccountDisabled = True
  46.             End If
  47.             Exit For
  48.         End If
  49.     Next
  50.  
  51.     Err.Clear   'Ignore errors generated here
  52.  
  53. End Function
  54.  
  55. '=======================
  56. ' BLogonUser
  57. ' Logs user onto Server
  58. '
  59. ' Returns: TRUE if Successful
  60. '=======================
  61. Public Function BLogonUser(bstrMailbox)  
  62.  
  63.     Dim objOMSession1
  64.  
  65.     On Error Resume Next
  66.  
  67.     BLogonUser = False
  68.  
  69.     If (Session(bstrAuthenticated)) Then
  70.         bAuthenticated = True
  71.     Else 
  72.         bAuthenticated = False
  73.     End If      
  74.  
  75.     Err.Clear
  76.     Set objOMSession1 = Server.CreateObject("MAPI.Session")
  77.  
  78.     If (Err.Number <> 0) Then
  79.         ReportError1 L_errFailedToCreateSession_ErrorMessage
  80.     Else
  81.         set objRenderApp = Application( bstrRenderApp )
  82.         bstrExchServer = objRenderApp.ConfigParameter("Server")
  83.         if IsEmpty(bstrExchServer) then    
  84.             bstrExchServer = Request.ServerVariables("SERVER_NAME")
  85.         end if
  86.  
  87.         ' Construct the OLEMSG profile from server and mailbox name
  88.         If (bAuthenticated) Then
  89.             bstrProfileInfo = bstrExchServer + vbLF + bstrMailbox
  90.  
  91.         Else
  92.             bstrExchOrg    = objRenderApp.ConfigParameter("Enterprise")
  93.             bstrExchSite   = objRenderApp.ConfigParameter("Site")
  94.             bstrExchServDN = "/o=" + bstrExchOrg + "/ou=" + bstrExchSite +_
  95.                 "/cn=Configuration/cn=Servers/cn=" + bstrExchServer
  96.  
  97.             bstrProfileInfo = bstrExchServDN + vbLF + "anon" + vbLF + "anon"
  98.  
  99.         End If
  100.  
  101.         ' Set user's locale before Logon -- do this with ObjectRenderer to avoid race condition
  102.         Set objRenderObj = GetObjectRenderer
  103.         Session.CodePage = objRenderObj.CodePage    'set the denali session codepage
  104.         objOMSession1.SetLocaleIDs objRenderObj.LCID, objRenderObj.CodePage
  105.         Set objRenderObj = Nothing  ' Release
  106.  
  107.         Err.Clear
  108.         objOMSession1.Logon "", "", False, True, 0, True, bstrProfileInfo 
  109.  
  110.         If (Err.Number <> 0) Then
  111.             ReportError1 L_errFailedConnect_ErrorMessage & bstrExchServer
  112.         Else
  113.             If (bAuthenticated) Then
  114.  
  115.                 If (BAccountDisabled(objOMSession1)) Then
  116.                     objOMSession1.Logoff
  117.                     ReportError1 L_errHTTPDisabled_ErrorMessage
  118.                 Else
  119.                     
  120.                     Err.Clear
  121.                     Set objInbox = objOMSession1.Inbox
  122.                     If (Err.Number <> 0) Then
  123.                         objOMSession1.Logoff
  124.                         Set objOMSession1 = Nothing
  125.                         ' This will exit the function
  126.                         ReportError1 L_errFailedToGetInbox_ErrorMessage
  127.                     End If
  128.  
  129.                     iTimeout = objRenderApp.ConfigParameter("AuthenticatedSessionTimeout")
  130.                     If iTimeout = 0 Then
  131.                         ITimeout = 60 'minutes
  132.                     End If
  133.                     Session.Timeout = iTimeout
  134.                 End If
  135.  
  136.             Else
  137.  
  138.                 iTimeout = objRenderApp.ConfigParameter("AnonymousSessionTimeout")
  139.                 If iTimeout = 0 Then
  140.                     ITimeout = 20 'minutes
  141.                 End If
  142.                 Session.Timeout = iTimeout
  143.             End If   'bAuthenticated
  144.  
  145.             BLogonUser = True
  146.             Set Session(bstrOMSession) = objOMSession1
  147.             Session("hImp") = objRenderApp.ImpID
  148.             SetPageDefaults
  149.  
  150.         End If    'Err <> 0
  151.     End If   'Err <> 0
  152.  
  153.  
  154.  
  155. End Function
  156.  
  157. %>
  158.