Skip to content

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

feat(linux/gui): logging and DNS switches are stored per profile

anof-cyber0ae2b8a9827a
diff --git a/Linux/README.md b/Linux/README.md
index 8933d44..0ca3fda 100644
--- a/Linux/README.md
+++ b/Linux/README.md
@@ -304,7 +304,7 @@ sudo ProxyBridge --profile work --rule "curl:*:*:TCP:DIRECT" # profile first,
- Linux keeps domain names in the host list. On export they are written to `TargetDomains` (as the Windows app does) and merged back on import.
- Fields this version has no use for (`LocalhostViaProxy`, `LogFilters`, `SendDomainToProxy`, ...) are ignored on import. `DnsViaProxy` and `DefaultProxyId` are Linux additions that other apps ignore. The CLI takes DNS-via-proxy from the profile unless `--dns-via-proxy` is given, and uses `--verbose` instead of the logging flag.
- Disabled rules (`"IsEnabled": false`) are kept in the GUI and skipped by the CLI.
-- **GUI storage:** `/etc/proxybridge/profiles/<name>.pbprofile` (one file per profile) and `/etc/proxybridge/settings.json` (active profile, logging and DNS switches). The directory is `0700` and the files `0600`, because they hold proxy passwords; exported files are `0600` as well, and the CLI warns when a profile with credentials is readable by others. The `config.ini` of earlier versions is converted on the first start and kept as `config.ini.bak`.
+- **GUI storage:** `/etc/proxybridge/profiles/<name>.pbprofile` (one file per profile) and `/etc/proxybridge/settings.json`, which holds only the name of the active profile. Everything else, including the *Enable Traffic Logging* and *DNS via Proxy* switches, is saved inside the profile, so switching profiles switches those too. The directory is `0700` and the files `0600`, because they hold proxy passwords; exported files are `0600` as well, and the CLI warns when a profile with credentials is readable by others. The `config.ini` of earlier versions is converted on the first start and kept as `config.ini.bak`.
- Files are limited to 4 MiB, 256 proxies and 4096 rules; malformed files are rejected with the reason, never partly applied.
## Domain rules
diff --git a/Linux/gui/gui.h b/Linux/gui/gui.h
index dfaecae..97184bb 100644
--- a/Linux/gui/gui.h
+++ b/Linux/gui/gui.h
@@ -39,6 +39,7 @@ typedef struct {
GList *proxies;
char *default_proxy;
GList *rules;
+ bool logging, dns; // traffic logging and DNS via proxy, stored in the profile like the Windows app does
char *saved; // what is on disk, to skip rewriting unchanged profiles
} Profile;
@@ -73,6 +74,7 @@ char *extract_sub_json_str(const char *json, const char *key);
int rules_from_json(const char *json, RuleImportCb cb, void *ud);
char *rules_to_json(GList *rules, bool only_selected);
+void gui_sync_switches(); // pushes the active profile's logging/DNS switches to the engine and the menu
void save_config();
void load_config();
void config_free_all();
diff --git a/Linux/gui/gui_config.c b/Linux/gui/gui_config.c
index fa27b43..cb295df 100644
--- a/Linux/gui/gui_config.c
+++ b/Linux/gui/gui_config.c
@@ -57,12 +57,16 @@ static void profile_sync_active() {
p->proxies = g_proxies_list;
p->rules = g_rules_list;
p->default_proxy = g_default_proxy;
+ p->logging = g_chk_logging;
+ p->dns = g_chk_dns;
}
static void load_globals_from(Profile *p) {
g_proxies_list = p->proxies;
g_rules_list = p->rules;
g_default_proxy = p->default_proxy;
+ g_chk_logging = p->logging;
+ g_chk_dns = p->dns;
}
void config_free_all() {
@@ -78,6 +82,7 @@ void config_free_all() {
static Profile *profile_new_empty(const char *name) {
Profile *p = g_malloc0(sizeof(Profile));
p->name = g_strdup(name);
+ p->logging = p->dns = true;
g_profiles = g_list_append(g_profiles, p);
return p;
}
@@ -114,6 +119,8 @@ Profile *profile_create(const char *name, bool copy_active) {
for (GList *l = src->proxies; l != NULL; l = l->next) p->proxies = g_list_append(p->proxies, copy_proxy((ProxyData *)l->data));
for (GList *l = src->rules; l != NULL; l = l->next) p->rules = g_list_append(p->rules, copy_rule((RuleData *)l->data));
p->default_proxy = g_strdup(src->default_proxy);
+ p->logging = src->logging;
+ p->dns = src->dns;
}
return p;
}
@@ -170,8 +177,8 @@ static ProxyData *find_in_list(GList *list, const char *name) {
static void profile_to_pbp(const Profile *prof, struct pbp_profile *out) {
memset(out, 0, sizeof *out);
out->name = prof->name;
- out->logging = g_chk_logging;
- out->dns_via_proxy = g_chk_dns;
+ out->logging = prof->logging;
+ out->dns_via_proxy = prof->dns;
out->nproxies = g_list_length(prof->proxies);
out->nrules = g_list_length(prof->rules);
out->proxies = g_new0(struct pbp_proxy, out->nproxies + 1);
@@ -239,6 +246,8 @@ static void fill_profile_from_pbp(Profile *p, const struct pbp_profile *src) {
const struct pbp_proxy *d = src->default_proxy_id ? pbp_find_proxy(src, src->default_proxy_id) : NULL;
g_free(p->default_proxy);
p->default_proxy = d ? g_strdup(d->name) : NULL;
+ p->logging = src->logging;
+ p->dns = src->dns_via_proxy;
}
bool profile_export(const Profile *prof, const char *path, char *err, size_t errlen) {
@@ -327,7 +336,7 @@ void save_config() {
g_free(path);
}
char *settings = g_strdup_printf("%s/settings.json", dir);
- if (pbp_settings_save(settings, g_active_profile, g_chk_logging, g_chk_dns, err, sizeof err) != 0)
+ if (pbp_settings_save(settings, g_active_profile, err, sizeof err) != 0)
fprintf(stderr, "failed to save settings: %s\n", err);
g_free(settings);
out:
@@ -541,9 +550,15 @@ void load_config() {
load_profile_files(dir);
char *settings = g_strdup_printf("%s/settings.json", dir);
- pbp_settings_load(settings, &settings_active, &g_chk_logging, &g_chk_dns);
+ pbp_settings_load(settings, &settings_active);
g_free(settings);
- if (!g_profiles) migrate = load_legacy_ini(dir, &legacy_active);
+ if (!g_profiles) {
+ migrate = load_legacy_ini(dir, &legacy_active);
+ for (GList *l = g_profiles; l != NULL; l = l->next) { // the old file had one pair of switches for all profiles
+ ((Profile *)l->data)->logging = g_chk_logging;
+ ((Profile *)l->data)->dns = g_chk_dns;
+ }
+ }
char *active = g_strdup(migrate && legacy_active ? legacy_active : settings_active);
free(settings_active);
g_free(legacy_active);
diff --git a/Linux/gui/gui_settings.c b/Linux/gui/gui_settings.c
index 7d7f14f..cbf9912 100644
--- a/Linux/gui/gui_settings.c
+++ b/Linux/gui/gui_settings.c
@@ -459,6 +459,7 @@ static void reapply_active_profile() {
ProxyBridge_ClearRules();
apply_proxies_to_lib();
apply_rules_to_lib();
+ gui_sync_switches();
save_config();
refresh_rules_window();
update_profile_ui();
diff --git a/Linux/gui/main.c b/Linux/gui/main.c
index 0cfc867..a447872 100644
--- a/Linux/gui/main.c
+++ b/Linux/gui/main.c
@@ -11,6 +11,7 @@ guint status_context_id;
GList *g_rules_list = NULL;
bool g_chk_logging = true;
bool g_chk_dns = true;
+static GtkWidget *log_item, *dns_item;
static void on_log_traffic_toggled(GtkCheckMenuItem *item, gpointer data) {
bool active = gtk_check_menu_item_get_active(item);
@@ -26,6 +27,14 @@ static void on_dns_proxy_toggled(GtkCheckMenuItem *item, gpointer data) {
save_config();
}
+// the switches belong to the profile: after a profile change, show and apply the new profile's values
+void gui_sync_switches() {
+ ProxyBridge_SetTrafficLoggingEnabled(g_chk_logging);
+ ProxyBridge_SetDnsViaProxy(g_chk_dns);
+ if (log_item) gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(log_item), g_chk_logging);
+ if (dns_item) gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(dns_item), g_chk_dns);
+}
+
// same feed as windows/mac: https://download.interceptsuite.com/proxybridge.json
#define UPD_FEED_URL "https://download.interceptsuite.com/proxybridge.json"
@@ -318,11 +327,12 @@ static GtkWidget *add_menu_item(GtkWidget *menu, const char *label, GCallback cb
return item;
}
-static void add_check_item(GtkWidget *menu, const char *label, bool active, GCallback cb) {
+static GtkWidget *add_check_item(GtkWidget *menu, const char *label, bool active, GCallback cb) {
GtkWidget *item = gtk_check_menu_item_new_with_label(label);
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), active);
g_signal_connect(item, "toggled", cb, NULL);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
+ return item;
}
static void add_separator(GtkWidget *menu) {
@@ -396,8 +406,8 @@ int main(int argc, char *argv[]) {
add_menu_item(proxy_menu, "Proxy Rules...", G_CALLBACK(on_proxy_rules_clicked));
add_menu_item(proxy_menu, "Profiles...", G_CALLBACK(on_profiles_clicked));
add_separator(proxy_menu);
- add_check_item(proxy_menu, "Enable Traffic Logging", g_chk_logging, G_CALLBACK(on_log_traffic_toggled));
- add_check_item(proxy_menu, "DNS via Proxy", g_chk_dns, G_CALLBACK(on_dns_proxy_toggled));
+ log_item = add_check_item(proxy_menu, "Enable Traffic Logging", g_chk_logging, G_CALLBACK(on_log_traffic_toggled));
+ dns_item = add_check_item(proxy_menu, "DNS via Proxy", g_chk_dns, G_CALLBACK(on_dns_proxy_toggled));
add_separator(proxy_menu);
start_item = add_menu_item(proxy_menu, "Start Engine", G_CALLBACK(on_start_engine));
stop_item = add_menu_item(proxy_menu, "Stop Engine", G_CALLBACK(on_stop_engine));
diff --git a/Linux/gui/tests/config_test.c b/Linux/gui/tests/config_test.c
index a4b416b..1c251c1 100644
--- a/Linux/gui/tests/config_test.c
+++ b/Linux/gui/tests/config_test.c
@@ -55,7 +55,15 @@ static void check_storage(const char *dir) {
CHECK(stat(p, &st) == 0 && (st.st_mode & 0777) == 0700);
g_free(p);
p = g_strdup_printf("%s/settings.json", dir);
- CHECK(stat(p, &st) == 0);
+ char *settings = NULL;
+ CHECK(g_file_get_contents(p, &settings, NULL, NULL) && strstr(settings, "ActiveProfileName") &&
+ !strstr(settings, "Logging") && !strstr(settings, "Dns")); // nothing but the pointer to the active profile
+ g_free(settings);
+ g_free(p);
+ p = g_strdup_printf("%s/profiles/Work.pbprofile", dir);
+ char *prof = NULL;
+ CHECK(g_file_get_contents(p, &prof, NULL, NULL) && strstr(prof, "\"IsTrafficLoggingEnabled\": false") && strstr(prof, "\"DnsViaProxy\": false"));
+ g_free(prof);
g_free(p);
// the migration set the old file aside
p = g_strdup_printf("%s/config.ini", dir);
@@ -182,7 +190,9 @@ int main() {
CHECK(profile_activate("Work"));
CHECK(g_proxies_list == NULL && g_rules_list == NULL);
add_content("p 1|x");
+ CHECK(g_chk_logging && g_chk_dns); // a new profile starts with both switches on
g_chk_dns = false;
+ g_chk_logging = false;
save_config();
check_storage(dir);
@@ -193,9 +203,16 @@ int main() {
CHECK(strcmp(((ProxyData *)g_proxies_list->data)->name, "p 1|x") == 0);
CHECK(strcmp(((ProxyData *)g_proxies_list->data)->password, "s3cr|et") == 0);
CHECK(strcmp(((RuleData *)g_rules_list->data)->target_hosts, "*.github.com") == 0);
- CHECK(!g_chk_dns && !g_chk_logging);
+ CHECK(!g_chk_dns && !g_chk_logging); // restored from the Work profile file itself
+ CHECK(profile_find("Home") && !profile_find("Home")->logging && profile_find("Home")->dns); // migrated values of the old file, per profile
CHECK(profile_find("Home") && g_list_length(profile_find("Home")->rules) == 1);
+ CHECK(profile_activate("Home")); // switching profiles switches the values too
+ CHECK(!g_chk_logging && g_chk_dns);
+ CHECK(profile_activate("Work"));
+ CHECK(!g_chk_logging && !g_chk_dns);
+ CHECK(profile_activate("Home"));
+ CHECK(profile_activate("Work"));
CHECK(profile_delete(profile_find("Work")));
CHECK(strcmp(g_active_profile, "Default") == 0 && g_list_length(g_rules_list) == 1);
CHECK(profile_delete(profile_find("Home")));
diff --git a/Linux/profile/pb_profile.c b/Linux/profile/pb_profile.c
index 90e85e9..d00b267 100644
--- a/Linux/profile/pb_profile.c
+++ b/Linux/profile/pb_profile.c
@@ -703,7 +703,7 @@ int pbp_save_file(const char *path, const struct pbp_profile *p, char *err, size
return rc;
}
-int pbp_settings_load(const char *path, char **active, bool *logging, bool *dns)
+int pbp_settings_load(const char *path, char **active)
{
char err[200];
FILE *f = fopen(path, "r");
@@ -719,21 +719,17 @@ int pbp_settings_load(const char *path, char **active, bool *logging, bool *dns)
if (rc == 0 && root.t == J_OBJ) {
char *a = jtext(&root, "ActiveProfileName");
if (a && *a) { free(*active); *active = a; } else free(a);
- *logging = jbool(&root, "IsTrafficLoggingEnabled", *logging);
- *dns = jbool(&root, "DnsViaProxy", *dns);
} else rc = -1;
jfree(&root);
free(buf);
return rc;
}
-int pbp_settings_save(const char *path, const char *active, bool logging, bool dns, char *err, size_t errlen)
+int pbp_settings_save(const char *path, const char *active, char *err, size_t errlen)
{
struct sb b = {0};
sb_puts(&b, "{\n");
- sb_kv(&b, " ", "ActiveProfileName", active ? active : "", ",\n");
- sb_puts(&b, logging ? " \"IsTrafficLoggingEnabled\": true,\n" : " \"IsTrafficLoggingEnabled\": false,\n");
- sb_puts(&b, dns ? " \"DnsViaProxy\": true\n}\n" : " \"DnsViaProxy\": false\n}\n");
+ sb_kv(&b, " ", "ActiveProfileName", active ? active : "", "\n}\n");
if (b.oom) { free(b.p); snprintf(err, errlen, "out of memory"); return -1; }
int rc = pbp_write_file(path, b.p, err, errlen);
free(b.p);
diff --git a/Linux/profile/pb_profile.h b/Linux/profile/pb_profile.h
index 9a547bf..e0e99ad 100644
--- a/Linux/profile/pb_profile.h
+++ b/Linux/profile/pb_profile.h
@@ -58,9 +58,9 @@ int pbp_write_file(const char *path, const char *data, char *err, size_t errle
// Atomic (temporary file + rename), mode 0600 because the file holds proxy credentials.
int pbp_save_file(const char *path, const struct pbp_profile *p, char *err, size_t errlen);
-// settings.json next to the profiles: which profile is active, plus the GUI-wide switches (absent keys keep the defaults).
-int pbp_settings_load(const char *path, char **active, bool *logging, bool *dns); // -1 if missing or unreadable
-int pbp_settings_save(const char *path, const char *active, bool logging, bool dns, char *err, size_t errlen);
+// settings.json next to the profiles holds only the name of the active profile; everything else lives in the profile files.
+int pbp_settings_load(const char *path, char **active); // -1 if missing or unreadable
+int pbp_settings_save(const char *path, const char *active, char *err, size_t errlen);
// Profile name <-> file name inside a profiles directory (percent-encoding, so any name is safe).
char *pbp_filename_for(const char *name); // malloc'd, includes the extension
diff --git a/Linux/tests/gui_headless.sh b/Linux/tests/gui_headless.sh
index 68da172..7db459a 100755
--- a/Linux/tests/gui_headless.sh
+++ b/Linux/tests/gui_headless.sh
@@ -52,7 +52,7 @@ chmod 600 "$WORK/cfg/config.ini"
run_gui() { # active profile
if [ ! -d "$WORK/cfg/profiles" ]; then write_cfg "$1"
- else printf '{ "ActiveProfileName": "%s", "IsTrafficLoggingEnabled": true, "DnsViaProxy": true }\n' "$1" > "$WORK/cfg/settings.json"; fi
+ else printf '{ "ActiveProfileName": "%s" }\n' "$1" > "$WORK/cfg/settings.json"; fi
GDK_BACKEND=broadway BROADWAY_DISPLAY=:9 PROXYBRIDGE_CONFIG_DIR="$WORK/cfg" LD_LIBRARY_PATH="$LIBDIR" "$GUI" > "$WORK/gui.out" 2>&1 & GUI_PID=$!
for _ in $(seq 60); do "${BPFTOOL:-bpftool}" prog show 2>/dev/null | grep -q pb_connect4 && break; kill -0 $GUI_PID 2>/dev/null || break; sleep 0.25; done
sleep 1
@@ -87,6 +87,9 @@ P="$WORK/cfg/profiles"
grep -q '"ActiveProfileName": "Alt"' "$WORK/cfg/settings.json" && ok "settings.json remembers the active profile" || bad "settings.json: $(cat "$WORK/cfg/settings.json")"
grep -q '"ProxyConfigs"' "$P/Default.pbprofile" && grep -q '"TargetDomains": "\*.example.test"' "$P/Default.pbprofile" && grep -q '"Version": "1.0"' "$P/Default.pbprofile" \
&& ok "the saved profile uses the Windows/macOS format (domain rule in TargetDomains)" || bad "profile format: $(head -40 "$P/Default.pbprofile")"
+grep -q '"IsTrafficLoggingEnabled": true' "$P/Default.pbprofile" && grep -q '"DnsViaProxy": true' "$P/Default.pbprofile" \
+ && [ "$(grep -c . "$WORK/cfg/settings.json")" -le 4 ] && ! grep -q Dns "$WORK/cfg/settings.json" \
+ && ok "logging and DNS switches live in the profile; settings.json only names the active profile" || bad "switches placement"
[ "$(stat -c %a "$P/Default.pbprofile")" = 600 ] && [ "$(stat -c %a "$P")" = 700 ] && ok "profile files are 0600 in a 0700 directory" || bad "profile permissions"
echo "== a profile exported by the Windows app, dropped into the profiles directory"