From 88733913169bd47ab6a437ced128ee0c5eda39b8 Mon Sep 17 00:00:00 2001 From: kenzok8 Date: Tue, 2 Jul 2024 20:32:00 +0800 Subject: [PATCH] update 2024-07-02 20:32:00 --- luci-app-store/Makefile | 2 +- luci-app-store/luasrc/controller/store.lua | 38 +++++++++- luci-app-store/root/bin/is-opkg | 3 + luci-app-store/swagger.yaml | 84 +++++++++++++++++++++- 4 files changed, 122 insertions(+), 5 deletions(-) diff --git a/luci-app-store/Makefile b/luci-app-store/Makefile index c1219c440..7bbdee446 100644 --- a/luci-app-store/Makefile +++ b/luci-app-store/Makefile @@ -11,7 +11,7 @@ LUCI_DEPENDS:=+curl +opkg +luci-base +tar +coreutils +coreutils-stat +libuci-lua LUCI_EXTRA_DEPENDS:=luci-lib-taskd (>=1.0.19) LUCI_PKGARCH:=all -PKG_VERSION:=0.1.22-0 +PKG_VERSION:=0.1.23-0 # PKG_RELEASE MUST be empty for luci.mk PKG_RELEASE:= diff --git a/luci-app-store/luasrc/controller/store.lua b/luci-app-store/luasrc/controller/store.lua index 2f6dec978..b7561e6d8 100644 --- a/luci-app-store/luasrc/controller/store.lua +++ b/luci-app-store/luasrc/controller/store.lua @@ -29,6 +29,7 @@ function index() entry({"admin", "store", "get_block_devices"}, call("get_block_devices")) entry({"admin", "store", "configured"}, call("configured")) + entry({"admin", "store", "entrysh"}, post("entrysh")) -- docker entry({"admin", "store", "docker_check_dir"}, call("docker_check_dir")) @@ -36,7 +37,7 @@ function index() entry({"admin", "store", "docker_migrate"}, post("docker_migrate")) -- package - for _, action in ipairs({"update", "install", "upgrade", "remove"}) do + for _, action in ipairs({"update", "install", "upgrade", "remove", "autoconf"}) do store_api(action, true) end for _, action in ipairs({"status", "installed"}) do @@ -302,8 +303,8 @@ function store_action(param) end local metapkg = pkg and (metapkgpre .. pkg) or "" if action == "update" or pkg then - if action == "update" or action == "install" then - if action == "install" and "1" == luci.http.formvalue("autoconf") then + if action == "update" or action == "install" or action == "autoconf" then + if (action == "install" and "1" == luci.http.formvalue("autoconf")) or action == "autoconf" then local autoenv = "AUTOCONF=" .. pkg local autopath = luci.http.formvalue("path") local autoenable = luci.http.formvalue("enable") @@ -416,6 +417,37 @@ function configured() luci.http.write_json({code=200, configured=configured}) end +function entrysh() + local package = luci.http.formvalue("package") + local hostname = luci.http.formvalue("hostname") + if hostname == nil or hostname == "" or not validate_pkgname(package) then + luci.http.status(400, "Bad Request") + return + end + + local result + local entryfile = "/usr/libexec/istoree/" .. package .. ".sh" + if nixio.fs.access(entryfile) then + local o = luci.util.exec(entryfile .. " status " .. luci.util.shellquote(hostname)) + if o == nil or o == "" then + result = {code=500, msg="entrysh execute failed"} + else + local jsonc = require "luci.jsonc" + local json_parse = jsonc.parse + local status = json_parse(o) + if status == nil then + result = {code=500, msg="json parse failed: " .. o} + else + result = {code=200, status=status} + end + end + else + result = {code=404, msg="entrysh of this package not found"} + end + luci.http.prepare_content("application/json") + luci.http.write_json(result) +end + function docker_check_dir() local docker_on_system = luci.sys.call("/usr/libexec/istore/docker check_dir >/dev/null 2>&1") ~= 0 luci.http.prepare_content("application/json") diff --git a/luci-app-store/root/bin/is-opkg b/luci-app-store/root/bin/is-opkg index 8031e409f..5fbe84749 100755 --- a/luci-app-store/root/bin/is-opkg +++ b/luci-app-store/root/bin/is-opkg @@ -247,6 +247,9 @@ case $action in check_space wrapped_in_update opkg_wrap_mirrors install "$@" && try_autoconf ;; + "autoconf") + try_autoconf + ;; "upgrade") new_upgrade "$@" ;; diff --git a/luci-app-store/swagger.yaml b/luci-app-store/swagger.yaml index bb7f69135..ac1f89d52 100644 --- a/luci-app-store/swagger.yaml +++ b/luci-app-store/swagger.yaml @@ -55,6 +55,33 @@ paths: description: OK schema: $ref: "#/definitions/ResponseStore" + /cgi-bin/luci/admin/store/autoconf: + post: + tags: + - install + summary: 自动配置插件 + parameters: + - in: "query" + name: "token" + type: string + required: true + - in: "query" + name: "package" + type: string + required: true + - in: "query" + name: "path" + type: string + description: "可选参数" + - in: "query" + name: "enable" + type: string + description: "可选参数" + responses: + "200": + description: OK + schema: + $ref: "#/definitions/ResponseStore" /cgi-bin/luci/admin/store/remove: post: tags: @@ -205,6 +232,32 @@ paths: description: OK schema: $ref: "#/definitions/ResponseStoreConfigured" + /cgi-bin/luci/admin/store/entrysh: + post: + tags: + - entrysh + summary: 查询插件运行状态,主要为了获取入口信息。 + description: 调用前应该检查meta数据中autoconf数组包含entrysh,注意如果是安装插件则检查服务器端的autoconf,如果是调用已安装插件则检查路由器端的autoconf。 + parameters: + - in: "query" + name: "token" + type: string + required: true + - in: "query" + name: "package" + type: string + required: true + description: "包名,例如aria2" + - in: "query" + name: "hostname" + type: string + required: true + description: "主机名,不包含端口。前端应该使用location.hostname获取" + responses: + "200": + description: OK + schema: + $ref: "#/definitions/ResponseStoreEntrysh" /cgi-bin/luci/admin/store/docker_check_dir: get: tags: @@ -235,7 +288,8 @@ paths: post: tags: - docker_migrate - summary: docker迁移到目标目录,异步,当返回code为0的时候,可以使用taskd接口展示日志,跟安装插件时一样 + summary: docker迁移到目标目录,异步 + description: 当返回code为0的时候,可以使用taskd接口展示日志,跟安装插件时一样 parameters: - in: "query" name: "token" @@ -401,5 +455,33 @@ definitions: error: type: string description: "当result为bad时,此处返回错误日志" + ResponseStoreEntrysh: + type: object + properties: + code: + type: integer + description: "为200时" + msg: + type: string + description: "code不为200时显示错误信息" + status: + type: object + description: "状态和入口信息,不同插件可能有些不一样,仅列出常用公共参数" + properties: + app: + type: string + description: "插件名称,跟请求的包名一致" + docker: + type: boolean + description: "如果是docker插件" + running: + type: boolean + description: "是否运行中" + deployed: + type: boolean + description: "如果是docker插件且未运行,则是否已经部署" + web: + type: string + description: "web端跳转url"