security: 前端 WebSocket 连接传递 panel_token 认证

- dashboard.js / logs.js: WS URL 追加 ?token= 查询参数
- app.js: 添加 getCookie() 工具函数

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
qinglong
2026-06-13 13:38:38 +08:00
parent f7b4908322
commit a75b9d0975
3 changed files with 10 additions and 2 deletions
+6
View File
@@ -6,6 +6,12 @@
document.documentElement.setAttribute("data-theme", s);
})();
// ═══ 工具函数 ═══
function getCookie(name) {
var match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
return match ? match[2] : '';
}
window.toggleTheme = function(){
var t = document.documentElement.getAttribute("data-theme") === "light" ? "dark" : "light";
document.documentElement.setAttribute("data-theme", t);
+2 -1
View File
@@ -32,7 +32,8 @@ window.DashboardModule = {
}
var base = window.location.pathname.split("/").slice(0, 2).join("/");
var ws = new WebSocket("ws://" + location.host + base + "/api/system/ws");
var tok = getCookie("panel_token");
var ws = new WebSocket("ws://" + location.host + base + "/api/system/ws?token=" + (tok || ""));
self.ws = ws;
ws.onopen = function() {
+2 -1
View File
@@ -25,7 +25,8 @@ window.LogsModule = {
}
var base = window.location.pathname.split("/").slice(0, 2).join("/");
var ws = new WebSocket("ws://" + location.host + base + "/api/logs/ws");
var tok = getCookie("panel_token");
var ws = new WebSocket("ws://" + location.host + base + "/api/logs/ws?token=" + (tok || ""));
self.ws = ws;
ws.onopen = function() {