diff --git a/.gitignore b/.gitignore index cbc77e0..5b09bcb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.DS_Store .idea +Installation ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. diff --git a/README.md b/README.md index f606beb..4d903bd 100644 --- a/README.md +++ b/README.md @@ -1 +1,5 @@ -https://www.flaticon.com/free-icon/vpn_188120 \ No newline at end of file +## SoftEther VPN Client + + + +https://www.flaticon.com/free-icon/vpn_188120 diff --git a/src/Logixware.SoftEther.Client.Core/Logixware.SoftEther.Client.Core.csproj b/src/Logixware.SoftEther.Client.Core/Logixware.SoftEther.Client.Core.csproj index 3152a56..c17931c 100644 --- a/src/Logixware.SoftEther.Client.Core/Logixware.SoftEther.Client.Core.csproj +++ b/src/Logixware.SoftEther.Client.Core/Logixware.SoftEther.Client.Core.csproj @@ -29,8 +29,8 @@ Copyright © 2017 - CURRENT_YEAR Tobias Punke. - - + + diff --git a/src/Logixware.SoftEther.Client.Core/Logixware/SoftEther/Client/LoggerExtensions.cs b/src/Logixware.SoftEther.Client.Core/Logixware/SoftEther/Client/LoggerExtensions.cs index b17fe25..ae88ef7 100644 --- a/src/Logixware.SoftEther.Client.Core/Logixware/SoftEther/Client/LoggerExtensions.cs +++ b/src/Logixware.SoftEther.Client.Core/Logixware/SoftEther/Client/LoggerExtensions.cs @@ -6,6 +6,11 @@ namespace Logixware.SoftEther.Client { public static class LoggerExtensions { + public static void Debug(this ILogger target, String message) + { + target.Log(LogLevel.Debug, 1, message, null, (s, e) => DateTime.Now + " " + s.ToString()); + } + public static void Inform(this ILogger target, String message) { target.Log(LogLevel.Information, 1, message, null, (s, e) => DateTime.Now + " " + s.ToString()); diff --git a/src/Logixware.SoftEther.Client.Core/Logixware/SoftEther/Client/Shell/Platform/BashShell.cs b/src/Logixware.SoftEther.Client.Core/Logixware/SoftEther/Client/Shell/Platform/BashShell.cs index b4f44d7..0456daf 100644 --- a/src/Logixware.SoftEther.Client.Core/Logixware/SoftEther/Client/Shell/Platform/BashShell.cs +++ b/src/Logixware.SoftEther.Client.Core/Logixware/SoftEther/Client/Shell/Platform/BashShell.cs @@ -4,7 +4,6 @@ namespace Logixware.SoftEther.Client.Shell.Platform { - public class BashShell : IShell { public ExecutionResult ExecuteCommand(String command) diff --git a/src/Logixware.SoftEther.Client.Core/Logixware/SoftEther/Client/VpnService/CommandLineInterface.cs b/src/Logixware.SoftEther.Client.Core/Logixware/SoftEther/Client/VpnService/CommandLineInterface.cs index 3243a6e..a0de275 100644 --- a/src/Logixware.SoftEther.Client.Core/Logixware/SoftEther/Client/VpnService/CommandLineInterface.cs +++ b/src/Logixware.SoftEther.Client.Core/Logixware/SoftEther/Client/VpnService/CommandLineInterface.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Threading; +using System.Threading.Tasks; using System.Collections.Generic; using Microsoft.Extensions.Logging; @@ -102,12 +103,12 @@ public void StartClient() if (__StartExecution.Succeeded) { var __Message = $"Successfully started the VPN client: {__StartExecution.Result}"; - this._Logger.Inform(__Message); + this._Logger?.Inform(__Message); } else { var __Message = $"Error starting the VPN client: {__StartExecution.Result}"; - this._Logger.Error(__Message); + this._Logger?.Error(__Message); } } @@ -119,12 +120,12 @@ public void StopClient() if (__StopExecution.Succeeded) { var __Message = $"Successfully stopped the VPN client: {__StopExecution.Result}"; - this._Logger.Inform(__Message); + this._Logger?.Inform(__Message); } else { var __Message = $"Error stopping the VPN client: {__StopExecution.Result}"; - this._Logger.Error(__Message); + this._Logger?.Error(__Message); } } diff --git a/src/Logixware.SoftEther.Client.Core/Logixware/SoftEther/Client/VpnService/ICommandLineInterface.cs b/src/Logixware.SoftEther.Client.Core/Logixware/SoftEther/Client/VpnService/ICommandLineInterface.cs index 44ec202..ffd34a4 100644 --- a/src/Logixware.SoftEther.Client.Core/Logixware/SoftEther/Client/VpnService/ICommandLineInterface.cs +++ b/src/Logixware.SoftEther.Client.Core/Logixware/SoftEther/Client/VpnService/ICommandLineInterface.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using System.Collections.Generic; namespace Logixware.SoftEther.Client.VpnService diff --git a/src/Logixware.SoftEther.Client.Core/Properties/AssemblyInfo/AssemblyInfo.cs b/src/Logixware.SoftEther.Client.Core/Properties/AssemblyInfo/AssemblyInfo.cs index d11105b..998250d 100755 --- a/src/Logixware.SoftEther.Client.Core/Properties/AssemblyInfo/AssemblyInfo.cs +++ b/src/Logixware.SoftEther.Client.Core/Properties/AssemblyInfo/AssemblyInfo.cs @@ -10,7 +10,7 @@ [assembly: System.Reflection.AssemblyCopyright("Copyright © 2017 - 2018 Tobias Punke.")] [assembly: System.Reflection.AssemblyVersion("1.0.0.0")] -[assembly: System.Reflection.AssemblyFileVersion("1.0.0.5")] -[assembly: System.Reflection.AssemblyInformationalVersion("1.0.0.5")] +[assembly: System.Reflection.AssemblyFileVersion("1.0.0.11")] +[assembly: System.Reflection.AssemblyInformationalVersion("1.0.0.11")] diff --git a/src/Logixware.SoftEther.Client.Core/Properties/AssemblyInfo/AssemblyVersion.txt b/src/Logixware.SoftEther.Client.Core/Properties/AssemblyInfo/AssemblyVersion.txt index 090eef7..6cb4627 100755 --- a/src/Logixware.SoftEther.Client.Core/Properties/AssemblyInfo/AssemblyVersion.txt +++ b/src/Logixware.SoftEther.Client.Core/Properties/AssemblyInfo/AssemblyVersion.txt @@ -1 +1 @@ -1.0.0.5 \ No newline at end of file +1.0.0.11 \ No newline at end of file diff --git a/src/Logixware.SoftEther.Client.Daemon/Logixware.SoftEther.Client.Daemon.csproj b/src/Logixware.SoftEther.Client.Daemon/Logixware.SoftEther.Client.Daemon.csproj index f9fa799..b303540 100644 --- a/src/Logixware.SoftEther.Client.Daemon/Logixware.SoftEther.Client.Daemon.csproj +++ b/src/Logixware.SoftEther.Client.Daemon/Logixware.SoftEther.Client.Daemon.csproj @@ -38,15 +38,15 @@ - - - - - - - - - + + + + + + + + + diff --git a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/ClientConfigurationSection.cs b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Configuration/ClientConfigurationSection.cs similarity index 74% rename from src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/ClientConfigurationSection.cs rename to src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Configuration/ClientConfigurationSection.cs index 1a57441..5833473 100644 --- a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/ClientConfigurationSection.cs +++ b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Configuration/ClientConfigurationSection.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; -namespace Logixware.SoftEther.Client.Daemon +using Logixware.SoftEther.Client.Daemon.Entities; + +namespace Logixware.SoftEther.Client.Daemon.Configuration { public class ClientConfigurationSection { diff --git a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Platform/MacPlatformConfigurationSection.cs b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Configuration/MacPlatformConfigurationSection.cs similarity index 73% rename from src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Platform/MacPlatformConfigurationSection.cs rename to src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Configuration/MacPlatformConfigurationSection.cs index f0551d2..ad69366 100644 --- a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Platform/MacPlatformConfigurationSection.cs +++ b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Configuration/MacPlatformConfigurationSection.cs @@ -1,6 +1,6 @@ using System; -namespace Logixware.SoftEther.Client.Daemon.Platform +namespace Logixware.SoftEther.Client.Daemon.Configuration { public class MacPlatformConfigurationSection { diff --git a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/IPv4Information.cs b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Entities/IPv4Information.cs similarity index 82% rename from src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/IPv4Information.cs rename to src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Entities/IPv4Information.cs index 901b5ae..4cc4172 100644 --- a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/IPv4Information.cs +++ b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Entities/IPv4Information.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace Logixware.SoftEther.Client.Daemon +namespace Logixware.SoftEther.Client.Daemon.Entities { // ReSharper disable once InconsistentNaming public class IPv4Information diff --git a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/IPv4Route.cs b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Entities/IPv4Route.cs similarity index 84% rename from src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/IPv4Route.cs rename to src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Entities/IPv4Route.cs index 16f7b24..e1145fd 100644 --- a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/IPv4Route.cs +++ b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Entities/IPv4Route.cs @@ -1,6 +1,6 @@ using System; -namespace Logixware.SoftEther.Client.Daemon +namespace Logixware.SoftEther.Client.Daemon.Entities { // ReSharper disable once InconsistentNaming public class IPv4Route diff --git a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/IPv6Information.cs b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Entities/IPv6Information.cs similarity index 82% rename from src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/IPv6Information.cs rename to src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Entities/IPv6Information.cs index e5704e9..d203bbf 100644 --- a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/IPv6Information.cs +++ b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Entities/IPv6Information.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace Logixware.SoftEther.Client.Daemon +namespace Logixware.SoftEther.Client.Daemon.Entities { // ReSharper disable once InconsistentNaming public class IPv6Information diff --git a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/IPv6Route.cs b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Entities/IPv6Route.cs similarity index 84% rename from src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/IPv6Route.cs rename to src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Entities/IPv6Route.cs index 1c151a0..dbccc70 100644 --- a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/IPv6Route.cs +++ b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Entities/IPv6Route.cs @@ -1,6 +1,6 @@ using System; -namespace Logixware.SoftEther.Client.Daemon +namespace Logixware.SoftEther.Client.Daemon.Entities { // ReSharper disable once InconsistentNaming public class IPv6Route diff --git a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/VirtualNetwork.cs b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Entities/VirtualNetwork.cs similarity index 87% rename from src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/VirtualNetwork.cs rename to src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Entities/VirtualNetwork.cs index e388453..9823b6a 100644 --- a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/VirtualNetwork.cs +++ b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Entities/VirtualNetwork.cs @@ -1,6 +1,6 @@ using System; -namespace Logixware.SoftEther.Client.Daemon +namespace Logixware.SoftEther.Client.Daemon.Entities { public class VirtualNetwork { diff --git a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Program.cs b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Hosting/Program.cs similarity index 54% rename from src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Program.cs rename to src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Hosting/Program.cs index 27e2542..a162a8c 100644 --- a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Program.cs +++ b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Hosting/Program.cs @@ -1,20 +1,12 @@ using System; using System.IO; using System.Threading.Tasks; -using System.Runtime.InteropServices; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Logixware.SoftEther.Client.VpnService; -using Logixware.SoftEther.Client.Daemon.Platform; - -using Logixware.SoftEther.Client.Shell; -using Logixware.SoftEther.Client.Shell.Platform; - -namespace Logixware.SoftEther.Client.Daemon +namespace Logixware.SoftEther.Client.Daemon.Hosting { public class Program { @@ -30,6 +22,7 @@ public static async Task Main(String[] args) configHost.SetBasePath(Directory.GetCurrentDirectory()); configHost.AddJsonFile("hostsettings.json", optional: true); configHost.AddEnvironmentVariables(prefix: "PREFIX_"); + configHost.ConfigureHostConfiguration(); configHost.AddCommandLine(args); }) @@ -38,6 +31,7 @@ public static async Task Main(String[] args) configApp.AddJsonFile("appsettings.json", optional: true); configApp.AddJsonFile($"appsettings.{hostContext.HostingEnvironment.EnvironmentName}.json", optional: true); configApp.AddEnvironmentVariables(prefix: "PREFIX_"); + configApp.ConfigureAppConfiguration(hostContext); configApp.AddCommandLine(args); __ConfigurationRoot = configApp.Build(); @@ -45,29 +39,7 @@ public static async Task Main(String[] args) .ConfigureServices((hostContext, services) => { - services.AddLogging(); - services.AddHostedService(); - services.AddSingleton(services); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - - services.AddSingleton(__ConfigurationRoot); - - if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) - { - services.AddSingleton(); - services.AddSingleton(); - } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - { - services.AddSingleton(); - services.AddSingleton(); - } - else - { - throw new NotSupportedException("Platform not supported."); - } + services.ConfigureServices(__ConfigurationRoot); }) .ConfigureLogging((hostContext, configLogging) => diff --git a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Hosting/ProgramCollectionExtensions.cs b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Hosting/ProgramCollectionExtensions.cs new file mode 100644 index 0000000..365c710 --- /dev/null +++ b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Hosting/ProgramCollectionExtensions.cs @@ -0,0 +1,81 @@ +using System; +using System.Runtime.InteropServices; + +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; + +using Logixware.SoftEther.Client.Shell; +using Logixware.SoftEther.Client.Shell.Platform; +using Logixware.SoftEther.Client.VpnService; + +using Logixware.SoftEther.Client.Daemon.Services; + +namespace Logixware.SoftEther.Client.Daemon.Hosting +{ + internal static class ProgramCollectionExtensions + { + internal static void ConfigureHostConfiguration(this IConfigurationBuilder configHost) + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + configHost.AddJsonFile("/Library/Preferences/Logixware/Logixware.SoftEther.Client.Daemon/hostsettings.json", optional: true); + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + configHost.AddJsonFile("/etc/logixware/Logixware.SoftEther.Client.Daemon/hostsettings.json", optional: true); + } + else + { + throw new NotSupportedException("Platform not supported."); + } + } + + internal static void ConfigureAppConfiguration(this IConfigurationBuilder configApp, HostBuilderContext hostContext) + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + configApp.AddJsonFile("/Library/Preferences/Logixware/Logixware.SoftEther.Client.Daemon/appsettings.json", optional: true); + configApp.AddJsonFile($"/Library/Preferences/Logixware/Logixware.SoftEther.Client.Daemon/appsettings.{hostContext.HostingEnvironment.EnvironmentName}.json", optional: false); + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + configApp.AddJsonFile("/etc/logixware/Logixware.SoftEther.Client.Daemon/appsettings.json", optional: true); + configApp.AddJsonFile($"/etc/logixware/Logixware.SoftEther.Client.Daemon/appsettings.{hostContext.HostingEnvironment.EnvironmentName}.json", optional: true); + } + else + { + throw new NotSupportedException("Platform not supported."); + } + } + + internal static void ConfigureServices(this IServiceCollection services, IConfigurationRoot configurationRoot) + { + services.AddSingleton(services); + services.AddSingleton(configurationRoot); + + services.AddHostedService(); + + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + services.AddSingleton(); + services.AddSingleton(); + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + services.AddSingleton(); + services.AddSingleton(); + } + else + { + throw new NotSupportedException("Platform not supported."); + } + } + } +} \ No newline at end of file diff --git a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Hosting/ProgramService.cs b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Hosting/ProgramService.cs new file mode 100644 index 0000000..3ccf3ea --- /dev/null +++ b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Hosting/ProgramService.cs @@ -0,0 +1,61 @@ +using System; + +using System.Threading; +using System.Threading.Tasks; + +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +using Logixware.SoftEther.Client.Daemon.Services; + +namespace Logixware.SoftEther.Client.Daemon.Hosting +{ + public class ProgramService : IHostedService + { + private readonly ILogger _Logger; + private readonly IApplicationLifetime _AppLifetime; + private readonly IClientService _ClientService; + + public ProgramService + ( + ILogger logger, + IApplicationLifetime appLifetime, + IClientService nasService + ) + { + this._Logger = logger ?? throw new ArgumentNullException(nameof(logger)); + this._AppLifetime = appLifetime ?? throw new ArgumentNullException(nameof(appLifetime)); + this._ClientService = nasService ?? throw new ArgumentNullException(nameof(nasService)); + } + + public async Task StartAsync(CancellationToken cancellationToken) + { + this._AppLifetime.ApplicationStarted.Register(this.OnStarted); + this._AppLifetime.ApplicationStopping.Register(this.OnStopping); + this._AppLifetime.ApplicationStopped.Register(this.OnStopped); + + await this._ClientService.StartAsync(cancellationToken); + } + + public async Task StopAsync(CancellationToken cancellationToken) + { + this._Logger.Inform("Shutting down application..."); + await this._ClientService.StopAsync(cancellationToken); + } + + private void OnStarted() + { + this._Logger.Inform("Starting application..."); + } + + private void OnStopping() + { + this._Logger.Inform("Shutting down application..."); + } + + private void OnStopped() + { + this._Logger.Inform("Application shut down. C ya."); + } + } +} diff --git a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/IConnectionVerifier.cs b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/IConnectionVerifier.cs deleted file mode 100644 index aafe753..0000000 --- a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/IConnectionVerifier.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System; - -namespace Logixware.SoftEther.Client.Daemon -{ - public interface IConnectionVerifier - { - ConnectionVerificationResult Verify(String host); - } -} \ No newline at end of file diff --git a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/ReachableResult.cs b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/ReachableResult.cs index 0fc7f6f..a5f87ec 100644 --- a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/ReachableResult.cs +++ b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/ReachableResult.cs @@ -1,5 +1,7 @@ using System; +using Logixware.SoftEther.Client.Daemon.Services; + namespace Logixware.SoftEther.Client.Daemon { public struct ReachableResult diff --git a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/ClientConfiguration.cs b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/ClientConfiguration.cs similarity index 97% rename from src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/ClientConfiguration.cs rename to src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/ClientConfiguration.cs index 2f14f1b..8a360e0 100644 --- a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/ClientConfiguration.cs +++ b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/ClientConfiguration.cs @@ -8,7 +8,10 @@ using Logixware.SoftEther.Client.VpnService; -namespace Logixware.SoftEther.Client.Daemon +using Logixware.SoftEther.Client.Daemon.Entities; +using Logixware.SoftEther.Client.Daemon.Configuration; + +namespace Logixware.SoftEther.Client.Daemon.Services { public class ClientConfiguration : IClientConfiguration { diff --git a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/ProgramService.cs b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/ClientService.cs similarity index 63% rename from src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/ProgramService.cs rename to src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/ClientService.cs index f10259b..ccb1055 100644 --- a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/ProgramService.cs +++ b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/ClientService.cs @@ -13,16 +13,17 @@ using Logixware.SoftEther.Client.VpnService; -namespace Logixware.SoftEther.Client.Daemon +namespace Logixware.SoftEther.Client.Daemon.Services { - public class ProgramService : IHostedService + public class ClientService : IClientService, IDisposable { - private readonly ILogger _Logger; + private readonly ILogger _Logger; private readonly ILogger _NetworkLogger; private readonly IApplicationLifetime _AppLifetime; private readonly IClientConfiguration _Configuration; private readonly ICommandLineInterface _Cli; - private readonly IConnectionVerifier _ConnectionVerifier; + private readonly IVpnConnectionVerifier _VpnConnectionVerifier; + private readonly IInternetConnectionVerifier _InternetConnectionVerifierVerifier; private readonly IPlatform _Platform; private readonly Subject _ClientServiceRestarting; @@ -30,27 +31,30 @@ public class ProgramService : IHostedService private readonly Dictionary _Networks; private Boolean? _IsInternetConnected; - private Boolean _Run; - private Timer _Timer; + private CancellationTokenSource _RunCancellationTokenSource; + private Boolean _IsRunning; + private Task _RunTask; - public ProgramService + public ClientService ( - ILogger logger, - ILogger networklogger, + ILogger logger, + ILogger networkLogger, IApplicationLifetime appLifetime, IClientConfiguration configuration, ICommandLineInterface cli, - IConnectionVerifier connectionVerifier, + IInternetConnectionVerifier internetConnectionVerifierVerifier, + IVpnConnectionVerifier vpnConnectionVerifier, IPlatform platform ) { this._Logger = logger ?? throw new ArgumentNullException(nameof(logger)); - this._NetworkLogger = networklogger ?? throw new ArgumentNullException(nameof(networklogger)); + this._NetworkLogger = networkLogger ?? throw new ArgumentNullException(nameof(networkLogger)); this._AppLifetime = appLifetime ?? throw new ArgumentNullException(nameof(appLifetime)); this._Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); this._Cli = cli ?? throw new ArgumentNullException(nameof(cli)); - this._ConnectionVerifier = connectionVerifier ?? throw new ArgumentNullException(nameof(connectionVerifier)); + this._InternetConnectionVerifierVerifier = internetConnectionVerifierVerifier ?? throw new ArgumentNullException(nameof(internetConnectionVerifierVerifier)); + this._VpnConnectionVerifier = vpnConnectionVerifier ?? throw new ArgumentNullException(nameof(vpnConnectionVerifier)); this._Platform = platform ?? throw new ArgumentNullException(nameof(platform)); this._ClientServiceRestarting = new Subject(); @@ -58,45 +62,41 @@ IPlatform platform this._Networks = new Dictionary(); this._IsInternetConnected = null; - this._Run = false; } public Task StartAsync(CancellationToken cancellationToken) { - this._AppLifetime.ApplicationStarted.Register(this.OnStarted); - this._AppLifetime.ApplicationStopping.Register(this.OnStopping); - this._AppLifetime.ApplicationStopped.Register(this.OnStopped); + if (this._IsRunning) + { + throw new InvalidOperationException("Service is already running."); + } - return Task.CompletedTask; - } + this._IsRunning = true; + this._RunCancellationTokenSource = new CancellationTokenSource(); - private void OnStarted() - { - this._Logger.Inform("Starting application..."); + this._Logger?.Inform("Initializing platform."); + this._Platform.Initialize(); + + this._Logger?.Inform("Starting VPN client service..."); + this._Cli.StartClient(); var __ValidNetworks = this._Configuration.GetValidNetworks(this._Cli).ToList(); if (__ValidNetworks.Count == 0) { - this._Logger.Critical("No valid network found."); + this._Logger?.Critical("No valid network found."); this._AppLifetime.StopApplication(); - return; + return Task.CompletedTask; } - this._Logger.Inform("Initializing platform."); - this._Platform.Initialize(); - - this._Logger.Inform("Starting VPN client service..."); - this._Cli.StartClient(); - foreach (var __Network in __ValidNetworks) { this._Networks.Add(new VirtualNetworkService( this._NetworkLogger, this._Cli, - this._ConnectionVerifier, + this._VpnConnectionVerifier, this._Platform, this._ClientServiceRestarting, this._ClientServiceRestarted, @@ -105,35 +105,28 @@ private void OnStarted() ), 0); } - this._Run = true; - this._Timer = new Timer(this.Run, null, TimeSpan.Zero, Timeout.InfiniteTimeSpan); - } - - private async void Run(Object parameter) - { - while (this._Run) + this._RunTask = Task.Run(async () => { - await this.TickAsync(parameter).ConfigureAwait(false); - Thread.Sleep(5000); - } - } + while (true) + { + await this.TickAsync(this._RunCancellationTokenSource.Token); + await Task.Delay(TimeSpan.FromSeconds(5), this._RunCancellationTokenSource.Token); + } - private async Task TickAsync(Object parameter) - { - if (!this._Run) - { - this._Timer.Dispose(); - this._AppLifetime.StopApplication(); + // ReSharper disable once FunctionNeverReturns + }, this._RunCancellationTokenSource.Token); - return; - } + return Task.CompletedTask; + } - if (await InternetConnection.IsAvailibleAsync(this._Configuration.Settings.InternetConnectionTestUrl).ConfigureAwait(false)) + private async Task TickAsync(CancellationToken cancellationToken) + { + if (await this._InternetConnectionVerifierVerifier.IsAvailableAsync(this._Configuration.Settings.InternetConnectionTestUrl).ConfigureAwait(false)) { if (this._IsInternetConnected == null || !(Boolean) this._IsInternetConnected) { this._IsInternetConnected = true; - this._Logger.Inform("Connected to the internet"); + this._Logger?.Inform("Connected to the internet"); } var __Results = new List(); @@ -184,7 +177,7 @@ private async Task TickAsync(Object parameter) __NonReachableServices.ForEach(r => { - this._Logger.Error($"VPN \"{r.Network.Configuration.Name}\": Connection test host \"{r.Network.Configuration.ConnectionTestHost}\" did not respond {this._Networks[r.Network]} times."); + this._Logger?.Error($"VPN \"{r.Network.Configuration.Name}\": Connection test host \"{r.Network.Configuration.ConnectionTestHost}\" did not respond {this._Networks[r.Network]} times."); }); if (__ReachableServices.Count == 0 && __DisconnectedServices.Count == 0) @@ -201,7 +194,7 @@ private async Task TickAsync(Object parameter) if (this._IsInternetConnected == null || (Boolean) this._IsInternetConnected) { this._IsInternetConnected = false; - this._Logger.Inform("Not connected to the internet"); + this._Logger?.Inform("Not connected to the internet"); } this.ResetAttemptCounters(this._Networks.Keys); @@ -218,7 +211,7 @@ private void ResetAttemptCounters(IEnumerable items) private void RestartClientService() { - this._Logger.Warn("Restarting the VPN client..."); + this._Logger?.Warn("Restarting the VPN client..."); this._ClientServiceRestarting.OnNext(null); @@ -228,36 +221,29 @@ private void RestartClientService() this._ClientServiceRestarted.OnNext(null); } - public Task StopAsync(CancellationToken cancellationToken) + public async Task StopAsync(CancellationToken cancellationToken) { - this._Logger.Inform("Shutting down application..."); - this._Run = false; + if (!this._IsRunning) + { + throw new InvalidOperationException("Service not running."); + } - return Task.CompletedTask; - } + this._RunCancellationTokenSource.Cancel(); + this._IsRunning = false; - private void OnStopping() - { - this._Logger.Inform("Stoppping VPN client service..."); this._Cli.StopClient(); + + if (this._RunTask != null && this._RunTask.Status == TaskStatus.Running) + { + await this._RunTask; + } } - private void OnStopped() + public void Dispose() { - this._Logger.Inform("Application shut down. C ya."); + this._ClientServiceRestarting?.Dispose(); + this._ClientServiceRestarted?.Dispose(); + this._RunCancellationTokenSource?.Dispose(); } - -// private Task Sleep(int millisecondsTimeout) -// { -// var taskCompletionSource = new TaskCompletionSource(); -// -// ThreadPool.QueueUserWorkItem((state) => -// { -// Thread.Sleep(millisecondsTimeout); -// taskCompletionSource.SetResult(true); -// }, null); -// -// return taskCompletionSource.Task; -// } } } diff --git a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/IClientConfiguration.cs b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/IClientConfiguration.cs similarity index 61% rename from src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/IClientConfiguration.cs rename to src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/IClientConfiguration.cs index 8209b46..66d8805 100644 --- a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/IClientConfiguration.cs +++ b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/IClientConfiguration.cs @@ -2,7 +2,10 @@ using Logixware.SoftEther.Client.VpnService; -namespace Logixware.SoftEther.Client.Daemon +using Logixware.SoftEther.Client.Daemon.Entities; +using Logixware.SoftEther.Client.Daemon.Configuration; + +namespace Logixware.SoftEther.Client.Daemon.Services { public interface IClientConfiguration { diff --git a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/IClientService.cs b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/IClientService.cs new file mode 100644 index 0000000..759a37e --- /dev/null +++ b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/IClientService.cs @@ -0,0 +1,11 @@ +using System.Threading; +using System.Threading.Tasks; + +namespace Logixware.SoftEther.Client.Daemon.Services +{ + public interface IClientService + { + Task StartAsync(CancellationToken cancellationToken); + Task StopAsync(CancellationToken cancellationToken); + } +} \ No newline at end of file diff --git a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/IInternetConnectionVerifier.cs b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/IInternetConnectionVerifier.cs new file mode 100644 index 0000000..e14b134 --- /dev/null +++ b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/IInternetConnectionVerifier.cs @@ -0,0 +1,11 @@ +using System; +using System.Threading.Tasks; + +namespace Logixware.SoftEther.Client.Daemon.Services +{ + public interface IInternetConnectionVerifier + { + Boolean IsAvailable(String url); + Task IsAvailableAsync(String url); + } +} \ No newline at end of file diff --git a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/IPlatform.cs b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/IPlatform.cs similarity index 89% rename from src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/IPlatform.cs rename to src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/IPlatform.cs index 08d901f..ccfb464 100644 --- a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/IPlatform.cs +++ b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/IPlatform.cs @@ -1,9 +1,9 @@ -using System; using System.Net.NetworkInformation; using Logixware.SoftEther.Client.Shell; +using Logixware.SoftEther.Client.Daemon.Entities; -namespace Logixware.SoftEther.Client.Daemon +namespace Logixware.SoftEther.Client.Daemon.Services { public interface IPlatform { diff --git a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/IVpnConnectionVerifier.cs b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/IVpnConnectionVerifier.cs new file mode 100644 index 0000000..fc69bf1 --- /dev/null +++ b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/IVpnConnectionVerifier.cs @@ -0,0 +1,9 @@ +using System; + +namespace Logixware.SoftEther.Client.Daemon.Services +{ + public interface IVpnConnectionVerifier + { + ConnectionVerificationResult Verify(String host); + } +} \ No newline at end of file diff --git a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/InternetConnection.cs b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/InternetConnectionVerifier.cs similarity index 66% rename from src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/InternetConnection.cs rename to src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/InternetConnectionVerifier.cs index a9e8256..7e3f9fc 100644 --- a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/InternetConnection.cs +++ b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/InternetConnectionVerifier.cs @@ -2,11 +2,11 @@ using System.Net; using System.Threading.Tasks; -namespace Logixware.SoftEther.Client.Daemon +namespace Logixware.SoftEther.Client.Daemon.Services { - public class InternetConnection + public class InternetConnectionVerifier : IInternetConnectionVerifier { - public static Boolean IsAvailible(String url) + public Boolean IsAvailable(String url) { try { @@ -22,7 +22,7 @@ public static Boolean IsAvailible(String url) } } - public static async Task IsAvailibleAsync(String url) + public async Task IsAvailableAsync(String url) { try { diff --git a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/PingConnectionVerifier.cs b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/PingVpnConnectionVerifier.cs similarity index 83% rename from src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/PingConnectionVerifier.cs rename to src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/PingVpnConnectionVerifier.cs index 27b12a3..836b895 100644 --- a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/PingConnectionVerifier.cs +++ b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/PingVpnConnectionVerifier.cs @@ -2,13 +2,13 @@ using System.Text; using System.Net.NetworkInformation; -namespace Logixware.SoftEther.Client.Daemon +namespace Logixware.SoftEther.Client.Daemon.Services { - public class PingConnectionVerifier : IConnectionVerifier + public class PingVpnConnectionVerifier : IVpnConnectionVerifier { private IClientConfiguration _Configuration; - public PingConnectionVerifier(IClientConfiguration configuration) + public PingVpnConnectionVerifier(IClientConfiguration configuration) { this._Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); } diff --git a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Platform/LinuxPlatform.cs b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/Platform/LinuxPlatform.cs similarity index 96% rename from src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Platform/LinuxPlatform.cs rename to src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/Platform/LinuxPlatform.cs index 6592162..111bb6a 100644 --- a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Platform/LinuxPlatform.cs +++ b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/Platform/LinuxPlatform.cs @@ -6,7 +6,9 @@ using Logixware.SoftEther.Client.Shell; -namespace Logixware.SoftEther.Client.Daemon.Platform +using Logixware.SoftEther.Client.Daemon.Entities; + +namespace Logixware.SoftEther.Client.Daemon.Services { public class LinuxPlatform : IPlatform diff --git a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Platform/MacPlatform.cs b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/Platform/MacPlatform.cs similarity index 97% rename from src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Platform/MacPlatform.cs rename to src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/Platform/MacPlatform.cs index fd35e95..3ca353f 100644 --- a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Platform/MacPlatform.cs +++ b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/Platform/MacPlatform.cs @@ -2,16 +2,16 @@ using System.Threading; using System.Net.NetworkInformation; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Configuration; using Logixware.SoftEther.Client.Shell; -//using System.Runtime.InteropServices; +using Logixware.SoftEther.Client.Daemon.Entities; +using Logixware.SoftEther.Client.Daemon.Configuration; -namespace Logixware.SoftEther.Client.Daemon.Platform +namespace Logixware.SoftEther.Client.Daemon.Services { - public class MacPlatform : IPlatform { private readonly ILogger _Logger; diff --git a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/VirtualNetworkService.cs b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/VirtualNetworkService.cs similarity index 79% rename from src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/VirtualNetworkService.cs rename to src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/VirtualNetworkService.cs index fa47071..42815c3 100644 --- a/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/VirtualNetworkService.cs +++ b/src/Logixware.SoftEther.Client.Daemon/Logixware/SoftEther/Client/Daemon/Services/VirtualNetworkService.cs @@ -9,14 +9,15 @@ using Microsoft.Extensions.Logging; using Logixware.SoftEther.Client.VpnService; +using Logixware.SoftEther.Client.Daemon.Entities; -namespace Logixware.SoftEther.Client.Daemon +namespace Logixware.SoftEther.Client.Daemon.Services { public class VirtualNetworkService : IDisposable { private readonly ILogger _Logger; private readonly ICommandLineInterface _Cli; - private readonly IConnectionVerifier _ConnectionVerifier; + private readonly IVpnConnectionVerifier _VpnConnectionVerifier; private readonly IPlatform _Platform; private readonly Subject _IsDisposed; @@ -41,7 +42,7 @@ public VirtualNetworkService ( ILogger logger, ICommandLineInterface cli, - IConnectionVerifier connectionVerifier, + IVpnConnectionVerifier vpnConnectionVerifier, IPlatform platform, Subject clientServiceRestarting, Subject clientServiceRestarted, @@ -53,7 +54,7 @@ VirtualNetwork network this._Logger = logger ?? throw new ArgumentNullException(nameof(logger)); this._Cli = cli ?? throw new ArgumentNullException(nameof(cli)); - this._ConnectionVerifier = connectionVerifier ?? throw new ArgumentNullException(nameof(connectionVerifier)); + this._VpnConnectionVerifier = vpnConnectionVerifier ?? throw new ArgumentNullException(nameof(vpnConnectionVerifier)); this._Platform = platform ?? throw new ArgumentNullException(nameof(platform)); this.Configuration = network ?? throw new ArgumentNullException(nameof(network)); @@ -186,11 +187,11 @@ private void OnConfigurationStateChanged(ConfigurationState? state) { if (state == ConfigurationState.OK) { - this._Logger.Inform($"VPN \"{this.Configuration.Name}\": Interface configuration completed."); + this._Logger?.Inform($"VPN \"{this.Configuration.Name}\": Interface configuration completed."); } else { - this._Logger.Warn($"VPN \"{this.Configuration.Name}\": Interface configuration error."); + this._Logger?.Warn($"VPN \"{this.Configuration.Name}\": Interface configuration error."); } } @@ -198,12 +199,12 @@ private void OnConnectionStateChanged(ConnectionState? state) { if (state == ConnectionState.Connected) { - this._Logger.Inform($"VPN \"{this.Configuration.Name}\": Connection is established."); + this._Logger?.Inform($"VPN \"{this.Configuration.Name}\": Connection is established."); this.AssignIPAddresses(); } else { - this._Logger.Warn($"VPN \"{this.Configuration.Name}\": Connection is not established, State: \"{state}\"."); + this._Logger?.Warn($"VPN \"{this.Configuration.Name}\": Connection is not established, State: \"{state}\"."); this.ReleaseIPAddresses(); } } @@ -212,11 +213,11 @@ private void OnReachableStateChanged(ReachableState? state) { if (state == ReachableState.Reachable) { - this._Logger.Inform($"VPN \"{this.Configuration.Name}\": Network is reachable."); + this._Logger?.Inform($"VPN \"{this.Configuration.Name}\": Network is reachable."); } else { - this._Logger.Warn($"VPN \"{this.Configuration.Name}\": Network is not reachable."); + this._Logger?.Warn($"VPN \"{this.Configuration.Name}\": Network is not reachable."); } } @@ -224,11 +225,11 @@ private void OnAccountFoundChanged(Account value) { if (value != null) { - this._Logger.Inform($"VPN \"{this.Configuration.Name}\": Account found in the VPN client service."); + this._Logger?.Inform($"VPN \"{this.Configuration.Name}\": Account found in the VPN client service."); } else { - this._Logger.Warn($"VPN \"{this.Configuration.Name}\": Account not found in the VPN client service."); + this._Logger?.Warn($"VPN \"{this.Configuration.Name}\": Account not found in the VPN client service."); } } @@ -236,11 +237,11 @@ private void OnDeviceFoundChanged(Device value) { if (value != null) { - this._Logger.Inform($"VPN \"{this.Configuration.Name}\": Device \"{this._Account.Value?.DeviceName}\" in the VPN client service found."); + this._Logger?.Inform($"VPN \"{this.Configuration.Name}\": Device \"{this._Account.Value?.DeviceName}\" in the VPN client service found."); } else { - this._Logger.Warn($"VPN \"{this.Configuration.Name}\": Device \"{this._Account.Value?.DeviceName}\" in the VPN client service not found."); + this._Logger?.Warn($"VPN \"{this.Configuration.Name}\": Device \"{this._Account.Value?.DeviceName}\" in the VPN client service not found."); } } @@ -248,11 +249,11 @@ private void OnInterfaceFoundChanged(String value) { if (!String.IsNullOrEmpty(value)) { - this._Logger.Inform($"VPN \"{this.Configuration.Name}\": Interface \"{value} found."); + this._Logger?.Inform($"VPN \"{this.Configuration.Name}\": Interface \"{value} found."); } else { - this._Logger.Warn($"VPN \"{this.Configuration.Name}\": No interface for physical address \"{this._Device.Value?.PhysicalAddress}\" found."); + this._Logger?.Warn($"VPN \"{this.Configuration.Name}\": No interface for physical address \"{this._Device.Value?.PhysicalAddress}\" found."); } } @@ -262,12 +263,12 @@ private void OnIPv4AddressAssignedChanged(Boolean? value) if ((Boolean) value) { - this._Logger.Inform($"VPN \"{this.Configuration.Name}\": IP address \"{this.Configuration.IPv4.Address}\" assigned to adapter \"{this._InterfaceName.Value}\"."); + this._Logger?.Inform($"VPN \"{this.Configuration.Name}\": IP address \"{this.Configuration.IPv4.Address}\" assigned to adapter \"{this._InterfaceName.Value}\"."); this.AssignIPv4Routes(); } else { - this._Logger.Inform($"VPN \"{this.Configuration.Name}\": IP address \"{this.Configuration.IPv4.Address}\" released from adapter \"{this._InterfaceName.Value}\"."); + this._Logger?.Inform($"VPN \"{this.Configuration.Name}\": IP address \"{this.Configuration.IPv4.Address}\" released from adapter \"{this._InterfaceName.Value}\"."); this.ReleaseIPv4Routes(); } } @@ -275,7 +276,7 @@ private void OnIPv4AddressAssignedChanged(Boolean? value) private void OnIPv4AddressAssignmentError(Exception ex) { if (this.Configuration.IPv4 == null) return; - this._Logger.Error($"VPN \"{this.Configuration.Name}\": Error assigning or releasing IP address \"{this.Configuration.IPv4.Address}\" on adapter \"{this._InterfaceName.Value}\": {ex.Message}"); + this._Logger?.Error($"VPN \"{this.Configuration.Name}\": Error assigning or releasing IP address \"{this.Configuration.IPv4.Address}\" on adapter \"{this._InterfaceName.Value}\": {ex.Message}"); } private void OnIPv6AddressAssignedChanged(Boolean? value) @@ -284,12 +285,12 @@ private void OnIPv6AddressAssignedChanged(Boolean? value) if ((Boolean) value) { - this._Logger.Inform($"VPN \"{this.Configuration.Name}\": IP address \"{this.Configuration.IPv6.Address}/{this.Configuration.IPv6.Prefix}\" assigned to adapter \"{this._InterfaceName.Value}\"."); + this._Logger?.Inform($"VPN \"{this.Configuration.Name}\": IP address \"{this.Configuration.IPv6.Address}/{this.Configuration.IPv6.Prefix}\" assigned to adapter \"{this._InterfaceName.Value}\"."); this.AssignIPv6Routes(); } else { - this._Logger.Inform($"VPN \"{this.Configuration.Name}\": IP address \"{this.Configuration.IPv6.Address}/{this.Configuration.IPv6.Prefix}\" released from adapter \"{this._InterfaceName.Value}\"."); + this._Logger?.Inform($"VPN \"{this.Configuration.Name}\": IP address \"{this.Configuration.IPv6.Address}/{this.Configuration.IPv6.Prefix}\" released from adapter \"{this._InterfaceName.Value}\"."); this.ReleaseIPv6Routes(); } } @@ -297,7 +298,7 @@ private void OnIPv6AddressAssignedChanged(Boolean? value) private void OnIPv6AddressAssignmentError(Exception ex) { if (this.Configuration.IPv6 == null) return; - this._Logger.Error($"VPN \"{this.Configuration.Name}\": Error assigning or releasing IP address \"{this.Configuration.IPv6.Address}/{this.Configuration.IPv6.Prefix}\" on adapter \"{this._InterfaceName.Value}\": {ex.Message}"); + this._Logger?.Error($"VPN \"{this.Configuration.Name}\": Error assigning or releasing IP address \"{this.Configuration.IPv6.Address}/{this.Configuration.IPv6.Prefix}\" on adapter \"{this._InterfaceName.Value}\": {ex.Message}"); } private void OnIPv4RoutesAppliedChanged(Boolean? value) @@ -306,19 +307,19 @@ private void OnIPv4RoutesAppliedChanged(Boolean? value) if ((Boolean) value) { - this._Logger.Inform($"VPN \"{this.Configuration.Name}\": IPv4 routes assigned."); + this._Logger?.Inform($"VPN \"{this.Configuration.Name}\": IPv4 routes assigned."); this.AssignIPv6Routes(); } else { - this._Logger.Inform($"VPN \"{this.Configuration.Name}\": IPv4 routes released."); + this._Logger?.Inform($"VPN \"{this.Configuration.Name}\": IPv4 routes released."); this.ReleaseIPv6Routes(); } } private void OnIPv4RoutesAssignmentError(Exception ex) { - this._Logger.Error($"VPN \"{this.Configuration.Name}\": Error assigning or releasing IPv4 routes: {ex.Message}"); + this._Logger?.Error($"VPN \"{this.Configuration.Name}\": Error assigning or releasing IPv4 routes: {ex.Message}"); } private void OnIPv6RoutesAppliedChanged(Boolean? value) @@ -327,19 +328,19 @@ private void OnIPv6RoutesAppliedChanged(Boolean? value) if ((Boolean) value) { - this._Logger.Inform($"VPN \"{this.Configuration.Name}\": IPv6 routes assigned."); + this._Logger?.Inform($"VPN \"{this.Configuration.Name}\": IPv6 routes assigned."); this.AssignIPv6Routes(); } else { - this._Logger.Inform($"VPN \"{this.Configuration.Name}\": IPv6 routes released."); + this._Logger?.Inform($"VPN \"{this.Configuration.Name}\": IPv6 routes released."); this.ReleaseIPv6Routes(); } } private void OnIPv6RoutesAssignmentError(Exception ex) { - this._Logger.Error($"VPN \"{this.Configuration.Name}\": Error assigning or releasing IPv6 routes: {ex.Message}"); + this._Logger?.Error($"VPN \"{this.Configuration.Name}\": Error assigning or releasing IPv6 routes: {ex.Message}"); } private void OnConnectionVerificationResultChanged(ConnectionVerificationResult value) @@ -347,11 +348,11 @@ private void OnConnectionVerificationResultChanged(ConnectionVerificationResult if (value == null) return; if (value.Reachable == ReachableState.Reachable) { - this._Logger.Inform($"VPN \"{this.Configuration.Name}\": Connection test host \"{this.Configuration.ConnectionTestHost}\" successfully reached: \"{value.Details}\"."); + this._Logger?.Inform($"VPN \"{this.Configuration.Name}\": Connection test host \"{this.Configuration.ConnectionTestHost}\" successfully reached: \"{value.Details}\"."); } else { - this._Logger.Error($"VPN \"{this.Configuration.Name}\": Error reaching connection test host \"{this.Configuration.ConnectionTestHost}\": \"{value.Details}\"."); + this._Logger?.Error($"VPN \"{this.Configuration.Name}\": Error reaching connection test host \"{this.Configuration.ConnectionTestHost}\": \"{value.Details}\"."); } } @@ -388,7 +389,7 @@ public async Task IsReachableAsync() return await ReturnResult().ConfigureAwait(false); } - this._ConnectionVerificationResult.OnNext(this._ConnectionVerifier.Verify(this.Configuration.ConnectionTestHost)); + this._ConnectionVerificationResult.OnNext(this._VpnConnectionVerifier.Verify(this.Configuration.ConnectionTestHost)); this._ReachableState.OnNext(this._ConnectionVerificationResult.Value.Reachable); return await ReturnResult().ConfigureAwait(false); diff --git a/src/Logixware.SoftEther.Client.Daemon/Properties/AssemblyInfo/AssemblyInfo.cs b/src/Logixware.SoftEther.Client.Daemon/Properties/AssemblyInfo/AssemblyInfo.cs index 9c40d0e..8cd93d2 100755 --- a/src/Logixware.SoftEther.Client.Daemon/Properties/AssemblyInfo/AssemblyInfo.cs +++ b/src/Logixware.SoftEther.Client.Daemon/Properties/AssemblyInfo/AssemblyInfo.cs @@ -10,7 +10,7 @@ [assembly: System.Reflection.AssemblyCopyright("Copyright © 2017 - 2018 Tobias Punke.")] [assembly: System.Reflection.AssemblyVersion("1.0.0.0")] -[assembly: System.Reflection.AssemblyFileVersion("1.0.0.4")] -[assembly: System.Reflection.AssemblyInformationalVersion("1.0.0.4")] +[assembly: System.Reflection.AssemblyFileVersion("1.0.0.8")] +[assembly: System.Reflection.AssemblyInformationalVersion("1.0.0.8")] diff --git a/src/Logixware.SoftEther.Client.Daemon/Properties/AssemblyInfo/AssemblyVersion.txt b/src/Logixware.SoftEther.Client.Daemon/Properties/AssemblyInfo/AssemblyVersion.txt index df4e830..904927c 100755 --- a/src/Logixware.SoftEther.Client.Daemon/Properties/AssemblyInfo/AssemblyVersion.txt +++ b/src/Logixware.SoftEther.Client.Daemon/Properties/AssemblyInfo/AssemblyVersion.txt @@ -1 +1 @@ -1.0.0.4 \ No newline at end of file +1.0.1.18 \ No newline at end of file diff --git a/src/Logixware.SoftEther.Client.Daemon/appsettings.Development.json b/src/Logixware.SoftEther.Client.Daemon/appsettings.Development.json index f999bc2..1b9ebab 100644 --- a/src/Logixware.SoftEther.Client.Daemon/appsettings.Development.json +++ b/src/Logixware.SoftEther.Client.Daemon/appsettings.Development.json @@ -2,8 +2,8 @@ "Logging": { "LogLevel": { "Default": "Debug", - "System": "Information", - "Microsoft": "Information" + "System": "Debug", + "Microsoft": "Debug" } } } \ No newline at end of file diff --git a/src/Logixware.SoftEther.Client.Daemon/appsettings.Production.json b/src/Logixware.SoftEther.Client.Daemon/appsettings.Production.json index 302a911..eedb1ba 100644 --- a/src/Logixware.SoftEther.Client.Daemon/appsettings.Production.json +++ b/src/Logixware.SoftEther.Client.Daemon/appsettings.Production.json @@ -1,7 +1,7 @@ { "Logging": { "LogLevel": { - "Default": "Error", + "Default": "Information", "System": "Information", "Microsoft": "Information" } diff --git a/src/Logixware.SoftEther.Client.Daemon/appsettings.example.linux.json b/src/Logixware.SoftEther.Client.Daemon/appsettings.example.linux.json index f32db01..83681fe 100644 --- a/src/Logixware.SoftEther.Client.Daemon/appsettings.example.linux.json +++ b/src/Logixware.SoftEther.Client.Daemon/appsettings.example.linux.json @@ -3,7 +3,7 @@ { "LogLevel": { - "Default": "Warning" + "Default": "Information" } }, "AllowedHosts": "*", @@ -11,8 +11,8 @@ { "CommandLineInterface": { - "PathToClient": "/opt/logixware/Logixware.SoftEther.Client/vpnclient/vpnclient", - "PathToCli": "/opt/logixware/Logixware.SoftEther.Client/vpnclient/vpncmd", + "PathToClient": "/opt/softether/vpnclient/vpnclient", + "PathToCli": "/opt/softether/vpnclient/vpncmd", "CliPassword": "" }, diff --git a/src/Logixware.SoftEther.Client.Daemon/appsettings.example.macos.json b/src/Logixware.SoftEther.Client.Daemon/appsettings.example.macos.json index 0a51b11..278babf 100644 --- a/src/Logixware.SoftEther.Client.Daemon/appsettings.example.macos.json +++ b/src/Logixware.SoftEther.Client.Daemon/appsettings.example.macos.json @@ -3,7 +3,7 @@ { "LogLevel": { - "Default": "Warning" + "Default": "Information" } }, "AllowedHosts": "*", @@ -11,8 +11,8 @@ { "CommandLineInterface": { - "PathToClient": "/Applications/SoftEther VPN Client.app/Contents/Resources/vpnclient/vpnclient", - "PathToCli": "/Applications/SoftEther VPN Client.app/Contents/Resources/vpnclient/vpncmd", + "PathToClient": "/Library/Application Support/SoftEther/vpnclient/vpnclient", + "PathToCli": "/Library/Application Support/SoftEther/vpnclient/vpncmd", "CliPassword": "" }, diff --git a/src/Logixware.SoftEther.Client.Daemon/de.logixware.SoftEther.Client.Daemon.plist b/src/Logixware.SoftEther.Client.Daemon/de.logixware.SoftEther.Client.Daemon.plist index b280848..4079733 100755 --- a/src/Logixware.SoftEther.Client.Daemon/de.logixware.SoftEther.Client.Daemon.plist +++ b/src/Logixware.SoftEther.Client.Daemon/de.logixware.SoftEther.Client.Daemon.plist @@ -1,28 +1,27 @@ - - Label - de.logixware.SoftEther.Client.Daemon - RunAtLoad - - KeepAlive - - EnvironmentVariables - - PATH - /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin - - ProgramArguments - - /Applications/SoftEther VPN Client.app/Contents/Resources/daemon/Logixware.SoftEther.Client.Daemon - - - WorkingDirectory - /Applications/SoftEther VPN Client.app/Contents/Resources/daemon - StandardOutPath - /var/log/logixware/vpnclient/output.log - StandardErrorPath - /var/log/logixware/vpnclient/error.log - + + Label + de.logixware.SoftEther.Client.Daemon + RunAtLoad + + KeepAlive + + EnvironmentVariables + + PATH + /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin + + ProgramArguments + + /Library/Application Support/Logixware/Logixware.SoftEther.Client.Daemon/Logixware.SoftEther.Client.Daemon + + WorkingDirectory + /Library/Application Support/Logixware/Logixware.SoftEther.Client.Daemon + StandardOutPath + /var/log/logixware/Logixware.SoftEther.Client.Daemon/output.log + StandardErrorPath + /var/log/logixware/Logixware.SoftEther.Client.Daemon/error.log + diff --git a/src/Logixware.SoftEther.Client.Daemon/vpnclient.service b/src/Logixware.SoftEther.Client.Daemon/vpnclient.service index cb9b178..9779414 100644 --- a/src/Logixware.SoftEther.Client.Daemon/vpnclient.service +++ b/src/Logixware.SoftEther.Client.Daemon/vpnclient.service @@ -1,5 +1,5 @@ [Unit] -Description=SoftEther VPN Client Daemon +Description=Logixware SoftEther Client Daemon After=network.target StartLimitIntervalSec=0 @@ -8,8 +8,8 @@ Type=simple Restart=always RestartSec=10 User=root -ExecStart=/usr/bin/env /opt/logixware/Logixware.SoftEther.Client/daemon/Logixware.SoftEther.Client.Daemon -WorkingDirectory=/opt/logixware/Logixware.SoftEther.Client/daemon +ExecStart=/usr/bin/env /opt/logixware/Logixware.SoftEther.Client.Daemon +WorkingDirectory=/opt/logixware/Logixware.SoftEther.Client.Daemon [Install] WantedBy=multi-user.target diff --git a/src/Logixware.SoftEther.Client.Manager/Info.plist b/src/Logixware.SoftEther.Client.Manager/Info.plist index e19684f..496f9db 100644 --- a/src/Logixware.SoftEther.Client.Manager/Info.plist +++ b/src/Logixware.SoftEther.Client.Manager/Info.plist @@ -1,33 +1,32 @@ - + - CFBundleName - SoftEther VPN Client - CFBundleIdentifier - de.logixware.SoftEther.Client.Manager - CFBundleShortVersionString - 1.0.0.16 - CFBundleVersion - 1 - LSMinimumSystemVersion - 10.13 CFBundleDevelopmentRegion en + CFBundleIdentifier + de.logixware.SoftEther.Client.Manager CFBundleInfoDictionaryVersion 6.0 + CFBundleName + Logixware SoftEther Client Manager CFBundlePackageType APPL + CFBundleShortVersionString + 1.0.1.18 CFBundleSignature ???? + CFBundleVersion + 1.0.1.18 + LSMinimumSystemVersion + 10.13 NSHumanReadableCopyright - ${AuthorCopyright:HtmlEncode} - NSPrincipalClass - NSApplication + Tobias Punke NSMainStoryboardFile Main + NSPrincipalClass + NSApplication XSAppIconAssets Assets.xcassets/AppIcon.appiconset - diff --git a/src/Logixware.SoftEther.Client.Manager/Logixware.SoftEther.Client.Manager.csproj b/src/Logixware.SoftEther.Client.Manager/Logixware.SoftEther.Client.Manager.csproj index b16b65f..a21dabb 100644 --- a/src/Logixware.SoftEther.Client.Manager/Logixware.SoftEther.Client.Manager.csproj +++ b/src/Logixware.SoftEther.Client.Manager/Logixware.SoftEther.Client.Manager.csproj @@ -7,7 +7,7 @@ {A3F8F2AB-B479-4A4A-A458-A89E7DC349F1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} Exe Logixware.SoftEther.Client.Manager - SoftEther VPN Client + Logixware SoftEther Client Manager v2.0 Resources Xamarin.Mac @@ -44,7 +44,7 @@ DEBUG; prompt 4 - false + true Mac Developer false false @@ -54,6 +54,7 @@ x86 None Latest + 3rd Party Mac Developer Installer pdbonly @@ -113,15 +114,5 @@ - - - - - - - - - - \ No newline at end of file diff --git a/src/Logixware.SoftEther.Client.Manager/Properties/AssemblyInfo/AssemblyVersion.txt b/src/Logixware.SoftEther.Client.Manager/Properties/AssemblyInfo/AssemblyVersion.txt index 349c513..904927c 100755 --- a/src/Logixware.SoftEther.Client.Manager/Properties/AssemblyInfo/AssemblyVersion.txt +++ b/src/Logixware.SoftEther.Client.Manager/Properties/AssemblyInfo/AssemblyVersion.txt @@ -1 +1 @@ -1.0.0.16 \ No newline at end of file +1.0.1.18 \ No newline at end of file diff --git a/src/Logixware.SoftEther.Client.Manager/Resources/daemon/.gitkeep b/src/Logixware.SoftEther.Client.Manager/Resources/daemon/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/Logixware.SoftEther.Client.Manager/Resources/vpnclient/.gitkeep b/src/Logixware.SoftEther.Client.Manager/Resources/vpnclient/.gitkeep deleted file mode 100644 index e69de29..0000000