Beispiel #1
0
        private void STDdeleteclick(object sender, MouseButtonEventArgs e)
        {
            ISTDRulesManage fw     = new STDRulesManage();
            string          dev_ip = (from devices in StaticGlobal.fwdev_list
                                      where devices.getDev_MAC() == StaticGlobal.firewallmac
                                      select devices).ToList <FWDeviceForm>()[0].getProtecDevIP_list()[0];
            string protocol = (STDdataGrid.SelectedItem as STDRuleDataTable).protocol;
            string srcIP    = (STDdataGrid.SelectedItem as STDRuleDataTable).srcIP;
            string dstIP    = (STDdataGrid.SelectedItem as STDRuleDataTable).dstIP;
            string sport    = (STDdataGrid.SelectedItem as STDRuleDataTable).sport;
            string dport    = (STDdataGrid.SelectedItem as STDRuleDataTable).dport;
            bool   log      = (STDdataGrid.SelectedItem as STDRuleDataTable).log;

            if (fw.DelSTDRules(dev_ip, log, protocol, srcIP, dstIP, sport, dport))
            {
                StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getSTDRule_list().Remove((STDdataGrid.SelectedItem as STDRuleDataTable));
                UserMessageBox.Show("提示", "规则删除成功!");
            }
            else
            {
                UserMessageBox.Show("提示", "规则删除失败,请检查设备连接!");
            }
        }
Beispiel #2
0
        public void STDApplying()
        {
            Dispatcher.Invoke(new Action(() =>
            {
                NewSTDRulebutton.IsEnabled = false;
                STDApplybutton.IsEnabled   = false;
                STDdataGrid.IsEnabled      = false;
                Closebutton.IsEnabled      = false;
            }));
            //找出需要删除的规则
            var deleteRules = StaticGlobal.STDoldrules.Where(deleteRule => !StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getSTDRule_list().Contains(deleteRule)).ToList();

            //找出需要增加的规则
            var    addRules     = StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getSTDRule_list().Where(addRule => !StaticGlobal.STDoldrules.Contains(addRule)).ToList();
            bool   STDApplyFlag = true;
            string dev_ip       = (from devices in StaticGlobal.fwdev_list
                                   where devices.getDev_MAC() == StaticGlobal.firewallmac
                                   select devices).ToList <FWDeviceForm>()[0].getProtecDevIP_list()[0];
            ISTDRulesManage cncrule = new STDRulesManage();

            //添加规则
            for (int i = 0; i < addRules.Count(); i++)
            {
                string protocol = addRules[i].protocol;
                string srcIP    = addRules[i].srcIP;
                string dstIP    = addRules[i].dstIP;
                string sport    = addRules[i].sport;
                string dport    = addRules[i].dport;
                bool   log      = addRules[i].log;
                if (cncrule.AddSTDRules(dev_ip, log, protocol, srcIP, dstIP, sport, dport))
                {
                    STDApplyFlag = true;
                }
                else
                {
                    STDApplyFlag = false;
                }
            }
            //删除规则
            for (int j = 0; j < deleteRules.Count(); j++)
            {
                string protocol = deleteRules[j].protocol;
                string srcIP    = deleteRules[j].srcIP;
                string dstIP    = deleteRules[j].dstIP;
                string sport    = deleteRules[j].sport;
                string dport    = deleteRules[j].dport;
                bool   log      = deleteRules[j].log;
                if (cncrule.DelSTDRules(dev_ip, log, protocol, srcIP, dstIP, sport, dport))
                {
                    STDApplyFlag = true;
                }
                else
                {
                    STDApplyFlag = false;
                }
            }
            Dispatcher.Invoke(new Action(() =>
            {
                if (STDApplyFlag)
                {
                    UserMessageBox.Show("提示", "所有规则已成功应用!");
                }
                else
                {
                    UserMessageBox.Show("提示", "部分规则未成功应用,请检查设备之间的连接!");
                }
                this.Close();
            }
                                         ));
            STDApplyThread.Abort();
        }