chore(center): 下线第一代中心机并清除旧公网信息
- 删除 desktop/controlplane(FastAPI 旧中心机)全部代码,历史见 git - 移除依赖旧中心机模块的两个失效测试 - AGENTS/README/docs 表述改为「已移除/只有内网一套」,去掉旧公网地址与宝塔部署信息 - agent_cli 去掉旧库拦截逻辑,--base 帮助指向内网生产;electron-shell .env.example 默认地址改内网
This commit is contained in:
@@ -1,45 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""测试保留期清理:回填一条 40 天前的运行日志 + 一个 40 天前的设备壳日志后执行 cleanup_expired。"""
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, r"D:\work\code\37duAutomation\desktop")
|
||||
import pymysql
|
||||
|
||||
from controlplane.core import config, logstore
|
||||
|
||||
c = pymysql.connect(host="127.0.0.1", port=3306, user="root", password="123456",
|
||||
database="37du_center_test")
|
||||
with c.cursor() as cur:
|
||||
cur.execute(
|
||||
"INSERT INTO run_logs(run_id, account, device_id, plugin_id, name, version, `trigger`, "
|
||||
"schedule_id, status, ok, error, summary, started, finished, duration_sec, log_count, "
|
||||
"logs, uploaded_at) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,"
|
||||
"DATE_SUB(NOW(), INTERVAL 40 DAY))",
|
||||
("oldrun0000000000000000000000000001", "olduser", "dev-old-1", "XQ1", "老插件",
|
||||
"1.0", "manual", "", "error", 0, "x", "y", 0, 0, 0, 0, "[]"))
|
||||
cur.execute(
|
||||
"INSERT INTO device_logs(device_id, account, hostname, client_version, size_bytes, "
|
||||
"updated_at) VALUES (%s,%s,%s,%s,%s, DATE_SUB(NOW(), INTERVAL 40 DAY))",
|
||||
("dev-old-1", "olduser", "OLD-PC", "1.0", 10))
|
||||
c.commit()
|
||||
c.close()
|
||||
|
||||
config.SHELL_LOGS_DIR.mkdir(parents=True, exist_ok=True)
|
||||
f = os.path.join(config.SHELL_LOGS_DIR, "dev-old-1.log")
|
||||
with open(f, "wb") as fh:
|
||||
fh.write(b"old content\n")
|
||||
|
||||
r = logstore.cleanup_expired()
|
||||
print("cleanup result:", r)
|
||||
print("file exists after cleanup:", os.path.exists(f))
|
||||
|
||||
c = pymysql.connect(host="127.0.0.1", port=3306, user="root", password="123456",
|
||||
database="37du_center_test")
|
||||
with c.cursor() as cur:
|
||||
cur.execute("SELECT COUNT(*) FROM run_logs WHERE run_id LIKE %s", ("oldrun%",))
|
||||
print("old run_logs left:", cur.fetchone()[0])
|
||||
cur.execute("SELECT COUNT(*) FROM device_logs WHERE device_id = %s", ("dev-old-1",))
|
||||
print("old device_logs left:", cur.fetchone()[0])
|
||||
c.close()
|
||||
print("CLEANUP OK")
|
||||
@@ -1,83 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""本地集成测试:中心机日志回传 + 管理端查询(对 127.0.0.1:8890 测试库)。"""
|
||||
import sys
|
||||
import json
|
||||
import urllib.request
|
||||
import urllib.error
|
||||
|
||||
sys.path.insert(0, r"D:\work\code\37duAutomation\desktop")
|
||||
from controlplane.core.auth import _sign_admin_token
|
||||
|
||||
BASE = "http://127.0.0.1:8890"
|
||||
TOKEN = "test-token-123"
|
||||
ADMIN = _sign_admin_token("puddy")
|
||||
|
||||
|
||||
def call(method, path, body=None, raw=None, headers=None):
|
||||
h = dict(headers or {})
|
||||
data = None
|
||||
if body is not None:
|
||||
data = json.dumps(body, ensure_ascii=False).encode("utf-8")
|
||||
h["Content-Type"] = "application/json"
|
||||
elif raw is not None:
|
||||
data = raw
|
||||
req = urllib.request.Request(BASE + path, data=data, method=method, headers=h)
|
||||
try:
|
||||
with urllib.request.urlopen(req, timeout=10) as r:
|
||||
return r.status, r.read()
|
||||
except urllib.error.HTTPError as e:
|
||||
return e.code, e.read()
|
||||
|
||||
|
||||
H = {"X-API-Token": TOKEN}
|
||||
A = {"X-Admin-Token": ADMIN}
|
||||
|
||||
# --- 1) 客户端回传运行日志(两次同 run_id → 幂等) ---
|
||||
run = {
|
||||
"run_id": "feed0000000000000000000000000001",
|
||||
"account": "lisi", "device_id": "dev-lisi-9", "plugin_id": "XQ0021",
|
||||
"name": "工资条下载", "version": "2.1.0", "trigger": "manual", "schedule_id": "",
|
||||
"status": "done", "ok": True, "error": "", "summary": "下载完成,共 3 条",
|
||||
"started": 1700001000, "finished": 1700001200, "duration_sec": 200,
|
||||
"logs": [
|
||||
{"t": "10:00:01", "level": "INFO", "msg": "开始"},
|
||||
{"t": "10:00:02", "level": "INFO", "msg": "解析工资条 1/3"},
|
||||
{"t": "10:00:03", "level": "INFO", "msg": "完成"},
|
||||
],
|
||||
}
|
||||
s, b = call("POST", "/api/runtime/logs", body=run, headers=H)
|
||||
print("run-logs POST", s, b.decode("utf-8"))
|
||||
s, b = call("POST", "/api/runtime/logs", body=run, headers=H)
|
||||
print("run-logs POST#2", s, b.decode("utf-8"))
|
||||
|
||||
# --- 2) 客户端壳日志增量(reset 首传 + 追加) ---
|
||||
line1 = "2026-10-22 10:00:01 INFO app 启动完成\n".encode("utf-8")
|
||||
qs = "device_id=dev-lisi-9&account=lisi&hostname=PC-LISI&client_version=1.6.4&reset=1"
|
||||
s, b = call("POST", "/api/runtime/shell-log?" + qs, raw=line1, headers=H)
|
||||
print("shell-log reset", s, b.decode("utf-8"))
|
||||
line2 = "2026-10-22 10:01:00 ERROR plugin-sync 同步失败\n".encode("utf-8")
|
||||
qs2 = "device_id=dev-lisi-9&account=lisi&hostname=PC-LISI&client_version=1.6.4"
|
||||
s, b = call("POST", "/api/runtime/shell-log?" + qs2, raw=line2, headers=H)
|
||||
print("shell-log append", s, b.decode("utf-8"))
|
||||
|
||||
# --- 3) 管理端查询 ---
|
||||
s, b = call("GET", "/api/admin/run-logs?plugin=XQ0021&page=1&page_size=10", headers=A)
|
||||
print("admin run-logs", s, b.decode("utf-8")[:400])
|
||||
s, b = call("GET", "/api/admin/run-logs/feed0000000000000000000000000001", headers=A)
|
||||
print("admin run-logs detail", s, b.decode("utf-8")[:300])
|
||||
s, b = call("GET", "/api/admin/device-logs", headers=A)
|
||||
print("admin device-logs", s, b.decode("utf-8")[:300])
|
||||
s, b = call("GET", "/api/admin/device-logs/dev-lisi-9", headers=A)
|
||||
print("admin device-log detail", s, b.decode("utf-8")[:300])
|
||||
s, b = call("GET", "/api/admin/device-logs/dev-lisi-9/download", headers=A)
|
||||
print("admin device-log download", s, b.decode("utf-8"))
|
||||
s, b = call("GET", "/api/admin/run-logs/../etc/passwd", headers=A)
|
||||
print("admin path-traversal run-logs", s)
|
||||
|
||||
# --- 4) 无 token 鉴权 ---
|
||||
s, b = call("POST", "/api/runtime/logs", body=run)
|
||||
print("no-token POST", s)
|
||||
|
||||
# --- 5) 清理接口 ---
|
||||
s, b = call("POST", "/api/admin/logs/cleanup", headers=A)
|
||||
print("admin cleanup", s, b.decode("utf-8"))
|
||||
Reference in New Issue
Block a user