Example #1
0
        /// <summary>
        /// Parses out the arguments of a UDPPort rule
        /// 
        /// We accept single or multiple ports and port ranges
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        private static UDPPortRule GenUDPPORT(PacketStatus ps, string args, Direction dir, bool log, bool notify)
        {
            // first tokenize the args
            List<string> tmp = new List<string>(args.Split(' '));
            UDPPortRule rule = new UDPPortRule();
            rule.port_ranges = new List<PortRange>();
            try
            {
                // iterate through the given arguments
                foreach (string s in tmp)
                {
                    string loc = s;
                    // parse the port range
                    if (loc.Contains("-"))
                    {
                        // parse the start/end ports out of the arguments
                        PortRange p = new PortRange();
                        string[] split = loc.Split('-');
                        p.start = Convert.ToInt32(split[0]);
                        p.end = Convert.ToInt32(split[1]);

                        // instead of an error message, we can just swap them
                        if (p.start > p.end)
                        {
                            int temp = p.start;
                            p.start = p.end;
                            p.end = temp;
                        }

                        // add it to the rule port ranges list
                        rule.port_ranges.Add(p);
                    }
                    // else it's just a port, add it as usual
                    else
                    {
                        rule.port.Add(Convert.ToInt32(s));
                    }
                }

                // set the other rule stuff
                rule.ps = ps;
                rule.direction = dir;
                rule.log = log;
                rule.notify = notify;
            }
            catch (Exception e)
            {
                // probably a parsing error; log it and throw an 
                // exception so the rule isn't touched
                //LogCenter.WriteErrorLog(e);
                throw new Exception();
            }
            return rule;
        }
Example #2
0
        /// <summary>
        /// Parses out the arguments of a UDPPort rule
        ///
        /// We accept single or multiple ports and port ranges
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        private static UDPPortRule GenUDPPORT(PacketStatus ps, string args, Direction dir, bool log, bool notify)
        {
            // first tokenize the args
            List <string> tmp  = new List <string>(args.Split(' '));
            UDPPortRule   rule = new UDPPortRule();

            try
            {
                // iterate through the given arguments
                foreach (string s in tmp)
                {
                    string loc = s;
                    // parse the port range
                    if (loc.Contains("-"))
                    {
                        // parse the start/end ports out of the arguments
                        PortRange p     = new PortRange();
                        string[]  split = loc.Split('-');
                        p.start = Convert.ToInt32(split[0]);
                        p.end   = Convert.ToInt32(split[1]);

                        // instead of an error message, we can just swap them
                        if (p.start > p.end)
                        {
                            int temp = p.start;
                            p.start = p.end;
                            p.end   = temp;
                        }

                        // add it to the rule port ranges list
                        rule.port_ranges.Add(p);
                    }
                    // else it's just a port, add it as usual
                    else
                    {
                        rule.port.Add(Convert.ToInt32(s));
                    }
                }

                // set the other rule stuff
                rule.ps        = ps;
                rule.direction = dir;
                rule.log       = log;
                rule.notify    = notify;
            }
            catch (Exception e)
            {
                // probably a parsing error; log it and throw an
                // exception so the rule isn't touched
                //LogCenter.WriteErrorLog(e);
                throw new Exception();
            }
            return(rule);
        }
