From 8509d4f2132ef4835041a01da80f10487e8c7369 Mon Sep 17 00:00:00 2001 From: guo-yong-zhi <55872791+guo-yong-zhi@users.noreply.github.com> Date: Sat, 28 Aug 2021 14:22:32 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=89=93=E5=BC=80WiFi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- filebrowser/README.md | 5 +++-- filebrowser/config.xml | 2 +- filebrowser/menu.json | 17 ++++++++------- filebrowser/show_status.sh | 6 +++--- filebrowser/start.sh | 42 +++++++++++++++++++++++++++++------- filebrowser/start_auth.sh | 44 ++++++++++++++++++++++++++++++-------- 6 files changed, 85 insertions(+), 31 deletions(-) diff --git a/filebrowser/README.md b/filebrowser/README.md index f09f4c9..fd23ef1 100644 --- a/filebrowser/README.md +++ b/filebrowser/README.md @@ -10,8 +10,9 @@ Kindle 越狱插件 File Browser 使用说明: -【 Start (Auth) 】可开启带登录验证的 WEB 服务(默认用户名密码均为:admin) -【 Reset 】删除包含配置信息的数据文件 filebrowser.db -【 Stop 】停止 WEB 服务 -3. 开启 WEB 服务后,可以在 Kindle 界面的顶部看到 IP 地址,在同一局域网下即可通过浏览器访问此地址。 -4. 服务开启后会阻止屏幕自动关闭,第一次按电源键会关闭filebrowser服务,再按即可正常锁屏休眠。 +3. 如果服务开启时设备 WiFi 处于关闭状态,WiFi 会被自动打开并在服务关闭后恢复原来状态。 +4. 开启 WEB 服务后,可以在 Kindle 界面的顶部看到 IP 地址,在同一局域网下即可通过浏览器访问此地址。 +5. 服务开启后会阻止屏幕自动关闭,第一次按电源键会关闭filebrowser服务,再按即可正常锁屏休眠。 ======================================================= diff --git a/filebrowser/config.xml b/filebrowser/config.xml index 3e919af..bf22853 100644 --- a/filebrowser/config.xml +++ b/filebrowser/config.xml @@ -2,7 +2,7 @@ File Browser - 1.1 + 1.2 Sparkle filebrowser diff --git a/filebrowser/menu.json b/filebrowser/menu.json index 4538d7d..f3420f9 100644 --- a/filebrowser/menu.json +++ b/filebrowser/menu.json @@ -17,22 +17,23 @@ "param": "" }, { - "name": "Reset", + "name": "Show Status", "priority": 3, - "action": "rm ./filebrowser.db", - "param": "" + "action": "./show_status.sh", + "param": "", + "exitmenu": false }, { - "name": "Stop", + "name": "Kill", "priority": 4, "action": "killall filebrowser", "param": "" }, { - "name": "Show Status", - "action": "./show_status.sh", - "param": "", - "exitmenu": false + "name": "Reset", + "priority": 5, + "action": "rm ./filebrowser.db", + "param": "" } ] } diff --git a/filebrowser/show_status.sh b/filebrowser/show_status.sh index 615bcc8..671112f 100644 --- a/filebrowser/show_status.sh +++ b/filebrowser/show_status.sh @@ -3,8 +3,8 @@ test_process=$(ps aux | grep "[f]ilebrowser") if [ -n "$test_process" ] then - result="File Browser is Running....." + result="File Browser is Running..... " else - result="File Browser is not running." + result="File Browser is not running " fi -eips 25 2 "$result" \ No newline at end of file +eips 29 3 "$result" diff --git a/filebrowser/start.sh b/filebrowser/start.sh index 1037b22..5a663ba 100644 --- a/filebrowser/start.sh +++ b/filebrowser/start.sh @@ -1,14 +1,15 @@ #!/bin/sh -lipc-set-prop -i com.lab126.powerd preventScreenSaver 1 -lipc-wait-event com.lab126.hal powerButtonPressed| if read event; then - lipc-set-prop -i com.lab126.powerd preventScreenSaver 0 - killall filebrowser - eips 25 2 "File Browser is turned off. " -fi > /dev/null & - iptables -I INPUT -p tcp --dport 80 -j ACCEPT -eips 25 1 "IP: `ifconfig wlan0 | grep 'inet addr' | awk -F '[ :]' '{print $13}'`" +# enable wireless if it is currently off +WIFI_IS_OFF=0 +if [ 0 -eq `lipc-get-prop com.lab126.cmd wirelessEnable` ]; then + eips 30 3 "WiFi is off, turning it on now" + lipc-set-prop com.lab126.cmd wirelessEnable 1 + WIFI_IS_OFF=1 +fi + +# start filebrowser in the background if [ "$(ps aux | grep '[f]ilebrowser')" ];then killall filebrowser;fi if [ ! -f ./filebrowser.db ] @@ -21,4 +22,29 @@ else ./filebrowser config set --auth.method=noauth > /dev/null fi ./filebrowser -a 0.0.0.0 -p 80 -r /mnt/us > /dev/null +fi & + +# refresh IP display in the background +while :; do + eips 30 1 "== `ifconfig wlan0 | grep 'inet addr' | awk -F '[ :]' '{print $13}'` ==" + sleep 5 +done > /dev/null & + +# waiting for powerButtonPressed +lipc-set-prop -i com.lab126.powerd preventScreenSaver 1 +lipc-wait-event com.lab126.hal powerButtonPressed | read event #it's blocking +lipc-set-prop -i com.lab126.powerd preventScreenSaver 0 +kill $(jobs -p) +eips 30 3 "File Browser is turned off. " + +# Restore WiFi status +if [ 1 -eq $WIFI_IS_OFF ]; then + lipc-set-prop com.lab126.cmd wirelessEnable 0 + sleep 0.5 + eips 30 3 "Turning off WiFi " fi + +# Clear screen +sleep 1 +eips 30 1 " " +eips 30 3 " " diff --git a/filebrowser/start_auth.sh b/filebrowser/start_auth.sh index 7581cd1..8ccaa73 100644 --- a/filebrowser/start_auth.sh +++ b/filebrowser/start_auth.sh @@ -1,14 +1,15 @@ #!/bin/sh -lipc-set-prop -i com.lab126.powerd preventScreenSaver 1 -lipc-wait-event com.lab126.hal powerButtonPressed| if read event; then - lipc-set-prop -i com.lab126.powerd preventScreenSaver 0 - killall filebrowser - eips 25 2 "File Browser is turned off. " -fi > /dev/null & - iptables -I INPUT -p tcp --dport 80 -j ACCEPT -eips 25 1 "IP: `ifconfig wlan0 | grep 'inet addr' | awk -F '[ :]' '{print $13}'`" +# enable wireless if it is currently off +WIFI_IS_OFF=0 +if [ 0 -eq `lipc-get-prop com.lab126.cmd wirelessEnable` ]; then + eips 30 3 "WiFi is off, turning it on now" + lipc-set-prop com.lab126.cmd wirelessEnable 1 + WIFI_IS_OFF=1 +fi + +# start filebrowser in the background if [ "$(ps aux | grep '[f]ilebrowser')" ];then killall filebrowser;fi if [ -f ./filebrowser.db ] @@ -19,4 +20,29 @@ then ./filebrowser config set --auth.method=json > /dev/null fi fi -./filebrowser -a 0.0.0.0 -p 80 -r /mnt/us > /dev/null +./filebrowser -a 0.0.0.0 -p 80 -r /mnt/us > /dev/null & + +# refresh IP display in the background +while :; do + eips 30 1 "== `ifconfig wlan0 | grep 'inet addr' | awk -F '[ :]' '{print $13}'` ==" + sleep 5 +done > /dev/null & + +# waiting for powerButtonPressed +lipc-set-prop -i com.lab126.powerd preventScreenSaver 1 +lipc-wait-event com.lab126.hal powerButtonPressed | read event #it's blocking +lipc-set-prop -i com.lab126.powerd preventScreenSaver 0 +kill $(jobs -p) +eips 30 3 "File Browser is turned off. " + +# Restore WiFi status +if [ 1 -eq $WIFI_IS_OFF ]; then + lipc-set-prop com.lab126.cmd wirelessEnable 0 + sleep 0.5 + eips 30 3 "Turning off WiFi " +fi + +# Clear screen +sleep 1 +eips 30 1 " " +eips 30 3 " "