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.

517 lines
17 KiB

  1. <% @Language=VbScript%>
  2. <% Option Explicit %>
  3. <%
  4. '-------------------------------------------------------------------------
  5. ' Log_details.asp : This page displays the details of a selected log event
  6. ' Copyright (c) Microsoft Corporation. All rights reserved.
  7. '-------------------------------------------------------------------------
  8. %>
  9. <!-- #include virtual="/admin/inc_framework.asp"--->
  10. <!-- #include file="loc_event.asp"--->
  11. <!-- #include file="inc_log.asp"-->
  12. <%
  13. '-------------------------------------------------------------------------
  14. ' Global Variables
  15. '-------------------------------------------------------------------------
  16. Dim G_strLogName 'Logname in WMI
  17. Dim G_intRecordNumber 'Current record number of the event
  18. Dim G_intMaxRecords 'Maximum records in the log
  19. Dim G_strDescription 'Description of an Event
  20. Dim G_objService 'object to WMI service
  21. Dim G_btnClicked 'Flag to indicate Ok button not used
  22. Dim G_intLowestRec 'Lowest record for the log
  23. Dim page 'Variable that receives the output page object when
  24. 'creating a page
  25. Dim rc 'Return value for CreatePage
  26. '-------------------------------------------------------------------------
  27. ' Global Form Variables
  28. '-------------------------------------------------------------------------
  29. Dim F_strDate 'Start date of Event
  30. Dim F_strTime 'Start time of Event
  31. Dim F_strType 'Type of selected Event
  32. Dim F_strSource 'SourceName of Event
  33. Dim F_intEventid 'Event Identifier
  34. Dim F_strDescription 'Description of the Event
  35. Dim F_strPrev 'To capture Pkey of the previous page
  36. Dim F_strTitle 'To capture Log Title from previous page
  37. Dim arrTitle(1)
  38. F_strPrev = Request.QueryString("Pkey")
  39. F_strTitle = Request.QueryString("Title")
  40. G_intRecordNumber = Cint(F_strPrev)
  41. G_strLogName = F_strTitle
  42. 'Localisation of page title
  43. arrTitle(0) = GetLocalizationTitle(F_strTitle)
  44. 'Page title
  45. L_PAGETITLE_LOGDETAILS_TEXT = SA_GetLocString("event.dll", "403F006E", arrTitle)
  46. ' Create and show the page
  47. Call SA_CreatePage(L_PAGETITLE_LOGDETAILS_TEXT, "", PT_AREA, Page)
  48. Call SA_ShowPage(Page)
  49. '-------------------------------------------------------------------------
  50. 'Function: OnInitPage()
  51. 'Description: Called to signal first time processing for this page.
  52. ' Use this method to do first time initialization tasks
  53. 'Input Variables: PageIn,EventArg
  54. 'Output Variables: None
  55. 'Returns: True/False
  56. 'Global Variables: G_btnClicked
  57. '-------------------------------------------------------------------------
  58. Public Function OnInitPage(ByRef PageIn,ByRef EventArg)
  59. OnInitPage=TRUE
  60. End Function
  61. '-------------------------------------------------------------------------
  62. 'Function: OnServePropertyPage()
  63. 'Description: Called when the page needs to be served.Use this
  64. ' method to serve content
  65. 'Input Variables: PageIn,EventArg
  66. 'Output Variables: None
  67. 'Returns: True/False
  68. 'Global Variables: Input: G_btnClicked,L_(*),F_strDate,G_intRecordNumber,G_intMaxRecords
  69. ' F_strTime,F_strType,F_strSource,F_intEventid,G_strLogName
  70. '-------------------------------------------------------------------------
  71. Public Function OnServeAreaPage(ByRef PageIn,Byref EventArg)
  72. Dim sDisabled
  73. Dim oEncoder
  74. Set oEncoder = new CSAEncoder
  75. OnServeAreaPage=True
  76. If ( Len(Request.Form("hdnRecordNum")) > 0 ) Then
  77. Call GetFormVariables()
  78. Else
  79. Call GetDefaultValues()
  80. End if
  81. %>
  82. <br>
  83. <div class='PageBodyInnerIndent'>
  84. <table border=0>
  85. <tr>
  86. <td nowrap class="TasksBody"><%=oEncoder.EncodeElement(L_DATE_DETAILS_TEXT)%></td>
  87. <td nowrap class="TasksBody"><%=oEncoder.EncodeElement(Cdate(F_strDate))%></td>
  88. <td>
  89. <%
  90. If trim(G_intRecordNumber) = trim(G_intMaxRecords) Then
  91. sDisabled = "DISABLED"
  92. Else
  93. sDisabled = ""
  94. End If
  95. Call SA_ServeOnClickButtonEx(L_UPBUTTON_TEXT, "", "goNext()", 90, 0, sDisabled, "UpButton")
  96. %>
  97. </td>
  98. </tr>
  99. <tr>
  100. <td nowrap class="TasksBody"><%=oEncoder.EncodeElement(L_TIME_DETAILS_TEXT)%></td>
  101. <td nowrap class="TasksBody"><%=oEncoder.EncodeElement(Cdate(F_strTime))%></td>
  102. <td>
  103. <%
  104. If G_intRecordNumber = G_intLowestRec Then
  105. sDisabled = "DISABLED"
  106. Else
  107. sDisabled = ""
  108. End If
  109. Call SA_ServeOnClickButtonEx(L_DOWNBUTTON_TEXT, "", "goPrevious()", 90, 0, sDisabled, "DownButton")
  110. %>
  111. </td>
  112. </tr>
  113. <tr>
  114. <td nowrap class="TasksBody"><%=oEncoder.EncodeElement(L_TYPE_LABEL_TEXT)%></td>
  115. <td class="TasksBody" nowrap><%=oEncoder.EncodeElement(F_strType)%></td>
  116. <td class="TasksBody">&nbsp;</td>
  117. </tr>
  118. <tr>
  119. <td nowrap class="TasksBody"><%=oEncoder.EncodeElement(L_SOURCE_DETAILS_TEXT)%></td>
  120. <td class="TasksBody" nowrap><%=oEncoder.EncodeElement(F_strSource)%></td>
  121. <td class="TasksBody">&nbsp;</td>
  122. </tr>
  123. <tr>
  124. <td nowrap class="TasksBody"><%=oEncoder.EncodeElement(L_EVENTID_TEXT)%></td>
  125. <td class="TasksBody" nowrap><%=oEncoder.EncodeElement(F_intEventid)%></td>
  126. <td class="TasksBody">&nbsp;</td>
  127. </tr>
  128. <tr>
  129. <td class="TasksBody">&nbsp;</td>
  130. <td class="TasksBody">&nbsp;</td>
  131. <td class="TasksBody">&nbsp;</td>
  132. </tr>
  133. <tr>
  134. <td nowrap class="TasksBody">
  135. <%=oEncoder.EncodeElement(L_DESCRIPTION_TEXT)%>
  136. </td>
  137. </tr>
  138. <tr>
  139. <td align="left" colspan=3 nowrap class="TasksBody">
  140. <textarea rows=5 cols=60 readonly id=textdescription name=textdescription><%=oEncoder.EncodeElement(F_strDescription)%></textarea>
  141. </td>
  142. </tr>
  143. <tr>
  144. <td class="TasksBody">&nbsp;</td>
  145. <td class="TasksBody">&nbsp;</td>
  146. <td class="TasksBody">&nbsp;</td>
  147. </tr>
  148. <tr>
  149. <td class="TasksBody">&nbsp;</td>
  150. <td class="TasksBody">&nbsp;</td>
  151. <td class="TasksBody">&nbsp;</td>
  152. </tr>
  153. </table>
  154. </div>
  155. <input type="hidden" name="hdnLogName" value="<%=G_strLogName%>">
  156. <input id="hdnRecordNum" type="hidden" name="hdnRecordNum" value="<%=G_intRecordNumber%>">
  157. <input id="hdnMaxRecords" type="hidden" name="hdnMaxRecords" value="<%=G_intMaxRecords%>">
  158. <input type="hidden" name="hdnMinRecords" value="<%=G_intLowestRec%>">
  159. <%
  160. Call ServeCommonJavaScript()
  161. End Function
  162. '-------------------------------------------------------------------------
  163. 'Function: ServeCommonJavaScript
  164. 'Description: Serves in initialiging the values,setting the form
  165. ' data and validating the form values
  166. 'Input Variables: None
  167. 'Output Variables: None
  168. 'Returns: None
  169. 'Global Variables: None
  170. '-------------------------------------------------------------------------
  171. Function ServeCommonJavaScript()
  172. %>
  173. <script language="JavaScript" src ='<%=m_VirtualRoot%>inc_global.js'>
  174. </script>
  175. <script language="JavaScript">
  176. // Set the initial form values
  177. function Init()
  178. {
  179. return true
  180. }
  181. //function to next consecutive event
  182. function goNext()
  183. {
  184. var oRecordNum;
  185. var oMaxRecords;
  186. oRecordNum = document.getElementById("hdnRecordNum");
  187. oMaxRecords = document.getElementById("hdnMaxRecords");
  188. if ( oRecordNum != null && oMaxRecords != null )
  189. {
  190. var intRecordNum = parseInt(oRecordNum.value,10);
  191. var intMaxRecords = parseInt(oMaxRecords.value,10);
  192. if (intRecordNum < intMaxRecords)
  193. {
  194. oRecordNum.value = intRecordNum + 1;
  195. document.TVData.submit();
  196. }
  197. }
  198. else
  199. {
  200. if ( oRecordNum == null)
  201. {
  202. if ( SA_IsDebugEnabled() )
  203. {
  204. alert("document.getElementById('hdnRecordNum') returned null");
  205. }
  206. }
  207. if ( oMaxRecords == null)
  208. {
  209. if ( SA_IsDebugEnabled() )
  210. {
  211. alert("document.getElementById('hdnMaxRecords') returned null");
  212. }
  213. }
  214. }
  215. }
  216. //function to previous event
  217. function goPrevious()
  218. {
  219. var oRecordNum;
  220. oRecordNum = document.getElementById("hdnRecordNum");
  221. if ( oRecordNum != null )
  222. {
  223. var intRecordNum = parseInt(oRecordNum.value,10);
  224. if (intRecordNum > 0 )
  225. {
  226. oRecordNum.value = intRecordNum - 1;
  227. document.TVData.submit();
  228. }
  229. }
  230. else
  231. {
  232. if ( oRecordNum == null)
  233. {
  234. if ( SA_IsDebugEnabled() )
  235. {
  236. alert("document.getElementById('hdnRecordNum') returned null");
  237. }
  238. }
  239. }
  240. }
  241. </script>
  242. <%
  243. End Function
  244. '-------------------------------------------------------------------------
  245. 'Function name: GetFormVariables()
  246. 'Description: Fetches state variables from form fields
  247. 'Input Variables: None
  248. 'Output Variables: None
  249. 'Returns: True - If GetDefaultValues function returns true
  250. ' False - Else
  251. 'Global Variables: Input: None
  252. ' Output: G_strLogName - Log Name
  253. ' Output: G_intRecordNumber - Current record number in the log
  254. '-------------------------------------------------------------------------
  255. Function GetFormVariables()
  256. G_strLogName = Request.Form("hdnLogName")
  257. G_intRecordNumber = CInt(Request.Form("hdnRecordNum"))
  258. G_intMaxRecords = CInt(Request.Form("hdnMaxRecords"))
  259. G_intLowestRec = CInt(Request.Form("hdnMinRecords"))
  260. If GetDefaultValues() then
  261. GetFormVariables=True
  262. Else
  263. GetFormVariables=False
  264. End if
  265. End Function
  266. '-------------------------------------------------------------------------
  267. 'Function name: GetDefaultValues
  268. 'Description: Serves in Getting the default values of the selected log
  269. 'Input Variables: None
  270. 'Output Variables: None
  271. 'Returns: False - If error in retrieving values
  272. ' True - Else
  273. 'Global Variables: Out:G_objService - WMI connection object
  274. ' In:G_strLogName - Log Name
  275. ' In:G_intRecordNumber - Current record number in the log
  276. ' In:F_strDate - Date the Event was logged
  277. ' In:F_strTime - Time the log event was created
  278. ' In:F_strType - Type of event
  279. ' In:F_strSource - Source of the log event
  280. ' In:F_intEventId - Id of the log event
  281. ' In:F_strDescription - Description of the log event
  282. '-------------------------------------------------------------------------
  283. Function GetDefaultValues()
  284. Err.Clear
  285. On Error Resume Next
  286. Dim objLognames 'To store the results of the query
  287. Dim strQuery 'To store the query
  288. Dim objLog 'To process the result of the query
  289. Dim intNoOfRecords 'Total records
  290. Dim strLogType 'Type of log
  291. Const CONST_wbemPrivilegeSecurity = 7 'Privilege constant
  292. Const CONST_strSecurityLog = "SECURITY" 'Constant for security log
  293. Dim oValidator
  294. Set oValidator = new CSAValidator
  295. If ( FALSE = oValidator.IsValidIdentifier(G_strLogName)) Then
  296. Call SA_TraceOut(SA_GetScriptFileName(), "LogName is invalid: " & G_strLogName)
  297. Call SA_ServeFailurepage(L_RETREIVEVALUES_ERRORMESSAGE)
  298. Set oValidator = Nothing
  299. Exit Function
  300. End If
  301. Set oValidator = Nothing
  302. Set G_objService = GetWMIConnection(CONST_WMI_WIN32_NAMESPACE)
  303. If Ucase(G_strLogName) = CONST_strSecurityLog then
  304. 'G_objService.Security_.Privileges.Add CONST_wbemPrivilegeSecurity 'giving the req Privilege
  305. End if
  306. If Err.number <> 0 then
  307. Call SA_TraceOut(SA_GetScriptFileName(), "G_objService.Security_.Privileges.Add failed: " + CStr(Hex(Err.Number)) + " " + Err.Description)
  308. Call SA_ServeFailurepage(L_FAILEDTOGETWMICONNECTION_ERRORMESSAGE)
  309. GetDefaultValues=False
  310. Exit Function
  311. End If
  312. strQuery ="SELECT * FROM Win32_NTlogEvent WHERE Logfile=" & chr(34) & G_strLogName & chr(34) & "AND RecordNumber =" & cint(G_intRecordNumber)
  313. Set objLognames = G_objService.ExecQuery(strQuery,"WQL",48,null)
  314. If Err.number <> 0 then
  315. Call SA_TraceOut(SA_GetScriptFileName(), "G_objService.ExecQuery(strQuery,WQL,48) failed: " + CStr(Hex(Err.Number)) + " " + Err.Description)
  316. Call SA_TraceOut(SA_GetScriptFileName(), "Query was: " + strQuery)
  317. Call SA_ServeFailurepage(L_RETREIVEVALUES_ERRORMESSAGE)
  318. GetDefaultValues=False
  319. Exit Function
  320. End If
  321. For each objLog in objLognames
  322. F_strDate = Mid(objLog.TimeGenerated,5,2)& "/" & Mid(objLog.TimeGenerated,7,2) & "/" & Mid(objLog.TimeGenerated,1,4)
  323. F_strTime = Mid(objLog.TimeGenerated,9,2)& ":" & Mid(objLog.TimeGenerated,11,2)& ":" & Mid(objLog.TimeGenerated,13,2)
  324. F_strType = objLog.Type
  325. F_strSource = objLog.SourceName
  326. F_intEventid= Cstr(objLog.EventCode)
  327. F_strDescription=objLog.Message
  328. Exit For
  329. Next
  330. 'Replace the carriagereturn string with null
  331. F_strDescription = Replace(F_strDescription,VBCrLf,"")
  332. Select Case F_strType
  333. case "information" :
  334. strLogType = L_INFORMATION_TYPE_TEXT
  335. case "error" :
  336. strLogType = L_ERROR_TYPE_TEXT
  337. case "warning" :
  338. strLogType = L_WARNING_TYPE_TEXT
  339. case "audit success" :
  340. strLogType = L_SUCCESSAUDIT_TYPE_TEXT
  341. case "audit failure" :
  342. strLogType = L_FAILUREAUDIT_TYPE_TEXT
  343. case else
  344. strLogType = ""
  345. End Select
  346. F_strType = strLogType
  347. 'Get max records
  348. If GetMaxRecords(G_strLogName,G_objService) then
  349. GetDefaultValues=True
  350. Else
  351. GetDefaultValues=False
  352. Exit function
  353. End if
  354. intNoOfRecords = getEventLogCount(G_strLogName,G_objService)
  355. 'Lowest record number
  356. G_intLowestRec = G_intMaxRecords - intNoOfRecords + 1
  357. GetDefaultValues = true
  358. Set G_objService=Nothing
  359. Set objLognames=Nothing
  360. Set objLog = Nothing
  361. End Function
  362. '-------------------------------------------------------------------------
  363. 'Function name: GetMaxRecords
  364. 'Description: gets the maximum records available from WMI
  365. 'Input Variables: None
  366. 'Output Variables: None
  367. 'Returns: True - If Maxrecords retrieved properly
  368. ' False - If error in retrieval of Maxrecords
  369. 'Global Variables: Out:G_intMaxRecords - Maximum records in the log
  370. ' In:G_objService - WMI connection object
  371. ' In:G_strLogName - Log name
  372. '-------------------------------------------------------------------------
  373. Function GetMaxRecords(strLogName,strObjService)
  374. On Error Resume Next
  375. Err.Clear
  376. Dim strQuery 'To store the query
  377. Dim objLognames 'To store the results of the query
  378. Dim objLog 'To process the results of the query
  379. strQuery ="SELECT * FROM Win32_NTlogEvent WHERE Logfile=" & chr(34) & G_strLogName & chr(34)
  380. Set objLognames = strObjService.ExecQuery(strQuery,"WQL",48,null)
  381. If Err.number <> 0 then
  382. Call SA_ServeFailurepage(L_FAILEDTOGETMAXLOGCOUNT_ERRORMESSAGE)
  383. GetMaxRecords = false
  384. Exit Function
  385. End if
  386. For each objLog in objLognames
  387. G_intMaxRecords = objLog.RecordNumber
  388. Exit for
  389. Next
  390. If Err.number <> 0 then
  391. Call SA_SetErrMsg (L_RETREIVEVALUES_ERRORMESSAGE)
  392. GetMaxRecords=False
  393. Exit Function
  394. End If
  395. GetMaxRecords=True
  396. Set objLognames=nothing
  397. Set objLog = nothing
  398. End Function
  399. '-------------------------------------------------------------------------`
  400. ' Function name: getEventLogCount
  401. ' Description: returns Log Count
  402. ' Input Variables: strEventLogName - Log Name( Application,system,Security)
  403. ' Output Variables: None
  404. ' Return Values: Returns Log Count
  405. ' Global Variables: L_FAILEDTOGETCOUNT_ERRORMESSAGE,G_objConnection,G_strReturnURL
  406. ' Gets the instance of Logname and returns the count.
  407. '-------------------------------------------------------------------------
  408. Function getEventLogCount(strEventLogName,objService)
  409. Err.Clear
  410. On Error Resume Next
  411. Dim objLognames
  412. Dim objLogname
  413. Dim nRecordCount
  414. nRecordCount = 0
  415. 'Getting the instances of the Logfile
  416. Set objLognames = objService.InstancesOf("Win32_NTEventlogFile")
  417. 'Checking for recordcount if zero "No Events"
  418. If ( objLognames.count = 0 ) Then
  419. nRecordCount = 0
  420. Else
  421. For each objLogname in objLognames
  422. 'checking for the selected logfilename if so get the record number for future use
  423. If LCase(objLogname.LogFileName)=LCase(strEventLogName) Then
  424. 'Assigning the no of records for the selected Log
  425. If IsNull(objLogname.NumberOfRecords) Then
  426. nRecordCount = 0
  427. Else
  428. nRecordCount=CInt(objLogname.NumberOfRecords)
  429. End If
  430. Exit For
  431. End If
  432. Next
  433. End IF
  434. 'Set to nothing
  435. Set objLogname = Nothing
  436. Set objLognames =Nothing
  437. If Err.number <> 0 Then
  438. Call SA_ServeFailurepage(L_FAILEDTOGETCOUNT_ERRORMESSAGE)
  439. getEventLogCount = false
  440. Exit function
  441. End If
  442. getEventLogCount = nRecordCount
  443. End Function
  444. %>