home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2004 July / APC0407D1.iso / powerkit / firewall / files / NPF2004.exe / Setup / ISCommon / APP / fwUI.dll / HTML / RULECREATION.JS < prev    next >
Encoding:
JavaScript  |  2003-09-06  |  27.0 KB  |  1,264 lines

  1. ////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // PRODUCT: Norton Internet Security/Symantec Desktop Firewall
  4. //
  5. // NAME:    ruleCreation.js (Javascript file for ruleCreation.HTM)
  6. //
  7. // Copyright (c) 2001 by Symantec Corporation. All rights reserved.
  8. //
  9. ////////////////////////////////////////////////////////////////////////////////////////////
  10.     var MB_OK =                     0x00000000;
  11.     var MB_OKCANCEL =               0x00000001;
  12.     var MB_ABORTRETRYIGNORE =       0x00000002;
  13.     var MB_YESNOCANCEL =            0x00000003;
  14.     var MB_YESNO =                  0x00000004;
  15.     var MB_RETRYCANCEL =            0x00000005;
  16.         
  17.     var MB_ICONHAND =               0x00000010;
  18.     var MB_ICONQUESTION =           0x00000020;
  19.     var MB_ICONEXCLAMATION =        0x00000030;
  20.     var MB_ICONASTERISK  =          0x00000040;
  21.         
  22.     var MB_USERICON =               0x00000080;
  23.     var MB_ICONWARNING =            MB_ICONEXCLAMATION;
  24.     var MB_ICONERROR =              MB_ICONHAND;
  25.         
  26.     var MB_ICONINFORMATION =        MB_ICONASTERISK;
  27.     var MB_ICONSTOP =               MB_ICONHAND;
  28.         
  29.     var IDOK =              1;
  30.     var IDCANCEL =          2;
  31.     var IDABORT =           3;
  32.     var IDRETRY =           4;
  33.     var IDIGNORE =          5;
  34.     var IDYES =             6;
  35.     var IDNO =              7;
  36.  
  37.     var CurrPage = "Action";
  38.     var g_appName = "";
  39.     var g_bIgnoreLocations = false;
  40.  
  41.     returnValue = null;
  42.  
  43. function Page_OnLoad()
  44. {
  45.     // Set the title...
  46.     window.title = UserManager.ProductName;
  47.  
  48.     var bLAIsOn = RLevel.LocationAwarenessEnabled;
  49.     if(bLAIsOn)
  50.     {
  51.         LocationAwarenessIsOffText.innerText = " ";
  52.     }
  53.     
  54.     //
  55.     // Special onload section
  56.     //
  57.     IPList_OnLoad();
  58.     PortList_OnLoad();
  59.  
  60.     //
  61.     // Register special handlers
  62.     //
  63.     IPAdd.onclick = IPAdd_OnClick;
  64.     IPRemove.onclick = IPRemove_OnClick;
  65.     PortsAdd.onclick = PortsAdd_OnClick;
  66.     PortsRemove.onclick = PortsRemove_OnClick;
  67.     IPAdapters.onclick = IPAdapters_OnClick;
  68. }
  69.  
  70. function ruleTellMeMore()
  71. {
  72.     TellMeMore("RuleEdit" + CurrPage);
  73. }
  74.  
  75. function SetActionText(bOnAdd)
  76. {
  77.     DirectinSetText();
  78.     IPSetText();
  79.     PortSetText();
  80.  
  81.     if(bOnAdd == true)
  82.     {
  83.         LoggingSetText();
  84.     }
  85. }
  86.  
  87. function HideAll()
  88. {
  89.     UIAction.style.display = "none";
  90.     UIDirection.style.display = "none";
  91.     UIIP.style.display = "none";
  92.     UIPorts.style.display = "none";
  93.     UILogging.style.display = "none";
  94.     UITitle.style.display = "none";
  95.     UIType.style.display = "none";
  96.     UILocations.style.display = "none";
  97.     UIFinish.style.display = "none";
  98. }
  99.  
  100. function SetPage(Name, Page)
  101. {
  102.     var Page = null;
  103.     CurrPage = Name;
  104.     HideAll();
  105.  
  106.     //
  107.     // Find the correct page to display
  108.     //
  109.     switch(CurrPage)
  110.     {
  111.         case "Action":
  112.             Page = UIAction;
  113.             break;
  114.         case "Direction":
  115.             Page = UIDirection;
  116.             break;
  117.         case "IP":
  118.             Page = UIIP;
  119.             break;
  120.         case "Ports":
  121.             Page = UIPorts;
  122.             break;
  123.         case "Logging":
  124.             Page = UILogging;
  125.             break;
  126.         case "Title":
  127.             Page = UITitle;
  128.             break;
  129.         case "Locations":    
  130.             Page = UILocations;
  131.             UILocation_UpdateNextButtonState();
  132.             break;
  133.         case "Type":
  134.             Page = UIType;
  135.             break;
  136.         case "Finished":
  137.             Page = UIFinish;
  138.     }
  139.  
  140.     if (false)
  141.     {
  142.         //
  143.         // Use this code if you want a fade transition.
  144.         //
  145.         Page.children[0].style.visibility="hidden";
  146.         Page.style.display = "";
  147.         Page.children[0].style.filter="blendTrans(duration=0.20)";
  148.         Page.children[0].filters.blendTrans.apply();
  149.         Page.children[0].style.visibility="visible";
  150.         Page.children[0].filters.blendTrans.play();
  151.     }
  152.     else
  153.     {
  154.         //
  155.         // "Normal" transition with no effects.
  156.         //
  157.         Page.style.display = "";
  158.     }
  159.  
  160. }
  161.  
  162. function saveRule()
  163. {
  164.     UIActionStore(g_rule);
  165.     UIDirectionStore(g_rule);
  166.     UIIPStore(g_rule);
  167.  
  168.     UIAdapterStore(g_rule);
  169.     UIPortsStore(g_rule);
  170.  
  171.     UILoggingStore(g_rule);
  172.     UITitleStore(g_rule);
  173.     UITypeStore(g_rule);
  174.  
  175.     // Set rule InUse to true;
  176.     g_rule.InUse = true;
  177.  
  178. // &!SWM - Remove this
  179.     //g_rule.RemoteIPs = g_ipList;
  180.     //g_rule.LocalIPs = g_AdapterList;
  181.     //g_rule.LocalPorts = g_LocalPorts;
  182.     //g_rule.RemotePorts = g_RemotePorts;
  183.  
  184.     if (!g_bIgnoreLocations)
  185.     {
  186.         var arrayLocations = Location_GetListBoxSelectedItems(locationList);
  187.         for(var i = 0; i < arrayLocations.length; i++)
  188.         {
  189.             g_rule.AddToLocation(arrayLocations[i]);
  190.             g_rule.AddInUseLocation(arrayLocations[i]);
  191.         }
  192.     }
  193.     
  194.     return g_rule;
  195. }
  196.  
  197.  
  198. function init(rule, szRuleType, appName, bIgnoreLocations)
  199. {
  200.     g_appName = appName;
  201.     g_rule = rule;
  202.     g_ipList = g_rule.RemoteIPs;
  203.     if (null == bIgnoreLocations)
  204.         bIgnoreLocations = false;
  205.     g_bIgnoreLocations = bIgnoreLocations;
  206.  
  207.     UIActionLoad(g_rule);
  208.     UIDirectionLoad(g_rule);
  209.     UIIPLoad(g_rule);
  210.     UIAdapterLoad(g_rule);
  211.     UIPortsLoad(g_rule);
  212.     UILoggingLoad(g_rule);
  213.     UITitleLoad(g_rule);
  214.     UITypeLoad(g_rule);
  215.     UILocationsLoad();
  216.  
  217.     // don't allow ICMP protocol on application rules
  218.     if ("" != rule.ApplicationDescription)
  219.     {
  220.         nonappitems.style.display ="none";
  221.     }
  222.  
  223.     SetActionText(false);
  224. }
  225.  
  226. function validateAll()
  227. {
  228.  
  229.     if (!ActionValidate())
  230.     {
  231.         return("Action");
  232.     }
  233.     if (!DirectionValidate())
  234.     {
  235.         return("Direction");
  236.     }
  237.        if (!IPValidate())
  238.     {
  239.         return("IP");
  240.     }
  241.     if (!ProtocolAndPortValidate())
  242.     {
  243.         return("Ports");
  244.     }
  245.     if (!TitleValidate())
  246.     {
  247.         return("Title");
  248.     }
  249.  
  250.     return null;
  251. }
  252.  
  253.  
  254. ////////////////////////////////////////////////////////////////////////////////////
  255. //  Select Rule Action page
  256. //
  257.  
  258. function UIActionStore(rule)
  259. {
  260.     if(Action[0].checked)
  261.         rule.Action = 2;
  262.     else if(Action[1].checked)
  263.         rule.Action  = 1;
  264.     else if(Action[2].checked)
  265.         rule.Action = 4;
  266. }
  267.  
  268. function UIActionLoad(rule)
  269. {
  270.     nElem = 0;
  271.  
  272.     switch(rule.Action)
  273.     {
  274.         case 2: // Permit
  275.             nElem = 0;
  276.             break;
  277.         case 1: // Block
  278.             nElem = 1;
  279.             break;
  280.         case 4: // Monitor
  281.             nElem = 2;
  282.             break;
  283.     }
  284.     
  285.     Action[nElem].checked = true;
  286. }
  287.  
  288.  
  289. function  RuleActionHandler()
  290. {
  291.     SetActionText(true);
  292. }
  293.  
  294. function ActionValidate()
  295. {
  296.     return true;
  297. }
  298.  
  299. ////////////////////////////////////////////////////////////////////////////////////
  300. //  Determine traffic direction page
  301. //
  302. function UIDirectionStore(rule)
  303. {
  304.     if(Direction[0].checked)
  305.         rule.Direction = 1;
  306.     else if(Direction[1].checked)
  307.         rule.Direction = 2;
  308.     else if(Direction[2].checked)
  309.         rule.Direction = 3;
  310. }
  311.  
  312. function UIDirectionLoad(rule)
  313. {
  314.     nElem = 0;
  315.  
  316.     switch(rule.Direction)
  317.     {
  318.         case 1: // Out
  319.             nElem = 0;
  320.             break;
  321.         case 2: // In
  322.             nElem = 1;
  323.             break;
  324.         case 3: // In-Out
  325.             nElem = 2;
  326.             break;
  327.     }
  328.     
  329.     Direction[nElem].checked = true;
  330. }
  331.  
  332.  
  333. function DirectinSetText()
  334. {
  335.     DirPermitRule.style.display = "none";
  336.     DirBlockRule.style.display = "none";
  337.     DirMonitorRule.style.display = "none";
  338.  
  339.     if (Action[0].checked)
  340.         DirPermitRule.style.display = "";
  341.  
  342.     if (Action[1].checked)
  343.         DirBlockRule.style.display = "";
  344.  
  345.     if (Action[2].checked)
  346.         DirMonitorRule.style.display = "";
  347. }
  348.  
  349. function DirectionValidate()
  350. {
  351.     return true;
  352. }
  353.  
  354. ////////////////////////////////////////////////////////////////////////////////////
  355. //  Remote Sites/Zones to Block page
  356. //
  357.  
  358. var g_ipList = null;
  359. var g_AdapterList = null;
  360.  
  361. var currentActionState = null;
  362.  
  363. function IPList_OnClick()
  364. {
  365.     // Enable the modify/delete buttons
  366.     EnableButton(IPRemove,true);
  367. }
  368.  
  369. function IPCtlsEnabled(enable)
  370. {
  371.  
  372.     EnableButton(IPAdd,enable);
  373.  
  374.     //
  375.     // Only allow this button to be disabled. Be sure to remove
  376.     // selection too.
  377.     //
  378.     if (!enable)
  379.     {
  380.         EnableButton(IPRemove,enable);
  381.         IPList.SetCurSel(-1);
  382.     }
  383.  
  384.     //
  385.     // Enable radio buttons appropriately.
  386.     //
  387.     Addresses[0].checked = !enable;
  388.     Addresses[1].checked = enable;
  389. }
  390.  
  391. function UIIPStore(rule)
  392. {
  393.     //
  394.     // If the user didn't narrow this down, delete everthing
  395.     // in the list
  396.     //
  397.     if(Addresses[0].checked)
  398.     {
  399.         if(g_ipList != null)
  400.             g_ipList.DeleteAll();
  401.         else
  402.             g_ipList = new ActiveXObject("ccFWSettg.IPList");
  403.     }
  404.  
  405.     //
  406.     // Save data.
  407.     //
  408.     // &!SWM - Remove This rule.RemoteIPs = g_ipList;
  409. }
  410.  
  411. function UIAdapterStore(rule)
  412. {
  413.     //
  414.     // Save data.
  415.     //
  416.     // &!SWM - Remove This rule.LocalIPs = g_AdapterList;
  417. }
  418.  
  419. function UIIPLoad(rule)
  420. {
  421.     IPList_OnLoad();
  422.  
  423.     //
  424.     // Check to see if any addresses were specified.
  425.     //  
  426.     refreshIPList();
  427. }
  428.  
  429. function UIAdapterLoad(rule)
  430. {
  431.     g_AdapterList = rule.LocalIPs;
  432.     refreshAdapters();
  433. }
  434.  
  435. function refreshIPList()
  436. {
  437.     //
  438.     // Reset the list control
  439.     //
  440.     IPList.DeleteAllRows();
  441.     IPList.SetColumnCount(2);
  442.  
  443.     var bEnableList = false;
  444.  
  445.     var curIP = g_ipList.GetFirst();
  446.  
  447.     while(null != curIP)
  448.     {
  449.         // If the ip item is a Network...
  450.         if(curIP.Type == 3)
  451.         {
  452.             var text = StrID("IP") + ": " + curIP.NetworkIP + "<BR>" + StrID("Mask") + ": " + curIP.NetworkMask;
  453.  
  454.             pRow = IPList.InsertRow(-1);
  455.             IPList.SetCellTextPtr(pRow, 0, StrID("NetworkAddress"));
  456.             IPList.SetCellTextPtr(pRow, 1, text);
  457.         }
  458.         // If the IP item is a range...
  459.         else if(curIP.Type == 2)
  460.         {
  461.             var text = StrID("From") + ": " + curIP.RangeStart + "<BR>" + StrID("To") + ": " + curIP.RangeEnd;
  462.  
  463.             pRow = IPList.InsertRow(-1);
  464.             IPList.SetCellTextPtr(pRow, 0, StrID("AddressRange"));
  465.             IPList.SetCellTextPtr(pRow, 1, text);
  466.         }
  467.         // If the IP item is a named item...
  468.         else if(curIP.Type == 1)
  469.         {
  470.             var text = StrID("Name") + ": " + curIP.NamedIP;
  471.  
  472.             pRow = IPList.InsertRow(-1);
  473.             IPList.SetCellTextPtr(pRow, 0, StrID("SingleAddress"));
  474.             IPList.SetCellTextPtr(pRow, 1, text);
  475.         }
  476.         // If the IP item is an address...
  477.         else if(curIP.Type == 0)
  478.         {
  479.             var text = StrID("IP") + ": " + curIP.RawIP;
  480.  
  481.             pRow = IPList.InsertRow(-1);
  482.             IPList.SetCellTextPtr(pRow, 0, StrID("SingleAddress"));
  483.             IPList.SetCellTextPtr(pRow, 1, text);
  484.         }            
  485.  
  486.         curIP = g_ipList.GetNext();
  487.     }
  488.  
  489.     if(g_ipList.ItemCount > 0)
  490.         bEnableList = true;
  491.  
  492.     IPCtlsEnabled(bEnableList);
  493. }
  494.  
  495. function IPAdd_OnClick()
  496. {
  497.     var Params = new Array;    
  498.  
  499.     Params[0] = currentActionState;
  500.     Params[1] = null;
  501.     Params[2] = g_ipList;
  502.  
  503.     webWnd.SetIcon2("res://NisRes.dll/105");
  504.     var newIPList = webWnd.showModalDialog('res://fwui.dll/IP-Popup.htm', 450, 350, Params);
  505.  
  506.     if(null != newIPList)
  507.     {
  508.         var curIP = newIPList.GetFirst();
  509.  
  510.         while(null != curIP)
  511.         {    
  512.             if(null == g_ipList.IsIPInList(curIP))
  513.             {
  514.                 g_ipList.LastError = 0;
  515.                 g_ipList.AppendItem(curIP);
  516.                 if(HandleListError(g_ipList.LastError, 1008, 135))
  517.                     break;
  518.             }
  519.  
  520.             curIP = newIPList.GetNext();
  521.         }
  522.     }
  523.  
  524.     refreshIPList();
  525.     IPRemove.disabled = true;            
  526. }
  527.  
  528. function IPRemove_OnClick()
  529. {
  530.     var nSel = IPList.GetCurSel();
  531.     var rule = g_ipList.GetItem(nSel);
  532.  
  533.     if(null != rule)
  534.         g_ipList.DeleteItem(rule);
  535.  
  536.     refreshIPList();
  537.  
  538.     if(IPList.GetRowCount() <= nSel)
  539.         nSel = IPList.GetRowCount()-1;
  540.     IPList.SetCurSel(nSel);        
  541. }
  542.  
  543. function IPList_OnLoad()
  544. {
  545.     IPList.SetTableClass("ListBoxClass");
  546.     IPList.OnClick = IPList_OnClick;
  547. }
  548.  
  549. function IPSetText()
  550. {
  551.     IPPermitRule.style.display = "none";
  552.     IPBlockRule.style.display = "none";
  553.     IPMonitorRule.style.display = "none";
  554.  
  555.     if (Action[0].checked)
  556.     {
  557.         IPPermitRule.style.display = "";
  558.         currentActionState = "permit";
  559.     }
  560.  
  561.     if (Action[1].checked)
  562.     {
  563.         IPBlockRule.style.display = "";
  564.         currentActionState = "block";
  565.     }
  566.  
  567.     if (Action[2].checked)
  568.     {
  569.         IPMonitorRule.style.display = "";
  570.         currentActionState = "monitor";
  571.     }
  572. }
  573.  
  574. function IPValidate()
  575. {
  576.     if (Addresses[1].checked && g_ipList.ItemCount == 0)
  577.     {
  578.         webWnd.MsgBox(StrID("IPListError"), UserManager.AppTitle, MB_OK | MB_ICONEXCLAMATION);        
  579.         return false;
  580.     }
  581.  
  582.  
  583.     return true;
  584. }
  585.  
  586.  
  587. ////////////////////////////////////////////////////////////////////////////////////
  588. //  Ports to Block page
  589. //
  590.  
  591. var currentProtocol = 2;
  592. var g_LocalPorts = null;
  593. var g_RemotePorts = null;
  594.  
  595.  
  596. function PortCtlsEnabled(enable)
  597. {
  598.     var sVal = "";
  599.     if (!enable)
  600.         sVal = "yes";
  601. //        PortsWebBrowsing.disabled = sVal;
  602. //        PortsEmail.disabled = sVal;
  603.     EnableButton(PortsAdd,enable);
  604.  
  605.     //
  606.     // Only allow this button to be disabled. Be sure to remove
  607.     // selection too.
  608.     //
  609.     if (!enable)
  610.     {
  611.         EnableButton(PortsRemove,enable);
  612.         PortList.SetCurSel(-1);
  613.     }
  614.  
  615.     PortsSel[0].checked = !enable;
  616.     PortsSel[1].checked = enable;
  617.     
  618.     // If the user clicked on PortsSel[1] (specific ports), no longer force
  619.     // all ports in the rule.
  620.     if (enable) g_rule.AllPorts = false;
  621. }
  622.  
  623. function portList_OnClick()
  624. {
  625.     //
  626.     // Enable the Remove button.
  627.     //
  628.     EnableButton(PortsRemove,true);
  629. }
  630.  
  631. function UIPortsStore(rule)
  632. {
  633.     var node = null;
  634.     var nodes = null;
  635.  
  636.     //
  637.     // Store protocol
  638.     //
  639.     if(SelProtocol[0].checked)
  640.         rule.Protocol = 6; // TCP
  641.     else if(SelProtocol[1].checked)
  642.         rule.Protocol = 17; // UDP;
  643.     else if(SelProtocol[2].checked)
  644.         rule.Protocol = 0; // TCP-UDP
  645.     if(SelProtocol[3].checked)
  646.         rule.Protocol = 1; // ICMP
  647.  
  648.     //
  649.     // If the user specify any ports, delete the lists
  650.     //
  651.     if (PortsSel[0].checked)
  652.     {
  653.         if(g_LocalPorts != null)
  654.             g_LocalPorts.DeleteAll();
  655.         else
  656.             g_LocalPorts = new ActiveXObject("ccFWSettg.PortList");
  657.             
  658.         if(g_RemotePorts != null)
  659.             g_RemotePorts.DeleteAll();
  660.         else
  661.             g_RemotePorts = new ActiveXObject("ccFWSettg.PortList");
  662.     }
  663.  
  664.     // &!SWM - Remove This rule.LocalPorts = g_LocalPorts;
  665.     // &!SWM - Remove This rule.RemotePorts = g_RemotePorts;
  666. }
  667.  
  668. function UIPortsLoad(rule)
  669. {
  670.     PortList_OnLoad();
  671.     //
  672.     // Enable correct protocol
  673.     //
  674.     switch(rule.Protocol)
  675.     {
  676.         case 6: // TCP
  677.             currentProtocol = 0;
  678.             break;
  679.         case 17: // UDP
  680.             currentProtocol = 1;
  681.             break;
  682.         case 0: // TCP-UDP
  683.             currentProtocol = 2;
  684.             break;
  685.         case 1: // ICMP
  686.             currentProtocol = 3;
  687.             break;
  688.     }
  689.     SelProtocol[currentProtocol].checked = true;
  690.  
  691.  
  692.     g_LocalPorts = rule.LocalPorts;
  693.  
  694.     g_RemotePorts = rule.RemotePorts;
  695.  
  696.     refreshPortList();
  697. }
  698.  
  699. function refreshPortList()
  700. {
  701.     PortList.DeleteAllRows();
  702.     PortList.SetColumnCount(1);
  703.  
  704.     var bEnableList = false;
  705.     //
  706.     // Now add each port to our list.
  707.     //
  708.     var lPort = g_LocalPorts.GetFirst();
  709.  
  710.     while(null != lPort)
  711.     {
  712.         bEnableList = true;
  713.         pRow = PortList.InsertRow(-1);
  714.  
  715.         if(currentProtocol == 3)
  716.             PortList.SetCellTextPtr(pRow, 0, getPortStr(lPort, (currentProtocol == 3)));
  717.         else
  718.             PortList.SetCellTextPtr(pRow, 0, StrID("local_port") + " " + getPortStr(lPort, (currentProtocol == 3)));
  719.  
  720.         lPort = g_LocalPorts.GetNext();
  721.     }
  722.  
  723.     //
  724.     // Now add each port to our list.
  725.     //
  726.     var rPort = g_RemotePorts.GetFirst()
  727.  
  728.     while(null != rPort)
  729.     {
  730.         bEnableList = true;
  731.         pRow = PortList.InsertRow(-1);
  732.         if(currentProtocol == 3)
  733.             PortList.SetCellTextPtr(pRow, 0, getPortStr(rPort, (currentProtocol == 3)));
  734.         else
  735.             PortList.SetCellTextPtr(pRow, 0, StrID("remote_port") + " " + getPortStr(rPort, (currentProtocol == 3)));
  736.  
  737.         rPort = g_RemotePorts.GetNext();
  738.     }
  739.     
  740.     //
  741.     // Rules may ask that all ports be selected even if some individual ports are listed.
  742.     // This can happen when a listening alert comes up. We want to list the port being listened
  743.     // on, but want to recommend all ports be allowed.
  744.     //
  745.     if (bEnableList && typeof(g_rule) != "undefined")
  746.     {
  747.         if (g_rule.AllPorts) bEnableList = false;
  748.     }
  749.  
  750.     PortCtlsEnabled(bEnableList);
  751. }
  752.  
  753. function PortsAdd_OnClick()
  754. {
  755.     var Params = new Array;    
  756.  
  757.     Params[0] = Direction[1].checked?"local":"remote";    
  758.     Params[1] = g_LocalPorts;
  759.     Params[2] = g_RemotePorts;
  760.  
  761.     var popup = "res://fwui.dll/Ports-Popup.htm";
  762.     if (currentProtocol == 3)
  763.         popup = "res://fwui.dll/ICMP-Popup.htm";
  764.  
  765.     webWnd.SetIcon2("res://NisRes.dll/105");
  766.     var outParams = webWnd.showModalDialog(popup, 450, 425, Params);
  767.     
  768.     if (outParams == null)
  769.         return;
  770.  
  771.     if(null != outParams[0])
  772.     {
  773.         var lPort = outParams[0].GetFirst();
  774.  
  775.         while(null != lPort)
  776.         {
  777.             if(null == g_LocalPorts.IsPortInList(lPort))
  778.             {
  779.                 g_LocalPorts.LastError = 0;
  780.                 g_LocalPorts.AppendItem(lPort);
  781.                 if(HandleListError(g_LocalPorts.LastError, 1008, 134))
  782.                     break;
  783.             }
  784.             lPort = outParams[0].GetNext();
  785.         }
  786.     }
  787.  
  788.     if(null != outParams[1])
  789.     {
  790.         var rPort = outParams[1].GetFirst();
  791.  
  792.         while(null != rPort)
  793.         {
  794.             if(null == g_RemotePorts.IsPortInList(rPort))
  795.             {
  796.                 g_RemotePorts.LastError = 0;
  797.                 g_RemotePorts.AppendItem(rPort);
  798.                 if(HandleListError(g_RemotePorts.LastError, 1008, 135))
  799.                     break;
  800.             }
  801.             rPort = outParams[1].GetNext();
  802.         }
  803.     }
  804.  
  805.     refreshPortList();    
  806.     
  807.     //
  808.     // Disable the Remove button.
  809.     //
  810.     EnableButton(PortsRemove,false);
  811. }
  812.  
  813. function PortsRemove_OnClick()
  814. {
  815.     var nDivide = 0;
  816.     var nSel = PortList.GetCurSel();
  817.  
  818.     if(nSel < g_LocalPorts.ItemCount)
  819.     {
  820.         var lPort = g_LocalPorts.GetItem(nSel);
  821.  
  822.         g_LocalPorts.DeleteItem(lPort);
  823.     }
  824.     else
  825.     {
  826.         var rPort = g_RemotePorts.GetItem(nSel - g_LocalPorts.ItemCount);
  827.  
  828.         g_RemotePorts.DeleteItem(rPort);
  829.     }
  830.  
  831.     refreshPortList();
  832.  
  833.     if (PortList.GetRowCount() <= nSel)
  834.         nSel = PortList.GetRowCount()-1;
  835.     PortList.SetCurSel(nSel);    
  836. }
  837.  
  838. function PortList_OnLoad()
  839. {
  840.     PortList.SetTableClass("ListBoxClass");
  841.     PortList.OnClick = portList_OnClick;
  842.     
  843.     //
  844.     // Reset the list control
  845.     //
  846.     PortList.DeleteAllRows();
  847.     PortList.SetColumnCount(1);    
  848. }
  849.  
  850. // if the user switches to/from ICMP - he can't take his ports with him
  851. function Protocol_Onclick(newProtocol)
  852. {
  853.     if((newProtocol != currentProtocol) &&
  854.        ((newProtocol == 3) || (currentProtocol == 3)))
  855.     {        
  856.         g_LocalPorts.DeleteAll();
  857.         g_RemotePorts.DeleteAll();
  858.     }
  859.     
  860.     currentProtocol = newProtocol;
  861.  
  862.     refreshPortList();
  863. }
  864.  
  865. function PortSetText()
  866. {
  867.     PortProtPermitRule.style.display = "none";
  868.     PortProtBlockRule.style.display = "none";
  869.     PortProtMonitorRule.style.display = "none";
  870.     PortPermitRulePort.style.display = "none";
  871.     PortBlockRulePort.style.display = "none";
  872.     PortMonitorRulePort.style.display = "none";
  873.  
  874.     if (Action[0].checked)
  875.     {
  876.         PortProtPermitRule.style.display = "";
  877.         PortPermitRulePort.style.display = "";
  878.     }
  879.  
  880.     if (Action[1].checked)
  881.     {
  882.         PortProtBlockRule.style.display = "";
  883.         PortBlockRulePort.style.display = "";
  884.     }
  885.  
  886.     if (Action[2].checked)
  887.     {
  888.         PortProtMonitorRule.style.display = "";
  889.         PortMonitorRulePort.style.display = "";
  890.     }
  891. }
  892.  
  893. function ProtocolAndPortValidate()
  894. {
  895.  
  896.     if (PortsSel[1].checked && PortList.GetRowCount() == 0)
  897.     {
  898.         webWnd.MsgBox(StrID("PortListError"), UserManager.AppTitle, MB_OK | MB_ICONEXCLAMATION);                
  899.         return false;
  900.     }
  901.  
  902.     return true;
  903. }
  904.  
  905. ////////////////////////////////////////////////////////////////////////////////////
  906. //  Logging page
  907. //
  908. function UILoggingLoad(rule)
  909. {   
  910.     if(1 & rule.Logging)
  911.         Logging.checked = true;
  912.     if(18 & rule.Logging)
  913.         SecAlert.checked = true;
  914.  
  915.     if(rule.LogThreshold>1)
  916.     {
  917.         NumTimesText.value = rule.LogThreshold;
  918.     }
  919.     else
  920.     {
  921.         NumTimesText.value = 1;
  922.     }
  923.     
  924.     Logging_OnClick();
  925. }
  926.  
  927. function UILoggingStore(rule)
  928. {   
  929.     var loggingValue = "";
  930.  
  931.     rule.Logging = 0;
  932.  
  933.     if (SecAlert.checked)
  934.     {
  935.         rule.Logging |= 18;
  936.     }
  937.  
  938.     if (Logging.checked)
  939.     {
  940.         rule.Logging |= 1;
  941.  
  942.          var NumberOfTimes = NumTimesText.value;
  943.  
  944.         if(NumberOfTimes > 1)
  945.         {
  946.             rule.LogThreshold = NumberOfTimes;
  947.         }
  948.         else
  949.         {
  950.             rule.LogThreshold = 1;
  951.         }
  952.     }    
  953.  
  954. }
  955.  
  956. function LoggingSetText()
  957. {
  958.     if (Action[2].checked    // If the user chose to monitor ...
  959.      && !Logging.checked    // ... and no forms of monitoring are already selected ...
  960.      && !SecAlert.checked)
  961.         Logging.checked = true;    // ... ensure that at least one form of monitoring is selected
  962. }
  963.  
  964.  
  965. function Logging_OnClick()
  966. {
  967.     IDS_RuleCreation5.disabled = !Logging.checked;
  968. }
  969.  
  970. ////////////////////////////////////////////////////////////////////////////////////
  971. //  Enter title and category page
  972. //
  973. var g_CategoryList = null;
  974. var g_catref = 0;
  975.  
  976. function initCatList()
  977. {    
  978.     g_CategoryList = new ActiveXObject("ccFWSettg.CategoryList");
  979.  
  980.     for (var nElem = 0; nElem < g_CategoryList.ItemCount; nElem++)
  981.     {
  982.         var oOption = document.createElement("OPTION");
  983.         oOption.text = g_CategoryList.GetItem(nElem).Name;
  984.         oOption.value = g_CategoryList.GetItem(nElem).Value;
  985.     
  986.         //
  987.         // Don't display non-user categories (> 255)
  988.         //
  989.         if (oOption.value < 256)
  990.             catlist.add(oOption);
  991.     }
  992. }
  993.  
  994. function UITitleLoad(rule)
  995. {
  996.     var txt = rule.Description;
  997.     g_catref = rule.CategoryReference;
  998.  
  999.     if (txt == "")
  1000.         titletext.value = StrID("firewall_rule");
  1001.     else
  1002.         titletext.value =  txt;
  1003.  
  1004.     //
  1005.     // Ensure categories only displayed for NISFE.
  1006.     // Don't display non-user categories (> 255)
  1007.     //
  1008.     if((!RLevel.AreAccountsInstalled) || (g_catref >= 255))
  1009.         return;
  1010.  
  1011.     catUI.style.display = "";
  1012.  
  1013.     initCatList();
  1014.  
  1015.     //
  1016.     // Now set selected item in category list
  1017.     //
  1018.     var nItem = 0;
  1019.     for (nItem = 0; nItem < catlist.length; nItem++)
  1020.     {
  1021.         if (catlist.item(nItem).value == g_catref)
  1022.             break;
  1023.     }
  1024.     if (nItem < catlist.length)
  1025.     {
  1026.         catlist.selectedIndex = nItem;
  1027.     }
  1028.     else
  1029.     {
  1030.         // Failed to find the category... choose "General"
  1031.         catlist.selectedIndex = 0;
  1032.     }
  1033. }
  1034.  
  1035. function UITitleStore(rule)
  1036. {
  1037.     rule.Description = titletext.value;
  1038.     
  1039.     if(RLevel.AreAccountsInstalled && g_catref < 256)
  1040.         rule.CategoryReference = g_CategoryList.GetItem(catlist.selectedIndex).Value;
  1041.     else
  1042.         rule.CategoryReference = g_catref;
  1043. }
  1044.  
  1045. function UITypeLoad(rule)
  1046. {
  1047.     ruleType[rule.Priority].checked = true;
  1048. }
  1049.  
  1050. function UITypeStore(rule)
  1051. {
  1052.     if(usingClientRules())
  1053.     {
  1054.         if(ruleType[0].checked)
  1055.             rule.Priority = 0;
  1056.         else if(ruleType[1].checked)
  1057.             rule.Priority = 1;
  1058.     }
  1059.     else
  1060.         rule.Priority = 0;
  1061. }
  1062.  
  1063. function TitleValidate()
  1064. {
  1065.     titletext.value = trim(titletext.value);
  1066.  
  1067.     if(titletext.value == "")
  1068.     {
  1069.         webWnd.MsgBox(StrID("RuleNoDescription"), UserManager.AppTitle, MB_OK | MB_ICONEXCLAMATION);    
  1070.         return false;
  1071.     }
  1072.     
  1073.     return true;
  1074. }
  1075.  
  1076. ///////////////////////////////////////////////////////////////////////
  1077. //    Select location page
  1078. //
  1079.  
  1080. function UILocationsLoad()
  1081. {
  1082.     // Setup the list control
  1083.     locationList.OnClick    = locationList_OnClick;
  1084.     locationList.OnDblClick = locationList_OnDblClick;
  1085.     locationList.OnSpace    = locationList_OnSpace;
  1086.  
  1087.     // populate list
  1088.     RuleCreation_Body.style.cursor = "wait";
  1089.  
  1090.     var bCheckDefault = !RLevel.LocationAwarenessEnabled;
  1091.     var bCheckActive = RLevel.LocationAwarenessEnabled;
  1092.     Location_PopulateListBox(locationList,bCheckDefault,bCheckActive);
  1093.     
  1094.     RuleCreation_Body.style.cursor = "";
  1095. }
  1096.  
  1097. function UILocation_UpdateNextButtonState()
  1098. {
  1099.     var arrayLocations = Location_GetListBoxSelectedItems(locationList);
  1100.  
  1101.     // too bad we have intimate knowledge of the containing (parent) window, but oh well
  1102.     if(arrayLocations.length)
  1103.     {
  1104.         window.parent.NextB.disabled = false;
  1105.     }
  1106.     else
  1107.     {
  1108.         window.parent.NextB.disabled = true;
  1109.     }
  1110. }
  1111.  
  1112. function locationList_OnSpace()
  1113. {
  1114.     var nCurSel = locationList.GetCurSel();
  1115.     var bEnable = false;
  1116.  
  1117.     if(nCurSel < 0)
  1118.     {
  1119.         return;    
  1120.     }
  1121.  
  1122.     // Swap the state of the check box for this item
  1123.     var CheckBox = locationList.GetCellPtr(nCurSel, 0).children[0];
  1124.     CheckBox.checked = !CheckBox.checked;
  1125.     
  1126.     UILocation_UpdateNextButtonState();
  1127. }
  1128.  
  1129. function locationList_OnClick()
  1130. {
  1131.     UILocation_UpdateNextButtonState();
  1132. }
  1133.  
  1134. function locationList_OnDblClick()
  1135. {
  1136.     var nCurSel = locationList.GetCurSel();
  1137.     var bEnable = false;
  1138.  
  1139.     if(nCurSel < 0)
  1140.     {
  1141.         return;    
  1142.     }
  1143.  
  1144.     // Swap the state of the check box for this item
  1145.     var CheckBox = locationList.GetCellPtr(nCurSel, 0).children[0];
  1146.     CheckBox.checked = !CheckBox.checked;
  1147.     
  1148.     UILocation_UpdateNextButtonState();
  1149. }
  1150.  
  1151. function UILocation_SelectAll()
  1152. {
  1153.     Location_SelectAllListBoxItems(locationList, true);
  1154.     UILocation_UpdateNextButtonState();
  1155. }
  1156.  
  1157. function UILocation_DeselectAll()
  1158. {
  1159.     Location_SelectAllListBoxItems(locationList, false);
  1160.     UILocation_UpdateNextButtonState();
  1161. }
  1162.  
  1163.  
  1164. ////////////////////////////////////////////////////////////////////////////////////
  1165. //  All done page
  1166. //
  1167. function displayRuleData()
  1168. {
  1169.     UIActionStore(g_rule);
  1170.     UIDirectionStore(g_rule);
  1171.     UIIPStore(g_rule);
  1172.     UIAdapterStore(g_rule);
  1173.     UIPortsStore(g_rule);
  1174.     UILoggingStore(g_rule);
  1175.     UITitleStore(g_rule);
  1176.     UITypeStore(g_rule);
  1177.  
  1178.     switch(g_rule.Action)
  1179.     {
  1180.         case 1: // Block
  1181.             finMonitor.style.display = "none";
  1182.             finPermit.style.display = "none";
  1183.             finBlock.style.display = "";
  1184.             break;
  1185.         case 4: // Monitor
  1186.             finBlock.style.display = "none";
  1187.             finPermit.style.display = "none";
  1188.             finMonitor.style.display = "";
  1189.             break;
  1190.         case 2: // Permit
  1191.         default:
  1192.             finBlock.style.display = "none";
  1193.             finMonitor.style.display = "none";
  1194.             finPermit.style.display = "";
  1195.             break;
  1196.     }
  1197.  
  1198. // Don't show the warning if the new rule is for monitoring only
  1199. // But show the warning if the rule is for any ip address or any local 
  1200. // or remote port 
  1201.  
  1202.     if(g_rule.Action                    !=4 && // Monitor
  1203.        g_ipList.ItemCount                ==0    &&
  1204.        g_LocalPorts.ItemCount            ==0    &&
  1205.        g_RemotePorts.ItemCount            ==0    &&
  1206.        g_rule.ApplicationDescription    == "")
  1207.     {
  1208.         finWarning.style.display = "";
  1209.     }
  1210.  
  1211.     finAppName.innerText = g_appName;
  1212.     
  1213.     var arrayLocations = Location_GetListBoxSelectedItems(locationList);
  1214.     
  1215.     var ruleTxt = "<p class=nisText style='margin-top: 3; margin-bottom: 0; margin-left:0'>Description: " + g_rule.Description +
  1216.         "</p><p class=nisText style='margin-top: 3; margin-bottom: 0; margin-left:0'>Action: ";
  1217.     ruleTxt += ruleString(g_rule, arrayLocations, "</p><p class=nisText style='margin-top: 3; margin-bottom: 0; margin-left:0'>");
  1218.     ruleTxt += "</p>";
  1219.     
  1220.     if( usingClientRules() && (UserManager.CurrentUserType == "UT_SUPERVISOR") )
  1221.     {
  1222.         ruleTxt += "<p class=nisText style='margin-top: 3; margin-bottom: 0; margin-left:0'>Type: ";
  1223.         
  1224.         if(0 == g_rule.Priority)
  1225.             ruleTxt += StrID("Admin_Type");
  1226.         else
  1227.             ruleTxt += StrID("User_Type");
  1228.             
  1229.         ruleTxt += "</p>";
  1230.     }
  1231.  
  1232.     ruleSummary.innerHTML = ruleTxt;
  1233. }
  1234.  
  1235. function IPAdapters_OnClick()
  1236. {
  1237.     UIActionStore(g_rule);
  1238.  
  1239.     var Params = new Array;
  1240.  
  1241.     var newList = new ActiveXObject("ccFWSettg.IPList");
  1242.     newList.CopyFrom(g_AdapterList);
  1243.  
  1244.     Params[0] = currentActionState;
  1245.     Params[1] = newList;
  1246.  
  1247.     var retList = null;
  1248.  
  1249.     webWnd.SetIcon2("res://NisRes.dll/105");
  1250.     retList = webWnd.showModalDialog('res://fwui.dll/Adapters-popup.htm', 450, 330, Params);    
  1251.  
  1252.     if(null != retList)
  1253.         g_AdapterList.CopyFrom(retList);
  1254.     refreshAdapters();
  1255. }
  1256.  
  1257. function refreshAdapters()
  1258. {
  1259.     if (g_AdapterList.ItemCount == 0)
  1260.         IPAdaptersSpecified.style.display = "none";
  1261.     else
  1262.         IPAdaptersSpecified.style.display = "";
  1263. }
  1264.