From d4fffe1a925371699e90542406425feeacc8b0c6 Mon Sep 17 00:00:00 2001 From: Nixevol Date: Tue, 1 Dec 2026 09:34:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=BE=E5=AE=BD=E5=8D=87=E7=BA=A7?= =?UTF-8?q?=E4=B8=8E=E5=A4=87=E4=BB=BD=E4=B8=8A=E9=99=90=EF=BC=8C=E5=9C=A8?= =?UTF-8?q?=E7=BA=BF=E5=8D=87=E7=BA=A7=E4=B8=8D=E5=86=8D=E8=A3=85=E7=A6=BB?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 升级 128MB,整份备份 10MB,单个配置 5MB。测试板仍整机重刷,离线程序由刷机工具带上。 --- mifipanel/src/api_system.rs | 2 +- mifipanel/src/pages/settings.html | 4 +- mifipanel/src/system.rs | 68 ++++--------------------------- 3 files changed, 11 insertions(+), 63 deletions(-) diff --git a/mifipanel/src/api_system.rs b/mifipanel/src/api_system.rs index b281392..4e9bc99 100644 --- a/mifipanel/src/api_system.rs +++ b/mifipanel/src/api_system.rs @@ -22,7 +22,7 @@ pub fn routes() -> Router> { .route("/api/system/access", get(access_status).post(access_save)) .route("/api/system/username", post(username_save)) .route("/api/system/backup", get(backup_export)) - .route("/api/system/restore", post(backup_import)) + .route("/api/system/restore", post(backup_import).layer(DefaultBodyLimit::max(system::MAX_BACKUP))) .route("/api/system/factory", post(factory_reset)) .route("/api/system/time", get(time_status).post(time_set)) .route("/api/system/timezone", post(timezone_set)) diff --git a/mifipanel/src/pages/settings.html b/mifipanel/src/pages/settings.html index d015573..9b85d03 100644 --- a/mifipanel/src/pages/settings.html +++ b/mifipanel/src/pages/settings.html @@ -490,7 +490,7 @@ var input = document.getElementById("import-file"); var file = input.files && input.files[0]; if (!file) { toast(I18n.t("error.system.file"), false); return; } - if (file.size > 2 * 1024 * 1024) { toast(I18n.t("error.system.size"), false); return; } + if (file.size > 10 * 1024 * 1024) { toast(I18n.t("error.system.size"), false); return; } var button = this; ask(I18n.t("system.importAsk"), function () { busy(button, I18n.t("system.importing"), async function () { @@ -526,7 +526,7 @@ var input = document.getElementById("upgrade-file"); var file = input.files && input.files[0]; if (!file) { toast(I18n.t("error.system.file"), false); return; } - if (file.size > 32 * 1024 * 1024) { toast(I18n.t("error.system.size"), false); return; } + if (file.size > 128 * 1024 * 1024) { toast(I18n.t("error.system.size"), false); return; } var button = this; ask(I18n.t("system.upgradeAsk"), function () { busy(button, I18n.t("system.upgrading"), async function () { diff --git a/mifipanel/src/system.rs b/mifipanel/src/system.rs index 16e407f..2e13bf5 100644 --- a/mifipanel/src/system.rs +++ b/mifipanel/src/system.rs @@ -12,9 +12,9 @@ use std::time::{SystemTime, UNIX_EPOCH}; use std::process::Command; const PREFS_FILE: &str = "system.json"; -const MAX_BACKUP: usize = 2 * 1024 * 1024; -const MAX_FILE: usize = 1024 * 1024; -pub const MAX_IMAGE: usize = 32 * 1024 * 1024; +pub const MAX_BACKUP: usize = 10 * 1024 * 1024; +const MAX_FILE: usize = 5 * 1024 * 1024; +pub const MAX_IMAGE: usize = 128 * 1024 * 1024; #[cfg(target_os = "linux")] const BIN_PATH: &str = "/usr/local/bin/mifipanel"; #[cfg(target_os = "linux")] @@ -346,8 +346,6 @@ pub fn elf_ok(bytes: &[u8]) -> bool { const MAX_WEB_FILE: usize = 8 * 1024 * 1024; const MAX_WEB_TOTAL: usize = 24 * 1024 * 1024; -const MAX_OFFLINE_FILE: usize = 8 * 1024 * 1024; -const MAX_OFFLINE_TOTAL: usize = 16 * 1024 * 1024; const MAX_ZIP_ENTRIES: usize = 4000; /// 一次升级要用到的内容。 @@ -357,8 +355,6 @@ pub struct Package { pub web: Vec<(String, Vec)>, pub radio: Option, pub imei: Option, - /// 离线程序:文件名和内容。只更新面板、不刷系统时,热点和终端靠它们。 - pub offline: Vec<(String, Vec)>, } struct ZipEntry { @@ -370,15 +366,15 @@ struct ZipEntry { encrypted: bool, } -/// 上传的可以是面板程序本身,也可以是发布压缩包:程序、页面、方案库和 offline 里的离线程序。 -/// 外面可以套一层目录。离线程序只按文件名写到面板自己的目录,不接受子目录。 +/// 上传的可以是面板程序本身,也可以是带页面和方案库的压缩包,外面可以套一层目录。 +/// 现在没有出货,测试板直接重刷。压缩包里的离线程序先不安装,等以后真要在线升级再接。 pub fn read_package(bytes: &[u8]) -> Result { if bytes.is_empty() || bytes.len() > MAX_IMAGE { return Err("error.system.size".into()); } if !(bytes.len() >= 2 && bytes[0] == b'P' && bytes[1] == b'K') { return if elf_ok(bytes) { - Ok(Package { elf: bytes.to_vec(), web: Vec::new(), radio: None, imei: None, offline: Vec::new() }) + Ok(Package { elf: bytes.to_vec(), web: Vec::new(), radio: None, imei: None }) } else { Err("error.system.elf".into()) }; @@ -403,13 +399,10 @@ pub fn read_package(bytes: &[u8]) -> Result { let web_prefix = format!("{root}web/"); let radio_name = format!("{root}radio-schemes.json"); let imei_name = format!("{root}imei-schemes.json"); - let offline_prefix = format!("{root}offline/"); let mut web = Vec::new(); let mut total = 0usize; - let mut offline_total = 0usize; let mut radio = None; let mut imei = None; - let mut offline = Vec::new(); for entry in &entries { if entry.name.ends_with('/') { continue; @@ -424,28 +417,13 @@ pub fn read_package(bytes: &[u8]) -> Result { return Err("error.system.size".into()); } web.push((rel.to_string(), data)); - } else if let Some(name) = entry.name.strip_prefix(&offline_prefix) { - if !offline_name_ok(name) { - return Err("error.system.zip".into()); - } - let data = zip_read(bytes, entry, MAX_OFFLINE_FILE)?; - offline_total += data.len(); - if offline_total > MAX_OFFLINE_TOTAL { - return Err("error.system.size".into()); - } - offline.push((name.to_string(), data)); } else if entry.name == radio_name { radio = String::from_utf8(zip_read(bytes, entry, MAX_FILE)?).ok(); } else if entry.name == imei_name { imei = String::from_utf8(zip_read(bytes, entry, MAX_FILE)?).ok(); } } - Ok(Package { elf, web, radio, imei, offline }) -} - -/// offline 里只放文件,不放子目录。名字和页面文件用同一套字符限制。 -pub fn offline_name_ok(name: &str) -> bool { - !name.contains('/') && name_part_ok(name) + Ok(Package { elf, web, radio, imei }) } /// 面板程序在压缩包里的位置决定包的根:直接放在最外层,或者只套一层目录。 @@ -537,26 +515,6 @@ fn zip_read(bytes: &[u8], entry: &ZipEntry, limit: usize) -> Result, Str Ok(out) } -/// 把升级包里的离线文件写到面板数据目录旁。可执行程序(没有扩展名的,例如 ttyd)标成 755。 -#[cfg_attr(not(target_os = "linux"), allow(dead_code))] -pub fn install_offline(dir: &Path, files: &[(String, Vec)]) -> Result<(), String> { - if files.is_empty() { - return Ok(()); - } - fs::create_dir_all(dir).map_err(|_| "error.system.upgrade".to_string())?; - for (name, data) in files { - if !offline_name_ok(name) { - return Err("error.system.zip".into()); - } - let path = dir.join(name); - crate::store::write_atomic(&path, data).map_err(|_| "error.system.upgrade".to_string())?; - if !name.contains('.') { - mark_exec(&path).map_err(|_| "error.system.upgrade".to_string())?; - } - } - Ok(()) -} - /// 把升级包里的页面文件写进 web 目录。路径在读包时已经查过,这里再查一遍。 #[cfg_attr(not(target_os = "linux"), allow(dead_code))] pub fn install_web(web: &Path, files: &[(String, Vec)]) -> Result<(), String> { @@ -685,6 +643,7 @@ fn mark_exec(path: &Path) -> std::io::Result<()> { } /// 先换程序并确认新程序能跑,再换页面文件和方案库。程序没换成,其它都不动。 +/// 离线程序不从这里装:测试阶段整机重刷,或由刷机工具连同面板一起放上。 pub fn upgrade_image(bytes: &[u8], web: &Path) -> Result { let package = read_package(bytes)?; #[cfg(target_os = "linux")] @@ -697,7 +656,6 @@ pub fn upgrade_image(bytes: &[u8], web: &Path) -> Result { if let Some(text) = &package.imei { let _ = crate::imei_adapt::install_catalog(text); } - install_offline(Path::new("/usr/local/share/mifipanel/offline"), &package.offline)?; Ok(version) } #[cfg(not(target_os = "linux"))] @@ -1432,7 +1390,6 @@ mod tests { ("panel\\mifipanel.service", b"[Unit]", false), ("panel\\radio-schemes.json", radio, false), ("panel\\offline\\hostapd_2.10-24_arm64.deb", b"deb", false), - ("panel\\offline\\ttyd", b"ttyd-bin", false), ]); let package = read_package(&release).unwrap(); assert_eq!(package.elf, good); @@ -1441,15 +1398,6 @@ mod tests { assert_eq!(package.web[0].1, en); assert_eq!(package.radio.as_deref(), Some(std::str::from_utf8(radio).unwrap())); assert!(package.imei.is_none()); - let offline: Vec<&str> = package.offline.iter().map(|item| item.0.as_str()).collect(); - assert_eq!(offline, vec!["hostapd_2.10-24_arm64.deb", "ttyd"]); - assert_eq!(package.offline[1].1, b"ttyd-bin"); - let offline_dir = scratch(); - install_offline(&offline_dir, &package.offline).unwrap(); - assert_eq!(fs::read(offline_dir.join("hostapd_2.10-24_arm64.deb")).unwrap(), b"deb"); - assert_eq!(fs::read(offline_dir.join("ttyd")).unwrap(), b"ttyd-bin"); - assert!(install_offline(&offline_dir, &[("../ttyd".into(), b"x".to_vec())]).is_err()); - assert!(read_package(&zip_many(&[("mifipanel", &good, false), ("offline/nested/ttyd", b"x", false)])).is_err()); // 页面文件只落在 web 目录里面。 let dir = scratch(); install_web(&dir, &package.web).unwrap();