mirror of
https://github.com/hotwa/luci-app-openclaw.git
synced 2026-03-31 04:52:33 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
156837877d | ||
|
|
2816ba19c3 |
9
.gitattributes
vendored
Normal file
9
.gitattributes
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
*.sh text eol=lf
|
||||||
|
*.bash text eol=lf
|
||||||
|
Makefile text eol=lf
|
||||||
|
VERSION text eol=lf
|
||||||
|
*.yml text eol=lf
|
||||||
|
*.yaml text eol=lf
|
||||||
|
*.lua text eol=lf
|
||||||
|
*.htm text eol=lf
|
||||||
|
*.md text eol=lf
|
||||||
@@ -51,17 +51,53 @@ local port = uci:get("openclaw", "main", "port") or "18789"
|
|||||||
box-shadow: 0 1px 4px rgba(0,0,0,0.06);
|
box-shadow: 0 1px 4px rgba(0,0,0,0.06);
|
||||||
}
|
}
|
||||||
|
|
||||||
#oc-console-iframe { width: 100%; height: 700px; border: none; display: block; }
|
|
||||||
|
|
||||||
.oc-console-loading {
|
.oc-console-loading {
|
||||||
display: flex; flex-direction: column; align-items: center; justify-content: center;
|
display: flex; flex-direction: column; align-items: center; justify-content: center;
|
||||||
height: 300px; color: #666; font-size: 14px; background: #fafafa;
|
min-height: 320px; color: #666; font-size: 14px; background: #fafafa;
|
||||||
|
padding: 32px 24px;
|
||||||
|
text-align: center;
|
||||||
}
|
}
|
||||||
.oc-console-loading .spinner {
|
.oc-console-loading .spinner {
|
||||||
width: 32px; height: 32px; border: 3px solid #e0e0e0; border-top: 3px solid #4a90d9;
|
width: 32px; height: 32px; border: 3px solid #e0e0e0; border-top: 3px solid #4a90d9;
|
||||||
border-radius: 50%; animation: oc-spin .8s linear infinite; margin-bottom: 12px;
|
border-radius: 50%; animation: oc-spin .8s linear infinite; margin-bottom: 12px;
|
||||||
}
|
}
|
||||||
@keyframes oc-spin { to { transform: rotate(360deg); } }
|
@keyframes oc-spin { to { transform: rotate(360deg); } }
|
||||||
|
|
||||||
|
.oc-console-note {
|
||||||
|
max-width: 640px;
|
||||||
|
line-height: 1.8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.oc-console-note strong {
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.oc-console-note code {
|
||||||
|
padding: 2px 6px;
|
||||||
|
background: #f0f3f6;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-family: monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
.oc-console-actions {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 10px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
margin-top: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.oc-console-link {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #666;
|
||||||
|
word-break: break-all;
|
||||||
|
margin-top: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.oc-console-link a {
|
||||||
|
color: #4a90d9;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<div class="oc-page-header">
|
<div class="oc-page-header">
|
||||||
@@ -107,13 +143,28 @@ local port = uci:get("openclaw", "main", "port") or "18789"
|
|||||||
var openBtn = document.getElementById('oc-console-open-btn');
|
var openBtn = document.getElementById('oc-console-open-btn');
|
||||||
|
|
||||||
function getConsoleUrl() {
|
function getConsoleUrl() {
|
||||||
var proto = window.location.protocol;
|
|
||||||
var host = window.location.hostname;
|
var host = window.location.hostname;
|
||||||
var url = proto + '//' + host + ':' + gwPort + '/';
|
var url = 'http://' + host + ':' + gwPort + '/';
|
||||||
if (gwToken) url += '#token=' + encodeURIComponent(gwToken);
|
if (gwToken) url += '#token=' + encodeURIComponent(gwToken);
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function showOpenMessage(url) {
|
||||||
|
loading.innerHTML =
|
||||||
|
'<div class="oc-console-note">' +
|
||||||
|
'<div style="font-size:42px;margin-bottom:12px;">🪟</div>' +
|
||||||
|
'<div style="font-size:16px;margin-bottom:8px;"><strong>请在新窗口中打开 OpenClaw 控制台</strong></div>' +
|
||||||
|
'<div style="font-size:13px;color:#666;">' +
|
||||||
|
'OpenClaw 控制台会返回浏览器安全头,拒绝被 LuCI 页面内嵌。' +
|
||||||
|
'请点击上方「新窗口打开」访问控制台。' +
|
||||||
|
'</div>' +
|
||||||
|
'<div class="oc-console-actions">' +
|
||||||
|
'<a class="btn cbi-button cbi-button-action" href="' + url + '" target="_blank" rel="noopener">↗ 新窗口打开</a>' +
|
||||||
|
'</div>' +
|
||||||
|
'<div class="oc-console-link">直接地址:<a href="' + url + '" target="_blank" rel="noopener">' + url + '</a></div>' +
|
||||||
|
'</div>';
|
||||||
|
}
|
||||||
|
|
||||||
function checkAndLoad() {
|
function checkAndLoad() {
|
||||||
addrEl.textContent = window.location.hostname + ':' + gwPort;
|
addrEl.textContent = window.location.hostname + ':' + gwPort;
|
||||||
|
|
||||||
@@ -135,7 +186,7 @@ local port = uci:get("openclaw", "main", "port") or "18789"
|
|||||||
statusTextEl.innerHTML = '<span style="color:#1a7f37;">● 网关运行中</span>';
|
statusTextEl.innerHTML = '<span style="color:#1a7f37;">● 网关运行中</span>';
|
||||||
openBtn.href = url;
|
openBtn.href = url;
|
||||||
openBtn.style.display = '';
|
openBtn.style.display = '';
|
||||||
showIframe(url);
|
showOpenMessage(url);
|
||||||
} else if (d.gateway_starting) {
|
} else if (d.gateway_starting) {
|
||||||
statusTextEl.innerHTML = '<span style="color:#9a6700;">⏳ 网关正在启动</span>';
|
statusTextEl.innerHTML = '<span style="color:#9a6700;">⏳ 网关正在启动</span>';
|
||||||
openBtn.style.display = 'none';
|
openBtn.style.display = 'none';
|
||||||
@@ -160,21 +211,6 @@ local port = uci:get("openclaw", "main", "port") or "18789"
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function showIframe(url) {
|
|
||||||
loading.style.display = 'none';
|
|
||||||
var existing = document.getElementById('oc-console-iframe');
|
|
||||||
if (existing) return;
|
|
||||||
|
|
||||||
var iframe = document.createElement('iframe');
|
|
||||||
iframe.id = 'oc-console-iframe';
|
|
||||||
iframe.src = url;
|
|
||||||
iframe.style.width = '100%';
|
|
||||||
iframe.style.height = '700px';
|
|
||||||
iframe.style.border = 'none';
|
|
||||||
iframe.setAttribute('allowfullscreen', 'true');
|
|
||||||
container.appendChild(iframe);
|
|
||||||
}
|
|
||||||
|
|
||||||
checkAndLoad();
|
checkAndLoad();
|
||||||
})();
|
})();
|
||||||
//]]>
|
//]]>
|
||||||
|
|||||||
30
tests/test_luci_console_contract.sh
Normal file
30
tests/test_luci_console_contract.sh
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
SCRIPT_DIR=$(CDPATH= cd -- "$(dirname "$0")" && pwd)
|
||||||
|
REPO_ROOT=$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd)
|
||||||
|
|
||||||
|
CONSOLE_VIEW="$REPO_ROOT/luasrc/view/openclaw/console.htm"
|
||||||
|
|
||||||
|
fail() {
|
||||||
|
echo "FAIL: $1" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
grep -Fq "http://' + host + ':' + gwPort + '/'" "$CONSOLE_VIEW" || fail "console view should force http for the gateway URL"
|
||||||
|
grep -Fq '请点击上方「新窗口打开」访问控制台。' "$CONSOLE_VIEW" || fail "console view should explain that the console must open in a new window"
|
||||||
|
|
||||||
|
if grep -Fq "document.createElement('iframe')" "$CONSOLE_VIEW"; then
|
||||||
|
fail "console view should not embed the OpenClaw UI in an iframe"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if grep -Fq 'window.location.protocol' "$CONSOLE_VIEW"; then
|
||||||
|
fail "console view should not reuse the LuCI page protocol for the gateway URL"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cr=$(printf '\r')
|
||||||
|
if LC_ALL=C grep -q "$cr" "$CONSOLE_VIEW"; then
|
||||||
|
fail "console view should use LF line endings"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "ok"
|
||||||
@@ -12,6 +12,11 @@ BUILD_RUN="$REPO_ROOT/scripts/build_run.sh"
|
|||||||
ENV_SCRIPT="$REPO_ROOT/root/usr/bin/openclaw-env"
|
ENV_SCRIPT="$REPO_ROOT/root/usr/bin/openclaw-env"
|
||||||
CONTROLLER_SCRIPT="$REPO_ROOT/luasrc/controller/openclaw.lua"
|
CONTROLLER_SCRIPT="$REPO_ROOT/luasrc/controller/openclaw.lua"
|
||||||
BASIC_LUA="$REPO_ROOT/luasrc/model/cbi/openclaw/basic.lua"
|
BASIC_LUA="$REPO_ROOT/luasrc/model/cbi/openclaw/basic.lua"
|
||||||
|
PROFILE_SCRIPT="$REPO_ROOT/root/etc/profile.d/openclaw.sh"
|
||||||
|
UCI_DEFAULTS_SCRIPT="$REPO_ROOT/root/etc/uci-defaults/99-openclaw"
|
||||||
|
INIT_SCRIPT="$REPO_ROOT/root/etc/init.d/openclaw"
|
||||||
|
PATHS_HELPER="$REPO_ROOT/root/usr/libexec/openclaw-paths.sh"
|
||||||
|
NODE_HELPER="$REPO_ROOT/root/usr/libexec/openclaw-node.sh"
|
||||||
|
|
||||||
fail() {
|
fail() {
|
||||||
echo "FAIL: $1" >&2
|
echo "FAIL: $1" >&2
|
||||||
@@ -71,6 +76,24 @@ grep -Fq 'openclaw/paths.lua' "$BUILD_IPK" || fail "ipk builder should package L
|
|||||||
grep -Fq 'openclaw-paths.sh' "$BUILD_RUN" || fail "run builder should package path helper"
|
grep -Fq 'openclaw-paths.sh' "$BUILD_RUN" || fail "run builder should package path helper"
|
||||||
grep -Fq 'openclaw-node.sh' "$BUILD_RUN" || fail "run builder should package node helper"
|
grep -Fq 'openclaw-node.sh' "$BUILD_RUN" || fail "run builder should package node helper"
|
||||||
grep -Fq 'openclaw/paths.lua' "$BUILD_RUN" || fail "run builder should package Lua path helper"
|
grep -Fq 'openclaw/paths.lua' "$BUILD_RUN" || fail "run builder should package Lua path helper"
|
||||||
|
|
||||||
|
python - "$ENV_SCRIPT" "$PROFILE_SCRIPT" "$UCI_DEFAULTS_SCRIPT" "$INIT_SCRIPT" "$PATHS_HELPER" "$NODE_HELPER" "$BUILD_IPK" "$BUILD_RUN" "$BUILD_SCRIPT" <<'PY' || fail "shell-oriented source files must use LF line endings"
|
||||||
|
from pathlib import Path
|
||||||
|
import sys
|
||||||
|
|
||||||
|
bad = []
|
||||||
|
for arg in sys.argv[1:]:
|
||||||
|
data = Path(arg).read_bytes()
|
||||||
|
if b"\r\n" in data:
|
||||||
|
bad.append(arg)
|
||||||
|
|
||||||
|
if bad:
|
||||||
|
print("CRLF detected in:", file=sys.stderr)
|
||||||
|
for path in bad:
|
||||||
|
print(path, file=sys.stderr)
|
||||||
|
raise SystemExit(1)
|
||||||
|
PY
|
||||||
|
|
||||||
grep -Fq 'local GITHUB_REPO = "hotwa/luci-app-openclaw"' "$CONTROLLER_SCRIPT" || fail "controller should default to hotwa repo"
|
grep -Fq 'local GITHUB_REPO = "hotwa/luci-app-openclaw"' "$CONTROLLER_SCRIPT" || fail "controller should default to hotwa repo"
|
||||||
grep -Fq 'local GITHUB_RELEASES_URL = "https://github.com/" .. GITHUB_REPO .. "/releases"' "$CONTROLLER_SCRIPT" || fail "controller should derive release URLs from hotwa repo"
|
grep -Fq 'local GITHUB_RELEASES_URL = "https://github.com/" .. GITHUB_REPO .. "/releases"' "$CONTROLLER_SCRIPT" || fail "controller should derive release URLs from hotwa repo"
|
||||||
grep -Fq 'local GITHUB_API_RELEASES_URL = "https://api.github.com/repos/" .. GITHUB_REPO .. "/releases"' "$CONTROLLER_SCRIPT" || fail "controller should derive API URLs from hotwa repo"
|
grep -Fq 'local GITHUB_API_RELEASES_URL = "https://api.github.com/repos/" .. GITHUB_REPO .. "/releases"' "$CONTROLLER_SCRIPT" || fail "controller should derive API URLs from hotwa repo"
|
||||||
|
|||||||
Reference in New Issue
Block a user