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.

185 lines
6.4 KiB

  1. <%@ Language=VBScript %>
  2. <% Option Explicit %>
  3. <% Response.Buffer = True
  4. '-------------------------------------------------------------------------
  5. ' Text_log_download.asp: to download the log files of type text
  6. '
  7. ' NOTE: This is a customized page written to take care of the "Downloading"
  8. ' of the log(text) files.
  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. Call SAI_EnablePageCaching(TRUE)
  15. %>
  16. <!-- #include virtual="/admin/inc_framework.asp" -->
  17. <!-- #include file="loc_Log.asp" -->
  18. <!-- #include file="inc_Log.asp" -->
  19. <%
  20. '-------------------------------------------------------------------------
  21. ' Form Variables
  22. '-------------------------------------------------------------------------
  23. Dim F_strFilePath 'Name of the file to be downloaded 'Example: "C:\SFU\Log\"
  24. Dim F_strFileName 'File name to be prompted for download - Example: nfssvr.txt
  25. '-------------------------------------------------------------------------
  26. ' Global Variables
  27. '-------------------------------------------------------------------------
  28. Dim G_strBrowserVersion 'variable for getting the client config
  29. Dim G_nBrowserVersion 'variable to locate the positin occurence of Browser version string
  30. Dim blnFlagIE
  31. dim rc
  32. dim page
  33. dim L_LOGS_TEXT
  34. L_LOGS_TEXT = "Logs"
  35. If SA_IsIE = True Then
  36. blnFlagIE = True
  37. End If
  38. Call SA_CreatePage(L_LOGS_TEXT,"", PT_PAGELET, page)
  39. Call SA_ShowPage(page)
  40. '---------------------------------------------------------------------
  41. ' Function name: OnInitPage
  42. ' Description: Called to signal first time processing for this page.
  43. ' Input Variables: PageIn and EventArg
  44. ' Output Variables: PageIn and EventArg
  45. ' Return Values: TRUE to indicate initialization was successful. FALSE to indicate
  46. ' errors. Returning FALSE will cause the page to be abandoned.
  47. ' Global Variables: None
  48. ' Called to signal first time processing for this page.
  49. '---------------------------------------------------------------------
  50. Public Function OnInitPage(ByRef Page, ByRef Reserved)
  51. OnInitPage = TRUE
  52. End Function
  53. '---------------------------------------------------------------------
  54. ' Function name: OnServePageletPage
  55. ' Description: Called when the page needs to be served.
  56. ' Input Variables: PageIn, Reserved
  57. ' Output Variables: PageIn, Reserved
  58. ' Return Values: TRUE to indicate no problems occured. FALSE to indicate errors.
  59. ' Returning FALSE will cause the page to be abandoned.
  60. ' Global Variables: F_*
  61. 'Called when the page needs to be served. Use this method to serve content.
  62. '---------------------------------------------------------------------
  63. Public Function OnServePageletPage(ByRef Page, ByRef Reserved)
  64. OnServePageletPage = TRUE
  65. Call SA_ServeDefaultClientScript()
  66. 'frame work variables used for getting the selected ots entries
  67. Dim x
  68. Dim itemCount
  69. Dim itemKey
  70. 'File name(along with the path) that is obtained from earlier form
  71. F_strFilePath = Request.QueryString("FilePath")
  72. ' get the file to be deleted as Query String from previous page
  73. If Instr(1,Request.QueryString(),"Single",1) then
  74. F_strFileName = Request.QueryString("Pkey")
  75. Else
  76. ' Show a list of the items selected
  77. itemCount = OTS_GetTableSelectionCount("")
  78. For x = 1 to itemCount
  79. If ( OTS_GetTableSelection("", x, itemKey) ) Then
  80. F_strFileName = itemKey
  81. End If
  82. Next
  83. End if
  84. 'Check if the file is existing
  85. If Not (isFileExisting(F_strFilePath & "\" & F_strFileName)) Then
  86. 'File is moved/deleted/renamed. Display failure page
  87. Call SA_ServeFailurePage (L_LOGFILE_NOTFOUND_ERRORMESSAGE)
  88. End If
  89. 'Call to output the log file
  90. Call DispalyFileContent(F_strFilePath,F_strFileName)
  91. End Function
  92. '---------------------------------------------------------------------
  93. ' Function name: DispalyFileContent
  94. ' Description: To Read and Output the contents of the file
  95. ' Input Variables: The file to be read and displayed
  96. ' Output Variables: None
  97. ' Return Values: None
  98. ' Global Variables: None
  99. 'Called to read the total content of the file and output it.
  100. 'For Netscape the headers are not added location.href is used
  101. 'Due to the headers, the "download" dialog appears
  102. '---------------------------------------------------------------------
  103. Sub DispalyFileContent(strFilePath , strFileName)
  104. Err.clear
  105. On Error Resume Next
  106. Dim objFSO ' the File System Object
  107. Dim objFile ' the File to be read
  108. Dim strTemp,strTotalFileName
  109. Dim strLogPath
  110. Dim strDownloadFile
  111. const TempDir = "TempFiles" ' A Temporary directory in web directory
  112. const LogDir = "LogFiles" ' A logs directory in Temporary directory
  113. const strON = "On"
  114. strTotalFileName=strFilePath & "\" & strFileName
  115. Set objFSO = CreateObject("Scripting.FileSystemObject")
  116. If blnFlagIE = True then
  117. Set objFile = objFSO.OpenTextFile(strTotalFileName, 1, False)
  118. 'Read the contents of the file
  119. If not objFile.AtEndOfStream Then strTemp = objFile.readall End IF
  120. ' Add headers required for download
  121. Response.AddHeader "Content-Type", "text/plain"
  122. Response.AddHeader "Content-Disposition", "attachment; filename=" & F_strFileName
  123. 'Clear any previous buffered output
  124. Response.Clear
  125. 'Output it for download
  126. Response.Write strTemp
  127. objFile.Close
  128. Response.End
  129. Else
  130. strLogPath = GetLogsDirectoryPath(objFSO)
  131. If objFSO.FileExists(strLogPath& "\" &strFileName) then
  132. objFSO.DeleteFile strLogPath& "\" &strFileName,True
  133. End If
  134. ' Copying from log's original directory to web root
  135. If objFSO.FileExists(strTotalFileName) Then
  136. objFSO.CopyFile strTotalFileName, strLogPath& "\" ,True
  137. End If
  138. 'Clean up
  139. Set objFile = Nothing
  140. Set objFSO = Nothing
  141. strDownloadFile = SA_GetNewHostURLBase(SA_DEFAULT, SAI_GetSecurePort(), True, SA_DEFAULT)
  142. strDownloadFile = strDownloadFile & TempDir &"/" &LogDir &"/" & strFileName
  143. Call SA_TraceOut(SA_GetScriptFileName, "Redirect to URL: " & strDownloadFile)
  144. Response.Redirect strDownloadFile
  145. End If
  146. End Sub
  147. %>