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.
- //
- ////////////////////////////////////////////////////////////////////////////////////////////
-
- // Global Variables
-
- var szRuleType = StrID("UnknownB");
- var g_nNumAdminRules = 0;
- var g_IEVer = GetIEVersion();
- var g_htmlappFullPath = null;
- var g_RuleList = null; // List of rules
- var g_NumRules = 0;
- var g_nRulesProcessed = 0;
- var g_bInitialized = false;
- var g_sLocation = "";
-
- var MB_OK = 0;
- var MB_OKCANCEL = 1;
- var IDCANCEL = 2;
-
-
- function init()
- {
- g_RuleList = window.dialogArguments;
-
- UserManager.WatchForFREIntegStart();
-
- //
- // Setup the list control
- //
- ruleList.SetTableFont("MS Sans Serif", "75%", "", "");
- ruleList.OnClick = ruleList_OnClick;
- ruleList.OnDblClick = ruleList_OnDblClick;
- ruleList.OnSpace = ruleList_OnSpace;
-
- var RLevelStatus = new ActiveXObject("RLevel.NISStatusInfo");
- var bLAIsOn = RLevelStatus.LocationAwarenessEnabled;
- if(bLAIsOn)
- {
- LocationAwarenessIsOffText.innerText = " ";
- RuleSummary_SELECT_LocationDropDown.style.width = "400px";
- }
-
- //
- // Insert app name if the list comes from an application. Otherwise, show straight text
- //
-
- if(g_RuleList.ApplicationDescription != "")
- {
- g_htmlappFullPath = g_RuleList.ApplicationPath;
-
- htmlappPath.innerText = Ellipse_Path(30, g_htmlappFullPath);
- htmlappName.innerText = g_RuleList.ApplicationDescription;
-
- 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 (g_RuleList.Type == 1)
- {
- htmlHeading.innerText = StrID("TrojanRuleListTitle");
- document.title = StrID("TrojanRuleListTitle");
- }
- else
- {
- htmlHeading.innerText = StrID("SysRuleListTitle");
- document.title = StrID("RuleListMenuTitle");
- }
-
- CancelB.style.display = "none";
- }
-
- // add all locations to the dropdown
- Location_PopulateDropDown(RuleSummary_SELECT_LocationDropDown);
-
- //select the FilterByLocation
- if (g_RuleList.FilterByLocation != "")
- {
- for (var i=RuleSummary_SELECT_LocationDropDown.length-1; i>=0; i--)
- {
- var oOption = RuleSummary_SELECT_LocationDropDown.options[i];
- var sOption = Location_GetDropDownSelectedItemText(oOption);
- if (sOption == g_RuleList.FilterByLocation)
- {
- RuleSummary_SELECT_LocationDropDown.selectedIndex = i;
- break;
- }
- }
- }
-
- OnLocationDropListChange(RuleSummary_SELECT_LocationDropDown.options[RuleSummary_SELECT_LocationDropDown.selectedIndex]);
- }
-
- function UserManager_OnFREIntegratorStart()
- {
- window.navigate('res://closeme.xyz');
- }
-
- function OnLocationDropListChange(oSelectedOption)
- {
- if(g_bInitialized)
- {
- updateRules();
- }
-
- g_sLocation = Location_GetDropDownSelectedItemText(oSelectedOption);
- g_RuleList.FilterByLocation = g_sLocation;
- g_NumRules = g_RuleList.ItemCount;
-
- // Initialize the list
- g_nRulesProcessed = 0;
- g_nNumAdminRules = 0;
- processRulesForDisplay();
- g_bInitialized = true;
- }
-
-
-
- function RefreshRules()
- {
- g_RuleList.FilterByLocation = g_sLocation;
-
- // Initialize the list
- g_nRulesProcessed = 0;
- g_nNumAdminRules = 0;
- processRulesForDisplay();
- g_bInitialized = true;
- }
-
- 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!
- if(g_RuleList.ApplicationDescription != "")
- {
- g_RuleList.AppAccess = 3; // Set app access to custom
- }
-
- UpdateRulesInUseStatus();
-
- return length;
- }
-
- function ruleList_OnClick()
- {
- //
- // Enable or Disable the Modify, Delete, Up, and Down buttons
- //
- var ncurrSel = ruleList.GetCurSel();
- var bEnable = false;
-
- if (0 > ncurrSel)
- return;
-
- var rule = g_RuleList.GetItem(ncurrSel);
-
- if(null == rule)
- return;
-
- if(UserManager.CurrentUserType == "UT_SUPERVISOR")
- bEnable = true;
- else if( usingClientRules() && (UserManager.CurrentUserType == "UT_NORMAL") && (rule.Priority == 1) )
- bEnable = true;
-
- EnableButton(Modify, bEnable);
- EnableButton(Remove, bEnable);
- EnableButton(MoveUp, bEnable);
- EnableButton(MoveDown, bEnable);
- }
-
- function ruleList_OnDblClick()
- {
- var ncurrSel = ruleList.GetCurSel();
- var bEnable = false;
-
- if (0 > ncurrSel)
- return;
-
- var rule = g_RuleList.GetItem(ncurrSel);
-
- if(null == rule)
- return;
-
- if(UserManager.CurrentUserType == "UT_SUPERVISOR")
- bEnable = true;
- else if( usingClientRules() && (UserManager.CurrentUserType == "UT_NORMAL") && (rule.Priority == 1) )
- bEnable = true;
- //
- // Emulate a click on the modify button
- //
- if(bEnable)
- {
- if(!Modify.disabled)
- Modify.click();
- }
- }
-
- function ruleList_OnSpace(nRow)
- {
- var ncurrSel = ruleList.GetCurSel();
- var bEnable = false;
-
- if (0 > ncurrSel)
- return;
-
- var rule = g_RuleList.GetItem(ncurrSel);
-
- if(null == rule)
- return;
-
- if(UserManager.CurrentUserType == "UT_SUPERVISOR")
- bEnable = true;
- else if( usingClientRules() && (UserManager.CurrentUserType == "UT_NORMAL") && (rule.Priority == 1) )
- bEnable = true;
-
- //
- // Swap the state of the check box for this item
- //
- if(bEnable)
- {
- var CheckBox = ruleList.GetCellPtr(nRow, 0).children[0];
- CheckBox.checked = !CheckBox.checked;
- }
- }
-
- function LoadingList(bLoading)
- {
- RuleSummary_SELECT_LocationDropDown.disabled = 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:
- {
- OKB.focus();
- LoadingList(true);
-
- //
- // Reset the list control
- //
- ruleList.DeleteAllRows();
- ruleList.SetColumnCount(4);
- ruleList.SetColumnWidth(0, "15px");
-
- if(usingClientRules())
- ruleList.SetColumnWidth(1, "40px");
- else
- ruleList.SetColumnWidth(1, "0px");
-
- ruleList.SetColumnWidth(2, "72px");
- ruleList.SetColumnWidth(3, "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 // ejp 2003june05 we require ie 5.x now so this is a non-issue
- // 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);
-
- // 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()
- {
- // If we are not done processing Admin Rules, continue
- if(g_nRulesProcessed < g_NumRules)
- {
- // display rules 5 at a time, when we are done clear the timer
- for(var nCount = 0; nCount < 5; nCount++)
- {
- var rule;
- if (g_nRulesProcessed == 0) rule = g_RuleList.GetFirst();
- else rule = g_RuleList.GetNext();
-
- if(null != rule)
- {
- processRuleForDisplay(rule);
- g_nRulesProcessed++;
-
- if(rule.Priority == 0)
- g_nNumAdminRules++;
- }
- else
- break;
- }
- }
- // Else we're done processing rules, continue initialization of rules list
- else
- {
- 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, nRow)
- {
- var TextString;
- var direction;
- var action = "";
- var Enabled;
- var checkboxString = "";
-
- if (rule.IsInUseForLocation(g_sLocation))
- Enabled = "checked=yes";
- else
- Enabled = "";
-
-
- TextString = rule.Description;
-
- TextString = "<B>" + TextString + "<br></B>" + developRuleString(rule);
-
- switch (rule.Direction)
- {
- case 2: // IN
- direction= "FROM"
- break;
- case 1: // OUT
- direction= "TO"
- break;
- case 3: // IN-OUT
- direction= "BETWEEN"
- break;
- }
-
- switch (rule.Action)
- {
- case 2: // Permit
- action = "ALLOW";
- break;
- case 1: // Block
- action = "BLOCK";
- break;
- case 4: // Monitor
- action = "MONITOR";
- break;
- }
-
- if((pRow == null) && (nRow == null))
- pRow = ruleList.InsertRow(-1);
- else if((pRow == null) && (nRow != null))
- pRow = ruleList.InsertRow(nRow);
-
- checkboxString = "<input type=checkbox " + Enabled + " ";
-
- if( usingClientRules() && (rule.Priority == 0) && (UserManager.CurrentUserType != "UT_SUPERVISOR") )
- checkboxString += "disabled";
-
- checkboxString += ">";
-
- ruleList.SetCellTextPtr(pRow, 0, checkboxString);
-
- if(usingClientRules())
- {
- if(rule.Priority == 0)
- ruleList.SetCellTextPtr(pRow, 1, "<font type=bold color=red>Admin</font>");
- else
- ruleList.SetCellTextPtr(pRow, 1, "<font type=bold color=blue>User</font>");
- }
-
- TextToAdd = "<img src=res://fwui.dll//" + action + "_" + direction + "_256" + ".GIF>";
- ruleList.SetCellTextPtr(pRow, 2, TextToAdd);
- TextToAdd = "<div style='margin-top:6;margin-bottom:6'>" + TextString + "</div>";
- ruleList.SetCellTextPtr(pRow, 3, TextToAdd);
- }
-
-
- function AddB_OnClick()
- {
- var newRule = null;
- var rule = new ActiveXObject("ccFWSettg.Rule");
-
- rule.ApplicationDescription = g_RuleList.ApplicationDescription;
- rule.ApplicationPath = g_RuleList.ApplicationPath;
- rule.Type = g_RuleList.Type;
-
- webWnd.SetIcon2("res://NisRes.dll/105");
- newRule = webWnd.showModalDialog("res://fwui.dll/addRuleWiz.htm", 550, 415, rule);
-
- if (null != newRule)
- {
- var index = null;
-
- g_RuleList.LastError = 0;
- g_RuleList.AppendItem(newRule);
-
- if(HandleListError(g_RuleList.LastError, 1008, 116))
- return;
-
- if (newRule.IsInUseForLocation(g_sLocation))
- {
- //Update the number of rules. Do not increment, because the new rule might have been merged.
- g_NumRules = g_RuleList.ItemCount;
- RefreshRules();
- }
- }
- }
-
- function ModifyB_OnClick()
- {
- var ncurrSel = ruleList.GetCurSel();
- if (0 > ncurrSel)
- return;
-
- var rule = g_RuleList.GetItem(ncurrSel);
-
- if(null != rule)
- {
- var oldPriority = rule.Priority;
-
- var ruleCopy = new ActiveXObject("ccFWSettg.Rule");
- ruleCopy.CopyFrom(rule);
-
- ruleCopy.ApplicationDescription = g_RuleList.ApplicationDescription;
-
- webWnd.SetIcon2("res://NisRes.dll/105");
- ruleCopy = webWnd.showModalDialog("res://fwui.dll/modifyRule.htm", 550, 468, ruleCopy);
-
- if (null != ruleCopy)
- {
- ruleCopy.ClearLocations();
- ruleCopy.AddToLocation( g_sLocation );
-
- if(ruleCopy.Priority == oldPriority)
- {
- ruleList.DeleteRow(ncurrSel);
-
- g_RuleList.LastError = 0;
-
- g_RuleList.InsertItem(rule, ruleCopy);
-
- if(HandleListError(g_RuleList.LastError, 1008, 116))
- return;
-
- g_RuleList.DeleteItem(rule);
-
- processRuleForDisplay(ruleCopy, null, ncurrSel);
- }
- else
- {
- ruleList.DeleteRow(ncurrSel);
-
- var index = null;
-
- if(ruleCopy.Priority == 0)
- {
- index = g_nNumAdminRules;
- g_nNumAdminRules++;
- }
- else
- {
- g_nNumAdminRules--;
- }
-
- g_RuleList.LastError = 0;
- g_RuleList.AppendItem(ruleCopy);
- if(HandleListError(g_RuleList.LastError, 1008, 117))
- return;
- g_RuleList.DeleteItem(rule);
-
- processRuleForDisplay(ruleCopy, null, index);
- }
-
- 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();
-
- // Delete the rule from the rule list object
- var rule = g_RuleList.GetItem(ncurrSel);
-
- if(null != rule)
- {
- webWnd.SetIcon2("res://NisRes.dll/105");
-
- if(webWnd.MsgBox(StrID("DeleteRulePrompt"), UserManager.ProductName, MB_OKCANCEL) == IDOK)
- {
- if(rule.Priority == 0)
- g_nNumAdminRules--;
-
- var nLocations = rule.NumLocations;
- if (nLocations == 1 ||
- webWnd.MsgBox(StrID("RemoveRuleFromAllLocations?"), UserManager.ProductName, MB_YESNO) == IDNO)
- {
- g_RuleList.DeleteItem(rule);
- }
- else
- g_RuleList.DeleteItemFromAllLocations(rule);
-
- ruleList.DeleteRow(ncurrSel);
- g_NumRules--;
-
- if (ruleList.GetRowCount() <= ncurrSel)
- ncurrSel = ruleList.GetRowCount()-1;
-
- ruleList.SetCurSel(ncurrSel);
- }
- }
- }
-
-
- function MoveUpB_OnClick()
- {
- var ncurrSel = ruleList.GetCurSel();
-
- if(ncurrSel == 0)
- return;
-
- //
- // Ensure any updates to rules in UI are made to data before move.
- //
- updateRules();
-
- var rule = g_RuleList.GetItem(ncurrSel);
- var ruleBefore = g_RuleList.GetItem(ncurrSel - 1);
-
- var newRule = new ActiveXObject("CcFWSettg.Rule");
- newRule.CopyFrom(rule);
- newRule.ClearLocations();
- newRule.AddToLocation(g_sLocation);
-
- // Swap the rules in the RuleList Object
- if(rule.Priority == 0)
- {
- g_RuleList.LastError = 0;
- g_RuleList.InsertItem(ruleBefore, newRule);
- if(HandleListError(g_RuleList.LastError, 1008, 121))
- return;
- g_RuleList.DeleteItem(rule);
- }
- else
- {
- if(ruleBefore.Priority == 0)
- return;
- else
- {
- g_RuleList.LastError = 0;
- g_RuleList.InsertItem(ruleBefore, newRule);
- if(HandleListError(g_RuleList.LastError, 1008, 122))
- return;
- g_RuleList.DeleteItem(rule);
- }
- }
-
- 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 it's the last rule then do nothing
- if(ncurrSel == (g_NumRules - 1))
- return;
-
- //
- // Ensure any updates to rules in UI are made to data before move.
- //
- updateRules();
-
- var rule = g_RuleList.GetItem(ncurrSel);
- var ruleNext = g_RuleList.GetItem(ncurrSel + 1);
- var ruleBefore = null;
-
- if((ncurrSel+2) < g_NumRules)
- ruleBefore = g_RuleList.GetItem(ncurrSel + 2);
-
- var newRule = new ActiveXObject("CcFWSettg.Rule");
- newRule.CopyFrom(rule);
- newRule.ClearLocations();
- newRule.AddToLocation(g_sLocation);
-
- // Swap the rules in the RuleList Object
- if(rule.Priority == 0)
- {
- if((null != ruleNext) && (ruleNext.Priority == 1))
- return;
-
- g_RuleList.LastError = 0;
- if(null != ruleBefore)
- g_RuleList.InsertItem(ruleBefore, newRule);
- else
- g_RuleList.AppendItem(newRule);
-
- if(HandleListError(g_RuleList.LastError, 1008, 124))
- return;
-
- g_RuleList.DeleteItem(rule);
- }
- else
- {
- g_RuleList.LastError = 0;
- if(null != ruleBefore)
- g_RuleList.InsertItem(ruleBefore, newRule);
- else
- g_RuleList.AppendItem(newRule);
-
- if(HandleListError(g_RuleList.LastError, 1008, 125))
- return;
-
- g_RuleList.DeleteItem(rule);
- }
-
- 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, determine if there are no rules left (for application rules only).
- // If so, we prompt the user to be sure this is what they meant and to let them know
- // that the application entry will go away.
- //
- var n = updateRules();
-
- //
- // Only if the user agreed (or there's no problem), do we save and exit.
- //
- if (("" == g_RuleList.ApplicationDescription) || (n != 0) || confirm_empty())
- {
- window.returnValue = g_RuleList;
- window.navigate('res://closeme.xyz');
- }
- }
-
- function CancelB_OnClickOrReset()
- {
- window.navigate('res://closeme.xyz');
- }
-
-
- function UpdateRulesInUseStatus()
- {
- g_RuleList.FilterByLocation = g_sLocation;
- var nElem = -1;
-
- for (var rule = g_RuleList.GetFirst(); rule != null; rule = g_RuleList.GetNext())
- {
- nElem++;
- var bChanged = false;
- //
- // If the user checked this rule (via the nested child INPUT tag), enable it.
- // Otherwise, disable it.
- //
- var newRule = new ActiveXObject("ccFWSettg.Rule");
-
- newRule.CopyFrom(rule);
- newRule.ClearLocations();
- newRule.AddToLocation(g_sLocation);
-
- if (null == rule)
- continue;
-
- if (ruleList.GetCellPtr(nElem, 0).children[0].checked)
- {
- if(rule.IsInUseForLocation(g_sLocation) == false)
- {
- bChanged = true;
- }
- newRule.ClearInUseLocations();
- newRule.AddInUseLocation(g_sLocation);
- }
- else
- {
- if(rule.IsInUseForLocation(g_sLocation) == true)
- {
- bChanged = true;
- }
-
- newRule.ClearInUseLocations();
- newRule.RemoveInUseLocation(g_sLocation);
- }
-
- // Fix for defect# 394925
- // This is how you write the settings back to the driver
- if(bChanged==true)
- {
- g_RuleList.LastError = 0;
- g_RuleList.InsertItem(rule, newRule);
- if(HandleListError(g_RuleList.LastError, 1008, 128))
- break;
-
- g_RuleList.DeleteItem(rule);
- }
- }
- }
-
-