Skip to content

Commit

Permalink
Cleanup, Simplify Client Country Filter
Browse files Browse the repository at this point in the history
  • Loading branch information
trudyhood committed May 31, 2022
1 parent 32a8a8a commit c448808
Show file tree
Hide file tree
Showing 173 changed files with 10,371 additions and 10,494 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# v2.4.302
# Upcoming

### Client
* Update: Simplify Client's Country exclusion

### Server
* Update: Improve Session Management


### Developer
* Update: Move VpnHood.Client.WebUI to a standalone repo

Expand Down
2 changes: 1 addition & 1 deletion Pub/PublishApps.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ if ($client)
if ($server)
{
Remove-Item $packagesServerDir -ErrorAction Ignore -Recurse;
& "$solutionDir/VpnHood.Server.App.Net/_publish.ps1" -ftp:$false;
& "$solutionDir/VpnHood.Server.App.Net/_publish.ps1" -pushDocker:$distribute;
}

# publish android
Expand Down
41 changes: 20 additions & 21 deletions Samples/VpnHood.Samples.SimpleClient.Win/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,33 @@
using VpnHood.Common;

// ReSharper disable StringLiteralTypo
namespace VpnHood.Samples.SimpleClient.Win
namespace VpnHood.Samples.SimpleClient.Win;

internal class Program
{
internal class Program
private static void Main()
{
private static void Main()
{
Console.WriteLine("Hello VpnClient!");
Console.WriteLine("Hello VpnClient!");

// a clientId should be generated for each client
var clientId = Guid.Parse("7BD6C156-EEA3-43D5-90AF-B118FE47ED0A");
// a clientId should be generated for each client
var clientId = Guid.Parse("7BD6C156-EEA3-43D5-90AF-B118FE47ED0A");

// accessKey must obtain from the server
var accessKey = "vh://eyJuYW1lIjoiVnBuSG9vZCBQdWJsaWMgU2VydmVycyIsInYiOjEsInNpZCI6MTAwMSwidGlkIjoiNWFhY2VjNTUtNWNhYy00NTdhLWFjYWQtMzk3Njk2OTIzNmY4Iiwic2VjIjoiNXcraUhNZXcwQTAzZ3c0blNnRFAwZz09IiwiaXN2IjpmYWxzZSwiaG5hbWUiOiJtby5naXdvd3l2eS5uZXQiLCJocG9ydCI6NDQzLCJjaCI6IjNnWE9IZTVlY3VpQzlxK3NiTzdobExva1FiQT0iLCJwYiI6dHJ1ZSwidXJsIjoiaHR0cHM6Ly93d3cuZHJvcGJveC5jb20vcy82YWlrdHFmM2xhZW9vaGY/ZGw9MSIsImVwIjpbIjUxLjgxLjIxMC4xNjQ6NDQzIl19";
var token = Token.FromAccessKey(accessKey);
// accessKey must obtain from the server
var accessKey = "vh://eyJuYW1lIjoiVnBuSG9vZCBQdWJsaWMgU2VydmVycyIsInYiOjEsInNpZCI6MTAwMSwidGlkIjoiNWFhY2VjNTUtNWNhYy00NTdhLWFjYWQtMzk3Njk2OTIzNmY4Iiwic2VjIjoiNXcraUhNZXcwQTAzZ3c0blNnRFAwZz09IiwiaXN2IjpmYWxzZSwiaG5hbWUiOiJtby5naXdvd3l2eS5uZXQiLCJocG9ydCI6NDQzLCJjaCI6IjNnWE9IZTVlY3VpQzlxK3NiTzdobExva1FiQT0iLCJwYiI6dHJ1ZSwidXJsIjoiaHR0cHM6Ly93d3cuZHJvcGJveC5jb20vcy82YWlrdHFmM2xhZW9vaGY/ZGw9MSIsImVwIjpbIjUxLjgxLjIxMC4xNjQ6NDQzIl19";
var token = Token.FromAccessKey(accessKey);

var packetCapture = new WinDivertPacketCapture();
var vpnHoodClient = new VpnHoodClient(packetCapture, clientId, token, new ClientOptions());
var packetCapture = new WinDivertPacketCapture();
var vpnHoodClient = new VpnHoodClient(packetCapture, clientId, token, new ClientOptions());

// connect to VpnHood server
vpnHoodClient.Connect().Wait();
// connect to VpnHood server
vpnHoodClient.Connect().Wait();

Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("\nIP logging is enabled on these servers. Please follow United States law, especially if using torrent. Read privacy policy before use: https://github.com/vpnhood/VpnHood/blob/main/PRIVACY.md\n");
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("\nIP logging is enabled on these servers. Please follow United States law, especially if using torrent. Read privacy policy before use: https://github.com/vpnhood/VpnHood/blob/main/PRIVACY.md\n");
Console.ResetColor();

Console.WriteLine("VpnHood Client Is Running! Open your browser and browse the Internet! Press Ctrl+C to stop.");
while (vpnHoodClient.State != ClientState.Disposed)
Thread.Sleep(1000);
}
Console.WriteLine("VpnHood Client Is Running! Open your browser and browse the Internet! Press Ctrl+C to stop.");
while (vpnHoodClient.State != ClientState.Disposed)
Thread.Sleep(1000);
}
}
143 changes: 71 additions & 72 deletions VpnHood.App.Launcher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,96 +8,95 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;