Example #3
0
        /// <summary>
        /// Constructor for initializing the GUi when editing a rule
        /// </summary>
        /// <param name="tmp"></param>
        public AddEditRule(Rule tmp)
        {
            InitializeComponent();

            // force the combo box to load the rules
            AddEditRule_Load(this, null);

            // disallow changing the base type of the rule
            comboBox1.Enabled = false;

            // set the rule type and GUI options
            if (tmp is AllRule)
            {
                AllRule t = (AllRule)tmp;
                checkBoxLog.Checked = t.log;

                // set the rule type
                comboBox1.SelectedIndex = 5;

                // set the direction
                checkBoxIn.Checked  = ((t.direction & Direction.IN) != 0) ? true : false;
                checkBoxOut.Checked = ((t.direction & Direction.OUT) != 0) ? true : false;

                // set the action box
                comboBoxAction.SelectedIndex = ((t.ps & PacketStatus.ALLOWED) != 0) ? 1 : 0;

                //notify
                notifyBox.Checked = (t.notify);
            }
            else if (tmp is IPRule)
            {
                IPRule t = (IPRule)tmp;
                checkBoxLog.Checked = t.log;

                //idx
                comboBox1.SelectedIndex = 6;

                //direction
                checkBoxIn.Checked  = ((t.direction & Direction.IN) != 0) ? true : false;
                checkBoxOut.Checked = ((t.direction & Direction.OUT) != 0) ? true : false;

                //action
                comboBoxAction.SelectedIndex = ((t.ps & PacketStatus.ALLOWED) != 0) ? 1 : 0;

                //args
                textBoxArguments.Text = t.GetIPString();

                //notify
                notifyBox.Checked = (t.notify);
            }
            else if (tmp is TCPAllRule)
            {
                TCPAllRule t = (TCPAllRule)tmp;
                checkBoxLog.Checked = t.log;

                //idx
                comboBox1.SelectedIndex = 0;

                //dir
                checkBoxIn.Checked  = ((t.direction & Direction.IN) != 0) ? true : false;
                checkBoxOut.Checked = ((t.direction & Direction.OUT) != 0) ? true : false;

                //action
                comboBoxAction.SelectedIndex = ((t.ps & PacketStatus.ALLOWED) != 0) ? 1 : 0;

                //notify
                notifyBox.Checked = (t.notify);
            }
            else if (tmp is TCPIPPortRule)
            {
                TCPIPPortRule t = (TCPIPPortRule)tmp;
                checkBoxLog.Checked = t.log;

                //idx
                comboBox1.SelectedIndex = 1;

                //dir
                checkBoxIn.Checked  = ((t.direction & Direction.IN) != 0) ? true : false;
                checkBoxOut.Checked = ((t.direction & Direction.OUT) != 0) ? true : false;

                //action
                comboBoxAction.SelectedIndex = ((t.ps & PacketStatus.ALLOWED) != 0) ? 1 : 0;

                //args
                textBoxArguments.Text = String.Format("{0} {1}", t.ip, t.port);

                //notify
                notifyBox.Checked = (t.notify);
            }
            else if (tmp is TCPPortRule)
            {
                TCPPortRule t = (TCPPortRule)tmp;
                checkBoxLog.Checked = t.log;

                //idx
                comboBox1.SelectedIndex = 2;

                //dir
                checkBoxIn.Checked  = ((t.direction & Direction.IN) != 0) ? true : false;
                checkBoxOut.Checked = ((t.direction & Direction.OUT) != 0) ? true : false;

                //action
                comboBoxAction.SelectedIndex = ((t.ps & PacketStatus.ALLOWED) != 0) ? 1 : 0;

                //args
                textBoxArguments.Text = t.GetPortString();

                //notify
                notifyBox.Checked = (t.notify);
            }
            else if (tmp is UDPAllRule)
            {
                UDPAllRule t = (UDPAllRule)tmp;
                checkBoxLog.Checked = t.log;

                //idx
                comboBox1.SelectedIndex = 3;

                //dir
                checkBoxIn.Checked  = ((t.direction & Direction.IN) != 0) ? true : false;
                checkBoxOut.Checked = ((t.direction & Direction.OUT) != 0) ? true : false;

                //action
                comboBoxAction.SelectedIndex = ((t.ps & PacketStatus.ALLOWED) != 0) ? 1 : 0;

                //notify
                notifyBox.Checked = (t.notify);
            }
            else if (tmp is UDPPortRule)
            {
                UDPPortRule t = (UDPPortRule)tmp;
                checkBoxLog.Checked = t.log;

                //idx
                comboBox1.SelectedIndex = 4;

                //dir
                checkBoxIn.Checked  = ((t.direction & Direction.IN) != 0) ? true : false;
                checkBoxOut.Checked = ((t.direction & Direction.OUT) != 0) ? true : false;

                //action
                comboBoxAction.SelectedIndex = ((t.ps & PacketStatus.ALLOWED) != 0) ? 1 : 0;

                //args
                textBoxArguments.Text = t.GetPortString();

                //notify
                notifyBox.Checked = (t.notify);
            }
        }
