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.

394 lines
17 KiB

  1. <%@ Language=VBScript %>
  2. <% Option Explicit %>
  3. <% '-------------------------------------------------------------------------
  4. ' Log_downloadView.asp : This page displays a special framework window to download logs
  5. ' Copyright (c) Microsoft Corporation. All rights reserved.
  6. '-------------------------------------------------------------------------
  7. Call SAI_EnablePageCaching(TRUE)
  8. %>
  9. <!-- #include virtual="/admin/inc_framework.asp" -->
  10. <!-- #include file="loc_event.asp" -->
  11. <!-- #include file="inc_log.asp" -->
  12. <%
  13. Dim F_strRadSelected 'variable to get selected radio button value
  14. Dim F_strEventName 'variable to store eventlog name
  15. Dim F_strVirtualRoot 'variable to store virtual root directory path
  16. Dim F_strDownloadFile 'download fiel URL
  17. Dim F_blnAddHeaders 'variable to determine the state Addheaders
  18. Dim arrBtntxt(1)
  19. Const G_wbemPrivilegeSecurity=7 'Prilivilege constant
  20. F_strEventName = Request.QueryString("Title")
  21. F_strRadSelected = Request.Form("hdnstrfiletype")
  22. Call SA_TraceOut("Log_DownloadView.asp", "F_strRadSelected: " + F_strRadSelected)
  23. Select Case Lcase(F_strRadSelected)
  24. Case Lcase("Tabdelimitedtextfile"), Lcase("Commadelimitedtextfile")
  25. Call getLogEventsTxtCsv()
  26. Case Lcase("Windowseventlogfile")
  27. Call getLogEventsEvt()
  28. Case Else
  29. Call ServePage()
  30. Response.Write "<Script language=javascript>document.sa_formdownload.hdnstrfiletype.value = 'Windowseventlogfile' ;</script>"
  31. End Select
  32. '-------------------------------------------------------------------------
  33. 'Sub: ServePage()
  34. 'Description: For displaying outputs HTML to the user
  35. 'Input Variables: None
  36. 'Output Variables: None
  37. 'Returns: Nothing
  38. 'Global Variables: F_strRadSelected,L_WINDOWSEVENT_TEXT,L_TABDELIMITED_TEXT
  39. ' L_COMMADELIMITED_TEXT,F_strEventName,F_strRadValue
  40. '-------------------------------------------------------------------------
  41. Sub ServePage
  42. %>
  43. <html>
  44. <head>
  45. <link rel="STYLESHEET" type="text/css" href="/admin/style/mssastyles.css">
  46. <script language=javascript>
  47. function UpdateHiddenSelect()
  48. {
  49. var strradno;
  50. var count;
  51. strradno = sa_formdownload.rdoLogfile.length;
  52. //to retain the value of selected radio button
  53. for (count=0; count < strradno; count++)
  54. {
  55. if ((sa_formdownload.rdoLogfile[count].checked)== true)
  56. {
  57. sa_formdownload.hdnstrfiletype.value = sa_formdownload.rdoLogfile[count].value;
  58. }
  59. }
  60. }
  61. </script>
  62. </head>
  63. <body onload="UpdateHiddenSelect()">
  64. <form id=sa_formdownload name=sa_formdownload method="POST" target="_self">
  65. <input name="<%=SAI_FLD_PAGEKEY%>" type="hidden" value="<%=SAI_GetPageKey()%>">
  66. <table width=518 border=0 cellspacing=0 cellpadding=2 >
  67. <tr>
  68. <td class="TasksBody" colspan=2><%=L_PAGEDESCRIPTION_DOWNLOAD_TEXT%></td>
  69. </tr>
  70. <tr>
  71. <td class="TasksBody" colspan=2>&nbsp;</td>
  72. </tr>
  73. <tr>
  74. <td class="TasksBody" >&nbsp;</td>
  75. <td class="TasksBody" >
  76. <% If lcase(F_strRadSelected) = lcase("Windowseventlogfile") or F_strRadSelected = "" then%>
  77. <input type=Radio name='rdoLogfile' value='Windowseventlogfile' checked
  78. class="FormRadioButton" onClick="sa_formdownload.hdnstrfiletype.value = this.value;" >
  79. <% else %>
  80. <input type=Radio name='rdoLogfile' value='Windowseventlogfile'
  81. class="FormRadioButton" onClick="sa_formdownload.hdnstrfiletype.value = this.value;">
  82. <% End if %>
  83. <%=L_WINDOWSEVENT_TEXT%>
  84. </td>
  85. </tr>
  86. <tr>
  87. <td class="TasksBody" >&nbsp;</td>
  88. <td class="TasksBody" ><% If lcase(F_strRadSelected) = lcase("Tabdelimitedtextfile") then%>
  89. <input type=Radio name='rdoLogfile' value='Tabdelimitedtextfile' checked
  90. onclick="sa_formdownload.hdnstrfiletype.value = this.value;" >
  91. <% else %>
  92. <input type=Radio name='rdoLogfile' value='Tabdelimitedtextfile'
  93. onclick="sa_formdownload.hdnstrfiletype.value = this.value;">
  94. <% End if %>
  95. <%=L_TABDELIMITED_TEXT%>
  96. </td>
  97. </tr>
  98. <tr>
  99. <td class="TasksBody" >&nbsp;</td>
  100. <td class="TasksBody">
  101. <% If lcase(F_strRadSelected) = lcase("Commadelimitedtextfile") then%>
  102. <input type=Radio name='rdoLogfile' value='Commadelimitedtextfile' checked
  103. onclick="sa_formdownload.hdnstrfiletype.value = this.value;" >
  104. <% else %>
  105. <input type=Radio name='rdoLogfile' value='Commadelimitedtextfile'
  106. onclick="sa_formdownload.hdnstrfiletype.value = this.value;">
  107. <% End if %>
  108. <%=L_COMMADELIMITED_TEXT%>
  109. </td>
  110. </tr>
  111. <tr>
  112. <td class="TasksBody" >
  113. </td>
  114. <td class="TasksBody" >
  115. <input type=submit name=submitlog value="<%=L_DOWNLOAD_TEXT%>" class=TaskFrameButtons>
  116. <input type=hidden name=hdnstrfiletype id=hdnstrfiletype value='<%=F_strRadSelected%>'>
  117. </td>
  118. </tr>
  119. </table>
  120. </form>
  121. </body>
  122. </html>
  123. <%
  124. End Sub
  125. '-------------------------------------------------------------------------
  126. ' Function name: getLogEventsEvt
  127. ' Description: returns download URL for the logtype EVT
  128. ' Input Variables: None
  129. ' Output Variables: None
  130. ' Return Values: None
  131. ' Global Variables: L_WMISECURITY_ERRORMESSAGE,L_FILESYSTEMOBJECT_ERRORMESSAGE
  132. ' L_LOGDOWNLOAD_ERRORMESSAGE
  133. '-------------------------------------------------------------------------
  134. sub getLogEventsEvt()
  135. Err.clear
  136. On Error Resume Next
  137. Dim objWMIConnection 'wmiconnection object
  138. Dim objInstances 'for object instances
  139. Dim instance 'for looping instance
  140. Dim objErr 'temp variable
  141. Dim objFileSysObject 'filesystem object
  142. Dim strLogFile 'log filename
  143. Dim strLogPath 'log path
  144. Dim strEventFile 'event file name
  145. Dim strQuery 'query to wmi
  146. Dim strFileType 'type of the file for output
  147. Dim returnvalue 'temp variable
  148. Dim DirectoryPath
  149. const TempDir = "TempFiles" ' A Temporary directory in web directory
  150. const LogDir = "LogFiles" ' A logs directory in Temporary directory
  151. const wbemPrivilegeBackup = 16
  152. 'Trying to connect to the server
  153. set objWMIConnection = getWMIConnection(CONST_WMI_WIN32_NAMESPACE) 'Connecting to the server
  154. 'ERROR handling is done in the function itself
  155. objWMIConnection.Security_.Privileges.Add G_wbemPrivilegeSecurity 'giving the req privelages
  156. If Err.number <> 0 then
  157. SA_SetErrMsg L_WMISECURITY_ERRORMESSAGE
  158. Err.Clear
  159. Exit sub
  160. End If
  161. objWMIConnection.Security_.Privileges.Add wbemPrivilegeBackup 'giving the req privelages
  162. If Err.number <> 0 then
  163. SA_SetErrMsg L_WMISECURITY_ERRORMESSAGE
  164. Err.Clear
  165. Exit sub
  166. End If
  167. strLogPath = Server.MapPath(m_VirtualRoot)
  168. 'creating a filesystem object
  169. Set objFileSysObject = Server.CreateObject("SCripting.filesystemobject")
  170. If Err.number <> 0 then
  171. SA_SetErrMsg L_FILESYSTEMOBJECT_ERRORMESSAGE
  172. Err.Clear
  173. Exit sub
  174. End If
  175. strLogPath = GetLogsDirectoryPath(objFileSysObject)
  176. strLogFile = left(F_strEventName,3) & "Event.evt"
  177. strEventFile = strLogPath & "\" & strLogFile
  178. 'delete the file,if already exists
  179. if objFileSysObject.FileExists(strEventFile) then
  180. objFileSysObject.DeleteFile(strEventFile)
  181. end if
  182. strQuery = "Select * From Win32_NTEventlogFile where LogFileName='" & F_strEventName & "'"
  183. set objInstances= objWMIConnection.ExecQuery(strQuery)
  184. For Each instance in objInstances
  185. objErr = instance.BackupEventlog(strEventFile)
  186. Exit For
  187. Next
  188. DirectoryPath = m_VirtualRoot & TempDir & "/" & LogDir & "/" & strLogFile
  189. Response.Redirect DirectoryPath
  190. If Err.number <> 0 then
  191. SA_SetErrMsg L_LOGDOWNLOAD_ERRORMESSAGE
  192. Err.Clear
  193. Exit sub
  194. End If
  195. Set objWMIConnection = Nothing
  196. Set objInstances = Nothing
  197. Set objFileSysObject = Nothing
  198. End sub
  199. '-------------------------------------------------------------------------
  200. ' Function name: getLogEventsTxtCsv
  201. ' Description: Gets the logevents into the file of CSV type
  202. ' Input Variables: None
  203. ' Output Variables: None
  204. ' Return Values: None
  205. ' Global Variables: L_GETTINGLOGINSTANCES_ERRORMESSAGE,L_FILESYSTEMOBJECT_ERRORMESSAGE
  206. '-------------------------------------------------------------------------
  207. sub getLogEventsTxtCsv()
  208. On Error Resume Next
  209. Err.Clear
  210. Dim objWMIConnection 'wmiconnection object
  211. Dim objInstances 'for object instances
  212. Dim objLognames 'name of the logs
  213. Dim objInstance 'instances of the queried object
  214. Dim instance 'for looping instance
  215. Dim objErr 'temp variable
  216. Dim strLogFile 'log filename
  217. Dim strQuery 'query to wmi
  218. Dim strDelimiter 'delimeter in the log file
  219. Dim strEventstring
  220. Dim objFileSysObject 'FileSystemobject
  221. Dim strLogPath 'log path
  222. Dim strEventFile 'event file name
  223. Dim strDownloadfile
  224. Dim blnFlagIE
  225. Dim strType,strDate,strTime,strSource,strCategory,strEvent,strUser,strComputer 'variables for the event details
  226. const TempDir = "TempFiles" ' A Temporary directory in web directory
  227. const LogDir = "LogFiles" ' A logs directory in Temporary directory
  228. const wbemPrivilegeBackup = 16
  229. const CONST_STRSECURITY = "Security"
  230. 'Trying to connect to the server
  231. set objWMIConnection = getWMIConnection(CONST_WMI_WIN32_NAMESPACE) 'Connecting to the server
  232. 'ERROR handling is done in the function itself
  233. If lcase(F_strEventName) = lcase(CONST_STRSECURITY) then
  234. objWMIConnection.Security_.Privileges.Add G_wbemPrivilegeSecurity 'giving the req priveleges
  235. End If
  236. If Err.number <> 0 then
  237. SA_SetErrMsg L_WMISECURITY_ERRORMESSAGE
  238. Err.Clear
  239. Exit sub
  240. End If
  241. objWMIConnection.Security_.Privileges.Add wbemPrivilegeBackup 'giving the req priveleges
  242. If Err.number <> 0 then
  243. SA_SetErrMsg L_WMISECURITY_ERRORMESSAGE
  244. Err.Clear
  245. Exit sub
  246. End If
  247. 'to format the output depending on the file type
  248. Select Case lcase(F_strRadSelected)
  249. Case lcase("Commadelimitedtextfile")
  250. strLogFile = left(F_strEventName,3) & "Event.csv"
  251. strDelimiter = ","
  252. Case lcase("Tabdelimitedtextfile")
  253. strLogFile = left(F_strEventName,3) & "Event.log"
  254. strDelimiter = vbtab
  255. End Select
  256. 'Wmi query for getting all the logevents
  257. strQuery ="SELECT * FROM Win32_NTlogEvent WHERE Logfile='" & F_strEventName & "'"
  258. 'getting the logevents
  259. Set objLognames = objWMIConnection.ExecQuery(strQuery,"WQL",48,null)
  260. If Err.number <> 0 then
  261. SA_SetErrMsg L_GETTINGLOGINSTANCES_ERRORMESSAGE
  262. Err.Clear
  263. Exit sub
  264. End If
  265. strLogPath = Server.MapPath(m_VirtualRoot)
  266. 'creating a filesystem object
  267. Set objFileSysObject = Server.CreateObject("Scripting.filesystemobject")
  268. If Err.number <> 0 then
  269. SA_SetErrMsg L_FILESYSTEMOBJECT_ERRORMESSAGE
  270. Err.Clear
  271. Exit sub
  272. End If
  273. strLogPath = GetLogsDirectoryPath(objFileSysObject)
  274. strEventFile = strLogPath & "\" & strLogFile
  275. If SA_IsIE = True Then
  276. blnFlagIE = True
  277. End If
  278. If not blnFlagIE = True Then
  279. 'delete the file,if already exists
  280. if objFileSysObject.FileExists(strEventFile) then
  281. objFileSysObject.DeleteFile(strEventFile)
  282. end if
  283. Call SA_TraceOut("Log_DownloadView.asp", "strEventFile: " + strEventFile)
  284. Set strDownloadfile = objFileSysObject.CreateTextFile(strEventFile, True)
  285. End If
  286. 'adding AddHeaders in case of IE
  287. If blnFlagIE = True Then
  288. Response.AddHeader "Content-Type", "text/plain"
  289. Response.AddHeader "Content-Disposition", "attachment; filename=" & strLogFile
  290. Response.Clear
  291. End If
  292. 'for loop to write all the required event values in text file
  293. For each objInstance in objLognames
  294. strDate=Mid(objInstance.TimeGenerated,5,2)& "/" & Mid(objInstance.TimeGenerated,7,2) & "/" & Mid(objInstance.TimeGenerated,1,4)
  295. strTime=Mid(objInstance.TimeGenerated,9,2)& ":" & Mid(objInstance.TimeGenerated,11,2)& ":" & Mid(objInstance.TimeGenerated,13,2)
  296. strType=objInstance.Type
  297. strSource=objInstance.SourceName
  298. strCategory=objInstance.Category
  299. strEvent=objInstance.EventCode
  300. strUser=objInstance.User
  301. strComputer=objInstance.ComputerName
  302. 'to format the output depending on the file type
  303. strEventstring=strDate & strDelimiter & strTime & strDelimiter & strType & strDelimiter &strSource& strDelimiter &strCategory& strDelimiter &strEvent& strDelimiter & strUser& strDelimiter &strComputer
  304. 'writing to the file
  305. If blnFlagIE = True then
  306. Response.Write strEventstring
  307. Response.Write vbcrlf
  308. Else
  309. strDownloadfile.WriteLine(strEventstring)
  310. End If
  311. Next
  312. If Err.number <> 0 then
  313. Err.Clear
  314. Call SA_TraceOut("Log_DownloadView.asp", "Error: " + Err.number)
  315. Exit sub
  316. End If
  317. 'release the objects
  318. Set objLognames = Nothing
  319. If blnFlagIE = True then
  320. Response.Flush
  321. Else
  322. Call SA_TraceOut("Log_DownloadView.asp", "F_strDownloadFile: " + F_strDownloadFile)
  323. 'close the opened file
  324. strDownloadfile.Close
  325. F_strDownloadFile = SA_GetNewHostURLBase(SA_DEFAULT, SAI_GetSecurePort(), True, SA_DEFAULT)
  326. F_strDownloadFile = F_strDownloadFile & TempDir &"/" &LogDir &"/" & strLogFile
  327. Call SA_TraceOut(SA_GetScriptFileName, "Download file URL: " & F_strDownloadFile)
  328. Call ServePage()
  329. %>
  330. <script language="javascript">
  331. top.location.href = '<%=F_strDownloadFile%>';
  332. </script>
  333. <%
  334. End If
  335. End Sub
  336. %>