Source code of Windows XP (NT5)
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.

539 lines
17 KiB

  1. var kalpaxml = null ; // holds our binary component.
  2. var PAGE_SIZE; // number of records in a page.
  3. var PAGES_IN_DATA = 3; //number of pages in the table
  4. var DATA_SIZE = 500; // number of records in the table
  5. var INDEX_DATA = 0;
  6. // do not hard-code
  7. var ROW_HEIGHT = 20;
  8. var INDEX_NEXT_TOP = 0 ; // index of EEL data in cache that is at the top of eelData island
  9. var OLD_PAGE_SIZE;
  10. var MAX_ROWS = 50;
  11. var fResizing = false;
  12. var fScrollChange = false;
  13. var numEELRecords = 0 ; // max. number of records in eelDataCache
  14. var fRecordPresent = false;
  15. var fLogTypePresent = false ;
  16. var arrayProp = new Array( );
  17. var viewingNTEventLog = false ; // true only for NT Event Log.
  18. var typePos = null;
  19. var valuePos = null;
  20. var classificationPos = null;
  21. var valNumClassification = new Array("","discovery","inventory","configuration",
  22. "operation/availablity","problem management", "threshold crossings",
  23. "Performance and Capacity","Billing");
  24. var valNumLogType=new Array("","System","Application","Security");
  25. var valImageSrc= new Array("images/high_imp.gif","images/error.gif","images/alert.gif","images/info.gif","images/key.gif","images/lock.gif","images/garbage.gif");
  26. var valType = new Array("red alert","error","warning","information","security audit success","security audit failure","garbage");
  27. var valNTImageSrc = new Array();
  28. valNTImageSrc["error"] = "images/error.gif";
  29. valNTImageSrc["warning"] = "images/alert.gif";
  30. valNTImageSrc["information"] = "images/info.gif";
  31. valNTImageSrc["audit success"] = "images/key.gif";
  32. valNTImageSrc["audit failure"] = "images/lock.gif";
  33. var valType1=new Array();
  34. valType1["red alert"]=0;
  35. valType1["error"]=1;
  36. valType1["warning"]=2;
  37. valType1["information"]=3;
  38. valType1["security audit success"]=4;
  39. valType1["security audit failure"]=5;
  40. valType1["garbage"]=6;
  41. var arrAMPM = Array("AM","AM","AM","AM","AM","AM","AM","AM","AM","AM","AM","AM","PM","PM","PM","PM","PM","PM","PM","PM","PM","PM","PM","PM");
  42. var arrHours = Array("00","01","02","03","04","05","06","07","08","09","10","11",
  43. "00","01","02","03","04","05","06","07","08","09","10","11");
  44. // this parameter is used to set the scrollbar.
  45. var maxRecords = 1000000;
  46. window.onerror = fnErrorTrap ;
  47. var numColumns = 0;
  48. var cache = new Array(6000);
  49. var record = new Array(500);
  50. var logfilearray = new Array(500);
  51. var RECORDNUMBER_INDEX = 0;
  52. var LOGFILE_INDEX = 0 ;
  53. var maxNTRecords = 1000;
  54. // BugBug - Adjustment to get alignment correct
  55. function fnErrorTrap (sMsg, sUrl, sLine) {
  56. alert (sMsg + sUrl + sLine) ;
  57. }
  58. //-------------------------------------------------------------------------------
  59. // onload
  60. // This function will be executed when viewer window is first loaded.
  61. //--------------------------------------------------------------------------------
  62. function window.onresize() {
  63. document.recalc (true) ;
  64. if(fMadeConnection == true)
  65. {
  66. fResizing = true;
  67. OLD_PAGE_SIZE = PAGE_SIZE;
  68. calcPageSize();
  69. setScrollBarParameters();
  70. pageInRange();
  71. fResizing = false;
  72. }
  73. else
  74. calcPageSize();
  75. fillTable();
  76. }
  77. function window.onload () {
  78. wmiInit () ;
  79. init () ;
  80. tableDiv.style.setExpression ("height", "mainBody.clientHeight - taskDiv.offsetHeight - drillDownDiv.style.pixelHeight - TABLE0.style.pixelHeight") ;
  81. tableDiv.style.setExpression("width", "mainBody.clientWidth - scrollBar.clientWidth");
  82. customizeDiv.style.setExpression ("height", "mainBody.clientHeight") ;
  83. scrollBar.style.setExpression ("top", "tableDiv.offsetTop") ;
  84. scrollBar.style.setExpression ("left", "mainBody.clientWidth-scrollBar.clientWidth") ;
  85. scrollBar.style.setExpression ("pixelHeight", "tableDiv.style.pixelHeight") ;
  86. document.recalc(true);
  87. calcPageSize();
  88. setScrollBarParameters();
  89. scrollBar.style.visibility = 'visible';
  90. fillTable();
  91. // this is because the document.location.search also returns the '?'
  92. var tempStr = document.location.search.substring(1);
  93. argv = tempStr.split(",");
  94. if(argv.length >= 2)
  95. startUpConnectionFromMMC(argv);
  96. }
  97. function window.onunload () {
  98. close() ;
  99. }
  100. function handleScroll(){
  101. // this is to prevent cascading events
  102. if(fScrollChange== true)
  103. return;
  104. else
  105. {
  106. fScrollChange = true;
  107. pageInRange();
  108. fScrollChange = false;
  109. }
  110. }
  111. function cacheAway()
  112. {
  113. var k = 0;
  114. var d = new Date();
  115. var numberToGet = Math.min (DATA_SIZE, (numEELRecords - INDEX_NEXT_TOP)) ;
  116. var numberGot = 0;
  117. var i,j;
  118. for (i = 0; i < numberToGet; i++)
  119. {
  120. try {
  121. kalpaxml.wmiGetNextObject();
  122. } catch (e) {
  123. // try to update count.
  124. // BUGBUG! what query to use?
  125. // BUGBUG! logic for updating number of records since we cannot get it from
  126. // WMI yet.
  127. numEELRecords = kalpaxml.wmiGetCount ("") ;
  128. setScrollBarParameters () ;
  129. scrollBar.value = Math.max(numEELRecords - PAGE_SIZE,0);
  130. numberGot = i;
  131. convertCacheDateTime(numberGot);
  132. return;
  133. }
  134. for(j = 0; j < numColumns; j++)
  135. {
  136. if( (j!=typePos)&&(j!=classificationPos)&&(j!=valuePos ) )
  137. {
  138. cache[k++] = kalpaxml.wmiGetPropertyText(arrayProp[j]);
  139. }
  140. else
  141. {
  142. if(j==classificationPos)
  143. {
  144. cache[k++] = valNumClassification [kalpaxml.wmiGetPropertyText(arrayProp[j])];
  145. }
  146. else
  147. if(j==typePos)
  148. {
  149. if(viewingNTEventLog == true)
  150. {
  151. var temp = kalpaxml.wmiGetPropertyText(arrayProp[j]);
  152. cache[k++] = "<IMG align='left' src=" + valNTImageSrc[temp] + "></IMG>" + temp;
  153. }
  154. else
  155. {
  156. var temp = kalpaxml.wmiGetPropertyText(arrayProp[j]);
  157. cache[k++] = "<IMG align='left' src=" + valImageSrc[temp] + "></IMG>" + valType[temp];
  158. }
  159. }
  160. else
  161. {
  162. cache[k++] = valNumLogType[kalpaxml.wmiGetPropertyText(arrayProp[j])]
  163. }
  164. }
  165. }
  166. //this is for drillDown - we always put the RecordNumber for EEL case
  167. //and RecordNumber+LogType in NT Case;
  168. if(fRecordPresent == false)
  169. {
  170. record[INDEX_NEXT_TOP + i] = kalpaxml.wmiGetPropertyText("RecordNumber");
  171. }
  172. if(fLogTypePresent == false && viewingNTEventLog)
  173. {
  174. logfilearray[INDEX_NEXT_TOP + i] = kalpaxml.wmiGetPropertyText("Logfile");
  175. }
  176. }
  177. numberGot = i;
  178. convertCacheDateTime(numberGot);
  179. }
  180. function convertCacheDateTime(numberGot)
  181. {
  182. var i,j;
  183. for(j=0;j<numColumns;j++)
  184. {
  185. if(arrayProp[j].indexOf("Time")!=-1)
  186. {
  187. for (i = 0; i < numberGot; i++)
  188. cache[i*numColumns+j] = convertDateTime(cache[i*numColumns+j])
  189. }
  190. }
  191. }
  192. function convertDateTime(dateTimeStr)
  193. {
  194. hours = dateTimeStr.substring(8,10) * 1;
  195. gmtTime = dateTimeStr.substring (22,24) ;
  196. gmtTimeHours = ((gmtTime - (gmtTime)%6)/6) ;
  197. gmtTimeMins = gmtTime - (gmtTimeHours * 6);
  198. return(dateTimeStr.substring(4,6)+"/"+dateTimeStr.substring(6,8)+"/"+dateTimeStr.substring(2,4)+ " " + arrHours[hours]+":"+dateTimeStr.substring(10,12)+":"+dateTimeStr.substring(12,14)+" "+arrAMPM[hours]+
  199. " GMT"+dateTimeStr.substring(21,22)+gmtTimeHours+":"+gmtTimeMins+"0");
  200. }
  201. function fillUpTableFromCache(startRow,numRows,cachePosition)
  202. {
  203. //startTimer();
  204. var i,j;
  205. for(i=startRow;i<numRows;i++)
  206. {
  207. for(j = 0; j < numColumns; j++)
  208. {
  209. if(j==typePos)
  210. {
  211. TABLEBODY1.rows(i).cells(j).innerHTML = cache[cachePosition++] ;
  212. }
  213. else
  214. TABLEBODY1.rows(i).cells(j).innerText = cache[cachePosition++] ;
  215. }
  216. }
  217. if(fRecordPresent == false)
  218. {
  219. for(i=startRow;i<numRows;i++)
  220. TABLEBODY1.rows(i).cells(RECORDNUMBER_INDEX).innerText = record[INDEX_NEXT_TOP+i];
  221. }
  222. if(fLogTypePresent == false) {
  223. for(i=startRow;i<numRows;i++)
  224. TABLEBODY1.rows(i).cells(LOGFILE_INDEX).innerText = logfilearray[INDEX_NEXT_TOP+i];
  225. }
  226. // endTimer();
  227. /*
  228. //Is the code below better optimised - reduced number of comparisions
  229. //versus rewriting into the cells??
  230. for(i=startRow;i<numRows;i++)
  231. {
  232. for(j = 0; j < numColumns; j++)
  233. TABLEBODY1.rows(i).cells(j).innerText = cache[cachePosition++] ;
  234. }
  235. for(i=startRow;i<numRows;i++)
  236. {
  237. TABLEBODY1.rows(i).cells(typePos).innerHTML = cache[cachePosition++] ;
  238. }
  239. if(fRecordPresent == false)
  240. {
  241. for(i=startRow;i<numRows;i++)
  242. TABLEBODY1.rows(i).cells(RECORDNUMBER_INDEX).innerText = record[INDEX_NEXT_TOP+i];
  243. }
  244. */
  245. }
  246. function getCount(queryCount)
  247. {
  248. var cnt=-1;
  249. try {
  250. cnt = kalpaxml.wmiGetCount(queryCount);;
  251. } catch (e) {
  252. //errorMessage = e.description;
  253. }
  254. return(cnt);
  255. }
  256. function getDrillDownNode(strRecordNumber, strLogFile) {
  257. var query;
  258. var wqlStr;
  259. var nt = false ;
  260. if (viewingNTEventLog == true)
  261. {
  262. query = "(RecordNumber=" + "'"+ strRecordNumber + "') and (Logfile=" + "'" + strLogFile + "')";
  263. wqlStr = "SELECT Message, Data, Type FROM Win32_NTLogEvent WHERE (" + query + ")";
  264. nt = true ;
  265. }
  266. else
  267. {
  268. query = "(RecordNumber=" + "'"+ strRecordNumber + "')";
  269. wqlStr = "SELECT OriginalEvent, Priority, Severity, Type FROM Microsoft_EELEntry WHERE (" + query + ")";
  270. }
  271. var rs;
  272. try {
  273. s = kalpaxml.wmiGetDetailsText (wqlStr) ;
  274. } catch (e) {
  275. return (null);
  276. }
  277. if (nt) {
  278. xmlStr = toDrillDownXMLNT (s) ;
  279. } else {
  280. xmlStr = toDrillDownXML (s) ;
  281. }
  282. xmlStr = "<INSTANCE>" + xmlStr + "</INSTANCE>" ;
  283. drillDownTemp.loadXML (xmlStr) ;
  284. var node = drillDownTemp.selectSingleNode("INSTANCE");
  285. return (node);
  286. }
  287. function toDrillDownXML (s) {
  288. var start,end;
  289. //Saving the value as it will be required later
  290. sT=s;
  291. //The next three lines get the part required by drilldown part.
  292. //The remaining is type, priority and severity.
  293. start = s.indexOf ("instance") ;
  294. end = s.indexOf ("Priority", start) ;
  295. s= s.slice (start, end-1) ;
  296. // replace new line
  297. a = s.replace (/[\s\n]/g," ") ;
  298. b = a.replace (/(\s\S)*\s(\w+)\s*=\s*(instance of)\s*(\w+)(\s*{ )/g,
  299. "$1<PROPERTY.OBJECT NAME=\"$2\"><VALUE.OBJECT><INSTANCE CLASSNAME=\"$4\">")
  300. c = b.replace (/\s*(\w+)(\s*=\s*)"*([\w\s]*)"*;/g,"<PROPERTY NAME=\"$1\"><VALUE>$3</VALUE></PROPERTY>") ;
  301. d = c.replace (/};/g, "</INSTANCE></VALUE.OBJECT></PROPERTY.OBJECT>") ;
  302. //Getting the part which contains priority, type and severity fields
  303. start = sT.indexOf ("Priority") ;
  304. end = sT.indexOf ("Type", start) ;
  305. g= sT.slice (start, end+9) ;
  306. h = g.replace (/[\s\n]/g," ") ;
  307. //Getting the Severity value
  308. start = h.indexOf ("Sev") ;
  309. end = h.indexOf ("Typ") ;
  310. d=d+"<PROPERTY NAME=\""+h.slice(start,start+8)+"\" CLASSORIGIN=\"Microsoft_EELEntry\" TYPE=\"uint16\"><VALUE>"+h.slice(end-4,end-3)+"</VALUE></PROPERTY>";
  311. //Getting priority value
  312. start = h.indexOf ("Pri") ;
  313. end = h.indexOf ("Sev") ;
  314. d=d+"<PROPERTY NAME=\""+h.slice(start,start+8)+"\" CLASSORIGIN=\"Microsoft_EELEntry\" TYPE=\"uint16\"><VALUE>"+h.slice(end-4,end-3)+"</VALUE></PROPERTY>";
  315. //Getting type value
  316. start = h.indexOf ("Ty") ;
  317. end = h.indexOf ("}") ;
  318. d=d+"<PROPERTY NAME=\""+h.slice(start,start+4)+"\" CLASSORIGIN=\"Microsoft_EELEntry\" TYPE=\"uint8\"><VALUE>"+h.slice(start+7,start+8)+"</VALUE></PROPERTY>";
  319. return d ;
  320. }
  321. function toDrillDownXMLNT (s) {
  322. var start,end;
  323. //Next 4 lines get the value of the type field
  324. start = s.indexOf ("Type = \"") ;
  325. end = s.indexOf ("\";", start) ;
  326. sT = s.slice (start+8, end) ;
  327. sType=valType1[sT];
  328. //Next three lines get the part which is for the drilldown
  329. start = s.indexOf("inst");
  330. end = s.indexOf("Ty");
  331. s = s.slice(start,end -1);
  332. s=s+"};" ;
  333. // replace new line
  334. a = s.replace (/[\s\n]/g," ") ;
  335. a = s.replace (/\\n/g, "") ;
  336. // find the message part.
  337. start = a.indexOf ("Message = \"") ;
  338. end = a.indexOf ("\";", start) ;
  339. message = a.slice (start+11, end) ;
  340. // find data.
  341. data = "" ;
  342. ds = a.indexOf ("Data = {") ;
  343. if (ds !=-1) {
  344. de = a.indexOf ("}", ds) ;
  345. data = a.slice (ds+8,de) + ",";
  346. }
  347. if (data != "") {
  348. //break it up into <VALUE> nodes as we want.
  349. datax = data.replace(/\s*(\d+),/g,"<VALUE>$1.</VALUE>") ;
  350. } else{
  351. datax = "";
  352. }
  353. datax = "<PROPERTY NAME=\"Data\"><VALUE>"+datax+"</VALUE></PROPERTY>" ;
  354. // build the xml
  355. s1 = "<PROPERTY NAME=\"Type\"><VALUE>"+sType+"</VALUE></PROPERTY><PROPERTY.OBJECT NAME=\"Details Data\">"
  356. +"<VALUE.OBJECT>"
  357. +"<INSTANCE CLASSNAME=\"Message and Data\" NAME=\"NT\">"
  358. +"<VALUE>1</VALUE>"
  359. +"<PROPERTY NAME=\"Message\">"
  360. +"<VALUE>"+message+"</VALUE></PROPERTY>"
  361. +datax
  362. +"</INSTANCE></VALUE.OBJECT></PROPERTY.OBJECT>" ;
  363. return s1 ;
  364. }
  365. //-----------------------------------------------------------------------------
  366. // Respositions the forward only enumerator to the required position
  367. //-----------------------------------------------------------------------------
  368. function positionEnumerator (index) {
  369. try {
  370. kalpaxml.wmiGoTo(index);
  371. } catch (e) {
  372. // the failure will be caught in the
  373. // cacheAway function
  374. }
  375. }
  376. //-----------------------------------------------------------------------------
  377. // pageInRange ()
  378. //
  379. // displays the page in specified range
  380. //-----------------------------------------------------------------------------
  381. function pageInRange() {
  382. //This function is called when you scroll and when you resize
  383. if(fMadeConnection == false)
  384. return;
  385. var prev_INDEX_NEXT_TOP = INDEX_NEXT_TOP;
  386. INDEX_NEXT_TOP = scrollBar.value;
  387. if( (numEELRecords<MAX_ROWS) )
  388. {
  389. // fix this
  390. for(i=0;i<numEELRecords;i++)
  391. {
  392. TABLEBODY1.rows(i).style.display = "";
  393. }
  394. for(i=numEELRecords;i<MAX_ROWS;i++)
  395. {
  396. TABLEBODY1.rows(i).style.display = "none";
  397. }
  398. }
  399. if( ( ( INDEX_NEXT_TOP + PAGE_SIZE > INDEX_DATA + DATA_SIZE) && (INDEX_NEXT_TOP + PAGE_SIZE <= numEELRecords) ) || ( INDEX_NEXT_TOP < INDEX_DATA) )
  400. {
  401. // should we let this code be as it is
  402. // that should be done if the strategy is always to straddle,
  403. // which seems to be the best thing to do
  404. // check with AmitC
  405. // we do not have the required data with us
  406. // now get the appropriate data page
  407. if (INDEX_NEXT_TOP + DATA_SIZE > numEELRecords)
  408. INDEX_DATA = numEELRecords - DATA_SIZE;
  409. else
  410. INDEX_DATA = Math.max(INDEX_NEXT_TOP - Math.floor(DATA_SIZE/2),0);
  411. var tmpINDEX_NEXT_TOP = INDEX_NEXT_TOP;
  412. INDEX_NEXT_TOP = INDEX_DATA;
  413. // BUGBUG! Trying to counter the fact that we don't have the right count
  414. var tmp = numEELRecords ;
  415. positionEnumerator( INDEX_NEXT_TOP );
  416. getNextDataPage ();
  417. if (tmp != numEELRecords) {
  418. // This means we just realized that we did not have the right count.
  419. // we have adjusted the scroll bar params, but values like INDEX_NEXT_TOP are wrong.
  420. // we will call getNextDataPage again with a corrected INDEX_NEXT_TOP
  421. tmpINDEX_NEXT_TOP = scrollBar.value;
  422. INDEX_NEXT_TOP = Math.max(tmpINDEX_NEXT_TOP - Math.floor(DATA_SIZE/2),0);
  423. INDEX_DATA = INDEX_NEXT_TOP;
  424. positionEnumerator( INDEX_NEXT_TOP );
  425. getNextDataPage () ;
  426. }
  427. INDEX_NEXT_TOP = tmpINDEX_NEXT_TOP;
  428. }
  429. else
  430. {
  431. //optimise for
  432. //a)resizing - put data into table only for OLD_PAGE_SIZE to new PAGE_SIZE;
  433. //b)scroll by 1 - try using insertCell and deleteCell - this will give the required effect as well
  434. //the function fillUpTableFromCache
  435. // is very generic for doing that
  436. if(INDEX_NEXT_TOP+PAGE_SIZE>numEELRecords)
  437. {
  438. INDEX_NEXT_TOP = Math.max(numEELRecords - PAGE_SIZE,0);
  439. }
  440. fillUpTableFromCache(0,PAGE_SIZE+1,(INDEX_NEXT_TOP-INDEX_DATA)* numColumns);
  441. }
  442. if(numEELRecords > 0)
  443. {
  444. if(selectedRecord == selectedRow+INDEX_NEXT_TOP)
  445. {
  446. highlightRow();
  447. //TABLEBODY1.rows(selectedRow-1).cells(0).focus();
  448. }
  449. else
  450. {
  451. for (j=0; j < TABLE1.rows(selectedRow).cells.length; j++)
  452. TABLE1.rows(selectedRow).cells(j).style.background="rgb(255,255,255)" ;
  453. }
  454. }
  455. getCurrentRecords();
  456. //ResultSetCache.ReportStatistics();
  457. }
  458. function startTimer()
  459. {
  460. date0 = new Date();
  461. }
  462. function endTimer()
  463. {
  464. date1 = new Date();
  465. alert("Time for your function - " + (date1.getTime() - date0.getTime() )/1000 + "seconds")
  466. }
  467. <!-- ******************************************************** -->
  468. <!-- -->
  469. <!-- Copyright (c) 1999-2000 Microsoft Corporation -->
  470. <!-- -->
  471. <!-- main.js -->
  472. <!-- -->
  473. <!-- Build Type : Free -->
  474. <!-- Build Number : 0622 -->
  475. <!-- Build Date : 06/22/2000 -->
  476. <!-- ******************************************************* -->