home *** CD-ROM | disk | FTP | other *** search
- ////////////////////////////////////////////////////////////////////////////////////////////
- //
- // PRODUCT: Norton Internet Security/Symantec Desktop Firewall
- //
- // NAME: RuleSummary.js (Javascript file for RuleSummary.HTM)
- //
- // Copyright (c) 2001 by Symantec Corporation. All rights reserved.
- //
- ////////////////////////////////////////////////////////////////////////////////////////////
-
- var xmlRules = null;
- var szMoveUp = StrID("MoveUpB");
- var szMoveDown = StrID("MoveDownB");
- var szAdd = StrID("AddB");
- var szModify = StrID("ModifyB");
- var szRemove = StrID("RemoveB");
- var szRuleType = StrID("UnknownB");
- var g_nRuleProcessed = 0;
- var g_Rules = 0;
- var g_IEVer = GetIEVersion();
- var g_htmlappFullPath = null;
-
- function init()
- {
- xmlRules = window.dialogArguments;
- //
- // Setup the list control
- //
- ruleList.SetTableFont("MS Sans Serif", "75%", "", "");
- ruleList.OnClick = ruleList_OnClick;
- ruleList.OnDblClick = ruleList_OnDblClick;
- ruleList.OnSpace = ruleList_OnSpace;
-
- //
- // Insert app name if the list comes from an application. Otherwise, show straight text
- //
-
- var appName = xmlRules.selectSingleNode("/*/ApplicationDescription");
- if (null != appName)
- {
- var info = xmlRules.selectSingleNode("/*/ApplicationInfo");
- var xmlpath = info.selectSingleNode("ApplicationName");
-
- g_htmlappFullPath = xmlpath.nodeTypedValue;
-
- htmlappPath.innerText = Ellipse_Path(30, g_htmlappFullPath);
- htmlappName.innerText = appName.nodeTypedValue;
-
- szRuleType = "Application";
- htmlapplistline.style.display = "";
- htmlrulelistline.style.display = "none";
-
- htmlHeading.innerText = StrID("AppRuleListTitle");
- document.title = StrID("AppRuleListTitle");
-
-
- }
- else
- {
- htmlapplistline.style.display = "none";
- htmlrulelistline.style.display = "";
-
- if (xmlRules.selectSingleNode("TrojanRules") != null)
- {
- htmlHeading.innerText = StrID("TrojanRuleListTitle");
- document.title = StrID("TrojanRuleListTitle");
- }
- else
- {
- htmlHeading.innerText = StrID("SysRuleListTitle");
- document.title = StrID("SysRuleListTitle");
- }
- }
-
- // Initialize the list
- //
- processRulesForDisplay();
- }
-
- function Ellipse_Path(nMaxLen, szPath)
- {
- var szItems = szPath.split("\\");
- var nItem = 0;
- var nLastStart = 1;
- var szOutput = szPath;
- while(szOutput.length > nMaxLen)
- {
- szOutput = szItems[0];
- szOutput = szOutput + "\\" + "...";
-
- for(nItem = nLastStart; nItem < szItems.length; nItem++)
- {
- szOutput = szOutput + "\\" + szItems[nItem];
- }
-
- nLastStart++;
- }
-
- return szOutput;
- }
-
-
- function updateRules()
- {
- // Since the user clicked OK, this app is now "CUSTOM",
- // even if the user made NO changes!
- //
- // App rules only!
- var appInfoNode = xmlRules.selectSingleNode("/*/ApplicationInfo");
- if(appInfoNode)
- {
- var appAccessNode = xmlRules.selectSingleNode("/*/ApplicationInfo/ApplicationAccess");
- if(appAccessNode == null)
- {
- // create this node...
- appAccessNode = xmlRules.createElement("ApplicationAccess");
- appInfoNode.appendChild(appAccessNode);
- }
- appAccessNode.text = "custom";
- }
-
- //
- // Iterate over each rule listed in our dialog.
- //
- var rules = xmlRules.selectNodes("/*/Rule");
-
- for (var nElem = 0; nElem < rules.length; nElem++)
- {
- //
- // If the user checked this rule (via the nested child INPUT tag), enable it.
- // Otherwise, disable it.
- //
- var node = rules[nElem].selectSingleNode("InUse");
-
- if (null == node)
- continue;
-
- if (ruleList.GetCellPtr(nElem, 0).children[0].checked)
- node.text = "enabled";
- else
- node.text = "disabled";
- }
- return rules.length;
- }
-
- function ruleList_OnClick()
- {
- //
- // Enable the Modify, Delete, Up, and Down buttons
- //
- EnableButton(Modify, true);
- EnableButton(Remove, true);
- EnableButton(MoveUp, true);
- EnableButton(MoveDown, true);
- }
-
- function ruleList_OnDblClick()
- {
- //
- // Emulate a click on the modify button
- //
- if(!Modify.disabled)
- Modify.click();
- }
-
- function ruleList_OnSpace(nRow)
- {
- //
- // Swap the state of the check box for this item
- //
- var CheckBox = ruleList.GetCellPtr(nRow, 0).children[0];
- CheckBox.checked = !CheckBox.checked;
- }
-
- function LoadingList(bLoading)
- {
- if(bLoading)
- {
- ruleListLoading.style.display = "";
- ruleListDIV.style.display = "none";
- docBody.style.cursor = "wait";
- }
- else
- {
- ruleListLoading.style.display = "none";
- ruleListDIV.style.display = "";
- docBody.style.cursor = "";
- }
- }
-
- function processRulesForDisplay(nStep)
- {
- if(nStep == null)
- nStep = 0;
-
- switch(nStep)
- {
- case 0:
- {
- LoadingList(true);
-
- //
- // Reset the list control
- //
- ruleList.DeleteAllRows();
- ruleList.SetColumnCount(3);
- ruleList.SetColumnWidth(0, "15px");
- ruleList.SetColumnWidth(1, "72px");
- ruleList.SetColumnWidth(2, "400px"); // needed for IE4x
-
- //
- // Disable the Modify, Delete, Up, and Down buttons
- //
- EnableButton(Modify, false);
- EnableButton(Remove, false);
- EnableButton(MoveUp, false);
- EnableButton(MoveDown, false);
-
- // Disable these buttons during the load
- EnableButton(Add, false);
- EnableButton(OKB, false);
- EnableButton(CancelB, false);
-
- // DWong 01/15/01 Defect 351342 - Add button text missing
- // innterHTML -> innerHTML
- Add.innerHTML = szAdd;
- Modify.innerHTML = szModify;
- Remove.innerHTML = szRemove;
- MoveUp.innerHTML = szMoveUp;
- MoveDown.innerHTML = szMoveDown;
-
- // Set a timer for step 1 (so the screen will redraw)
- g_nTimerID = window.setInterval("processRulesForDisplay(1)", 0);
- break;
- }
- case 1:
- {
- clearInterval(g_nTimerID);
-
- // Load the rules into the list...
- g_Rules = xmlRules.selectNodes("/*/Rule");
- g_nRuleProcessed = 0;
-
- // DWong 01/12/01 Defect 351101 UI locks up on IE4
- // The slowness comes from the table (ruleList) when we insert rows and columns
- // (inserting column for some reason is extremely slow on IE4)
- //
- // The workaround now is to create a timer to display the rules continuously
- // until all is read. In this case the HTML page will display right away
- // with maybe 5 or 10 rules at first, while the timer still adding rules
- // to the list box
- //
- g_nTimerID = window.setInterval("TimerProcessRule()", 1);
- break;
- }
- case 2:
- {
- clearInterval(g_nTimerID);
- LoadingList(false);
- // DWong 01/19/01 Defect 351342 - On IE4 machines repainting the list box
- // (in LoadingList) causes the button text disappear
- // Reset the text explicitly for the buttons (except Add button, which will be
- // set in EnableButton function) but for IE4 case only
- if (g_IEVer < 5)
- {
- Modify.innerHTML = szModify;
- Remove.innerHTML = szRemove;
- MoveUp.innerHTML = szMoveUp;
- MoveDown.innerHTML = szMoveDown;
- }
- EnableButton(Add, true);
- EnableButton(OKB, true);
- EnableButton(CancelB, true);
-
- OKB.focus();
- break;
- }
- }
- }
-
- function TimerProcessRule()
- {
- // display rules 5 at a time, when we are done clear the timer
- for(var nCount = 0; nCount < 5; nCount++)
- {
- if (g_nRuleProcessed < g_Rules.length)
- {
- processRuleForDisplay(g_Rules[g_nRuleProcessed]);
- g_nRuleProcessed++;
- }
- }
-
- if(g_nRuleProcessed >= g_Rules.length)
- {
- window.clearInterval(g_nTimerID);
-
- // Set a timer for processRulesForDisplay(step 2) (so the screen will redraw)
- g_nTimerID = window.setInterval("processRulesForDisplay(2)", 0);
- }
- }
-
-
- function processRuleForDisplay(rule, pRow)
- {
- var TextString;
- var direction;
- var action = "";
- var Enabled;
-
-
- if ("ENABLED" == getElem(rule, "InUse").toUpperCase())
- Enabled = "checked=yes";
- else
- Enabled = "";
-
-
- TextString = getElem(rule,"Description");
-
- TextString = "<B>" + TextString + "<br></B>" + developRuleString(rule);
-
- switch (getElem(rule,"Direction").toUpperCase())
- {
- case "IN":
- direction= "FROM"
- break;
- case "OUT":
- direction= "TO"
- break;
- case "IN-OUT":
- direction= "BETWEEN"
- break;
- }
-
- switch (getElem(rule, "Action").toLowerCase())
- {
- case "permit":
- action = "ALLOW";
- break;
- case "block":
- action = "BLOCK";
- break;
- case "monitor":
- action = "MONITOR";
- break;
- }
-
- if(pRow == null)
- pRow = ruleList.InsertRow(-1);
- ruleList.SetCellTextPtr(pRow, 0, "<input type=checkbox " + Enabled + ">");
- TextToAdd = "<img src=res://fwui.dll//" + action + "_" + direction + "_256" + ".GIF>";
- ruleList.SetCellTextPtr(pRow, 1, TextToAdd);
- TextToAdd = "<div style='margin-top:6;margin-bottom:6'>" + TextString + "</div>";
- ruleList.SetCellTextPtr(pRow, 2, TextToAdd);
- }
-
-
- function AddB_OnClick()
- {
- var newRule = null;
-
-
- var xmlDefaults = new ActiveXObject("Microsoft.XMLDOM");
- var bValidType = false;
-
- var AppDescription = xmlRules.selectSingleNode("/*/ApplicationDescription");
- if (AppDescription != null)
- {
- // seed it with the application information and a generic rule.
- xmlDefaults.loadXML("<Application/>");
-
- var AppInfo = xmlRules.selectSingleNode("/*/ApplicationInfo");
- var Blankrule = new ActiveXObject("Microsoft.XMLDOM");
- Blankrule.loadXML("<Rule><Description>" + StrID("firewall_rule") + "</Description><CategoryReference>0</CategoryReference><Action>permit</Action><Direction>out</Direction></Rule>");
-
- xmlDefaults.documentElement.appendChild(AppDescription.cloneNode(true));
- xmlDefaults.documentElement.appendChild(AppInfo.cloneNode(true));
- xmlDefaults.documentElement.appendChild(Blankrule.documentElement);
- bValidType = true;
- }
- else if (xmlRules.documentElement.nodeName == "SystemRules")
- {
- xmlDefaults.loadXML("<SystemRules><Rule><Description>" + StrID("firewall_rule") + "</Description><CategoryReference>257</CategoryReference><Action>permit</Action><Direction>out</Direction></Rule></SystemRules>");
- bValidType = true;
- }
- else if (xmlRules.documentElement.nodeName == "TrojanRules")
- {
- 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>");
- bValidType = true;
- }
-
- if (bValidType)
- {
- newRule = webWnd.showModalDialog("res://fwui.dll/addRuleWiz.htm", 550, 400, xmlDefaults);
- if (null != newRule)
- {
- var pRule = xmlRules.documentElement.appendChild(newRule.documentElement.cloneNode(true));
- processRuleForDisplay(pRule);
- }
- }
- else
- {
- webWind.MsgBox2(StrID("InvalidRuleType"), UserManager.AppTitle);
-
- }
- }
-
- function ModifyB_OnClick()
- {
- var ncurrSel = ruleList.GetCurSel();
- if (0 > ncurrSel)
- return;
- var rule = xmlRules.selectSingleNode("/*/Rule["+ncurrSel+"]");
-
- var modifiedRule = webWnd.showModalDialog("res://fwui.dll/modifyRule.htm", 550, 468, rule);
-
- if (null != modifiedRule)
- {
- rule.parentNode.replaceChild(modifiedRule.documentElement.cloneNode(true), rule);
-
- var row = ruleList.GetCurSelPtr();
- var newRule = xmlRules.selectSingleNode("/*/Rule["+ncurrSel+"]");
- processRuleForDisplay(newRule, row);
-
- ruleList.SetCurSel(ncurrSel);
- }
- }
-
-
- function RemoveB_OnClick()
- {
- var ncurrSel = ruleList.GetCurSel();
-
- if (0 > ncurrSel)
- return;
-
- //
- // Ensure any updates to rules in UI are made to data before move.
- //
- updateRules();
-
- var rule = xmlRules.selectSingleNode("/*/Rule["+ncurrSel+"]");
- rule.parentNode.removeChild(rule);
- ruleList.DeleteRow(ncurrSel);
-
- if (ruleList.GetRowCount() <= ncurrSel)
- ncurrSel = ruleList.GetRowCount()-1;
- ruleList.SetCurSel(ncurrSel);
- }
-
-
- function MoveUpB_OnClick()
- {
- var ncurrSel = ruleList.GetCurSel();
-
- if (1 > ncurrSel)
- return;
-
- //
- // Ensure any updates to rules in UI are made to data before move.
- //
- updateRules();
-
- var ruleToMove = xmlRules.selectSingleNode("/*/Rule["+ncurrSel+"]");
- var ruleBefore = xmlRules.selectSingleNode("/*/Rule["+(ncurrSel-1)+"]");
-
- ruleToMove.parentNode.insertBefore(ruleToMove.cloneNode(true), ruleBefore);
- ruleToMove.parentNode.removeChild(ruleToMove);
-
- ruleList.SwapRow(ncurrSel, false);
-
- ruleList.SetCurSel(ncurrSel-1);
- var row = ruleList.GetCurSelPtr();
-
- var oElement = row.offsetParent;
- var iOffsetTop = row.offsetTop;
- var iListTop = oElement.parentElement.scrollTop;
-
- if (iOffsetTop < iListTop)
- row.scrollIntoView(true);
- }
-
- function MoveDownB_OnClick()
- {
- var ncurrSel = ruleList.GetCurSel();
-
- if ((0 > ncurrSel) || (ruleList.GetRowCount()-1 == ncurrSel))
- return;
-
- //
- // Ensure any updates to rules in UI are made to data before move.
- //
- updateRules();
-
- var ruleToMove = xmlRules.selectSingleNode("/*/Rule["+ncurrSel+"]");
- var rule2After = xmlRules.selectSingleNode("/*/Rule["+(ncurrSel+2)+"]");
-
- ruleToMove.parentNode.insertBefore(ruleToMove.cloneNode(true), rule2After);
- ruleToMove.parentNode.removeChild(ruleToMove);
-
- ruleList.SwapRow(ncurrSel, true);
-
- ruleList.SetCurSel(ncurrSel+1);
- var row = ruleList.GetCurSelPtr();
-
- var oElement = row.offsetParent;
- var iOffsetTop = row.offsetTop + row.offsetHeight;
- var iListTop = oElement.parentElement.scrollTop;
- var iBottom = oElement.parentElement.offsetHeight + iListTop;
-
- // if bottom of row is below window, scroll.
- if (iOffsetTop >= iBottom)
- row.scrollIntoView(false);
-
- }
-
- // confirm that the rule list is empty and the user wants to
- // erase this application
-
- function confirm_empty()
- {
- return (webWnd.MsgBox(StrID("RuleSumNoRules"), StrID("RuleSumNoRulesTitle"), 1) == 1);
- }
-
- function OKB_OnClick()
- {
- //
- // Before we leave, go figure out which rules are enabled in the UI
- // and store that info in the rules.
- //
- var n = updateRules();
- var appInfoNode = xmlRules.selectSingleNode("/*/ApplicationInfo");
- if(!appInfoNode)
- n++; // Pretend to have one below... (for system or trojan)
-
- if ((n != 0) || confirm_empty())
- {
- window.returnValue = xmlRules;
- window.navigate('res://closeme.xyz');
- }
- }
-
- function CancelB_OnClickOrReset()
- {
- window.navigate('res://closeme.xyz');
- }
-