home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2003 September / INTERNET107.ISO / pc / software / windows / utils / tiny_firewall / tpf45.exe / Data1.cab / functions.js < prev    next >
Encoding:
JavaScript  |  2002-11-01  |  3.6 KB  |  165 lines

  1.  
  2. //Functions.js
  3. //fuctions for procesing logs
  4. //cretaed by Jozef Palocko jpalocko@securitae.com
  5.  
  6. //global definitions
  7. var XSL_ALL = "all.xslt";
  8. var XSL_SBX = "sbx.xslt";
  9. var XSL_FW = "fw.xslt";
  10. var XSL_IDS = "ids.xslt";
  11. var XSL_SYSTEM = "system.xslt";
  12.  
  13. //Create XML file  as a DOMDocument.
  14. var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
  15.  
  16. var gModule = XSL_ALL;
  17.  
  18. function OnLoad()
  19. {
  20.     var d = new Date();              // Create Date object with today's date.
  21.     var s = (d.getMonth() + 1) + "/";          // Get month
  22.     s += d.getDate() + "/";                 // Get day
  23.     s += d.getYear();         
  24.     form.from.value = s;
  25.     form.to.value =s;
  26.     form.submit.value = DISPLAY;
  27. }
  28. function HandleMenu (id, str)
  29. {
  30.     var  title = TITLE_TEXT + " - " + str;
  31.     document.all.top.innerHTML = title;
  32.     switch (id)
  33.     {
  34.     case 0:
  35.         gModule = XSL_ALL;break;
  36.     case 1:
  37.         gModule = XSL_SBX;break;
  38.     case 2:
  39.         gModule = XSL_FW;break;
  40.     case 3:
  41.         gModule = XSL_IDS;break;
  42.     case 4:
  43.         gModule = XSL_SYSTEM;break;
  44.     }
  45. }
  46.  
  47. function OnSubmit()
  48. {
  49.     if (CheckDates())
  50.     {
  51.         result.innerHTML =PLEASE_WAIT;
  52.  
  53.         var ret ="" ;
  54.         dFrom = new Date(Date.parse(form.from.value));
  55.         dTo= new Date( Date.parse(form.to.value));
  56.  
  57.         var d = dFrom;
  58.         var strLogDir = GetLogDir();
  59.         while( d<=dTo)
  60.         {
  61.             for (i=1;i<1000;i++)
  62.             {
  63.                 var xml = strLogDir + GetFileName(d, i);
  64.                 //load  XML file as a DOMDocument.
  65.                 if (!xmlDoc.load(xml))
  66.                     continue;        
  67.                 while (xmlDoc.readyState<4);
  68.                 ret += TransformXML(xmlDoc);
  69.             }
  70.             d.setDate(d.getDate()+1);
  71.         }
  72.         if (ret=="")
  73.             ret = NO_ENTRIES_STR;
  74.         result.innerHTML = ret;
  75.     }
  76. }
  77. function CheckDates()
  78. {
  79.     dFrom = Date.parse(form.from.value);
  80.     dTo= Date.parse(form.to.value);
  81.     if (!dFrom  || !dTo)
  82.     {
  83.         alert(ERR_DATE_FORMAT);
  84.         return false;
  85.     }
  86.     if (dFrom>dTo)
  87.     {
  88.         alert(ERR_DATE_RANGE);
  89.         return false;
  90.     }
  91.     return true;
  92. }
  93. function GetFileName(d, i)
  94. {
  95.     var strFile = new String;
  96.     var tmp = new String;
  97.     
  98.     tmp += d.getYear();
  99.     strFile += tmp.substr(2,2);
  100.     
  101.     tmp="";    tmp += d.getMonth() + 1;
  102.     if (tmp.length ==1)
  103.         tmp = "0" +tmp;
  104.     strFile +=tmp;
  105.     
  106.     tmp="";tmp += d.getDate();
  107.     if (tmp.length ==1)
  108.         tmp = "0" +tmp;
  109.     strFile += tmp;
  110.     
  111.     var index;
  112.     if (i<10)
  113.         index = "00"+i;
  114.     else if(i<100)
  115.         index = "0"+i;
  116.     
  117.     strFile += "_"+ index + ".xml";
  118.     return strFile;
  119. }
  120. function GetLogDir()
  121. {
  122.     var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
  123.     xmlDoc.async = false;
  124.     xmlDoc.resolveExternals = false;
  125.     xmlDoc.load("logcfg.xml");
  126.     currNode = xmlDoc.selectSingleNode("//Logdir");
  127.     strDir = currNode.text;
  128.     var ch = strDir.charAt(strDir.length-1)
  129.     if (ch !='\\')
  130.         strDir+="\\";
  131.     return strDir;
  132. }
  133.  
  134. function TransformXML(xml, xsl)
  135. {
  136.     //load the stylesheet as a DOMDocument.
  137.     var xslProc;
  138.  
  139.     //Create SAX writer.
  140.     var xmlWriter = new ActiveXObject("Msxml2.MXXMLWriter.4.0");
  141.     //Create the stylesheet as a DOMDocument.
  142.     var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0");
  143.     xslDoc.async = false;
  144.     xslDoc.load(gModule);
  145.     
  146.     var xslt = new ActiveXObject("Msxml2.XSLTemplate.4.0");
  147.     
  148.     //Connect the XSLTemplate object to stylesheet DOMDocument.
  149.     xslt.stylesheet = xslDoc;
  150.     
  151.     //Create XSLT processor using stylesheet for XSL template.
  152.     xslProc = xslt.createProcessor();
  153.     
  154.     //Assign XML sample file as input of the transform() method.
  155.     xslProc.input = xml;
  156.     
  157.     //Use a SAX writer as the output of the transform() method.
  158.     xslProc.output = xmlWriter;
  159.     
  160.     //Do transformation on the sample XML file.
  161.     xslProc.transform();
  162.  
  163.     //Use SAX writer ouptut 
  164.     return  xmlWriter.output;