private void generateFirewallConfigText(FirewallConfig fc)
        {
            // prepare the firewall config text in the list box
            StringBuilder firewallBuilder = new StringBuilder();

            firewallContentLB.Items.Add("hostname " + fc.label); firewallBuilder.AppendLine("\n");
            firewallContentLB.Items.Add("names"); firewallBuilder.AppendLine("\n");
            firewallContentLB.Items.Add("\n");

            // create the interfaces
            foreach (var ifc in fc.interfaces)
            {
                firewallContentLB.Items.Add("interface GigabitEthernet1/" + (fc.interfaces.IndexOf(ifc) + 1).ToString()); firewallBuilder.Append("\n");
                firewallContentLB.Items.Add("nameif " + ifc.interfaceName); firewallBuilder.Append("\n");
                firewallContentLB.Items.Add("security-level 100"); firewallBuilder.Append("\n");
                firewallContentLB.Items.Add("ip address " + ifc.ipAddress + " " + ifc.subnetMask); firewallBuilder.Append("\n");
                firewallContentLB.Items.Add("\n");
            }
            firewallContentLB.Items.Add("\n");

            // create the object-groups
            foreach (var og in fc.objectGroups)
            {
                if (og.networkObjects != null)
                {
                    foreach (var no in og.networkObjects)
                    {
                        firewallContentLB.Items.Add("object-group network " + og.objectName); firewallBuilder.Append("\n");
                        firewallContentLB.Items.Add(" network-object " + no.type + " " + no.ipAddress); firewallBuilder.Append("\n");
                    }
                }
                if (og.portObjects != null)
                {
                    firewallContentLB.Items.Add("object-group service " + og.objectName); firewallBuilder.Append("\n");
                    foreach (var po in og.portObjects)
                    {
                        firewallContentLB.Items.Add(" port-object eq " + po.portNumber); firewallBuilder.Append("\n");
                    }
                }
            }
            firewallContentLB.Items.Add("\n");

            // create access control list
            List <string> AccessGroups = new List <string>();

            foreach (var acl in fc.acls)
            {
                var aclString = "access-list " + acl.accessGroup + " extended " + acl.permit + " " + acl.protocol + " ";
                if (!AccessGroups.Contains(acl.accessGroup))
                {
                    AccessGroups.Add(acl.accessGroup);
                }

                foreach (var og in acl.objectGroups)
                {
                    aclString += "object-group " + og + " ";
                }
                firewallContentLB.Items.Add(aclString); firewallBuilder.Append("\n");
            }
            firewallContentLB.Items.Add("\n");

            // add the access group
            foreach (var ag in AccessGroups)
            {
                if (ag.Contains("inside"))
                {
                    firewallContentLB.Items.Add("access-group " + ag + " in interface inside"); firewallBuilder.Append("\n");
                }
                else
                {
                    firewallContentLB.Items.Add("access-group " + ag + " in interface outside"); firewallBuilder.Append("\n");
                }
            }
            firewallContentLB.Items.Add("\n");

            firewallContentLB.Items.Add("telnet timeout 5"); firewallBuilder.Append("\n");
            firewallContentLB.Items.Add("ssh timeout 5"); firewallBuilder.Append("\n");
            firewallContentLB.Items.Add("\n");

            //string firewallConfig = firewallBuilder.ToString();
            //firewallContentLB.Text = firewallConfig;
            //for (int i = 0; i < firewallBuilder.Length; i++)
            //{
            //    firewallContentLB.Items.Add(firewallBuilder[i].ToString());
            //}
        }
 public ReviewConfigForm(FirewallConfig _firewallConfig)
 {
     InitializeComponent();
     firewallConfig = _firewallConfig;
     generateFirewallConfigText(firewallConfig);
 }
