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.

325 lines
10 KiB

  1. var g_objFileSystem = null;
  2. var g_nTotalDialog = 0;
  3. var g_nTotalWeb = 0;
  4. // The file is located in %Windir%\system32\LogFiles\W3SVC1\extend<xx>.log
  5. function DebugSquirt(strText, fClear)
  6. {
  7. if (true == fClear)
  8. {
  9. document.all.idStatus2.innerText = "";
  10. }
  11. document.all.idStatus2.innerText += strText;
  12. }
  13. function MyOnLoad()
  14. {
  15. g_objFileSystem = new ActiveXObject("Scripting.FileSystemObject");
  16. var objfolder = g_objFileSystem.GetSpecialFolder(1 /* %windir%\system32\ */);
  17. var strPath = objfolder.Path;
  18. strPath += "\\LogFiles\\W3SVC1\\extend";
  19. var nExists = 1;
  20. // Find the last
  21. while (true == g_objFileSystem.FileExists(strPath + (1 + nExists) + ".log"))
  22. {
  23. // alert("CHecking for: " + strPath + (1 + nExists) + ".log");
  24. nExists++;
  25. }
  26. strPath += (nExists + ".log");
  27. // alert("strPath " + strPath);
  28. document.all.idPath.value = strPath;
  29. if (null != g_objFileSystem)
  30. {
  31. GetAllStatsFromPath(strPath);
  32. }
  33. }
  34. function GetAllStatsFromPath(strIISLog)
  35. {
  36. g_nTotalDialog = 0;
  37. g_nTotalWeb = 0;
  38. document.all.idStatus.innerText = "Please wait while loading the statistics...";
  39. GetStatsFromPath(strIISLog, "/fileassoc/fileassoc.asp", "fileassoc.dialog.log", true); // Generate Results for Dialog
  40. GetStatsFromPath(strIISLog, "/fileassoc/0409/xml/redir.asp", "fileassoc.web.log", false); // Generate Results for Click Thru To Web
  41. }
  42. function GetStatsFromPath(strIISLog, strUrlPath, strLogFile, fDialog)
  43. {
  44. var objDictionary = new ActiveXObject("Scripting.Dictionary");
  45. // alert("strIISLog: " + strIISLog + " strUrlPath: " + strUrlPath);
  46. // try
  47. {
  48. if (g_objFileSystem.FileExists(strIISLog))
  49. {
  50. DebugSquirt("Opening " + strIISLog, false);
  51. var objFile = g_objFileSystem.OpenTextFile(strIISLog, 1, false);
  52. if (null != objFile)
  53. {
  54. var nFieldIndex = -1;
  55. var strToFind = "#Fields:";
  56. var strLine = "";
  57. // Search for the "#Fields:" string
  58. while (!objFile.AtEndOfStream)
  59. {
  60. strLine = objFile.ReadLine();
  61. DebugSquirt("strLine: " + strLine, true);
  62. if (strLine.substring(0, strToFind.length) == strToFind)
  63. {
  64. CalcResults(objFile, objDictionary, GetFieldIndex(strLine, "cs-uri-query"), GetFieldIndex(strLine, "cs-uri-stem"), strUrlPath, fDialog);
  65. }
  66. }
  67. DebugSquirt("Displaying Results", true);
  68. DisplayResults(strLogFile, objDictionary, fDialog);
  69. objFile.Close();
  70. }
  71. }
  72. }
  73. if (0) //catch (objException)
  74. {
  75. alert("EXCEPTION 2: " + objException.description + " LINE: " + objException.line);
  76. throw objException;
  77. }
  78. }
  79. function GetFieldIndex(strLayout, strToken)
  80. {
  81. var nField = -1;
  82. var nParts = strLayout.split(" ");
  83. var nIndex;
  84. // Find the index into strToken.
  85. for (nIndex = 0; nIndex < strLayout.length; nIndex++)
  86. {
  87. if (strToken == nParts[nIndex])
  88. {
  89. nField = (nIndex - 1);
  90. break;
  91. }
  92. }
  93. return nField;
  94. }
  95. function CalcResults(objFile, objDictionary, nField, nFieldPath, strUrlPath, fDialog)
  96. {
  97. var strExtCached = null;
  98. var nExtCountCached = 0;
  99. var nTotal = ((true == fDialog) ? g_nTotalDialog : g_nTotalWeb);
  100. if (-1 != nField)
  101. {
  102. while (!objFile.AtEndOfStream)
  103. {
  104. var strLine = objFile.ReadLine();
  105. if (('#' != strLine.charAt(0)) && ("-" != strLine))
  106. {
  107. var strArray = strLine.split(" ");
  108. if (null != strArray)
  109. {
  110. var strQuery = strArray[nField];
  111. var strTheUrlPath = strArray[nFieldPath];
  112. if ((null != strQuery) && (null != strTheUrlPath) &&
  113. (strUrlPath == strTheUrlPath))
  114. {
  115. var arrayExt = strQuery.split("Ext=");
  116. if ((null != arrayExt) && (0 < arrayExt.length))
  117. {
  118. var strExt = arrayExt[1];
  119. if (null != strExt)
  120. {
  121. try
  122. {
  123. // alert("strExt: " + strExt);
  124. strExt = (strExt.split("&"))[0];
  125. }
  126. catch (objException)
  127. {
  128. alert("Fat cow. strExt: " + strExt);
  129. }
  130. // alert("strQuery: " + strQuery + " strExt: " + strExt);
  131. if ((null != strExt) && ("" != strExt))
  132. {
  133. nTotal++;
  134. if (strExtCached == strExt)
  135. {
  136. nExtCountCached++;
  137. }
  138. else
  139. {
  140. // First save off the cached ext
  141. if (null != strExtCached)
  142. {
  143. // alert("1");
  144. if (objDictionary.Exists(strExtCached))
  145. {
  146. // alert("2a");
  147. objDictionary.Item(strExtCached) = nExtCountCached;
  148. }
  149. else
  150. {
  151. // alert("2b");
  152. objDictionary.Add(strExtCached, nExtCountCached);
  153. }
  154. // alert("3");
  155. }
  156. strExtCached = strExt;
  157. if (objDictionary.Exists(strExt))
  158. {
  159. // alert("4a");
  160. nExtCountCached = objDictionary.Item(strExt);
  161. }
  162. else
  163. {
  164. // alert("4b");
  165. nExtCountCached = 0;
  166. }
  167. // alert("end");
  168. nExtCountCached++;
  169. }
  170. }
  171. }
  172. }
  173. }
  174. } else alert("strArray is null");
  175. }
  176. else
  177. {
  178. // break if we hit a new batch of log entries.
  179. var strToFind = "#Fields:";
  180. if (strLine.substring(0, strToFind.length) == strToFind)
  181. {
  182. break;
  183. }
  184. }
  185. }
  186. // First save off the cached ext
  187. if (null != strExtCached)
  188. {
  189. if (objDictionary.Exists(strExtCached))
  190. {
  191. objDictionary.Item(strExtCached) = nExtCountCached;
  192. }
  193. else
  194. {
  195. objDictionary.Add(strExtCached, nExtCountCached);
  196. }
  197. }
  198. }
  199. else
  200. {
  201. document.all.idStatus.innerText = "ERROR: You need to have IIS include the URI Query (cs-uri-query) in the log file.";
  202. }
  203. if (true == fDialog)
  204. {
  205. g_nTotalDialog = nTotal;
  206. }
  207. else
  208. {
  209. g_nTotalWeb = nTotal;
  210. }
  211. }
  212. function DisplayResults(strLogFile, objDictionary, fDialog)
  213. {
  214. var strUI = "";
  215. var nIndex;
  216. var strKeyArray = (new VBArray(objDictionary.Keys())).toArray();
  217. var strCount;
  218. var objfolder = g_objFileSystem.GetSpecialFolder(1 /* %windir%\system32\ */);
  219. var strPath = (objfolder.Path + "\\" + strLogFile);
  220. var objDataBinding = null;
  221. var objTotalUsers = null;
  222. var nTotal;
  223. if (true == fDialog)
  224. {
  225. objDataBinding = document.all.dsoResults;
  226. objTotalUsers = document.all.idTotalDialogUsers;
  227. nTotal = g_nTotalDialog;
  228. }
  229. else
  230. {
  231. objDataBinding = document.all.dsoResults2;
  232. objTotalUsers = document.all.idTotalWebUsers;
  233. nTotal = g_nTotalWeb;
  234. }
  235. try
  236. {
  237. g_objFileSystem.DeleteFile(strPath);
  238. }
  239. catch (objException)
  240. {
  241. // We don't care if we can't delete it.
  242. }
  243. var objFile = g_objFileSystem.CreateTextFile(strPath, true, false);
  244. objFile.WriteLine("col_Extension:String, col_Number:Int, col_Percent:String");
  245. var strPercent;
  246. var fTotal = (nTotal * 1.0);
  247. objTotalUsers.innerText = nTotal;
  248. if (0 != strKeyArray.length)
  249. {
  250. for (nIndex = 0; nIndex < strKeyArray.length; nIndex++)
  251. {
  252. strCount = objDictionary.Item(strKeyArray[nIndex]);
  253. strPercent = ((strCount / fTotal) * 100.0) + "";
  254. strPercent = strPercent.substring(0, 5) + "%";
  255. objFile.WriteLine(strKeyArray[nIndex] + ", " + strCount + ", " + strPercent);
  256. }
  257. }
  258. else
  259. {
  260. objFile.WriteLine("None, 0, 100.00%");
  261. }
  262. objFile.Close();
  263. objDataBinding.DataURL = strPath;
  264. // document.all.idStatus.innerText = "";
  265. // document.all.idStatus.innerText = objDataBinding.DataURL;
  266. try
  267. {
  268. objDataBinding.Reset();
  269. }
  270. catch (objException)
  271. {
  272. // We don't care if we can't delete it.
  273. document.all.idStatus.innerText += " objDataBinding.Reset() failed";
  274. }
  275. }