Able to power off devices, power them back on, and devices off will not pass packets.

This commit is contained in:
Tim Young 2017-03-10 16:07:53 +03:00
parent bd1ca9fdf2
commit 4500416364
7 changed files with 72 additions and 47 deletions

View File

@ -649,6 +649,17 @@ namespace EduNetworkBuilder
pbNetworkView.ContextMenuStrip.Items.Add(string.Format(NB.Translate("NB_NetViewRmLnkStr"), host)); pbNetworkView.ContextMenuStrip.Items.Add(string.Format(NB.Translate("NB_NetViewRmLnkStr"), host));
pbNetworkView.ContextMenuStrip.Items[index++].Click += pbNetworkView_RemoveLink_Click; pbNetworkView.ContextMenuStrip.Items[index++].Click += pbNetworkView_RemoveLink_Click;
} }
if(ReleasedOn.PowerOff)
{
pbNetworkView.ContextMenuStrip.Items.Add(NB.Translate("NB_PowerOn"));
pbNetworkView.ContextMenuStrip.Items[index++].Click += pbNetworkView_PowerOn_Click;
}
else if(ReleasedOn.ForwardsPackets() || ReleasedOn.RoutesPackets())
{
pbNetworkView.ContextMenuStrip.Items.Add(NB.Translate("NB_PowerOff"));
pbNetworkView.ContextMenuStrip.Items[index++].Click += pbNetworkView_PowerOff_Click;
}
} }
} }
else //we are locked out. else //we are locked out.
@ -678,6 +689,24 @@ namespace EduNetworkBuilder
} }
} }
private void pbNetworkView_PowerOn_Click(object sender, EventArgs e)
{
if (ItemClickedOn != null)
{
ItemClickedOn.PowerOff = false;
UpdateVisuals();
}
}
private void pbNetworkView_PowerOff_Click(object sender, EventArgs e)
{
if (ItemClickedOn != null)
{
ItemClickedOn.PowerOff = true;
UpdateVisuals();
}
}
private void pbNetworkView_Color_Click(object sender, EventArgs e) private void pbNetworkView_Color_Click(object sender, EventArgs e)
{ {
ToolStripMenuItem TSMI = (ToolStripMenuItem)sender; ToolStripMenuItem TSMI = (ToolStripMenuItem)sender;

View File

@ -35,6 +35,7 @@ namespace EduNetworkBuilder
public Color BackgroundColor = Color.Empty; public Color BackgroundColor = Color.Empty;
protected Color MorphColor = Color.Empty; protected Color MorphColor = Color.Empty;
public List<FirewallRule> FirewallRules = new List<FirewallRule>(); public List<FirewallRule> FirewallRules = new List<FirewallRule>();
public bool PowerOff = false;
public NetworkDevice(NetworkComponentType what, string tHostname, Point tLocation, NicType firstNic = NicType.eth) public NetworkDevice(NetworkComponentType what, string tHostname, Point tLocation, NicType firstNic = NicType.eth)
{ {
@ -384,6 +385,9 @@ namespace EduNetworkBuilder
case "morphcolor": case "morphcolor":
MorphColor = Color.FromName(Individual.InnerText); MorphColor = Color.FromName(Individual.InnerText);
break; break;
case "poweroff":
bool.TryParse(Individual.InnerText, out PowerOff);
break;
} }
} }
} }
@ -404,6 +408,8 @@ namespace EduNetworkBuilder
writer.WriteElementString("hasadvfirewall", HasAdvFirewall.ToString()); writer.WriteElementString("hasadvfirewall", HasAdvFirewall.ToString());
if (MorphColor != Color.Empty) if (MorphColor != Color.Empty)
writer.WriteElementString("morphcolor", MorphColor.Name); writer.WriteElementString("morphcolor", MorphColor.Name);
if(PowerOff == true)
writer.WriteElementString("poweroff", PowerOff.ToString());
DefaultGW.Save(writer, "gateway"); DefaultGW.Save(writer, "gateway");
foreach (NetworkCard nic in NICs) foreach (NetworkCard nic in NICs)
{ {
@ -648,11 +654,23 @@ namespace EduNetworkBuilder
{ {
//double magnitude = 1 / 3d * (data[i] + data[i + 1] + data[i + 2]); //double magnitude = 1 / 3d * (data[i] + data[i + 1] + data[i + 2]);
if (PowerOff)
{
byte bcol = data[i];
byte gcol = data[i + 1];
byte rcol = data[i + 2];
//Check to see if it is green. If so, we make it mostly not-green.
if (rcol == 70 && gcol == 217 && bcol == 31)
data[i + 1] = 0; //set green to none
}
//data[i] is the first of 3 bytes of color //data[i] is the first of 3 bytes of color
if (MorphColor != Color.Empty)
{
data[i] = (byte)((data[i] + MorphColor.B) / 2); data[i] = (byte)((data[i] + MorphColor.B) / 2);
data[i + 1] = (byte)((data[i + 1] + MorphColor.G) / 2); data[i + 1] = (byte)((data[i + 1] + MorphColor.G) / 2);
data[i + 2] = (byte)((data[i + 2] + MorphColor.R) / 2); data[i + 2] = (byte)((data[i + 2] + MorphColor.R) / 2);
} }
}
/* This override copies the data back into the location specified */ /* This override copies the data back into the location specified */
System.Runtime.InteropServices.Marshal.Copy(data, 0, bData.Scan0, data.Length); System.Runtime.InteropServices.Marshal.Copy(data, 0, bData.Scan0, data.Length);
@ -969,53 +987,10 @@ namespace EduNetworkBuilder
Network myNet = NB.GetNetwork(); Network myNet = NB.GetNetwork();
myNet.Invalidate(Location); myNet.Invalidate(Location);
} }
if(MorphColor == Color.Empty) if(MorphColor == Color.Empty && PowerOff == false)
Graphics.FromImage(BaseImage).DrawImage(MyImage, MyLocation.X, MyLocation.Y, Size, Size); Graphics.FromImage(BaseImage).DrawImage(MyImage, MyLocation.X, MyLocation.Y, Size, Size);
else else
{ {
//ColorMap colorMap = new ColorMap();
//int width = MyImage.Width;
//int height = MyImage.Height;
//colorMap.OldColor = Color.FromArgb(33,39,63); // opaque red
//colorMap.NewColor = MorphColor; // opaque blue
//ColorMap[] remapTable = { colorMap };
//ImageAttributes imageAttributes = new ImageAttributes();
//imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);
//using (Graphics G = Graphics.FromImage(BaseImage))
//{
// G.DrawImage(
// MyImage,
// new Rectangle(MyLocation.X, MyLocation.Y, Size, Size), // destination rectangle
// 0, 0, // upper-left corner of source rectangle
// width, // width of source rectangle
// height, // height of source rectangle
// GraphicsUnit.Pixel,
// imageAttributes);
//}
//---------------------------
//Color color = MorphColor; //Your desired colour
//Bitmap bmp = new Bitmap(MyImage);
//for (int x = 0; x < bmp.Width; x++)
//{
// for (int y = 0; y < bmp.Height; y++)
// {
// int a = 0;
// int r = 0;
// int g = 0;
// int b = 0;
// Color gotColor = bmp.GetPixel(x, y);
// a = gotColor.A;
// r = (gotColor.R + color.R) / 2;
// g = (gotColor.G + color.G) / 2;
// b = (gotColor.B + color.B) / 2;
// gotColor = Color.FromArgb(a, r, g, b);
// bmp.SetPixel(x, y, gotColor);
// }
//}
//Graphics.FromImage(BaseImage).DrawImage(bmp, MyLocation.X, MyLocation.Y, Size, Size);
//------------------------------------
Image NewBMP = ColoredImage(MyImage); Image NewBMP = ColoredImage(MyImage);
Graphics.FromImage(BaseImage).DrawImage(NewBMP, MyLocation.X, MyLocation.Y, Size, Size); Graphics.FromImage(BaseImage).DrawImage(NewBMP, MyLocation.X, MyLocation.Y, Size, Size);
} }
@ -2428,6 +2403,15 @@ namespace EduNetworkBuilder
tPacket.MyStatus = PacketStatus.processing; tPacket.MyStatus = PacketStatus.processing;
// //
if(PowerOff)
{
//A packet came in, but the power was off on the device.
tPacket.AddMessage(DebugLevel.info, NB.Translate("ND_DoInputFromLink_PowerOff"));
tPacket.Tracking.Status = NB.LeftPad(hostname) + " " + string.Format(NB.Translate("ND_DoInputFromLink_PowerOff"));
tPacket.MyStatus = PacketStatus.finished_failed;
return;
}
tPacket.PacketDump(hostname, DebugPausePoint.packet_in); tPacket.PacketDump(hostname, DebugPausePoint.packet_in);
if(nc == null) if(nc == null)
{ {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -1637,4 +1637,16 @@
<value>Firewall Dropped Packet: Device {0}</value> <value>Firewall Dropped Packet: Device {0}</value>
<comment>P_FirewallDropped = Firewall Dropped Packet: Device {0}</comment> <comment>P_FirewallDropped = Firewall Dropped Packet: Device {0}</comment>
</data> </data>
<data name="NB_PowerOff" xml:space="preserve">
<value>Power Off</value>
<comment>NB_PowerOff = Power Off</comment>
</data>
<data name="NB_PowerOn" xml:space="preserve">
<value>Power On</value>
<comment>NB_PowerOn = Power On</comment>
</data>
<data name="ND_DoInputFromLink_PowerOff" xml:space="preserve">
<value>Device cannot respond - Packet Failed</value>
<comment>ND_DoInputFromLink_PowerOff = Device cannot respond - Packet Failed</comment>
</data>
</root> </root>