Skip to content

Commit

Permalink
简化了使用流程
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-zhou committed Oct 29, 2014
1 parent 0612293 commit f03a01d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 71 deletions.
82 changes: 50 additions & 32 deletions init
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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 <start|stop|restart|status|config|install|uninstall>"
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" [email protected] "$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 [email protected]

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() {
Expand All @@ -82,15 +100,15 @@ case "$1" in
start;;
"stop" )
stop;;
"run" )
run;;
"restart" )
start
stop;;
"run" )
run;;
"install" )
config;;
"uninstall" )
uninstall;;
* )
usage ;;
esac
esac
6 changes: 3 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"author" : "魔豆开发团队-阿耀",
"author_mail" : "[email protected]",
"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"
}
}
36 changes: 0 additions & 36 deletions ssh-reverse.sh

This file was deleted.

0 comments on commit f03a01d

Please sign in to comment.