home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 May / 05_02.iso / software / nis / files / NIS / NIS.MSI / fwUI.dll / HTML / RULESUMMARY.JS < prev    next >
Encoding:
JavaScript  |  2001-12-01  |  14.6 KB  |  546 lines

  1. ////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // PRODUCT: Norton Internet Security/Symantec Desktop Firewall
  4. //
  5. // NAME:    RuleSummary.js (Javascript file for RuleSummary.HTM)
  6. //
  7. // Copyright (c) 2001 by Symantec Corporation. All rights reserved.
  8. //
  9. ////////////////////////////////////////////////////////////////////////////////////////////
  10.  
  11.     var xmlRules = null;
  12.     var szMoveUp = StrID("MoveUpB");
  13.     var szMoveDown = StrID("MoveDownB");
  14.     var szAdd      = StrID("AddB");
  15.     var szModify  = StrID("ModifyB");
  16.     var szRemove  = StrID("RemoveB");
  17.     var szRuleType = StrID("UnknownB");
  18.     var g_nRuleProcessed = 0;
  19.     var g_Rules = 0;
  20.     var g_IEVer = GetIEVersion();
  21.     var g_htmlappFullPath = null;
  22.  
  23. function init()
  24. {
  25.     xmlRules = window.dialogArguments;
  26.        //
  27.     // Setup the list control
  28.     //
  29.     ruleList.SetTableFont("MS Sans Serif", "75%", "", "");
  30.     ruleList.OnClick = ruleList_OnClick;
  31.     ruleList.OnDblClick = ruleList_OnDblClick;
  32.     ruleList.OnSpace = ruleList_OnSpace;
  33.  
  34.     //
  35.     // Insert app name if the list comes from an application. Otherwise, show straight text
  36.     //
  37.  
  38.     var appName = xmlRules.selectSingleNode("/*/ApplicationDescription");
  39.     if (null != appName)
  40.     {
  41.         var info = xmlRules.selectSingleNode("/*/ApplicationInfo");
  42.         var xmlpath = info.selectSingleNode("ApplicationName");
  43.  
  44.         g_htmlappFullPath = xmlpath.nodeTypedValue; 
  45.  
  46.         htmlappPath.innerText = Ellipse_Path(30, g_htmlappFullPath);
  47.         htmlappName.innerText = appName.nodeTypedValue; 
  48.  
  49.         szRuleType = "Application";
  50.         htmlapplistline.style.display = "";
  51.         htmlrulelistline.style.display = "none"; 
  52.  
  53.         htmlHeading.innerText = StrID("AppRuleListTitle");
  54.         document.title = StrID("AppRuleListTitle");
  55.  
  56.  
  57.     }
  58.     else
  59.     {
  60.         htmlapplistline.style.display = "none";
  61.         htmlrulelistline.style.display = ""; 
  62.  
  63.         if (xmlRules.selectSingleNode("TrojanRules") != null)
  64.         {
  65.             htmlHeading.innerText = StrID("TrojanRuleListTitle");
  66.             document.title = StrID("TrojanRuleListTitle");
  67.         }
  68.         else
  69.         {
  70.             htmlHeading.innerText = StrID("SysRuleListTitle");
  71.             document.title = StrID("SysRuleListTitle");
  72.         }
  73.     }
  74.  
  75.     // Initialize the list
  76.     //
  77.     processRulesForDisplay();
  78. }
  79.  
  80. function Ellipse_Path(nMaxLen, szPath)
  81. {
  82.     var szItems = szPath.split("\\");
  83.     var nItem = 0;
  84.     var nLastStart = 1;
  85.     var szOutput = szPath;
  86.     while(szOutput.length > nMaxLen)
  87.     {
  88.         szOutput = szItems[0];
  89.         szOutput = szOutput + "\\" + "...";
  90.         
  91.         for(nItem = nLastStart; nItem < szItems.length; nItem++)
  92.         {
  93.             szOutput = szOutput + "\\" + szItems[nItem];            
  94.         }
  95.         
  96.         nLastStart++;
  97.     }
  98.     
  99.     return szOutput;
  100. }
  101.  
  102.  
  103. function updateRules()
  104. {
  105.     // Since the user clicked OK, this app is now "CUSTOM",
  106.     // even if the user made NO changes!
  107.     //
  108.     // App rules only!
  109.     var appInfoNode = xmlRules.selectSingleNode("/*/ApplicationInfo");
  110.     if(appInfoNode)
  111.     {
  112.         var appAccessNode = xmlRules.selectSingleNode("/*/ApplicationInfo/ApplicationAccess");
  113.         if(appAccessNode == null)
  114.         {
  115.             // create this node...
  116.             appAccessNode = xmlRules.createElement("ApplicationAccess");
  117.             appInfoNode.appendChild(appAccessNode);
  118.         }
  119.         appAccessNode.text = "custom";
  120.     }
  121.  
  122.     //
  123.     // Iterate over each rule listed in our dialog.
  124.     //
  125.     var rules = xmlRules.selectNodes("/*/Rule");
  126.  
  127.     for (var nElem = 0; nElem < rules.length; nElem++)
  128.     {
  129.         //
  130.         // If the user checked this rule (via the nested child INPUT tag), enable it.
  131.         // Otherwise, disable it.
  132.         //
  133.         var node = rules[nElem].selectSingleNode("InUse");
  134.         
  135.         if (null == node)
  136.             continue;
  137.  
  138.         if (ruleList.GetCellPtr(nElem, 0).children[0].checked)
  139.             node.text = "enabled";
  140.         else
  141.             node.text = "disabled"; 
  142.     }
  143.     return rules.length;
  144. }
  145.  
  146. function ruleList_OnClick()
  147. {
  148.     //
  149.     // Enable the Modify, Delete, Up, and Down buttons
  150.     //
  151.     EnableButton(Modify, true);
  152.     EnableButton(Remove, true);
  153.     EnableButton(MoveUp, true);
  154.     EnableButton(MoveDown, true);
  155. }
  156.  
  157. function ruleList_OnDblClick()
  158. {
  159.     //
  160.     // Emulate a click on the modify button
  161.     //
  162.     if(!Modify.disabled)
  163.         Modify.click();
  164. }
  165.  
  166. function ruleList_OnSpace(nRow)
  167. {
  168.     //
  169.     // Swap the state of the check box for this item
  170.     //
  171.     var CheckBox = ruleList.GetCellPtr(nRow, 0).children[0];
  172.     CheckBox.checked = !CheckBox.checked;
  173. }
  174.  
  175. function LoadingList(bLoading)
  176. {
  177.     if(bLoading)
  178.     {
  179.         ruleListLoading.style.display = "";
  180.         ruleListDIV.style.display = "none";    
  181.         docBody.style.cursor = "wait";
  182.     }
  183.     else
  184.     {
  185.         ruleListLoading.style.display = "none";
  186.         ruleListDIV.style.display = "";        
  187.         docBody.style.cursor = "";
  188.     }
  189. }
  190.  
  191. function processRulesForDisplay(nStep)
  192. {
  193.     if(nStep == null)
  194.         nStep = 0;
  195.  
  196.     switch(nStep)
  197.     {
  198.         case 0:
  199.         {
  200.             LoadingList(true);
  201.  
  202.             //
  203.             // Reset the list control
  204.             //
  205.             ruleList.DeleteAllRows();
  206.             ruleList.SetColumnCount(3);
  207.             ruleList.SetColumnWidth(0, "15px");
  208.             ruleList.SetColumnWidth(1, "72px");
  209.             ruleList.SetColumnWidth(2, "400px");    // needed for IE4x
  210.  
  211.             //
  212.             // Disable the Modify, Delete, Up, and Down buttons
  213.             //
  214.             EnableButton(Modify, false);
  215.             EnableButton(Remove, false);
  216.             EnableButton(MoveUp, false);
  217.             EnableButton(MoveDown, false);
  218.  
  219.             // Disable these buttons during the load
  220.             EnableButton(Add, false);
  221.             EnableButton(OKB, false);
  222.             EnableButton(CancelB, false);
  223.  
  224.             // DWong 01/15/01 Defect 351342 - Add button text missing
  225.             // innterHTML -> innerHTML
  226.             Add.innerHTML = szAdd;
  227.             Modify.innerHTML = szModify;
  228.             Remove.innerHTML = szRemove;
  229.             MoveUp.innerHTML = szMoveUp;
  230.             MoveDown.innerHTML = szMoveDown;
  231.  
  232.             // Set a timer for step 1 (so the screen will redraw)
  233.             g_nTimerID = window.setInterval("processRulesForDisplay(1)", 0);
  234.             break;
  235.         }
  236.         case 1:
  237.         {
  238.             clearInterval(g_nTimerID);
  239.  
  240.             // Load the rules into the list...
  241.             g_Rules = xmlRules.selectNodes("/*/Rule");
  242.             g_nRuleProcessed = 0;
  243.  
  244.             // DWong 01/12/01 Defect 351101 UI locks up on IE4
  245.             // The slowness comes from the table (ruleList) when we insert rows and columns
  246.             // (inserting column for some reason is extremely slow on IE4)
  247.             //
  248.             // The workaround now is to create a timer to display the rules continuously
  249.             // until all is read. In this case the HTML page will display right away
  250.             // with maybe 5 or 10 rules at first, while the timer still adding rules
  251.             // to the list box
  252.             //
  253.             g_nTimerID = window.setInterval("TimerProcessRule()", 1);
  254.             break;
  255.         }
  256.         case 2:
  257.         {
  258.             clearInterval(g_nTimerID);
  259.             LoadingList(false);
  260.             // DWong 01/19/01 Defect 351342 - On IE4 machines repainting the list box
  261.             // (in LoadingList) causes the button text disappear
  262.             // Reset the text explicitly for the buttons (except Add button, which will be
  263.             // set in EnableButton function) but for IE4 case only
  264.             if (g_IEVer < 5)
  265.             {
  266.                 Modify.innerHTML = szModify;
  267.                 Remove.innerHTML = szRemove;
  268.                 MoveUp.innerHTML = szMoveUp;
  269.                 MoveDown.innerHTML = szMoveDown;
  270.             }
  271.             EnableButton(Add, true);
  272.             EnableButton(OKB, true);
  273.             EnableButton(CancelB, true);
  274.             
  275.             OKB.focus();
  276.             break;
  277.         }
  278.     }
  279. }
  280.  
  281. function TimerProcessRule()
  282. {
  283.     // display rules 5 at a time, when we are done clear the timer
  284.     for(var nCount = 0; nCount < 5; nCount++)
  285.     {
  286.         if (g_nRuleProcessed < g_Rules.length)
  287.         {
  288.             processRuleForDisplay(g_Rules[g_nRuleProcessed]);
  289.             g_nRuleProcessed++;
  290.         }
  291.     }
  292.  
  293.     if(g_nRuleProcessed >= g_Rules.length)
  294.     {
  295.         window.clearInterval(g_nTimerID);
  296.  
  297.         // Set a timer for processRulesForDisplay(step 2) (so the screen will redraw)
  298.         g_nTimerID = window.setInterval("processRulesForDisplay(2)", 0);
  299.     }
  300. }
  301.  
  302.  
  303. function processRuleForDisplay(rule, pRow)
  304. {
  305.     var TextString;
  306.     var direction;
  307.     var action = "";
  308.     var Enabled;
  309.  
  310.  
  311.     if ("ENABLED" == getElem(rule, "InUse").toUpperCase())
  312.         Enabled = "checked=yes";
  313.     else
  314.         Enabled = "";
  315.  
  316.  
  317.     TextString = getElem(rule,"Description");
  318.  
  319.     TextString =  "<B>" + TextString + "<br></B>" + developRuleString(rule);
  320.  
  321.      switch (getElem(rule,"Direction").toUpperCase())
  322.     {
  323.         case "IN":
  324.             direction= "FROM"
  325.              break;
  326.         case "OUT":
  327.             direction= "TO"
  328.              break;
  329.         case "IN-OUT":
  330.             direction= "BETWEEN"
  331.             break;
  332.      }
  333.  
  334.     switch (getElem(rule, "Action").toLowerCase())
  335.     {
  336.         case "permit":
  337.             action = "ALLOW";
  338.             break;
  339.         case "block":
  340.             action = "BLOCK";
  341.             break;
  342.         case "monitor":
  343.             action = "MONITOR";
  344.             break;
  345.     }
  346.  
  347.     if(pRow == null)
  348.         pRow = ruleList.InsertRow(-1);
  349.     ruleList.SetCellTextPtr(pRow, 0, "<input type=checkbox " + Enabled + ">");
  350.     TextToAdd = "<img src=res://fwui.dll//" + action + "_" + direction + "_256" + ".GIF>";
  351.     ruleList.SetCellTextPtr(pRow, 1, TextToAdd);
  352.     TextToAdd = "<div style='margin-top:6;margin-bottom:6'>" + TextString + "</div>";
  353.     ruleList.SetCellTextPtr(pRow, 2, TextToAdd);
  354. }
  355.  
  356.  
  357. function AddB_OnClick()
  358. {
  359.     var newRule = null;
  360.  
  361.  
  362.     var xmlDefaults = new ActiveXObject("Microsoft.XMLDOM");
  363.     var bValidType = false;
  364.  
  365.     var AppDescription = xmlRules.selectSingleNode("/*/ApplicationDescription");
  366.     if (AppDescription != null)
  367.     {
  368.         // seed it with the application information and a generic rule.
  369.         xmlDefaults.loadXML("<Application/>");
  370.  
  371.         var AppInfo   = xmlRules.selectSingleNode("/*/ApplicationInfo");
  372.         var Blankrule = new ActiveXObject("Microsoft.XMLDOM");
  373.         Blankrule.loadXML("<Rule><Description>" + StrID("firewall_rule") + "</Description><CategoryReference>0</CategoryReference><Action>permit</Action><Direction>out</Direction></Rule>");
  374.  
  375.         xmlDefaults.documentElement.appendChild(AppDescription.cloneNode(true));
  376.         xmlDefaults.documentElement.appendChild(AppInfo.cloneNode(true));
  377.         xmlDefaults.documentElement.appendChild(Blankrule.documentElement);
  378.         bValidType = true;
  379.     }
  380.     else if (xmlRules.documentElement.nodeName == "SystemRules")
  381.     {
  382.         xmlDefaults.loadXML("<SystemRules><Rule><Description>" + StrID("firewall_rule") + "</Description><CategoryReference>257</CategoryReference><Action>permit</Action><Direction>out</Direction></Rule></SystemRules>");
  383.         bValidType = true;
  384.     }
  385.     else if (xmlRules.documentElement.nodeName == "TrojanRules")
  386.     {
  387.         xmlDefaults.loadXML("<TrojanRules><Rule><Description>" + StrID("default_trojan_rule_title") + "</Description><CategoryReference>258</CategoryReference><Action>block</Action><Direction>out</Direction><Logging>logging,dashboard,dialog</Logging><LogThreshold>1</LogThreshold></Rule></TrojanRules>");
  388.         bValidType = true;
  389.     }
  390.  
  391.     if (bValidType)
  392.     {
  393.         newRule = webWnd.showModalDialog("res://fwui.dll/addRuleWiz.htm", 550, 400, xmlDefaults);
  394.         if (null != newRule)
  395.         {
  396.             var pRule = xmlRules.documentElement.appendChild(newRule.documentElement.cloneNode(true));
  397.             processRuleForDisplay(pRule);
  398.         }
  399.     }
  400.     else
  401.     {
  402.         webWind.MsgBox2(StrID("InvalidRuleType"), UserManager.AppTitle);        
  403.  
  404.     }
  405. }
  406.  
  407. function ModifyB_OnClick()
  408. {
  409.     var ncurrSel = ruleList.GetCurSel();
  410.     if (0 > ncurrSel)
  411.         return;
  412.     var rule = xmlRules.selectSingleNode("/*/Rule["+ncurrSel+"]");
  413.  
  414.     var modifiedRule = webWnd.showModalDialog("res://fwui.dll/modifyRule.htm", 550, 468, rule);
  415.  
  416.     if (null != modifiedRule)
  417.     {
  418.         rule.parentNode.replaceChild(modifiedRule.documentElement.cloneNode(true), rule);
  419.  
  420.         var row = ruleList.GetCurSelPtr();
  421.         var newRule = xmlRules.selectSingleNode("/*/Rule["+ncurrSel+"]");
  422.         processRuleForDisplay(newRule, row);
  423.  
  424.         ruleList.SetCurSel(ncurrSel);
  425.     }
  426. }
  427.  
  428.  
  429. function RemoveB_OnClick()
  430. {
  431.     var ncurrSel = ruleList.GetCurSel();
  432.  
  433.     if (0 > ncurrSel)
  434.         return;
  435.  
  436.     //
  437.     // Ensure any updates to rules in UI are made to data before move.
  438.     //
  439.     updateRules();
  440.  
  441.     var rule = xmlRules.selectSingleNode("/*/Rule["+ncurrSel+"]");
  442.     rule.parentNode.removeChild(rule);
  443.     ruleList.DeleteRow(ncurrSel);
  444.     
  445.     if (ruleList.GetRowCount() <= ncurrSel)
  446.         ncurrSel = ruleList.GetRowCount()-1;
  447.     ruleList.SetCurSel(ncurrSel);
  448. }
  449.  
  450.  
  451. function MoveUpB_OnClick()
  452. {
  453.     var ncurrSel = ruleList.GetCurSel();
  454.     
  455.     if (1 > ncurrSel)
  456.         return;
  457.  
  458.     //
  459.     // Ensure any updates to rules in UI are made to data before move.
  460.     //
  461.     updateRules();
  462.     
  463.     var ruleToMove = xmlRules.selectSingleNode("/*/Rule["+ncurrSel+"]");
  464.     var ruleBefore = xmlRules.selectSingleNode("/*/Rule["+(ncurrSel-1)+"]");
  465.     
  466.     ruleToMove.parentNode.insertBefore(ruleToMove.cloneNode(true), ruleBefore);
  467.     ruleToMove.parentNode.removeChild(ruleToMove);
  468.     
  469.     ruleList.SwapRow(ncurrSel, false);
  470.     
  471.     ruleList.SetCurSel(ncurrSel-1);
  472.     var row = ruleList.GetCurSelPtr();
  473.  
  474.     var oElement = row.offsetParent;
  475.     var iOffsetTop = row.offsetTop;
  476.     var iListTop = oElement.parentElement.scrollTop;
  477.  
  478.     if (iOffsetTop < iListTop)
  479.         row.scrollIntoView(true);
  480. }
  481.  
  482. function MoveDownB_OnClick()
  483. {
  484.     var ncurrSel = ruleList.GetCurSel();
  485.     
  486.     if ((0 > ncurrSel) || (ruleList.GetRowCount()-1 == ncurrSel))
  487.         return;
  488.  
  489.     //
  490.     // Ensure any updates to rules in UI are made to data before move.
  491.     //
  492.     updateRules();
  493.     
  494.     var ruleToMove = xmlRules.selectSingleNode("/*/Rule["+ncurrSel+"]");
  495.     var rule2After = xmlRules.selectSingleNode("/*/Rule["+(ncurrSel+2)+"]");
  496.     
  497.     ruleToMove.parentNode.insertBefore(ruleToMove.cloneNode(true), rule2After);
  498.     ruleToMove.parentNode.removeChild(ruleToMove);
  499.  
  500.     ruleList.SwapRow(ncurrSel, true);
  501.     
  502.     ruleList.SetCurSel(ncurrSel+1);
  503.     var row = ruleList.GetCurSelPtr();
  504.  
  505.     var oElement = row.offsetParent;
  506.     var iOffsetTop = row.offsetTop + row.offsetHeight;
  507.     var iListTop = oElement.parentElement.scrollTop;
  508.     var iBottom  = oElement.parentElement.offsetHeight + iListTop;
  509.  
  510.     // if bottom of row is below window, scroll.
  511.     if (iOffsetTop >= iBottom)
  512.         row.scrollIntoView(false);
  513.  
  514. }
  515.  
  516. // confirm that the rule list is empty and the user wants to
  517. // erase this application
  518.  
  519. function confirm_empty()
  520. {
  521.     return (webWnd.MsgBox(StrID("RuleSumNoRules"), StrID("RuleSumNoRulesTitle"), 1) == 1);
  522. }
  523.  
  524. function OKB_OnClick()
  525. {
  526.     //
  527.     // Before we leave, go figure out which rules are enabled in the UI
  528.     // and store that info in the rules.
  529.     //
  530.     var n = updateRules();
  531.     var appInfoNode = xmlRules.selectSingleNode("/*/ApplicationInfo");
  532.     if(!appInfoNode)
  533.         n++;    // Pretend to have one below... (for system or trojan)
  534.         
  535.     if ((n != 0) || confirm_empty())
  536.     {
  537.         window.returnValue = xmlRules;
  538.         window.navigate('res://closeme.xyz');
  539.     }
  540. }
  541.  
  542. function CancelB_OnClickOrReset()
  543. {
  544.     window.navigate('res://closeme.xyz');
  545. }
  546.