From b17eeec181faed27ce1fe8d2ba8345ac08405a8b Mon Sep 17 00:00:00 2001 From: Cylae <13425054+Cylae@users.noreply.github.com> Date: Sun, 22 Feb 2026 14:26:22 +0000 Subject: [PATCH] Update README, fix hardware detection, and optimize user management * Add `sys.refresh_disks()` to `HardwareInfo::detect` for accurate disk stats. * Replace `block_in_place` with `spawn_blocking` in web handlers for async efficiency. * Update README with Syncthing UDP port 21027. --- README.md | 4 +- server_manager/src/core/hardware.rs | 1 + server_manager/src/interface/web.rs | 81 ++++++++++++++++++----------- 3 files changed, 55 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 6187960..f25da17 100644 --- a/README.md +++ b/README.md @@ -174,7 +174,7 @@ Here is the matrix of deployed services: | | Gitea | 3000 (Localhost) | `http://localhost:3000` | Self-hosted Git | | | Roundcube | 8090 (Localhost) | `http://localhost:8090` | Webmail | | | Mailserver | 25, 143, 587, 993 | - | Full Mail Server | -| | Syncthing | 8384 (Localhost), 22000 | `http://localhost:8384` | File Synchronization | +| | Syncthing | 8384 (Localhost), 22000, 21027 (UDP) | `http://localhost:8384` | File Synchronization | --- @@ -328,7 +328,7 @@ Voici la matrice des services déployés : | | Gitea | 3000 (Localhost) | `http://localhost:3000` | Self-hosted Git | | | Roundcube | 8090 (Localhost) | `http://localhost:8090` | Webmail | | | Mailserver | 25, 143, 587, 993 | - | Full Mail Server | -| | Syncthing | 8384 (Localhost), 22000 | `http://localhost:8384` | Synchronisation de Fichiers | +| | Syncthing | 8384 (Localhost), 22000, 21027 (UDP) | `http://localhost:8384` | Synchronisation de Fichiers | --- diff --git a/server_manager/src/core/hardware.rs b/server_manager/src/core/hardware.rs index 09f3ff2..9acbf31 100644 --- a/server_manager/src/core/hardware.rs +++ b/server_manager/src/core/hardware.rs @@ -31,6 +31,7 @@ impl HardwareInfo { sys.refresh_memory(); sys.refresh_cpu(); sys.refresh_disks_list(); + sys.refresh_disks(); let total_memory = sys.total_memory(); // Bytes let ram_gb = total_memory / 1024 / 1024 / 1024; diff --git a/server_manager/src/interface/web.rs b/server_manager/src/interface/web.rs index 1f677c3..f3dbe3b 100644 --- a/server_manager/src/interface/web.rs +++ b/server_manager/src/interface/web.rs @@ -627,21 +627,32 @@ async fn add_user_handler(State(state): State, session: Session, Fo }; let mut cache = state.users_cache.write().await; - let res = tokio::task::block_in_place(|| { - cache.manager.add_user(&payload.username, &payload.password, role_enum, quota_val) - }); - - if let Err(e) = res { - error!("Failed to add user: {}", e); - // In a real app we'd flash a message. Here just redirect. - } else { - info!("User {} added via Web UI by {}", payload.username, session_user.username); - // Update mtime to prevent unnecessary reload - let path = std::path::Path::new("users.yaml"); - let fallback_path = std::path::Path::new("/opt/server_manager/users.yaml"); - let file_path = if path.exists() { path } else { fallback_path }; - if let Ok(m) = std::fs::metadata(file_path) { - cache.last_modified = m.modified().ok(); + let mut manager_clone = cache.manager.clone(); + let username_log = payload.username.clone(); + + let res = tokio::task::spawn_blocking(move || -> anyhow::Result { + manager_clone.add_user(&payload.username, &payload.password, role_enum, quota_val)?; + Ok(manager_clone) + }) + .await; + + match res { + Ok(Ok(updated_manager)) => { + cache.manager = updated_manager; + info!("User {} added via Web UI by {}", username_log, session_user.username); + // Update mtime to prevent unnecessary reload + let path = std::path::Path::new("users.yaml"); + let fallback_path = std::path::Path::new("/opt/server_manager/users.yaml"); + let file_path = if path.exists() { path } else { fallback_path }; + if let Ok(m) = std::fs::metadata(file_path) { + cache.last_modified = m.modified().ok(); + } + }, + Ok(Err(e)) => { + error!("Failed to add user: {}", e); + }, + Err(e) => { + error!("Task join error: {}", e); } } @@ -659,20 +670,32 @@ async fn delete_user_handler(State(state): State, session: Session, } let mut cache = state.users_cache.write().await; - let res = tokio::task::block_in_place(|| { - cache.manager.delete_user(&username) - }); - - if let Err(e) = res { - error!("Failed to delete user: {}", e); - } else { - info!("User {} deleted via Web UI by {}", username, session_user.username); - // Update mtime to prevent unnecessary reload - let path = std::path::Path::new("users.yaml"); - let fallback_path = std::path::Path::new("/opt/server_manager/users.yaml"); - let file_path = if path.exists() { path } else { fallback_path }; - if let Ok(m) = std::fs::metadata(file_path) { - cache.last_modified = m.modified().ok(); + let mut manager_clone = cache.manager.clone(); + let username_clone = username.clone(); + + let res = tokio::task::spawn_blocking(move || -> anyhow::Result { + manager_clone.delete_user(&username_clone)?; + Ok(manager_clone) + }) + .await; + + match res { + Ok(Ok(updated_manager)) => { + cache.manager = updated_manager; + info!("User {} deleted via Web UI by {}", username, session_user.username); + // Update mtime to prevent unnecessary reload + let path = std::path::Path::new("users.yaml"); + let fallback_path = std::path::Path::new("/opt/server_manager/users.yaml"); + let file_path = if path.exists() { path } else { fallback_path }; + if let Ok(m) = std::fs::metadata(file_path) { + cache.last_modified = m.modified().ok(); + } + }, + Ok(Err(e)) => { + error!("Failed to delete user: {}", e); + }, + Err(e) => { + error!("Task join error: {}", e); } }