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

  1. <%
  2. '!--Microsoft Outlook Web Access-->
  3. '!--Session.inc - Session Management-->
  4. '!--Copyright (c) Microsoft Corporation 1993-1997. All rights reserved.-->
  5.  
  6. '===============================
  7. ' the objOMSession we always use
  8. ' note that this has FILE scope
  9. '===============================
  10.  
  11. Dim objOMSession
  12. Dim iFontSize
  13. iFontSize=Session("iFontSize")
  14.  
  15. '=======================
  16. ' CheckSession
  17. '
  18. ' Check session is still valid and logon if not.
  19. ' Side Effect: Initializes objOMSession
  20. '=======================
  21. '***
  22. Public Sub CheckSession
  23.     CheckSession2 ""
  24. End Sub
  25.  
  26. 'for backwards compatability but now returns a boolean
  27. Public Function CheckSession2(bstrRedirectURL)
  28.     CheckSession2 = CheckSession3(bstrRedirectURL,"top",-1)
  29. End Function
  30.  
  31. Public Function SessionIsValid()
  32.     On Error Resume Next
  33.     SessionGet
  34.     If IsEmpty(objOMSession) Or (objOMSession Is Nothing) Then
  35.         SessionIsValid = false
  36.     Else
  37.         SessionImpersonate
  38.         SessionIsValid = true
  39.     End If
  40. End Function
  41.  
  42.  
  43. 'returns boolean success
  44. 'use CheckSession3(url, location, iStore)
  45. 'use CheckSession3("0","newwindow",1) for new window logon no viewer button
  46. 'use CheckSession3("1","newwindow",1) for new window logon with open viewer button
  47. 'bstrLogonLocation can be self, parent, parent.parent, top, etc
  48. Public Function CheckSession3(bstrRedirectURL,bstrLogonLocation,iStore)
  49.  
  50.     On Error Resume Next
  51.     Err.Clear
  52.  
  53.     If Not SessionIsValid() Then
  54.         'if no redirect url given then 
  55.         If bstrRedirectURL = "" Then 
  56.             'use the current script file for redirection and it's current URL
  57.             bstrName = Request.ServerVariables("SCRIPT_NAME")
  58.             bstrQuery = Request.ServerVariables("QUERY_STRING")
  59.             If Len(bstrQuery) > 0 Then
  60.                 bstrName = bstrName + "?" + bstrQuery
  61.             End If            
  62.         Else 'passed in both the redirect file and url
  63.             bstrName = bstrRedirectURL
  64.             bstrQuery = ""
  65.         End If
  66.  
  67.         ' user is not logged on, send them to logon page now
  68.         If InStr(1, bstrName, "/logon", 1) = 0 Then
  69.             If bstrLogonLocation = "newwindow" Then            
  70.                 fNewWindow = true
  71.                 Session(bstrURLReq) = ""
  72.                 Session("iStoreReq")=iStore
  73.             Else
  74.                 fNewWindow = false
  75.                 Session(bstrURLReq) = bstrName
  76.             End If
  77.  
  78.             Response.Write "<script language=""JavaScript"">"
  79.  
  80.             If ((InStr(1, bstrName,  "anon", 1) <> 0)  OR _
  81.                 (InStr(1, bstrQuery, "acs=anon", 1) <> 0)) Then
  82.                 ' Anon users don't need to see logon page
  83.                 bstrLogonFile = bstrVirtRoot+"/logonfrm.asp"
  84.             Else
  85.                 bstrLogonFile = bstrVirtRoot+"/logon.asp"
  86.             End If
  87.  
  88.             If fNewWindow Then
  89.                 Response.Write "window.open(""" + bstrLogonFile + "?newwindow=1&viewer=" + bstrRedirectURL + """,""newLogon"",""toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=600,height=400"")"
  90.             Else
  91.                 Response.Write bstrLogonLocation + ".location='" + bstrLogonFile + "'"
  92.             End If
  93.  
  94.             Response.Write "</script>"
  95.             If Not fNewWindow Then Response.End
  96.             CheckSession3 = false
  97.         End If
  98.     Else
  99.         CheckSession3 =true
  100.     End If
  101.  
  102.  
  103. End Function
  104.  
  105. Public Sub SessionGet
  106.  
  107.     On Error Resume Next
  108.  
  109.     If (Not IsEmpty(Session(bstrAuthenticated)) ) Then
  110.         Set objOMSession = Session(bstrOMSession)
  111.     End If
  112.  
  113. End Sub
  114.  
  115. Public Sub SessionImpersonate
  116.     On Error Resume Next
  117.  
  118.     hImp = Session("hImp")
  119.  
  120.     set objRA = Application(bstrRenderApp)
  121.     If objRA Is Nothing Then
  122.         ReportError1 L_errApplicNull_ErrorMessage
  123.     Else
  124.         fOk = objRA.Impersonate(hImp)
  125.         If fOk <> 1 Then
  126.             ReportError1 L_errFailedToAuthenticate_ErrorMessage
  127.         End If
  128.     End If
  129.  
  130. End Sub
  131.  
  132. '=======================
  133. ' ClearSession
  134. ' Clears the session for a new logon
  135. '=======================
  136. Public Sub ClearSession
  137.  
  138.     On Error Resume Next
  139.  
  140.     ' Commented this out since as far as we know, strings don't need
  141.     ' to get freed in a specific security context, and we need to keep
  142.     ' this particular var around, so it can be used to redirect in MainLogon.
  143.     ' (raid 23673)
  144.     ' Set Session(bstrURLReq) = Nothing
  145.     'Get the cached dictionary object
  146.     Set objCacheID =  Session(bstrCacheObject)
  147.     'Ask the object for the array that contains the ID's for all the session objects
  148.     rgObjectIDs = objCacheID.Items
  149.     
  150.     
  151.     
  152.     For i = Lbound(rgObjectIDs) to Ubound(rgObjectIDs)
  153.         
  154.     
  155.         Set Session(rgObjectIDs(i)) = Nothing
  156.     Next
  157.       
  158.     
  159.     
  160.  
  161.  
  162.  
  163.  
  164.     Set Session(bstrRenderObject) = Nothing
  165.     Set Session(bstrRenderMessage) = Nothing
  166.     Set Session(bstrRenderFolder) = Nothing
  167.     Set Session(bstrRenderAddressContainer) = Nothing
  168.     Set Session(bstrRenderAddressEntry) = Nothing
  169.     Set Session(bstrRenderHierarchy) = Nothing
  170.     Set Session(bstrRenderRecipients) = Nothing
  171.     Set Session(bstrRenderCalendar) = Nothing
  172.     
  173.     ' Clear Format flags for HierarchyRenderer
  174.     Session("fPublicFormats") = False
  175.     Session("fPrivateFormats") = False
  176.  
  177.     Set Session(bstrObjPrivateStore) = Nothing
  178.     Set Session(bstrObjPublicStore) = Nothing
  179.     Set Session(bstrObjThisFolderLink) = Nothing
  180.     
  181.     Set Session(bstrPublicStoreID) = Nothing
  182.     Set Session(bstrPublicStoreEntryID) = Nothing
  183.     Set Session(bstrPublicStoreRootID) = Nothing
  184.     Set Session(bstrDeletedItemsID) = Nothing
  185.     
  186.     Set Session(CURRENT_FOLDER) = Nothing
  187.     Set Session(CURRENT_HIERARCHY) = Nothing
  188.     Set Session(CURRENT_CONTENTS) = Nothing
  189.     Set Session(CURRENT_INDEX) = Nothing
  190.     Set Session(CURRENT_COUNT) = Nothing
  191.     Set Session(CURRENT_PAGES) = Nothing
  192.     Set Session(CURRENT_ROWS) = Nothing
  193.     Set Session(CURRENT_VIEW) = Nothing
  194.     Set Session(CURRENT_PAGE) = Nothing
  195.     Set Session(CURRENT_MSG)  = Nothing
  196.  
  197.     If Not objOMSession Is Nothing Then
  198.         Set Session(bstrOMSession) = Nothing
  199.         objOMSession.Logoff
  200.     End If
  201.     hImp = Session("hImp")
  202.     If Not IsEmpty(hImp) Then
  203.         If hImp <> 0 Then
  204.             set objRenderApp = Application(bstrRenderApp)
  205.             set Session("hImp") = Nothing
  206.             objRenderApp.CloseSysHandle(hImp)
  207.         End If
  208.     End If
  209.  
  210.     Set Session(bstrAuthenticated) = Nothing
  211.  
  212. End Sub
  213.  
  214. '=======================
  215. ' ReportError*
  216. '
  217. ' Error handling functions
  218. '=======================
  219. Public Function ReportError2(bstrWhat, bstrErr)
  220.     DisplayError bstrWhat & bstrErr, 0, "" '= back once
  221. End Function
  222.  
  223. Public Function ReportError1(bstrErr)
  224.     DisplayError bstrErr, 0, "" '= back once
  225. End Function
  226.  
  227. Public Function ReportError3(bstrErr)
  228.     DisplayError bstrErr, 3, "" '= no back
  229. End Function
  230.  
  231. Public Function DisplayError(bstrErr, nAction, bstrLocation)
  232.     ' nAction:
  233.     '
  234.     ' 0: the function will navigate to the previous location in the history
  235.     ' 1: the current window is closed
  236.     ' 2: will go to bstrLocation after displaying error
  237.     ' 3: will display error and return (no redirect)
  238.  
  239.     ' Displays Active Messaging Error Descriptions if Debug Parameter
  240.     ' is set to one.
  241.     Dim bstrMessage
  242.     Dim objRenderer
  243.     Set objRenderer = Nothing
  244.     bstrMessage = bstrErr
  245.     Set objRenderApp = Application(bstrRenderApp)
  246.     If objRenderApp.ConfigParameter("Debug") = 1 Then
  247.         If Err.Number <> 0 Then
  248.             bstrMessage = bstrMessage & "\n\n" & Err.Description
  249.             bstrMessage = bstrMessage & "\n\n" & Request.ServerVariables("SCRIPT_NAME")
  250.         End If
  251.     End If
  252.  
  253.     Set objRenderer = objRenderApp.CreateRenderer(2)
  254.     objRenderer.CodePage = Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")
  255.     Session.CodePage = objRenderer.CodePage    'set the denali session codepage
  256.     
  257.     Response.write("<HTML>")
  258.     
  259.  
  260. %>
  261.     <body text=000000 link=black vlink=black onLoad="statusAlert()">
  262.     <script language="javascript">
  263.     function statusAlert() {
  264. <%
  265.     Set br = Request.ServerVariables("HTTP_USER_AGENT")
  266.  
  267.     If objRenderer Is Nothing Then
  268.     ' Can't get a rendering object, output error
  269.     ' without codepage conversion
  270.         If (isUNIX and isNav) Then %>
  271.             confirm("<%=bstrMessage%>");
  272.         <% Else %>
  273.             alert("<%=bstrMessage%>");
  274.         <% End If
  275.      Else
  276.      ' We have a rendering object, output error
  277.      ' with codepage conversion
  278.         If (isUNIX and isNav) Then %>
  279.             confirm("<%objRenderer.Write bstrMessage, Response%>");
  280.         <% Else %>
  281.             alert("<%objRenderer.Write bstrMessage, Response%>");
  282.         <% End If
  283.     End If
  284.  
  285.     If nAction = 0 Then %>
  286.             self.history.back();
  287. <%  ElseIf nAction = 2 Then %>
  288.             top.location = "<%=bstrLocation%>";
  289. <%  ElseIf nAction = 3 Then ' no redirect %>
  290. <%  Else %>
  291.             self.close();
  292. <%  End If %>
  293.    }
  294.    </script>
  295.    </body>
  296. <%
  297.     Response.write("</HTML>")
  298.     Set objRenderApp = Nothing
  299.     Set objRenderer = Nothing
  300.     Response.End
  301. End Function
  302.  
  303. Public Function ReportError
  304.     ReportError1 ""
  305. End Function
  306.  
  307. Public Function ReportErrorClose2(bstrWhat, bstrErr)
  308.     DisplayMessage bstrWhat & bstrErr, 1, "" '= Close window
  309. End Function
  310.  
  311. Public Function ReportErrorClose(bstrErr)
  312.     DisplayError bstrErr, 1, "" '= Close window
  313. End Function
  314.  
  315. Public Function ReportErrorLoad(bstrErr, bstrLocation)
  316.     DisplayError bstrErr, 2, bstrLocation '= go to location
  317. End Function
  318.  
  319. Public Function SetPageDefaults
  320.     Session(CURRENT_INDEX) = 1
  321.     Session(CURRENT_COUNT) = 0
  322.     Session(CURRENT_PAGES) = 1
  323.     Session(CURRENT_ROWS) = iDefaultNumRows
  324.     Session(CURRENT_VIEW) = 1
  325.     Session(CURRENT_PAGE) = 1
  326. End Function
  327.  
  328. Public Function isWin16
  329.     Set br = Request.ServerVariables("HTTP_USER_AGENT")
  330.     if (instr(br, "Win") <> 0) Then
  331.         isWin16 = (instr(br, "3.1") <> 0) OR  (instr(br, "16") <> 0)
  332.     else
  333.         isWin16 = false
  334.     End If
  335. End Function
  336.  
  337. Public Function isWin32
  338.     Set br = Request.ServerVariables("HTTP_USER_AGENT")
  339.     If (instr(br, "Win") <> 0) Then
  340.         isWin32 = (instr(br, "95") <> 0) OR  (instr(br, "NT") <> 0)
  341.     Else
  342.         isWin32 = false
  343.     End If
  344. End Function
  345.  
  346. Public Function isMac
  347.     Set br = Request.ServerVariables("HTTP_USER_AGENT")
  348.     isMac = instr(br, "Mac")
  349. End Function
  350.  
  351. 'returns ver 3 or 4 if success or 1 if ver unknown
  352. 'returns 0 on fail
  353. Public Function isSun 
  354.     'Mozilla/4.02 [en] (X11;I;SunOS 5.5.1 sun4u)
  355.     Set br = Request.ServerVariables("HTTP_USER_AGENT")
  356.     if instr(br, "Sun") then
  357.         if instr(br,"4.0") then
  358.             isSun=4
  359.         elseif instr(br,"3.0") then
  360.             isSun=3
  361.         else
  362.             isSun=1
  363.         end if
  364.     else
  365.         isSun=0
  366.     end if
  367. End Function
  368.  
  369. Public Function isUNIX
  370.     Set br = Request.ServerVariables("HTTP_USER_AGENT")
  371.     isUNIX = ((instr(br, "Win") = 0) AND (instr(br, "Mac") = 0))
  372. End Function
  373.  
  374. Public Function isMSIE
  375.     Set br = Request.ServerVariables("HTTP_USER_AGENT")
  376.     isMSIE = instr(br, "MSIE")
  377. End Function
  378.  
  379. Public Function isNav
  380.     Set br = Request.ServerVariables("HTTP_USER_AGENT")
  381.     isNav = (instr(br, "MSIE") = 0)
  382. End Function
  383.  
  384. Function isAttachSupported()
  385.     If getVersion() >= 3.02 or isNav() or isMac() Then
  386.        isAttachSupported=true
  387.     Else
  388.        isAttachSupported=false
  389.     End If
  390. End Function
  391.  
  392. Function getVersion()
  393.     ' What browser requested this page?
  394.     set szClient = Request.ServerVariables("HTTP_USER_AGENT")
  395.  
  396.     ' Are we using Microsoft Internet Explorer?
  397.     nPos = Instr(szClient, "MSIE")
  398.  
  399.     ' Strip everything left of the major version #
  400.     if (nPos <> 0) then      
  401.         ' MSIE Agents are of the form "Mozilla/#.# (compatable; MSIE M.m; Platform)" 
  402.         szVersion = Right(szClient, len(szClient) - nPos - len("MSIE")) 
  403.       else
  404.         ' NS Nav Agents are of the form "Mozilla/M.m (Platform; I; Processor)" 
  405.         szVersion = Right(szClient, len(szClient) - len("Mozilla/"))
  406.     end if
  407.  
  408.     ' Get the major version #
  409.     nPos = Instr(szVersion, ".")
  410.     szMajor = Left(szVersion, nPos - 1)
  411.  
  412.     ' Get the minor version #
  413.     nPos = Instr(szVersion, ".")
  414.     for nPos2=nPos+1 to len(szVersion)
  415.         a = asc(Mid(szVersion, nPos2, 1)) 
  416.         if  (a < asc("0")) OR (a > asc("9")) Then
  417.             Exit For
  418.         end if
  419.     Next 
  420.     szMinor = Mid(szVersion, nPos+1, nPos2 - nPos - 1)
  421.  
  422.     ' If your browser is version 3.x or higher, your supported
  423.     getVersion =  CSng(szMinor) / (10 ^ Len(szMinor)) + CSng(szMajor)
  424. End Function
  425.  
  426. Sub SendHeader (nSensitive, nForm)
  427.     'nSensitive
  428.     ' 0: not sensitive
  429.     ' 1: contains sensitive info
  430.     'nForm
  431.     ' 0: no form on page
  432.     ' 1: form on page
  433.     If isMSIE Then
  434.        If (nSensitive <> 0) Then
  435.           Response.AddHeader "pragma", "no-cache"
  436.        End If
  437.        If (nForm <> 0) Then
  438.           Response.Expires=0
  439.        End If
  440.     End IF
  441. End Sub
  442.  
  443. Public Function IsEXAddress(strAddress)
  444.     If InStr(strAddress, "EX:") = 1 Then
  445.         IsEXAddress = True
  446.     Else
  447.         IsEXAddress = False
  448.     End If
  449. End Function
  450.  
  451. Public Sub GetSMTPAddress(objAddressEntry, ByRef strAddress)
  452.     strAddress = ""
  453.  
  454.     If Not objAddressEntry Is Nothing Then
  455.         astrAddresses = objAddressEntry.Fields.Item(ActMsgPR_EMS_AB_PROXY_ADDRESSES)
  456.         cAddresses = UBound(astrAddresses)
  457.         For iAddress = LBound(astrAddresses) To cAddresses
  458.             strTempAddress = astrAddresses(iAddress)
  459.             If (InStr(strTempAddress, "SMTP:") = 1) Then
  460.                 strAddress = strTempAddress
  461.                 Exit For
  462.             End If
  463.         Next
  464.     End If
  465. End Sub
  466.  
  467. Public Function EscapeAddresses(str)
  468.     Dim startpos
  469.     Dim endpos
  470.     Dim cBrackets
  471.     Dim strlen
  472.     Dim done
  473.     Dim item
  474.     Dim ch
  475.     Dim prevch
  476.     Dim nextch
  477.     Dim i
  478.     Dim newstr
  479.  
  480.     startpos  = 1
  481.     endpos    = 1
  482.     cBrackets = 0
  483.     strlen    = Len(str)
  484.     done      = False
  485.  
  486.     Do While endpos <= strlen
  487.         cBrackets = 0
  488.         done      = False
  489.  
  490.         Do While done = False
  491.             If Mid(str, endpos, 1) = "[" Then
  492.                 cBrackets = cBrackets + 1
  493.             End If
  494.  
  495.             If Mid(str, endpos, 1) = "]" Then
  496.                 cBrackets = cBrackets - 1
  497.             End If
  498.  
  499.             If (((Mid(str, endpos, 1) = ";") And (cBrackets = 0)) Or (endpos = strlen)) Then
  500.                 done = True
  501.                 Exit Do
  502.             End If
  503.  
  504.             endpos = endpos + 1
  505.         Loop
  506.  
  507.         item   = Mid(str, startpos, endpos - startpos + 1)
  508.  
  509.         If InStr(item, "[") > 0 Then
  510.  
  511.             item   = ""
  512.             ch     = ""
  513.             prevch = ""
  514.             nextch = ""
  515.  
  516.             i = 0
  517.         
  518.             For i = startpos To endpos
  519.                 ch     = Mid(str, i, 1)
  520.                 nextch = Mid(str, i+1, 1)
  521.  
  522.                 If (ch = ":") And (prevch <> "\") Then
  523.                     ch = "\:"
  524.                 End If
  525.  
  526.                 If (ch = "]") And (prevch <> "\") Then
  527.                     ch = "\]"
  528.                 End If
  529.  
  530.                 If (ch = "\") And (prevch <> "\") And (InStr("[:]\", nextch) = 0) Then
  531.                     ch = "\\"
  532.                 End If
  533.  
  534.                 item = item + ch
  535.  
  536.                 If ch = "[" Then
  537.                 Exit For
  538.                 End If
  539.  
  540.                 prevch = Mid(str, i, 1)
  541.             Next
  542.  
  543.             ch       = ""
  544.             prevch   = ""
  545.             nextch   = ""
  546.             startpos = i + 1
  547.                 
  548.             For i = startpos To endpos
  549.                 ch     = Mid(str, i, 1)
  550.                 nextch = Mid(str, i+1, 1)
  551.  
  552.                 If (ch = "[") And (prevch <> "\") Then
  553.                     ch = "\["
  554.                 End If
  555.  
  556.                 If (ch = "]") And (prevch <> "\") Then
  557.                     ch = "\]"
  558.                 End If
  559.  
  560.                 If (ch = "\") And (prevch <> "\") And (InStr("[:]\", nextch) = 0) Then
  561.                     ch = "\\"
  562.                 End If
  563.  
  564.                 item = item + ch
  565.  
  566.                 If ch = ":" Then
  567.                     Exit For
  568.                 End If
  569.  
  570.                 prevch = Mid(str, i, 1)
  571.             Next
  572.  
  573.             ch       = ""
  574.             prevch   = ""
  575.             nextch   = ""
  576.             startpos = i + 1
  577.                 
  578.             For i = startpos To endpos
  579.                 ch     = Mid(str, i, 1)
  580.                 nextch = Mid(str, i+1, 1)
  581.  
  582.                 If (ch = "[") And (prevch <> "\") Then
  583.                     ch = "\["
  584.                 End If
  585.  
  586.                 If (ch = ":") And (prevch <> "\") Then
  587.                     ch = "\:"
  588.                 End If
  589.  
  590.                 If (ch = "\") And (prevch <> "\") And (InStr("[:]\", nextch) = 0) Then
  591.                     ch = "\\"
  592.                 End If
  593.  
  594.                 item = item + ch
  595.  
  596.                 If ch = "]" Then
  597.                     Exit For
  598.                 End If
  599.  
  600.                 prevch = Mid(str, i, 1)
  601.             Next
  602.  
  603.             startpos = i + 1
  604.  
  605.             For i = startpos To endpos
  606.                 ch   = Mid(str, i, 1)
  607.                 item = item + ch
  608.             Next
  609.         End If
  610.  
  611.         newstr = newstr + item
  612.  
  613.         startpos  = endpos + 1
  614.         endpos    = startpos
  615.         cBrackets = 0
  616.     Loop
  617.  
  618.     EscapeAddresses = newstr
  619. End Function
  620.  
  621. Public Sub AddIDToCache(bstrObjID)
  622.     On Error Resume Next
  623.     Set objCacheID =  Session(bstrCacheObject)
  624.     objCacheID.Add bstrObjID, bstrObjID
  625.     Set Session(bstrCacheObject) = objCacheID
  626. End Sub
  627.  
  628. Public Sub RemoveIDFromCache(bstrObjID)
  629.     On Error Resume Next
  630.     Set objCacheID =  Session(bstrCacheObject)
  631.     objCacheID.Remove bstrObjID    
  632.     Set Session(bstrCacheObject) = objCacheID
  633. End Sub
  634.  
  635. Public Function BStringToJString(bstrString)
  636.     On Error Resume Next
  637.     bstrString = Replace(bstrString, "\", "\\")
  638.     bstrString = Replace(bstrString, " ", "\ ")
  639.     bstrString = Replace(bstrString, """", "\""")
  640.     bstrString = Replace(bstrString, "&", "&")
  641.     bstrString = Replace(bstrString, "<", "<")
  642.     bstrString = Replace(bstrString, ">", ">")
  643.     BStringToJString =  bstrString
  644. End Function
  645.  
  646.  
  647. %>
  648.