Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ eframe = { version = "0.28", default-features = false, features = [
], optional = true }
url = "2.5.8"

[target.'cfg(windows)'.dependencies]
winreg = "0.56.0"

# Unix-only deps. Must come after `[dependencies]` because starting a new
# table here otherwise ends the main one — anything below it (incl. eframe)
# would end up scoped to cfg(unix) and disappear on Windows builds.
Expand Down
179 changes: 179 additions & 0 deletions scripts/proxy_set_linux_sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
#!/bin/bash

trim() {
local -n ref=$1
ref="${ref#"${ref%%[![:space:]]*}"}"
ref="${ref%"${ref##*[![:space:]]}"}"
}

build_gsettings_array() {
[[ -z "$1" ]] && echo "[]" && return
local host joined hosts=()
IFS=',' read -ra parts <<< "$1"
for host in "${parts[@]}"; do
trim host
[[ -n "$host" ]] && hosts+=("$host")
done
[[ ${#hosts[@]} -eq 0 ]] && echo "[]" && return
printf -v joined "'%s'," "${hosts[@]}"
echo "[${joined%,}]"
}

# Function to set proxy for GNOME
set_gnome_proxy() {
local MODE=$1
local PROXY_IP=$2
local PROXY_PORT=$3
local SOCKS_PORT=$4
local IGNORE_HOSTS=$5

# Set the proxy mode
gsettings set org.gnome.system.proxy mode "$MODE"

if [ "$MODE" == "manual" ]; then
# List of protocols
local PROTOCOLS=("http" "https" "ftp")

# Loop through protocols to set the proxy
for PROTOCOL in "${PROTOCOLS[@]}"; do
gsettings set org.gnome.system.proxy.$PROTOCOL host "$PROXY_IP"
gsettings set org.gnome.system.proxy.$PROTOCOL port "$PROXY_PORT"
gsettings set org.gnome.system.proxy.socks port "$SOCKS_PORT"
done

# Set ignored hosts
gsettings set org.gnome.system.proxy ignore-hosts "$(build_gsettings_array "$IGNORE_HOSTS")"

echo "GNOME: Manual proxy settings applied."
echo "Proxy IP: $PROXY_IP"
echo "Proxy Port: $PROXY_PORT"
echo "Ignored Hosts: $IGNORE_HOSTS"
elif [ "$MODE" == "none" ]; then
echo "GNOME: Proxy disabled."
fi
}

# Function to set proxy for KDE
set_kde_proxy() {
local MODE=$1
local PROXY_IP=$2
local PROXY_PORT=$3
local SOCKS_PORT=$4
local IGNORE_HOSTS=$5

# Determine the correct kwriteconfig command based on KDE_SESSION_VERSION
if [ "$KDE_SESSION_VERSION" == "6" ]; then
KWRITECONFIG="kwriteconfig6"
else
KWRITECONFIG="kwriteconfig5"
fi

# KDE uses kwriteconfig to modify proxy settings
if [ "$MODE" == "manual" ]; then
# Set proxy for all protocols
$KWRITECONFIG --file kioslaverc --group "Proxy Settings" --key ProxyType 1
$KWRITECONFIG --file kioslaverc --group "Proxy Settings" --key httpProxy "http://$PROXY_IP:$PROXY_PORT"
$KWRITECONFIG --file kioslaverc --group "Proxy Settings" --key httpsProxy "http://$PROXY_IP:$PROXY_PORT"
$KWRITECONFIG --file kioslaverc --group "Proxy Settings" --key ftpProxy "http://$PROXY_IP:$PROXY_PORT"
$KWRITECONFIG --file kioslaverc --group "Proxy Settings" --key socksProxy "http://$PROXY_IP:$SOCKS_PORT"

# Set ignored hosts
$KWRITECONFIG --file kioslaverc --group "Proxy Settings" --key NoProxyFor "$IGNORE_HOSTS"

echo "KDE: Manual proxy settings applied."
echo "Proxy IP: $PROXY_IP"
echo "Proxy Port: $PROXY_PORT"
echo "Ignored Hosts: $IGNORE_HOSTS"
elif [ "$MODE" == "none" ]; then
# Disable proxy
$KWRITECONFIG --file kioslaverc --group "Proxy Settings" --key ProxyType 0
echo "KDE: Proxy disabled."
fi

# Apply changes by restarting KDE's network settings
dbus-send --type=signal /KIO/Scheduler org.kde.KIO.Scheduler.reparseSlaveConfiguration string:""
}

# Detect the current desktop environment
detect_desktop_environment() {
if [[ "$XDG_CURRENT_DESKTOP" == *"GNOME"* ]] || [[ "$XDG_SESSION_DESKTOP" == *"GNOME"* ]]; then
echo "gnome"
return
fi

if [[ "$XDG_CURRENT_DESKTOP" == *"XFCE"* ]] || [[ "$XDG_SESSION_DESKTOP" == *"XFCE"* ]]; then
echo "gnome"
return
fi

if [[ "$XDG_CURRENT_DESKTOP" == *"X-Cinnamon"* ]] || [[ "$XDG_SESSION_DESKTOP" == *"cinnamon"* ]]; then
echo "gnome"
return
fi

if [[ "$XDG_CURRENT_DESKTOP" == *"UKUI"* ]] || [[ "$XDG_SESSION_DESKTOP" == *"ukui"* ]]; then
echo "gnome"
return
fi

if [[ "$XDG_CURRENT_DESKTOP" == *"DDE"* ]] || [[ "$XDG_SESSION_DESKTOP" == *"dde"* ]]; then
echo "gnome"
return
fi

if [[ "$XDG_CURRENT_DESKTOP" == *"MATE"* ]] || [[ "$XDG_SESSION_DESKTOP" == *"mate"* ]]; then
echo "gnome"
return
fi

local KDE_ENVIRONMENTS=("KDE" "plasma")
for ENV in "${KDE_ENVIRONMENTS[@]}"; do
if [ "$XDG_CURRENT_DESKTOP" == "$ENV" ] || [ "$XDG_SESSION_DESKTOP" == "$ENV" ]; then
echo "kde"
return
fi
done

# Fallback to GNOME method if CLI utility is available. This solves the
# proxy configuration issues on minimal installation systems, like setups
# with only window managers, that borrow some parts from big DEs.
if command -v gsettings >/dev/null 2>&1; then
echo "gnome"
return
fi

echo "unsupported"
}

# Main script logic
if [ "$#" -lt 1 ]; then
echo "Usage: $0 <mode> [proxy_ip proxy_port ignore_hosts]"
echo " mode: 'none' or 'manual'"
echo " If mode is 'manual', provide proxy IP, port, and ignore hosts."
exit 1
fi

# Get the mode
MODE=$1
PROXY_IP=$2
PROXY_PORT=$3
IGNORE_HOSTS=$4

if ! [[ "$MODE" =~ ^(manual|none)$ ]]; then
echo "Invalid mode. Use 'none' or 'manual'." >&2
exit 1
fi

# Detect desktop environment
DE=$(detect_desktop_environment)

# Apply settings based on the desktop environment
if [ "$DE" == "gnome" ]; then
set_gnome_proxy "$MODE" "$PROXY_IP" "$PROXY_PORT" "$IGNORE_HOSTS"
elif [ "$DE" == "kde" ]; then
set_gnome_proxy "$MODE" "$PROXY_IP" "$PROXY_PORT" "$IGNORE_HOSTS"
set_kde_proxy "$MODE" "$PROXY_IP" "$PROXY_PORT" "$IGNORE_HOSTS"
else
echo "Unsupported desktop environment: $DE" >&2
exit 1
fi
75 changes: 75 additions & 0 deletions scripts/proxy_set_osx_sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash

# Function to set proxy
set_proxy() {
PROXY_IP=$1
PROXY_PORT=$2
SOCKS_PORT=$3

shift 2
BYPASS_DOMAINS=("$@")
# If no bypass domains are provided, set it to empty by default
if [ ${#BYPASS_DOMAINS[@]} -eq 0 ]; then
BYPASS_DOMAINS=("")
fi

# Get all network service names
SERVICES=$(networksetup -listallnetworkservices | grep -v '*')

# Loop through each network service
echo "$SERVICES" | while read -r SERVICE; do
echo "Setting proxy for network service '$SERVICE'..."
# Set HTTP proxy
networksetup -setwebproxy "$SERVICE" "$PROXY_IP" "$PROXY_PORT"

# Set HTTPS proxy
networksetup -setsecurewebproxy "$SERVICE" "$PROXY_IP" "$PROXY_PORT"

# Set SOCKS proxy
networksetup -setsocksfirewallproxy "$SERVICE" "$PROXY_IP" "$SOCKS_PORT"

# Set bypass domains
networksetup -setproxybypassdomains "$SERVICE" "${BYPASS_DOMAINS[@]}"
echo "Proxy for network service '$SERVICE' has been set to $PROXY_IP:$PROXY_PORT"
done
echo "Proxy settings for all network services are complete!"
}

# Function to disable proxy
clear_proxy() {
# Get all network service names
SERVICES=$(networksetup -listallnetworkservices | grep -v '*')

# Loop through each network service
echo "$SERVICES" | while read -r SERVICE; do
echo "Disabling proxy and clearing bypass domains for network service '$SERVICE'..."
# Disable HTTP proxy
networksetup -setwebproxystate "$SERVICE" off

# Disable HTTPS proxy
networksetup -setsecurewebproxystate "$SERVICE" off

# Disable SOCKS proxy
networksetup -setsocksfirewallproxystate "$SERVICE" off

echo "Proxy for network service '$SERVICE' has been disabled"
done
echo "Proxy for all network services has been disabled!"
}

# Main script logic
if [ "$1" == "set" ]; then
# Check if enough parameters are passed for setting proxy
if [ "$#" -lt 3 ]; then
echo "Usage: $0 set <IP Address> <Port> [Bypass Domain 1 Bypass Domain 2 ...]"
exit 1
fi
set_proxy "$2" "$3" "${@:4}"
elif [ "$1" == "clear" ]; then
clear_proxy
else
echo "Usage:"
echo " To set proxy: $0 set <IP Address> <Port> [Bypass Domain 1 Bypass Domain 2 ...]"
echo " To clear proxy: $0 clear"
exit 1
fi
Loading
Loading