% local meminfo = luci.sys.exec("grep -E '^(MemTotal|MemAvailable):' /proc/meminfo | awk '{print $2}'") local mem_values = {} for value in meminfo:gmatch("%d+") do table.insert(mem_values, tonumber(value)) end local mem_total = mem_values[1] or 0 local mem_available = mem_values[2] or 0 local mem_available_mb = math.floor(mem_available / 1024) local memory_warning = mem_available_mb < 80 -- 获取OpenWrt主机名 local hostname = luci.sys.exec("uci get system.@system[0].hostname 2>/dev/null || echo 'OpenWrt'") hostname = hostname:gsub("%s+$", "") -- 去除尾部换行符和空格 -- 获取小宝运行状态 local owjdxb_pid = luci.sys.exec("${IPKG_INSTROOT}/usr/local/owjdxb/bin/owjdxb -sign 2>/dev/null") local owjdxb_running = false if owjdxb_pid and string.find(owjdxb_pid, "OW&t=") then local owjdxb_prog = luci.sys.exec("pidof owjdxb 2>/dev/null") owjdxb_running = owjdxb_prog and (#owjdxb_prog > 1) end -- 新增:读取和解析file-config.yaml配置文件 local config_path = "/usr/local/owjdxb/config/file-config.yaml" local file_config_content = luci.sys.exec("cat " .. config_path .. " 2>/dev/null || echo ''") local file_server_enabled = "off" local file_list = {} -- 解析YAML配置 if file_config_content and #file_config_content > 0 then local lines = {} -- 将内容按行分割 for line in file_config_content:gmatch("[^\r\n]+") do table.insert(lines, line) end local i = 1 while i <= #lines do local line = lines[i] -- 清理注释和空白 local clean_line = line:match("^%s*([^#]+)") or "" clean_line = clean_line:gsub("%s*$", "") -- 解析file-server if clean_line:match("^file%-server:") then local value = clean_line:match("file%-server:%s*(%w+)") if value then file_server_enabled = value:lower() end end -- 解析file-list if clean_line:match("^%s*%-%s*local:") then local local_path = clean_line:match("local:%s*(.+)") local name = "" -- 检查下一行是否是name if i + 1 <= #lines then local next_line = lines[i + 1] local clean_next = next_line:match("^%s*([^#]+)") or "" clean_next = clean_next:gsub("%s*$", "") if clean_next:match("^%s*name:") then name = clean_next:match("name:%s*(.+)") or "" i = i + 1 -- 跳过name行 end end if local_path then table.insert(file_list, { local_path = local_path:gsub("^%s*(.-)%s*$", "%1"), name = name:gsub("^%s*(.-)%s*$", "%1") }) end end i = i + 1 end end -- 如果没有读取到配置,使用默认值 if #file_list == 0 then file_list = { { local_path = "/usr/local/owjdxb/share", name = "share" } } end -- 调试:显示原始配置内容 local debug_content = file_config_content:gsub("\n", "\\n"):gsub("\r", "\\r") %>