feat(wip): amnezia-wg 3.1 support
This commit is contained in:
29 files changed
+4092
-12
No files matched your search
@@ -0,0 +1,50 @@
|
||||
{ pkgs }:
|
||||
|
||||
let
|
||||
# Tools and the kernel module currently publish 3.1.20260812, while the
|
||||
# userspace implementation has follow-up 3.1 fixes through 20260828.
|
||||
# nixpkgs itself still tracks AWG 3.0.
|
||||
version = "3.1.20260812";
|
||||
userspaceVersion = "3.1.20260828";
|
||||
tools = pkgs.amneziawg-tools.overrideAttrs (old: {
|
||||
inherit version;
|
||||
src = pkgs.fetchFromGitHub {
|
||||
owner = "amnezia-vpn";
|
||||
repo = "amneziawg-tools";
|
||||
tag = "v${version}";
|
||||
hash = "sha256-6GEb41ERhR0Hg3RbSyIHdXPSKaxugoFCmFS5S0UiZso=";
|
||||
};
|
||||
patches = (old.patches or [ ]) ++ [ ./patches/amneziawg-tools-force-userspace.patch ];
|
||||
});
|
||||
userspace = pkgs.amneziawg-go.overrideAttrs (_: {
|
||||
version = userspaceVersion;
|
||||
src = pkgs.fetchFromGitHub {
|
||||
owner = "amnezia-vpn";
|
||||
repo = "amneziawg-go";
|
||||
tag = "v${userspaceVersion}";
|
||||
hash = "sha256-vZb72SA+6v8FXZX247K05yiVEBWpLqAAIyw6bEE4eUQ=";
|
||||
};
|
||||
patches = [ ./patches/amneziawg-go-random-trailers-transport.patch ];
|
||||
# The 3.1 releases keep the dependency set used by nixpkgs' 3.0 package.
|
||||
vendorHash = "sha256-Y2dCwlKMVLrkzDcNKyCPxFJwMbCA2mQKkakvzwbamCY=";
|
||||
});
|
||||
|
||||
kernelModule = kernelPackages: kernelPackages.amneziawg.overrideAttrs (_: {
|
||||
inherit version;
|
||||
src = pkgs.fetchFromGitHub {
|
||||
owner = "amnezia-vpn";
|
||||
repo = "amneziawg-linux-kernel-module";
|
||||
tag = "v${version}";
|
||||
hash = "sha256-dJ7Au4J8iPlphSzTa3Gol/LMlroroSc2IUmXZfjA0k8=";
|
||||
};
|
||||
});
|
||||
in
|
||||
{
|
||||
inherit
|
||||
version
|
||||
userspaceVersion
|
||||
tools
|
||||
userspace
|
||||
kernelModule
|
||||
;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
{ pkgs }:
|
||||
let
|
||||
amneziaWg = import ./amneziawg.nix { inherit pkgs; };
|
||||
mkTgWsProxy = _args: import ./tg-ws-proxy.nix { inherit pkgs; };
|
||||
mkProxySuiteTray = args: import ./proxy-suite-tray.nix ({ inherit pkgs; } // args);
|
||||
mkProxyCtl = import ./proxy-ctl.nix {
|
||||
@@ -8,6 +9,9 @@ let
|
||||
};
|
||||
in
|
||||
{
|
||||
inherit amneziaWg;
|
||||
amneziawg-tools = amneziaWg.tools;
|
||||
amneziawg-go = amneziaWg.userspace;
|
||||
inherit
|
||||
mkTgWsProxy
|
||||
mkProxySuiteTray
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
diff --git a/device/receive.go b/device/receive.go
|
||||
index d1901f8..8d709bf 100644
|
||||
--- a/device/receive.go
|
||||
+++ b/device/receive.go
|
||||
@@ -124,8 +124,18 @@ func (device *Device) RoutineReceiveIncoming(
|
||||
cip.XORKeyStream(typeHash, typeHash)
|
||||
}
|
||||
|
||||
- // get message padding and type based on information from S1-S4 and H1-H4
|
||||
- msgSize, msgType, padding := device.DeterminePacketTypeAndPadding(packet, typeHash)
|
||||
+ // A transport packet can also match a ranged H1-H3 value when random
|
||||
+ // handshake trailers are enabled. Prefer an H4 candidate only when its
|
||||
+ // decrypted receiver index belongs to this device; otherwise retain the
|
||||
+ // normal handshake classification. This avoids silently sending valid
|
||||
+ // transport packets to the handshake queue where MAC1 rejects them.
|
||||
+ msgSize, msgType, padding := 0, uint32(MessageUnknownType), uint32(0)
|
||||
+ if transportPadding, ok := device.DetermineTransportCandidate(packet); ok {
|
||||
+ msgSize, msgType, padding = MessageTransportSize, MessageTransportType, transportPadding
|
||||
+ } else {
|
||||
+ // get message padding and type based on information from S1-S4 and H1-H4
|
||||
+ msgSize, msgType, padding = device.DeterminePacketTypeAndPadding(packet, typeHash)
|
||||
+ }
|
||||
|
||||
packet = packet[padding:]
|
||||
if msgType != MessageTransportType {
|
||||
@@ -590,6 +600,42 @@ func applyHash(dst, src, hash []byte) {
|
||||
}
|
||||
}
|
||||
|
||||
+// DetermineTransportCandidate recognizes transport packets before the ranged
|
||||
+// handshake classifier. A range match by itself is ambiguous, so also require
|
||||
+// the decrypted receiver index to identify a keypair owned by this device.
|
||||
+func (device *Device) DetermineTransportCandidate(packet []byte) (uint32, bool) {
|
||||
+ padding := device.paddings.transport.Load()
|
||||
+ if len(packet) < int(padding)+MessageTransportSize {
|
||||
+ return 0, false
|
||||
+ }
|
||||
+
|
||||
+ header := make([]byte, MessageTransportHeaderSize)
|
||||
+ copy(header, packet[padding:padding+MessageTransportHeaderSize])
|
||||
+
|
||||
+ cip, err := device.HeaderProtectionCipher(packet[:HeaderCipherNonceSize])
|
||||
+ if err != nil {
|
||||
+ return 0, false
|
||||
+ }
|
||||
+ if cip != nil {
|
||||
+ cip.XORKeyStream(header, header)
|
||||
+ }
|
||||
+
|
||||
+ transportHeader := device.headers.transport.Load()
|
||||
+ if !transportHeader.Contains(binary.LittleEndian.Uint32(header[:4])) {
|
||||
+ return 0, false
|
||||
+ }
|
||||
+
|
||||
+ receiver := binary.LittleEndian.Uint32(
|
||||
+ header[MessageTransportOffsetReceiver:MessageTransportOffsetCounter],
|
||||
+ )
|
||||
+ value := device.indexTable.Lookup(receiver)
|
||||
+ if value.keypair == nil || value.peer == nil {
|
||||
+ return 0, false
|
||||
+ }
|
||||
+
|
||||
+ return padding, true
|
||||
+}
|
||||
+
|
||||
func (device *Device) DeterminePacketTypeAndPadding(packet []byte, typeHash []byte) (int, uint32, uint32) {
|
||||
var headerBytes [4]byte
|
||||
var padding uint32
|
||||
@@ -0,0 +1,17 @@
|
||||
diff --git a/wg-quick/linux.bash b/wg-quick/linux.bash
|
||||
index 20c820d..af0aef0 100755
|
||||
--- a/wg-quick/linux.bash
|
||||
+++ b/wg-quick/linux.bash
|
||||
@@ -87,7 +87,11 @@ auto_su() {
|
||||
|
||||
add_if() {
|
||||
local ret
|
||||
- if ! cmd ip link add "$INTERFACE" type amneziawg; then
|
||||
+ if [[ ${WG_QUICK_FORCE_USERSPACE_IMPLEMENTATION:-0} == 1 ]]; then
|
||||
+ command -v "${WG_QUICK_USERSPACE_IMPLEMENTATION:-amneziawg-go}" >/dev/null || exit 1
|
||||
+ echo "[!] Using the userspace AmneziaWG implementation for this configuration." >&2
|
||||
+ cmd "${WG_QUICK_USERSPACE_IMPLEMENTATION:-amneziawg-go}" "$INTERFACE"
|
||||
+ elif ! cmd ip link add "$INTERFACE" type amneziawg; then
|
||||
ret=$?
|
||||
[[ -e /sys/module/amneziawg ]] || ! command -v "${WG_QUICK_USERSPACE_IMPLEMENTATION:-amneziawg-go}" >/dev/null && exit $ret
|
||||
echo "[!] Missing WireGuard (Amnezia VPN) kernel module. Falling back to slow userspace implementation." >&2
|
||||
@@ -7,6 +7,38 @@ ALL_SERVICES=(
|
||||
zapret-discord-youtube
|
||||
)
|
||||
|
||||
_awg_service() {
|
||||
printf 'proxy-suite-awg-%s' "$1"
|
||||
}
|
||||
|
||||
_awg_profile_exists() {
|
||||
local wanted="$1" profile
|
||||
for profile in "${AWG_PROFILES[@]}"; do
|
||||
if [ "$profile" = "$wanted" ]; then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
_require_awg_profile() {
|
||||
local profile="$1"
|
||||
if ! _awg_profile_exists "$profile"; then
|
||||
echo "Unknown AmneziaWG profile: $profile" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
_active_awg_profiles() {
|
||||
local profile service
|
||||
for profile in "${AWG_PROFILES[@]}"; do
|
||||
service="$(_awg_service "$profile")"
|
||||
if _svc_active "$service"; then
|
||||
printf '%s\n' "$profile"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
_usage() {
|
||||
local status="${1:-1}"
|
||||
echo "Usage: proxy-ctl <command> [args]"
|
||||
@@ -17,6 +49,10 @@ _usage() {
|
||||
echo " proxy on|off enable/disable the proxy backend stack"
|
||||
echo " tproxy on|off enable/disable TProxy transparent mode"
|
||||
echo " tun on|off enable/disable TUN mode"
|
||||
echo " awg list|status [profile] list profiles or show AmneziaWG status"
|
||||
echo " awg on <profile> start an AmneziaWG profile"
|
||||
echo " awg off [profile] stop one or all active AmneziaWG profiles"
|
||||
echo " awg restart [profile] restart one or all active AmneziaWG profiles"
|
||||
echo " route-mode default|whitelist|blacklist|all-proxy|all-bypass|status"
|
||||
echo " set temporary routing override"
|
||||
echo " zapret on|off enable/disable zapret-discord-youtube"
|
||||
@@ -139,6 +175,9 @@ _status_tray() {
|
||||
printf 'route_mode_available=%s\n' "$(_bool _svc_exists proxy-suite-socks)"
|
||||
printf 'route_mode=%s\n' "$(_route_mode_current)"
|
||||
printf 'default_route_mode=%s\n' "$(_route_mode_default)"
|
||||
printf 'awg_available=%s\n' "$(_bool test "${#AWG_PROFILES[@]}" -gt 0)"
|
||||
printf 'awg_active=%s\n' "$(_active_awg_profiles | head -n1)"
|
||||
printf 'awg_profiles=%s\n' "$(IFS=,; echo "${AWG_PROFILES[*]}")"
|
||||
}
|
||||
|
||||
_ensure_app_routing() {
|
||||
@@ -246,6 +285,9 @@ cmd_status() {
|
||||
for svc in "${ALL_SERVICES[@]}"; do
|
||||
_svc_status "$svc"
|
||||
done
|
||||
for profile in "${AWG_PROFILES[@]}"; do
|
||||
_svc_status "$(_awg_service "$profile")"
|
||||
done
|
||||
if _svc_exists proxy-suite-socks; then
|
||||
echo ""
|
||||
echo "routing:"
|
||||
@@ -335,6 +377,80 @@ cmd_restart() {
|
||||
systemctl restart "$svc"
|
||||
fi
|
||||
done
|
||||
local profile
|
||||
for profile in "${AWG_PROFILES[@]}"; do
|
||||
if _svc_active "$(_awg_service "$profile")"; then
|
||||
systemctl restart "$(_awg_service "$profile")"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
cmd_awg() {
|
||||
local action="${1:-list}" profile service active
|
||||
shift || true
|
||||
|
||||
case "$action" in
|
||||
list)
|
||||
if [ "${#AWG_PROFILES[@]}" -eq 0 ]; then
|
||||
echo "No AmneziaWG profiles configured."
|
||||
return
|
||||
fi
|
||||
printf " %-24s %s\n" "PROFILE" "STATUS"
|
||||
for profile in "${AWG_PROFILES[@]}"; do
|
||||
service="$(_awg_service "$profile")"
|
||||
active="$(systemctl is-active "$service" 2>/dev/null || true)"
|
||||
printf " %-24s %s\n" "$profile" "${active:-unknown}"
|
||||
done
|
||||
;;
|
||||
status)
|
||||
if [ "$#" -gt 0 ]; then
|
||||
profile="$1"
|
||||
_require_awg_profile "$profile"
|
||||
systemctl is-active "$(_awg_service "$profile")"
|
||||
else
|
||||
_active_awg_profiles
|
||||
fi
|
||||
;;
|
||||
on)
|
||||
profile="${1:?Usage: proxy-ctl awg on <profile>}"
|
||||
_require_awg_profile "$profile"
|
||||
systemctl start "$(_awg_service "$profile")"
|
||||
;;
|
||||
off)
|
||||
if [ "$#" -gt 0 ]; then
|
||||
profile="$1"
|
||||
_require_awg_profile "$profile"
|
||||
systemctl stop "$(_awg_service "$profile")"
|
||||
else
|
||||
for profile in "${AWG_PROFILES[@]}"; do
|
||||
service="$(_awg_service "$profile")"
|
||||
if _svc_active "$service"; then
|
||||
systemctl stop "$service"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
;;
|
||||
restart)
|
||||
if [ "$#" -gt 0 ]; then
|
||||
profile="$1"
|
||||
_require_awg_profile "$profile"
|
||||
systemctl restart "$(_awg_service "$profile")"
|
||||
else
|
||||
active="$(_active_awg_profiles)"
|
||||
if [ -z "$active" ]; then
|
||||
echo "No AmneziaWG profile is active." >&2
|
||||
exit 1
|
||||
fi
|
||||
while IFS= read -r profile; do
|
||||
systemctl restart "$(_awg_service "$profile")"
|
||||
done <<< "$active"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "Usage: proxy-ctl awg list|status [profile]|on <profile>|off [profile]|restart [profile]" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
cmd_outbounds() {
|
||||
|
||||
+5
-1
@@ -18,6 +18,7 @@
|
||||
proxychainsQuietArg,
|
||||
routeModeStateFile,
|
||||
defaultRouteMode,
|
||||
amneziaWgProfileNamesFile,
|
||||
}:
|
||||
|
||||
let
|
||||
@@ -39,6 +40,7 @@ let
|
||||
PROXYCHAINS_QUIET_ARG = lib.removeSuffix " " proxychainsQuietArg;
|
||||
ROUTE_MODE_STATE_FILE = routeModeStateFile;
|
||||
DEFAULT_ROUTE_MODE = defaultRouteMode;
|
||||
AWG_PROFILES_FILE = toString amneziaWgProfileNamesFile;
|
||||
};
|
||||
in
|
||||
pkgs.symlinkJoin {
|
||||
@@ -51,6 +53,7 @@ pkgs.symlinkJoin {
|
||||
subscriptionTagsFile
|
||||
perAppRoutingProfilesFile
|
||||
proxychainsConfigFile
|
||||
amneziaWgProfileNamesFile
|
||||
;
|
||||
script = unwrapped.drvAttrs.text;
|
||||
};
|
||||
@@ -80,6 +83,7 @@ pkgs.symlinkJoin {
|
||||
--set PROXYCHAINS_CONFIG ${lib.escapeShellArg (toString proxychainsConfigFile)} \
|
||||
--set PROXYCHAINS_QUIET_ARG ${lib.escapeShellArg (lib.removeSuffix " " proxychainsQuietArg)} \
|
||||
--set ROUTE_MODE_STATE_FILE ${lib.escapeShellArg routeModeStateFile} \
|
||||
--set DEFAULT_ROUTE_MODE ${lib.escapeShellArg defaultRouteMode}
|
||||
--set DEFAULT_ROUTE_MODE ${lib.escapeShellArg defaultRouteMode} \
|
||||
--set AWG_PROFILES_FILE ${lib.escapeShellArg (toString amneziaWgProfileNamesFile)}
|
||||
'';
|
||||
}
|
||||
@@ -2,13 +2,19 @@ set -euo pipefail
|
||||
|
||||
# Wrapped binary provides runtime config through env vars.
|
||||
SUB_TAGS_FILE="${SUB_TAGS_FILE:-}"
|
||||
AWG_PROFILES_FILE="${AWG_PROFILES_FILE:-}"
|
||||
PROXYCHAINS_QUIET_ARG="${PROXYCHAINS_QUIET_ARG:-}"
|
||||
SUB_TAGS=()
|
||||
AWG_PROFILES=()
|
||||
|
||||
if [ -n "$SUB_TAGS_FILE" ] && [ -f "$SUB_TAGS_FILE" ]; then
|
||||
mapfile -t SUB_TAGS < <(jq -r '.[]' "$SUB_TAGS_FILE")
|
||||
fi
|
||||
|
||||
if [ -n "$AWG_PROFILES_FILE" ] && [ -f "$AWG_PROFILES_FILE" ]; then
|
||||
mapfile -t AWG_PROFILES < <(jq -r '.[]' "$AWG_PROFILES_FILE")
|
||||
fi
|
||||
|
||||
cmd="${1:-status}"
|
||||
shift || true
|
||||
|
||||
@@ -33,6 +39,10 @@ case "$cmd" in
|
||||
cmd_mode_toggle proxy-suite-tun on "${1:-}"
|
||||
;;
|
||||
|
||||
awg)
|
||||
cmd_awg "$@"
|
||||
;;
|
||||
|
||||
route-mode)
|
||||
cmd_route_mode "$@"
|
||||
;;
|
||||
|
||||
@@ -21,6 +21,7 @@ static GtkWidget *route_mode_item;
|
||||
static GtkWidget *route_mode_items[ROUTE_MODE_CHOICE_COUNT];
|
||||
static GtkWidget *tproxy_item;
|
||||
static GtkWidget *tun_item;
|
||||
static GtkWidget *awg_item;
|
||||
static GtkWidget *zapret_item;
|
||||
static GtkWidget *open_controls_item;
|
||||
static GtkWidget *controls_window;
|
||||
@@ -29,12 +30,18 @@ static GtkWidget *controls_core_status_label;
|
||||
static GtkWidget *controls_route_mode_status_label;
|
||||
static GtkWidget *controls_route_mode_combo;
|
||||
static GtkWidget *controls_traffic_status_label;
|
||||
static GtkWidget *controls_awg_status_label;
|
||||
static GtkWidget *controls_awg_combo;
|
||||
static GtkWidget *controls_zapret_status_label;
|
||||
static GtkWidget *controls_proxy_button;
|
||||
static GtkWidget *controls_tproxy_button;
|
||||
static GtkWidget *controls_tun_button;
|
||||
static GtkWidget *controls_zapret_button;
|
||||
static gboolean updating_route_mode_widgets = FALSE;
|
||||
static gboolean updating_awg_widgets = FALSE;
|
||||
static gchar **awg_profile_names;
|
||||
static GtkWidget **awg_profile_items;
|
||||
static gsize awg_profile_count;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
@@ -67,12 +74,15 @@ typedef struct
|
||||
gboolean socks_available;
|
||||
gboolean tproxy_available;
|
||||
gboolean tun_available;
|
||||
gboolean awg_available;
|
||||
gboolean zapret_available;
|
||||
gboolean subscription_update_available;
|
||||
gboolean route_mode_available;
|
||||
gboolean socks;
|
||||
gboolean tproxy;
|
||||
gboolean tun;
|
||||
gchar awg_active[64];
|
||||
gchar awg_profiles[1024];
|
||||
gboolean zapret;
|
||||
RouteMode route_mode;
|
||||
RouteMode default_route_mode;
|
||||
@@ -201,6 +211,17 @@ static gboolean run_proxy_ctl(const char *arg1, const char *arg2)
|
||||
return proxy_ctl_command(arg1, arg2, NULL);
|
||||
}
|
||||
|
||||
static gboolean run_proxy_ctl3(const char *arg1, const char *arg2, const char *arg3)
|
||||
{
|
||||
gchar *argv[] = {
|
||||
(gchar *)PROXY_CTL_BIN,
|
||||
(gchar *)arg1,
|
||||
(gchar *)arg2,
|
||||
(gchar *)arg3,
|
||||
NULL};
|
||||
return command_succeeds(argv);
|
||||
}
|
||||
|
||||
static gboolean parse_proxy_ctl_bool(const char *value)
|
||||
{
|
||||
return value && strcmp(value, "true") == 0;
|
||||
@@ -307,6 +328,18 @@ static ServiceState get_service_state(void)
|
||||
{
|
||||
state.tun = parse_proxy_ctl_bool(parts[1]);
|
||||
}
|
||||
else if (strcmp(parts[0], "awg_available") == 0)
|
||||
{
|
||||
state.awg_available = parse_proxy_ctl_bool(parts[1]);
|
||||
}
|
||||
else if (strcmp(parts[0], "awg_active") == 0)
|
||||
{
|
||||
g_strlcpy(state.awg_active, parts[1], sizeof(state.awg_active));
|
||||
}
|
||||
else if (strcmp(parts[0], "awg_profiles") == 0)
|
||||
{
|
||||
g_strlcpy(state.awg_profiles, parts[1], sizeof(state.awg_profiles));
|
||||
}
|
||||
else if (strcmp(parts[0], "zapret_available") == 0)
|
||||
{
|
||||
state.zapret_available = parse_proxy_ctl_bool(parts[1]);
|
||||
@@ -343,6 +376,10 @@ static ServiceState get_service_state(void)
|
||||
|
||||
static const char *traffic_mode_label(const ServiceState *state)
|
||||
{
|
||||
if (state->awg_active[0] != '\0')
|
||||
{
|
||||
return "AmneziaWG tunnel enabled";
|
||||
}
|
||||
if (state->tun)
|
||||
{
|
||||
return "TUN tunnel enabled";
|
||||
@@ -408,13 +445,37 @@ static void sync_route_mode_widgets(RouteMode mode)
|
||||
updating_route_mode_widgets = FALSE;
|
||||
}
|
||||
|
||||
static void sync_awg_widgets(const char *active_profile)
|
||||
{
|
||||
updating_awg_widgets = TRUE;
|
||||
if (awg_profile_items)
|
||||
{
|
||||
gtk_check_menu_item_set_active(
|
||||
GTK_CHECK_MENU_ITEM(awg_profile_items[0]),
|
||||
!active_profile || active_profile[0] == '\0');
|
||||
for (gsize i = 0; i < awg_profile_count; ++i)
|
||||
{
|
||||
gtk_check_menu_item_set_active(
|
||||
GTK_CHECK_MENU_ITEM(awg_profile_items[i + 1]),
|
||||
active_profile && strcmp(active_profile, awg_profile_names[i]) == 0);
|
||||
}
|
||||
}
|
||||
if (controls_awg_combo)
|
||||
{
|
||||
gtk_combo_box_set_active_id(
|
||||
GTK_COMBO_BOX(controls_awg_combo),
|
||||
active_profile && active_profile[0] != '\0' ? active_profile : "off");
|
||||
}
|
||||
updating_awg_widgets = FALSE;
|
||||
}
|
||||
|
||||
static const char *indicator_label_text(const ServiceState *state)
|
||||
{
|
||||
if (state->socks && (state->tproxy || state->tun) && state->zapret)
|
||||
if (state->socks && (state->tproxy || state->tun || state->awg_active[0] != '\0') && state->zapret)
|
||||
{
|
||||
return "Proxy + traffic + zapret";
|
||||
}
|
||||
if (state->socks && (state->tproxy || state->tun))
|
||||
if (state->socks && (state->tproxy || state->tun || state->awg_active[0] != '\0'))
|
||||
{
|
||||
return "Proxy + traffic";
|
||||
}
|
||||
@@ -426,6 +487,10 @@ static const char *indicator_label_text(const ServiceState *state)
|
||||
{
|
||||
return "Proxy only";
|
||||
}
|
||||
if (state->awg_active[0] != '\0')
|
||||
{
|
||||
return "AmneziaWG";
|
||||
}
|
||||
if (state->zapret)
|
||||
{
|
||||
return "Zapret only";
|
||||
@@ -500,6 +565,10 @@ static void update_status(void)
|
||||
{
|
||||
gtk_label_set_text(GTK_LABEL(controls_traffic_status_label), "[Traffic] Mode: Unknown");
|
||||
}
|
||||
if (controls_awg_status_label)
|
||||
{
|
||||
gtk_label_set_text(GTK_LABEL(controls_awg_status_label), "[AmneziaWG] Profile: Unknown");
|
||||
}
|
||||
if (controls_route_mode_status_label)
|
||||
{
|
||||
gtk_label_set_text(GTK_LABEL(controls_route_mode_status_label), "[Routing] Mode: Unknown");
|
||||
@@ -526,11 +595,14 @@ static void update_status(void)
|
||||
state.socks ? "Running" : "Stopped");
|
||||
gchar *route_mode_text = g_strdup_printf("[Routing] Mode: %s", route_mode);
|
||||
gchar *traffic_text = g_strdup_printf("[Traffic] Mode: %s", traffic);
|
||||
gchar *awg_text = g_strdup_printf(
|
||||
"[AmneziaWG] Profile: %s",
|
||||
state.awg_active[0] != '\0' ? state.awg_active : "Off");
|
||||
gchar *zapret_text = g_strdup_printf(
|
||||
"[Zapret] zapret-discord-youtube: %s",
|
||||
zapret);
|
||||
|
||||
if (state.tproxy || state.tun)
|
||||
if (state.tproxy || state.tun || state.awg_active[0] != '\0')
|
||||
{
|
||||
app_indicator_set_icon(
|
||||
indicator,
|
||||
@@ -582,6 +654,10 @@ static void update_status(void)
|
||||
{
|
||||
gtk_label_set_text(GTK_LABEL(controls_traffic_status_label), traffic_text);
|
||||
}
|
||||
if (controls_awg_status_label)
|
||||
{
|
||||
gtk_label_set_text(GTK_LABEL(controls_awg_status_label), awg_text);
|
||||
}
|
||||
if (controls_zapret_status_label)
|
||||
{
|
||||
gtk_label_set_text(GTK_LABEL(controls_zapret_status_label), zapret_text);
|
||||
@@ -619,6 +695,15 @@ static void update_status(void)
|
||||
gtk_menu_item_set_label(GTK_MENU_ITEM(tun_item),
|
||||
state.tun ? "[Traffic] Stop TUN Mode" : "[Traffic] Start TUN Mode");
|
||||
}
|
||||
if (awg_item)
|
||||
{
|
||||
gchar *label = g_strdup_printf(
|
||||
"[Traffic] AmneziaWG: %s",
|
||||
state.awg_active[0] != '\0' ? state.awg_active : "Off");
|
||||
gtk_menu_item_set_label(GTK_MENU_ITEM(awg_item), label);
|
||||
g_free(label);
|
||||
sync_awg_widgets(state.awg_active);
|
||||
}
|
||||
if (controls_tun_button)
|
||||
{
|
||||
gtk_button_set_label(GTK_BUTTON(controls_tun_button),
|
||||
@@ -641,6 +726,7 @@ static void update_status(void)
|
||||
g_free(core_text);
|
||||
g_free(route_mode_text);
|
||||
g_free(traffic_text);
|
||||
g_free(awg_text);
|
||||
g_free(zapret_text);
|
||||
}
|
||||
|
||||
@@ -732,6 +818,44 @@ static void on_tun_toggle(GtkWidget *item, gpointer data)
|
||||
update_status();
|
||||
}
|
||||
|
||||
static void set_awg_profile(const char *profile)
|
||||
{
|
||||
if (profile && profile[0] != '\0' && strcmp(profile, "off") != 0)
|
||||
{
|
||||
run_proxy_ctl3("awg", "on", profile);
|
||||
}
|
||||
else
|
||||
{
|
||||
run_proxy_ctl("awg", "off");
|
||||
}
|
||||
}
|
||||
|
||||
static void on_awg_menu_toggled(GtkCheckMenuItem *item, gpointer data)
|
||||
{
|
||||
if (updating_awg_widgets || !gtk_check_menu_item_get_active(item))
|
||||
{
|
||||
return;
|
||||
}
|
||||
set_awg_profile((const char *)data);
|
||||
update_status();
|
||||
}
|
||||
|
||||
static void on_awg_combo_changed(GtkComboBox *combo, gpointer data)
|
||||
{
|
||||
(void)data;
|
||||
if (updating_awg_widgets)
|
||||
{
|
||||
return;
|
||||
}
|
||||
const gchar *profile = gtk_combo_box_get_active_id(combo);
|
||||
if (!profile)
|
||||
{
|
||||
return;
|
||||
}
|
||||
set_awg_profile(profile);
|
||||
update_status();
|
||||
}
|
||||
|
||||
static void on_zapret_toggle(GtkWidget *item, gpointer data)
|
||||
{
|
||||
(void)item;
|
||||
@@ -867,6 +991,25 @@ static void build_controls_window(void)
|
||||
gtk_box_pack_start(GTK_BOX(traffic_box), controls_tun_button, FALSE, FALSE, 0);
|
||||
}
|
||||
|
||||
if (initial_state.awg_available)
|
||||
{
|
||||
controls_awg_status_label = gtk_label_new("[AmneziaWG] Profile: Off");
|
||||
gtk_label_set_xalign(GTK_LABEL(controls_awg_status_label), 0.0f);
|
||||
gtk_box_pack_start(GTK_BOX(traffic_box), controls_awg_status_label, FALSE, FALSE, 0);
|
||||
|
||||
controls_awg_combo = gtk_combo_box_text_new();
|
||||
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(controls_awg_combo), "off", "AmneziaWG Off");
|
||||
for (gsize i = 0; i < awg_profile_count; ++i)
|
||||
{
|
||||
gtk_combo_box_text_append(
|
||||
GTK_COMBO_BOX_TEXT(controls_awg_combo),
|
||||
awg_profile_names[i],
|
||||
awg_profile_names[i]);
|
||||
}
|
||||
g_signal_connect(controls_awg_combo, "changed", G_CALLBACK(on_awg_combo_changed), NULL);
|
||||
gtk_box_pack_start(GTK_BOX(traffic_box), controls_awg_combo, FALSE, FALSE, 0);
|
||||
}
|
||||
|
||||
if (initial_state.zapret_available)
|
||||
{
|
||||
GtkWidget *zapret_frame = gtk_frame_new("[Zapret] DPI bypass");
|
||||
@@ -971,6 +1114,40 @@ static void build_menu(void)
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(menu), tun_item);
|
||||
}
|
||||
|
||||
|
||||
if (initial_state.awg_available)
|
||||
{
|
||||
awg_item = gtk_menu_item_new_with_label("[Traffic] AmneziaWG: Off");
|
||||
GtkWidget *awg_menu = gtk_menu_new();
|
||||
GSList *awg_group = NULL;
|
||||
awg_profile_items = g_new0(GtkWidget *, awg_profile_count + 1);
|
||||
|
||||
awg_profile_items[0] = gtk_radio_menu_item_new_with_label(awg_group, "Off");
|
||||
g_signal_connect(
|
||||
awg_profile_items[0],
|
||||
"toggled",
|
||||
G_CALLBACK(on_awg_menu_toggled),
|
||||
(gpointer)"");
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(awg_menu), awg_profile_items[0]);
|
||||
awg_group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(awg_profile_items[0]));
|
||||
|
||||
for (gsize i = 0; i < awg_profile_count; ++i)
|
||||
{
|
||||
awg_profile_items[i + 1] = gtk_radio_menu_item_new_with_label(
|
||||
awg_group,
|
||||
awg_profile_names[i]);
|
||||
g_signal_connect(
|
||||
awg_profile_items[i + 1],
|
||||
"toggled",
|
||||
G_CALLBACK(on_awg_menu_toggled),
|
||||
awg_profile_names[i]);
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(awg_menu), awg_profile_items[i + 1]);
|
||||
awg_group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(awg_profile_items[i + 1]));
|
||||
}
|
||||
gtk_menu_item_set_submenu(GTK_MENU_ITEM(awg_item), awg_menu);
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(menu), awg_item);
|
||||
}
|
||||
|
||||
if (initial_state.zapret_available)
|
||||
{
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(menu), gtk_separator_menu_item_new());
|
||||
@@ -1035,6 +1212,11 @@ int main(int argc, char *argv[])
|
||||
app_indicator_set_status(indicator, APP_INDICATOR_STATUS_ACTIVE);
|
||||
|
||||
initial_state = get_service_state();
|
||||
if (initial_state.awg_profiles[0] != '\0')
|
||||
{
|
||||
awg_profile_names = g_strsplit(initial_state.awg_profiles, ",", -1);
|
||||
awg_profile_count = g_strv_length(awg_profile_names);
|
||||
}
|
||||
build_menu();
|
||||
build_controls_window();
|
||||
app_indicator_set_menu(indicator, GTK_MENU(menu));
|
||||
@@ -1045,5 +1227,7 @@ int main(int argc, char *argv[])
|
||||
g_timeout_add_seconds(POLL_INTERVAL, on_timer, NULL);
|
||||
|
||||
gtk_main();
|
||||
g_strfreev(awg_profile_names);
|
||||
g_free(awg_profile_items);
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user