Skip to content

Commit f03a01d

Browse files
author
eric-zhou
committed
简化了使用流程
1 parent 0612293 commit f03a01d

File tree

3 files changed

+53
-71
lines changed

3 files changed

+53
-71
lines changed

init

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#!/bin/sh
22

3-
CURWDIR="$(cd $(dirname $0) && pwd)"
3+
PWD="$(cd $(dirname $0) && pwd)"
44
TITLE="远程协助"
55
PROGRAM_NAME="app-ssh-reverse"
66
CUSTOM_BIN="/system/apps/tp/bin/custom"
7-
CUSTOM_CONFIG_FILE="$CURWDIR/custom.conf"
87

98
APPS_CONFIG_DIR="/data/conf"
109
LAUNCHER_CONFIG_DIR="$APPS_CONFIG_DIR/launcher/conf.d"
@@ -13,58 +12,77 @@ LAUNCHER_CONFIG_FILE="$LAUNCHER_CONFIG_DIR/$PROGRAM_NAME.conf"
1312
ICON="./res/icon.png"
1413
PRESSED_ICON="./res/icon_pressed.png"
1514

16-
PID_FILE="$CURWDIR/$PROGRAM_NAME.pid"
17-
PKILL_BIN="/usr/bin/pkill"
1815
INSTALL_BIN="/usr/bin/install"
1916
REMOVE="/bin/rm -f"
2017

18+
KEY_FILE=$PWD/ali-ssh-reverse-id_rsa
19+
KNOWN_HOSTS=$PWD/known_hosts
20+
SSH=$PWD/ssh
21+
2122
usage() {
2223
echo "ERROR: action missing"
2324
echo "syntax: $0 <start|stop|restart|status|config|install|uninstall>"
2425
echo "example: $0 start"
2526
}
2627

27-
start() {
28-
echo "start function no implemented"
29-
# $CUSTOM_BIN "$CUSTOM_CONFIG_FILE" &
30-
# [ "$!""XXX" != "XXX" ] && echo "$!" > $PID_FILE
28+
remote_exec()
29+
{
30+
exec_result=`$SSH -i $KEY_FILE -o UserKnownHostsFile="$KNOWN_HOSTS" [email protected] "$1"`
3131
}
3232

33+
get_port()
34+
{
35+
local netstat="busy"
36+
local portlist=1
37+
38+
while [ "$netstat" != "" -o "$portlist" != "0" ]
39+
do
40+
# 可以考虑用/dev/random实现,且是1024以上即可
41+
local RAN_NUM=`date +%s`
42+
local t1=`expr $RAN_NUM % 50000`
43+
port_result=`expr $t1 + 1030`
44+
45+
remote_exec "netstat -an | grep $port"
46+
netstat=$exec_result
47+
remote_exec "cat port.list | grep $port | wc -l"
48+
portlist=$exec_result
49+
done
50+
}
51+
52+
3353
run() {
34-
$CUSTOM_BIN "$CUSTOM_CONFIG_FILE"&
54+
# 随机取得端口
55+
get_port;
56+
local port=$port_result
57+
58+
echo "使用PORT:$port"
59+
$SSH -i $KEY_FILE -o UserKnownHostsFile="$KNOWN_HOSTS" \
60+
-g -NfR *:$port:*:22 [email protected]
61+
62+
messagebox 远程协助 "远程协助已开启,服务序号$port
63+
请在结束协助后点击结束退出远程协助。" 1 结束 "killall ssh"
64+
65+
}
66+
67+
start() {
68+
echo "not implemented"
3569
}
3670

3771
stop() {
38-
echo "stop function not implemented"
39-
# if [ -f $PID_FILE ]; then
40-
# kill `cat "$PID_FILE"`
41-
# $REMOVE $PID_FILE
42-
# fi
72+
echo "not implemented"
4373
}
4474

4575
config() {
4676
echo "{" > "$PROGRAM_NAME.conf"
4777
echo "\"name\" : \"$TITLE\"," >> "$PROGRAM_NAME.conf"
48-
echo "\"icon\" : \"$CURWDIR/$ICON\"," >> "$PROGRAM_NAME.conf"
49-
echo "\"iconPressed\" : \"$CURWDIR/$PRESSED_ICON\"," >> "$PROGRAM_NAME.conf"
50-
echo "\"exec\" : \"$CURWDIR/init run\"," >> "$PROGRAM_NAME.conf"
78+
echo "\"icon\" : \"$PWD/$ICON\"," >> "$PROGRAM_NAME.conf"
79+
echo "\"iconPressed\" : \"$PWD/$PRESSED_ICON\"," >> "$PROGRAM_NAME.conf"
80+
echo "\"exec\" : \"$PWD/init run\"," >> "$PROGRAM_NAME.conf"
5181
echo "\"msgNum\" : 4" >> "$PROGRAM_NAME.conf"
5282
echo "}" >> "$PROGRAM_NAME.conf"
5383

5484
$INSTALL_BIN -d $LAUNCHER_CONFIG_DIR
5585
$INSTALL_BIN "$PROGRAM_NAME.conf" "$LAUNCHER_CONFIG_FILE"
56-
57-
echo "{" > "$CUSTOM_CONFIG_FILE"
58-
echo "\"title\" : \"$TITLE\"," >> "$CUSTOM_CONFIG_FILE"
59-
echo " \"content\" : \"点击开始,然后按照所提示文字即可远程ssh到路由器上\"," >> "$CUSTOM_CONFIG_FILE"
60-
echo " \"button1\" : {" >> "$CUSTOM_CONFIG_FILE"
61-
echo " \"txt\" : \"开始\"," >> "$CUSTOM_CONFIG_FILE"
62-
echo " \"cmd\" : \"$CURWDIR/ssh-reverse.sh $CURWDIR/ali-ssh-reverse-id_rsa \"," >> "$CUSTOM_CONFIG_FILE"
63-
echo " \"code\" : {" >> "$CUSTOM_CONFIG_FILE"
64-
echo " \"0\" : \"执行成功\" " >> "$CUSTOM_CONFIG_FILE"
65-
echo " }" >> "$CUSTOM_CONFIG_FILE"
66-
echo " } " >> "$CUSTOM_CONFIG_FILE"
67-
echo "} " >> "$CUSTOM_CONFIG_FILE"
6886
}
6987

7088
uninstall() {
@@ -82,15 +100,15 @@ case "$1" in
82100
start;;
83101
"stop" )
84102
stop;;
85-
"run" )
86-
run;;
87103
"restart" )
88104
start
89105
stop;;
106+
"run" )
107+
run;;
90108
"install" )
91109
config;;
92110
"uninstall" )
93111
uninstall;;
94112
* )
95113
usage ;;
96-
esac
114+
esac

manifest.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
"author" : "魔豆开发团队-阿耀",
55
"author_mail" : "[email protected]",
66
"homepage" : "www.modouwifi.com",
7-
"version" : "0.1.3",
8-
"release_date" : "2014.08.13",
7+
"version" : "0.2.0",
8+
"release_date" : "2014.10.24",
99
"icon" : "./res/icon.png",
1010
"location" : "internal",
1111
"description" : "运行插件后,点击开始即可开启远程协助",
1212
"instruction" : "",
1313
"os_version" : "0.6.17"
14-
}
14+
}

ssh-reverse.sh

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)