namespace VpnHood.App.Launcher
namespace VpnHood.App.Launcher;

internal class Program
{
internal class Program
private static readonly ILogger Logger = NullLogger.Instance;

private static int Main(string[] args)
{
private static readonly ILogger Logger = NullLogger.Instance;
// set sessionName from -launcher:sessionName:
var sessionName = FindSessionName(args);
if (!string.IsNullOrEmpty(sessionName))
_ = new Mutex(true, sessionName, out _);

private static int Main(string[] args)
// updateAndLaunch mode
if (args.Length > 0 && args[0] == "update")
return Update(args);

// test mode
if (args.Length > 0 && args[0] == "test")
{
// set sessionName from -launcher:sessionName:
var sessionName = FindSessionName(args);
if (!string.IsNullOrEmpty(sessionName))
_ = new Mutex(true, sessionName, out _);
Thread.Sleep(30000);
return 0;
}

// updateAndLaunch mode
if (args.Length > 0 && args[0] == "update")
return Update(args);
string appFolder = Path.GetDirectoryName(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)) ??
throw new Exception($"Could not find {nameof(appFolder)}!");
using Updater updater = new(appFolder, new UpdaterOptions {Logger = new SimpleLogger()});
var res = updater.Start();
return res;
}

// test mode
if (args.Length > 0 && args[0] == "test")
{
Thread.Sleep(30000);
return 0;
}

string appFolder = Path.GetDirectoryName(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)) ??
throw new Exception($"Could not find {nameof(appFolder)}!");
using Updater updater = new(appFolder, new UpdaterOptions {Logger = new SimpleLogger()});
var res = updater.Start();
return res;
}
private static string? FindSessionName(string[] args)
{
// get launcher sessionName
var key = "-launcher:sessionName:";
var sessionArg = args.FirstOrDefault(x => x.IndexOf(key, StringComparison.OrdinalIgnoreCase) == 0);

private static string? FindSessionName(string[] args)
// get test sessionName
if (string.IsNullOrEmpty(sessionArg))
{
// get launcher sessionName
var key = "-launcher:sessionName:";
var sessionArg = args.FirstOrDefault(x => x.IndexOf(key, StringComparison.OrdinalIgnoreCase) == 0);
key = "-sessionName:";
sessionArg = args.FirstOrDefault(x => x.IndexOf(key, StringComparison.OrdinalIgnoreCase) == 0);
}

// get test sessionName
if (string.IsNullOrEmpty(sessionArg))
{
key = "-sessionName:";
sessionArg = args.FirstOrDefault(x => x.IndexOf(key, StringComparison.OrdinalIgnoreCase) == 0);
}
return sessionArg?[key.Length..];
}

return sessionArg?[key.Length..];
}
/*
* update zipFile destinationFolder dotnetArgs"
*/
private static int Update(string[] args)
{
return Update(args[1], args[2], args[3..]);
}

