From f130a9ffbf88a01d49f40305d5026cb26b56c7fa Mon Sep 17 00:00:00 2001 From: ville rantanen Date: Mon, 7 Aug 2017 14:44:12 +0300 Subject: [PATCH] list incoming ssh too --- web/ssh-tunnelier | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/web/ssh-tunnelier b/web/ssh-tunnelier index d6f8f72..786cd3c 100755 --- a/web/ssh-tunnelier +++ b/web/ssh-tunnelier @@ -36,31 +36,42 @@ colRow="\033[0;1m" colMenu="\033[0;33m" colWarn="\033[0;1;31m" +function fpgrep() { + pgrep -x -u $UID "$@" | xargs --no-run-if-empty ps -o pid,bsdtime,args; + test ${PIPESTATUS[0]} -ne 0 && echo '----' +} + function get_id() { id=$( printf "%s" "$line" | base64 -w 0 ) echo -n $id } + function get_command() { switches=$( echo "$1" | base64 -d ) echo -n "ssh -f -n $switches \"sleep $MAGIC_TIME; echo tunneler $1\"" } + function get_pid() { pgrep -f "$MAGIC_TIME.*echo tunneler $1" | head -n 1 } + function list_all_ssh() { printf "\n${colTitle}=============================================\n" printf "${colTitle} List of SSH:${colZ}\n" printf "${colTitle}Enter PID to kill, empty to return $colZ\n" - printf "${colTitle}=============================================\n" - printf "${colRow}PID command\n" - pgrep -a -x ssh + printf "${colTitle}Outgoing SSH processes\n" + printf "${colTitle}=============================================\n${colRow}" + fpgrep ssh + printf "${colTitle}Incoming SSH processes\n" + printf "${colTitle}=============================================\n${colRow}" + fpgrep sshd read -t 600 inputpid [[ "$inputpid" =~ $number_re ]] && { kill $inputpid } - } + function read_config() { while read line; do id=$( get_id "$line" ) @@ -70,6 +81,7 @@ function read_config() { i=$(( i + 1 )) done < <( grep -v ^# "$CONF" | grep '[a-zA-Z]' ) } + function run_command() { eval $( get_command "$1" ) }