Skip to content

Force Proxy to any Windows/MacOS/Linux Application TCP and UDP traffic

added logging on off in Windows app

Sourav Kalal976429a77a7f
diff --git a/Windows/gui/Resources/Resources.Designer.cs b/Windows/gui/Resources/Resources.Designer.cs
index 4d947af..95d49cb 100644
--- a/Windows/gui/Resources/Resources.Designer.cs
+++ b/Windows/gui/Resources/Resources.Designer.cs
@@ -92,6 +92,12 @@ namespace ProxyBridge.GUI.Resources {
}
}
+ internal static string MenuEnableTrafficLogging {
+ get {
+ return ResourceManager.GetString("MenuEnableTrafficLogging", resourceCulture);
+ }
+ }
+
internal static string MenuSettings {
get {
return ResourceManager.GetString("MenuSettings", resourceCulture);
diff --git a/Windows/gui/Resources/Resources.resx b/Windows/gui/Resources/Resources.resx
index 67fe3cc..e26a7b4 100644
--- a/Windows/gui/Resources/Resources.resx
+++ b/Windows/gui/Resources/Resources.resx
@@ -26,6 +26,9 @@
<data name="MenuDnsViaProxy" xml:space="preserve">
<value>DNS via Proxy</value>
</data>
+ <data name="MenuEnableTrafficLogging" xml:space="preserve">
+ <value>Enable Traffic Logging</value>
+ </data>
<data name="MenuSettings" xml:space="preserve">
<value>Settings</value>
</data>
diff --git a/Windows/gui/Resources/Resources.zh.resx b/Windows/gui/Resources/Resources.zh.resx
index 40d1497..c9dbca9 100644
--- a/Windows/gui/Resources/Resources.zh.resx
+++ b/Windows/gui/Resources/Resources.zh.resx
@@ -26,6 +26,9 @@
<data name="MenuDnsViaProxy" xml:space="preserve">
<value>DNS通过代理</value>
</data>
+ <data name="MenuEnableTrafficLogging" xml:space="preserve">
+ <value>启用流量日志</value>
+ </data>
<data name="MenuSettings" xml:space="preserve">
<value>设置</value>
</data>
diff --git a/Windows/gui/Services/ConfigManager.cs b/Windows/gui/Services/ConfigManager.cs
index 75a8151..1ce26d9 100644
--- a/Windows/gui/Services/ConfigManager.cs
+++ b/Windows/gui/Services/ConfigManager.cs
@@ -15,6 +15,7 @@ public class AppConfig
public string ProxyUsername { get; set; } = "";
public string ProxyPassword { get; set; } = "";
public bool DnsViaProxy { get; set; } = true;
+ public bool IsTrafficLoggingEnabled { get; set; } = true;
public string Language { get; set; } = "en";
public bool CloseToTray { get; set; } = true;
public List<ProxyRuleConfig> ProxyRules { get; set; } = new();
diff --git a/Windows/gui/Services/Loc.cs b/Windows/gui/Services/Loc.cs
index b11895a..43854fc 100644
--- a/Windows/gui/Services/Loc.cs
+++ b/Windows/gui/Services/Loc.cs
@@ -41,6 +41,7 @@ public class Loc : INotifyPropertyChanged
public string MenuProxySettings => Resources.Resources.MenuProxySettings;
public string MenuProxyRules => Resources.Resources.MenuProxyRules;
public string MenuDnsViaProxy => Resources.Resources.MenuDnsViaProxy;
+ public string MenuEnableTrafficLogging => Resources.Resources.MenuEnableTrafficLogging;
public string MenuSettings => Resources.Resources.MenuSettings;
public string MenuCloseToTray => Resources.Resources.MenuCloseToTray;
public string MenuRunAtStartup => Resources.Resources.MenuRunAtStartup;
diff --git a/Windows/gui/ViewModels/MainWindowViewModel.cs b/Windows/gui/ViewModels/MainWindowViewModel.cs
index fa8083a..2b096aa 100644
--- a/Windows/gui/ViewModels/MainWindowViewModel.cs
+++ b/Windows/gui/ViewModels/MainWindowViewModel.cs
@@ -101,7 +101,10 @@ public class MainWindowViewModel : ViewModelBase
}
ConnectionsLog += sb.ToString();
};
- _connectionLogTimer.Start();
+ if (_isTrafficLoggingEnabled)
+ {
+ _connectionLogTimer.Start();
+ }
// Apply config DNS setting
_proxyService.SetDnsViaProxy(_dnsViaProxy);
@@ -272,6 +275,33 @@ public class MainWindowViewModel : ViewModelBase
}
}
+ private bool _isTrafficLoggingEnabled = true; // Default TRUE
+ public bool IsTrafficLoggingEnabled
+ {
+ get => _isTrafficLoggingEnabled;
+ set
+ {
+ if (SetProperty(ref _isTrafficLoggingEnabled, value))
+ {
+ if (value)
+ {
+ _connectionLogTimer?.Start();
+ }
+ else
+ {
+ _connectionLogTimer?.Stop();
+ // Clear pending logs when disabled
+ lock (_connectionLogLock)
+ {
+ _pendingConnectionLogs.Clear();
+ }
+ }
+ SaveConfigurationInternal();
+ ActivityLog += $"[{DateTime.Now:HH:mm:ss}] Traffic Logging: {(value ? "Enabled" : "Disabled")}\n";
+ }
+ }
+ }
+
private bool _closeToTray = true;
public bool CloseToTray
{
@@ -310,6 +340,7 @@ public class MainWindowViewModel : ViewModelBase
public ICommand ShowAboutCommand { get; }
public ICommand CheckForUpdatesCommand { get; }
public ICommand ToggleDnsViaProxyCommand { get; }
+ public ICommand ToggleTrafficLoggingCommand { get; }
public ICommand ToggleCloseToTrayCommand { get; }
public ICommand ToggleStartWithWindowsCommand { get; }
public ICommand CloseDialogCommand { get; }
@@ -454,6 +485,11 @@ public class MainWindowViewModel : ViewModelBase
DnsViaProxy = !DnsViaProxy;
});
+ ToggleTrafficLoggingCommand = new RelayCommand(() =>
+ {
+ IsTrafficLoggingEnabled = !IsTrafficLoggingEnabled;
+ });
+
ToggleCloseToTrayCommand = new RelayCommand(() =>
{
CloseToTray = !CloseToTray;
@@ -643,6 +679,7 @@ public class MainWindowViewModel : ViewModelBase
DnsViaProxy = config.DnsViaProxy;
CloseToTray = config.CloseToTray;
+ IsTrafficLoggingEnabled = config.IsTrafficLoggingEnabled;
_currentLanguage = config.Language;
_loc.CurrentCulture = new System.Globalization.CultureInfo(config.Language);
@@ -686,6 +723,7 @@ public class MainWindowViewModel : ViewModelBase
ProxyUsername = _currentProxyUsername,
ProxyPassword = _currentProxyPassword,
DnsViaProxy = _dnsViaProxy,
+ IsTrafficLoggingEnabled = _isTrafficLoggingEnabled,
Language = _currentLanguage,
CloseToTray = _closeToTray,
ProxyRules = ProxyRules.Select(r => new ProxyRuleConfig
diff --git a/Windows/gui/Views/MainWindow.axaml b/Windows/gui/Views/MainWindow.axaml
index 5fa35ea..76094b8 100644
--- a/Windows/gui/Views/MainWindow.axaml
+++ b/Windows/gui/Views/MainWindow.axaml
@@ -205,6 +205,14 @@
<MenuItem Header="{Binding Loc.MenuProxySettings}" Command="{Binding ShowProxySettingsCommand}"/>
<MenuItem Header="{Binding Loc.MenuProxyRules}" Command="{Binding ShowProxyRulesCommand}"/>
<Separator/>
+ <MenuItem Header="{Binding Loc.MenuEnableTrafficLogging}"
+ Command="{Binding ToggleTrafficLoggingCommand}">
+ <MenuItem.Icon>
+ <CheckBox IsChecked="{Binding IsTrafficLoggingEnabled}"
+ IsHitTestVisible="False"
+ Margin="0"/>
+ </MenuItem.Icon>
+ </MenuItem>
<MenuItem Header="{Binding Loc.MenuDnsViaProxy}"
Command="{Binding ToggleDnsViaProxyCommand}">
<MenuItem.Icon>
diff --git a/Windows/src/ProxyBridge.c b/Windows/src/ProxyBridge.c
index 9ca247d..2283137 100644
--- a/Windows/src/ProxyBridge.c
+++ b/Windows/src/ProxyBridge.c
@@ -2527,6 +2527,7 @@ PROXYBRIDGE_API BOOL ProxyBridge_Stop(void)
if (windivert_handle != INVALID_HANDLE_VALUE)
{
+ WinDivertShutdown(windivert_handle, WINDIVERT_SHUTDOWN_BOTH);
WinDivertClose(windivert_handle);
windivert_handle = INVALID_HANDLE_VALUE;
}