update 2022-04-29 16:51:37

This commit is contained in:
github-actions[bot]
2022-04-29 16:51:37 +08:00
parent c376846787
commit c4571814aa
12 changed files with 206 additions and 411 deletions

View File

@ -5,44 +5,42 @@ function index()
return
end
local page = entry({"admin", "system", "amlogic"}, alias("admin", "system", "amlogic", "info"), _("Amlogic Service"), 88)
local page = entry({ "admin", "system", "amlogic" }, alias("admin", "system", "amlogic", "info"), _("Amlogic Service"), 88)
page.dependent = true
page.acl_depends = { "luci-app-amlogic" }
entry({"admin", "system", "amlogic", "info"}, cbi("amlogic/amlogic_info"), _("Amlogic Service"), 1).leaf = true
entry({"admin", "system", "amlogic", "install"}, cbi("amlogic/amlogic_install"), _("Install OpenWrt"), 2).leaf = true
entry({"admin", "system", "amlogic", "upload"}, cbi("amlogic/amlogic_upload"), _("Manually Upload Update"), 3).leaf = true
entry({"admin", "system", "amlogic", "check"}, cbi("amlogic/amlogic_check"), _("Online Download Update"), 4).leaf = true
entry({"admin", "system", "amlogic", "backup"}, cbi("amlogic/amlogic_backup"), _("Backup Firmware Config"), 5).leaf = true
entry({"admin", "system", "amlogic", "armcpu"}, cbi("amlogic/amlogic_armcpu"), _("CPU Settings"), 6).leaf = true
entry({"admin", "system", "amlogic", "config"}, cbi("amlogic/amlogic_config"), _("Plugin Settings"), 7).leaf = true
entry({"admin", "system", "amlogic", "log"}, cbi("amlogic/amlogic_log"), _("Server Logs"), 8).leaf = true
entry({"admin", "system", "amlogic", "poweroff"}, cbi("amlogic/amlogic_poweroff"), _("PowerOff"), 9).leaf = true
entry({"admin", "system", "amlogic", "check_firmware"}, call("action_check_firmware"))
entry({"admin", "system", "amlogic", "check_plugin"}, call("action_check_plugin"))
entry({"admin", "system", "amlogic", "check_kernel"}, call("action_check_kernel"))
entry({"admin", "system", "amlogic", "refresh_log"}, call("action_refresh_log"))
entry({"admin", "system", "amlogic", "del_log"}, call("action_del_log"))
entry({"admin", "system", "amlogic", "start_model_database"}, call("action_check_model_database")).leaf = true
entry({"admin", "system", "amlogic", "start_check_install"}, call("action_start_check_install")).leaf = true
entry({"admin", "system", "amlogic", "start_check_firmware"}, call("action_start_check_firmware")).leaf = true
entry({"admin", "system", "amlogic", "start_check_plugin"}, call("action_start_check_plugin")).leaf = true
entry({"admin", "system", "amlogic", "start_check_kernel"}, call("action_start_check_kernel")).leaf = true
entry({"admin", "system", "amlogic", "start_check_upfiles"}, call("action_start_check_upfiles")).leaf = true
entry({"admin", "system", "amlogic", "start_amlogic_install"}, call("action_start_amlogic_install")).leaf = true
entry({"admin", "system", "amlogic", "start_amlogic_update"}, call("action_start_amlogic_update")).leaf = true
entry({"admin", "system", "amlogic", "start_amlogic_kernel"}, call("action_start_amlogic_kernel")).leaf = true
entry({"admin", "system", "amlogic", "start_amlogic_plugin"}, call("action_start_amlogic_plugin")).leaf = true
entry({"admin", "system", "amlogic", "start_snapshot_delete"}, call("action_start_snapshot_delete")).leaf = true
entry({"admin", "system", "amlogic", "start_snapshot_restore"}, call("action_start_snapshot_restore")).leaf = true
entry({"admin", "system", "amlogic", "start_snapshot_list"}, call("action_check_snapshot")).leaf = true
entry({"admin", "system", "amlogic", "start_openwrt_author"}, call("action_openwrt_author")).leaf = true
entry({"admin", "system", "amlogic", "state"}, call("action_state")).leaf = true
entry({"admin", "system", "amlogic", "start_poweroff"}, call("action_poweroff")).leaf = true
entry({ "admin", "system", "amlogic", "info" }, cbi("amlogic/amlogic_info"), _("Amlogic Service"), 1).leaf = true
entry({ "admin", "system", "amlogic", "install" }, cbi("amlogic/amlogic_install"), _("Install OpenWrt"), 2).leaf = true
entry({ "admin", "system", "amlogic", "upload" }, cbi("amlogic/amlogic_upload"), _("Manually Upload Update"), 3).leaf = true
entry({ "admin", "system", "amlogic", "check" }, cbi("amlogic/amlogic_check"), _("Online Download Update"), 4).leaf = true
entry({ "admin", "system", "amlogic", "backup" }, cbi("amlogic/amlogic_backup"), _("Backup Firmware Config"), 5).leaf = true
entry({ "admin", "system", "amlogic", "armcpu" }, cbi("amlogic/amlogic_armcpu"), _("CPU Settings"), 6).leaf = true
entry({ "admin", "system", "amlogic", "config" }, cbi("amlogic/amlogic_config"), _("Plugin Settings"), 7).leaf = true
entry({ "admin", "system", "amlogic", "log" }, cbi("amlogic/amlogic_log"), _("Server Logs"), 8).leaf = true
entry({ "admin", "system", "amlogic", "poweroff" }, cbi("amlogic/amlogic_poweroff"), _("PowerOff"), 9).leaf = true
entry({ "admin", "system", "amlogic", "check_firmware" }, call("action_check_firmware"))
entry({ "admin", "system", "amlogic", "check_plugin" }, call("action_check_plugin"))
entry({ "admin", "system", "amlogic", "check_kernel" }, call("action_check_kernel"))
entry({ "admin", "system", "amlogic", "refresh_log" }, call("action_refresh_log"))
entry({ "admin", "system", "amlogic", "del_log" }, call("action_del_log"))
entry({ "admin", "system", "amlogic", "start_model_database" }, call("action_check_model_database")).leaf = true
entry({ "admin", "system", "amlogic", "start_check_install" }, call("action_start_check_install")).leaf = true
entry({ "admin", "system", "amlogic", "start_check_firmware" }, call("action_start_check_firmware")).leaf = true
entry({ "admin", "system", "amlogic", "start_check_plugin" }, call("action_start_check_plugin")).leaf = true
entry({ "admin", "system", "amlogic", "start_check_kernel" }, call("action_start_check_kernel")).leaf = true
entry({ "admin", "system", "amlogic", "start_check_upfiles" }, call("action_start_check_upfiles")).leaf = true
entry({ "admin", "system", "amlogic", "start_amlogic_install" }, call("action_start_amlogic_install")).leaf = true
entry({ "admin", "system", "amlogic", "start_amlogic_update" }, call("action_start_amlogic_update")).leaf = true
entry({ "admin", "system", "amlogic", "start_amlogic_kernel" }, call("action_start_amlogic_kernel")).leaf = true
entry({ "admin", "system", "amlogic", "start_amlogic_plugin" }, call("action_start_amlogic_plugin")).leaf = true
entry({ "admin", "system", "amlogic", "start_snapshot_delete" }, call("action_start_snapshot_delete")).leaf = true
entry({ "admin", "system", "amlogic", "start_snapshot_restore" }, call("action_start_snapshot_restore")).leaf = true
entry({ "admin", "system", "amlogic", "start_snapshot_list" }, call("action_check_snapshot")).leaf = true
entry({ "admin", "system", "amlogic", "start_openwrt_author" }, call("action_openwrt_author")).leaf = true
entry({ "admin", "system", "amlogic", "state" }, call("action_state")).leaf = true
entry({ "admin", "system", "amlogic", "start_poweroff" }, call("action_poweroff")).leaf = true
end
local fs = require "luci.fs2"
--Remove the spaces in the string
function trim(str)
--return (string.gsub(str, "^%s*(.-)%s*$", "%1"))
@ -102,10 +100,10 @@ end
function string.split(input, delimiter)
input = tostring(input)
delimiter = tostring(delimiter)
if (delimiter=='') then return false end
local pos,arr = 0, {}
if (delimiter == '') then return false end
local pos, arr = 0, {}
-- for each divider found
for st,sp in function() return string.find(input, delimiter, pos, true) end do
for st, sp in function() return string.find(input, delimiter, pos, true) end do
table.insert(arr, string.sub(input, pos, st - 1))
pos = sp + 1
end
@ -115,8 +113,8 @@ end
--Refresh the log
function action_refresh_log()
local logfile="/tmp/amlogic/amlogic.log"
if not fs.access(logfile) then
local logfile = "/tmp/amlogic/amlogic.log"
if not nixio.fs.access(logfile) then
luci.sys.exec("uname -a > /tmp/amlogic/amlogic.log && sync")
luci.sys.exec("echo '' > /tmp/amlogic/amlogic_check_install.log && sync >/dev/null 2>&1")
luci.sys.exec("echo '' > /tmp/amlogic/amlogic_check_upfiles.log && sync >/dev/null 2>&1")
@ -126,9 +124,9 @@ function action_refresh_log()
luci.sys.exec("echo '' > /tmp/amlogic/amlogic_running_script.log && sync >/dev/null 2>&1")
end
luci.http.prepare_content("text/plain; charset=utf-8")
local f=io.open(logfile, "r+")
local f = io.open(logfile, "r+")
f:seek("set")
local a=f:read(2048000) or ""
local a = f:read(2048000) or ""
f:close()
luci.http.write(a)
end
@ -229,7 +227,7 @@ end
--Check the kernel
function action_check_kernel()
luci.http.prepare_content("application/json")
luci.http.write_json({
luci.http.write_json({
check_kernel_status = check_kernel();
})
end

View File

@ -1,9 +1,8 @@
--Copyright: https://github.com/coolsnowwolf/lede/tree/master/package/lean/luci-app-cpufreq
--Copyright: https://github.com/coolsnowwolf/luci/tree/master/applications/luci-app-cpufreq
--Planner: https://github.com/unifreq/openwrt_packit
--Extended support: https://github.com/ophub/luci-app-amlogic
--Function: Support multi-core
local fs = require "luci.fs2"
local mp
--Remove the spaces in the string
@ -17,12 +16,12 @@ function string.split(e, t)
e = tostring(e)
t = tostring(t)
if (t == '') then return false end
local a,o = 0,{}
for i,t in function() return string.find(e, t, a, true) end do
table.insert(o,string.sub(e, a, i-1))
local a, o = 0, {}
for i, t in function() return string.find(e, t, a, true) end do
table.insert(o, string.sub(e, a, i - 1))
a = t + 1
end
table.insert(o,string.sub(e, a))
table.insert(o, string.sub(e, a))
return o
end
@ -38,56 +37,56 @@ mp = Map("amlogic")
mp.title = translate("CPU Freq Settings")
mp.description = translate("Set CPU Scaling Governor to Max Performance or Balance Mode")
s = mp:section(NamedSection,"armcpu","settings")
s = mp:section(NamedSection, "armcpu", "settings")
s.anonymouse = true
local cpu_policys = luci.sys.exec("ls /sys/devices/system/cpu/cpufreq | grep -E 'policy[0-9]{1,3}' | xargs") or "policy0"
policy_array = string.split(cpu_policys, " ")
for tt,policy_name in ipairs(policy_array) do
for tt, policy_name in ipairs(policy_array) do
--Dynamic tab, automatically changes according to the number of cores, begin ------
policy_name = tostring(trim(policy_name))
policy_id = tostring(trim(string.gsub(policy_name, "policy", "")))
--Dynamic tab, automatically changes according to the number of cores, begin ------
policy_name = tostring(trim(policy_name))
policy_id = tostring(trim(string.gsub(policy_name, "policy", "")))
tab_name = policy_name
tab_id = tostring(trim("tab" .. policy_id))
tab_name = policy_name
tab_id = tostring(trim("tab" .. policy_id))
cpu_freqs = fs.readfile(trim("/sys/devices/system/cpu/cpufreq/" .. policy_name .. "/scaling_available_frequencies")) or "100000"
cpu_freqs = string.sub(cpu_freqs, 1, -3)
cpu_governors = fs.readfile(trim("/sys/devices/system/cpu/cpufreq/" .. policy_name .. "/scaling_available_governors")) or "performance"
cpu_governors = string.sub(cpu_governors, 1, -3)
freq_array = string.split(cpu_freqs, " ")
governor_array = string.split(cpu_governors, " ")
cpu_freqs = nixio.fs.readfile(trim("/sys/devices/system/cpu/cpufreq/" .. policy_name .. "/scaling_available_frequencies")) or "100000"
cpu_freqs = string.sub(cpu_freqs, 1, -3)
cpu_governors = nixio.fs.readfile(trim("/sys/devices/system/cpu/cpufreq/" .. policy_name .. "/scaling_available_governors")) or "performance"
cpu_governors = string.sub(cpu_governors, 1, -3)
freq_array = string.split(cpu_freqs, " ")
governor_array = string.split(cpu_governors, " ")
s:tab(tab_id, tab_name)
s:tab(tab_id, tab_name)
tab_core_type = s:taboption(tab_id, DummyValue, trim("core_type" .. policy_id), translate("Microarchitectures:"))
tab_core_type.default = luci.sys.exec("cat /sys/devices/system/cpu/cpu" .. policy_id .. "/uevent | grep -E '^OF_COMPATIBLE_0.*' | tr -d 'OF_COMPATIBLE_0=' | xargs") or "Unknown"
tab_core_type.rmempty = false
tab_core_type = s:taboption(tab_id, DummyValue, trim("core_type" .. policy_id), translate("Microarchitectures:"))
tab_core_type.default = luci.sys.exec("cat /sys/devices/system/cpu/cpu" .. policy_id .. "/uevent | grep -E '^OF_COMPATIBLE_0.*' | tr -d 'OF_COMPATIBLE_0=' | xargs") or "Unknown"
tab_core_type.rmempty = false
governor = s:taboption(tab_id, ListValue, trim("governor" .. policy_id), translate("CPU Scaling Governor:"))
for t,e in ipairs(governor_array) do
if e ~= "" then governor:value(e,translate(e,string.upper(e))) end
end
governor.default = "schedutil"
governor.rmempty = false
governor = s:taboption(tab_id, ListValue, trim("governor" .. policy_id), translate("CPU Scaling Governor:"))
for t, e in ipairs(governor_array) do
if e ~= "" then governor:value(e, translate(e, string.upper(e))) end
end
governor.default = "schedutil"
governor.rmempty = false
minfreq = s:taboption(tab_id, ListValue, trim("minfreq" .. policy_id), translate("Min Freq:"))
for t,e in ipairs(freq_array) do
if e ~= "" then minfreq:value(e) end
end
minfreq.default = "500000"
minfreq.rmempty = false
minfreq = s:taboption(tab_id, ListValue, trim("minfreq" .. policy_id), translate("Min Freq:"))
for t, e in ipairs(freq_array) do
if e ~= "" then minfreq:value(e) end
end
minfreq.default = "500000"
minfreq.rmempty = false
maxfreq = s:taboption(tab_id, ListValue, trim("maxfreq" .. policy_id), translate("Max Freq:"))
for t,e in ipairs(freq_array) do
if e ~= "" then maxfreq:value(e) end
end
maxfreq.default = "1512000"
maxfreq.rmempty = false
maxfreq = s:taboption(tab_id, ListValue, trim("maxfreq" .. policy_id), translate("Max Freq:"))
for t, e in ipairs(freq_array) do
if e ~= "" then maxfreq:value(e) end
end
maxfreq.default = "1512000"
maxfreq.rmempty = false
--Dynamic tab, automatically changes according to the number of cores, end ------
--Dynamic tab, automatically changes according to the number of cores, end ------
end

View File

@ -1,8 +1,17 @@
local fs = require "luci.fs2"
local http = require "luci.http"
local DISP = require "luci.dispatcher"
--Copyright: https://github.com/coolsnowwolf/luci/tree/master/applications/luci-app-filetransfer
--Extended support: https://github.com/ophub/luci-app-amlogic
--Function: Download files
local io = require "io"
local os = require "os"
local fs = require "nixio.fs"
local b, c
-- Checks wheather the given path exists and points to a directory.
function isdirectory(dirname)
return fs.stat(dirname, "type") == "dir"
end
--SimpleForm for Backup Config
b = SimpleForm("backup", nil)
b.title = translate("Backup Firmware Config")
@ -33,9 +42,9 @@ o.write = function(self, section, scope)
local sPath, sFile, fd, block
sPath = "/.reserved/openwrt_config.tar.gz"
sFile = nixio.fs.basename(sPath)
if luci.fs.isdirectory(sPath) then
fd = io.popen('tar -C "%s" -cz .' % {sPath}, "r")
sFile = fs.basename(sPath)
if isdirectory(sPath) then
fd = io.popen('tar -C "%s" -cz .' % { sPath }, "r")
sFile = sFile .. ".tar.gz"
else
fd = nixio.open(sPath, "r")
@ -47,18 +56,18 @@ o.write = function(self, section, scope)
um.value = translate("The file Will download automatically.") .. sPath
end
http.header('Content-Disposition', 'attachment; filename="%s"' % {sFile})
http.prepare_content("application/octet-stream")
luci.http.header('Content-Disposition', 'attachment; filename="%s"' % { sFile })
luci.http.prepare_content("application/octet-stream")
while true do
block = fd:read(nixio.const.buffersize)
if (not block) or (#block ==0) then
if (not block) or (#block == 0) then
break
else
http.write(block)
luci.http.write(block)
end
end
fd:close()
http.close()
luci.http.close()
end
-- SimpleForm for Create Snapshot
@ -82,7 +91,7 @@ end
w.write = function(self, section, scope)
local x = luci.sys.exec("btrfs subvolume snapshot -r /etc /.snapshots/etc-" .. os.date("%m.%d.%H%M%S") .. " 2>/dev/null && sync")
http.redirect(DISP.build_url("admin", "system", "amlogic", "backup"))
luci.http.redirect(luci.dispatcher.build_url("admin", "system", "amlogic", "backup"))
end
w = d:option(TextValue, "snapshot_list", nil)
w.template = "amlogic/other_snapshot"

View File

@ -1,14 +1,12 @@
local fs = require "luci.fs2"
local http = require "luci.http"
local DISP = require "luci.dispatcher"
local b
--SimpleForm for Check
b = SimpleForm("amlogic", nil)
b.title = translate("Check Update")
b = SimpleForm("amlogic", nil)
b.title = translate("Check Update")
b.description = translate("Provide OpenWrt Firmware, Kernel and Plugin online check, download and update service.")
b.reset = false
b.submit = false
b:section(SimpleSection).template = "amlogic/other_check"
b.reset = false
b.submit = false
b:section(SimpleSection).template = "amlogic/other_check"
return b

View File

@ -1,15 +1,15 @@
--Remove the spaces in the string
function trim(str)
--return (string.gsub(str, "^%s*(.-)%s*$", "%1"))
return (string.gsub(str, "%s+", ""))
--return (string.gsub(str, "^%s*(.-)%s*$", "%1"))
return (string.gsub(str, "%s+", ""))
end
--Auto-complete node
local check_config_amlogic = luci.sys.exec("uci get amlogic.@amlogic[0].amlogic_firmware_repo 2>/dev/null") or ""
if (trim(check_config_amlogic) == "") then
luci.sys.exec("uci delete amlogic.@amlogic[0] 2>/dev/null")
luci.sys.exec("uci set amlogic.config='amlogic' 2>/dev/null")
luci.sys.exec("uci commit amlogic 2>/dev/null")
luci.sys.exec("uci delete amlogic.@amlogic[0] 2>/dev/null")
luci.sys.exec("uci set amlogic.config='amlogic' 2>/dev/null")
luci.sys.exec("uci commit amlogic 2>/dev/null")
end
b = Map("amlogic")

View File

@ -1,14 +1,12 @@
local fs = require "luci.fs2"
local http = require "luci.http"
local DISP = require "luci.dispatcher"
local b
--SimpleForm for Info
b = SimpleForm("amlogic", nil)
b.title = translate("Amlogic Service")
b = SimpleForm("amlogic", nil)
b.title = translate("Amlogic Service")
b.description = translate("Supports management of Amlogic s9xxx, Allwinner (V-Plus Cloud), and Rockchip (BeikeYun, Chainedbox L1 Pro) boxes.")
b.reset = false
b.submit = false
b:section(SimpleSection).template = "amlogic/other_info"
b.reset = false
b.submit = false
b:section(SimpleSection).template = "amlogic/other_info"
return b

View File

@ -1,14 +1,12 @@
local fs = require "luci.fs2"
local http = require "luci.http"
local DISP = require "luci.dispatcher"
local b
--SimpleForm for Install OpenWrt to Amlogic EMMC
b = SimpleForm("amlogic_install", nil)
b.title = translate("Install OpenWrt")
b = SimpleForm("amlogic_install", nil)
b.title = translate("Install OpenWrt")
b.description = translate("Install OpenWrt to EMMC, Please select the device model, Or enter the dtb file name.")
b.reset = false
b.submit = false
b:section(SimpleSection).template = "amlogic/other_install"
b.reset = false
b.submit = false
b:section(SimpleSection).template = "amlogic/other_install"
return b

View File

@ -1,6 +1,3 @@
local fs = require "luci.fs2"
local http = require "luci.http"
local DISP = require "luci.dispatcher"
local b
--SimpleForm for Server Logs

View File

@ -1,14 +1,12 @@
local fs = require "luci.fs2"
local http = require "luci.http"
local DISP = require "luci.dispatcher"
local b
--SimpleForm for PowerOff
b = SimpleForm("poweroff", nil)
b.title = translate("PowerOff")
b = SimpleForm("poweroff", nil)
b.title = translate("PowerOff")
b.description = translate("Shut down your router device.")
b.reset = false
b.submit = false
b:section(SimpleSection).template = "amlogic/other_poweroff"
b.reset = false
b.submit = false
b:section(SimpleSection).template = "amlogic/other_poweroff"
return b

View File

@ -1,6 +1,11 @@
local fs = require "luci.fs2"
local http = require "luci.http"
local DISP = require "luci.dispatcher"
--Copyright: https://github.com/coolsnowwolf/luci/tree/master/applications/luci-app-filetransfer
--Extended support: https://github.com/ophub/luci-app-amlogic
--Function: Upload files
local os = require "os"
local fs = require "nixio.fs"
local nutil = require "nixio.util"
local type = type
local b, form
--Remove the spaces in the string
@ -9,6 +14,45 @@ function trim(str)
return (string.gsub(str, "%s+", ""))
end
-- Evaluate given shell glob pattern and return a table containing all matching
function glob(...)
local iter, code, msg = fs.glob(...)
if iter then
return nutil.consume(iter)
else
return nil, code, msg
end
end
-- Checks wheather the given path exists and points to a regular file.
function isfile(filename)
return fs.stat(filename, "type") == "reg"
end
-- Get the last modification time of given file path in Unix epoch format.
function mtime(path)
return fs.stat(path, "mtime")
end
local stat_tr = {
reg = "regular",
dir = "directory",
lnk = "link",
chr = "character device",
blk = "block device",
fifo = "fifo",
sock = "socket"
}
-- Get information about given file or directory.
function stat(path, key)
local data, code, msg = fs.stat(path)
if data then
data.mode = data.modestr
data.type = stat_tr[data.type] or "?"
end
return key and data and data[key] or data, code, msg
end
--Set default upload path
local ROOT_PTNAME = trim(luci.sys.exec("df / | tail -n1 | awk '{print $1}' | awk -F '/' '{print $3}'"))
if ROOT_PTNAME then
@ -46,26 +90,26 @@ um.template = "amlogic/other_dvalue"
local dir, fd
dir = upload_path
nixio.fs.mkdir(dir)
http.setfilehandler(
fs.mkdir(dir)
luci.http.setfilehandler(
function(meta, chunk, eof)
if not fd then
if not meta then return end
if meta and chunk then fd = nixio.open(dir .. meta.file, "w") end
if not fd then
if not meta then return end
if meta and chunk then fd = nixio.open(dir .. meta.file, "w") end
if not fd then
um.value = translate("Create upload file error.") .. " Error Info: " .. trim(upload_path .. meta.file)
return
end
end
if chunk and fd then
fd:write(chunk)
end
if eof and fd then
fd:close()
fd = nil
um.value = translate("File saved to") .. trim(upload_path .. meta.file)
um.value = translate("Create upload file error.") .. " Error Info: " .. trim(upload_path .. meta.file)
return
end
end
if chunk and fd then
fd:write(chunk)
end
if eof and fd then
fd:close()
fd = nil
um.value = translate("File saved to") .. trim(upload_path .. meta.file)
end
end
)
if luci.http.formvalue("upload") then
@ -77,18 +121,18 @@ end
local function getSizeStr(size)
local i = 0
local byteUnits = {' kB', ' MB', ' GB', ' TB'}
local byteUnits = { ' kB', ' MB', ' GB', ' TB' }
repeat
size = size / 1024
i = i + 1
until(size <= 1024)
until (size <= 1024)
return string.format("%.1f", size) .. byteUnits[i]
end
local inits, attr = {}
for i, f in ipairs(fs.glob(trim(upload_path .. "*"))) do
attr = fs.stat(f)
itisfile = fs.isfile(f)
for i, f in ipairs(glob(trim(upload_path .. "*"))) do
attr = stat(f)
itisfile = isfile(f)
if attr and itisfile then
inits[i] = {}
inits[i].name = fs.basename(f)
@ -161,7 +205,7 @@ if openwrt_firmware_file then
end
if description_info ~= "" then
form.description = ' <span style="color: green"><b> Tip: ' .. description_info .. ' </b></span> '
form.description = ' <span style="color: green"><b> Tip: ' .. description_info .. ' </b></span> '
end
tb = form:section(Table, inits)
@ -175,7 +219,7 @@ btnrm.render = function(self, section, scope)
Button.render(self, section, scope)
end
btnrm.write = function(self, section)
local v = luci.fs.unlink(trim(upload_path .. luci.fs.basename(inits[section].name)))
local v = fs.unlink(trim(upload_path .. fs.basename(inits[section].name)))
if v then table.remove(inits, section) end
return v
end
@ -213,16 +257,16 @@ end
btnis.write = function(self, section)
if IsIpkFile(inits[section].name) then
local r = luci.sys.exec(string.format('opkg --force-reinstall install ' .. upload_path .. '%s', inits[section].name))
local x = luci.sys.exec("rm -rf /tmp/luci-indexcache /tmp/luci-modulecache/* 2>/dev/null")
local x = luci.sys.exec("rm -rf /tmp/luci-indexcache /tmp/luci-modulecache/* 2>/dev/null")
form.description = string.format('<span style="color: red">%s</span>', r)
elseif IsConfigFile(inits[section].name) then
form.description = ' <span style="color: green"><b> ' .. translate("Tip: The config is being restored, and it will automatically restart after completion.") .. ' </b></span> '
form.description = ' <span style="color: green"><b> ' .. translate("Tip: The config is being restored, and it will automatically restart after completion.") .. ' </b></span> '
local x = luci.sys.exec("chmod +x /usr/sbin/openwrt-backup 2>/dev/null")
local r = luci.sys.exec("/usr/sbin/openwrt-backup -r > /tmp/amlogic/amlogic.log && sync 2>/dev/null")
end
end
--SimpleForm for Check upload files
form:section(SimpleSection).template = "amlogic/other_upfiles"
form:section(SimpleSection).template = "amlogic/other_upfiles"
return b, form