home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 May / 05_02.iso / software / nis / files / NIS / NIS.MSI / fwUI.dll / HTML / RULECREATION.JS < prev    next >
Encoding:
JavaScript  |  2001-12-01  |  25.2 KB  |  1,074 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.  
  11.     var CurrPage = "Action";
  12.     var g_appName = "";
  13.     var g_xml = null;        // Holds the rule while being modified
  14.  
  15.     returnValue = null;
  16.  
  17. function Page_OnLoad()
  18. {
  19.     // Set the title...
  20.     window.title = UserManager.ProductName;
  21.     
  22.     //
  23.     // Special onload section
  24.     //
  25.     IPList_OnLoad();
  26.     PortList_OnLoad();
  27.  
  28.     //
  29.     // Register special handlers
  30.     //
  31.     IPAdd.onclick = IPAdd_OnClick;
  32.     IPRemove.onclick = IPRemove_OnClick;
  33.     PortsAdd.onclick = PortsAdd_OnClick;
  34.     PortsRemove.onclick = PortsRemove_OnClick;
  35.     IPAdapters.onclick = IPAdapters_OnClick;
  36. }
  37.  
  38. function ruleTellMeMore()
  39. {
  40.     TellMeMore("RuleEdit" + CurrPage);
  41. }
  42.  
  43. function SetActionText()
  44. {
  45.     DirectinSetText();
  46.     IPSetText();
  47.     PortSetText();
  48.     LoggingSetText();
  49. }
  50.  
  51. function HideAll()
  52. {
  53.     UIAction.style.display = "none";
  54.     UIDirection.style.display = "none";
  55.     UIIP.style.display = "none";
  56.     UIPorts.style.display = "none";
  57.     UILogging.style.display = "none";
  58.     UITitle.style.display = "none";
  59.     UIFinish.style.display = "none";
  60. }
  61.  
  62. function SetPage(Name, Page)
  63. {
  64.     var Page = null;
  65.     CurrPage = Name;
  66.     HideAll();
  67.  
  68.     //
  69.     // Find the correct page to display
  70.     //
  71.     switch(CurrPage)
  72.     {
  73.         case "Action":
  74.             Page = UIAction;
  75.             break;
  76.         case "Direction":
  77.             Page = UIDirection;
  78.             break;
  79.         case "IP":
  80.             Page = UIIP;
  81.             break;
  82.         case "Ports":
  83.             Page = UIPorts;
  84.             break;
  85.         case "Logging":
  86.             Page = UILogging;
  87.             break;
  88.         case "Title":
  89.             Page = UITitle;
  90.             break;
  91.         case "Finished":
  92.             Page = UIFinish;
  93.     }
  94.  
  95.     if (false)
  96.     {
  97.         //
  98.         // Use this code if you want a fade transition.
  99.         //
  100.         Page.children[0].style.visibility="hidden";
  101.         Page.style.display = "";
  102.         Page.children[0].style.filter="blendTrans(duration=0.20)";
  103.         Page.children[0].filters.blendTrans.apply();
  104.         Page.children[0].style.visibility="visible";
  105.         Page.children[0].filters.blendTrans.play();
  106.     }
  107.     else
  108.     {
  109.         //
  110.         // "Normal" transition with no effects.
  111.         //
  112.         Page.style.display = "";
  113.     }
  114.  
  115. }
  116.  
  117. function saveRule()
  118. {
  119.     //
  120.     // Prepare a working xml doc.
  121.     //
  122.     var xml = new ActiveXObject("Microsoft.XMLDOM");
  123.     xml.documentElement = g_xml.cloneNode(true);
  124.     var xmlTLN = xml.selectSingleNode("Rule");
  125.  
  126.     setXMLNode(xmlTLN, "InUse", "enabled");
  127.     UIActionStore(xmlTLN);
  128.     UIDirectionStore(xmlTLN);
  129.     UIIPStore(xmlTLN);
  130.  
  131.     UIAdapterStore(xmlTLN);
  132.     UIPortsStore(xmlTLN);
  133.  
  134.     setXMLNode(xmlTLN, "Logging", "");
  135.     UILoggingStore(xmlTLN);
  136.     UITitleStore(xmlTLN);
  137.  
  138.     return xml;
  139. }
  140.  
  141.  
  142. function init(xml, szRuleType, appName)
  143. {
  144.     g_appName = appName;
  145.     g_xml = xml;
  146.  
  147.     UIActionLoad(xml);
  148.     UIDirectionLoad(xml);
  149.     UIIPLoad(xml);
  150.     UIAdapterLoad(xml);
  151.     UIPortsLoad(xml);
  152.     UILoggingLoad(xml);
  153.     UITitleLoad(xml);
  154.  
  155.     // don't allow ICMP protocol on application rules
  156.     if (szRuleType == "Application")
  157.     {
  158.         nonappitems.style.visibility="hidden";
  159.     }
  160.  
  161.     SetActionText();
  162. }
  163.  
  164. function validateAll()
  165. {
  166.  
  167.     if (!ActionValidate())
  168.     {
  169.         return("Action");
  170.     }
  171.     if (!DirectionValidate())
  172.     {
  173.         return("Direction");
  174.     }
  175.        if (!IPValidate())
  176.     {
  177.         return("IP");
  178.     }
  179.     if (!ProtocolAndPortValidate())
  180.     {
  181.         return("Ports");
  182.     }
  183.     if (!TitleValidate())
  184.     {
  185.         return("Title");
  186.     }
  187.  
  188.     return null;
  189. }
  190.  
  191.  
  192. ////////////////////////////////////////////////////////////////////////////////////
  193. //  Select Rule Action page
  194. //
  195.  
  196. function UIActionStore(xml)
  197. {
  198.     for(nElem = 0; nElem < 3; nElem++)
  199.     {
  200.         if (Action[nElem].checked)
  201.         {
  202.             setXMLNode(xml, "Action", Action[nElem].value.toLowerCase());
  203.             break;
  204.         }
  205.     }
  206. }
  207.  
  208. function UIActionLoad(xml)
  209. {
  210.     nElem = 0;
  211.  
  212.     switch (getElem(xml, "Action").toLowerCase())
  213.     {
  214.         case "permit":
  215.             nElem = 0;
  216.             break;
  217.         case "block":
  218.             nElem = 1;
  219.             break;
  220.         case "monitor":
  221.             nElem = 2;
  222.             break;
  223.     }
  224.     
  225.     Action[nElem].checked = true;
  226. }
  227.  
  228.  
  229. function  RuleActionHandler()
  230. {
  231.     SetActionText();
  232. }
  233.  
  234. function ActionValidate()
  235. {
  236.     return true;
  237. }
  238.  
  239. ////////////////////////////////////////////////////////////////////////////////////
  240. //  Determine traffic direction page
  241. //
  242. function UIDirectionStore(xml)
  243. {
  244.     setXMLNode(xml, "Direction", getDirection());
  245. }
  246.  
  247. function UIDirectionLoad(xml)
  248. {
  249.     nElem = 0;
  250.  
  251.     switch (getElem(xml, "Direction").toLowerCase())
  252.     {
  253.         case "out":
  254.             nElem = 0;
  255.             break;
  256.         case "in":
  257.             nElem = 1;
  258.             break;
  259.         case "in-out":
  260.             nElem = 2;
  261.             break;
  262.     }
  263.     
  264.     Direction[nElem].checked = true;
  265. }
  266.  
  267. function getDirection()
  268. {
  269.     for(nElem = 0; nElem < 3; nElem++)
  270.         if (Direction[nElem].checked)
  271.             return Direction[nElem].value.toLowerCase();
  272. }
  273.  
  274. function DirectinSetText()
  275. {
  276.     DirPermitRule.style.display = "none";
  277.     DirBlockRule.style.display = "none";
  278.     DirMonitorRule.style.display = "none";
  279.  
  280.     if (Action[0].checked)
  281.         DirPermitRule.style.display = "";
  282.  
  283.     if (Action[1].checked)
  284.         DirBlockRule.style.display = "";
  285.  
  286.     if (Action[2].checked)
  287.         DirMonitorRule.style.display = "";
  288. }
  289.  
  290. function DirectionValidate()
  291. {
  292.     return true;
  293. }
  294.  
  295. ////////////////////////////////////////////////////////////////////////////////////
  296. //  Remote Sites/Zones to Block page
  297. //
  298.  
  299. var xmlIPList = new ActiveXObject("Microsoft.XMLDOM");
  300. var xmlAdapterList = new ActiveXObject("Microsoft.XMLDOM");
  301.  
  302. xmlIPList.loadXML("<RemoteAddresses/>");
  303. xmlAdapterList.loadXML("<LocalAddresses/>");
  304.  
  305. var currentActionState = null;
  306.  
  307. function IPList_OnClick()
  308. {
  309.     // Enable the modify/delete buttons
  310.     EnableButton(IPRemove,true);
  311. }
  312.  
  313. function IPCtlsEnabled(enable)
  314. {
  315.  
  316.     EnableButton(IPAdd,enable);
  317.  
  318.     //
  319.     // Only allow this button to be disabled. Be sure to remove
  320.     // selection too.
  321.     //
  322.     if (!enable)
  323.     {
  324.         EnableButton(IPRemove,enable);
  325.         IPList.SetCurSel(-1);
  326.     }
  327.  
  328.     //
  329.     // Enable radio buttons appropriately.
  330.     //
  331.     Addresses[0].checked = !enable;
  332.     Addresses[1].checked = enable;
  333. }
  334.  
  335. function UIIPStore(xml)
  336. {
  337.     var node = xml.selectSingleNode("RemoteAddresses");
  338.     if (null != node)
  339.         node.parentNode.removeChild(node);
  340.     //
  341.     // If the user didn't narrow this down, get out now. The firewall
  342.     // will default to all when no IP addresses are specified.
  343.     //
  344.     if (Addresses[0].checked)
  345.         return;
  346.  
  347.     //
  348.     // Save data.
  349.     //
  350.     var nodes = xmlIPList.selectNodes("(Address|NamedAddress|AddressRange|MaskedAddress|ZoneName)");
  351.     if (nodes.length > 0)
  352.     {
  353.         var node = getDoc(xml).createElement("RemoteAddresses");
  354.         for (var nElem = 0; nodes.length > nElem; nElem++)
  355.             node.appendChild(nodes[nElem].cloneNode(true));
  356.         xml.appendChild(node);
  357.     }
  358. }
  359.  
  360. function UIAdapterStore(xml)
  361. {
  362.     node = xml.selectSingleNode("LocalAddresses");
  363.     if (null != node)
  364.         node.parentNode.removeChild(node);
  365.     //
  366.     // Save data.
  367.     //
  368.     var nodes = xmlAdapterList.selectNodes("(Address|NamedAddress|AddressRange|MaskedAddress|ZoneName)");
  369.     if (nodes.length > 0)
  370.     {
  371.         var node = getDoc(xml).createElement("LocalAddresses");
  372.         for (var nElem = 0; nodes.length > nElem; nElem++)
  373.             node.appendChild(nodes[nElem].cloneNode(true));
  374.         xml.appendChild(node);
  375.     }
  376. }
  377.  
  378. function UIIPLoad(xml)
  379. {
  380.     IPList_OnLoad();
  381.  
  382.     //
  383.     // Check to see if any addresses were specified.
  384.     //
  385.     var temp = xml.selectSingleNode("RemoteAddresses");
  386.     
  387.     if (null == temp)
  388.     {
  389.         temp = xml.ownerDocument.createElement("RemoteAddresses");
  390.         xml.appendChild(temp);
  391.     }
  392.  
  393.     xmlIPList = temp;
  394.     refreshIPList();
  395. }
  396.  
  397. function UIAdapterLoad(xml)
  398. {
  399.     //
  400.     // Check to see if any addresses were specified.
  401.     //
  402.     var temp = xml.selectSingleNode("LocalAddresses");
  403.     
  404.     if (null == temp)
  405.     {
  406.         temp = xml.ownerDocument.createElement("LocalAddresses");
  407.         xml.appendChild(temp);
  408.     }
  409.  
  410.     xmlAdapterList = temp;
  411. }
  412.  
  413. function refreshIPList()
  414. {
  415.     //
  416.     // Reset the list control
  417.     //
  418.     IPList.DeleteAllRows();
  419.     IPList.SetColumnCount(2);
  420.  
  421.     var addressNodeList = xmlIPList.selectNodes("(Address|NamedAddress|AddressRange|MaskedAddress|ZoneName)");
  422.     var ChildCount = 0;
  423.     var bEnableList = false;
  424.  
  425.     for(ChildCount = 0; ChildCount < addressNodeList.length; ChildCount++)
  426.     {
  427.         var addressChildNode = addressNodeList.item(ChildCount);
  428.  
  429.         if(stricmp(addressChildNode.nodeName, "MaskedAddress") == 0)
  430.         {
  431.             bEnableList = true;
  432.             var chunks = addressChildNode.nodeTypedValue.split(":");
  433.             var text = StrID("IP") + ": " + chunks[0] + "<BR>" + StrID("Mask") + ": " + chunks[1];
  434.  
  435.             pRow = IPList.InsertRow(-1);
  436.             IPList.SetCellTextPtr(pRow, 0, StrID("NetworkAddress"));
  437.             IPList.SetCellTextPtr(pRow, 1, text);
  438.         }
  439.         else if(stricmp(addressChildNode.nodeName, "AddressRange") == 0)
  440.         {
  441.             bEnableList = true;
  442.             var chunks = addressChildNode.nodeTypedValue.split(":");
  443.             var text = StrID("From") + ": " + chunks[0] + "<BR>" + StrID("To") + ": " + chunks[1];
  444.  
  445.             pRow = IPList.InsertRow(-1);
  446.             IPList.SetCellTextPtr(pRow, 0, StrID("AddressRange"));
  447.             IPList.SetCellTextPtr(pRow, 1, text);
  448.         }
  449.         else if(stricmp(addressChildNode.nodeName, "NamedAddress") == 0)
  450.         {
  451.             bEnableList = true;
  452.             var text = StrID("Name") + ": " + addressChildNode.nodeTypedValue;
  453.  
  454.             pRow = IPList.InsertRow(-1);
  455.             IPList.SetCellTextPtr(pRow, 0, StrID("SingleAddress"));
  456.             IPList.SetCellTextPtr(pRow, 1, text);
  457.         }
  458.         else if(stricmp(addressChildNode.nodeName, "Address") == 0)
  459.         {
  460.             bEnableList = true;
  461.             var text = StrID("IP") + ": " + addressChildNode.nodeTypedValue;
  462.  
  463.             pRow = IPList.InsertRow(-1);
  464.             IPList.SetCellTextPtr(pRow, 0, StrID("SingleAddress"));
  465.             IPList.SetCellTextPtr(pRow, 1, text);
  466.         }
  467.     }
  468.  
  469.     IPCtlsEnabled(bEnableList);
  470. }
  471.  
  472. function IPAdd_OnClick()
  473. {
  474.     var xmlOut = webWnd.showModalDialog('res://fwui.dll/IP-Popup.htm', 450, 330, currentActionState);
  475.     if (null != xmlOut)
  476.     {
  477.         var nodes = xmlOut.selectNodes("/*/*");
  478.         for (var nElem = 0; nodes.length > nElem; nElem++)
  479.         {
  480.             var appendTo = xmlIPList.selectSingleNode(".");
  481.             if (null == xmlIPList.ownerDocument)
  482.                 appendTo = xmlIPList.selectSingleNode("*");
  483.             appendTo.appendChild(nodes[nElem].cloneNode(true));
  484.  
  485.         }
  486.         refreshIPList();
  487.         IPRemove.disabled = true;            
  488.     }
  489. }
  490.  
  491. function IPRemove_OnClick()
  492. {
  493.     var nSel = IPList.GetCurSel();
  494.     var nodes = xmlIPList.selectNodes("(Address|NamedAddress|AddressRange|MaskedAddress)");
  495.     if (nodes.length <= nSel)
  496.     {
  497.         IPList.SetCurSel(-1);
  498.         return;
  499.     }
  500.     var nodeRemove = nodes[nSel];
  501.     nodeRemove.parentNode.removeChild(nodeRemove);
  502.     refreshIPList();
  503.  
  504.     if (IPList.GetRowCount() <= nSel)
  505.         nSel = IPList.GetRowCount()-1;
  506.     IPList.SetCurSel(nSel);        
  507. }
  508.  
  509. function IPList_OnLoad()
  510. {
  511.     IPList.SetTableClass("ListBoxClass");
  512.     IPList.OnClick = IPList_OnClick;
  513. }
  514.  
  515. function IPSetText()
  516. {
  517.     IPPermitRule.style.display = "none";
  518.     IPBlockRule.style.display = "none";
  519.     IPMonitorRule.style.display = "none";
  520.  
  521.     if (Action[0].checked)
  522.     {
  523.         IPPermitRule.style.display = "";
  524.         currentActionState = "permit";
  525.     }
  526.  
  527.     if (Action[1].checked)
  528.     {
  529.         IPBlockRule.style.display = "";
  530.         currentActionState = "block";
  531.     }
  532.  
  533.     if (Action[2].checked)
  534.     {
  535.         IPMonitorRule.style.display = "";
  536.         currentActionState = "monitor";
  537.     }
  538. }
  539.  
  540. function IPValidate()
  541. {
  542.     if (Addresses[1].checked && IPList.GetRowCount() == 0)
  543.     {
  544.         webWind.MsgBox2(StrID("IPListError"), UserManager.AppTitle);        
  545.         return false;
  546.     }
  547.  
  548.  
  549.     return true;
  550. }
  551.  
  552.  
  553. ////////////////////////////////////////////////////////////////////////////////////
  554. //  Ports to Block page
  555. //
  556.  
  557. var currentProtocol = 2;
  558.  
  559. var xmlLocalPorts = null;
  560. var xmlRemotePorts = null;
  561.  
  562. function PortCtlsEnabled(enable)
  563. {
  564.     var sVal = "";
  565.     if (!enable)
  566.         sVal = "yes";
  567. //        PortsWebBrowsing.disabled = sVal;
  568. //        PortsEmail.disabled = sVal;
  569.     EnableButton(PortsAdd,enable);
  570.  
  571.     //
  572.     // Only allow this button to be disabled. Be sure to remove
  573.     // selection too.
  574.     //
  575.     if (!enable)
  576.     {
  577.         EnableButton(PortsRemove,enable);
  578.         PortList.SetCurSel(-1);
  579.     }
  580.  
  581.     PortsSel[0].checked = !enable;
  582.     PortsSel[1].checked = enable;
  583. }
  584.  
  585. function portList_OnClick()
  586. {
  587.     //
  588.     // Enable the Remove button.
  589.     //
  590.     EnableButton(PortsRemove,true);
  591. }
  592.  
  593. function UIPortsStore(xml)
  594. {
  595.     var node = null;
  596.     var nodes = null;
  597.     //
  598.     // Store protocol
  599.     //
  600.     node = xml.selectSingleNode("Protocol");
  601.     if (null != node)
  602.         node.parentNode.removeChild(node);
  603.     node = xml.selectSingleNode("LocalPorts");
  604.     if (null != node)
  605.         node.parentNode.removeChild(node);
  606.     node = xml.selectSingleNode("RemotePorts");
  607.     if (null != node)
  608.         node.parentNode.removeChild(node);
  609.  
  610.     node = getDoc(xml).createElement("Protocol");
  611.     node.text = SelProtocol[currentProtocol].value.toLowerCase();
  612.     xml.appendChild(node);
  613.  
  614.     //
  615.     // If the user specify any ports, get out now. The firewall
  616.     // will default to all ports when no ports are specified.
  617.     //
  618.     if (PortsSel[0].checked)
  619.         return;
  620.     
  621.     nodes = xmlLocalPorts.selectNodes("(Port|PortRange)");
  622.     if (nodes.length > 0)
  623.     {
  624.         var portsNode = getDoc(xml).createElement("LocalPorts");
  625.         for (var nElem = 0; nodes.length > nElem; nElem++)
  626.             portsNode.appendChild(nodes[nElem].cloneNode(true));
  627.         xml.appendChild(portsNode);
  628.     }
  629.  
  630.  
  631.     nodes = xmlRemotePorts.selectNodes("(Port|PortRange)");
  632.     if (nodes.length > 0)
  633.     {
  634.         var portsNode = getDoc(xml).createElement("RemotePorts");
  635.         for (var nElem = 0; nodes.length > nElem; nElem++)
  636.             portsNode.appendChild(nodes[nElem].cloneNode(true));
  637.         xml.appendChild(portsNode);
  638.     }
  639. }
  640.  
  641. function UIPortsLoad(xml)
  642. {
  643.     PortList_OnLoad();
  644.     //
  645.     // Enable correct protocol
  646.     //
  647.     switch (getElem(xml, "Protocol").toUpperCase())
  648.     {
  649.         case "TCP":
  650.             currentProtocol = 0;
  651.             break;
  652.         case "UDP":
  653.             currentProtocol = 1;
  654.             break;
  655.         case "TCP-UDP":
  656.             currentProtocol = 2;
  657.             break;
  658.         case "ICMP":
  659.             currentProtocol = 3;
  660.             break;
  661.     }
  662.     SelProtocol[currentProtocol].checked = true;
  663.  
  664.  
  665.     var localports = xml.selectSingleNode("LocalPorts");
  666.     if (localports != null)
  667.     {
  668.         
  669.         xmlLocalPorts = localports.cloneNode(true);
  670.     }
  671.     else
  672.     {
  673.         xmlLocalPorts = xml.ownerDocument.createElement("LocalPorts");
  674.     }
  675.  
  676.     var remoteports = xml.selectSingleNode("RemotePorts");
  677.     if (remoteports != null)
  678.     {
  679.         xmlRemotePorts = remoteports.cloneNode(true);
  680.     }
  681.     else
  682.     {
  683.         xmlRemotePorts = xml.ownerDocument.createElement("RemotePorts");
  684.     }
  685.     refreshPortList();
  686. }
  687.  
  688. function refreshPortList()
  689. {
  690.     PortList.DeleteAllRows();
  691.     PortList.SetColumnCount(1);
  692.  
  693.     var bEnableList = false;
  694.     //
  695.     // Now add each port to our list.
  696.     //
  697.     var oPortList = xmlLocalPorts.selectNodes("(Port|PortRange)");
  698.  
  699.     for(var nElem = 0; oPortList.length > nElem; nElem++)
  700.     {
  701.         bEnableList = true;
  702.         pRow = PortList.InsertRow(-1);
  703.         if(currentProtocol == 3)
  704.             PortList.SetCellTextPtr(pRow, 0, getPortStr(oPortList[nElem], (currentProtocol == 3)));
  705.         else
  706.             PortList.SetCellTextPtr(pRow, 0, StrID("local_port") + " " + getPortStr(oPortList[nElem], (currentProtocol == 3)));
  707.     }
  708.     //
  709.     // Now add each port to our list.
  710.     //
  711.     oPortList = xmlRemotePorts.selectNodes("(Port|PortRange)");
  712.  
  713.     for(var nElem = 0; oPortList.length > nElem; nElem++)
  714.     {
  715.         bEnableList = true;
  716.         pRow = PortList.InsertRow(-1);
  717.         if(currentProtocol == 3)
  718.             PortList.SetCellTextPtr(pRow, 0, getPortStr(oPortList[nElem], (currentProtocol == 3)));
  719.         else
  720.             PortList.SetCellTextPtr(pRow, 0, StrID("remote_port") + " " + getPortStr(oPortList[nElem], (currentProtocol == 3)));
  721.     }
  722.  
  723.     PortCtlsEnabled(bEnableList);
  724. }
  725.  
  726. function PortsAdd_OnClick()
  727. {
  728.     var popup = "res://fwui.dll/Ports-Popup.htm";
  729.     if (currentProtocol == 3)
  730.         popup = "res://fwui.dll/ICMP-Popup.htm";
  731.  
  732.     var xmlOut = webWnd.showModalDialog(popup, 450, 425, Direction[1].checked?"local":"remote");
  733.  
  734.     if(xmlOut != null)
  735.     {
  736.         var nodes = xmlOut.selectNodes("/*/*");
  737.         if (xmlOut.documentElement.nodeName == "LocalPorts") {
  738.             for (var nElem = 0; nodes.length > nElem; nElem++)
  739.                 addPort_limited(xmlLocalPorts, nodes[nElem].nodeTypedValue);
  740.         }
  741.         else if (xmlOut.documentElement.nodeName == "RemotePorts")
  742.         {
  743.             for (var nElem = 0; nodes.length > nElem; nElem++)
  744.                 addPort_limited(xmlRemotePorts, nodes[nElem].nodeTypedValue);
  745.         }
  746.  
  747.         refreshPortList();    
  748.     }
  749. }
  750.  
  751. function PortsRemove_OnClick()
  752. {
  753.     var nDivide = 0;
  754.     var nSel = PortList.GetCurSel();
  755.     var nodes = xmlLocalPorts.selectNodes("(Port|PortRange)");
  756.     if (nSel >= nodes.length)
  757.     {
  758.         nDivide = nodes.length;
  759.         nodes = xmlRemotePorts.selectNodes("(Port|PortRange)");
  760.         if (nSel - nDivide >= nodes.length)
  761.         {
  762.             PortList.SetCurSel(-1);
  763.             return;
  764.         }
  765.     }
  766.     var nodeRemove = nodes[nSel - nDivide];
  767.     nodeRemove.parentNode.removeChild(nodeRemove);
  768.     refreshPortList();
  769.  
  770.     if (PortList.GetRowCount() <= nSel)
  771.         nSel = PortList.GetRowCount()-1;
  772.     PortList.SetCurSel(nSel);    
  773. }
  774.  
  775. function PortList_OnLoad()
  776. {
  777.     PortList.SetTableClass("ListBoxClass");
  778.     PortList.OnClick = portList_OnClick;
  779.     
  780.     //
  781.     // Reset the list control
  782.     //
  783.     PortList.DeleteAllRows();
  784.     PortList.SetColumnCount(1);    
  785. }
  786.  
  787. // if the user switches to/from ICMP - he can't take his ports with him
  788. function Protocol_Onclick(newProtocol)
  789. {
  790.  
  791.  
  792.     if (    ((currentProtocol == 3) && (newProtocol != 3))
  793.         ||    ((currentProtocol != 3) && (newProtocol == 3)))
  794.     {
  795.         if (PortList.GetRowCount() == 0)
  796.         {
  797.             currentProtocol = newProtocol;
  798.         } else {
  799.             if (webWnd.MsgBox(StrID("ChangeToICMP"), StrID("RuleSumNoRulesTitle"), 1) == 1)
  800.             {
  801.                 nodes = xmlLocalPorts.selectNodes("(Port|PortRange)");
  802.                 for (var nSel=0; nSel < nodes.length; nSel++)
  803.                 {
  804.                     var nodeRemove = nodes[nSel];
  805.                     nodeRemove.parentNode.removeChild(nodeRemove);
  806.                 }
  807.                 nodes = xmlRemotePorts.selectNodes("(Port|PortRange)");
  808.                 for (var nSel=0; nSel < nodes.length; nSel++)
  809.                 {
  810.                     var nodeRemove = nodes[nSel];
  811.                     nodeRemove.parentNode.removeChild(nodeRemove);
  812.                 }
  813.  
  814.                 PortList.SetCurSel(-1);
  815.                 refreshPortList();
  816.                 currentProtocol = newProtocol;
  817.             } else {
  818.                 SelProtocol[currentProtocol].checked = true;
  819.             }
  820.         }
  821.     }
  822.     else
  823.     {
  824.         currentProtocol = newProtocol;
  825.     }
  826. }
  827.  
  828. function PortSetText()
  829. {
  830.     PortProtPermitRule.style.display = "none";
  831.     PortProtBlockRule.style.display = "none";
  832.     PortProtMonitorRule.style.display = "none";
  833.     PortPermitRulePort.style.display = "none";
  834.     PortBlockRulePort.style.display = "none";
  835.     PortMonitorRulePort.style.display = "none";
  836.  
  837.     if (Action[0].checked)
  838.     {
  839.         PortProtPermitRule.style.display = "";
  840.         PortPermitRulePort.style.display = "";
  841.     }
  842.  
  843.     if (Action[1].checked)
  844.     {
  845.         PortProtBlockRule.style.display = "";
  846.         PortBlockRulePort.style.display = "";
  847.     }
  848.  
  849.     if (Action[2].checked)
  850.     {
  851.         PortProtMonitorRule.style.display = "";
  852.         PortMonitorRulePort.style.display = "";
  853.     }
  854. }
  855.  
  856. function ProtocolAndPortValidate()
  857. {
  858.  
  859.     if (PortsSel[1].checked && PortList.GetRowCount() == 0)
  860.     {
  861.         webWind.MsgBox2(StrID("PortListError"), UserManager.AppTitle);                
  862.         return false;
  863.     }
  864.  
  865.     return true;
  866. }
  867.  
  868. ////////////////////////////////////////////////////////////////////////////////////
  869. //  Logging page
  870. //
  871. function UILoggingLoad(xml)
  872. {
  873.  
  874.     var val = getElem(xml,"Logging").toLowerCase();
  875.  
  876.     //
  877.     // Default.
  878.     //
  879.     var reDialog = new RegExp("dialog", "i");
  880.     var reAlertTracker = new RegExp("AlertTracker", "i");
  881.     var reLogging = new RegExp("logging", "i");
  882.     var reDashboard = new RegExp("dashboard,dialog", "i");
  883.  
  884.     if (-1 != val.search(reAlertTracker))
  885.         ATracker.checked = true;
  886.     if (-1 != val.search(reLogging))
  887.         Logging.checked = true;
  888.     if ((-1 != val.search(reDialog)) && (-1 != val.search(reDashboard)))
  889.         SecAlert.checked = true;
  890. }
  891.  
  892. function UILoggingStore(xml)
  893. {
  894.     var loggingValue = "";
  895.  
  896.     if (SecAlert.checked)
  897.     {
  898.         if (loggingValue != "")
  899.             loggingValue += ",";
  900.  
  901.         loggingValue += SecAlert.value.toLowerCase();
  902.     }
  903.  
  904.  
  905.     if (ATracker.checked)
  906.     {
  907.         if (loggingValue != "")
  908.             loggingValue += ",";
  909.  
  910.         loggingValue += ATracker.value.toLowerCase();
  911.     }
  912.  
  913.  
  914.     if (Logging.checked)
  915.     {
  916.         if (loggingValue != "")
  917.             loggingValue += ",";
  918.  
  919.         loggingValue +=  Logging.value.toLowerCase();
  920.     }
  921.  
  922.     if(loggingValue != "")
  923.         setXMLNode(xml, "Logging", loggingValue);
  924. }
  925.  
  926. function LoggingSetText()
  927. {
  928.     if (Action[2].checked    // If the user chose to monitor ...
  929.      && !Logging.checked    // ... and no forms of monitoring are already selected ...
  930.      && !ATracker.checked
  931.      && !SecAlert.checked)
  932.         Logging.checked = true;    // ... ensure that at least one form of monitoring is selected
  933. }
  934.  
  935. ////////////////////////////////////////////////////////////////////////////////////
  936. //  Enter title and category page
  937. //
  938. var xmlCategories = null;
  939. var g_catref = 0;
  940.  
  941. function initCatList()
  942. {
  943.     var xmlFW = regORxml.FirewallData;
  944.     xmlCategories = xmlFW.selectNodes("/FirewallData/Categories/Category");
  945.  
  946.     for (var nElem = 0; nElem < xmlCategories.length; nElem++)
  947.     {
  948.         var oOption = document.createElement("OPTION");
  949.         var name = xmlCategories.item(nElem).selectSingleNode("CategoryName");
  950.         var val = xmlCategories.item(nElem).selectSingleNode("CategoryValue");
  951.         oOption.text = name.nodeTypedValue;
  952.         oOption.value = val.nodeTypedValue;
  953.     
  954.         //
  955.         // Don't display non-user categories (> 255)
  956.         //
  957.         if (oOption.value < 256)
  958.             catlist.add(oOption);
  959.     }
  960. }
  961.  
  962. function UITitleLoad(xml)
  963. {
  964.     var txt = getElem(xml,"Description");
  965.     g_catref = getElem(xml, "CategoryReference");
  966.  
  967.     if (txt == "")
  968.         titletext.value = StrID("firewall_rule");
  969.     else
  970.         titletext.value =  txt;
  971.  
  972.     //
  973.     // Ensure categories only displayed for NISFE.
  974.     // Don't display non-user categories (> 255)
  975.     //
  976.     if ("PT_FE" != UserManager.ProductType || g_catref >= 255)
  977.         return;
  978.  
  979.     catUI.style.display = "";
  980.  
  981.     initCatList();
  982.  
  983.     //
  984.     // Now set selected item in category list
  985.     //
  986.     var nItem = 0;
  987.     for (nItem = 0; nItem < catlist.length; nItem++)
  988.     {
  989.         if (catlist.item(nItem).value == g_catref)
  990.             break;
  991.     }
  992.     if (nItem < catlist.length)
  993.     {
  994.         catlist.selectedIndex = nItem;
  995.     }
  996.     else
  997.     {
  998.         // Failed to find the category... choose "General"
  999.         catlist.selectedIndex = 0;
  1000.     }
  1001. }
  1002.  
  1003. function UITitleStore(xml)
  1004. {
  1005.     setXMLNode(xml, "Description", titletext.value);
  1006.     
  1007.     if("PT_FE" == UserManager.ProductType && g_catref < 256)
  1008.         setXMLNode(xml, "CategoryReference", catlist.item(catlist.selectedIndex).value);
  1009.     else
  1010.         setXMLNode(xml, "CategoryReference", g_catref);
  1011. }
  1012.  
  1013. function TitleValidate()
  1014. {
  1015.     return true;
  1016. }
  1017. ////////////////////////////////////////////////////////////////////////////////////
  1018. //  All done page
  1019. //
  1020. function displayRuleData()
  1021. {
  1022.     //
  1023.     // Prepare a working xml doc.
  1024.     //
  1025.     var xml = new ActiveXObject("Microsoft.XMLDOM");
  1026.     xml.documentElement = xml.createElement("Rule");
  1027.     var xmlTLN = xml.selectSingleNode("Rule");
  1028.  
  1029.     setXMLNode(xmlTLN, "InUse", "enabled");
  1030.     UIActionStore(xmlTLN);
  1031.     UIDirectionStore(xmlTLN);
  1032.     UIIPStore(xmlTLN);
  1033.     UIAdapterStore(xmlTLN);
  1034.     UIPortsStore(xmlTLN);
  1035.     UILoggingStore(xmlTLN);
  1036.     UITitleStore(xmlTLN);
  1037.  
  1038.     switch (getElem(xmlTLN,"Action").toUpperCase())
  1039.     {
  1040.         case "BLOCK":
  1041.             finMonitor.style.display = "none";
  1042.             finPermit.style.display = "none";
  1043.             finBlock.style.display = "";
  1044.             break;
  1045.         case "MONITOR":
  1046.             finBlock.style.display = "none";
  1047.             finPermit.style.display = "none";
  1048.             finMonitor.style.display = "";
  1049.             break;
  1050.         case "PERMIT":
  1051.         default:
  1052.             finBlock.style.display = "none";
  1053.             finMonitor.style.display = "none";
  1054.             finPermit.style.display = "";
  1055.             break;
  1056.     }
  1057.  
  1058.     finAppName.innerText = g_appName;
  1059.     
  1060.     var rule = "<p class=nisText style='margin-top: 3; margin-bottom: 0; margin-left:0'>Description: " + getElem(xmlTLN,"Description") +
  1061.         "</p><p class=nisText style='margin-top: 3; margin-bottom: 0; margin-left:0'>Action: ";
  1062.     rule += ruleString(xmlTLN, "</p><p class=nisText style='margin-top: 3; margin-bottom: 0; margin-left:0'>");
  1063.     rule += "</p>";
  1064.     ruleSummary.innerHTML = rule;
  1065. }
  1066.  
  1067. function IPAdapters_OnClick()
  1068. {
  1069.     UIActionStore(xmlAdapterList.parentNode);
  1070.     var xml = webWnd.showModalDialog('res://fwui.dll/Adapters-popup.htm', 450, 330, xmlAdapterList);
  1071.     if (xml != null)
  1072.         xmlAdapterList = xml;
  1073. }
  1074.