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.

133 lines
4.4 KiB

  1. <%@ Language=VBScript %>
  2. <% Option Explicit %>
  3. <%
  4. '-------------------------------------------------------------------------
  5. ' log_view.asp: to view the log file through the iframe
  6. '
  7. ' NOTE: This is a customized page written to take care of the "Viewing"
  8. ' of the log(text) files in the IFrame.
  9. ' This is not the types of the pages(area, property, etc) of the framework.
  10. ' Hence, the events applicable to those is not used here.
  11. '
  12. ' Copyright (c) Microsoft Corporation. All rights reserved.
  13. '-------------------------------------------------------------------------
  14. %>
  15. <meta http-equiv="Content-Type" content="text/html; charset=<%=GetCharSet()%>">
  16. <!-- #include virtual="/admin/inc_framework.asp" -->
  17. <!-- #include file="loc_Log.asp" -->
  18. <%
  19. Dim G_FileToView ' the file be displayed in the IFrame
  20. Dim strFileError ' to capture any file related error that occurs
  21. ' Get the File to be displayed through the Query String
  22. G_FileToView = Request.QueryString("FileToView")
  23. If Len(Trim(G_FileToView)) <=0 Then
  24. ' error occuerd. Display message and end response
  25. Call ShowErrorMessageAndExit(L_NOLOGSAVAILABLE_TEXT)
  26. End If
  27. ' Call the function to display the file contents.
  28. ' The function returns "" <empty> string if no error occurs
  29. ' In case of error, the error message is returned
  30. strFileError = WriteFileData(G_FileToView)
  31. If ((Err.number <> 0) OR (Len(Trim(strFileError)) > 0 ))Then
  32. ' error occuerd. Display message and end response
  33. Call ShowErrorMessageAndExit(strFileError)
  34. End If
  35. '-------------------------------------------------------------------------
  36. ' Function name: WriteFileData
  37. ' Description: Serves in Writing the file content
  38. ' Input Variables: strFilePath
  39. ' Output Variables: None
  40. ' Returns: Empty string if success, Error Message in case of any error
  41. 'Writes the log file content in the IFrame
  42. '-------------------------------------------------------------------------
  43. Function WriteFileData(strFilePath)
  44. On Error Resume Next
  45. Err.Clear
  46. Dim objFso ' the file system object
  47. Dim objFile ' the File object
  48. Dim strFileData ' the file data
  49. Dim oEncoder
  50. Set oEncoder = new CSAEncoder
  51. ' create the FSO
  52. Set objFso = CreateObject("Scripting.FileSystemObject")
  53. If Err.number <> 0 Then
  54. WriteFileData = L_FSO_OBJECTCREATE_ERRORMESSAGE
  55. Call SA_TraceOut(SA_GetScriptFileName(), "CreateObject(Scripting.FileSystemObject) error: " & Hex(Err.Numer) & " " & Err.Description)
  56. Err.Clear
  57. Exit Function
  58. End If
  59. 'checking for the file existence
  60. If NOT (objFso.FileExists(strFilePath)) Then
  61. ' file does not exist
  62. WriteFileData = L_NOLOGSAVAILABLE_TEXT
  63. Call SA_TraceOut(SA_GetScriptFileName(), "File " & strFilePath & " does not exist.")
  64. Err.Clear
  65. Exit Function
  66. End IF
  67. ' open the file
  68. Set objFile=objFso.OpenTextFile(strFilePath)
  69. If Err.number <> 0 Then
  70. ' error occured
  71. WriteFileData = L_FILEERROR_ERRORMESSAGE
  72. Call SA_TraceOut(SA_GetScriptFileName(), "OpenTextFile(" & strFilePath & ") error: " & Hex(Err.Numer) & " " & Err.Description)
  73. Err.Clear
  74. Exit Function
  75. End If
  76. ' loop till EOF
  77. While NOT objFile.AtEndofStream
  78. Response.Write( oEncoder.EncodeElement(objFile.ReadLine) & "<br>" )
  79. Wend
  80. If Err.number <> 0 Then
  81. ' error occured
  82. WriteFileData = L_FILEERROR_ERRORMESSAGE
  83. Call SA_TraceOut(SA_GetScriptFileName(), "File I/O Error reading file " & strFilePath & " Error: " & Hex(Err.Numer) & " " & Err.Description)
  84. Err.Clear
  85. Exit Function
  86. End If
  87. 'Clean up
  88. Set objFile = Nothing
  89. Set objFso = Nothing
  90. Set oEncoder = Nothing
  91. ' Success, return <empty> string
  92. WriteFileData = ""
  93. End function
  94. '-------------------------------------------------------------------------
  95. ' Function name: ShowErrorMessageAndExit
  96. ' Description: Serves in displaying the message and terminating the Response
  97. ' Input Variables: strMessage - the message to be displayed
  98. ' Output Variables: None
  99. ' Returns: None
  100. 'Displays the message and quits
  101. '-------------------------------------------------------------------------
  102. Sub ShowErrorMessageAndExit(strMessage)
  103. On Error Resume Next
  104. Err.Clear
  105. Dim oEncoder
  106. oEncoder = new CSAEncoder
  107. ' display the message
  108. Response.Write( oEncoder.EncodeElement(strMessage))
  109. Set oEncoder = Nothing
  110. ' terminate the response
  111. Response.End
  112. End Sub
  113. %>