示例#3
0
        private void subFirewallBtn_Click(object sender, EventArgs e)
        {
            FirewallConfig fg = new FirewallConfig();

            fg.label = configuratorTC.SelectedTab.Text;

            // Adding all the interfaces
            List <Interface> interfaces = new List <Interface>();

            for (int i = 0; i < subInterfaceGB.Controls.Count / 3; i++)
            {
                var inter = new Interface();
                inter.interfaceName = subInterfaceGB.Controls[3 * i].Text;
                inter.ipAddress     = subInterfaceGB.Controls[3 * i + 1].Text;
                inter.subnetMask    = subInterfaceGB.Controls[3 * i + 2].Text;
                interfaces.Add(inter);
            }
            fg.interfaces = interfaces;

            // Adding all the object groups
            List <ObjectGroup> ogs = new List <ObjectGroup>();

            for (int i = 0; i < subObjectGroupGB.Controls.Count / 3; i++)
            {
                var og = new ObjectGroup();
                og.objectName = subObjectGroupGB.Controls[3 * i].Text;
                og.objectType = subObjectGroupGB.Controls[3 * i + 1].Text.ToLower();
                if (og.objectType == "network")
                {
                    List <NetworkObject> networkObjects = new List <NetworkObject>();
                    var noComponents = subObjectGroupGB.Controls[3 * i + 2].Text.Split(',').ToList();
                    foreach (var noComponent in noComponents)
                    {
                        var nobject = new NetworkObject();
                        var items   = noComponent.Split('#');
                        nobject.type          = items[0];
                        nobject.ipAddress     = items[1];
                        nobject.subnetAddress = items[2];
                        networkObjects.Add(nobject);
                    }
                    og.networkObjects = networkObjects;
                }
                else
                {
                    List <PortObject> portObjects = new List <PortObject>();
                    var portComponents            = subObjectGroupGB.Controls[3 * i + 2].Text.Split(',').ToList();
                    foreach (var portComponent in portComponents)
                    {
                        var pobject = new PortObject();
                        var items   = portComponent.Split('#');
                        pobject.portCount  = Convert.ToInt32(items[0]);
                        pobject.portNumber = items[1];
                        portObjects.Add(pobject);
                    }
                    og.portObjects = portObjects;
                }
                ogs.Add(og);
            }
            fg.objectGroups = ogs;

            // Adding all the ACLS
            List <AccessControl> acls = new List <AccessControl>();

            for (int i = 0; i < subAclGB.Controls.Count / 4; i++)
            {
                var acl = new AccessControl();
                acl.accessGroup  = subAclGB.Controls[4 * i].Text;
                acl.permit       = subAclGB.Controls[4 * i + 1].Text;
                acl.protocol     = subAclGB.Controls[4 * i + 2].Text;
                acl.objectGroups = subAclGB.Controls[4 * i + 3].Text.Split(',').ToList();
                acls.Add(acl);
            }
            fg.acls = acls;

            firewallStorer.Add(new KeyValuePair <string, FirewallConfig>(fg.label, fg));
        }
        public string createFirewall(FirewallConfig fw)
        {
            string config = "";

            return(config);
        }
示例#5
0
        private void populateSubFirewallConfig(FirewallConfig fg)
        {
            // populate interfaces
            var interfaces = fg.interfaces;

            foreach (var inter in interfaces)
            {
                Label[] lb = new Label[3];
                lb[0]          = new Label();
                lb[0].Text     = inter.interfaceName;
                lb[0].Location = new Point(subInterfaceGB.Location.X + 5, 20 * interfaces.IndexOf(inter) + 15);
                lb[1]          = new Label();
                lb[1].Text     = inter.ipAddress;
                lb[1].Location = new Point(subInterfaceGB.Location.X + 150, 20 * interfaces.IndexOf(inter) + 15);
                lb[2]          = new Label();
                lb[2].Text     = inter.subnetMask;
                lb[2].Location = new Point(subInterfaceGB.Location.X + 300, 20 * interfaces.IndexOf(inter) + 15);
                subInterfaceGB.Controls.AddRange(lb);
            }

            // populate object groups
            var objectGrps = fg.objectGroups;

            foreach (var objectGrp in objectGrps)
            {
                Label[] lb = new Label[3];
                lb[0]          = new Label();
                lb[0].Text     = objectGrp.objectName;
                lb[0].Location = new Point(subObjectGroupGB.Location.X + 5, 20 * objectGrps.IndexOf(objectGrp) + 15);
                lb[1]          = new Label();
                lb[1].Text     = objectGrp.objectType;
                lb[1].Location = new Point(subObjectGroupGB.Location.X + 150, 20 * objectGrps.IndexOf(objectGrp) + 15);

                lb[2] = new Label();
                List <string> storeObjects = new List <string>();
                if (objectGrp.objectType == "network")
                {
                    foreach (var item in objectGrp.networkObjects)
                    {
                        var hostString = "";
                        hostString += (item.type + "#" + item.ipAddress + "#" + item.subnetAddress + "#");
                        storeObjects.Add(hostString);
                    }
                    lb[2].Text = string.Join(",", storeObjects.ToArray());
                }
                else
                {
                    foreach (var item in objectGrp.portObjects)
                    {
                        var hostString = "";
                        hostString += (item.portCount.ToString() + "#" + item.portNumber + "#");
                        storeObjects.Add(hostString);
                    }
                    lb[2].Text = string.Join(",", storeObjects.ToArray());
                }
                lb[2].Location = new Point(subObjectGroupGB.Location.X + 300, 20 * objectGrps.IndexOf(objectGrp) + 15);
                subObjectGroupGB.Controls.AddRange(lb);
            }

            // populate ACLS
            var acls = fg.acls;

            foreach (var acl in acls)
            {
                Label[] lb = new Label[4];
                lb[0]          = new Label();
                lb[0].Text     = acl.accessGroup;
                lb[0].Location = new Point(subAclGB.Location.X + 5, 20 * acls.IndexOf(acl) + 15);
                lb[1]          = new Label();
                lb[1].Text     = acl.permit;
                lb[1].Location = new Point(subAclGB.Location.X + 150, 20 * acls.IndexOf(acl) + 15);
                lb[2]          = new Label();
                lb[2].Text     = acl.protocol;
                lb[2].Location = new Point(subAclGB.Location.X + 250, 20 * acls.IndexOf(acl) + 15);
                lb[3]          = new Label();
                lb[3].Text     = string.Join(",", acl.objectGroups.ToArray());
                lb[3].Location = new Point(subAclGB.Location.X + 350, 20 * acls.IndexOf(acl) + 15);

                subAclGB.Controls.AddRange(lb);
            }
        }