From f03a01d0296611723023bfe302dcb77f94c3d5cb Mon Sep 17 00:00:00 2001 From: eric-zhou Date: Wed, 29 Oct 2014 17:27:50 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=80=E5=8C=96=E4=BA=86=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- init | 82 ++++++++++++++++++++++++++++++-------------------- manifest.json | 6 ++-- ssh-reverse.sh | 36 ---------------------- 3 files changed, 53 insertions(+), 71 deletions(-) delete mode 100755 ssh-reverse.sh diff --git a/init b/init index 5cf6412..ff2d2e6 100755 --- a/init +++ b/init @@ -1,10 +1,9 @@ #!/bin/sh -CURWDIR="$(cd $(dirname $0) && pwd)" +PWD="$(cd $(dirname $0) && pwd)" TITLE="远程协助" PROGRAM_NAME="app-ssh-reverse" CUSTOM_BIN="/system/apps/tp/bin/custom" -CUSTOM_CONFIG_FILE="$CURWDIR/custom.conf" APPS_CONFIG_DIR="/data/conf" LAUNCHER_CONFIG_DIR="$APPS_CONFIG_DIR/launcher/conf.d" @@ -13,58 +12,77 @@ LAUNCHER_CONFIG_FILE="$LAUNCHER_CONFIG_DIR/$PROGRAM_NAME.conf" ICON="./res/icon.png" PRESSED_ICON="./res/icon_pressed.png" -PID_FILE="$CURWDIR/$PROGRAM_NAME.pid" -PKILL_BIN="/usr/bin/pkill" INSTALL_BIN="/usr/bin/install" REMOVE="/bin/rm -f" +KEY_FILE=$PWD/ali-ssh-reverse-id_rsa +KNOWN_HOSTS=$PWD/known_hosts +SSH=$PWD/ssh + usage() { echo "ERROR: action missing" echo "syntax: $0 " echo "example: $0 start" } -start() { - echo "start function no implemented" - # $CUSTOM_BIN "$CUSTOM_CONFIG_FILE" & - # [ "$!""XXX" != "XXX" ] && echo "$!" > $PID_FILE +remote_exec() +{ + exec_result=`$SSH -i $KEY_FILE -o UserKnownHostsFile="$KNOWN_HOSTS" ssh-reverse@115.29.171.150 "$1"` } +get_port() +{ + local netstat="busy" + local portlist=1 + + while [ "$netstat" != "" -o "$portlist" != "0" ] + do + # 可以考虑用/dev/random实现,且是1024以上即可 + local RAN_NUM=`date +%s` + local t1=`expr $RAN_NUM % 50000` + port_result=`expr $t1 + 1030` + + remote_exec "netstat -an | grep $port" + netstat=$exec_result + remote_exec "cat port.list | grep $port | wc -l" + portlist=$exec_result + done +} + + run() { - $CUSTOM_BIN "$CUSTOM_CONFIG_FILE"& + # 随机取得端口 + get_port; + local port=$port_result + + echo "使用PORT:$port" + $SSH -i $KEY_FILE -o UserKnownHostsFile="$KNOWN_HOSTS" \ + -g -NfR *:$port:*:22 ssh-reverse@115.29.171.150 + + messagebox 远程协助 "远程协助已开启,服务序号$port。 +请在结束协助后点击结束退出远程协助。" 1 结束 "killall ssh" + +} + +start() { + echo "not implemented" } stop() { - echo "stop function not implemented" - # if [ -f $PID_FILE ]; then - # kill `cat "$PID_FILE"` - # $REMOVE $PID_FILE - # fi + echo "not implemented" } config() { echo "{" > "$PROGRAM_NAME.conf" echo "\"name\" : \"$TITLE\"," >> "$PROGRAM_NAME.conf" - echo "\"icon\" : \"$CURWDIR/$ICON\"," >> "$PROGRAM_NAME.conf" - echo "\"iconPressed\" : \"$CURWDIR/$PRESSED_ICON\"," >> "$PROGRAM_NAME.conf" - echo "\"exec\" : \"$CURWDIR/init run\"," >> "$PROGRAM_NAME.conf" + echo "\"icon\" : \"$PWD/$ICON\"," >> "$PROGRAM_NAME.conf" + echo "\"iconPressed\" : \"$PWD/$PRESSED_ICON\"," >> "$PROGRAM_NAME.conf" + echo "\"exec\" : \"$PWD/init run\"," >> "$PROGRAM_NAME.conf" echo "\"msgNum\" : 4" >> "$PROGRAM_NAME.conf" echo "}" >> "$PROGRAM_NAME.conf" $INSTALL_BIN -d $LAUNCHER_CONFIG_DIR $INSTALL_BIN "$PROGRAM_NAME.conf" "$LAUNCHER_CONFIG_FILE" - - echo "{" > "$CUSTOM_CONFIG_FILE" - echo "\"title\" : \"$TITLE\"," >> "$CUSTOM_CONFIG_FILE" - echo " \"content\" : \"点击开始,然后按照所提示文字即可远程ssh到路由器上\"," >> "$CUSTOM_CONFIG_FILE" - echo " \"button1\" : {" >> "$CUSTOM_CONFIG_FILE" - echo " \"txt\" : \"开始\"," >> "$CUSTOM_CONFIG_FILE" - echo " \"cmd\" : \"$CURWDIR/ssh-reverse.sh $CURWDIR/ali-ssh-reverse-id_rsa \"," >> "$CUSTOM_CONFIG_FILE" - echo " \"code\" : {" >> "$CUSTOM_CONFIG_FILE" - echo " \"0\" : \"执行成功\" " >> "$CUSTOM_CONFIG_FILE" - echo " }" >> "$CUSTOM_CONFIG_FILE" - echo " } " >> "$CUSTOM_CONFIG_FILE" - echo "} " >> "$CUSTOM_CONFIG_FILE" } uninstall() { @@ -82,15 +100,15 @@ case "$1" in start;; "stop" ) stop;; - "run" ) - run;; "restart" ) start stop;; + "run" ) + run;; "install" ) config;; "uninstall" ) uninstall;; * ) usage ;; -esac \ No newline at end of file +esac diff --git a/manifest.json b/manifest.json index 1e3962b..74e9d39 100644 --- a/manifest.json +++ b/manifest.json @@ -4,11 +4,11 @@ "author" : "魔豆开发团队-阿耀", "author_mail" : "zhouyao@mochui.net", "homepage" : "www.modouwifi.com", - "version" : "0.1.3", - "release_date" : "2014.08.13", + "version" : "0.2.0", + "release_date" : "2014.10.24", "icon" : "./res/icon.png", "location" : "internal", "description" : "运行插件后,点击开始即可开启远程协助", "instruction" : "", "os_version" : "0.6.17" -} \ No newline at end of file +} diff --git a/ssh-reverse.sh b/ssh-reverse.sh deleted file mode 100755 index 10a27d4..0000000 --- a/ssh-reverse.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh - -#中转服务器需要在/etc/ssh/sshd_config里面加一句: -# GatewayPorts clientspecified,才能远程连接中转服务器,否则只能在中转 -# 服务器上ssh到目标机器 - -KEY_FILE=$1 -SSH=$(dirname "$0")/ssh -KNOWN_HOSTS=$(dirname "$0")/known_hosts - -get_port() -{ - local RAN_NUM=`date +%s` - local t1=`expr $RAN_NUM % 50000` - local PORT=`expr $t1 + 1030` - - return $PORT -} - -NETSTAT="busy" - -while [ "$NETSTAT" != "" ] -do - get_port; - PORT=$? - echo "尝试使用port:$PORT" - - NETSTAT=`$SSH -i "$KEY_FILE" -o UserKnownHostsFile="$KNOWN_HOSTS" ssh-reverse@115.29.171.150 "netstat -an | grep $PORT "` - sleep 1 -done - -echo "开始使用PORT:$PORT" -$SSH -i $KEY_FILE -o UserKnownHostsFile="$KNOWN_HOSTS" -g -NfR *:$PORT:*:22 ssh-reverse@115.29.171.150 -echo -e "请用下面语句登录远程ssh: \nssh matrix@115.29.171.150 -p $PORT" - -messagebox 反向SSH "请用下面语句登录远程ssh: ssh matrix@115.29.171.150 -p $PORT" 1 确定 "" \ No newline at end of file