mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-19 15:03:22 +08:00
🗽 Sync 2026-10-23 00:46:23
This commit is contained in:
1 parent
6032a57538
commit
2b29b0c4e1
112 files changed
+1859
-6208
No files matched your search
@@ -8,8 +8,8 @@ include $(TOPDIR)/rules.mk
|
||||
|
||||
LUCI_TITLE:=KaiPlus
|
||||
PKG_VERSION:=1.0.9
|
||||
PKG_RELEASE:=11
|
||||
LUCI_DEPENDS:=+kaiplus +luci-compat +luci-lib-linkeaseauth +linkease-app-entry
|
||||
PKG_RELEASE:=12
|
||||
LUCI_DEPENDS:=+kaiplus +luci-compat +luci-lib-taskd +luci-lib-linkeaseauth +linkease-app-entry
|
||||
LUCI_MINIFY_CSS:=0
|
||||
LUCI_MINIFY_JS:=0
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
local http = require "luci.http"
|
||||
|
||||
module("luci.controller.kaiplus", package.seeall)
|
||||
|
||||
function index()
|
||||
@@ -9,9 +11,36 @@ function index()
|
||||
open.sysauth_authenticator = "htmlauth"
|
||||
|
||||
if not nixio.fs.access("/etc/config/kaiplus") then return end
|
||||
local install_kai = entry({"admin", "services", "kaiplus", "install_kai"}, call("install_kai"))
|
||||
install_kai.leaf = true
|
||||
entry({"admin", "services", "kaiplus"}, cbi("kaiplus"), _("KaiPlus"), 100).dependent = true
|
||||
end
|
||||
|
||||
local function write_json(obj)
|
||||
http.prepare_content("application/json")
|
||||
http.write_json(obj)
|
||||
end
|
||||
|
||||
local function require_post_csrf()
|
||||
local dispatcher = require "luci.dispatcher"
|
||||
local context = dispatcher.context or {}
|
||||
local expected = context.authtoken or context.token
|
||||
|
||||
if (http.getenv("REQUEST_METHOD") or "") ~= "POST" then
|
||||
http.status(405, "Method Not Allowed")
|
||||
write_json({ ok = false, error = "method not allowed" })
|
||||
return false
|
||||
end
|
||||
|
||||
if not context.authsession or not expected or http.formvalue("token") ~= expected then
|
||||
http.status(403, "Forbidden")
|
||||
write_json({ ok = false, error = "invalid csrf token" })
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
local function compat()
|
||||
local dispatcher = require "luci.dispatcher"
|
||||
return require("luci.model.linkease.apps_compat").new({
|
||||
@@ -22,16 +51,19 @@ local function compat()
|
||||
end
|
||||
|
||||
function kaiplus_status()
|
||||
local fs = require "nixio.fs"
|
||||
local sys = require "luci.sys"
|
||||
local uci = require("luci.model.uci").cursor()
|
||||
local external_port_enabled = uci:get_first("kaiplus", "kaiplus", "external_port_enabled") == "1"
|
||||
compat():legacy_status("kaiplus", {
|
||||
running = sys.call("pidof kaiplus_bin >/dev/null") == 0,
|
||||
running = sys.call("pidof kaiplus >/dev/null") == 0,
|
||||
kai_installed = not not (
|
||||
fs.access("/usr/share/kai/kai-plugin.json")
|
||||
and fs.access("/usr/lib/lua/luci/controller/kai.lua")
|
||||
),
|
||||
port = uci:get_first("kaiplus", "kaiplus", "port") or "8189",
|
||||
base_path = uci:get_first("kaiplus", "kaiplus", "base_path") or "/apps/kaiplus/",
|
||||
listen_mode = uci:get_first("kaiplus", "kaiplus", "listen_mode") or "auto",
|
||||
socket_path = uci:get_first("kaiplus", "kaiplus", "socket_path") or "/var/run/kaiplus.sock",
|
||||
external_port_enabled = external_port_enabled,
|
||||
base_path = "/apps/kaiplus/",
|
||||
listen_mode = "tcp",
|
||||
external_port_enabled = true,
|
||||
lan_ip = uci:get("network", "lan", "ipaddr") or ""
|
||||
})
|
||||
end
|
||||
@@ -39,3 +71,53 @@ end
|
||||
function kaiplus_open()
|
||||
compat():open("kaiplus")
|
||||
end
|
||||
|
||||
function install_kai()
|
||||
local fs = require "nixio.fs"
|
||||
local jsonc = require "luci.jsonc"
|
||||
local sys = require "luci.sys"
|
||||
local util = require "luci.util"
|
||||
local task_id = "kaiplus-kai-install"
|
||||
|
||||
if not require_post_csrf() then
|
||||
return
|
||||
end
|
||||
|
||||
if fs.access("/usr/share/kai/kai-plugin.json")
|
||||
and fs.access("/usr/lib/lua/luci/controller/kai.lua") then
|
||||
write_json({ ok = true, installed = true })
|
||||
return
|
||||
end
|
||||
if not fs.access("/etc/init.d/tasks") then
|
||||
write_json({ ok = false, error = "taskd is not available" })
|
||||
return
|
||||
end
|
||||
if not fs.access("/bin/is-opkg") then
|
||||
write_json({ ok = false, error = "iStore package installer is not available" })
|
||||
return
|
||||
end
|
||||
|
||||
local task_status = sys.exec("/etc/init.d/tasks task_status " .. task_id .. " 2>/dev/null")
|
||||
local status = jsonc.parse(task_status) or {}
|
||||
local running = type(status) == "table" and status.running
|
||||
if running == true or running == 1 or running == "1" or running == "true" then
|
||||
write_json({ ok = true, busy = true, task_id = task_id })
|
||||
return
|
||||
end
|
||||
|
||||
local install_script = table.concat({
|
||||
'set -e',
|
||||
'echo "[KaiPlus] Installing classic KAI..."',
|
||||
'/bin/is-opkg install luci-app-kai',
|
||||
'rm -f /tmp/luci-indexcache',
|
||||
'echo "[KaiPlus] Classic KAI installed successfully."'
|
||||
}, "\n")
|
||||
local command = "/bin/sh -c " .. util.shellquote(install_script)
|
||||
local rc = sys.call("/etc/init.d/tasks task_add " .. task_id .. " " .. util.shellquote(command) .. " >/dev/null 2>&1")
|
||||
if rc ~= 0 then
|
||||
write_json({ ok = false, error = "failed to start KAI installation", task_id = task_id })
|
||||
return
|
||||
end
|
||||
|
||||
write_json({ ok = true, task_id = task_id })
|
||||
end
|
||||
@@ -31,41 +31,10 @@ for _, val in pairs(paths) do
|
||||
end
|
||||
data_dir.default = default_path
|
||||
|
||||
local listen_mode = s:option(ListValue, "listen_mode", translate("Listen mode"))
|
||||
listen_mode:value("auto", translate("Auto"))
|
||||
listen_mode:value("unix", translate("Unix socket"))
|
||||
listen_mode:value("tcp", translate("TCP port"))
|
||||
listen_mode.default = "auto"
|
||||
listen_mode.rmempty = false
|
||||
|
||||
local external_port_enabled = s:option(Flag, "external_port_enabled", translate("Enable external port access"))
|
||||
external_port_enabled.default = "0"
|
||||
external_port_enabled.rmempty = false
|
||||
|
||||
local socket_path = s:option(Value, "socket_path", translate("Unix socket path"))
|
||||
socket_path.default = "/var/run/kaiplus.sock"
|
||||
socket_path.rmempty = false
|
||||
socket_path.readonly = true
|
||||
|
||||
local port = s:option(Value, "port", translate("Web port"))
|
||||
local port = s:option(Value, "port", translate("Access port"))
|
||||
port.default = "8189"
|
||||
port.rmempty = false
|
||||
port.datatype = "port"
|
||||
port.description = translate("Port for the KaiPlus web service.")
|
||||
|
||||
local bind_addr = s:option(Value, "bind_addr", translate("Bind address"))
|
||||
bind_addr.default = "0.0.0.0"
|
||||
bind_addr.rmempty = false
|
||||
|
||||
local base_path = s:option(Value, "base_path", translate("Base path"))
|
||||
base_path.default = "/apps/kaiplus/"
|
||||
base_path.rmempty = false
|
||||
base_path.readonly = true
|
||||
|
||||
local release_channel = s:option(ListValue, "release_channel", translate("Release channel"))
|
||||
release_channel:value("stable", translate("Stable"))
|
||||
release_channel:value("canary", translate("Canary"))
|
||||
release_channel.default = "stable"
|
||||
release_channel.rmempty = false
|
||||
port.description = translate("KaiPlus is available at http://router-address:port/apps/kaiplus/.")
|
||||
|
||||
return m
|
||||
@@ -1,7 +1,68 @@
|
||||
<%+tasks/embed%>
|
||||
|
||||
<style type="text/css">
|
||||
.kaiplus-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin: 16px;
|
||||
}
|
||||
.kaiplus-actions .cbi-button {
|
||||
min-height: 40px;
|
||||
transition: transform 120ms ease-out;
|
||||
}
|
||||
.kaiplus-actions .cbi-button:active {
|
||||
transform: scale(0.96);
|
||||
}
|
||||
</style>
|
||||
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
var kaiInstalled = false;
|
||||
var kaiLuciUrl = '<%=url("admin/services/kai")%>';
|
||||
var kaiInstallUrl = '<%=url("admin/services/kaiplus/install_kai")%>';
|
||||
var kaiCsrfToken = (window.taskd && window.taskd.csrfToken) || '';
|
||||
|
||||
function openClassicKai() {
|
||||
var button = document.getElementById('kaiplus-open-kai');
|
||||
if (kaiInstalled) {
|
||||
window.location.href = kaiLuciUrl;
|
||||
return;
|
||||
}
|
||||
if (!window.confirm('<%:Classic KAI is not installed. Install it now?%>')) return;
|
||||
if (!window.taskd || !window.taskd.show_log) {
|
||||
window.alert('<%:Task log window is not available.%>');
|
||||
return;
|
||||
}
|
||||
|
||||
button.disabled = true;
|
||||
button.value = '<%:Starting installation...%>';
|
||||
(new XHR()).post(kaiInstallUrl, { token: kaiCsrfToken }, function(x) {
|
||||
var data = {};
|
||||
button.disabled = false;
|
||||
button.value = '<%:Classic KAI%>';
|
||||
if (x && x.responseText) {
|
||||
try { data = JSON.parse(x.responseText || '{}'); }
|
||||
catch (e) { data = {}; }
|
||||
}
|
||||
if (!data.ok) {
|
||||
window.alert(data.error || '<%:Failed to start KAI installation.%>');
|
||||
return;
|
||||
}
|
||||
if (data.installed) {
|
||||
kaiInstalled = true;
|
||||
window.location.href = kaiLuciUrl;
|
||||
return;
|
||||
}
|
||||
window.taskd.show_log(data.task_id || 'kaiplus-kai-install');
|
||||
});
|
||||
}
|
||||
|
||||
XHR.poll(5, '<%=url("admin/services/kaiplus_status")%>', null, function(x, st) {
|
||||
var el = document.getElementById('kaiplus_status');
|
||||
var openButton = document.getElementById('kaiplus-open');
|
||||
if (st && el) {
|
||||
kaiInstalled = st.kai_installed === true;
|
||||
var status = st.running
|
||||
? '<br/><em style=\"color:green\"><%:The KaiPlus service is running.%></em>'
|
||||
: '<br/><em style=\"color:red\"><%:The KaiPlus service is not running.%></em>';
|
||||
@@ -15,10 +76,7 @@ XHR.poll(5, '<%=url("admin/services/kaiplus_status")%>', null, function(x, st) {
|
||||
status = status + '<br/><em><%:External port access is disabled.%></em>';
|
||||
}
|
||||
el.innerHTML = status;
|
||||
if (st.running) {
|
||||
el.innerHTML = el.innerHTML
|
||||
+ "<br/><br/><input class=\"btn cbi-button cbi-button-apply\" type=\"button\" value=\" <%:Click to open KaiPlus%> \" onclick=\"window.open('<%=url("admin/services/kaiplus/open")%>')\"/>";
|
||||
}
|
||||
if (openButton) openButton.style.display = st.running ? '' : 'none';
|
||||
}
|
||||
});
|
||||
//]]></script>
|
||||
@@ -28,4 +86,8 @@ XHR.poll(5, '<%=url("admin/services/kaiplus_status")%>', null, function(x, st) {
|
||||
<p id="kaiplus_status">
|
||||
<em><%:Collecting data...%></em>
|
||||
</p>
|
||||
<div class="kaiplus-actions">
|
||||
<input id="kaiplus-open" class="btn cbi-button cbi-button-apply" type="button" value=" <%:Click to open KaiPlus%> " onclick="window.open('<%=url("admin/services/kaiplus/open")%>')" style="display:none"/>
|
||||
<input id="kaiplus-open-kai" class="btn cbi-button" type="button" value=" <%:Classic KAI%> " onclick="openClassicKai()"/>
|
||||
</div>
|
||||
</fieldset>
|
||||
@@ -0,0 +1,65 @@
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=UTF-8"
|
||||
|
||||
msgid "KaiPlus"
|
||||
msgstr "酷友社AI"
|
||||
|
||||
msgid "KaiPlus is an AI workspace and session service."
|
||||
msgstr "酷友社AI 是一款 AI 工作区与会话服务。"
|
||||
|
||||
msgid "Global settings"
|
||||
msgstr "全局设置"
|
||||
|
||||
msgid "Enable"
|
||||
msgstr "启用"
|
||||
|
||||
msgid "Data directory"
|
||||
msgstr "数据目录"
|
||||
|
||||
msgid "Required. KaiPlus stores workspace, cache, config, and state under this directory."
|
||||
msgstr "必填。酷友社AI 会在此目录中保存工作区、缓存、配置和状态数据。"
|
||||
|
||||
msgid "Access port"
|
||||
msgstr "访问端口"
|
||||
|
||||
msgid "KaiPlus is available at http://router-address:port/apps/kaiplus/."
|
||||
msgstr "可通过 http://路由器地址:端口/apps/kaiplus/ 访问酷友社AI。"
|
||||
|
||||
msgid "The KaiPlus service is running."
|
||||
msgstr "酷友社AI 服务正在运行。"
|
||||
|
||||
msgid "The KaiPlus service is not running."
|
||||
msgstr "酷友社AI 服务未运行。"
|
||||
|
||||
msgid "Access mode: LinkEase Desktop proxy."
|
||||
msgstr "访问模式:LinkEase Desktop 代理。"
|
||||
|
||||
msgid "Access mode: external port."
|
||||
msgstr "访问模式:外部端口。"
|
||||
|
||||
msgid "External port access is disabled."
|
||||
msgstr "外部端口访问已禁用。"
|
||||
|
||||
msgid "Click to open KaiPlus"
|
||||
msgstr "点击打开酷友社AI"
|
||||
|
||||
msgid "Classic KAI"
|
||||
msgstr "经典版 KAI"
|
||||
|
||||
msgid "Classic KAI is not installed. Install it now?"
|
||||
msgstr "尚未安装经典版 KAI,是否现在安装?"
|
||||
|
||||
msgid "Task log window is not available."
|
||||
msgstr "任务日志窗口不可用。"
|
||||
|
||||
msgid "Starting installation..."
|
||||
msgstr "正在启动安装……"
|
||||
|
||||
msgid "Failed to start KAI installation."
|
||||
msgstr "无法启动经典版 KAI 安装任务。"
|
||||
|
||||
msgid "Status"
|
||||
msgstr "状态"
|
||||
|
||||
msgid "Collecting data..."
|
||||
msgstr "正在获取数据……"
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
zh-cn
|
||||
@@ -0,0 +1,57 @@
|
||||
from pathlib import Path
|
||||
import unittest
|
||||
|
||||
|
||||
APP_DIR = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
class ClassicKaiEntryContractTest(unittest.TestCase):
|
||||
def read(self, relative):
|
||||
return (APP_DIR / relative).read_text(encoding="utf-8")
|
||||
|
||||
def test_status_reports_classic_kai_manifest(self):
|
||||
controller = self.read("luasrc/controller/kaiplus.lua")
|
||||
|
||||
self.assertIn('fs.access("/usr/share/kai/kai-plugin.json")', controller)
|
||||
self.assertIn('fs.access("/usr/lib/lua/luci/controller/kai.lua")', controller)
|
||||
|
||||
def test_entry_opens_kai_luci_and_prompts_to_install_when_missing(self):
|
||||
controller = self.read("luasrc/controller/kaiplus.lua")
|
||||
status = self.read("luasrc/view/kaiplus/kaiplus_status.htm")
|
||||
|
||||
self.assertNotIn('entry({"admin", "services", "kaiplus", "open_kai"}', controller)
|
||||
self.assertIn('url("admin/services/kai")', status)
|
||||
self.assertIn("st.kai_installed === true", status)
|
||||
self.assertIn("function openClassicKai()", status)
|
||||
self.assertIn("Classic KAI is not installed. Install it now?", status)
|
||||
self.assertIn("window.location.href = kaiLuciUrl", status)
|
||||
|
||||
def test_missing_kai_starts_taskd_install_and_opens_log(self):
|
||||
makefile = self.read("Makefile")
|
||||
controller = self.read("luasrc/controller/kaiplus.lua")
|
||||
status = self.read("luasrc/view/kaiplus/kaiplus_status.htm")
|
||||
|
||||
self.assertIn("+luci-lib-taskd", makefile)
|
||||
self.assertIn('<%+tasks/embed%>', status)
|
||||
self.assertIn('entry({"admin", "services", "kaiplus", "install_kai"}', controller)
|
||||
self.assertIn("require_post_csrf()", controller)
|
||||
self.assertIn("/bin/is-opkg install luci-app-kai", controller)
|
||||
self.assertNotIn("app-meta-kai", controller)
|
||||
self.assertIn("/etc/init.d/tasks task_add ", controller)
|
||||
self.assertIn("window.taskd.show_log", status)
|
||||
self.assertIn("token: kaiCsrfToken", status)
|
||||
|
||||
def test_action_buttons_share_one_row(self):
|
||||
status = self.read("luasrc/view/kaiplus/kaiplus_status.htm")
|
||||
|
||||
actions = status.index('<div class="kaiplus-actions">')
|
||||
kaiplus = status.index('id="kaiplus-open"', actions)
|
||||
classic = status.index('id="kaiplus-open-kai"', actions)
|
||||
actions_end = status.index("</div>", classic)
|
||||
self.assertLess(kaiplus, classic)
|
||||
self.assertLess(classic, actions_end)
|
||||
self.assertIn("margin: 16px;", status)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user