Archived
1
0

3 Commits
0.0.7 ... main

Author SHA1 Message Date
f938fd4d5b Add startall and stopall 2025-08-24 19:40:37 +02:00
759e7412c3 Add startall and stopall 2025-08-24 19:36:55 +02:00
1dfd3f090f Add status command 2025-08-24 05:08:13 +02:00
2 changed files with 30 additions and 12 deletions

View File

@@ -9,6 +9,8 @@ function showHelp() {
echo " status" echo " status"
echo " start profile|port target" echo " start profile|port target"
echo " stop port" echo " stop port"
echo " startall"
echo " stopall"
echo "cmd_args :" echo "cmd_args :"
echo " profile Name of the profile (~/.config/ssh-proxy/*)" echo " profile Name of the profile (~/.config/ssh-proxy/*)"
echo " port Proxy local port (1024-65535)" echo " port Proxy local port (1024-65535)"
@@ -24,7 +26,7 @@ case ${1} in
showHelp showHelp
exit 0 exit 0
;; ;;
"status");; "status" | "startall" | "stopall");;
"start" | "stop") "start" | "stop")
if [ "${2}" == "" ] || [[ "${2}" == */* ]]; then if [ "${2}" == "" ] || [[ "${2}" == */* ]]; then
showHelp showHelp
@@ -38,15 +40,15 @@ case ${1} in
esac esac
function showProxyStatus() { function showProxyStatus() {
echo -e "Port\tProxy" if [ -d /tmp/ssh-proxy-"${USER}" ] && [ "$(find /tmp/ssh-proxy-"${USER}" -maxdepth 0 -empty -exec echo 1 \;)" == "" ]; then
if [ -d /tmp/ssh-proxy-"${USER}" ]; then echo -e "Port\tProxy"
if [ "$(find /tmp/ssh-proxy-"${USER}" -maxdepth 0 -empty -exec echo 1 \;)" == "" ]; then for FILE in /tmp/ssh-proxy-"${USER}"/*; do
for FILE in /tmp/ssh-proxy-"${USER}"/*; do PORT=$(basename "${FILE}")
PORT=$(basename "${FILE}") PROXY=$(grep 'PROXY=' "${FILE}" | sed 's/PROXY=//')
PROXY=$(grep 'PROXY=' "${FILE}" | sed 's/PROXY=//') echo -e "${PORT}\t${PROXY}"
echo -e "${PORT}\t${PROXY}" done
done else
fi echo "No open proxy"
fi fi
} }
@@ -151,9 +153,25 @@ function stopProxy() {
rm "${TMP_FILE}" rm "${TMP_FILE}"
} }
function startAll() {
for FILE in ~/.config/ssh-proxy/*; do
PROFILE=$(basename "${FILE}")
startProxy "${PROFILE}"
done
}
function stopAll() {
for FILE in /tmp/ssh-proxy-"${USER}"/*; do
PORT=$(basename "${FILE}")
stopProxy "${PORT}"
done
}
case ${1} in case ${1} in
"status") showProxyStatus;; "status") showProxyStatus;;
"start") startProxy "${2}" "${3}";; "start") startProxy "${2}" "${3}";;
"stop") stopProxy "${2}";; "stop") stopProxy "${2}";;
"startall") startAll;;
"stopall") stopAll;;
*) exit 1;; *) exit 1;;
esac esac

View File

@@ -5,7 +5,7 @@ _ssh-proxy() {
local cur prev words cword args local cur prev words cword args
_init_completion || return _init_completion || return
local -r cmdargs="status start stop" local -r cmdargs="status start stop startall stopall"
local -r cnfargs="--help" local -r cnfargs="--help"
local profiledir=~/.config/ssh-proxy local profiledir=~/.config/ssh-proxy
local tempdir="/tmp/ssh-proxy-${USER}" local tempdir="/tmp/ssh-proxy-${USER}"
@@ -30,7 +30,7 @@ _ssh-proxy() {
--help) --help)
return return
;; ;;
status) status | startall | stopall)
return return
;; ;;
start) start)