Firewall rule editor working
This commit is contained in:
parent
6f240bc311
commit
5b62aa59ee
31
EduNetworkBuilder/FirewallEditor.Designer.cs
generated
31
EduNetworkBuilder/FirewallEditor.Designer.cs
generated
@ -32,6 +32,7 @@
|
||||
this.btnNew = new System.Windows.Forms.Button();
|
||||
this.btnDone = new System.Windows.Forms.Button();
|
||||
this.btnDel = new System.Windows.Forms.Button();
|
||||
this.btnEdit = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// lbRules
|
||||
@ -43,15 +44,17 @@
|
||||
this.lbRules.ItemHeight = 16;
|
||||
this.lbRules.Location = new System.Drawing.Point(12, 23);
|
||||
this.lbRules.Name = "lbRules";
|
||||
this.lbRules.Size = new System.Drawing.Size(276, 228);
|
||||
this.lbRules.Size = new System.Drawing.Size(335, 212);
|
||||
this.lbRules.TabIndex = 0;
|
||||
this.lbRules.DoubleClick += new System.EventHandler(this.lbRules_DoubleClick);
|
||||
this.lbRules.MouseDown += new System.Windows.Forms.MouseEventHandler(this.lbRules_MouseDown);
|
||||
//
|
||||
// btnNew
|
||||
//
|
||||
this.btnNew.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.btnNew.Location = new System.Drawing.Point(12, 256);
|
||||
this.btnNew.Location = new System.Drawing.Point(12, 249);
|
||||
this.btnNew.Name = "btnNew";
|
||||
this.btnNew.Size = new System.Drawing.Size(75, 23);
|
||||
this.btnNew.Size = new System.Drawing.Size(58, 23);
|
||||
this.btnNew.TabIndex = 1;
|
||||
this.btnNew.Text = "New";
|
||||
this.btnNew.UseVisualStyleBackColor = true;
|
||||
@ -60,7 +63,7 @@
|
||||
// btnDone
|
||||
//
|
||||
this.btnDone.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.btnDone.Location = new System.Drawing.Point(213, 256);
|
||||
this.btnDone.Location = new System.Drawing.Point(272, 249);
|
||||
this.btnDone.Name = "btnDone";
|
||||
this.btnDone.Size = new System.Drawing.Size(75, 23);
|
||||
this.btnDone.TabIndex = 2;
|
||||
@ -71,24 +74,37 @@
|
||||
// btnDel
|
||||
//
|
||||
this.btnDel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.btnDel.Location = new System.Drawing.Point(93, 257);
|
||||
this.btnDel.Location = new System.Drawing.Point(76, 249);
|
||||
this.btnDel.Name = "btnDel";
|
||||
this.btnDel.Size = new System.Drawing.Size(75, 23);
|
||||
this.btnDel.Size = new System.Drawing.Size(57, 23);
|
||||
this.btnDel.TabIndex = 3;
|
||||
this.btnDel.Text = "Delete";
|
||||
this.btnDel.UseVisualStyleBackColor = true;
|
||||
this.btnDel.Click += new System.EventHandler(this.btnDel_Click);
|
||||
//
|
||||
// btnEdit
|
||||
//
|
||||
this.btnEdit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.btnEdit.Location = new System.Drawing.Point(139, 249);
|
||||
this.btnEdit.Name = "btnEdit";
|
||||
this.btnEdit.Size = new System.Drawing.Size(55, 23);
|
||||
this.btnEdit.TabIndex = 4;
|
||||
this.btnEdit.Text = "Edit";
|
||||
this.btnEdit.UseVisualStyleBackColor = true;
|
||||
this.btnEdit.Click += new System.EventHandler(this.btnEdit_Click);
|
||||
//
|
||||
// FirewallEditor
|
||||
//
|
||||
this.AcceptButton = this.btnDone;
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(300, 285);
|
||||
this.ClientSize = new System.Drawing.Size(359, 277);
|
||||
this.Controls.Add(this.btnEdit);
|
||||
this.Controls.Add(this.btnDel);
|
||||
this.Controls.Add(this.btnDone);
|
||||
this.Controls.Add(this.btnNew);
|
||||
this.Controls.Add(this.lbRules);
|
||||
this.MinimumSize = new System.Drawing.Size(309, 250);
|
||||
this.Name = "FirewallEditor";
|
||||
this.Text = "FirewallEditor";
|
||||
this.ResumeLayout(false);
|
||||
@ -101,5 +117,6 @@
|
||||
private System.Windows.Forms.Button btnNew;
|
||||
private System.Windows.Forms.Button btnDone;
|
||||
private System.Windows.Forms.Button btnDel;
|
||||
private System.Windows.Forms.Button btnEdit;
|
||||
}
|
||||
}
|
@ -25,10 +25,16 @@ namespace EduNetworkBuilder
|
||||
|
||||
void UpdateForm()
|
||||
{
|
||||
if (lbRules.SelectedIndex > 0)
|
||||
if (lbRules.SelectedIndex >= 0)
|
||||
{
|
||||
btnDel.Visible = true;
|
||||
btnEdit.Visible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
btnDel.Visible = false;
|
||||
btnEdit.Visible = false;
|
||||
}
|
||||
int selected = lbRules.SelectedIndex;
|
||||
lbRules.Items.Clear();
|
||||
foreach (FirewallRule FW in FirewallDevice.FirewallRules)
|
||||
@ -60,11 +66,75 @@ namespace EduNetworkBuilder
|
||||
private void btnDel_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
if (lbRules.SelectedIndex >= 0)
|
||||
{
|
||||
if (FirewallDevice.FirewallRules.Count > lbRules.SelectedIndex)
|
||||
{
|
||||
int old = lbRules.SelectedIndex;
|
||||
FirewallDevice.FirewallRules.RemoveAt(lbRules.SelectedIndex);
|
||||
old--;
|
||||
if (old > -1)
|
||||
lbRules.SelectedIndex = old;
|
||||
UpdateForm();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void btnDone_Click(object sender, EventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
private void btnEdit_Click(object sender, EventArgs e)
|
||||
{
|
||||
EditCurrent();
|
||||
}
|
||||
|
||||
private void EditCurrent()
|
||||
{
|
||||
if (lbRules.SelectedIndex >= 0)
|
||||
{
|
||||
if (FirewallDevice.FirewallRules.Count > lbRules.SelectedIndex)
|
||||
{
|
||||
FirewallRule FW = FirewallDevice.FirewallRules[lbRules.SelectedIndex];
|
||||
NetTestEditor NTE = new NetTestEditor(FW, FirewallDevice);
|
||||
NTE.ShowDialog();
|
||||
UpdateForm();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void lbRules_DoubleClick(object sender, EventArgs e)
|
||||
{
|
||||
EditCurrent();
|
||||
}
|
||||
|
||||
private void lbRules_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
//Do right-click stuff here
|
||||
if(e.Button == MouseButtons.Right)
|
||||
{
|
||||
if (lbRules.ContextMenuStrip == null)
|
||||
{
|
||||
lbRules.ContextMenuStrip = new ContextMenuStrip();
|
||||
}
|
||||
lbRules.ContextMenuStrip.Items.Clear();
|
||||
//we can open a right-click menu
|
||||
int index = 0;
|
||||
lbRules.ContextMenuStrip.Items.Add(NB.Translate("_Add"));
|
||||
lbRules.ContextMenuStrip.Items[index++].Click += btnNew_Click;
|
||||
if (lbRules.SelectedIndex >= 0)
|
||||
{
|
||||
lbRules.ContextMenuStrip.Items.Add(NB.Translate("_Edit"));
|
||||
lbRules.ContextMenuStrip.Items[index++].Click += btnEdit_Click;
|
||||
|
||||
lbRules.ContextMenuStrip.Items.Add(NB.Translate("_Delete"));
|
||||
lbRules.ContextMenuStrip.Items[index++].Click += btnDel_Click;
|
||||
}
|
||||
|
||||
lbRules.ContextMenuStrip.Visible = true;
|
||||
lbRules.ContextMenuStrip.Show(Cursor.Position);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -150,9 +150,9 @@ namespace EduNetworkBuilder
|
||||
cbSource.SelectedIndex = 0; //select the first item
|
||||
}
|
||||
|
||||
if (cbDest.Items.Contains(RuleToEdit.Source))
|
||||
if (cbDest.Items.Contains(RuleToEdit.Destination))
|
||||
{
|
||||
cbDest.SelectedItem = RuleToEdit.Source;
|
||||
cbDest.SelectedItem = RuleToEdit.Destination;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -447,10 +447,10 @@ namespace EduNetworkBuilder
|
||||
{
|
||||
if (EditingFirewallRule)
|
||||
{
|
||||
if (validate_choices())
|
||||
if (validate_choices() && !processing)
|
||||
{
|
||||
RuleToEdit.Source = cbSource.SelectedItem.ToString();
|
||||
if (!processing) UpdateForm();
|
||||
UpdateForm();
|
||||
}
|
||||
else
|
||||
if (!processing)
|
||||
@ -474,8 +474,11 @@ namespace EduNetworkBuilder
|
||||
{
|
||||
if (validate_choices())
|
||||
{
|
||||
RuleToEdit.Destination = cbDest.SelectedItem.ToString();
|
||||
if (!processing) UpdateForm();
|
||||
if (!processing)
|
||||
{
|
||||
RuleToEdit.Destination = cbDest.SelectedItem.ToString();
|
||||
UpdateForm();
|
||||
}
|
||||
}
|
||||
else
|
||||
if (!processing)
|
||||
|
Loading…
Reference in New Issue
Block a user