make firewall rules look nicer - add vlan to interface

This commit is contained in:
Tim Young 2017-02-20 16:59:04 +03:00
parent 1a0b42b727
commit 8da7714544

View File

@ -5,6 +5,7 @@ using System.Data;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using System.Xml; using System.Xml;
@ -15,6 +16,7 @@ namespace EduNetworkBuilder
public partial class FirewallEditor : Form public partial class FirewallEditor : Form
{ {
NetworkDevice FirewallDevice = null; NetworkDevice FirewallDevice = null;
public FirewallEditor(NetworkDevice WhatToEdit) public FirewallEditor(NetworkDevice WhatToEdit)
{ {
InitializeComponent(); InitializeComponent();
@ -23,13 +25,42 @@ namespace EduNetworkBuilder
Icon = Properties.Resources.NBIco; Icon = Properties.Resources.NBIco;
} }
string InterfaceVLAN(string device)
{
string answer = "";
string basedevice = Regex.Replace(device, ":.*","");
NetworkCard nic = FirewallDevice.NicFromName(basedevice);
if (nic != null)
{
NetworkInterface nif = nic.InterfaceFromName(device);
if(nif != null)
{
Network myNet = NB.GetNetwork();
int id = nif.GetNonForbiddenVLANID();
foreach(VLANName vn in myNet.VlanNames)
{
if(vn.ID == id)
{
answer = vn.Name;
break;
}
}
}
}
return answer;
}
void UpdateForm() void UpdateForm()
{ {
int selected = lbRules.SelectedIndex; int selected = lbRules.SelectedIndex;
lbRules.Items.Clear(); lbRules.Items.Clear();
foreach (FirewallRule FW in FirewallDevice.FirewallRules) foreach (FirewallRule FW in FirewallDevice.FirewallRules)
{ {
string OneLine = FW.Action.ToString() + " " + FW.Source + " -> " + FW.Destination; string svlan = InterfaceVLAN(FW.Source);
if (svlan != "") svlan = svlan + " ";
string dvlan = InterfaceVLAN(FW.Destination);
if (dvlan != "") dvlan = dvlan + " ";
string OneLine = FW.Action.ToString() + " " + FW.Source + " " + svlan + " -> " + FW.Destination + " " + dvlan;
lbRules.Items.Add(OneLine); lbRules.Items.Add(OneLine);
} }
if (selected >= 0 && selected < lbRules.Items.Count) if (selected >= 0 && selected < lbRules.Items.Count)