diff --git a/1_4.h13_bugFix/1-3.wget_timeout/index.lua b/1_4.h13_bugFix/1-3.wget_timeout/index.lua new file mode 100644 index 0000000..c6a6e9f --- /dev/null +++ b/1_4.h13_bugFix/1-3.wget_timeout/index.lua @@ -0,0 +1,134 @@ +module("luci.controller.bs.index", package.seeall) + + +local arpmon = require "meizu.arpmon" +local bfs = require "meizu.bfs" +local btfs = require "meizu.btfs" +local posix = require "Posix" + +new_device_notify = arpmon.new_device_notify +nw_get_bluetooth_info = btfs.nw_get_bluetooth_info + +function index() + local root = node() + if not root.target then + root.target = alias("bs") + root.index = true + end + local page = node("bs") + --page.target = firstchild() + page.title = _("bs") + page.order = 10 + page.index = true + page = entry({"bs", "testTimeout"}, call("testTimeout"), nil, nil) + page.leaf = true + page = entry({"bs", "info"}, call("info"), nil, nil) + page.leaf = true + page = entry({"bs", "token"}, call("token"), nil, nil) + page.leaf = true + page = entry({"bs", "getTokenByPsw"}, call("get_Token_By_Psw"), nil, nil) + page.leaf = true + + page = entry({"bs", "newdevicenotify"}, call("new_device_notify"), nil) + page.leaf = true + + page = entry({"bs", "devip"}, call("devip"), nil, nil) + page.leaf = true + page = entry({"bs", "testip"}, call("testip"), nil, nil) + page.leaf = true + page = entry({"bs", "normip"}, call("normip"), nil, nil) + page.leaf = true + + page = entry({"bs", "apk"}, call("apk"), nil) + page.leaf = true + page = entry({"bs", "getBluetoothInfo"}, call("nw_get_bluetooth_info"), nil) + page.leaf = true +end + +function testTimeout() + local res = "testTimeout" + posix.sleep(5) + luci.http.write_json(res) + return res +end +function info() + luci.http.prepare_content("application/json") + local result = bfs.sysinfo() + luci.http.write_json(result) +end + +function token() + luci.http.prepare_content("application/json") + local sauth = require "luci.sauth" + local token = sauth.noAuthGetToken() + if token then + luci.http.write_json(token) + end +end + +function get_Token_By_Psw() + luci.http.prepare_content("application/json") + local username = luci.http.formvalue("username") + local passwd = luci.http.formvalue("password") + local ret = luci.sys.user.checkpasswd(username, passwd) + if ret == true then + local sauth = require "luci.sauth" + local token = sauth.noAuthGetToken() + if token then + luci.http.write_json(token) + end + end +end + +function show_hosts() + local lue = require"luci.util".exec + local cmd = "cat /etc/hosts" + local ret = lue(cmd) + luci.http.write(ret) +end + +function devip() + local lue = require"luci.util".exec + local cmd = "/usr/sbin/mzrts_ips.sh devip" + local ret = lue(cmd) + show_hosts() +end + +function normip() + local lue = require"luci.util".exec + local cmd = "/usr/sbin/mzrts_ips.sh" + local ret = lue(cmd) + show_hosts() +end + +function testip() + local lue = require"luci.util".exec + local cmd = "/usr/sbin/mzrts_ips.sh testip" + local ret = lue(cmd) + show_hosts() +end + +function apk() + local fn, fd, block + local cmd = "ls /www/apk_download/apk/*.apk | awk '{printf $1}'" + fd = io.popen(cmd) + fn = fd:read("*l") + fd:close() + if fn ~= nil then + fd = nixio.open(fn, "r") + luci.http.header('Content-Disposition', 'attachment; filename="%s"' % {nixio.fs.basename(fn)}) + luci.http.prepare_content("application/octet-stream") + while true do + block = fd:read(nixio.const.buffersize) + require "MZLog".log(3, debug.getinfo(1).currentline) + if (not block) or (#block == 0) then + require "MZLog".log(3, debug.getinfo(1).currentline) + break + else + luci.http.write(block) + end + end + fd:close() + end + luci.http.close() +end diff --git a/1_4.h13_bugFix/1-3.wget_timeout/mzrts_monitor.sh b/1_4.h13_bugFix/1-3.wget_timeout/mzrts_monitor.sh new file mode 100755 index 0000000..4f0a521 --- /dev/null +++ b/1_4.h13_bugFix/1-3.wget_timeout/mzrts_monitor.sh @@ -0,0 +1,63 @@ +#!/bin/sh +#=============================================================================== +# +# FILE: mzrts_monitor.sh +# +# USAGE: ./mzrts_monitor.sh +# +# DESCRIPTION: +# +# OPTIONS: --- +# REQUIREMENTS: --- +# BUGS: --- +# NOTES: --- +# AUTHOR: Karl Zheng (), ZhengKarl#gmail.com +# COMPANY: Meizu +# CREATED: 2015年01月14日 21时43分00秒 CST +# REVISION: --- +#=============================================================================== + + +mzrts_monitor() +{ + local MZRTSMONITORLOG="/tmp/mzrts_monitor.log" + local MZRTSLOG="/tmp/mzrts.log" + local mzrts_cpu_usage=$(top -n 1 |sed -n -e '/% \/usr.*mzrt/s#%##gp'|awk '{print $7}') + if [ "x${mzrts_cpu_usage}" != "x" ];then + if [ ${mzrts_cpu_usage} -ge 30 ];then + echo "mzrts_cpu_usage: ${mzrts_cpu_usage}" + echo "killall mzrts" + killall mzrts + sleep 1 + fi + fi + local is_mzrts_run="$(ps w|grep /usr/bin/mzrts|grep -v 'mzrts_monitor'|grep -v 'grep'| wc -l)" + if [ ${is_mzrts_run} -lt 1 ];then + echo "" >> ${MZRTSMONITORLOG} + date >> ${MZRTSMONITORLOG} + echo "/usr/bin/mzrts -llon | tee -a ${MZRTSLOG} &" + /usr/bin/mzrts -llon | tee -a ${MZRTSLOG} & + echo "" >> ${MZRTSMONITORLOG} + else + echo "is_mzrts_run: ${is_mzrts_run}" + fi + local timers=$(date +%H) + if [ ${timers} -ge 18 ] && [ ${timers} -le 19 ];then + if [ ! -f "/tmp/is_upgrading" ];then + echo "check_mandatory_upgrade" + touch /tmp/is_upgrading + lua -e 'require("meizu.upgdfs").check_mandatory_upgrade()' + echo "mandatory_upgrade success!" + fi + fi + [ -e /tmp/luci_index.html ] && rm /tmp/luci_index.html + sh -c '/usr/bin/timeout -t 3 /usr/bin/wget "http://127.0.0.1/cgi-bin/luci/bs/testTimeout" -q -O /tmp/testTimeout.html' & + sleep i1 + [ ! -e /tmp/luci_index.html ] && echo "/etc/init.d/uhttpd restart" && /etc/init.d/uhttpd restart +} + +while [ true ]; +do + sleep 3 + mzrts_monitor +done diff --git a/1_4.h13_bugFix/1-3.wget_timeout/config b/1_4.h13_bugFix/1-3.wget_timeout/old/config similarity index 100% rename from 1_4.h13_bugFix/1-3.wget_timeout/config rename to 1_4.h13_bugFix/1-3.wget_timeout/old/config