Force Proxy to any Windows/MacOS/Linux Application TCP and UDP traffic
C ccybersecurityhttp3httpproxylinuxlinux-proxymacosmacos-appmacos-proxyproxifierproxifier-alternativeproxyclienttcpthick-clientudpwindivertwindows
added updated check in GUI
Sourav Kalal8e3caf164f81
diff --git a/gui/Services/UpdateService.cs b/gui/Services/UpdateService.csnew file mode 100644index 0000000..19b7091--- /dev/null+++ b/gui/Services/UpdateService.cs@@ -0,0 +1,210 @@+using System;+using System.IO;+using System.Net.Http;+using System.Text.Json;+using System.Text.Json.Serialization;+using System.Threading.Tasks;+using System.Reflection;+using System.Diagnostics;+using System.Linq;++namespace ProxyBridge.GUI.Services;++[JsonSourceGenerationOptions(WriteIndented = true)]+[JsonSerializable(typeof(GitHubRelease))]+[JsonSerializable(typeof(GitHubAsset))]+internal partial class SourceGenerationContext : JsonSerializerContext+{+}++public class UpdateService+{+ private readonly HttpClient _httpClient;+ private const string GitHubApiUrl = "https://api.github.com/repos/InterceptSuite/ProxyBridge/releases/latest";++ public UpdateService()+ {+ _httpClient = new HttpClient();+ _httpClient.DefaultRequestHeaders.Add("User-Agent", "ProxyBridge-UpdateChecker");+ }++ public async Task<VersionInfo> CheckForUpdatesAsync()+ {+ try+ {+ var response = await _httpClient.GetStringAsync(GitHubApiUrl);+ var release = JsonSerializer.Deserialize(response, SourceGenerationContext.Default.GitHubRelease);++ var currentVersion = GetCurrentVersion();+ var latestVersion = ParseVersion(release?.TagName);++ // Find the setup executable in assets+ var setupAsset = release?.Assets?.FirstOrDefault(a =>+ a.Name?.EndsWith(".exe", StringComparison.OrdinalIgnoreCase) == true &&+ (a.Name.Contains("setup", StringComparison.OrdinalIgnoreCase) ||+ a.Name.Contains("installer", StringComparison.OrdinalIgnoreCase) ||+ a.Name.Contains("ProxyBridge", StringComparison.OrdinalIgnoreCase)));++ return new VersionInfo+ {+ CurrentVersion = currentVersion,+ LatestVersion = latestVersion,+ IsUpdateAvailable = IsNewerVersion(latestVersion, currentVersion),+ LatestVersionString = release?.TagName ?? "Unknown",+ CurrentVersionString = FormatVersion(currentVersion),+ DownloadUrl = setupAsset?.BrowserDownloadUrl,+ SetupFileName = setupAsset?.Name+ };+ }+ catch (Exception ex)+ {+ return new VersionInfo+ {+ CurrentVersion = GetCurrentVersion(),+ LatestVersion = GetCurrentVersion(),+ IsUpdateAvailable = false,+ Error = ex.Message,+ LatestVersionString = "Error",+ CurrentVersionString = FormatVersion(GetCurrentVersion())+ };+ }+ }++ private Version GetCurrentVersion()+ {+ var version = Assembly.GetExecutingAssembly().GetName().Version;+ return version ?? new Version(1, 0, 0);+ }++ private Version ParseVersion(string? tagName)+ {+ if (string.IsNullOrEmpty(tagName))+ return new Version(0, 0, 0);++ // Remove 'v' prefix if present+ var versionString = tagName.StartsWith("v") ? tagName.Substring(1) : tagName;++ if (Version.TryParse(versionString, out var version))+ return version;++ return new Version(0, 0, 0);+ }++ private bool IsNewerVersion(Version latest, Version current)+ {+ return latest.CompareTo(current) > 0;+ }++ private string FormatVersion(Version version)+ {+ return $"v{version.Major}.{version.Minor}.{version.Build}";+ }++ public async Task<string?> DownloadUpdateAsync(string downloadUrl, string fileName, IProgress<int>? progress = null)+ {+ try+ {+ var tempPath = Path.Combine(Path.GetTempPath(), fileName);++ using var response = await _httpClient.GetAsync(downloadUrl, HttpCompletionOption.ResponseHeadersRead);+ response.EnsureSuccessStatusCode();++ var totalBytes = response.Content.Headers.ContentLength ?? 0;+ var downloadedBytes = 0L;++ using var contentStream = await response.Content.ReadAsStreamAsync();+ using var fileStream = new FileStream(tempPath, FileMode.Create, FileAccess.Write, FileShare.None);++ var buffer = new byte[8192];+ int bytesRead;++ while ((bytesRead = await contentStream.ReadAsync(buffer, 0, buffer.Length)) > 0)+ {+ await fileStream.WriteAsync(buffer, 0, bytesRead);+ downloadedBytes += bytesRead;++ if (totalBytes > 0)+ {+ var progressPercentage = (int)((downloadedBytes * 100) / totalBytes);+ progress?.Report(progressPercentage);+ }+ }++ return tempPath;+ }+ catch+ {+ return null;+ }+ }++ public void InstallUpdateAndExit(string installerPath)+ {+ try+ {+ // Start the installer+ var startInfo = new ProcessStartInfo+ {+ FileName = installerPath,+ UseShellExecute = true,+ Verb = "runas" // Run as administrator+ };++ Process.Start(startInfo);++ // Exit the current application+ Environment.Exit(0);+ }+ catch (Exception ex)+ {+ throw new InvalidOperationException($"Failed to start installer: {ex.Message}", ex);+ }+ }++ public void Dispose()+ {+ _httpClient?.Dispose();+ }+}++public class VersionInfo+{+ public Version CurrentVersion { get; set; } = new(1, 0, 0);+ public Version LatestVersion { get; set; } = new(1, 0, 0);+ public bool IsUpdateAvailable { get; set; }+ public string? Error { get; set; }+ public string LatestVersionString { get; set; } = "";+ public string CurrentVersionString { get; set; } = "";+ public string? DownloadUrl { get; set; }+ public string? SetupFileName { get; set; }+}++public class GitHubRelease+{+ [JsonPropertyName("tag_name")]+ public string? TagName { get; set; }++ [JsonPropertyName("name")]+ public string? Name { get; set; }++ [JsonPropertyName("prerelease")]+ public bool Prerelease { get; set; }++ [JsonPropertyName("published_at")]+ public DateTime PublishedAt { get; set; }++ [JsonPropertyName("assets")]+ public GitHubAsset[]? Assets { get; set; }+}++public class GitHubAsset+{+ [JsonPropertyName("name")]+ public string? Name { get; set; }++ [JsonPropertyName("browser_download_url")]+ public string? BrowserDownloadUrl { get; set; }++ [JsonPropertyName("size")]+ public long Size { get; set; }+}\ No newline at end of filediff --git a/gui/ViewModels/AboutViewModel.cs b/gui/ViewModels/AboutViewModel.csindex 72d16c3..776d84d 100644--- a/gui/ViewModels/AboutViewModel.cs+++ b/gui/ViewModels/AboutViewModel.cs@@ -9,6 +9,10 @@ public class AboutViewModelpublic string Version { get; }public ICommand CloseCommand { get; }+ public AboutViewModel() : this(() => { })+ {+ }+public AboutViewModel(Action onClose){var version = Assembly.GetExecutingAssembly().GetName().Version;diff --git a/gui/ViewModels/MainWindowViewModel.cs b/gui/ViewModels/MainWindowViewModel.csindex 42f2bef..4a5b86b 100644--- a/gui/ViewModels/MainWindowViewModel.cs+++ b/gui/ViewModels/MainWindowViewModel.cs@@ -224,6 +224,7 @@ public class MainWindowViewModel : ViewModelBasepublic ICommand ShowProxySettingsCommand { get; }public ICommand ShowProxyRulesCommand { get; }public ICommand ShowAboutCommand { get; }+ public ICommand CheckForUpdatesCommand { get; }public ICommand ToggleDnsViaProxyCommand { get; }public ICommand CloseDialogCommand { get; }public ICommand ClearConnectionsLogCommand { get; }@@ -345,6 +346,18 @@ public class MainWindowViewModel : ViewModelBase}});+ CheckForUpdatesCommand = new RelayCommand(async () =>+ {+ var updateWindow = new UpdateCheckWindow();+ var viewModel = new UpdateCheckViewModel(() => updateWindow.Close());+ updateWindow.DataContext = viewModel;++ if (_mainWindow != null)+ {+ await updateWindow.ShowDialog(_mainWindow);+ }+ });+ToggleDnsViaProxyCommand = new RelayCommand(() =>{DnsViaProxy = !DnsViaProxy;diff --git a/gui/ViewModels/UpdateCheckViewModel.cs b/gui/ViewModels/UpdateCheckViewModel.csnew file mode 100644index 0000000..d80dad0--- /dev/null+++ b/gui/ViewModels/UpdateCheckViewModel.cs@@ -0,0 +1,228 @@+using System;+using System.Windows.Input;+using System.Threading.Tasks;+using ProxyBridge.GUI.Services;++namespace ProxyBridge.GUI.ViewModels;++public class UpdateCheckViewModel : ViewModelBase+{+ private readonly UpdateService _updateService;+ private readonly Action _onClose;+ private string _currentVersion = "";+ private string _latestVersion = "";+ private string _statusMessage = "";+ private string _statusColor = "#FFB0B0B0";+ private string _latestVersionColor = "#FFB0B0B0";+ private string _errorMessage = "";+ private bool _isChecking = false;+ private bool _hasError = false;+ private bool _isUpdateAvailable = false;+ private bool _isDownloading = false;+ private int _downloadProgress = 0;+ private string _downloadStatus = "";+ private VersionInfo? _currentVersionInfo;++ public UpdateCheckViewModel() : this(() => { })+ {+ }++ public UpdateCheckViewModel(Action onClose)+ {+ _updateService = new UpdateService();+ _onClose = onClose;++ CheckUpdatesCommand = new RelayCommand(async () => await CheckForUpdatesAsync());+ DownloadNowCommand = new RelayCommand(async () => await DownloadAndInstallAsync(), () => IsUpdateAvailable && !IsDownloading);+ CloseCommand = new RelayCommand(onClose);++ // Start checking immediately+ _ = CheckForUpdatesAsync();+ }++ public string CurrentVersion+ {+ get => _currentVersion;+ set => SetProperty(ref _currentVersion, value);+ }++ public string LatestVersion+ {+ get => _latestVersion;+ set => SetProperty(ref _latestVersion, value);+ }++ public string StatusMessage+ {+ get => _statusMessage;+ set => SetProperty(ref _statusMessage, value);+ }++ public string StatusColor+ {+ get => _statusColor;+ set => SetProperty(ref _statusColor, value);+ }++ public string LatestVersionColor+ {+ get => _latestVersionColor;+ set => SetProperty(ref _latestVersionColor, value);+ }++ public string ErrorMessage+ {+ get => _errorMessage;+ set => SetProperty(ref _errorMessage, value);+ }++ public bool IsChecking+ {+ get => _isChecking;+ set => SetProperty(ref _isChecking, value);+ }++ public bool HasError+ {+ get => _hasError;+ set => SetProperty(ref _hasError, value);+ }++ public bool IsUpdateAvailable+ {+ get => _isUpdateAvailable;+ set => SetProperty(ref _isUpdateAvailable, value);+ }++ public bool IsDownloading+ {+ get => _isDownloading;+ set => SetProperty(ref _isDownloading, value);+ }++ public int DownloadProgress+ {+ get => _downloadProgress;+ set => SetProperty(ref _downloadProgress, value);+ }++ public string DownloadStatus+ {+ get => _downloadStatus;+ set => SetProperty(ref _downloadStatus, value);+ }++ public ICommand CheckUpdatesCommand { get; }+ public ICommand DownloadNowCommand { get; }+ public ICommand CloseCommand { get; }++ private async Task CheckForUpdatesAsync()+ {+ IsChecking = true;+ HasError = false;+ StatusMessage = "";+ ErrorMessage = "";++ try+ {+ var versionInfo = await _updateService.CheckForUpdatesAsync();+ _currentVersionInfo = versionInfo;++ CurrentVersion = versionInfo.CurrentVersionString;+ LatestVersion = versionInfo.LatestVersionString;+ IsUpdateAvailable = versionInfo.IsUpdateAvailable;++ if (!string.IsNullOrEmpty(versionInfo.Error))+ {+ HasError = true;+ ErrorMessage = $"Error checking for updates: {versionInfo.Error}";+ StatusMessage = "Unable to check for updates";+ StatusColor = "#FFFF6B6B";+ LatestVersionColor = "#FFFF6B6B";+ }+ else if (versionInfo.IsUpdateAvailable)+ {+ StatusMessage = "New version available!";+ StatusColor = "#FF4CAF50";+ LatestVersionColor = "#FF4CAF50";+ }+ else+ {+ StatusMessage = "You have the latest version";+ StatusColor = "#FF4CAF50";+ LatestVersionColor = "#FF007ACC";+ }++ // Refresh command can execute state+ (DownloadNowCommand as RelayCommand)?.RaiseCanExecuteChanged();+ }+ catch (Exception ex)+ {+ HasError = true;+ ErrorMessage = $"Error checking for updates: {ex.Message}";+ StatusMessage = "Unable to check for updates";+ StatusColor = "#FFFF6B6B";+ LatestVersionColor = "#FFFF6B6B";+ }+ finally+ {+ IsChecking = false;+ }+ }++ private async Task DownloadAndInstallAsync()+ {+ if (_currentVersionInfo?.DownloadUrl == null || _currentVersionInfo?.SetupFileName == null)+ {+ ErrorMessage = "Download URL not available";+ HasError = true;+ return;+ }++ IsDownloading = true;+ DownloadProgress = 0;+ DownloadStatus = "Starting download...";+ HasError = false;+ ErrorMessage = "";++ try+ {+ var progress = new Progress<int>(percent =>+ {+ DownloadProgress = percent;+ DownloadStatus = $"Downloading... {percent}%";+ });++ var installerPath = await _updateService.DownloadUpdateAsync(+ _currentVersionInfo.DownloadUrl,+ _currentVersionInfo.SetupFileName,+ progress);++ if (installerPath != null)+ {+ DownloadStatus = "Download complete. Starting installer...";+ await Task.Delay(1000); // Brief pause to show completion++ // This will close the current app and start the installer+ _updateService.InstallUpdateAndExit(installerPath);+ }+ else+ {+ HasError = true;+ ErrorMessage = "Failed to download the update";+ DownloadStatus = "Download failed";+ }+ }+ catch (Exception ex)+ {+ HasError = true;+ ErrorMessage = $"Download error: {ex.Message}";+ DownloadStatus = "Download failed";+ }+ finally+ {+ IsDownloading = false;+ (DownloadNowCommand as RelayCommand)?.RaiseCanExecuteChanged();+ }+ }+}\ No newline at end of filediff --git a/gui/Views/AboutWindow.axaml b/gui/Views/AboutWindow.axamlindex ba9da14..522ca01 100644--- a/gui/Views/AboutWindow.axaml+++ b/gui/Views/AboutWindow.axaml@@ -81,7 +81,6 @@Foreground="#FFB0B0B0"Margin="0,8,0,0"/>-</StackPanel></Grid></Window>diff --git a/gui/Views/AboutWindow.axaml.cs b/gui/Views/AboutWindow.axaml.csindex 675cff0..972827a 100644--- a/gui/Views/AboutWindow.axaml.cs+++ b/gui/Views/AboutWindow.axaml.cs@@ -1,7 +1,6 @@using Avalonia.Controls;using System.Diagnostics;using Avalonia.Input;-using Avalonia.Interactivity;namespace ProxyBridge.GUI.Views;diff --git a/gui/Views/MainWindow.axaml b/gui/Views/MainWindow.axamlindex 04be551..d8800b0 100644--- a/gui/Views/MainWindow.axaml+++ b/gui/Views/MainWindow.axaml@@ -213,7 +213,10 @@</MenuItem.Icon></MenuItem></MenuItem>- <MenuItem Header="About" Command="{Binding ShowAboutCommand}"/>+ <MenuItem Header="About">+ <MenuItem Header="About ProxyBridge" Command="{Binding ShowAboutCommand}"/>+ <MenuItem Header="Check for Updates" Command="{Binding CheckForUpdatesCommand}"/>+ </MenuItem></Menu><!-- Tab Control -->diff --git a/gui/Views/UpdateCheckWindow.axaml b/gui/Views/UpdateCheckWindow.axamlnew file mode 100644index 0000000..ca06c66--- /dev/null+++ b/gui/Views/UpdateCheckWindow.axaml@@ -0,0 +1,114 @@+<Window xmlns="https://github.com/avaloniaui"+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"+ xmlns:vm="using:ProxyBridge.GUI.ViewModels"+ x:Class="ProxyBridge.GUI.Views.UpdateCheckWindow"+ x:DataType="vm:UpdateCheckViewModel"+ x:CompileBindings="True"+ Title="Check for Updates"+ Icon="/Assets/logo.ico"+ Width="500" Height="300"+ CanResize="False"+ WindowStartupLocation="CenterOwner"+ Background="#FF1E1E1E">++ <Design.DataContext>+ <vm:UpdateCheckViewModel/>+ </Design.DataContext>++ <Grid RowDefinitions="Auto,*,Auto">+ <!-- Header -->+ <Border Grid.Row="0" Background="#FF252526" BorderBrush="#FF007ACC" BorderThickness="0,0,0,1" Padding="16,12">+ <StackPanel Orientation="Horizontal" Spacing="10">+ <TextBlock Text="Update Check"+ FontSize="16"+ FontWeight="SemiBold"+ VerticalAlignment="Center"/>+ </StackPanel>+ </Border>++ <!-- Content -->+ <StackPanel Grid.Row="1" Margin="32,24" Spacing="16" VerticalAlignment="Center">+ <!-- Current Version -->+ <StackPanel Orientation="Horizontal" Spacing="8">+ <TextBlock Text="Current Version:"+ FontWeight="Medium"+ Foreground="#FFB0B0B0"+ Width="120"/>+ <TextBlock Text="{Binding CurrentVersion}"+ Foreground="#FF007ACC"/>+ </StackPanel>++ <!-- Latest Version -->+ <StackPanel Orientation="Horizontal" Spacing="8">+ <TextBlock Text="Latest Version:"+ FontWeight="Medium"+ Foreground="#FFB0B0B0"+ Width="120"/>+ <TextBlock Text="{Binding LatestVersion}"+ Foreground="{Binding LatestVersionColor}"/>+ </StackPanel>++ <!-- Status Message -->+ <TextBlock Text="{Binding StatusMessage}"+ FontWeight="Medium"+ Foreground="{Binding StatusColor}"+ HorizontalAlignment="Center"+ TextWrapping="Wrap"+ Margin="0,8,0,0"/>++ <!-- Loading indicator -->+ <TextBlock Text="Checking for updates..."+ Foreground="#FFB0B0B0"+ HorizontalAlignment="Center"+ IsVisible="{Binding IsChecking}"/>++ <!-- Download Progress -->+ <StackPanel Spacing="8" IsVisible="{Binding IsDownloading}">+ <TextBlock Text="{Binding DownloadStatus}"+ Foreground="#FF007ACC"+ HorizontalAlignment="Center"/>+ <ProgressBar Value="{Binding DownloadProgress}"+ Minimum="0"+ Maximum="100"+ Height="6"+ Background="#FF3C3C3C"+ Foreground="#FF007ACC"/>+ </StackPanel>++ <!-- Error message -->+ <TextBlock Text="{Binding ErrorMessage}"+ Foreground="#FFFF6B6B"+ HorizontalAlignment="Center"+ TextWrapping="Wrap"+ IsVisible="{Binding HasError}"/>+ </StackPanel>++ <!-- Buttons -->+ <Border Grid.Row="2" Background="#FF252526" BorderBrush="#FF007ACC" BorderThickness="0,1,0,0" Padding="16,12">+ <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Spacing="10">+ <!-- Download Now Button (only visible when update is available) -->+ <Button Content="Download Now"+ Command="{Binding DownloadNowCommand}"+ IsVisible="{Binding IsUpdateAvailable}"+ IsEnabled="{Binding !IsDownloading}"+ Background="#FF4CAF50"+ Foreground="White"+ Padding="16,6"+ CornerRadius="3"/>+ <Button Content="Check Again"+ Command="{Binding CheckUpdatesCommand}"+ IsEnabled="{Binding !IsChecking}"+ Background="#FF007ACC"+ Foreground="White"+ Padding="16,6"+ CornerRadius="3"/>+ <Button Content="Close"+ Command="{Binding CloseCommand}"+ Background="#FF3C3C3C"+ Foreground="White"+ Padding="16,6"+ CornerRadius="3"/>+ </StackPanel>+ </Border>+ </Grid>+</Window>\ No newline at end of filediff --git a/gui/Views/UpdateCheckWindow.axaml.cs b/gui/Views/UpdateCheckWindow.axaml.csnew file mode 100644index 0000000..be0a1fe--- /dev/null+++ b/gui/Views/UpdateCheckWindow.axaml.cs@@ -0,0 +1,11 @@+using Avalonia.Controls;++namespace ProxyBridge.GUI.Views;++public partial class UpdateCheckWindow : Window+{+ public UpdateCheckWindow()+ {+ InitializeComponent();+ }+}\ No newline at end of file