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.

213 lines
6.5 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. Dim F_strFile 'File name with file path
  21. Dim F_strFileName 'File name to be prompted for download - Example: nfssvr.txt
  22. Dim F_strDownloadClick 'variable to get selected radio button value
  23. Dim blnFlagIE
  24. F_strDownloadClick = Request.Form("downloadclicked")
  25. If SA_IsIE = True Then
  26. blnFlagIE = True
  27. End If
  28. 'select case for download
  29. Select Case F_strDownloadClick
  30. Case "True"
  31. Call DownLoadLog()
  32. case else
  33. Call ServePage()
  34. End Select
  35. '---------------------------------------------------------------------
  36. ' Function name: DownLoadLog
  37. ' Description: Downloads the file
  38. ' Input Variables: None
  39. ' Output Variables: None
  40. ' Return Values: None
  41. ' Global Variables: F_strFileName,F_strFile,L_LOGFILE_NOTFOUND_ERRORMESSAGE
  42. 'Called to read the total content of the file and output it.
  43. 'Due to the headers, the "download" dialog appears
  44. '---------------------------------------------------------------------
  45. Function DownLoadLog()
  46. On error resume next
  47. Err.Clear
  48. 'File name(along with the path) that is obtained from earlier form
  49. F_strFile = Request.QueryString("FilePath")
  50. F_strFileName = Mid(F_strFile,instrRev(F_strFile, "\") + 1)
  51. 'Check if the file is existing
  52. If Not (isFileExisting(F_strFile)) Then
  53. 'File is moved/deleted/renamed. Display failure page
  54. Call SA_TraceOut("Text_Log_Download.asp", "File does not exist.")
  55. Exit function
  56. End If
  57. 'Call to output the log file
  58. If not ReadDisplayFileContent(F_strFile,F_strFileName) then
  59. Exit function
  60. End if
  61. End function
  62. '---------------------------------------------------------------------
  63. ' Function name: ReadDisplayFileContent
  64. ' Description: To Read and Output the contents of the file
  65. ' Input Variables: The file to be read and displayed
  66. ' Output Variables: None
  67. ' Return Values: None
  68. ' Global Variables: None
  69. 'Called to read the total content of the file and output it.
  70. 'For Netscape the headers are not added location.href is used
  71. 'Due to the headers, the "download" dialog appears
  72. '---------------------------------------------------------------------
  73. Function ReadDisplayFileContent(strFilePath , strFileName)
  74. On error resume next
  75. Err.Clear
  76. Dim objFSO
  77. Dim objFile ' the File to be read
  78. Dim strTemp
  79. Dim strLogPath
  80. Dim strDownloadFile
  81. const TempDir = "TempFiles" ' A Temporary directory in web directory
  82. const LogDir = "LogFiles" ' A logs directory in Temporary directory
  83. const strON = "On"
  84. Dim oEncoder
  85. Set oEncoder = new CSAEncoder
  86. ReadDisplayFileContent = true
  87. ' Add headers to download the log file
  88. Call SA_TraceOut("Text_Log_Download.asp", "strFileName: " + strFileName)
  89. Call SA_TraceOut("Text_Log_Download.asp", "strFilePath: " + strFilePath)
  90. Set objFSO = CreateObject("Scripting.FileSystemObject")
  91. If Err.number <> 0 then
  92. ReadDisplayFileContent = false
  93. Exit function
  94. End If
  95. If blnFlagIE = True then
  96. Set objFile = objFSO.OpenTextFile(strFilePath, 1)
  97. 'Read the contents of the file
  98. If not objFile.AtEndOfStream Then strTemp = objFile.readall End IF
  99. objFile.Close
  100. Set objFile = Nothing
  101. ' Add headers for text log download
  102. Response.AddHeader "Content-Type", "text/plain"
  103. Response.AddHeader "Content-Disposition", "attachment; filename=" & strFileName
  104. 'Clear any previous buffered output
  105. Response.Clear
  106. 'Output it for download
  107. Response.Write(oEncoder.EncodeElement(strTemp))
  108. Response.Flush
  109. Else
  110. strLogPath = GetLogsDirectoryPath(objFSO)
  111. If objFSO.FileExists(strLogPath& "\" &strFileName) then
  112. objFSO.DeleteFile strLogPath& "\" &strFileName,True
  113. End If
  114. ' Copying from log's original directory to web root
  115. If objFSO.FileExists(strFilePath) Then
  116. objFSO.CopyFile strFilePath, strLogPath& "\" ,True
  117. End If
  118. 'Clean up
  119. Set objFSO = Nothing
  120. strDownloadFile = SA_GetNewHostURLBase(SA_DEFAULT, SAI_GetSecurePort(), True, SA_DEFAULT)
  121. strDownloadFile = strDownloadFile & TempDir &"/" &LogDir &"/" & strFileName
  122. Call SA_TraceOut("SINGLELOGS" , "log file=" & strDownloadFile)
  123. Call ServePage()
  124. %>
  125. <script language="javascript">
  126. top.location.href = '<%=strDownloadFile%>';
  127. </script>
  128. <%
  129. End If
  130. Set oEncoder = Nothing
  131. Set objFSO = Nothing
  132. End function
  133. '---------------------------------------------------------------------
  134. ' Function name: ServePage
  135. ' Description: Serve the contents to the page
  136. ' Input Variables: None
  137. ' Output Variables: None
  138. ' Return Values: None
  139. ' Global Variables: None
  140. ' Submit(Download) button is displayed and on click of it the download
  141. ' Functionality is processed
  142. '---------------------------------------------------------------------
  143. Sub ServePage
  144. %>
  145. <html>
  146. <head>
  147. <link rel="STYLESHEET" type="text/css" href="<%=m_VirtualRoot%>style/mssastyles.css">
  148. </head>
  149. <body>
  150. <form id=sa_formdownload name=sa_formdownload method="POST" target="_self">
  151. <input name="<%=SAI_FLD_PAGEKEY%>" type="hidden" value="<%=SAI_GetPageKey()%>">
  152. <table border="0" cellspacing="0" cellpadding="0">
  153. <tr>
  154. <td class="TasksBody">
  155. <%
  156. Call SA_ServeOnClickButton(SA_EscapeQuotes(Trim(L_DOWNLOAD_TEXT)), "",_
  157. "SubmitLog()",_
  158. 90,"", "" )
  159. %>
  160. <input type=hidden name=downloadclicked id=downloadclicked value="">
  161. </td>
  162. </tr>
  163. </table>
  164. </form>
  165. </body>
  166. </html>
  167. <script language="JavaScript">
  168. function SubmitLog()
  169. {
  170. var oException;
  171. try
  172. {
  173. document.sa_formdownload.downloadclicked.value = "True";
  174. document.sa_formdownload.submit();
  175. }
  176. catch(oException)
  177. {
  178. }
  179. }
  180. </script>
  181. <%
  182. End Sub
  183. %>