mirror of
https://github.com/JamesonHuang/OpenWrt_Luci_Lua.git
synced 2024-11-24 06:10:11 +00:00
137 lines
4.3 KiB
Lua
137 lines
4.3 KiB
Lua
|
local bfs = require "meizu.bfs"
|
||
|
local dbfs = require("meizu.dbfs")
|
||
|
local upgdfs = require("meizu.upgdfs")
|
||
|
|
||
|
local get_device_SN = bfs.get_device_SN
|
||
|
local get_device_version = bfs.get_device_version
|
||
|
local get_https_data = bfs.get_https_data
|
||
|
local rts_get_access_token = bfs.rts_get_access_token
|
||
|
|
||
|
local delete_access_token = dbfs.delete_access_token
|
||
|
|
||
|
function getBasicInfo()
|
||
|
local sn = get_device_SN()
|
||
|
local url = "https://router.meizu.com/oauth/router/getBasicInfo?access_token="
|
||
|
local access_token = rts_get_access_token()
|
||
|
local newurl = url..access_token.."&device="..sn
|
||
|
local res, code, headers, status = get_https_data(newurl)
|
||
|
require "MZLog".log(3, debug.getinfo(1).currentline)
|
||
|
require "MZLog".log(3, newurl)
|
||
|
require "MZLog".log(3, res)
|
||
|
require "MZLog".log(3, debug.getinfo(1).currentline)
|
||
|
if code == 401 then
|
||
|
delete_access_token()
|
||
|
access_token = rts_get_access_token()
|
||
|
newurl = url..access_token.."&device="..sn
|
||
|
res, code, headers, status = get_https_data(newurl)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function upRouterPushId()
|
||
|
local sn = get_device_SN()
|
||
|
local pushId = sn.."100032"
|
||
|
local url="https://router.meizu.com/oauth/router/upRouterPushId"
|
||
|
local access_token = rts_get_access_token()
|
||
|
local postData = "access_token="..access_token.."&pushId="..pushId
|
||
|
local res, code, headers, status = get_https_data(url, postData)
|
||
|
require "MZLog".log(3, debug.getinfo(1).currentline)
|
||
|
require "MZLog".log(3, url)
|
||
|
require "MZLog".log(3, res)
|
||
|
require "MZLog".log(3, debug.getinfo(1).currentline)
|
||
|
if code == 401 then
|
||
|
delete_access_token()
|
||
|
access_token = rts_get_access_token()
|
||
|
postData = "access_token="..access_token.."&pushId="..pushId
|
||
|
res, code, headers, status = get_https_data(url, postData)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function report_rom_version()
|
||
|
local ver = get_device_version()
|
||
|
local url="https://router.meizu.com/oauth/router/updateStatus"
|
||
|
local access_token = rts_get_access_token()
|
||
|
local data = "&name=romversion&value="..ver
|
||
|
local pd = "access_token="..access_token..data
|
||
|
local res, code, headers, status = get_https_data(url, pd)
|
||
|
require "MZLog".log(3, debug.getinfo(1).currentline)
|
||
|
require "MZLog".log(3, url)
|
||
|
require "MZLog".log(3, res)
|
||
|
require "MZLog".log(3, debug.getinfo(1).currentline)
|
||
|
if code == 401 then
|
||
|
delete_access_token()
|
||
|
access_token = rts_get_access_token()
|
||
|
pd = "access_token="..access_token..data
|
||
|
res, code, headers, status = get_https_data(url, pd)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function check_upgrade_status()
|
||
|
local lu = require("luci.util")
|
||
|
local cmd = [[nvram get upgrading|awk '{printf $1}']]
|
||
|
local ret = lu.exec(cmd)
|
||
|
if ret == "1" then
|
||
|
local res, code, headers, status = upgdfs.push_upgrade_finish_msg()
|
||
|
require "MZLog".log(3, debug.getinfo(1).currentline)
|
||
|
require "MZLog".log(3, "check_upgrade_status")
|
||
|
require "MZLog".log(3, res)
|
||
|
require "MZLog".log(3, code)
|
||
|
require "MZLog".log(3, headers)
|
||
|
require "MZLog".log(3, status)
|
||
|
require "MZLog".log(3, debug.getinfo(1).currentline)
|
||
|
cmd = [[nvram unset upgrading;nvram commit;]]
|
||
|
lu.exec(cmd)
|
||
|
end
|
||
|
return ret
|
||
|
end
|
||
|
|
||
|
function ping_rts_server()
|
||
|
local lu = require("luci.util")
|
||
|
local cmd = "sleep 2;ping -W 2 -c 1 router.meizu.com > /dev/null ;echo -n $?"
|
||
|
local ret = lu.exec(cmd)
|
||
|
return ret
|
||
|
end
|
||
|
|
||
|
function ut()
|
||
|
local lu = require("luci.util")
|
||
|
local cmd = "uptime"
|
||
|
local ret = lu.exec(cmd)
|
||
|
require "MZLog".log(3, ret)
|
||
|
end
|
||
|
|
||
|
function init_ssid_dbdata()
|
||
|
dbfs.init_ssid_table()
|
||
|
local ssidtable = dbfs.fetch_ssid()
|
||
|
if nil == ssidtable or 0 == #ssidtable then
|
||
|
local network = require "luci.model.network".init()
|
||
|
local wifi_net_ra0 = network:get_wifinet('mt7628.network1')
|
||
|
local ssid24 = wifi_net_ra0:get("ssid")
|
||
|
local wifi_net_rai0 = network:get_wifinet('mt7610e.network1')
|
||
|
local ssid5 = wifi_net_rai0:get("ssid")
|
||
|
dbfs.add_ssid(ssid24, ssid5)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
init_ssid_dbdata()
|
||
|
dbfs.init_deny_mac_table()
|
||
|
|
||
|
ut()
|
||
|
require "MZLog".log(3, "start ping_rts_server()")
|
||
|
local ret = ping_rts_server()
|
||
|
while ret ~= "0" do
|
||
|
ret = ping_rts_server()
|
||
|
end
|
||
|
ut()
|
||
|
require "MZLog".log(3, "end ping_rts_server()")
|
||
|
require "MZLog".log(3, "getBasicInfo()")
|
||
|
getBasicInfo()
|
||
|
require "MZLog".log(3, "upRouterPushId()")
|
||
|
upRouterPushId()
|
||
|
ut()
|
||
|
require "MZLog".log(3, "upgdfs.subscribe_auto_upgrade")
|
||
|
local res, code, headers, status = upgdfs.subscribe_auto_upgrade()
|
||
|
ut()
|
||
|
require "MZLog".log(3, res, code, headers, status)
|
||
|
ut()
|
||
|
check_upgrade_status()
|
||
|
report_rom_version()
|