Example #4
0
        /// <summary>
        /// Constructor for initializing the GUi when editing a rule
        /// </summary>
        /// <param name="tmp"></param>
        public AddEditRule(Rule tmp)
        {
            //English
            multistring.SetString(Language.ENGLISH, "All TCP Rule", "All TCP Rule");
            multistring.SetString(Language.ENGLISH, "TCP IP and Port Rule", "TCP IP and Port Rule");
            multistring.SetString(Language.ENGLISH, "TCP Port Rule", "TCP Port Rule");
            multistring.SetString(Language.ENGLISH, "All UDP Rule", "All UDP Rule");
            multistring.SetString(Language.ENGLISH, "UDP Port Rule", "UDP Port Rule");
            multistring.SetString(Language.ENGLISH, "All Rule", "All Rule");
            multistring.SetString(Language.ENGLISH, "IP Rule", "IP Rule");

            //Portuguese
            multistring.SetString(Language.PORTUGUESE, "All TCP Rule", "Todos Regra TCP");
            multistring.SetString(Language.PORTUGUESE, "TCP IP and Port Rule", "TCP IP e regra de porta");
            multistring.SetString(Language.PORTUGUESE, "TCP Port Rule", "Porta TCP Regra");
            multistring.SetString(Language.PORTUGUESE, "All UDP Rule", "Todos Regra UDP");
            multistring.SetString(Language.PORTUGUESE, "UDP Port Rule", "Porta UDP Regra");
            multistring.SetString(Language.PORTUGUESE, "All Rule", "Todos Regra");
            multistring.SetString(Language.PORTUGUESE, "IP Rule", "Regra IP");

            //Chinese
            multistring.SetString(Language.CHINESE, "All TCP Rule", "所有的TCP規則");
            multistring.SetString(Language.CHINESE, "TCP IP and Port Rule", "TCP IP和端口規則");
            multistring.SetString(Language.CHINESE, "TCP Port Rule", "TCP端口規則");
            multistring.SetString(Language.CHINESE, "All UDP Rule", "所有的UDP規則");
            multistring.SetString(Language.CHINESE, "UDP Port Rule", "UDP端口規則");
            multistring.SetString(Language.CHINESE, "All Rule", "所有規則");
            multistring.SetString(Language.CHINESE, "IP Rule", "IP规则");

            //German
            multistring.SetString(Language.GERMAN, "All TCP Rule", "Alle TCP Rule");
            multistring.SetString(Language.GERMAN, "TCP IP and Port Rule", "TCP IP und Port Regel");
            multistring.SetString(Language.GERMAN, "TCP Port Rule", "TCP Port Rule");
            multistring.SetString(Language.GERMAN, "All UDP Rule", "Alle UDP Regel");
            multistring.SetString(Language.GERMAN, "UDP Port Rule", "UDP Port Rule");
            multistring.SetString(Language.GERMAN, "All Rule", "Alle Rule");
            multistring.SetString(Language.GERMAN, "IP Rule", "IP Rule");

            //Russian
            Language lang = Language.RUSSIAN;

            multistring.SetString(lang, "All TCP Rule", "Все правила TCP");
            multistring.SetString(lang, "TCP IP and Port Rule", "TCP-IP и порт Правило");
            multistring.SetString(lang, "TCP Port Rule", "TCP-порт Правило");
            multistring.SetString(lang, "All UDP Rule", "Все правила UDP");
            multistring.SetString(lang, "UDP Port Rule", "UDP-порта Правило");
            multistring.SetString(lang, "All Rule", "Все правила");
            multistring.SetString(lang, "IP Rule", "IP правила");

            //Spanish
            lang = Language.SPANISH;
            multistring.SetString(lang, "All TCP Rule", "Todos los Regla TCP");
            multistring.SetString(lang, "TCP IP and Port Rule", "TCP IP y puerto de Regla");
            multistring.SetString(lang, "TCP Port Rule", "Puerto TCP Regla");
            multistring.SetString(lang, "All UDP Rule", "Todos los Regla UDP");
            multistring.SetString(lang, "UDP Port Rule", "El puerto UDP Regla");
            multistring.SetString(lang, "All Rule", "todos los Regla");
            multistring.SetString(lang, "IP Rule", "Regla IP");

            //Dutch
            lang = Language.DUTCH;
            multistring.SetString(lang, "All TCP Rule", "Alle TCP regel");
            multistring.SetString(lang, "TCP IP and Port Rule", "TCP IP en poortregel");
            multistring.SetString(lang, "TCP Port Rule", "TCP-poort regel");
            multistring.SetString(lang, "All UDP Rule", "Alle UDP-regel");
            multistring.SetString(lang, "UDP Port Rule", "UDP-poort regel");
            multistring.SetString(lang, "All Rule", "Alle regel");
            multistring.SetString(lang, "IP Rule", "IP-regel");

            //French
            lang = Language.FRENCH;
            multistring.SetString(lang, "All TCP Rule", "Toutes les règle TCP");
            multistring.SetString(lang, "TCP IP and Port Rule", "TCP IP et la règle de Port");
            multistring.SetString(lang, "TCP Port Rule", "Règle de Port TCP");
            multistring.SetString(lang, "All UDP Rule", "Toutes les règle UDP");
            multistring.SetString(lang, "UDP Port Rule", "Règle de Port UDP");
            multistring.SetString(lang, "All Rule", "Règle tous les");
            multistring.SetString(lang, "IP Rule", "Règle de la IP");

            //Hebrew
            lang = Language.HEBREW;
            multistring.SetString(lang, "All TCP Rule", "כל כלל TCP");
            multistring.SetString(lang, "TCP IP and Port Rule", "TCP IP וכלל יציאה");
            multistring.SetString(lang, "TCP Port Rule", "כלל יציאה TCP");
            multistring.SetString(lang, "All UDP Rule", "כל כלל UDP");
            multistring.SetString(lang, "UDP Port Rule", "יציאת ה-UDP כלל");
            multistring.SetString(lang, "All Rule", "כל כלל");
            multistring.SetString(lang, "IP Rule", "כלל ה-IP");

            //Italian
            lang = Language.ITALIAN;
            multistring.SetString(lang, "All TCP Rule", "Ogni regola TCP");
            multistring.SetString(lang, "TCP IP and Port Rule", "TCP IP e regola di porta");
            multistring.SetString(lang, "TCP Port Rule", "Regola di porta TCP");
            multistring.SetString(lang, "All UDP Rule", "Ogni regola UDP");
            multistring.SetString(lang, "UDP Port Rule", "Regola di porta UDP");
            multistring.SetString(lang, "All Rule", "Regola tutte le");
            multistring.SetString(lang, "IP Rule", "IP Rule");

            //Japanese
            lang = Language.JAPANESE;
            multistring.SetString(lang, "All TCP Rule", "すべての TCP ルール");
            multistring.SetString(lang, "TCP IP and Port Rule", "TCP IP とポートの規則");
            multistring.SetString(lang, "TCP Port Rule", "TCP ポートの規則");
            multistring.SetString(lang, "All UDP Rule", "すべての UDP ルール");
            multistring.SetString(lang, "UDP Port Rule", "UDP ポート ルール");
            multistring.SetString(lang, "All Rule", "すべてのルール");
            multistring.SetString(lang, "IP Rule", "IP ルール");
            InitializeComponent();

            // force the combo box to load the rules
            AddEditRule_Load(this, null);

            // disallow changing the base type of the rule
            comboBox1.Enabled = false;

            // set the rule type and GUI options
            if (tmp is AllRule)
            {
                AllRule t = (AllRule)tmp;
                checkBoxLog.Checked = t.log;

                // set the rule type
                comboBox1.SelectedIndex = 5;

                // set the direction
                checkBoxIn.Checked  = ((t.direction & Direction.IN) != 0) ? true : false;
                checkBoxOut.Checked = ((t.direction & Direction.OUT) != 0) ? true : false;

                // set the action box
                comboBoxAction.SelectedIndex = ((t.ps & PacketStatus.ALLOWED) != 0) ? 1 : 0;

                //notify
                notifyBox.Checked = (t.notify);
            }
            else if (tmp is IPRule)
            {
                IPRule t = (IPRule)tmp;
                checkBoxLog.Checked = t.log;

                //idx
                comboBox1.SelectedIndex = 6;

                //direction
                checkBoxIn.Checked  = ((t.direction & Direction.IN) != 0) ? true : false;
                checkBoxOut.Checked = ((t.direction & Direction.OUT) != 0) ? true : false;

                //action
                comboBoxAction.SelectedIndex = ((t.ps & PacketStatus.ALLOWED) != 0) ? 1 : 0;

                //args
                textBoxArguments.Text = t.GetIPString();

                //notify
                notifyBox.Checked = (t.notify);
            }
            else if (tmp is TCPAllRule)
            {
                TCPAllRule t = (TCPAllRule)tmp;
                checkBoxLog.Checked = t.log;

                //idx
                comboBox1.SelectedIndex = 0;

                //dir
                checkBoxIn.Checked  = ((t.direction & Direction.IN) != 0) ? true : false;
                checkBoxOut.Checked = ((t.direction & Direction.OUT) != 0) ? true : false;

                //action
                comboBoxAction.SelectedIndex = ((t.ps & PacketStatus.ALLOWED) != 0) ? 1 : 0;

                //notify
                notifyBox.Checked = (t.notify);
            }
            else if (tmp is TCPIPPortRule)
            {
                TCPIPPortRule t = (TCPIPPortRule)tmp;
                checkBoxLog.Checked = t.log;

                //idx
                comboBox1.SelectedIndex = 1;

                //dir
                checkBoxIn.Checked  = ((t.direction & Direction.IN) != 0) ? true : false;
                checkBoxOut.Checked = ((t.direction & Direction.OUT) != 0) ? true : false;

                //action
                comboBoxAction.SelectedIndex = ((t.ps & PacketStatus.ALLOWED) != 0) ? 1 : 0;

                //args
                textBoxArguments.Text = String.Format("{0} {1}", t.ip, t.port);

                //notify
                notifyBox.Checked = (t.notify);
            }
            else if (tmp is TCPPortRule)
            {
                TCPPortRule t = (TCPPortRule)tmp;
                checkBoxLog.Checked = t.log;

                //idx
                comboBox1.SelectedIndex = 2;

                //dir
                checkBoxIn.Checked  = ((t.direction & Direction.IN) != 0) ? true : false;
                checkBoxOut.Checked = ((t.direction & Direction.OUT) != 0) ? true : false;

                //action
                comboBoxAction.SelectedIndex = ((t.ps & PacketStatus.ALLOWED) != 0) ? 1 : 0;

                //args
                textBoxArguments.Text = t.GetPortString();

                //notify
                notifyBox.Checked = (t.notify);
            }
            else if (tmp is UDPAllRule)
            {
                UDPAllRule t = (UDPAllRule)tmp;
                checkBoxLog.Checked = t.log;

                //idx
                comboBox1.SelectedIndex = 3;

                //dir
                checkBoxIn.Checked  = ((t.direction & Direction.IN) != 0) ? true : false;
                checkBoxOut.Checked = ((t.direction & Direction.OUT) != 0) ? true : false;

                //action
                comboBoxAction.SelectedIndex = ((t.ps & PacketStatus.ALLOWED) != 0) ? 1 : 0;

                //notify
                notifyBox.Checked = (t.notify);
            }
            else if (tmp is UDPPortRule)
            {
                UDPPortRule t = (UDPPortRule)tmp;
                checkBoxLog.Checked = t.log;

                //idx
                comboBox1.SelectedIndex = 4;

                //dir
                checkBoxIn.Checked  = ((t.direction & Direction.IN) != 0) ? true : false;
                checkBoxOut.Checked = ((t.direction & Direction.OUT) != 0) ? true : false;

                //action
                comboBoxAction.SelectedIndex = ((t.ps & PacketStatus.ALLOWED) != 0) ? 1 : 0;

                //args
                textBoxArguments.Text = t.GetPortString();

                //notify
                notifyBox.Checked = (t.notify);
            }
        }