diff --git a/EduNetworkBuilder/DeviceConfig.Designer.cs b/EduNetworkBuilder/DeviceConfig.Designer.cs index 6f0c864..55b0bb1 100644 --- a/EduNetworkBuilder/DeviceConfig.Designer.cs +++ b/EduNetworkBuilder/DeviceConfig.Designer.cs @@ -47,6 +47,7 @@ this.cbDHCP = new System.Windows.Forms.CheckBox(); this.btnDHCP = new System.Windows.Forms.Button(); this.btnVLAN = new System.Windows.Forms.Button(); + this.btnFirewall = new System.Windows.Forms.Button(); this.SuspendLayout(); // // tbHostname @@ -229,14 +230,24 @@ // // btnVLAN // - this.btnVLAN.Location = new System.Drawing.Point(182, 80); + this.btnVLAN.Location = new System.Drawing.Point(365, 55); this.btnVLAN.Name = "btnVLAN"; - this.btnVLAN.Size = new System.Drawing.Size(75, 23); + this.btnVLAN.Size = new System.Drawing.Size(94, 23); this.btnVLAN.TabIndex = 21; this.btnVLAN.Text = "VLANs"; this.btnVLAN.UseVisualStyleBackColor = true; this.btnVLAN.Click += new System.EventHandler(this.btnVLAN_Click); // + // btnFirewall + // + this.btnFirewall.Location = new System.Drawing.Point(251, 55); + this.btnFirewall.Name = "btnFirewall"; + this.btnFirewall.Size = new System.Drawing.Size(113, 23); + this.btnFirewall.TabIndex = 22; + this.btnFirewall.Text = "Firewall"; + this.btnFirewall.UseVisualStyleBackColor = true; + this.btnFirewall.Click += new System.EventHandler(this.btnFirewall_Click); + // // DeviceConfig // this.AcceptButton = this.btnOK; @@ -244,6 +255,7 @@ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.btnCancel; this.ClientSize = new System.Drawing.Size(471, 365); + this.Controls.Add(this.btnFirewall); this.Controls.Add(this.btnVLAN); this.Controls.Add(this.btnDHCP); this.Controls.Add(this.cbDHCP); @@ -292,5 +304,6 @@ private System.Windows.Forms.CheckBox cbDHCP; private System.Windows.Forms.Button btnDHCP; private System.Windows.Forms.Button btnVLAN; + private System.Windows.Forms.Button btnFirewall; } } \ No newline at end of file diff --git a/EduNetworkBuilder/DeviceConfig.cs b/EduNetworkBuilder/DeviceConfig.cs index 8d63d35..e293ffb 100644 --- a/EduNetworkBuilder/DeviceConfig.cs +++ b/EduNetworkBuilder/DeviceConfig.cs @@ -56,7 +56,8 @@ namespace EduNetworkBuilder btnRoutes.Text = NB.Translate("DC_btnRoutes"); cbDHCP.Text = NB.Translate("DC_cbDHCP"); btnDHCP.Text = NB.Translate("_DHCP"); - btnVLAN.Text = NB.Translate("DC_btnVLAN"); + btnVLAN.Text = NB.Translate("DC_btnVLAN"); + btnFirewall.Text = NB.Translate("DC_btnFirewall"); Text = NB.Translate("DC_Form"); } @@ -95,6 +96,10 @@ namespace EduNetworkBuilder nicLocked = true; interfacesLocked = true; } + if (theNet.FirewallEnabled && ndCLonedItem.DoesFirewall()) + btnFirewall.Visible = true; + else + btnFirewall.Visible = false; if (lbNics.SelectedIndex != -1) { string nic_name = StripNicName(lbNics.SelectedItem.ToString()); @@ -512,5 +517,15 @@ namespace EduNetworkBuilder VLANConfig VLC = new VLANConfig((NetworkDevice)ClonedItem); VLC.ShowDialog(); } + + private void btnFirewall_Click(object sender, EventArgs e) + { + //Open a firewall editing window. + if (ClonedItem is NetworkDevice) + { + FirewallEditor FEditor = new FirewallEditor((NetworkDevice)ClonedItem); + FEditor.ShowDialog(); + } + } } } diff --git a/EduNetworkBuilder/EduNetworkBuilder.csproj b/EduNetworkBuilder/EduNetworkBuilder.csproj index 483fe8b..039eac2 100644 --- a/EduNetworkBuilder/EduNetworkBuilder.csproj +++ b/EduNetworkBuilder/EduNetworkBuilder.csproj @@ -244,7 +244,6 @@ - diff --git a/EduNetworkBuilder/FirewallEditor.cs b/EduNetworkBuilder/FirewallEditor.cs index 10ea049..6556264 100644 --- a/EduNetworkBuilder/FirewallEditor.cs +++ b/EduNetworkBuilder/FirewallEditor.cs @@ -7,23 +7,20 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using System.Xml; namespace EduNetworkBuilder { - public class FirewallRule - { - public string Source; - public string Destination; - public FirewallRuleType Action; - } - public partial class FirewallEditor : Form { - public FirewallEditor() + NetworkDevice FirewallDevice = null; + public FirewallEditor(NetworkDevice WhatToEdit) { InitializeComponent(); + FirewallDevice = WhatToEdit; UpdateForm(); + Icon = Properties.Resources.NBIco; } void UpdateForm() @@ -32,11 +29,32 @@ namespace EduNetworkBuilder btnDel.Visible = true; else btnDel.Visible = false; + int selected = lbRules.SelectedIndex; + lbRules.Items.Clear(); + foreach (FirewallRule FW in FirewallDevice.FirewallRules) + { + string OneLine = FW.Action.ToString() + " " + FW.Source + " -> " + FW.Destination; + lbRules.Items.Add(OneLine); + } + if (selected >= 0 && selected < lbRules.Items.Count) + lbRules.SelectedIndex = selected; + else + { + if (lbRules.Items.Count > 0) + lbRules.SelectedIndex = 0; + } } private void btnNew_Click(object sender, EventArgs e) { - + FirewallRule FW = new FirewallRule("","",FirewallRuleType.Drop); + NetTestEditor NTE = new NetTestEditor(FW,FirewallDevice); + NTE.ShowDialog(); + if(FW.Source!="" && FW.Destination != "") + { + FirewallDevice.FirewallRules.Add(FW); + } + UpdateForm(); } private void btnDel_Click(object sender, EventArgs e) @@ -46,7 +64,7 @@ namespace EduNetworkBuilder private void btnDone_Click(object sender, EventArgs e) { - + Close(); } } } diff --git a/EduNetworkBuilder/NB.cs b/EduNetworkBuilder/NB.cs index a953e05..b749900 100644 --- a/EduNetworkBuilder/NB.cs +++ b/EduNetworkBuilder/NB.cs @@ -230,6 +230,54 @@ namespace EduNetworkBuilder } } + [Serializable] + public class FirewallRule + { + public string Source; + public string Destination; + public FirewallRuleType Action; + + public FirewallRule(string source, string dest, FirewallRuleType action) + { + Source = source; + Destination = dest; + Action = action; + } + + public FirewallRule(XmlNode theNode) + { + foreach (XmlNode Individual in theNode.ChildNodes) + { + XmlNodeType myNodetype = Individual.NodeType; + if (myNodetype == XmlNodeType.Element) + { + switch (Individual.Name.ToLower()) + { + case "source": + Source = Individual.InnerText; + break; + case "destination": + Destination = Individual.InnerText; + break; + case "action": + Action = NB.ParseEnum(Individual.InnerText); + break; + } + } + } + } + + public void Save(XmlWriter writer, string tag) + { + writer.WriteStartElement(tag); + writer.WriteElementString("source", Source); + writer.WriteElementString("destination", Destination); + writer.WriteElementString("action", Action.ToString()); + writer.WriteEndElement(); + } + } + + class NB { diff --git a/EduNetworkBuilder/NetTestEditor.cs b/EduNetworkBuilder/NetTestEditor.cs index 65da075..1e93605 100644 --- a/EduNetworkBuilder/NetTestEditor.cs +++ b/EduNetworkBuilder/NetTestEditor.cs @@ -21,12 +21,18 @@ namespace EduNetworkBuilder List HostNames = new List(); List Networks = new List(); List Broadcasts = new List(); + List Interfaces = new List(); bool processing = false; + FirewallRule RuleToEdit; + FirewallRule OrigRule; + NetworkDevice FirewallDevice = null; + bool EditingFirewallRule = false; public NetTestEditor(NetTest WhatToEdit) { + EditingFirewallRule = false; InitializeComponent(); - LanguagifyComponents(); + LanguagifyTestComponents(); OrigTest = WhatToEdit; ToEdit = new NetTest(OrigTest); @@ -37,23 +43,65 @@ namespace EduNetworkBuilder UpdateForm(); } - private void LanguagifyComponents() + public NetTestEditor(FirewallRule WhatToEdit, NetworkDevice DeviceWorkingOn) { - Text = NB.Translate("NTE_lblSource"); - Text = NB.Translate("NTE_lblTest"); - Text = NB.Translate("NTE_lblDest"); - Text = NB.Translate("_Done"); - Text = NB.Translate("_Cancel"); + EditingFirewallRule = true; + InitializeComponent(); + LanguagifyFWComponents(); + OrigRule = WhatToEdit; + FirewallDevice = DeviceWorkingOn; + RuleToEdit = new FirewallRule(OrigRule.Source, OrigRule.Destination, OrigRule.Action); + // Make a list of all interfaces on this device + foreach (string nname in DeviceWorkingOn.NICNames()) + { + NetworkCard nic = DeviceWorkingOn.NicFromName(nname); + for (int i = 0; i < nic.IFCount; i++) + { + NetworkInterface nif = nic.GetInterface(i); + Interfaces.Add(nif.nic_name); + } + } + if (Interfaces.Count < 2) + { + //we cannot do firewalling on a device that has one or zero interfaces. + Close(); + } + UpdateForm(); + } + + private void LanguagifyTestComponents() + { + lblSource.Text = NB.Translate("NTE_lblSource"); + lblTest.Text = NB.Translate("NTE_lblTest"); + lblDest.Text = NB.Translate("NTE_lblDest"); + btnOK.Text = NB.Translate("_Done"); + btnCancel.Text = NB.Translate("_Cancel"); Text = NB.Translate("NTE_Form"); } + private void LanguagifyFWComponents() + { + LanguagifyTestComponents(); + lblTest.Text = NB.Translate("NTE_lblTestFW"); + } + private void btnOK_Click(object sender, EventArgs e) { - OrigTest.UpdateValuesFromAnother(ToEdit); - OrigTest.TaskWasDone = false; //We edited it. Set it to false - OrigTest.SetInitialDoneState(); //Set some of them to true (locked. etc) - Close(); + if (EditingFirewallRule) + { + OrigRule.Destination = RuleToEdit.Destination; + OrigRule.Source = RuleToEdit.Source; + OrigRule.Action = RuleToEdit.Action; + Close(); + } + else + { + OrigTest.UpdateValuesFromAnother(ToEdit); + OrigTest.TaskWasDone = false; //We edited it. Set it to false + OrigTest.SetInitialDoneState(); //Set some of them to true (locked. etc) + Close(); + } } private void btnCancel_Click(object sender, EventArgs e) @@ -65,202 +113,256 @@ namespace EduNetworkBuilder { NetworkDevice sItem; processing = true; + List tList = new List(); + Network theNet = NB.GetNetwork(); //We add all the hostnames as source - cbSource.Items.Clear(); - foreach(string host in HostNames) - { - cbSource.Items.Add(host); - } - - //The tests are just the list of available tests. - cbTest.Items.Clear(); - List tList = new List(); - foreach (string test in Enum.GetNames(typeof(NetTestType))) - { - tList.Add(test); - } - tList.Sort(); //Sort them alphabetically. Just to make things easier - foreach (string test in tList) - { - cbTest.Items.Add(test); - } - - cbDest.Items.Clear(); - if (ToEdit.TheTest == NetTestType.NeedsRouteToNet) - { //List all the networks - foreach (string subnet in Networks) - { - cbDest.Items.Add(subnet); - } - } - else if (ToEdit.TheTest == NetTestType.DHCPServerEnabled) - { - cbDest.Items.Add(true.ToString()); - cbDest.Items.Add(false.ToString()); - } - else if (ToEdit.TheTest == NetTestType.HelpRequest) - { - foreach (string HelpLevel in Enum.GetNames(typeof(NetTestVerbosity))) - { - cbDest.Items.Add(HelpLevel); - } - cbDest.Items.Add("?Button"); - cbDest.Items.Add("ViewButton"); - } - else if (ToEdit.TheTest == NetTestType.ReadContextHelp) + if (EditingFirewallRule) { cbSource.Items.Clear(); - List theNames = new List(); - theNames.AddRange(Enum.GetNames(typeof(HelpTopics))); - theNames.Sort(); - theNames.Remove("None"); - foreach (string ContextHelp in theNames) + cbDest.Items.Clear(); + cbTest.Items.Clear(); + + foreach (string one in Interfaces) { - cbSource.Items.Add(ContextHelp); + if (one != RuleToEdit.Destination) + cbSource.Items.Add(one); //We add all of them except the selected destination + if (one != RuleToEdit.Source) + cbDest.Items.Add(one); //We add all of them except the selected source } - cbDest.Items.Add(NB.Translate("_Read")); - } - else if (ToEdit.TheTest == NetTestType.LockAll || ToEdit.TheTest == NetTestType.LockGateway) - { - cbDest.Items.Add(NB.Translate("_All")); - } - else if (ToEdit.TheTest == NetTestType.LockDHCP) - { - //return all the dhcp ranges - sItem = theNet.GetDeviceFromName(ToEdit.sHost); - foreach(string ip in sItem.DHCPStrings(false)) + foreach (string test in Enum.GetNames(typeof(FirewallRuleType))) { - cbDest.Items.Add(ip); + tList.Add(test); } - } - else if (ToEdit.TheTest == NetTestType.LockIP) - { - //return all the dhcp ranges - sItem = theNet.GetDeviceFromName(ToEdit.sHost); - foreach (IPAddress ip in sItem.IPAddressList()) + tList.Sort(); //Sort them alphabetically. Just to make things easier + foreach (string test in tList) { - cbDest.Items.Add(ip.GetIPString); + cbTest.Items.Add(test); } - } - else if (ToEdit.TheTest == NetTestType.LockRoute) - { - //return all the dhcp ranges - sItem = theNet.GetDeviceFromName(ToEdit.sHost); - foreach (IPAddress ip in sItem.ListRoutes()) + //select the current stuff + if (cbSource.Items.Contains(RuleToEdit.Source)) { - cbDest.Items.Add(ip.GetIPString); + cbSource.SelectedItem = RuleToEdit.Source; } - } - else if (ToEdit.TheTest == NetTestType.LockNic) - { - //return all the dhcp ranges - sItem = theNet.GetDeviceFromName(ToEdit.sHost); - foreach (string nname in sItem.NICNames()) + else { - cbDest.Items.Add(nname); + if (cbSource.Items.Count > 0) + cbSource.SelectedIndex = 0; //select the first item } - } - else if(ToEdit.TheTest == NetTestType.LockVLANNames) - { - //No items for lockvlannames - cbDest.Items.Add(NB.Translate("_All")); - cbSource.Items.Clear(); - cbSource.Items.Add(NB.Translate("_All")); - } - else if (ToEdit.TheTest == NetTestType.LockNicVLAN) - { - sItem = theNet.GetDeviceFromName(ToEdit.sHost); - foreach (string nname in sItem.NICNames()) + + if (cbDest.Items.Contains(RuleToEdit.Source)) { - NetworkCard nic = sItem.NicFromName(nname); - if (!nic.NicCanDoVLANs()) continue; - cbDest.Items.Add(nic.NicName()); + cbDest.SelectedItem = RuleToEdit.Source; } - } - else if (ToEdit.TheTest == NetTestType.LockVLANsOnHost) - { - //No items for lockvlannames - cbDest.Items.Add(NB.Translate("_All")); - } - else if (ToEdit.TheTest == NetTestType.LockInterfaceVLAN) - { - sItem = theNet.GetDeviceFromName(ToEdit.sHost); - foreach (string nname in sItem.NICNames()) + else { - NetworkCard nic = sItem.NicFromName(nname); - if (!nic.NicCanDoVLANs()) continue; - for (int i = 0; i < nic.IFCount; i++) - { - NetworkInterface nif = nic.GetInterface(i); - cbDest.Items.Add(nif.nic_name); - } + if (cbDest.Items.Count > 0) + cbDest.SelectedIndex = 0; //select the first item } - } - else if (ToEdit.TheTest == NetTestType.NeedsForbiddenVLAN || - ToEdit.TheTest == NetTestType.NeedsTaggedVLAN || - ToEdit.TheTest == NetTestType.NeedsUntaggedVLAN ) - { - sItem = theNet.GetDeviceFromName(ToEdit.sHost); - foreach (string nname in sItem.NICNames()) + + if (cbTest.Items.Contains(RuleToEdit.Action.ToString())) { - NetworkCard nic = sItem.NicFromName(nname); - if (!nic.NicCanDoVLANs()) continue; - for (int i = 0; i < nic.IFCount; i++) - { - NetworkInterface nif = nic.GetInterface(i); - foreach (VLANName vn in theNet.VlanNames) - { - cbDest.Items.Add(nif.nic_name + " - " + vn.ID.ToString()); - } - } + cbTest.SelectedItem = RuleToEdit.Action.ToString(); } + else + cbTest.SelectedIndex = 0;//select first item } else - { //List all the hosts + { + cbSource.Items.Clear(); foreach (string host in HostNames) { - cbDest.Items.Add(host); + cbSource.Items.Add(host); } - if (ToEdit.TheTest == NetTestType.SuccessfullyPings) - { //List all the network broadcasts - foreach (string subnet in Broadcasts) + //The tests are just the list of available tests. + cbTest.Items.Clear(); + foreach (string test in Enum.GetNames(typeof(NetTestType))) + { + tList.Add(test); + } + tList.Sort(); //Sort them alphabetically. Just to make things easier + foreach (string test in tList) + { + cbTest.Items.Add(test); + } + + cbDest.Items.Clear(); + if (ToEdit.TheTest == NetTestType.NeedsRouteToNet) + { //List all the networks + foreach (string subnet in Networks) { cbDest.Items.Add(subnet); } } - } + else if (ToEdit.TheTest == NetTestType.DHCPServerEnabled) + { + cbDest.Items.Add(true.ToString()); + cbDest.Items.Add(false.ToString()); + } + else if (ToEdit.TheTest == NetTestType.HelpRequest) + { + foreach (string HelpLevel in Enum.GetNames(typeof(NetTestVerbosity))) + { + cbDest.Items.Add(HelpLevel); + } + cbDest.Items.Add("?Button"); + cbDest.Items.Add("ViewButton"); + } + else if (ToEdit.TheTest == NetTestType.ReadContextHelp) + { + cbSource.Items.Clear(); + List theNames = new List(); + theNames.AddRange(Enum.GetNames(typeof(HelpTopics))); + theNames.Sort(); + theNames.Remove("None"); + foreach (string ContextHelp in theNames) + { + cbSource.Items.Add(ContextHelp); + } + cbDest.Items.Add(NB.Translate("_Read")); + } + else if (ToEdit.TheTest == NetTestType.LockAll || ToEdit.TheTest == NetTestType.LockGateway) + { + cbDest.Items.Add(NB.Translate("_All")); + } + else if (ToEdit.TheTest == NetTestType.LockDHCP) + { + //return all the dhcp ranges + sItem = theNet.GetDeviceFromName(ToEdit.sHost); + foreach (string ip in sItem.DHCPStrings(false)) + { + cbDest.Items.Add(ip); + } + } + else if (ToEdit.TheTest == NetTestType.LockIP) + { + //return all the dhcp ranges + sItem = theNet.GetDeviceFromName(ToEdit.sHost); + foreach (IPAddress ip in sItem.IPAddressList()) + { + cbDest.Items.Add(ip.GetIPString); + } + } + else if (ToEdit.TheTest == NetTestType.LockRoute) + { + //return all the dhcp ranges + sItem = theNet.GetDeviceFromName(ToEdit.sHost); + foreach (IPAddress ip in sItem.ListRoutes()) + { + cbDest.Items.Add(ip.GetIPString); + } + } + else if (ToEdit.TheTest == NetTestType.LockNic) + { + //return all the dhcp ranges + sItem = theNet.GetDeviceFromName(ToEdit.sHost); + foreach (string nname in sItem.NICNames()) + { + cbDest.Items.Add(nname); + } + } + else if (ToEdit.TheTest == NetTestType.LockVLANNames) + { + //No items for lockvlannames + cbDest.Items.Add(NB.Translate("_All")); + cbSource.Items.Clear(); + cbSource.Items.Add(NB.Translate("_All")); + } + else if (ToEdit.TheTest == NetTestType.LockNicVLAN) + { + sItem = theNet.GetDeviceFromName(ToEdit.sHost); + foreach (string nname in sItem.NICNames()) + { + NetworkCard nic = sItem.NicFromName(nname); + if (!nic.NicCanDoVLANs()) continue; + cbDest.Items.Add(nic.NicName()); + } + } + else if (ToEdit.TheTest == NetTestType.LockVLANsOnHost) + { + //No items for lockvlannames + cbDest.Items.Add(NB.Translate("_All")); + } + else if (ToEdit.TheTest == NetTestType.LockInterfaceVLAN) + { + sItem = theNet.GetDeviceFromName(ToEdit.sHost); + foreach (string nname in sItem.NICNames()) + { + NetworkCard nic = sItem.NicFromName(nname); + if (!nic.NicCanDoVLANs()) continue; + for (int i = 0; i < nic.IFCount; i++) + { + NetworkInterface nif = nic.GetInterface(i); + cbDest.Items.Add(nif.nic_name); + } + } + } + else if (ToEdit.TheTest == NetTestType.NeedsForbiddenVLAN || + ToEdit.TheTest == NetTestType.NeedsTaggedVLAN || + ToEdit.TheTest == NetTestType.NeedsUntaggedVLAN) + { + sItem = theNet.GetDeviceFromName(ToEdit.sHost); + foreach (string nname in sItem.NICNames()) + { + NetworkCard nic = sItem.NicFromName(nname); + if (!nic.NicCanDoVLANs()) continue; + for (int i = 0; i < nic.IFCount; i++) + { + NetworkInterface nif = nic.GetInterface(i); + foreach (VLANName vn in theNet.VlanNames) + { + cbDest.Items.Add(nif.nic_name + " - " + vn.ID.ToString()); + } + } + } + } + else + { //List all the hosts + foreach (string host in HostNames) + { + cbDest.Items.Add(host); + } - //Now we select all the appropriate items. - if(cbSource.Items.Contains(ToEdit.sHost)) - { - cbSource.SelectedItem = ToEdit.sHost; - } - else - { - if(cbSource.Items.Count > 0) - cbSource.SelectedIndex = 0; //select the first item - } + if (ToEdit.TheTest == NetTestType.SuccessfullyPings) + { //List all the network broadcasts + foreach (string subnet in Broadcasts) + { + cbDest.Items.Add(subnet); + } + } + } - if (cbDest.Items.Contains(ToEdit.dHost)) - { - cbDest.SelectedItem = ToEdit.dHost; - } - else - { - if (cbDest.Items.Count > 0) - cbDest.SelectedIndex = 0; //select the first item - } + //Now we select all the appropriate items. + if (cbSource.Items.Contains(ToEdit.sHost)) + { + cbSource.SelectedItem = ToEdit.sHost; + } + else + { + if (cbSource.Items.Count > 0) + cbSource.SelectedIndex = 0; //select the first item + } - if (cbTest.Items.Contains(ToEdit.TheTest.ToString())) - { - cbTest.SelectedItem = ToEdit.TheTest.ToString(); - } - else - { - if (cbTest.Items.Count > 0) - cbTest.SelectedIndex = 0; //select the first item + if (cbDest.Items.Contains(ToEdit.dHost)) + { + cbDest.SelectedItem = ToEdit.dHost; + } + else + { + if (cbDest.Items.Count > 0) + cbDest.SelectedIndex = 0; //select the first item + } + + if (cbTest.Items.Contains(ToEdit.TheTest.ToString())) + { + cbTest.SelectedItem = ToEdit.TheTest.ToString(); + } + else + { + if (cbTest.Items.Count > 0) + cbTest.SelectedIndex = 0; //select the first item + } } processing = false; } @@ -274,77 +376,121 @@ namespace EduNetworkBuilder { if (processing) return true; //If we are processing, we are all OK. Network theNet = NB.GetNetwork(); - NetTestType ntt = NB.ParseEnum(cbTest.SelectedItem.ToString()); - if (ntt == NetTestType.ReadContextHelp) return true; - if (ntt == NetTestType.DHCPServerEnabled) return true; - if (cbSource.SelectedItem.ToString() == cbDest.SelectedItem.ToString() && ntt != NetTestType.HelpRequest) - return false; //Source cannot equal dest - if (theNet.GetDeviceFromName(cbSource.SelectedItem.ToString()) == null) - return false; //This should never happen with a drop-down list, but just in case... - if (ntt == NetTestType.LockAll || ntt == NetTestType.LockDHCP || ntt == NetTestType.LockIP || - ntt == NetTestType.LockNic || ntt == NetTestType.LockRoute) + if (EditingFirewallRule) + { + //The source cannot be the dest. + //The values need to exist return true; - if (ntt == NetTestType.NeedsRouteToNet) - { - //We should have a network, not a host. - } - else if (ntt == NetTestType.HelpRequest) - { - //This uses a verbosity - } - else if (ntt == NetTestType.LockInterfaceVLAN || ntt == NetTestType.LockNicVLAN || - ntt == NetTestType.LockVLANNames || ntt == NetTestType.LockVLANsOnHost) - { - return true; - } - else if (ntt == NetTestType.NeedsUntaggedVLAN || ntt == NetTestType.NeedsTaggedVLAN || - ntt == NetTestType.NeedsForbiddenVLAN) - { - //We have an interface and a network ID. Verify they exist - if (cbDest.SelectedIndex < 0) return false; - Match result = Regex.Match(cbDest.SelectedItem.ToString(), @"(?[A-z:0-9]+) - (?\d+)"); - if (result.Groups["interface"] != null && result.Groups["id"] != null) - return true; - return false; } else { - if (ntt == NetTestType.SuccessfullyPings) return true; - if (theNet.GetDeviceFromName(cbDest.SelectedItem.ToString()) == null) + NetTestType ntt = NB.ParseEnum(cbTest.SelectedItem.ToString()); + if (ntt == NetTestType.ReadContextHelp) return true; + if (ntt == NetTestType.DHCPServerEnabled) return true; + if (cbSource.SelectedItem.ToString() == cbDest.SelectedItem.ToString() && ntt != NetTestType.HelpRequest) + return false; //Source cannot equal dest + if (theNet.GetDeviceFromName(cbSource.SelectedItem.ToString()) == null) return false; //This should never happen with a drop-down list, but just in case... + if (ntt == NetTestType.LockAll || ntt == NetTestType.LockDHCP || ntt == NetTestType.LockIP || + ntt == NetTestType.LockNic || ntt == NetTestType.LockRoute) + return true; + if (ntt == NetTestType.NeedsRouteToNet) + { + //We should have a network, not a host. + } + else if (ntt == NetTestType.HelpRequest) + { + //This uses a verbosity + } + else if (ntt == NetTestType.LockInterfaceVLAN || ntt == NetTestType.LockNicVLAN || + ntt == NetTestType.LockVLANNames || ntt == NetTestType.LockVLANsOnHost) + { + return true; + } + else if (ntt == NetTestType.NeedsUntaggedVLAN || ntt == NetTestType.NeedsTaggedVLAN || + ntt == NetTestType.NeedsForbiddenVLAN) + { + //We have an interface and a network ID. Verify they exist + if (cbDest.SelectedIndex < 0) return false; + Match result = Regex.Match(cbDest.SelectedItem.ToString(), @"(?[A-z:0-9]+) - (?\d+)"); + if (result.Groups["interface"] != null && result.Groups["id"] != null) + return true; + return false; + } + else + { + if (ntt == NetTestType.SuccessfullyPings) return true; + if (theNet.GetDeviceFromName(cbDest.SelectedItem.ToString()) == null) + return false; //This should never happen with a drop-down list, but just in case... + } } return true; } private void cbTest_SelectedValueChanged(object sender, EventArgs e) { - + if (EditingFirewallRule) + { + RuleToEdit.Action = NB.ParseEnum(cbTest.SelectedItem.ToString()); + if (!processing) + UpdateForm(); + } + else + { ToEdit.TheTest = NB.ParseEnum(cbTest.SelectedItem.ToString()); - if (!processing) - UpdateForm(); - + if (!processing) + UpdateForm(); + } } private void cbSource_SelectedValueChanged(object sender, EventArgs e) { - if (validate_choices()) + if (EditingFirewallRule) { - ToEdit.sHost = cbSource.SelectedItem.ToString(); + if (validate_choices()) + { + RuleToEdit.Source = cbSource.SelectedItem.ToString(); + if (!processing) UpdateForm(); + } + else + if (!processing) + UpdateForm(); } else - if (!processing) + { + if (validate_choices()) + { + ToEdit.sHost = cbSource.SelectedItem.ToString(); + } + else + if (!processing) UpdateForm(); + } } private void cbDest_SelectedValueChanged(object sender, EventArgs e) { - if (validate_choices()) + if (EditingFirewallRule) { - ToEdit.dHost = cbDest.SelectedItem.ToString(); + if (validate_choices()) + { + RuleToEdit.Destination = cbDest.SelectedItem.ToString(); + if (!processing) UpdateForm(); + } + else + if (!processing) + UpdateForm(); } else - if (!processing) + { + if (validate_choices()) + { + ToEdit.dHost = cbDest.SelectedItem.ToString(); + } + else + if (!processing) UpdateForm(); + } } } } diff --git a/EduNetworkBuilder/NetworkDevice.cs b/EduNetworkBuilder/NetworkDevice.cs index 09c74f6..9b9e5d3 100644 --- a/EduNetworkBuilder/NetworkDevice.cs +++ b/EduNetworkBuilder/NetworkDevice.cs @@ -33,7 +33,7 @@ namespace EduNetworkBuilder public bool CanAddNics = false; public Color BackgroundColor = Color.Empty; protected Color MorphColor = Color.Empty; - protected List FirewallRules = new List(); + public List FirewallRules = new List(); public NetworkDevice(NetworkComponentType what, string tHostname, Point tLocation, NicType firstNic = NicType.eth) { @@ -373,6 +373,10 @@ namespace EduNetworkBuilder IPAddress dhcpip = new IPAddress(Individual); DHCPRanges.Add(dhcpip); break; + case "firwallrule": + FirewallRule fwr = new FirewallRule(Individual); + FirewallRules.Add(fwr); + break; case "morphcolor": MorphColor = Color.FromName(Individual.InnerText); break; @@ -407,6 +411,10 @@ namespace EduNetworkBuilder { dhcp.Save(writer, "dhcprange"); } + foreach (FirewallRule fwr in FirewallRules) + { + fwr.Save(writer, "firewallrule"); + } writer.WriteEndElement(); } diff --git a/EduNetworkBuilder/OptionsWindow.cs b/EduNetworkBuilder/OptionsWindow.cs index b51030d..a353caf 100644 --- a/EduNetworkBuilder/OptionsWindow.cs +++ b/EduNetworkBuilder/OptionsWindow.cs @@ -65,6 +65,7 @@ namespace EduNetworkBuilder lblStartingHelp.Text = NB.Translate("OW_lblStartingHelp"); cbVLANs.Text = NB.Translate("OW_cbVLANs"); cb_ColoredPackets.Text = NB.Translate("OW_OWVLANColoredPackets"); + cbFirewallEnabled.Text = NB.Translate("OW_cbFirewallEnabled"); Text = NB.Translate("OW_Form"); } @@ -105,7 +106,7 @@ namespace EduNetworkBuilder cbStartingHelpLevel.Items.Add(helplevel); } cbStartingHelpLevel.SelectedItem = myNet.StartingHelpLevel.ToString(); - + cbVLANs_CheckedChanged(this, EventArgs.Empty); } private void SaveValuesToNetwork() diff --git a/EduNetworkBuilder/Resources/languages/edustrings.resx b/EduNetworkBuilder/Resources/languages/edustrings.resx index c336a40..651ee14 100644 --- a/EduNetworkBuilder/Resources/languages/edustrings.resx +++ b/EduNetworkBuilder/Resources/languages/edustrings.resx @@ -1609,6 +1609,10 @@ When packets are passing across a VLAN link, color the packets so we can visualize them better. OW_OWVLANColoredPacketsTT = When packets are passing across a VLAN link, color the packets so we can visualize them better. + + Firewall + DC_btnFirewall = Firewall + Locked Out. Cannot determine settings for this device. NB_LockedOut = Locked Out. Cannot determine settings for this device. @@ -1621,4 +1625,12 @@ ERROR: Packet forbidden by Management Interface VLAN ND_PrepPackVLANErr = ERROR: Packet forbidden by Management Interface VLAN + + Action + NTE_lblTestFW = Action + + + Adv. Firewall Enabled + OW_cbFirewallEnabled = Adv. Firewall Enabled + \ No newline at end of file