From 70a9891f4a5dc28d47c2a8161ec8d8f9ffa3b26b Mon Sep 17 00:00:00 2001 From: Lienol Date: Sun, 14 Jun 2020 18:26:17 +0800 Subject: [PATCH] luci-app-kodexplorer: update api new version (#4788) --- package/lean/luci-app-kodexplorer/Makefile | 6 +- .../luasrc/controller/kodexplorer.lua | 20 +- .../luasrc/model/cbi/kodexplorer/api.lua | 79 ++--- .../luasrc/view/kodexplorer/download.htm | 278 +++++++++--------- .../luasrc/view/kodexplorer/status.htm | 15 +- .../luasrc/view/kodexplorer/version.htm | 8 +- .../etc/uci-defaults/luci-app-kodexplorer | 2 +- .../rpcd/acl.d/luci-app-kodexplorer.json | 11 + 8 files changed, 198 insertions(+), 221 deletions(-) create mode 100644 package/lean/luci-app-kodexplorer/root/usr/share/rpcd/acl.d/luci-app-kodexplorer.json diff --git a/package/lean/luci-app-kodexplorer/Makefile b/package/lean/luci-app-kodexplorer/Makefile index 532719285..91245e646 100644 --- a/package/lean/luci-app-kodexplorer/Makefile +++ b/package/lean/luci-app-kodexplorer/Makefile @@ -6,10 +6,10 @@ include $(TOPDIR)/rules.mk LUCI_TITLE:=LuCI support for KodExplorer -LUCI_DEPENDS:=+nginx +zoneinfo-asia +php7 +php7-fpm +php7-mod-curl +php7-mod-gd +php7-mod-iconv +php7-mod-json +php7-mod-mbstring +php7-mod-opcache +php7-mod-session +php7-mod-zip +LUCI_DEPENDS:=+nginx +zoneinfo-asia +php7 +php7-fpm +php7-mod-curl +php7-mod-gd +php7-mod-iconv +php7-mod-json +php7-mod-mbstring +php7-mod-opcache +php7-mod-session +php7-mod-zip +php7-mod-sqlite3 +php7-mod-pdo +php7-mod-pdo-sqlite +php7-mod-pdo-mysql LUCI_PKGARCH:=all -PKG_VERSION:=1.1 -PKG_RELEASE:=20200210 +PKG_VERSION:=13 +PKG_DATE:=20200612 include $(TOPDIR)/feeds/luci/luci.mk diff --git a/package/lean/luci-app-kodexplorer/luasrc/controller/kodexplorer.lua b/package/lean/luci-app-kodexplorer/luasrc/controller/kodexplorer.lua index 08ec22fba..b8b2347c8 100644 --- a/package/lean/luci-app-kodexplorer/luasrc/controller/kodexplorer.lua +++ b/package/lean/luci-app-kodexplorer/luasrc/controller/kodexplorer.lua @@ -8,15 +8,11 @@ function index() if not nixio.fs.access("/etc/config/kodexplorer") then return end entry({"admin", "nas"}, firstchild(), "NAS", 44).dependent = false - entry({"admin", "nas", "kodexplorer"}, cbi("kodexplorer/settings"), - _("KodExplorer"), 3).dependent = true + entry({"admin", "nas", "kodexplorer"}, cbi("kodexplorer/settings"), _("KodExplorer"), 3).dependent = true - entry({"admin", "nas", "kodexplorer", "check"}, call("action_check")).leaf = - true - entry({"admin", "nas", "kodexplorer", "download"}, call("action_download")).leaf = - true - entry({"admin", "nas", "kodexplorer", "status"}, call("act_status")).leaf = - true + entry({"admin", "nas", "kodexplorer", "check"}, call("action_check")).leaf = true + entry({"admin", "nas", "kodexplorer", "download"}, call("action_download")).leaf = true + entry({"admin", "nas", "kodexplorer", "status"}, call("act_status")).leaf = true end local function http_write_json(content) @@ -26,12 +22,8 @@ end function act_status() local e = {} - e.nginx_status = luci.sys.call( - "ps -w | grep nginx | grep kodexplorer | grep -v grep > /dev/null") == - 0 - e.php_status = luci.sys.call( - "ps -w | grep php | grep kodexplorer | grep -v grep > /dev/null") == - 0 + e.nginx_status = luci.sys.call("ps -w | grep nginx | grep kodexplorer | grep -v grep > /dev/null") == 0 + e.php_status = luci.sys.call("ps -w | grep php | grep kodexplorer | grep -v grep > /dev/null") == 0 http_write_json(e) end diff --git a/package/lean/luci-app-kodexplorer/luasrc/model/cbi/kodexplorer/api.lua b/package/lean/luci-app-kodexplorer/luasrc/model/cbi/kodexplorer/api.lua index ac00a4cc6..949dd094f 100644 --- a/package/lean/luci-app-kodexplorer/luasrc/model/cbi/kodexplorer/api.lua +++ b/package/lean/luci-app-kodexplorer/luasrc/model/cbi/kodexplorer/api.lua @@ -7,26 +7,12 @@ local i18n = require "luci.i18n" module("luci.model.cbi.kodexplorer.api", package.seeall) local appname = "kodexplorer" -local api_url = - "https://api.github.com/repos/kalcaddle/KodExplorer/releases/latest" -local download_url = "https://github.com/kalcaddle/KodExplorer/archive/" +local api_url = "https://api.kodcloud.com/?app/version" local wget = "/usr/bin/wget" -local wget_args = { - "--no-check-certificate", "--quiet", "--timeout=10", "--tries=2" -} +local wget_args = { "--no-check-certificate", "--quiet", "--timeout=10", "--tries=2" } local command_timeout = 300 -function uci_get_type(type, config, default) - value = uci:get(appname, "@" .. type .. "[0]", config) or sys.exec( - "echo -n `uci -q get " .. appname .. ".@" .. type .. "[0]." .. - config .. "`") - if (value == nil or value == "") and (default and default ~= "") then - value = default - end - return value -end - local function _unpack(t, i) i = i or 1 if t[i] ~= nil then return t[i], _unpack(t, i + 1) end @@ -77,6 +63,15 @@ local function exec(cmd, args, writer, timeout) end end +function get_project_directory() + return uci:get(appname, "@global[0]", "project_directory") or "/tmp/kodcloud" +end + +function get_version() + local version = get_project_directory() .. "/config/version.php" + return sys.exec(string.format("echo -n $(cat %s 2>/dev/null | grep \"'KOD_VERSION'\" | cut -d \"'\" -f 4)", version)) +end + local function compare_versions(ver1, comp, ver2) local table = table @@ -108,42 +103,16 @@ local function get_api_json(url) -- function(chunk) output[#output + 1] = chunk end) -- local json_content = util.trim(table.concat(output)) - local json_content = luci.sys.exec("wget-ssl -q --no-check-certificate -O- " .. url) + local json_content = sys.exec(wget .. " --no-check-certificate --timeout=10 -t 1 -O- " .. url) if json_content == "" then return {} end return jsonc.parse(json_content) or {} end -function get_project_directory() - return uci_get_type("global", "project_directory", "/tmp/kodexplorer") -end - function to_check() local json = get_api_json(api_url) - if json.tag_name == nil then - return { - code = 1, - error = i18n.translate("Get remote version info failed.") - } - end - local remote_version = json.tag_name - local html_url = json.html_url - download_url = download_url .. json.tag_name .. ".tar.gz" - if not download_url then - return { - code = 1, - version = remote_version, - html_url = html_url, - error = i18n.translate( - "New version found, but failed to get new version download url.") - } - end - return { - code = 0, - version = remote_version, - url = {html = html_url, download = download_url} - } + return json end function to_download(url) @@ -151,13 +120,11 @@ function to_download(url) return {code = 1, error = i18n.translate("Download url is required.")} end - sys.call("/bin/rm -f /tmp/kodexplorer_download.*") + sys.call("/bin/rm -f /tmp/kodcloud_download.*") - local tmp_file = util.trim(util.exec( - "mktemp -u -t kodexplorer_download.XXXXXX")) + local tmp_file = util.trim(util.exec("mktemp -u -t kodcloud_download.XXXXXX")) - local result = exec(wget, {"-O", tmp_file, url, _unpack(wget_args)}, nil, - command_timeout) == 0 + local result = exec(wget, {"-O", tmp_file, url, _unpack(wget_args)}, nil, command_timeout) == 0 if not result then exec("/bin/rm", {"-f", tmp_file}) @@ -175,13 +142,11 @@ function to_extract(file) return {code = 1, error = i18n.translate("File path required.")} end - sys.call("/bin/rm -rf /tmp/kodexplorer_extract.*") - local tmp_dir = util.trim(util.exec( - "mktemp -d -t kodexplorer_extract.XXXXXX")) + sys.call("/bin/rm -rf /tmp/kodcloud_extract.*") + local tmp_dir = util.trim(util.exec("mktemp -d -t kodcloud_extract.XXXXXX")) local output = {} - exec("/bin/tar", {"-C", tmp_dir, "-zxvf", file}, - function(chunk) output[#output + 1] = chunk end) + exec("/usr/bin/unzip", {"-o", file, "-d", tmp_dir}, function(chunk) output[#output + 1] = chunk end) local files = util.split(table.concat(output)) @@ -192,14 +157,14 @@ end function to_move(file) if not file or file == "" or not fs.access(file) then - sys.call("/bin/rm -rf /tmp/kodexplorer_extract.*") + sys.call("/bin/rm -rf /tmp/kodcloud_extract.*") return {code = 1, error = i18n.translate("Client file is required.")} end local client_file = get_project_directory() sys.call("mkdir -p " .. client_file) - sys.call("cp -R " .. file .. "/KodExplorer*/* " .. client_file) - sys.call("/bin/rm -rf /tmp/kodexplorer_extract.*") + sys.call("cp -R " .. file .. "/* " .. client_file) + sys.call("/bin/rm -rf /tmp/kodcloud_extract.*") return {code = 0} end diff --git a/package/lean/luci-app-kodexplorer/luasrc/view/kodexplorer/download.htm b/package/lean/luci-app-kodexplorer/luasrc/view/kodexplorer/download.htm index fa271d6a6..21e522836 100644 --- a/package/lean/luci-app-kodexplorer/luasrc/view/kodexplorer/download.htm +++ b/package/lean/luci-app-kodexplorer/luasrc/view/kodexplorer/download.htm @@ -1,161 +1,163 @@ -<% -local dsp = require "luci.dispatcher" --%> + + // Move file to target dir + doAjaxGet(UpdateUrl, { + token: tokenStr, + task: 'move', + file: json.file + }, function (json) { + removePageNotice(); + if (json.code) { + onRequestError(btn, json.error); + } else { + onUpdateSuccess(btn); + } + }) + } + }) + } + }) + } + //]]> + <%+cbi/valueheader%> <% if self:cfgvalue(section) ~= false then %> diff --git a/package/lean/luci-app-kodexplorer/luasrc/view/kodexplorer/status.htm b/package/lean/luci-app-kodexplorer/luasrc/view/kodexplorer/status.htm index 8b0a84b12..61ab40ff6 100644 --- a/package/lean/luci-app-kodexplorer/luasrc/view/kodexplorer/status.htm +++ b/package/lean/luci-app-kodexplorer/luasrc/view/kodexplorer/status.htm @@ -22,10 +22,17 @@ local dsp = require "luci.dispatcher" XHR.poll(3,'<%=dsp.build_url("admin/nas/kodexplorer/status")%>', null, function(x, json) { if (x && x.status == 200) { - if (nginx_status) - nginx_status.innerHTML = json.nginx_status ? '<%:RUNNING%> ✓' : '<%:NOT RUNNING%> X'; - if (php_status) + if (nginx_status) { + nginx_status.innerHTML = json.nginx_status ? '<%:RUNNING%> ✓' : '<%:NOT RUNNING%> X'; + } + if (php_status) { php_status.innerHTML = json.php_status ? '<%:RUNNING%> ✓' : '<%:NOT RUNNING%> X'; + } } - }); + } + ); + function openwebui(){ + var url = window.location.host+":<%=luci.sys.exec("uci -q get kodexplorer.@global[0].port"):gsub("^%s*(.-)%s*$", "%1")%>"; + window.open('http://'+url,'target',''); + } //]]> \ No newline at end of file diff --git a/package/lean/luci-app-kodexplorer/luasrc/view/kodexplorer/version.htm b/package/lean/luci-app-kodexplorer/luasrc/view/kodexplorer/version.htm index 1a9c6d61a..c51541733 100644 --- a/package/lean/luci-app-kodexplorer/luasrc/view/kodexplorer/version.htm +++ b/package/lean/luci-app-kodexplorer/luasrc/view/kodexplorer/version.htm @@ -1,16 +1,16 @@ <% -local kodexplorer_path = luci.sys.exec("echo -n `uci get kodexplorer.@global[0].project_directory`") -local kodexplorer_version = luci.sys.exec("[ -f '" .. kodexplorer_path .. "/ChangeLog.md' ] && echo -n `cat " .. kodexplorer_path .. "/ChangeLog.md | head -1 | awk '{print $2}'`") +local api = require "luci.model.cbi.kodexplorer.api" +local app_version = api.get_version() -%> -<% if kodexplorer_version ~= nil and kodexplorer_version~="" then %> +<% if app_version and app_version ~= "" then %>
- 【 <%=kodexplorer_version%> 】 + 【 <%=app_version%> 】
diff --git a/package/lean/luci-app-kodexplorer/root/etc/uci-defaults/luci-app-kodexplorer b/package/lean/luci-app-kodexplorer/root/etc/uci-defaults/luci-app-kodexplorer index 3b9196276..4ac2bb502 100755 --- a/package/lean/luci-app-kodexplorer/root/etc/uci-defaults/luci-app-kodexplorer +++ b/package/lean/luci-app-kodexplorer/root/etc/uci-defaults/luci-app-kodexplorer @@ -8,5 +8,5 @@ uci -q batch <<-EOF >/dev/null EOF /etc/init.d/php7-fpm disable && /etc/init.d/php7-fpm stop -rm -f /tmp/luci-indexcache +rm -rf /tmp/luci-*cache exit 0 diff --git a/package/lean/luci-app-kodexplorer/root/usr/share/rpcd/acl.d/luci-app-kodexplorer.json b/package/lean/luci-app-kodexplorer/root/usr/share/rpcd/acl.d/luci-app-kodexplorer.json new file mode 100644 index 000000000..96e28b0c8 --- /dev/null +++ b/package/lean/luci-app-kodexplorer/root/usr/share/rpcd/acl.d/luci-app-kodexplorer.json @@ -0,0 +1,11 @@ +{ + "luci-app-kodexplorer": { + "description": "Grant UCI access for luci-app-kodexplorer", + "read": { + "uci": [ "kodexplorer" ] + }, + "write": { + "uci": [ "kodexplorer" ] + } + } +}