Beispiel #1
0
        private void Configure_Click(object sender, RoutedEventArgs e)
        {
            StaticGlobal.firewallmac = currentselectedItem.Header.ToString().Replace("防火墙  MAC: ", "");
            FireWallConfigurationApply fwca = new FireWallConfigurationApply();

            fwca.MAClabel.Content = "MAC: " + StaticGlobal.firewallmac;
            fwca.IPlabel.Content  = "IP: " + StaticGlobal.FwMACandIP[StaticGlobal.firewallmac];
            DB_DataGridbinding fw = new DB_DataGridbinding();

            fw.DPIDB_Gridbinding();
            fwca.ShowDialog();
        }
Beispiel #2
0
        private void Addbutton_Click(object sender, RoutedEventArgs e)
        {
            //需要加入的规则信息
            string protocoltext = ProtocolComboBox.SelectedItem.ToString();
            string sourcetext;

            if (SourceIPCheck.IsChecked == false)
            {
                sourcetext = SourceIPtextBox_1.Text + "." + SourceIPtextBox_2.Text + "." + SourceIPtextBox_3.Text + "." + SourceIPtextBox_4.Text;
            }
            else
            {
                sourcetext = "any";
            }
            string destinationtext;

            if (DestinationIPCheck.IsChecked == false)
            {
                destinationtext = DestinationIPtextBox_1.Text + "." + DestinationIPtextBox_2.Text + "." + DestinationIPtextBox_3.Text + "." + DestinationIPtextBox_4.Text;
            }
            else
            {
                destinationtext = "any";
            }
            string    coiladdressstarttext = CoilAddressStarttextBox.Text;
            string    coiladdressendtext   = CoilAddressEndtextBox.Text;
            int       mindatatext          = Convert.ToInt16(MinDatatextBox.Text);
            int       maxdatatext          = Convert.ToInt16(MaxDatatextBox.Text);
            string    functioncodetext     = FunctionCodeComboBox.Text;
            bool      logtext = Convert.ToBoolean(logcheckBox.IsChecked);
            IPAddress ip;

            if (ProtocolComboBox.Text == "modbusTcp")
            {
                //IPAddress.TryParse(sourcetext, out ip) && IPAddress.TryParse(destinationtext, out ip) &&
                if (coiladdressstarttext != "" && coiladdressendtext != "" && functioncodetext != "" && mindatatext >= 0 && maxdatatext >= 0)
                {
                    FireWallConfigurationApply fwca = new FireWallConfigurationApply();
                    if (StaticGlobal.editflag == false)
                    {
                        List <string> dt = (from rules in StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getFireWallRule_list()
                                            where rules.protocol == protocoltext && rules.source == sourcetext && rules.destination == destinationtext && rules.coiladdressstart == coiladdressstarttext && rules.coiladdressend == coiladdressendtext && rules.func == functioncodetext && rules.mindata == mindatatext && rules.maxdata == maxdatatext
                                            select rules.protocol).ToList <string>();
                        if (dt.Count == 0)
                        {
                            StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].addFireWallRule(new FireWallRuleDataTable()
                            {
                                protocol = protocoltext, source = sourcetext, destination = destinationtext, coiladdressstart = coiladdressstarttext, coiladdressend = coiladdressendtext, mindata = mindatatext, maxdata = maxdatatext, func = functioncodetext, log = logtext
                            });
                            this.Close();
                            fwca.MAClabel.Content = "MAC: " + StaticGlobal.firewallmac;
                            fwca.IPlabel.Content  = "IP: " + StaticGlobal.FwMACandIP[StaticGlobal.firewallmac];
                            fwca.ShowDialog();
                        }
                        else
                        {
                            UserMessageBox.Show("提示", "添加失败,已经存在此规则!");
                        }
                    }
                    else
                    {
                        //被修改的规则信息
                        string editedprotocol         = StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getFireWallRule_list()[StaticGlobal.selectedindex].protocol;
                        string editedsource           = StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getFireWallRule_list()[StaticGlobal.selectedindex].source;
                        string editeddestination      = StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getFireWallRule_list()[StaticGlobal.selectedindex].destination;
                        string editedcoiladdressstart = StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getFireWallRule_list()[StaticGlobal.selectedindex].coiladdressstart;
                        string editedcoiladdressend   = StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getFireWallRule_list()[StaticGlobal.selectedindex].coiladdressend;
                        int    editedmindata          = StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getFireWallRule_list()[StaticGlobal.selectedindex].mindata;
                        int    editedmaxdata          = StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getFireWallRule_list()[StaticGlobal.selectedindex].maxdata;
                        string editedfunctioncode     = StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getFireWallRule_list()[StaticGlobal.selectedindex].func;
                        bool   editedlog = StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getFireWallRule_list()[StaticGlobal.selectedindex].log;
                        StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getFireWallRule_list()[StaticGlobal.selectedindex] = new FireWallRuleDataTable()
                        {
                            protocol = ""
                        };
                        List <string> dt = (from rules in StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getFireWallRule_list()
                                            where rules.protocol == protocoltext && rules.source == sourcetext && rules.destination == destinationtext && rules.coiladdressstart == coiladdressstarttext && rules.coiladdressend == coiladdressendtext && rules.func == functioncodetext && rules.mindata == mindatatext && rules.maxdata == maxdatatext
                                            select rules.protocol).ToList <string>();
                        if (dt.Count == 0)
                        {
                            StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getFireWallRule_list()[StaticGlobal.selectedindex] = new FireWallRuleDataTable()
                            {
                                protocol = protocoltext, source = sourcetext, destination = destinationtext, coiladdressstart = coiladdressstarttext, coiladdressend = coiladdressendtext, mindata = mindatatext, maxdata = maxdatatext, func = functioncodetext, log = logtext
                            };
                            this.Close();
                            fwca.MAClabel.Content = "MAC: " + StaticGlobal.firewallmac;
                            fwca.IPlabel.Content  = "IP: " + StaticGlobal.FwMACandIP[StaticGlobal.firewallmac];
                            fwca.ShowDialog();
                        }
                        else
                        {
                            StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getFireWallRule_list()[StaticGlobal.selectedindex] = new FireWallRuleDataTable()
                            {
                                protocol = editedprotocol, source = editedsource, destination = editeddestination, coiladdressstart = editedcoiladdressstart, coiladdressend = editedcoiladdressend, mindata = editedmindata, maxdata = editedmaxdata, func = editedfunctioncode, log = editedlog
                            };
                            UserMessageBox.Show("提示", "编辑失败,已经存在此规则!");
                        }
                    }
                }
                else
                {
                    UserMessageBox.Show("提示", "请输入正确的规则!");
                }
            }
            else
            {
                if (IPAddress.TryParse(sourcetext, out ip) && IPAddress.TryParse(destinationtext, out ip))
                {
                    FireWallConfigurationApply fwca = new FireWallConfigurationApply();
                    if (StaticGlobal.editflag == false)
                    {
                        List <string> dt = (from rules in StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getFireWallRule_list()
                                            where rules.protocol == protocoltext && rules.source == sourcetext && rules.destination == destinationtext
                                            select rules.protocol).ToList <string>();
                        if (dt.Count == 0)
                        {
                            StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].addFireWallRule(new FireWallRuleDataTable()
                            {
                                protocol = protocoltext, source = sourcetext, destination = destinationtext, coiladdressstart = coiladdressstarttext, coiladdressend = coiladdressendtext, func = functioncodetext, log = logtext
                            });
                            this.Close();
                            fwca.MAClabel.Content = "MAC: " + StaticGlobal.firewallmac;
                            fwca.IPlabel.Content  = "IP: " + StaticGlobal.FwMACandIP[StaticGlobal.firewallmac];
                            fwca.ShowDialog();
                        }
                        else
                        {
                            UserMessageBox.Show("提示", "添加失败,已经存在此规则!");
                        }
                    }
                    else
                    {
                        //被修改的规则信息
                        string editedprotocol         = StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getFireWallRule_list()[StaticGlobal.selectedindex].protocol;
                        string editedsource           = StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getFireWallRule_list()[StaticGlobal.selectedindex].source;
                        string editeddestination      = StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getFireWallRule_list()[StaticGlobal.selectedindex].destination;
                        string editedcoiladdressstart = StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getFireWallRule_list()[StaticGlobal.selectedindex].coiladdressstart;
                        string editedcoiladdressend   = StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getFireWallRule_list()[StaticGlobal.selectedindex].coiladdressend;
                        int    editedmindata          = StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getFireWallRule_list()[StaticGlobal.selectedindex].mindata;
                        int    editedmaxdata          = StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getFireWallRule_list()[StaticGlobal.selectedindex].maxdata;
                        string editedfunctioncode     = StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getFireWallRule_list()[StaticGlobal.selectedindex].func;
                        bool   editedlog = StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getFireWallRule_list()[StaticGlobal.selectedindex].log;
                        StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getFireWallRule_list()[StaticGlobal.selectedindex] = new FireWallRuleDataTable()
                        {
                            protocol = ""
                        };
                        List <string> dt = (from rules in StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getFireWallRule_list()
                                            where rules.protocol == protocoltext && rules.source == sourcetext && rules.destination == destinationtext
                                            select rules.protocol).ToList <string>();
                        if (dt.Count == 0)
                        {
                            StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getFireWallRule_list()[StaticGlobal.selectedindex] = new FireWallRuleDataTable()
                            {
                                protocol = protocoltext, source = sourcetext, destination = destinationtext, coiladdressstart = coiladdressstarttext, coiladdressend = coiladdressendtext, func = functioncodetext, log = logtext
                            };
                            this.Close();
                            fwca.MAClabel.Content = "MAC: " + StaticGlobal.firewallmac;
                            fwca.IPlabel.Content  = "IP: " + StaticGlobal.FwMACandIP[StaticGlobal.firewallmac];
                            fwca.ShowDialog();
                        }
                        else
                        {
                            StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getFireWallRule_list()[StaticGlobal.selectedindex] = new FireWallRuleDataTable()
                            {
                                protocol = editedprotocol, source = editedsource, destination = editeddestination, coiladdressstart = editedcoiladdressstart, coiladdressend = editedcoiladdressend, func = editedfunctioncode, log = editedlog
                            };
                            UserMessageBox.Show("提示", "编辑失败,已经存在此规则!");
                        }
                    }
                }
                else
                {
                    UserMessageBox.Show("提示", "请输入正确的规则!");
                }
            }
        }