diff --git a/App.config b/App.config index 4486581..f4d6a3c 100644 --- a/App.config +++ b/App.config @@ -13,6 +13,9 @@ 30 + + True + diff --git a/GUI/NewFireWall.Designer.cs b/GUI/NewFireWall.Designer.cs new file mode 100644 index 0000000..a8ec11c --- /dev/null +++ b/GUI/NewFireWall.Designer.cs @@ -0,0 +1,326 @@ + +namespace eSwitch.GUI +{ + partial class NewFireWall + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.OperationComboBox = new System.Windows.Forms.ComboBox(); + this.SourceMacTextBox = new System.Windows.Forms.TextBox(); + this.DirectionComboBox = new System.Windows.Forms.ComboBox(); + this.SourceIpTextBox = new System.Windows.Forms.TextBox(); + this.DestinationMacTextBox = new System.Windows.Forms.TextBox(); + this.DestinationIpTextBox = new System.Windows.Forms.TextBox(); + this.SourcePortTextBox = new System.Windows.Forms.TextBox(); + this.DestinationPortTextBox = new System.Windows.Forms.TextBox(); + this.Operation = new System.Windows.Forms.Label(); + this.Protocol = new System.Windows.Forms.Label(); + this.Direction = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.label6 = new System.Windows.Forms.Label(); + this.label7 = new System.Windows.Forms.Label(); + this.label8 = new System.Windows.Forms.Label(); + this.label9 = new System.Windows.Forms.Label(); + this.AddNewFireWallButton = new System.Windows.Forms.Button(); + this.ProtocolTextBox = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // OperationComboBox + // + this.OperationComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.OperationComboBox.FormattingEnabled = true; + this.OperationComboBox.Items.AddRange(new object[] { + "Deny", + "Permit"}); + this.OperationComboBox.Location = new System.Drawing.Point(105, 49); + this.OperationComboBox.Name = "OperationComboBox"; + this.OperationComboBox.Size = new System.Drawing.Size(425, 33); + this.OperationComboBox.TabIndex = 0; + // + // SourceMacTextBox + // + this.SourceMacTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.SourceMacTextBox.Location = new System.Drawing.Point(105, 365); + this.SourceMacTextBox.Name = "SourceMacTextBox"; + this.SourceMacTextBox.Size = new System.Drawing.Size(425, 31); + this.SourceMacTextBox.TabIndex = 3; + // + // DirectionComboBox + // + this.DirectionComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.DirectionComboBox.FormattingEnabled = true; + this.DirectionComboBox.Items.AddRange(new object[] { + "Inside", + "Outside"}); + this.DirectionComboBox.Location = new System.Drawing.Point(105, 163); + this.DirectionComboBox.Name = "DirectionComboBox"; + this.DirectionComboBox.Size = new System.Drawing.Size(425, 33); + this.DirectionComboBox.TabIndex = 10; + // + // SourceIpTextBox + // + this.SourceIpTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.SourceIpTextBox.Location = new System.Drawing.Point(105, 454); + this.SourceIpTextBox.Name = "SourceIpTextBox"; + this.SourceIpTextBox.Size = new System.Drawing.Size(425, 31); + this.SourceIpTextBox.TabIndex = 11; + // + // DestinationMacTextBox + // + this.DestinationMacTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.DestinationMacTextBox.Location = new System.Drawing.Point(105, 559); + this.DestinationMacTextBox.Name = "DestinationMacTextBox"; + this.DestinationMacTextBox.Size = new System.Drawing.Size(425, 31); + this.DestinationMacTextBox.TabIndex = 12; + // + // DestinationIpTextBox + // + this.DestinationIpTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.DestinationIpTextBox.Location = new System.Drawing.Point(105, 653); + this.DestinationIpTextBox.Name = "DestinationIpTextBox"; + this.DestinationIpTextBox.Size = new System.Drawing.Size(425, 31); + this.DestinationIpTextBox.TabIndex = 13; + // + // SourcePortTextBox + // + this.SourcePortTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.SourcePortTextBox.Location = new System.Drawing.Point(105, 757); + this.SourcePortTextBox.Name = "SourcePortTextBox"; + this.SourcePortTextBox.Size = new System.Drawing.Size(425, 31); + this.SourcePortTextBox.TabIndex = 14; + // + // DestinationPortTextBox + // + this.DestinationPortTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.DestinationPortTextBox.Location = new System.Drawing.Point(105, 865); + this.DestinationPortTextBox.Name = "DestinationPortTextBox"; + this.DestinationPortTextBox.Size = new System.Drawing.Size(425, 31); + this.DestinationPortTextBox.TabIndex = 15; + this.DestinationPortTextBox.Tag = ""; + // + // Operation + // + this.Operation.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.Operation.AutoSize = true; + this.Operation.Location = new System.Drawing.Point(100, 21); + this.Operation.Name = "Operation"; + this.Operation.Size = new System.Drawing.Size(106, 25); + this.Operation.TabIndex = 16; + this.Operation.Text = "Operation"; + // + // Protocol + // + this.Protocol.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.Protocol.AutoSize = true; + this.Protocol.Location = new System.Drawing.Point(100, 241); + this.Protocol.Name = "Protocol"; + this.Protocol.Size = new System.Drawing.Size(91, 25); + this.Protocol.TabIndex = 17; + this.Protocol.Text = "Protocol"; + // + // Direction + // + this.Direction.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.Direction.AutoSize = true; + this.Direction.Location = new System.Drawing.Point(100, 135); + this.Direction.Name = "Direction"; + this.Direction.Size = new System.Drawing.Size(97, 25); + this.Direction.TabIndex = 18; + this.Direction.Text = "Direction"; + // + // label4 + // + this.label4.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(100, 337); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(133, 25); + this.label4.TabIndex = 19; + this.label4.Text = "Source MAC"; + // + // label5 + // + this.label5.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(100, 426); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(105, 25); + this.label5.TabIndex = 20; + this.label5.Text = "Source IP"; + // + // label6 + // + this.label6.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(100, 625); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(145, 25); + this.label6.TabIndex = 21; + this.label6.Text = "Destination IP"; + // + // label7 + // + this.label7.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.label7.AutoSize = true; + this.label7.Location = new System.Drawing.Point(100, 729); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(125, 25); + this.label7.TabIndex = 22; + this.label7.Text = "Source Port"; + // + // label8 + // + this.label8.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.label8.AutoSize = true; + this.label8.Location = new System.Drawing.Point(100, 837); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(165, 25); + this.label8.TabIndex = 23; + this.label8.Text = "Destination Port"; + // + // label9 + // + this.label9.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.label9.AutoSize = true; + this.label9.Location = new System.Drawing.Point(100, 531); + this.label9.Name = "label9"; + this.label9.Size = new System.Drawing.Size(173, 25); + this.label9.TabIndex = 24; + this.label9.Text = "Destination MAC"; + // + // AddNewFireWallButton + // + this.AddNewFireWallButton.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.AddNewFireWallButton.Location = new System.Drawing.Point(679, 326); + this.AddNewFireWallButton.Name = "AddNewFireWallButton"; + this.AddNewFireWallButton.Size = new System.Drawing.Size(174, 264); + this.AddNewFireWallButton.TabIndex = 25; + this.AddNewFireWallButton.Text = "Add"; + this.AddNewFireWallButton.UseVisualStyleBackColor = true; + this.AddNewFireWallButton.Click += new System.EventHandler(this.AddNewFireWallButton_Click); + // + // ProtocolTextBox + // + this.ProtocolTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.ProtocolTextBox.Location = new System.Drawing.Point(105, 269); + this.ProtocolTextBox.Name = "ProtocolTextBox"; + this.ProtocolTextBox.Size = new System.Drawing.Size(425, 31); + this.ProtocolTextBox.TabIndex = 26; + // + // NewFireWall + // + this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(932, 1143); + this.Controls.Add(this.ProtocolTextBox); + this.Controls.Add(this.AddNewFireWallButton); + this.Controls.Add(this.label9); + this.Controls.Add(this.label8); + this.Controls.Add(this.label7); + this.Controls.Add(this.label6); + this.Controls.Add(this.label5); + this.Controls.Add(this.label4); + this.Controls.Add(this.Direction); + this.Controls.Add(this.Protocol); + this.Controls.Add(this.Operation); + this.Controls.Add(this.DestinationPortTextBox); + this.Controls.Add(this.SourcePortTextBox); + this.Controls.Add(this.DestinationIpTextBox); + this.Controls.Add(this.DestinationMacTextBox); + this.Controls.Add(this.SourceIpTextBox); + this.Controls.Add(this.DirectionComboBox); + this.Controls.Add(this.SourceMacTextBox); + this.Controls.Add(this.OperationComboBox); + this.Name = "NewFireWall"; + this.Text = "NewFireWall"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.ComboBox OperationComboBox; + private System.Windows.Forms.TextBox SourceMacTextBox; + private System.Windows.Forms.ComboBox DirectionComboBox; + private System.Windows.Forms.TextBox SourceIpTextBox; + private System.Windows.Forms.TextBox DestinationMacTextBox; + private System.Windows.Forms.TextBox DestinationIpTextBox; + private System.Windows.Forms.TextBox SourcePortTextBox; + private System.Windows.Forms.TextBox DestinationPortTextBox; + private System.Windows.Forms.Label Operation; + private System.Windows.Forms.Label Protocol; + private System.Windows.Forms.Label Direction; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.Label label8; + private System.Windows.Forms.Label label9; + private System.Windows.Forms.Button AddNewFireWallButton; + private System.Windows.Forms.TextBox ProtocolTextBox; + } +} \ No newline at end of file diff --git a/GUI/NewFireWall.cs b/GUI/NewFireWall.cs new file mode 100644 index 0000000..0369341 --- /dev/null +++ b/GUI/NewFireWall.cs @@ -0,0 +1,84 @@ +using System; +using System.Windows.Forms; +using eSwitch.Networking; +using System.Net; +using System.Net.NetworkInformation; + +namespace eSwitch.GUI +{ + public partial class NewFireWall : Form + { + + private readonly Device _device; + + public Network N = new Network(); + public FirewallRule Rule { get; private set; } + + + public NewFireWall(int position) + { + _device = N.Devices[position]; + InitializeComponent(); + } + + public FirewallRule GetRule() + { + return Rule; + } + + private static void InlineTry(Action action) + { + try + { + action(); + } + catch {} + } + + private void AddNewFireWallButton_Click(object sender, EventArgs e) + { + var rule = new FirewallRule(); + + + int currentMyComboBoxIndex; + + if (OperationComboBox.SelectedIndex > -1) + { + currentMyComboBoxIndex = OperationComboBox.SelectedIndex; + Console.WriteLine(currentMyComboBoxIndex); + if (currentMyComboBoxIndex == 0) + rule.RuleOperation = FirewallRule.Operation.Deny; + else + rule.RuleOperation = FirewallRule.Operation.Permit; + } + if (DirectionComboBox.SelectedIndex > -1) + { + currentMyComboBoxIndex = DirectionComboBox.SelectedIndex; + Console.WriteLine(currentMyComboBoxIndex); + if (currentMyComboBoxIndex == 0) + rule.RuleDirection = FirewallRule.Direction.Inside; + else + rule.RuleDirection = FirewallRule.Direction.Outside; + + } + + InlineTry(() => rule.RuleProtocol = string.Format(ProtocolTextBox.Text)); + InlineTry(() => rule.DestinationMac = PhysicalAddress.Parse(DestinationMacTextBox.Text)); + InlineTry(() => rule.DestinationIp = IPAddress.Parse(DestinationIpTextBox.Text)); + InlineTry(() => rule.SourceMac = PhysicalAddress.Parse(SourceMacTextBox.Text)); + InlineTry(() => rule.SourceIp = IPAddress.Parse(SourceIpTextBox.Text)); + InlineTry(() => rule.DestinationPort = DestinationPortTextBox.Text.Length != 0 ? Convert.ToUInt16(DestinationPortTextBox.Text) : (ushort?)null); + InlineTry(() => rule.SourcePort = SourcePortTextBox.Text.Length != 0 ? Convert.ToUInt16(SourcePortTextBox.Text) : (ushort?)null); + + _device.FirewallRules.Add(rule); + Rule = rule; + + Console.WriteLine("NEW " + _device.FirewallRules.Count.ToString()); + Console.WriteLine(_device.FirewallRules[0].RuleDirection.ToString()); + Console.WriteLine(_device.FirewallRules[0].RuleOperation); + Console.WriteLine(_device.FirewallRules[0].RuleProtocol); + this.Close(); + } + } +} + diff --git a/GUI/NewFireWall.resx b/GUI/NewFireWall.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/GUI/NewFireWall.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/GUI/TableView.Designer.cs b/GUI/TableView.Designer.cs index bc32b3d..9fa02f3 100644 --- a/GUI/TableView.Designer.cs +++ b/GUI/TableView.Designer.cs @@ -48,6 +48,26 @@ private void InitializeComponent() this.LLDP = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.HTTP = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.RstStatsBtn = new System.Windows.Forms.Button(); + this.FireWallTable = new System.Windows.Forms.DataGridView(); + this.Dev = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Direction = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Protocol = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.SourceMac = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.SourceIp = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.DestinationMac = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.DestinationIp = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.SourcePort = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.DestinationPort = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.FireWallTable1 = new System.Windows.Forms.DataGridView(); + this.dataGridViewTextBoxColumn1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.dataGridViewTextBoxColumn2 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.dataGridViewTextBoxColumn3 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.dataGridViewTextBoxColumn4 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.dataGridViewTextBoxColumn5 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.dataGridViewTextBoxColumn6 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.dataGridViewTextBoxColumn7 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.dataGridViewTextBoxColumn8 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.dataGridViewTextBoxColumn9 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.deviceDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.tTLDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.physicalAdsressDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); @@ -60,6 +80,8 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.DeviceTable)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.CamTable)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.StatisticsTable)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.FireWallTable)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.FireWallTable1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.camRecordBindingSource)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.deviceBindingSource)).BeginInit(); this.SuspendLayout(); @@ -67,7 +89,7 @@ private void InitializeComponent() // StartButton // this.StartButton.Location = new System.Drawing.Point(44, 35); - this.StartButton.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.StartButton.Margin = new System.Windows.Forms.Padding(4); this.StartButton.Name = "StartButton"; this.StartButton.Size = new System.Drawing.Size(78, 44); this.StartButton.TabIndex = 0; @@ -79,7 +101,7 @@ private void InitializeComponent() // this.StopButton.Enabled = false; this.StopButton.Location = new System.Drawing.Point(142, 35); - this.StopButton.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.StopButton.Margin = new System.Windows.Forms.Padding(4); this.StopButton.Name = "StopButton"; this.StopButton.Size = new System.Drawing.Size(96, 44); this.StopButton.TabIndex = 1; @@ -101,12 +123,13 @@ private void InitializeComponent() this.receivedDataGridViewTextBoxColumn}); this.DeviceTable.DataSource = this.deviceBindingSource; this.DeviceTable.Location = new System.Drawing.Point(44, 87); - this.DeviceTable.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.DeviceTable.Margin = new System.Windows.Forms.Padding(4); this.DeviceTable.Name = "DeviceTable"; this.DeviceTable.RowHeadersWidth = 82; this.DeviceTable.RowTemplate.Height = 33; this.DeviceTable.Size = new System.Drawing.Size(684, 429); this.DeviceTable.TabIndex = 2; + this.DeviceTable.CellContentDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.DeviceTable_CellContentDoubleClick); // // CamTable // @@ -122,18 +145,18 @@ private void InitializeComponent() this.physicalAdsressDataGridViewTextBoxColumn}); this.CamTable.DataSource = this.camRecordBindingSource; this.CamTable.Location = new System.Drawing.Point(768, 87); - this.CamTable.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.CamTable.Margin = new System.Windows.Forms.Padding(4); this.CamTable.Name = "CamTable"; this.CamTable.RowHeadersWidth = 82; this.CamTable.RowTemplate.Height = 33; - this.CamTable.Size = new System.Drawing.Size(664, 429); + this.CamTable.Size = new System.Drawing.Size(761, 429); this.CamTable.TabIndex = 3; // // ClearCamButton // this.ClearCamButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.ClearCamButton.Location = new System.Drawing.Point(1326, 35); - this.ClearCamButton.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.ClearCamButton.Location = new System.Drawing.Point(1423, 35); + this.ClearCamButton.Margin = new System.Windows.Forms.Padding(4); this.ClearCamButton.Name = "ClearCamButton"; this.ClearCamButton.Size = new System.Drawing.Size(100, 44); this.ClearCamButton.TabIndex = 4; @@ -143,18 +166,18 @@ private void InitializeComponent() // // TTLBox // - this.TTLBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.TTLBox.Location = new System.Drawing.Point(1296, 630); - this.TTLBox.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.TTLBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.TTLBox.Location = new System.Drawing.Point(1393, 666); + this.TTLBox.Margin = new System.Windows.Forms.Padding(4); this.TTLBox.Name = "TTLBox"; this.TTLBox.Size = new System.Drawing.Size(136, 31); this.TTLBox.TabIndex = 5; // // ResetTTLButton // - this.ResetTTLButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.ResetTTLButton.Location = new System.Drawing.Point(1296, 688); - this.ResetTTLButton.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.ResetTTLButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.ResetTTLButton.Location = new System.Drawing.Point(1393, 705); + this.ResetTTLButton.Margin = new System.Windows.Forms.Padding(4); this.ResetTTLButton.Name = "ResetTTLButton"; this.ResetTTLButton.Size = new System.Drawing.Size(136, 58); this.ResetTTLButton.TabIndex = 6; @@ -164,7 +187,7 @@ private void InitializeComponent() // // StatisticsTable // - this.StatisticsTable.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + this.StatisticsTable.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.StatisticsTable.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCells; this.StatisticsTable.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCells; @@ -180,12 +203,12 @@ private void InitializeComponent() this.ARP, this.LLDP, this.HTTP}); - this.StatisticsTable.Location = new System.Drawing.Point(44, 630); - this.StatisticsTable.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.StatisticsTable.Location = new System.Drawing.Point(44, 595); + this.StatisticsTable.Margin = new System.Windows.Forms.Padding(4); this.StatisticsTable.Name = "StatisticsTable"; this.StatisticsTable.RowHeadersWidth = 82; this.StatisticsTable.RowTemplate.Height = 33; - this.StatisticsTable.Size = new System.Drawing.Size(1130, 196); + this.StatisticsTable.Size = new System.Drawing.Size(1227, 196); this.StatisticsTable.TabIndex = 9; // // DevName @@ -259,9 +282,8 @@ private void InitializeComponent() // // RstStatsBtn // - this.RstStatsBtn.Anchor = System.Windows.Forms.AnchorStyles.Left; - this.RstStatsBtn.Location = new System.Drawing.Point(44, 542); - this.RstStatsBtn.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.RstStatsBtn.Location = new System.Drawing.Point(44, 524); + this.RstStatsBtn.Margin = new System.Windows.Forms.Padding(4); this.RstStatsBtn.Name = "RstStatsBtn"; this.RstStatsBtn.Size = new System.Drawing.Size(194, 60); this.RstStatsBtn.TabIndex = 10; @@ -269,6 +291,184 @@ private void InitializeComponent() this.RstStatsBtn.UseVisualStyleBackColor = true; this.RstStatsBtn.Click += new System.EventHandler(this.RstStatsBtn_Click); // + // FireWallTable + // + this.FireWallTable.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.FireWallTable.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCells; + this.FireWallTable.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCells; + this.FireWallTable.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.FireWallTable.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.Dev, + this.Direction, + this.Protocol, + this.SourceMac, + this.SourceIp, + this.DestinationMac, + this.DestinationIp, + this.SourcePort, + this.DestinationPort}); + this.FireWallTable.Location = new System.Drawing.Point(44, 820); + this.FireWallTable.Margin = new System.Windows.Forms.Padding(4); + this.FireWallTable.Name = "FireWallTable"; + this.FireWallTable.RowHeadersWidth = 82; + this.FireWallTable.RowTemplate.Height = 33; + this.FireWallTable.Size = new System.Drawing.Size(1485, 209); + this.FireWallTable.TabIndex = 11; + this.FireWallTable.CellContentDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.FireWallTable_CellContentDoubleClick); + // + // Dev + // + this.Dev.HeaderText = "Operation "; + this.Dev.MinimumWidth = 10; + this.Dev.Name = "Dev"; + this.Dev.Width = 157; + // + // Direction + // + this.Direction.HeaderText = "Direction"; + this.Direction.MinimumWidth = 10; + this.Direction.Name = "Direction"; + this.Direction.Width = 142; + // + // Protocol + // + this.Protocol.HeaderText = "Protocol"; + this.Protocol.MinimumWidth = 10; + this.Protocol.Name = "Protocol"; + this.Protocol.Width = 136; + // + // SourceMac + // + this.SourceMac.HeaderText = "SourceMac"; + this.SourceMac.MinimumWidth = 10; + this.SourceMac.Name = "SourceMac"; + this.SourceMac.Width = 166; + // + // SourceIp + // + this.SourceIp.HeaderText = "SourceIp"; + this.SourceIp.MinimumWidth = 10; + this.SourceIp.Name = "SourceIp"; + this.SourceIp.Width = 142; + // + // DestinationMac + // + this.DestinationMac.HeaderText = "DestinationMac"; + this.DestinationMac.MinimumWidth = 10; + this.DestinationMac.Name = "DestinationMac"; + this.DestinationMac.Width = 206; + // + // DestinationIp + // + this.DestinationIp.HeaderText = "DestinationIp"; + this.DestinationIp.MinimumWidth = 10; + this.DestinationIp.Name = "DestinationIp"; + this.DestinationIp.Width = 182; + // + // SourcePort + // + this.SourcePort.HeaderText = "SourcePort"; + this.SourcePort.MinimumWidth = 10; + this.SourcePort.Name = "SourcePort"; + this.SourcePort.Width = 164; + // + // DestinationPort + // + this.DestinationPort.HeaderText = "DestinationPort"; + this.DestinationPort.MinimumWidth = 10; + this.DestinationPort.Name = "DestinationPort"; + this.DestinationPort.Width = 204; + // + // FireWallTable1 + // + this.FireWallTable1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.FireWallTable1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCells; + this.FireWallTable1.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCells; + this.FireWallTable1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.FireWallTable1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.dataGridViewTextBoxColumn1, + this.dataGridViewTextBoxColumn2, + this.dataGridViewTextBoxColumn3, + this.dataGridViewTextBoxColumn4, + this.dataGridViewTextBoxColumn5, + this.dataGridViewTextBoxColumn6, + this.dataGridViewTextBoxColumn7, + this.dataGridViewTextBoxColumn8, + this.dataGridViewTextBoxColumn9}); + this.FireWallTable1.Location = new System.Drawing.Point(44, 1067); + this.FireWallTable1.Margin = new System.Windows.Forms.Padding(4); + this.FireWallTable1.Name = "FireWallTable1"; + this.FireWallTable1.RowHeadersWidth = 82; + this.FireWallTable1.RowTemplate.Height = 33; + this.FireWallTable1.Size = new System.Drawing.Size(1485, 209); + this.FireWallTable1.TabIndex = 13; + this.FireWallTable1.CellContentDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.FireWallTable1_CellContentDoubleClick); + // + // dataGridViewTextBoxColumn1 + // + this.dataGridViewTextBoxColumn1.HeaderText = "Operation "; + this.dataGridViewTextBoxColumn1.MinimumWidth = 10; + this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1"; + this.dataGridViewTextBoxColumn1.Width = 157; + // + // dataGridViewTextBoxColumn2 + // + this.dataGridViewTextBoxColumn2.HeaderText = "Direction"; + this.dataGridViewTextBoxColumn2.MinimumWidth = 10; + this.dataGridViewTextBoxColumn2.Name = "dataGridViewTextBoxColumn2"; + this.dataGridViewTextBoxColumn2.Width = 142; + // + // dataGridViewTextBoxColumn3 + // + this.dataGridViewTextBoxColumn3.HeaderText = "Protocol"; + this.dataGridViewTextBoxColumn3.MinimumWidth = 10; + this.dataGridViewTextBoxColumn3.Name = "dataGridViewTextBoxColumn3"; + this.dataGridViewTextBoxColumn3.Width = 136; + // + // dataGridViewTextBoxColumn4 + // + this.dataGridViewTextBoxColumn4.HeaderText = "SourceMac"; + this.dataGridViewTextBoxColumn4.MinimumWidth = 10; + this.dataGridViewTextBoxColumn4.Name = "dataGridViewTextBoxColumn4"; + this.dataGridViewTextBoxColumn4.Width = 166; + // + // dataGridViewTextBoxColumn5 + // + this.dataGridViewTextBoxColumn5.HeaderText = "SourceIp"; + this.dataGridViewTextBoxColumn5.MinimumWidth = 10; + this.dataGridViewTextBoxColumn5.Name = "dataGridViewTextBoxColumn5"; + this.dataGridViewTextBoxColumn5.Width = 142; + // + // dataGridViewTextBoxColumn6 + // + this.dataGridViewTextBoxColumn6.HeaderText = "DestinationMac"; + this.dataGridViewTextBoxColumn6.MinimumWidth = 10; + this.dataGridViewTextBoxColumn6.Name = "dataGridViewTextBoxColumn6"; + this.dataGridViewTextBoxColumn6.Width = 206; + // + // dataGridViewTextBoxColumn7 + // + this.dataGridViewTextBoxColumn7.HeaderText = "DestinationIp"; + this.dataGridViewTextBoxColumn7.MinimumWidth = 10; + this.dataGridViewTextBoxColumn7.Name = "dataGridViewTextBoxColumn7"; + this.dataGridViewTextBoxColumn7.Width = 182; + // + // dataGridViewTextBoxColumn8 + // + this.dataGridViewTextBoxColumn8.HeaderText = "SourcePort"; + this.dataGridViewTextBoxColumn8.MinimumWidth = 10; + this.dataGridViewTextBoxColumn8.Name = "dataGridViewTextBoxColumn8"; + this.dataGridViewTextBoxColumn8.Width = 164; + // + // dataGridViewTextBoxColumn9 + // + this.dataGridViewTextBoxColumn9.HeaderText = "DestinationPort"; + this.dataGridViewTextBoxColumn9.MinimumWidth = 10; + this.dataGridViewTextBoxColumn9.Name = "dataGridViewTextBoxColumn9"; + this.dataGridViewTextBoxColumn9.Width = 204; + // // deviceDataGridViewTextBoxColumn // this.deviceDataGridViewTextBoxColumn.DataPropertyName = "Device"; @@ -341,7 +541,9 @@ private void InitializeComponent() // this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 25F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1522, 851); + this.ClientSize = new System.Drawing.Size(1619, 1678); + this.Controls.Add(this.FireWallTable1); + this.Controls.Add(this.FireWallTable); this.Controls.Add(this.RstStatsBtn); this.Controls.Add(this.StatisticsTable); this.Controls.Add(this.ResetTTLButton); @@ -351,12 +553,14 @@ private void InitializeComponent() this.Controls.Add(this.DeviceTable); this.Controls.Add(this.StopButton); this.Controls.Add(this.StartButton); - this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.Margin = new System.Windows.Forms.Padding(4); this.Name = "TableView"; this.Text = "eSwitch"; ((System.ComponentModel.ISupportInitialize)(this.DeviceTable)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.CamTable)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.StatisticsTable)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.FireWallTable)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.FireWallTable1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.camRecordBindingSource)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.deviceBindingSource)).EndInit(); this.ResumeLayout(false); @@ -394,5 +598,25 @@ private void InitializeComponent() private System.Windows.Forms.DataGridViewTextBoxColumn receivedDataGridViewTextBoxColumn; private System.Windows.Forms.Button RstStatsBtn; private System.Windows.Forms.DataGridViewTextBoxColumn HTTP; + private System.Windows.Forms.DataGridView FireWallTable; + private System.Windows.Forms.DataGridViewTextBoxColumn Dev; + private System.Windows.Forms.DataGridViewTextBoxColumn Direction; + private System.Windows.Forms.DataGridViewTextBoxColumn Protocol; + private System.Windows.Forms.DataGridViewTextBoxColumn SourceMac; + private System.Windows.Forms.DataGridViewTextBoxColumn SourceIp; + private System.Windows.Forms.DataGridViewTextBoxColumn DestinationMac; + private System.Windows.Forms.DataGridViewTextBoxColumn DestinationIp; + private System.Windows.Forms.DataGridViewTextBoxColumn SourcePort; + private System.Windows.Forms.DataGridViewTextBoxColumn DestinationPort; + private System.Windows.Forms.DataGridView FireWallTable1; + private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn1; + private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn2; + private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn3; + private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn4; + private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn5; + private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn6; + private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn7; + private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn8; + private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn9; } } \ No newline at end of file diff --git a/GUI/TableView.cs b/GUI/TableView.cs index 7a8fb81..fe60191 100644 --- a/GUI/TableView.cs +++ b/GUI/TableView.cs @@ -10,8 +10,9 @@ public partial class TableView : Form { public Network N { get; } = new Network(); + public Device D { get; } - private int q = 0; + private int q = 0, higher, lower; public TableView() { @@ -20,6 +21,9 @@ public TableView() DeviceTable.RowHeadersVisible = false; CamTable.RowHeadersVisible = false; StatisticsTable.RowHeadersVisible = false; + FireWallTable.RowHeadersVisible = false; + FireWallTable1.RowHeadersVisible = false; + DeviceTable.DataSource = N.Devices; @@ -31,14 +35,25 @@ private void StartButton_Click(object sender, EventArgs e) StartButton.Enabled = false; StopButton.Enabled = true; int i = 0; + int heh = 0; foreach (DataGridViewRow row in DeviceTable.Rows) { if (Convert.ToBoolean(row.Cells[0].Value)) { + Console.WriteLine("\n" + i + "\n"); N.Devices[i].Open(); q = StatisticsTable.Rows.Add(); StatisticsTable.Rows[q].Cells[0].Value = N.Devices[i].Name; + if (heh == 1) + lower = i; + + if (heh == 0) + { + higher = i; + heh = 1; + } + } i++; } @@ -54,8 +69,8 @@ private void RefreshCamTable(object sender, EventArgs eventArgs) private string StatisticsConverter(int DevNum, string ToConvert) { - return Convert.ToString(Convert.ToUInt64((long)N.Devices[DevNum].Statistics[ToConvert][0])) + - " / " + Convert.ToString(Convert.ToUInt64((long)N.Devices[DevNum].Statistics[ToConvert][1])); + return Convert.ToString(Convert.ToUInt64((long)N.Devices[DevNum].Statistics[ToConvert][FirewallRule.Direction.Inside])) + + " / " + Convert.ToString((long)N.Devices[DevNum].Statistics[ToConvert][FirewallRule.Direction.Outside]); } private void HandleSelection() @@ -151,33 +166,33 @@ private void RstStatsBtn_Click(object sender, EventArgs e) if (Convert.ToBoolean(row.Cells[0].Value) && z == 1) { N.Devices[i].Statistics["ICMPv4"][0] = 0; - N.Devices[i].Statistics["ICMPv4"][1] = 0; + N.Devices[i].Statistics["ICMPv4"][FirewallRule.Direction.Outside] = 0; N.Devices[i].Statistics["ICMPv6"][0] = 0; - N.Devices[i].Statistics["ICMPv6"][1] = 0; + N.Devices[i].Statistics["ICMPv6"][FirewallRule.Direction.Outside] = 0; N.Devices[i].Statistics["TCP"][0] = 0; - N.Devices[i].Statistics["TCP"][1] = 0; + N.Devices[i].Statistics["TCP"][FirewallRule.Direction.Outside] = 0; N.Devices[i].Statistics["UDP"][0] = 0; - N.Devices[i].Statistics["UDP"][1] = 0; + N.Devices[i].Statistics["UDP"][FirewallRule.Direction.Outside] = 0; N.Devices[i].Statistics["IPv4"][0] = 0; - N.Devices[i].Statistics["IPv4"][1] = 0; + N.Devices[i].Statistics["IPv4"][FirewallRule.Direction.Outside] = 0; N.Devices[i].Statistics["IPv6"][0] = 0; - N.Devices[i].Statistics["IPv6"][1] = 0; + N.Devices[i].Statistics["IPv6"][FirewallRule.Direction.Outside] = 0; N.Devices[i].Statistics["ARP"][0] = 0; - N.Devices[i].Statistics["ARP"][1] = 0; + N.Devices[i].Statistics["ARP"][FirewallRule.Direction.Outside] = 0; N.Devices[i].Statistics["LLDP"][0] = 0; - N.Devices[i].Statistics["LLDP"][1] = 0; + N.Devices[i].Statistics["LLDP"][FirewallRule.Direction.Outside] = 0; N.Devices[i].Statistics["HTTP"][0] = 0; - N.Devices[i].Statistics["HTTP"][1] = 0; + N.Devices[i].Statistics["HTTP"][FirewallRule.Direction.Outside] = 0; break; } @@ -185,32 +200,32 @@ private void RstStatsBtn_Click(object sender, EventArgs e) if (Convert.ToBoolean(row.Cells[0].Value) && z == 0) { N.Devices[i].Statistics["ICMPv4"][0] = 0; - N.Devices[i].Statistics["ICMPv4"][1] = 0; + N.Devices[i].Statistics["ICMPv4"][FirewallRule.Direction.Outside] = 0; N.Devices[i].Statistics["ICMPv6"][0] = 0; - N.Devices[i].Statistics["ICMPv6"][1] = 0; + N.Devices[i].Statistics["ICMPv6"][FirewallRule.Direction.Outside] = 0; N.Devices[i].Statistics["TCP"][0] = 0; - N.Devices[i].Statistics["TCP"][1] = 0; + N.Devices[i].Statistics["TCP"][FirewallRule.Direction.Outside] = 0; N.Devices[i].Statistics["UDP"][0] = 0; - N.Devices[i].Statistics["UDP"][1] = 0; + N.Devices[i].Statistics["UDP"][FirewallRule.Direction.Outside] = 0; N.Devices[i].Statistics["IPv4"][0] = 0; - N.Devices[i].Statistics["IPv4"][1] = 0; + N.Devices[i].Statistics["IPv4"][FirewallRule.Direction.Outside] = 0; N.Devices[i].Statistics["IPv6"][0] = 0; - N.Devices[i].Statistics["IPv6"][1] = 0; + N.Devices[i].Statistics["IPv6"][FirewallRule.Direction.Outside] = 0; N.Devices[i].Statistics["ARP"][0] = 0; - N.Devices[i].Statistics["ARP"][1] = 0; + N.Devices[i].Statistics["ARP"][FirewallRule.Direction.Outside] = 0; N.Devices[i].Statistics["LLDP"][0] = 0; - N.Devices[i].Statistics["LLDP"][1] = 0; + N.Devices[i].Statistics["LLDP"][FirewallRule.Direction.Outside] = 0; N.Devices[i].Statistics["HTTP"][0] = 0; - N.Devices[i].Statistics["HTTP"][1] = 0; + N.Devices[i].Statistics["HTTP"][FirewallRule.Direction.Outside] = 0; z = 1; } @@ -218,5 +233,74 @@ private void RstStatsBtn_Click(object sender, EventArgs e) } } + + private void DeviceTable_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e) + { + Console.WriteLine(e.RowIndex); + + var firewallWindow = new NewFireWall(e.RowIndex); + firewallWindow.ShowDialog(); + N.Devices[e.RowIndex].FirewallRules.Add(firewallWindow.GetRule()); + + if(e.RowIndex == higher) + BuildTable(e.RowIndex); + if(e.RowIndex == lower) + BuildTable1(e.RowIndex); + } + + private int g = 0; + private int gg = 0; + + private void FireWallTable_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e) + { + FirewallRule remove = N.Devices[higher].FirewallRules[e.RowIndex]; + N.Devices[higher].FirewallRules.Remove(remove); + BuildTable(higher); + } + + private void FireWallTable1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e) + { + FirewallRule remove = N.Devices[lower].FirewallRules[e.RowIndex]; + N.Devices[lower].FirewallRules.Remove(remove); + BuildTable1(lower); + } + + public void BuildTable(int z) + { + FireWallTable.Rows.Clear(); + for (int i = 0; i < N.Devices[z].FirewallRules.Count(); i++) + { + + g = FireWallTable.Rows.Add(); + FireWallTable.Rows[g].Cells[0].Value = N.Devices[z].FirewallRules[i].RuleOperation; + FireWallTable.Rows[g].Cells[1].Value = N.Devices[z].FirewallRules[i].RuleDirection; + FireWallTable.Rows[g].Cells[2].Value = N.Devices[z].FirewallRules[i].RuleProtocol; + FireWallTable.Rows[g].Cells[3].Value = N.Devices[z].FirewallRules[i].SourceMac; + FireWallTable.Rows[g].Cells[4].Value = N.Devices[z].FirewallRules[i].SourceIp; + FireWallTable.Rows[g].Cells[5].Value = N.Devices[z].FirewallRules[i].DestinationMac; + FireWallTable.Rows[g].Cells[6].Value = N.Devices[z].FirewallRules[i].DestinationIp; + FireWallTable.Rows[g].Cells[7].Value = N.Devices[z].FirewallRules[i].SourcePort; + FireWallTable.Rows[g].Cells[8].Value = N.Devices[z].FirewallRules[i].DestinationPort; + } + } + + public void BuildTable1(int z) + { + FireWallTable1.Rows.Clear(); + for (int i = 0; i < N.Devices[z].FirewallRules.Count(); i++) + { + + gg = FireWallTable1.Rows.Add(); + FireWallTable1.Rows[gg].Cells[0].Value = N.Devices[z].FirewallRules[i].RuleOperation; + FireWallTable1.Rows[gg].Cells[1].Value = N.Devices[z].FirewallRules[i].RuleDirection; + FireWallTable1.Rows[gg].Cells[2].Value = N.Devices[z].FirewallRules[i].RuleProtocol; + FireWallTable1.Rows[gg].Cells[3].Value = N.Devices[z].FirewallRules[i].SourceMac; + FireWallTable1.Rows[gg].Cells[4].Value = N.Devices[z].FirewallRules[i].SourceIp; + FireWallTable1.Rows[gg].Cells[5].Value = N.Devices[z].FirewallRules[i].DestinationMac; + FireWallTable1.Rows[gg].Cells[6].Value = N.Devices[z].FirewallRules[i].DestinationIp; + FireWallTable1.Rows[gg].Cells[7].Value = N.Devices[z].FirewallRules[i].SourcePort; + FireWallTable1.Rows[gg].Cells[8].Value = N.Devices[z].FirewallRules[i].DestinationPort; + } + } } } diff --git a/GUI/TableView.resx b/GUI/TableView.resx index 2fc0f31..6418a38 100644 --- a/GUI/TableView.resx +++ b/GUI/TableView.resx @@ -153,4 +153,58 @@ True + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + \ No newline at end of file diff --git a/Networking/Device.cs b/Networking/Device.cs index 8d9aded..d8a74d6 100644 --- a/Networking/Device.cs +++ b/Networking/Device.cs @@ -4,6 +4,7 @@ using PacketDotNet; using SharpPcap; using SharpPcap.WinPcap; +using System.Linq; namespace eSwitch.Networking @@ -18,63 +19,62 @@ public class Device public readonly WinPcapDevice _captureDevice; public event EventHandler PacketReceived; - private static readonly int Inside = 0; - private static readonly int Outside = 1; + public List FirewallRules = new List(); - public Dictionary> Statistics { get; set; } = new Dictionary> + public Dictionary> Statistics { get; set; } = new Dictionary> { - {"TCP", new Dictionary() + {"TCP", new Dictionary() { - {Inside, 0 }, - {Outside, 0 } + {FirewallRule.Direction.Inside, 0 }, + {FirewallRule.Direction.Outside, 0 } } }, - {"UDP", new Dictionary() + {"UDP", new Dictionary() { - {Inside, 0 }, - {Outside, 0 } + {FirewallRule.Direction.Inside, 0 }, + {FirewallRule.Direction.Outside, 0 } } }, - {"ICMPv4", new Dictionary() + {"ICMPv4", new Dictionary() { - {Inside, 0 }, - {Outside, 0 } + {FirewallRule.Direction.Inside, 0 }, + {FirewallRule.Direction.Outside, 0 } } }, - {"ICMPv6", new Dictionary() + {"ICMPv6", new Dictionary() { - {Inside, 0 }, - {Outside, 0 } + {FirewallRule.Direction.Inside, 0 }, + {FirewallRule.Direction.Outside, 0 } } }, - {"IPv4", new Dictionary() + {"IPv4", new Dictionary() { - {Inside, 0 }, - {Outside, 0 } + {FirewallRule.Direction.Inside, 0 }, + {FirewallRule.Direction.Outside, 0 } } }, - {"IPv6", new Dictionary() + {"IPv6", new Dictionary() { - {Inside, 0 }, - {Outside, 0 } + {FirewallRule.Direction.Inside, 0 }, + {FirewallRule.Direction.Outside, 0 } } }, - {"ARP", new Dictionary() + {"ARP", new Dictionary() { - {Inside, 0 }, - {Outside, 0 } + {FirewallRule.Direction.Inside, 0 }, + {FirewallRule.Direction.Outside, 0 } } }, - {"LLDP", new Dictionary() + {"LLDP", new Dictionary() { - {Inside, 0 }, - {Outside, 0 } + {FirewallRule.Direction.Inside, 0 }, + {FirewallRule.Direction.Outside, 0 } } }, - {"HTTP", new Dictionary() + {"HTTP", new Dictionary() { - {Inside, 0 }, - {Outside, 0 } + {FirewallRule.Direction.Inside, 0 }, + {FirewallRule.Direction.Outside, 0 } } } }; @@ -113,25 +113,47 @@ private void PacketArrival(object sender, CaptureEventArgs e) { var packet = Packet.ParsePacket(LinkLayers.Ethernet, e.Packet.Data); - if (packet is EthernetPacket) + if (packet is EthernetPacket eth) { - EthernetPacket eth = (EthernetPacket)packet; - Task.Run((() => { PacketReceived?.Invoke(this, eth); })); - Received++; - this.ProcessStatistics(Inside, eth); + Task.Run((() => + { + + if (this.PassedFirewall(FirewallRule.Direction.Inside, eth)) + { + PacketReceived?.Invoke(this, eth); + Received++; + this.ProcessStatistics(FirewallRule.Direction.Inside, eth); + } + })); + /* + Task.Run((() => + { + if (this.PassedFirewall(FirewallRule.Direction.Inside, eth)) + { + + Received++; + this.ProcessStatistics(FirewallRule.Direction.Inside, eth); + } + })); + */ } } public void SendPacket(EthernetPacket eth) { - - _captureDevice.SendPacket(eth.Bytes); - Sent++; - this.ProcessStatistics(Outside, eth); + if (eth.TotalPacketLength < 1400) + { + try + { + _captureDevice.SendPacket(eth.Bytes); + Sent++; + this.ProcessStatistics(FirewallRule.Direction.Outside, eth); + } catch {} + } } - private void ProcessStatistics(int direction, EthernetPacket packet) + private void ProcessStatistics(FirewallRule.Direction direction, EthernetPacket packet) { if (packet.Extract() != null) { @@ -167,6 +189,7 @@ private void ProcessStatistics(int direction, EthernetPacket packet) if (packet.Extract() != null) { + Statistics["IPv4"][direction]++; } @@ -185,5 +208,19 @@ private void ProcessStatistics(int direction, EthernetPacket packet) Statistics["LLDP"][direction]++; } } + + + public bool PassedFirewall(FirewallRule.Direction direction, EthernetPacket packet) + { + foreach (var rule in FirewallRules.Where(rule => rule.RuleDirection == null || direction.Equals(rule.RuleDirection))) + { + if (rule.IsMatch(packet)) + { + return rule.RuleOperation.Equals(FirewallRule.Operation.Permit); + } + } + + return Properties.Settings.Default.IsWhitelist; + } } } diff --git a/Networking/FirewallRule.cs b/Networking/FirewallRule.cs new file mode 100644 index 0000000..2d051fe --- /dev/null +++ b/Networking/FirewallRule.cs @@ -0,0 +1,171 @@ +using System; +using System.Collections.Generic; +using System.Net; +using System.Net.NetworkInformation; +using PacketDotNet; + +namespace eSwitch.Networking +{ + public class FirewallRule + { + + public enum Operation + { + Deny = 0, + Permit = 1 + } + + + public enum Direction + { + Inside = 0, + Outside = 1 + } + + public Operation RuleOperation { get; set; } + public Direction RuleDirection { get; set; } + public PhysicalAddress SourceMac { get; set; } + public IPAddress SourceIp { get; set; } + public PhysicalAddress DestinationMac { get; set; } + public IPAddress DestinationIp { get; set; } + public string RuleProtocol { get; set; } + public ushort? SourcePort { get; set; } + public ushort? DestinationPort { get; set; } + + + + private bool ResolveValidationStack(Stack> stack) + { + foreach (Func rule in stack) + { + if (!rule()) + { + return false; + } + } + return true; + } + + public bool IsMatch(EthernetPacket packet) + { + var validationStack = new Stack>(); + + if (SourceMac != null) + { + validationStack.Push(() => SourceMac.Equals(packet.SourceHardwareAddress)); + } + + if (DestinationMac != null) + { + validationStack.Push(() => DestinationMac.Equals(packet.DestinationHardwareAddress)); + } + + var arp = packet.Extract(); + if (arp != null && RuleProtocol.Equals("ARP")) + { + return ResolveValidationStack(validationStack); + } + + var lldp = packet.Extract(); + if (lldp != null && RuleProtocol.Equals("LLDP")) + { + return ResolveValidationStack(validationStack); + } + + + var ipv4 = packet.Extract(); + if (ipv4 != null) + { + if (SourceIp != null) + { + validationStack.Push(() => SourceIp.Equals(ipv4.SourceAddress)); + } + + if (DestinationIp != null) + { + validationStack.Push(() => DestinationIp.Equals(ipv4.DestinationAddress)); + } + + if (RuleProtocol.Equals("IPv4")) + { + return ResolveValidationStack(validationStack); + } + } + + var ipv6 = packet.Extract(); + if (ipv6 != null) + { + if (SourceIp != null) + { + validationStack.Push(() => SourceIp.Equals(ipv6.SourceAddress)); + } + + if (DestinationIp != null) + { + validationStack.Push(() => DestinationIp.Equals(ipv6.DestinationAddress)); + } + + if (RuleProtocol.Equals("IPv6")) + { + return ResolveValidationStack(validationStack); + } + } + + var icmpv4 = packet.Extract(); + if (icmpv4 != null && RuleProtocol.Equals("ICMPv4")) + { + if (DestinationPort != null) + { + validationStack.Push(() => (((ushort)icmpv4.TypeCode) / 256) == DestinationPort); + } + + return ResolveValidationStack(validationStack); + } + + var icmpv6 = packet.Extract(); + if (icmpv6 != null && RuleProtocol.Equals("ICMPv6")) + { + if (DestinationPort != null) + { + validationStack.Push(() => (((ushort)icmpv6.TypeCode) / 256) == DestinationPort); + } + + return ResolveValidationStack(validationStack); + } + + var tcp = packet.Extract(); + if (tcp != null && RuleProtocol.Equals("TCP")) + { + if (SourcePort != null) + { + validationStack.Push(() => SourcePort.Equals(tcp.SourcePort)); + } + + if (DestinationPort != null) + { + validationStack.Push(() => DestinationPort.Equals(tcp.DestinationPort)); + } + + return ResolveValidationStack(validationStack); + } + + var udp = packet.Extract(); + if (udp != null && RuleProtocol.Equals("UDP")) + { + if (SourcePort != null) + { + validationStack.Push(() => SourcePort.Equals(udp.SourcePort)); + } + + if (DestinationPort != null) + { + validationStack.Push(() => DestinationPort.Equals(udp.DestinationPort)); + } + + return ResolveValidationStack(validationStack); + } + + return false; + } + } +} \ No newline at end of file diff --git a/Networking/Network.cs b/Networking/Network.cs index 4e1aacb..b963a67 100644 --- a/Networking/Network.cs +++ b/Networking/Network.cs @@ -16,7 +16,8 @@ public class Network public event EventHandler CamChange; private Timer Clk { get; } = new Timer(1000); - + + public Network() { var devices = WinPcapDeviceList.Instance; @@ -40,7 +41,6 @@ private void ClockTickEvent(object source, ElapsedEventArgs e) { if (CamTable.Count == 0) { - Console.WriteLine("Count === 0"); return; } @@ -48,7 +48,6 @@ private void ClockTickEvent(object source, ElapsedEventArgs e) { if (CamTable[physicalAddress].TimeToDie()) { - Console.WriteLine("Remove after TTL \n"); CamTable.TryRemove(physicalAddress, out _); } } @@ -60,13 +59,28 @@ private void PacketArrival(object sender, EthernetPacket eth) { var senderDevice = (Device)sender; + if (!senderDevice.PassedFirewall(FirewallRule.Direction.Inside, eth)) + { + //this.Log(new Syslog(Severity.Debug, $"Packet thrown away by firewall on input")); + return; + } + + if (CamTable.ContainsKey(eth.DestinationHardwareAddress.ToString())) { var record = CamTable[eth.DestinationHardwareAddress.ToString()]; if (record.Device.Name != senderDevice.Name) { - record.Device.SendPacket(eth); + + if (record.Device.PassedFirewall(FirewallRule.Direction.Outside, eth)) + { + record.Device.SendPacket(eth); + } + else + { + //this.Log(new SyslogMessage(Severity.Debug, $"Packet thrown away by firewall on output")); + } } } else @@ -76,20 +90,23 @@ private void PacketArrival(object sender, EthernetPacket eth) { if (device.Name != senderDevice.Name) { - device.SendPacket(eth); + if (device.PassedFirewall(FirewallRule.Direction.Outside, eth)) + { + device.SendPacket(eth); + } + else + { + //this.Log(new SyslogMessage(Severity.Debug, $"Packet thrown away by firewall on output")); + } + } } } if (CamTable.ContainsKey(eth.SourceHardwareAddress.ToString()) && IndexOfValue(CamTable, senderDevice.Name, IndexOfKey(CamTable, eth.SourceHardwareAddress.ToString()))) - { - - //Console.WriteLine("\n\n Key index: tento print : " + IndexOfKey(CamTable, eth.SourceHardwareAddress.ToString())); - //Console.WriteLine("Value index tento print : " + IndexOfValue(CamTable, senderDevice.Name, IndexOfKey(CamTable, eth.SourceHardwareAddress.ToString()))); - CamTable[eth.SourceHardwareAddress.ToString()].Refresh(senderDevice); - - + { + CamTable[eth.SourceHardwareAddress.ToString()].Refresh(senderDevice); } else { @@ -98,7 +115,6 @@ private void PacketArrival(object sender, EthernetPacket eth) } } - // AddOrUpdate("dog", 5, (k, v) => v + 1) @@ -136,14 +152,12 @@ public void Stop() device.Close(); } ClearCam(); - Console.WriteLine("\nStop\n"); } public void ClearCam() { CamTable.Clear(); CamChange?.Invoke(this, null); - Console.WriteLine("\nClearcam\n"); } } } diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs index 67ce4ee..e22c380 100644 --- a/Properties/Settings.Designer.cs +++ b/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace eSwitch.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.7.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.8.1.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); @@ -34,5 +34,17 @@ public int TTL { this["TTL"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool IsWhitelist { + get { + return ((bool)(this["IsWhitelist"])); + } + set { + this["IsWhitelist"] = value; + } + } } } diff --git a/Properties/Settings.settings b/Properties/Settings.settings index 5330c81..0798128 100644 --- a/Properties/Settings.settings +++ b/Properties/Settings.settings @@ -5,5 +5,8 @@ 30 + + True + \ No newline at end of file diff --git a/bin/Debug/eSwitch.exe b/bin/Debug/eSwitch.exe index 4734293..fdd0e9c 100644 Binary files a/bin/Debug/eSwitch.exe and b/bin/Debug/eSwitch.exe differ diff --git a/bin/Debug/eSwitch.exe.config b/bin/Debug/eSwitch.exe.config index 4486581..f4d6a3c 100644 --- a/bin/Debug/eSwitch.exe.config +++ b/bin/Debug/eSwitch.exe.config @@ -13,6 +13,9 @@ 30 + + True + diff --git a/bin/Debug/eSwitch.pdb b/bin/Debug/eSwitch.pdb index efecd85..bdb06bc 100644 Binary files a/bin/Debug/eSwitch.pdb and b/bin/Debug/eSwitch.pdb differ diff --git a/eSwitch.csproj b/eSwitch.csproj index 144e6a5..05d8bd8 100644 --- a/eSwitch.csproj +++ b/eSwitch.csproj @@ -65,6 +65,12 @@ + + Form + + + NewFireWall.cs + Form @@ -73,6 +79,7 @@ + @@ -93,6 +100,9 @@ + + NewFireWall.cs + TableView.cs diff --git a/obj/Debug/DesignTimeResolveAssemblyReferences.cache b/obj/Debug/DesignTimeResolveAssemblyReferences.cache index c7ecd89..2b3662b 100644 Binary files a/obj/Debug/DesignTimeResolveAssemblyReferences.cache and b/obj/Debug/DesignTimeResolveAssemblyReferences.cache differ diff --git a/obj/Debug/eSwitch.GUI.NewFireWall.resources b/obj/Debug/eSwitch.GUI.NewFireWall.resources new file mode 100644 index 0000000..6c05a97 Binary files /dev/null and b/obj/Debug/eSwitch.GUI.NewFireWall.resources differ diff --git a/obj/Debug/eSwitch.csproj.CoreCompileInputs.cache b/obj/Debug/eSwitch.csproj.CoreCompileInputs.cache index 60c1070..df25e21 100644 --- a/obj/Debug/eSwitch.csproj.CoreCompileInputs.cache +++ b/obj/Debug/eSwitch.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -322faaa7ae30aa42ef7f082eb195ce43933d6f8e +fb80b9445a33fdbefbb139346431acddffde6875 diff --git a/obj/Debug/eSwitch.csproj.FileListAbsolute.txt b/obj/Debug/eSwitch.csproj.FileListAbsolute.txt index f690a77..0af3260 100644 --- a/obj/Debug/eSwitch.csproj.FileListAbsolute.txt +++ b/obj/Debug/eSwitch.csproj.FileListAbsolute.txt @@ -18,3 +18,4 @@ C:\GIT-Repositare\eSwitch\eSwitch\bin\Debug\System.Buffers.xml C:\GIT-Repositare\eSwitch\eSwitch\bin\Debug\System.Memory.xml C:\GIT-Repositare\eSwitch\eSwitch\bin\Debug\System.Numerics.Vectors.xml C:\GIT-Repositare\eSwitch\eSwitch\bin\Debug\System.Runtime.CompilerServices.Unsafe.xml +C:\GIT-Repositare\eSwitch\eSwitch\obj\Debug\eSwitch.GUI.NewFireWall.resources diff --git a/obj/Debug/eSwitch.csproj.GenerateResource.cache b/obj/Debug/eSwitch.csproj.GenerateResource.cache index 1148747..3d30ee4 100644 Binary files a/obj/Debug/eSwitch.csproj.GenerateResource.cache and b/obj/Debug/eSwitch.csproj.GenerateResource.cache differ diff --git a/obj/Debug/eSwitch.csprojAssemblyReference.cache b/obj/Debug/eSwitch.csprojAssemblyReference.cache index 41de7d1..8fdee2e 100644 Binary files a/obj/Debug/eSwitch.csprojAssemblyReference.cache and b/obj/Debug/eSwitch.csprojAssemblyReference.cache differ diff --git a/obj/Debug/eSwitch.exe b/obj/Debug/eSwitch.exe index 4734293..fdd0e9c 100644 Binary files a/obj/Debug/eSwitch.exe and b/obj/Debug/eSwitch.exe differ diff --git a/obj/Debug/eSwitch.pdb b/obj/Debug/eSwitch.pdb index efecd85..bdb06bc 100644 Binary files a/obj/Debug/eSwitch.pdb and b/obj/Debug/eSwitch.pdb differ