From d21b0bf01a1b319259d086f49927224edf57963f Mon Sep 17 00:00:00 2001 From: thek4n Date: Tue, 5 Dec 2023 14:48:25 +0300 Subject: [PATCH] update bash function --- home/user/.config/bash/functions | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/home/user/.config/bash/functions b/home/user/.config/bash/functions index cc20286..be6904c 100644 --- a/home/user/.config/bash/functions +++ b/home/user/.config/bash/functions @@ -131,15 +131,20 @@ vpn() { } toggle-ssh-proxy() { - if [ -v http_proxy ]; then + SSH_PROXY_CONTROL_FILE="$XDG_RUNTIME_DIR/ssh_$1_proxy.control" + + if [ -z "$1" ]; then + echo "Proxy ssh server hostname not specified" 1>&2 + return 1 + fi + + if [ -e "$SSH_PROXY_CONTROL_FILE" ]; then unset {http,https,ftp,rsync,no}_proxy + ssh -S "$SSH_PROXY_CONTROL_FILE" -O exit "$1" + unset SSH_PROXY_PID echo "Disabled" else - if [ -z "$1" ]; then - echo "Proxy ssh server hostname not specified" 1>&2 - return 1 - fi - ssh -vCTN -D 1080 "$1" 1>/dev/null 2>&1 & + ssh -nCTN -S "$SSH_PROXY_CONTROL_FILE" -D 1080 "$1" export {http,https,ftp,rsync}_proxy="socks5://127.0.0.1:1080" && \ export no_proxy="localhost,127.0.0.1/8,localaddress,.localdomain.com,192.168.0.0/16,10.0.0.0/8,172.16.0.0/12" echo "Enabled"