diff --git a/NetMonitorClient/Form1.cs b/NetMonitorClient/Form1.cs index ce4f188..4b2947b 100644 --- a/NetMonitorClient/Form1.cs +++ b/NetMonitorClient/Form1.cs @@ -12,12 +12,12 @@ namespace NetMonitorClient { public partial class Netzmonitor : Form { - private ServiceControl sc; + private NetMonitorUtils.NetworkSetter sc; public Netzmonitor() { InitializeComponent(); InitNetworks(); - this.sc = new ServiceControl("NetMonitorServer"); + this.sc = new NetMonitorUtils.NetworkSetter("network.ini","config.ini"); } private void Netzmonitor_Resize(object sender, System.EventArgs e) diff --git a/NetMonitorClient/NetMonitorClient.csproj b/NetMonitorClient/NetMonitorClient.csproj index b2e4ae1..4041811 100644 --- a/NetMonitorClient/NetMonitorClient.csproj +++ b/NetMonitorClient/NetMonitorClient.csproj @@ -10,7 +10,7 @@ Properties NetMonitorClient NetMonitorClient - v3.5 + v4.5 512 @@ -31,16 +31,18 @@ false false true + true full false - E:\Programme\NetMonitor\ + ..\bin\Debug\ DEBUG;TRACE prompt 4 AllRules.ruleset + false pdbonly @@ -50,6 +52,7 @@ prompt 4 AllRules.ruleset + false @@ -105,6 +108,7 @@ Resources.resx True + SettingsSingleFileGenerator @@ -139,6 +143,16 @@ + + + {fac8ce64-bf13-4ece-8097-aeb5dd060098} + Utils + + + {45ee003d-5572-48fe-b90e-6bfe18d9eec8} + NetMonitorUtils + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/NetMonitorTray/ClassDiagram1.cd b/NetMonitorTray/ClassDiagram1.cd new file mode 100644 index 0000000..3e72e82 --- /dev/null +++ b/NetMonitorTray/ClassDiagram1.cd @@ -0,0 +1,66 @@ + + + + + + ACAAAAAAIAAAAAAIAgEAAAAAAAAAAAIIBEAAAAAAAAI= + Controller\ControllerTray.cs + + + + + + gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIIAAAAAAAAAAg= + Controller\ControllerWindow.cs + + + + + + AAAAAAAAAAAAgAAwAAAAABAAAAQAAAIAAAAAIAAEAAg= + Models\ModelTray.cs + + + + + + AAAIAAAAAAAAAAAAAAIAAAAAAAAAAAIgAAQAAAAAACA= + Models\ModelWindow.cs + + + + + + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAA= + Program.cs + + + + + + SAACCAAAAAACAAAAEAgBEAAAAQAAAAAAAAAAAAAAAIA= + + + + + + AAhAQIAAACAAAAAAEAAMAAAEAACAAAIAAAgAAAAEAAQ= + Views\ViewTray.cs + + + + + + AQAAAAAAACAAAAAAAAAAAAAAAAAAAAIAAAgAAAAEAAA= + Views\ViewWindow.cs + + + + + + AAEAAAAACCAAABAAAACAEAECAwAAAAACACAAIIAIBAE= + Views\ViewWindowForm.cs + + + + \ No newline at end of file diff --git a/NetMonitorTray/Controller/ControllerTray.cs b/NetMonitorTray/Controller/ControllerTray.cs new file mode 100644 index 0000000..c3431d7 --- /dev/null +++ b/NetMonitorTray/Controller/ControllerTray.cs @@ -0,0 +1,140 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using NetMonitorUtils; +using BlubbFish.Utils; + +namespace NetMonitorTray.Controller { + public class Tray : OwnController { + private static View.Tray tray; + private static OpenVpnSetter vpn; + private static NetworkSetter network; + private static Controller.Window window; + /// + /// Tray Controller + /// + public Tray() { + vpn = new OpenVpnSetter("vpn.ini", "config.ini"); + network = new NetworkSetter("network.ini", "config.ini"); + } + /// + /// Init! + /// + override protected void init() { + tray = new View.Tray(); + window = new Controller.Window(); + tray.setWorkingIcon(); + try { + tray.Model.connectedStatus = false; + List vpns = tray.Model.getVpnList(); + tray.Model.VpnSelected = vpn.getStatus(vpns); + List adapter = tray.Model.getAdapterList(); + tray.Model.NetworkSelected = network.getNetwork(adapter); + } catch(Exception e) { + tray.showError(e.Message); + tray.Model.connectedStatus = false; + } + } + /// + /// User klickt auf den Eintrag Beenden + /// + /// + /// + internal static void Click_Quit(object sender, EventArgs e) { + tray.Dispose(); + //Application.ExitThread(); + Application.Exit(); + } + /// + /// User klick auf einen Eintrag Service Starten/Stoppen + /// + /// + /// + internal static void Click_Vpn(object sender, EventArgs e) { + tray.setWorkingIcon(); + + string[] conf = ((ToolStripMenuItem)sender).Name.Split('|'); + switch(tray.Model.VpnSelected[conf[1]]) { + case "disconnected": + case "unknown": + try { + vpn.setStart(conf[1]); + for(int i = 0; i < 10; i++) { + string status = vpn.getStatus(conf[1]); + if(status.StartsWith("[connected|")) { + tray.Model.VpnSelected[conf[1]] = "connected"; + status = status.Substring(0, status.Length - 1).Substring(1); + string[] ip = status.Split('|'); + tray.setVpn(true, "Verbunden am: " + ip[5] + "\nmit IP: " + ip[1] + "\nConfig: " + conf[1]); + break; + } + System.Threading.Thread.Sleep(3000); + } + } catch(Exception ex) { + tray.Model.connectedStatus = false; + tray.showError("Fehler beim starten von Openvpn mit " + conf[1] + ": " + ex.Message); + } + break; + case "connected": + try { + vpn.setStop(conf[1]); + for(int i = 0; i < 10; i++) { + string status = vpn.getStatus(conf[1]); + if(status == "[disconnected]") { + tray.Model.VpnSelected[conf[1]] = "disconnected"; + tray.setVpn(false, "Config: " + conf[1]); + break; + } + System.Threading.Thread.Sleep(1000); + } + } catch(Exception ex) { + tray.Model.connectedStatus = false; + tray.showError("Fehler beim beenden von Openvpn mit " + conf + ": " + ex.Message); + } + break; + } + } + /// + /// User klickt Doppelt auf das TrayIcon + /// + /// + /// + internal static void Click_Tray(object sender, EventArgs e) { + Click_Open(sender, e); + } + /// + /// User klickt auf den Tray-Ballon + /// + /// + /// + internal static void Click_Ballon(object sender, EventArgs e) { + throw new NotImplementedException(); + } + /// + /// User klickt auf einen Eintrag Netzwerk + /// + /// + /// + internal static void Click_Network(object sender, EventArgs e) { + tray.setWorkingIcon(); + try { + network.setNetwork(((ToolStripMenuItem)sender).Name); + string n = ((ToolStripMenuItem)sender).Name; + tray.Model.NetworkSelected[n.Split('|')[0]] = n.Split('|')[1]; + } catch(Exception ex) { + tray.showError("Fehler beim setzen des Netzwerks: " + ex.Message); + } + } + /// + /// User klickt auf den Eintrag Öffnen + /// + /// + /// + internal static void Click_Open(object sender, EventArgs e) { + window.execute(); + } + } +} diff --git a/NetMonitorTray/Controller/ControllerWindow.cs b/NetMonitorTray/Controller/ControllerWindow.cs new file mode 100644 index 0000000..4d8f225 --- /dev/null +++ b/NetMonitorTray/Controller/ControllerWindow.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using NetMonitorUtils; +using BlubbFish.Utils; + +namespace NetMonitorTray.Controller +{ + public class Window : OwnController + { + private static View.Window window; + /// + /// Tray Controller + /// + public Window() + { + + } + + override protected void init() + { + window = new View.Window(); + } + + public static void FormClosed(object sender, FormClosedEventArgs e) + { + window.Dispose(); + } + + internal static void NetworkSelected(object sender, EventArgs e) + { + MessageBox.Show("Angeklickt!"); + } + } +} diff --git a/NetMonitorTray/Controller/Tray.cs b/NetMonitorTray/Controller/Tray.cs deleted file mode 100644 index a3a1497..0000000 --- a/NetMonitorTray/Controller/Tray.cs +++ /dev/null @@ -1,84 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace NetMonitorTray.Controller -{ - public class Tray - { - private static View.Tray tray; - public Tray() - { - tray = new View.Tray(); - } - public void view() - { - Application.Run(); - } - /// - /// User klickt auf den Eintrag Beenden - /// - /// - /// - internal static void Click_Quit(object sender, EventArgs e) - { - tray.Dispose(); - Application.ExitThread(); - } - /// - /// User klick auf einen Eintrag Service Starten/Stoppen - /// - /// - /// - internal static void Click_Service(object sender, EventArgs e) - { - throw new NotImplementedException(); - //tray.showError("Fehler beim Starten/Stoppen von Service!"); - /*switch (((ToolStripMenuItem)sender).Name) - { - case "StartService": tray.setService(true); break; - case "StopService": tray.setService(false); break; - }*/ - } - /// - /// User klickt Doppelt auf das TrayIcon - /// - /// - /// - internal static void Click_Tray(object sender, EventArgs e) - { - //Doppelklick auf das Trayicon - throw new NotImplementedException(); - } - /// - /// User klickt auf den Tray-Ballon - /// - /// - /// - internal static void Click_Ballon(object sender, EventArgs e) - { - throw new NotImplementedException(); - } - /// - /// User klickt auf einen Eintrag Netzwerk - /// - /// - /// - internal static void Click_Network(object sender, EventArgs e) - { - throw new NotImplementedException(); - } - /// - /// User klickt auf den Eintrag Öffnen - /// - /// - /// - internal static void Click_Open(object sender, EventArgs e) - { - throw new NotImplementedException(); - } - } -} diff --git a/NetMonitorTray/Models/ModelTray.cs b/NetMonitorTray/Models/ModelTray.cs new file mode 100644 index 0000000..1d27644 --- /dev/null +++ b/NetMonitorTray/Models/ModelTray.cs @@ -0,0 +1,104 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using NetMonitorTray.Properties; +using BlubbFish.Utils; + +namespace NetMonitorTray.Models { + public class Tray : OwnModel { + private InIReader networks; + private InIReader vpns; + private Tray() { + this.init(); + } + + override protected void init() { + this.networks = InIReader.getInstance("network.ini"); + this.vpns = InIReader.getInstance("vpn.ini"); + } + + internal Dictionary>> getMenuNetwork() { + Dictionary>> ret = new Dictionary>>(); + List l = this.networks.getSections(); + foreach(String name in l) { + String adapter = this.networks.getValue(name, "Adapter"); + if(ret.Keys.Contains(adapter)) { + ret[adapter].Add(adapter + "|" + name, new Tuple("Netzwerk " + this.networks.getValue(name, "Name"), Properties.Resources.MenuImagesNetwork, true, (this.NetworkSelected.Keys.Contains(adapter) && this.NetworkSelected[adapter] == name))); + } else { + Dictionary> tmp = new Dictionary>(); + tmp.Add(adapter + "|" + name, new Tuple("Netzwerk " + this.networks.getValue(name, "Name"), Properties.Resources.MenuImagesNetwork, true, (this.NetworkSelected.Keys.Contains(adapter) && this.NetworkSelected[adapter] == name))); + ret.Add(adapter, tmp); + } + } + return ret; + } + + internal Dictionary>> getMenuVpn() { + Dictionary>> ret = new Dictionary>>(); + List l = this.vpns.getSections(); + Dictionary> tmp = new Dictionary>(); + + foreach(String vpn in l) { + String name = this.vpns.getValue(vpn, "Name"); + String conf = this.vpns.getValue(vpn, "Config"); + tmp.Add(vpn + "|" + conf, new Tuple("VPN " + name, Properties.Resources.MenuImagesOpenvpn, true, (this.VpnSelected.Keys.Contains(conf) && this.VpnSelected[conf] == "connected"))); + + } + ret.Add("OpenVpn", tmp); + return ret; + } + + private bool connectedStatusValue = false; + internal bool connectedStatus { + get { return connectedStatusValue; } + set { connectedStatusValue = value; this.update(); } + } + + private Dictionary VpnSelectedValue = new Dictionary(); + /// + /// Item1 = configfile + /// Item2 = status ("unknown";"connected";"disconnected") + /// + internal Dictionary VpnSelected { + get { return VpnSelectedValue; } + set { VpnSelectedValue = value; this.update(); } + } + + private Dictionary networkSelectedValue = new Dictionary(); + /// + /// Item1 = adapter + /// Item2 = network + /// + public Dictionary NetworkSelected { + get { return networkSelectedValue; } + set { networkSelectedValue = value; this.update(); } + } + + internal List getAdapterList() { + List ret = new List(); + List l = this.networks.getSections(); + foreach(String name in l) { + String adapter = this.networks.getValue(name, "Adapter"); + if(!ret.Contains(adapter)) { + ret.Add(adapter); + } + } + return ret; + } + + internal List getVpnList() { + List ret = new List(); + List l = this.vpns.getSections(); + foreach(String name in l) { + String adapter = this.vpns.getValue(name, "Config"); + if(!ret.Contains(adapter)) { + ret.Add(adapter); + } + } + return ret; + } + } +} diff --git a/NetMonitorTray/Models/ModelWindow.cs b/NetMonitorTray/Models/ModelWindow.cs new file mode 100644 index 0000000..eb0aa1f --- /dev/null +++ b/NetMonitorTray/Models/ModelWindow.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using NetMonitorTray.Properties; +using BlubbFish.Utils; + +namespace NetMonitorTray.Models +{ + public class Window : OwnModel + { + private InIReader networkfile; + private Window() + { + this.init(); + } + + override protected void init() + { + this.networkfile = InIReader.getInstance("network.ini"); + } + + /// + /// Listet alle Netzwerke auf + /// + public List Networks + { + get { return this.networkfile.getSections(); } + } + + public string getNetworkProperty(string network, string property) + { + return this.networkfile.getValue(network, property); + } + + /// + /// Fügt ein neues Netzwerk hinzu + /// + /// Netzwerkid + /// true if added, false if error + public bool addNetwork(string name) + { + if (this.networkfile.addSection(name)) + { + this.update(); + return true; + } + return false; + } + + /// + /// Löscht ein Netzwerk + /// + /// Netzwerkid + /// true if deleted, false if error + public bool removeNetwork(string name) + { + if (this.networkfile.removeSection(name)) + { + this.update(); + return true; + } + return false; + } + } +} diff --git a/NetMonitorTray/Models/Tray.cs b/NetMonitorTray/Models/Tray.cs deleted file mode 100644 index 3865643..0000000 --- a/NetMonitorTray/Models/Tray.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using NetMonitorTray.Properties; -using BlubbFish.Utils; - -namespace NetMonitorTray.Model -{ - public class Tray : OwnModel - { - private bool serviceRun; - private Tray() - { - this.init(); - } - private void init() - { - this.serviceRun = false; - } - - internal Dictionary> getMenuNetwork() - { - Dictionary> ret = new Dictionary>(); - ret.Add("network1", new Tuple("Netzwerk Home", null, true, false)); - ret.Add("network2", new Tuple("Netzwerk Arbeit", null, true, false)); - ret.Add("network3", new Tuple("Netzwerk Test", null, true, false)); - return ret; - } - - internal Dictionary> getMenuOpenVpnService() - { - Dictionary> ret = new Dictionary>(); - ret.Add("StartService", new Tuple("Service Starten", Properties.Resources.MenuImagesServerConnect, !this.serviceRun, !this.serviceRun)); - ret.Add("StopService", new Tuple("Service Stoppen", Properties.Resources.MenuImagesServerDisconnect, this.serviceRun, this.serviceRun)); - return ret; - } - - public void setService(bool run) - { - this.serviceRun = run; - this.update(); - } - - - } -} diff --git a/NetMonitorTray/NetMonitorTray.csproj b/NetMonitorTray/NetMonitorTray.csproj index b259e84..8639863 100644 --- a/NetMonitorTray/NetMonitorTray.csproj +++ b/NetMonitorTray/NetMonitorTray.csproj @@ -5,7 +5,7 @@ Debug AnyCPU {0B85C838-3295-4FDA-9B07-4F5B3681BE2F} - Exe + WinExe Properties NetMonitorTray NetMonitorTray @@ -52,8 +52,10 @@ - - + + + + @@ -61,13 +63,22 @@ True Resources.resx - + + Form + + + ViewWindowForm.cs + + + + + @@ -77,14 +88,23 @@ ResXFileCodeGenerator Resources.Designer.cs + + ViewWindowForm.cs + {fac8ce64-bf13-4ece-8097-aeb5dd060098} Utils + + {45ee003d-5572-48fe-b90e-6bfe18d9eec8} + NetMonitorUtils + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + \ No newline at end of file diff --git a/NetMonitorUtils/NetMonitorUtils.csproj b/NetMonitorUtils/NetMonitorUtils.csproj index ec2bade..2a68251 100644 --- a/NetMonitorUtils/NetMonitorUtils.csproj +++ b/NetMonitorUtils/NetMonitorUtils.csproj @@ -46,6 +46,7 @@ + @@ -53,6 +54,17 @@ Utils + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + +