Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f938fd4d5b | |||
| 759e7412c3 | |||
| 1dfd3f090f | |||
| 98542abb36 | |||
| 412744520e | |||
| b95b557fc1 |
@@ -1,14 +1,17 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
function showHelp() {
|
function showHelp() {
|
||||||
echo "ssh-proxy [args] command proxy"
|
echo "ssh-proxy [args] command cmd_args"
|
||||||
echo ""
|
echo ""
|
||||||
echo "args :"
|
echo "args :"
|
||||||
echo " --help Show help"
|
echo " --help Show help"
|
||||||
echo "command;"
|
echo "command :"
|
||||||
|
echo " status"
|
||||||
echo " start profile|port target"
|
echo " start profile|port target"
|
||||||
echo " stop port"
|
echo " stop port"
|
||||||
echo "proxy:"
|
echo " startall"
|
||||||
|
echo " stopall"
|
||||||
|
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)"
|
||||||
echo " target Proxy target [user@]server[:port]"
|
echo " target Proxy target [user@]server[:port]"
|
||||||
@@ -23,16 +26,31 @@ case ${1} in
|
|||||||
showHelp
|
showHelp
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
"start" | "stop");;
|
"status" | "startall" | "stopall");;
|
||||||
|
"start" | "stop")
|
||||||
|
if [ "${2}" == "" ] || [[ "${2}" == */* ]]; then
|
||||||
|
showHelp
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
showHelp
|
showHelp
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
if [ "${2}" == "" ] || [[ "${2}" == */* ]]; then
|
|
||||||
showHelp
|
function showProxyStatus() {
|
||||||
exit 1
|
if [ -d /tmp/ssh-proxy-"${USER}" ] && [ "$(find /tmp/ssh-proxy-"${USER}" -maxdepth 0 -empty -exec echo 1 \;)" == "" ]; then
|
||||||
|
echo -e "Port\tProxy"
|
||||||
|
for FILE in /tmp/ssh-proxy-"${USER}"/*; do
|
||||||
|
PORT=$(basename "${FILE}")
|
||||||
|
PROXY=$(grep 'PROXY=' "${FILE}" | sed 's/PROXY=//')
|
||||||
|
echo -e "${PORT}\t${PROXY}"
|
||||||
|
done
|
||||||
|
else
|
||||||
|
echo "No open proxy"
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function startProxy() {
|
function startProxy() {
|
||||||
LOCAL_PORT=0
|
LOCAL_PORT=0
|
||||||
@@ -117,6 +135,7 @@ function startProxy() {
|
|||||||
#echo "PROXY_USER=${PROXY_USER}"
|
#echo "PROXY_USER=${PROXY_USER}"
|
||||||
#echo "PROXY_SERVER=${PROXY_SERVER}"
|
#echo "PROXY_SERVER=${PROXY_SERVER}"
|
||||||
#echo "PROXY_SERVER_PORT=${PROXY_SERVER_PORT}"
|
#echo "PROXY_SERVER_PORT=${PROXY_SERVER_PORT}"
|
||||||
|
echo "PROXY=${PROXY_ADDRESS}"
|
||||||
echo "PID=${PID}"
|
echo "PID=${PID}"
|
||||||
} > "${TMP_FILE}"
|
} > "${TMP_FILE}"
|
||||||
}
|
}
|
||||||
@@ -134,8 +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;;
|
||||||
"start") startProxy "${2}" "${3}";;
|
"start") startProxy "${2}" "${3}";;
|
||||||
"stop") stopProxy "${2}";;
|
"stop") stopProxy "${2}";;
|
||||||
|
"startall") startAll;;
|
||||||
|
"stopall") stopAll;;
|
||||||
*) exit 1;;
|
*) exit 1;;
|
||||||
esac
|
esac
|
||||||
|
|||||||
@@ -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="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,6 +30,9 @@ _ssh-proxy() {
|
|||||||
--help)
|
--help)
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
|
status | startall | stopall)
|
||||||
|
return
|
||||||
|
;;
|
||||||
start)
|
start)
|
||||||
local -r PROFILELIST=$(\ls ${profiledir})
|
local -r PROFILELIST=$(\ls ${profiledir})
|
||||||
# shellcheck disable=SC2207
|
# shellcheck disable=SC2207
|
||||||
|
|||||||
Reference in New Issue
Block a user