diff --git a/Service/Plugins/ZeroKey.Plugin.Lock/LockWorkstation.cs b/Service/Plugins/ZeroKey.Plugin.Lock/LockWorkstation.cs index a4f2723..819d11d 100644 --- a/Service/Plugins/ZeroKey.Plugin.Lock/LockWorkstation.cs +++ b/Service/Plugins/ZeroKey.Plugin.Lock/LockWorkstation.cs @@ -33,9 +33,19 @@ public void NcfRingDown(string id, Dictionary parameters, System try { // Check if User is currently running medatixx Client + Process[] pname = Process.GetProcessesByName("Client.UI"); + if (pname.Length != 0) + { + Debug.WriteLine("Running medatixx Plugin (ignore lock) ..."); + string appDir = AppContext.BaseDirectory; + ProcessAsUser.Launch($"{appDir}\\medatixx\\ZeroKey.Plugin.medatixx.exe -c {id} -s"); + } + else + { + ProcessAsUser.Launch(@"C:\WINDOWS\system32\rundll32.exe user32.dll,LockWorkStation"); + Process.Start(@"C:\WINDOWS\system32\rundll32.exe", "user32.dll,LockWorkStation"); + } - string appDir = AppContext.BaseDirectory; - ProcessAsUser.Launch($"{appDir}\\medatixx\\ZeroKey.Plugin.medatixx.exe -c {id} -s"); // System.Threading.Thread.Sleep(8000); // ProcessAsUser.Launch(@"C:\WINDOWS\system32\rundll32.exe user32.dll,LockWorkStation"); } diff --git a/Service/ZeroKey.ServerUI/MainWindow.xaml.cs b/Service/ZeroKey.ServerUI/MainWindow.xaml.cs index 4cf45de..57d33e2 100644 --- a/Service/ZeroKey.ServerUI/MainWindow.xaml.cs +++ b/Service/ZeroKey.ServerUI/MainWindow.xaml.cs @@ -7,7 +7,7 @@ using System.Diagnostics; using System.IO; using Newtonsoft.Json; -using SuperSimpleTcp; +using WatsonTcp; using Wpf.Ui.Common; using Clipboard = System.Windows.Clipboard; @@ -19,21 +19,18 @@ namespace ZeroKey.ServerUI public partial class MainWindow : Window { private static bool _dark = true; - private SimpleTcpServer server; + private WatsonTcpServer server; - public static List AvailableUsers = new List(); + private string ip = GetLocalIpAddress(); + private int port = 9000; public MainWindow() { InitializeComponent(); - // Set server info - string ip = GetLocalIpAddress(); - int port = 9000; - if (ip != "No IPv4 address in the System!") { - server = new SimpleTcpServer($"{ip}:{port}"); + server = new WatsonTcpServer(ip,port); Console.WriteLine($"Listening on {ip}:{port}"); } else @@ -45,7 +42,7 @@ public MainWindow() // Set events server.Events.ClientConnected += ClientConnected; server.Events.ClientDisconnected += ClientDisconnected; - server.Events.DataReceived += DataReceived; + server.Events.MessageReceived += MessageReceived; Wpf.Ui.Appearance.Theme.Apply( Wpf.Ui.Appearance.ThemeType.Dark, // Theme type @@ -59,7 +56,7 @@ public MainWindow() #region Server Events - void ClientConnected(object sender, SuperSimpleTcp.ConnectionEventArgs e) + void ClientConnected(object sender, WatsonTcp.ConnectionEventArgs e) { Dispatcher.BeginInvoke(new Action(delegate { @@ -67,10 +64,9 @@ void ClientConnected(object sender, SuperSimpleTcp.ConnectionEventArgs e) RootSnackbar.Icon = SymbolRegular.Person24; RootSnackbar.Show("Connected", $"New Connection with \"{e.IpPort}\"."); })); - AvailableUsers.Add(e.IpPort); } - void ClientDisconnected(object sender, SuperSimpleTcp.ConnectionEventArgs e) + void ClientDisconnected(object sender, WatsonTcp.DisconnectionEventArgs e) { Dispatcher.BeginInvoke(new Action(delegate { @@ -78,18 +74,11 @@ void ClientDisconnected(object sender, SuperSimpleTcp.ConnectionEventArgs e) RootSnackbar.Icon = SymbolRegular.ArrowExit20; RootSnackbar.Show("Connected", $"Client \"{e.IpPort}\" disconnected: {e.Reason}"); })); - - try - { - int index = AvailableUsers.IndexOf(e.IpPort); - AvailableUsers.RemoveAt(index); - } - catch {; } } - void DataReceived(object sender, SuperSimpleTcp.DataReceivedEventArgs e) + void MessageReceived(object sender, WatsonTcp.MessageReceivedEventArgs e) { - string message = Encoding.UTF8.GetString(e.Data.Array, 0, e.Data.Count); + string message = Encoding.UTF8.GetString(e.Data); switch (message) { @@ -98,13 +87,35 @@ void DataReceived(object sender, SuperSimpleTcp.DataReceivedEventArgs e) Debug.WriteLine("[{0}] Got request command from client... sending config...", DateTime.Now); // Send configuration to user - if (!File.Exists("Application.config")) - server.Send(e.IpPort, "null"); - else + try + { + if (!File.Exists("Application.config")) + server.Send(e.IpPort, "null"); + else + { + server.Send(e.IpPort, File.ReadAllText("Application.config")); + //if (File.Exists("medatixx.json")) im.SendMessage(e.From, File.ReadAllText("medatixx.json")); + } + } + catch (TimeoutException) { - server.Send(e.IpPort, File.ReadAllText("Application.config")); - //if (File.Exists("medatixx.json")) im.SendMessage(e.From, File.ReadAllText("medatixx.json")); + Dispatcher.BeginInvoke(new Action(delegate + { + RootSnackbar.Appearance = ControlAppearance.Danger; + RootSnackbar.Icon = SymbolRegular.Warning24; + RootSnackbar.Show("Timeout", $"Failed to send config to client \"{e.IpPort}\"."); + })); + } + catch (Exception ex) + { + Dispatcher.BeginInvoke(new Action(delegate + { + RootSnackbar.Appearance = ControlAppearance.Danger; + RootSnackbar.Icon = SymbolRegular.Warning24; + RootSnackbar.Show("Error", $"Failed to send config to client \"{e.IpPort}\". {ex.Message}"); + })); } + break; } @@ -128,6 +139,8 @@ void DataReceived(object sender, SuperSimpleTcp.DataReceivedEventArgs e) if (charObj == "2") IsConfig = 2; + IEnumerable clients = server.ListClients(); + switch (IsConfig) { default: @@ -140,9 +153,9 @@ void DataReceived(object sender, SuperSimpleTcp.DataReceivedEventArgs e) Debug.WriteLine("[{0}] Got configuration from client... writing config...", DateTime.Now); File.WriteAllText("Application.config", message); Debug.WriteLine("[{0}] New configuration saved. Contacting all clients now ...", DateTime.Now); - foreach (string user in AvailableUsers) + foreach (string user in clients) { - server.Send(user, parseConfig); + server.Send(user, message); Debug.WriteLine("[{0}] Send config to {1}", DateTime.Now, user); } @@ -155,7 +168,7 @@ void DataReceived(object sender, SuperSimpleTcp.DataReceivedEventArgs e) Debug.WriteLine("[{0}] Got medatixx configuration from client... writing config...", DateTime.Now); File.WriteAllText("medatixx.json", message); Debug.WriteLine("[{0}] New configuration saved. Contacting all clients now ...", DateTime.Now); - foreach (string user in AvailableUsers) + foreach (string user in clients) { server.Send(user, message); Debug.WriteLine("[{0}] Send config to {1}", DateTime.Now, user); @@ -227,6 +240,8 @@ private void ToggleSwitchOn_Click(object sender, RoutedEventArgs e) } catch (Exception ex) { MessageBox.Show("Cannot start server: " + $"\n{ex.Message}"); } + TbIp.Text = $"{ip}:{port}"; + ResetPwBtn.IsEnabled = false; ClearUserBtn.IsEnabled = false; ClearBtn.IsEnabled = false; diff --git a/Service/ZeroKey.ServerUI/ZeroKey.ServerUI.csproj b/Service/ZeroKey.ServerUI/ZeroKey.ServerUI.csproj index 8573424..5306510 100644 --- a/Service/ZeroKey.ServerUI/ZeroKey.ServerUI.csproj +++ b/Service/ZeroKey.ServerUI/ZeroKey.ServerUI.csproj @@ -20,9 +20,9 @@ - - + + diff --git a/Service/ZeroKeyServiceCore/ServiceCore.cs b/Service/ZeroKeyServiceCore/ServiceCore.cs index f38106d..bb125c7 100644 --- a/Service/ZeroKeyServiceCore/ServiceCore.cs +++ b/Service/ZeroKeyServiceCore/ServiceCore.cs @@ -8,11 +8,12 @@ using System.Threading; using ZeroKey.Service.Common; using System.IO; +using System.Linq.Expressions; using System.Net.Sockets; using System.Net; using Newtonsoft.Json; using System.Management; -using SuperSimpleTcp; +using WatsonTcp; using ZeroKey.Libraries; namespace ZeroKey.Service.Core @@ -32,7 +33,7 @@ public class ServiceCore private TcpListener _registrationListener; private Thread _registrationListenThread; - SimpleTcpClient client; + WatsonTcpClient client; private int trys = 0; private bool IsConnected = false; private bool GotConfig = false; @@ -289,6 +290,7 @@ public void Start() _readerThread.Start(); _state = ServiceState.Running; Log("Core started"); + Debug.WriteLine("Service is now ready."); } private void InitialiseNetwork() @@ -618,22 +620,23 @@ private void UpdateFriendlyName(NetworkMessage networkMessage) SaveConfig(); } - private void LoginOK(object sender, SuperSimpleTcp.ConnectionEventArgs e) + private void ServerConnected(object sender, WatsonTcp.ConnectionEventArgs e) { Debug.WriteLine("Login successful."); IsConnected = true; } - private void Disconnected(object sender, SuperSimpleTcp.ConnectionEventArgs e) + private void ServerDisconnected(object sender, WatsonTcp.DisconnectionEventArgs e) { Debug.WriteLine("Disconnected."); IsConnected = false; } - private void DataReceived(object sender, SuperSimpleTcp.DataReceivedEventArgs e) + private void MessageReceived(object sender, WatsonTcp.MessageReceivedEventArgs e) { - if (e.Data.Array == null) return; - string message = Encoding.UTF8.GetString(e.Data.Array, 0, e.Data.Count); + if (e.Data == null) return; + + string message = Encoding.UTF8.GetString(e.Data); Debug.WriteLine("Got response from server... sync file now..."); @@ -692,10 +695,10 @@ private bool LoadConfig() if (!String.IsNullOrEmpty(ip)) { - client = new SimpleTcpClient($"{ip}:{port}"); - client.Events.Connected += LoginOK; - client.Events.Disconnected += Disconnected; - client.Events.DataReceived += DataReceived; + client = new WatsonTcpClient(ip, port); + client.Events.ServerConnected += ServerConnected; + client.Events.ServerDisconnected += ServerDisconnected; + client.Events.MessageReceived += MessageReceived; client.Connect(); Debug.WriteLine("Login requested!"); @@ -784,7 +787,7 @@ private bool RequestLogin() if (!String.IsNullOrEmpty(ip)) { - client = new SimpleTcpClient($"{ip}:{port}"); + client = new WatsonTcpClient(ip, port); client.Connect(); Debug.WriteLine("Login requested!"); diff --git a/Service/ZeroKeyServiceCore/ZeroKey.Service.Core.csproj b/Service/ZeroKeyServiceCore/ZeroKey.Service.Core.csproj index c27e630..769ed4b 100644 --- a/Service/ZeroKeyServiceCore/ZeroKey.Service.Core.csproj +++ b/Service/ZeroKeyServiceCore/ZeroKey.Service.Core.csproj @@ -80,8 +80,8 @@ 13.0.1 - - 3.0.0 + + 4.8.14.14 diff --git a/Setup/Scripts/Script.iss b/Setup/Scripts/Script.iss index 3801414..ecbbe45 100644 --- a/Setup/Scripts/Script.iss +++ b/Setup/Scripts/Script.iss @@ -76,6 +76,8 @@ Source: "..\..\bin\Release\Service\ZeroKeyServiceHost.exe.config"; DestDir: {#Se Source: "..\..\bin\Release\Service\Newtonsoft.Json.dll"; DestDir: {#ServiceAppPath}; Flags: ignoreversion Source: "..\..\bin\Release\Service\ZeroKeyServiceCommon.dll"; DestDir: {#ServiceAppPath}; Flags: ignoreversion Source: "..\..\bin\Release\Service\ZeroKeyServiceCore.dll"; DestDir: {#ServiceAppPath}; Flags: ignoreversion +Source: "..\..\bin\Release\Service\WatsonTcp.dll"; DestDir: {#ServiceAppPath}; Flags: ignoreversion +Source: "..\..\bin\Release\Service\Rijndael256.dll"; DestDir: {#ServiceAppPath}; Flags: ignoreversion Source: "..\..\bin\Release\Service\ZeroKeyServiceHost.exe"; DestDir: {#ServiceAppPath}; Flags: ignoreversion; \ BeforeInstall: TaskKill('ZeroKeyServiceHost.exe') diff --git a/Setup/Scripts/Server.iss b/Setup/Scripts/Server.iss index 8dfd2ac..6b96ef8 100644 --- a/Setup/Scripts/Server.iss +++ b/Setup/Scripts/Server.iss @@ -25,7 +25,6 @@ ArchitecturesInstallIn64BitMode=x64 OutputDir=..\Result OutputBaseFilename={#MyAppName}_{#GitCommitHash}_{#MyAppVersion} - CloseApplications=force Compression=lzma SolidCompression=yes @@ -46,7 +45,7 @@ Source: "..\..\bin\Release\ServerUI\ZeroKey.ServerUI.exe"; DestDir: {app}; Flags ; Application files Source: "..\..\bin\Release\ServerUI\Newtonsoft.Json.dll"; DestDir: {app}; Flags: ignoreversion Source: "server.pfx"; DestDir: {app}; Flags: ignoreversion -Source: "..\..\bin\Release\ServerUI\SuperSimpleTcp.dll"; DestDir: {app}; Flags: ignoreversion +Source: "..\..\bin\Release\ServerUI\WatsonTcp.dll"; DestDir: {app}; Flags: ignoreversion Source: "..\..\bin\Release\ServerUI\System.ServiceProcess.ServiceController.dll"; DestDir: {app}; Flags: ignoreversion Source: "..\..\bin\Release\ServerUI\Wpf.Ui.dll"; DestDir: {app}; Flags: ignoreversion Source: "..\..\bin\Release\ServerUI\ZeroKey.ServerUI.deps.json"; DestDir: {app}; Flags: ignoreversion diff --git a/UI/ZeroKey.UI.View/Resources/StringResources.de-DE.xaml b/UI/ZeroKey.UI.View/Resources/StringResources.de-DE.xaml index 82ddaa6..c3333f1 100644 --- a/UI/ZeroKey.UI.View/Resources/StringResources.de-DE.xaml +++ b/UI/ZeroKey.UI.View/Resources/StringResources.de-DE.xaml @@ -24,7 +24,7 @@ Lokale Autorisierung Serverseitige Autorisierung - + Fertig! Du kannst nun deine Karte zum Sperren und Entsperren deines PC's verwenden. Lege einfach deine Karte auf das Lesegerät. Auf der nächsten Seite können Sie auch weitere Karten für andere Benutzer hinzufügen oder den Zugang sperren.