public static int Update(string zipFile, string destination, string[] dotnetArgs)
{
Logger.LogInformation("Preparing for extraction...");
Thread.Sleep(3000);

/*
* update zipFile destinationFolder dotnetArgs"
*/
private static int Update(string[] args)
// unzip
try
{
return Update(args[1], args[2], args[3..]);
Logger.LogInformation($"Extracting '{zipFile}' to '{destination}'...");
ZipFile.ExtractToDirectory(zipFile, destination, true);
if (File.Exists(zipFile)) File.Delete(zipFile);
}

public static int Update(string zipFile, string destination, string[] dotnetArgs)
catch (Exception ex)
{
Logger.LogInformation("Preparing for extraction...");
Thread.Sleep(3000);

// unzip
try
{
Logger.LogInformation($"Extracting '{zipFile}' to '{destination}'...");
ZipFile.ExtractToDirectory(zipFile, destination, true);
if (File.Exists(zipFile)) File.Delete(zipFile);
}
catch (Exception ex)
{
Logger.LogError($"Could not extract! Error: {ex.Message}");
}
Logger.LogError($"Could not extract! Error: {ex.Message}");
}

// launch updated app
if (dotnetArgs.Length > 0 && !dotnetArgs.Contains("-launcher:noLaunchAfterUpdate"))
// launch updated app
if (dotnetArgs.Length > 0 && !dotnetArgs.Contains("-launcher:noLaunchAfterUpdate"))
{
// create processStartInfo
var processStartInfo = new ProcessStartInfo
{
// create processStartInfo
var processStartInfo = new ProcessStartInfo
{
FileName = "dotnet",
WorkingDirectory = destination
};
FileName = "dotnet",
WorkingDirectory = destination
};

foreach (var arg in dotnetArgs)
processStartInfo.ArgumentList.Add(arg);
foreach (var arg in dotnetArgs)
processStartInfo.ArgumentList.Add(arg);

// Start process
Process.Start(processStartInfo);
}

return 0;
// Start process
Process.Start(processStartInfo);
}

return 0;
}
}
85 changes: 42 additions & 43 deletions VpnHood.App.Launcher/PublishInfo.cs
Original file line number Diff line number Diff line change
@@ -1,47 +1,46 @@
namespace VpnHood.App.Launcher
namespace VpnHood.App.Launcher;

public class PublishInfo
{
public class PublishInfo
public PublishInfo(string version, string targetFramework, string launchPath)
{
public PublishInfo(string version, string targetFramework, string launchPath)
{
Version = version;
TargetFramework = targetFramework;
LaunchPath = launchPath;
}

/// <summary>
/// Publish version
/// </summary>
public string Version { get; set; }

/// <summary>
/// TargetFramework version
/// </summary>
public string TargetFramework { get; set; }

/// <summary>
/// Entry point dll of package after updating
/// </summary>
public string LaunchPath { get; set; }

/// <summary>
/// This argument will pass to LaunchPath
/// </summary>
public string[]? LaunchArguments { get; set; }

/// <summary>
/// Url to Updated PublishInfo for next releases
/// </summary>
public string? UpdateUrl { get; set; }

/// <summary>
/// Url to download this version
/// </summary>
public string? PackageDownloadUrl { get; set; }

/// <summary>
/// PackageFileName
/// </summary>
public string? PackageFileName { get; set; }
Version = version;
TargetFramework = targetFramework;
LaunchPath = launchPath;
}

/// <summary>
/// Publish version
/// </summary>
public string Version { get; set; }

/// <summary>
/// TargetFramework version
/// </summary>
public string TargetFramework { get; set; }

/// <summary>
/// Entry point dll of package after updating
/// </summary>
public string LaunchPath { get; set; }

/// <summary>
/// This argument will pass to LaunchPath
/// </summary>
public string[]? LaunchArguments { get; set; }

/// <summary>
/// Url to Updated PublishInfo for next releases
/// </summary>
public string? UpdateUrl { get; set; }

/// <summary>
/// Url to download this version
/// </summary>
public string? PackageDownloadUrl { get; set; }

/// <summary>
/// PackageFileName
/// </summary>
public string? PackageFileName { get; set; }
}
35 changes: 17 additions & 18 deletions VpnHood.App.Launcher/SimpleLogger.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
using System;
using Microsoft.Extensions.Logging;

namespace VpnHood.App.Launcher
namespace VpnHood.App.Launcher;

internal class SimpleLogger : ILogger
{
internal class SimpleLogger : ILogger
{
private readonly LoggerExternalScopeProvider _scopeProvider = new();
private readonly LoggerExternalScopeProvider _scopeProvider = new();

public IDisposable BeginScope<TState>(TState state)
{
return _scopeProvider.Push(state);
}
public IDisposable BeginScope<TState>(TState state)
{
return _scopeProvider.Push(state);
}

public bool IsEnabled(LogLevel logLevel)
{
return true;
}
public bool IsEnabled(LogLevel logLevel)
{
return true;
}

public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception,
Func<TState, Exception?, string> formatter)
{
var message = formatter(state, exception);
Console.WriteLine(message);
}
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception,
Func<TState, Exception?, string> formatter)
{
var message = formatter(state, exception);
Console.WriteLine(message);
}
}
Loading

0 comments on commit c448808

Please sign in to comment.