private void buttonMoveUp_Click(object sender, EventArgs e) { try { int index = listBox1.SelectedIndex; if (index != 0) { MacFilterModule.MacRule rule = (MacFilterModule.MacRule)listBox1.Items[index]; listBox1.Items.RemoveAt(index); index--; listBox1.Items.Insert(index, rule); listBox1.SelectedIndex = index; List <MacFilterModule.MacRule> r = new List <MacFilterModule.MacRule>(); foreach (object ru in listBox1.Items) { r.Add((MacFilterModule.MacRule)ru); } mf.InstanceGetRuleUpdates(r); } } catch (Exception ex) { LogCenter.Instance.LogException(ex); } }
/// <summary> /// Edits the selected rule /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void editButton_Click(object sender, EventArgs e) { if (listBox1.SelectedItem == null) { return; } try { // grab the current rule MacFilterModule.MacRule new_rule = (MacFilterModule.MacRule)listBox1.Items[listBox1.SelectedIndex]; // grab its idx int idx = listBox1.SelectedIndex; AddEditMacRule aer = new AddEditMacRule(new_rule); if (aer.ShowDialog() == DialogResult.OK) { // replace rule listBox1.Items[idx] = aer.newRule; List <MacFilterModule.MacRule> r = new List <MacFilterModule.MacRule>(); foreach (object rule in listBox1.Items) { r.Add((MacFilterModule.MacRule)rule); } mf.InstanceGetRuleUpdates(r); aer.Dispose(); } } catch (Exception exception) { LogCenter.Instance.LogException(exception); } }
private void button1_Click(object sender, EventArgs e) { try { MacFilterModule.Direction dir; if (checkBoxIn.Checked && checkBoxOut.Checked) dir = MacFilterModule.Direction.IN | MacFilterModule.Direction.OUT; else if (checkBoxOut.Checked) { dir = MacFilterModule.Direction.OUT; } else dir = MacFilterModule.Direction.IN; MacFilterModule.PacketStatus ps; if (comboBoxAction.Text == "Block") ps = MacFilterModule.PacketStatus.BLOCKED; else ps = MacFilterModule.PacketStatus.ALLOWED; if (String.IsNullOrEmpty(textBoxArguments.Text)) { newRule = new MacFilterModule.MacRule(ps, dir, checkBoxLog.Checked, notifyBox.Checked); } else { string macString = textBoxArguments.Text.ToUpper().Replace("-", "").Replace(":", "").Replace(";", ""); newRule = new MacFilterModule.MacRule(ps, System.Net.NetworkInformation.PhysicalAddress.Parse(macString), dir, checkBoxLog.Checked, notifyBox.Checked); } DialogResult = System.Windows.Forms.DialogResult.OK; this.Close(); } catch { } }
private void button1_Click(object sender, EventArgs e) { try { MacFilterModule.Direction dir; if (checkBoxIn.Checked && checkBoxOut.Checked) { dir = MacFilterModule.Direction.IN | MacFilterModule.Direction.OUT; } else if (checkBoxOut.Checked) { dir = MacFilterModule.Direction.OUT; } else { dir = MacFilterModule.Direction.IN; } MacFilterModule.PacketStatus ps; if (comboBoxAction.Text == "Block") { ps = MacFilterModule.PacketStatus.BLOCKED; } else { ps = MacFilterModule.PacketStatus.ALLOWED; } if (String.IsNullOrEmpty(textBoxArguments.Text)) { newRule = new MacFilterModule.MacRule(ps, dir, checkBoxLog.Checked, notifyBox.Checked); } else { string macString = textBoxArguments.Text.ToUpper().Replace("-", "").Replace(":", "").Replace(";", ""); newRule = new MacFilterModule.MacRule(ps, System.Net.NetworkInformation.PhysicalAddress.Parse(macString), dir, checkBoxLog.Checked, notifyBox.Checked); } DialogResult = System.Windows.Forms.DialogResult.OK; this.Close(); } catch { } }
private void buttonMoveDown_Click(object sender, EventArgs e) { try { int index = listBox1.SelectedIndex; if (index != listBox1.Items.Count - 1) { MacFilterModule.MacRule rule = (MacFilterModule.MacRule)listBox1.Items[index]; listBox1.Items.RemoveAt(index); index++; listBox1.Items.Insert(index, rule); listBox1.SelectedIndex = index; List <MacFilterModule.MacRule> r = new List <MacFilterModule.MacRule>(); foreach (object ru in listBox1.Items) { r.Add((MacFilterModule.MacRule)ru); } mf.InstanceGetRuleUpdates(r); } } catch { } }
// overloaded constructor for editing an existing rule public AddEditMacRule(MacFilterModule.MacRule RULE) { InitializeComponent(); // set the in/out boxes if ((RULE.direction & MacFilterModule.Direction.IN) != 0) { checkBoxIn.Checked = true; } if ((RULE.direction & MacFilterModule.Direction.OUT) != 0) { checkBoxOut.Checked = true; } // set the MAC if (!String.IsNullOrEmpty(RULE.mac.ToString())) { textBoxArguments.Text = new PhysicalAddress(RULE.mac).ToString(); } // set logging checkBoxLog.Checked = RULE.log; // set the status if ((RULE.ps & MacFilterModule.PacketStatus.ALLOWED) != 0) { comboBoxAction.SelectedIndex = 1; } else { comboBoxAction.SelectedIndex = 0; } //notify notifyBox.Checked = RULE.notify; }