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:
@@ -6,6 +6,12 @@
|
|||||||
document.documentElement.setAttribute("data-theme", s);
|
document.documentElement.setAttribute("data-theme", s);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
// ═══ 工具函数 ═══
|
||||||
|
function getCookie(name) {
|
||||||
|
var match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
|
||||||
|
return match ? match[2] : '';
|
||||||
|
}
|
||||||
|
|
||||||
window.toggleTheme = function(){
|
window.toggleTheme = function(){
|
||||||
var t = document.documentElement.getAttribute("data-theme") === "light" ? "dark" : "light";
|
var t = document.documentElement.getAttribute("data-theme") === "light" ? "dark" : "light";
|
||||||
document.documentElement.setAttribute("data-theme", t);
|
document.documentElement.setAttribute("data-theme", t);
|
||||||
|
|||||||
@@ -32,7 +32,8 @@ window.DashboardModule = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var base = window.location.pathname.split("/").slice(0, 2).join("/");
|
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;
|
self.ws = ws;
|
||||||
|
|
||||||
ws.onopen = function() {
|
ws.onopen = function() {
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ window.LogsModule = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var base = window.location.pathname.split("/").slice(0, 2).join("/");
|
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;
|
self.ws = ws;
|
||||||
|
|
||||||
ws.onopen = function() {
|
ws.onopen = function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user