diff --git a/ostp-server/src/api.rs b/ostp-server/src/api.rs index ddd3e19..72036df 100644 --- a/ostp-server/src/api.rs +++ b/ostp-server/src/api.rs @@ -352,23 +352,25 @@ async fn handle_list_users( let keys = state.access_keys.read().unwrap(); let stats = state.user_stats.read().unwrap(); - let mut users: Vec = keys.keys().map(|key| { + let mut users: Vec = keys.iter().map(|(key, meta)| { if let Some(us) = stats.get(key) { UserStatsSnapshot { access_key: key.clone(), + name: meta.name.clone(), bytes_up: us.bytes_up.load(Ordering::Relaxed), bytes_down: us.bytes_down.load(Ordering::Relaxed), connections: us.connections.load(Ordering::Relaxed), limit_bytes: us.limit_bytes, - online: true, // Simplified; real check requires session map + online: true, } } else { UserStatsSnapshot { access_key: key.clone(), + name: meta.name.clone(), bytes_up: 0, bytes_down: 0, connections: 0, - limit_bytes: None, + limit_bytes: meta.limit_bytes, online: false, } } @@ -389,14 +391,16 @@ async fn handle_get_user( } let keys = state.access_keys.read().unwrap(); - if !keys.contains_key(&key) { - return api_error("user not found"); - } + let meta = match keys.get(&key) { + Some(m) => m.clone(), + None => return api_error("user not found"), + }; let stats = state.user_stats.read().unwrap(); let snapshot = if let Some(us) = stats.get(&key) { UserStatsSnapshot { access_key: key.clone(), + name: meta.name.clone(), bytes_up: us.bytes_up.load(Ordering::Relaxed), bytes_down: us.bytes_down.load(Ordering::Relaxed), connections: us.connections.load(Ordering::Relaxed), @@ -406,10 +410,11 @@ async fn handle_get_user( } else { UserStatsSnapshot { access_key: key.clone(), + name: meta.name.clone(), bytes_up: 0, bytes_down: 0, connections: 0, - limit_bytes: None, + limit_bytes: meta.limit_bytes, online: false, } }; diff --git a/ostp-server/src/dispatcher.rs b/ostp-server/src/dispatcher.rs index db2584f..ec6bb17 100644 --- a/ostp-server/src/dispatcher.rs +++ b/ostp-server/src/dispatcher.rs @@ -55,6 +55,7 @@ impl UserStats { #[derive(Debug, Clone, serde::Serialize)] pub struct UserStatsSnapshot { pub access_key: String, + pub name: Option, pub bytes_up: u64, pub bytes_down: u64, pub connections: u64, @@ -113,6 +114,7 @@ impl Dispatcher { .collect(); stats.iter().map(|(key, us)| UserStatsSnapshot { access_key: key.clone(), + name: None, bytes_up: us.bytes_up.load(Ordering::Relaxed), bytes_down: us.bytes_down.load(Ordering::Relaxed), connections: us.connections.load(Ordering::Relaxed), diff --git a/ostp/src/main.rs b/ostp/src/main.rs index 67a5815..de80903 100644 --- a/ostp/src/main.rs +++ b/ostp/src/main.rs @@ -978,42 +978,15 @@ fn cmd_uninstall() -> Result<()> { fn cmd_update() -> Result<()> { use std::process::Command; - // Prefer the install script next to the binary, then the well-known path. - let script_candidates = [ - "/opt/ostp/install.sh", - "/tmp/ostp_install.sh", - ]; + println!("[ostp] Updating OSTP..."); + let status = Command::new("bash") + .args(["-c", "bash <(curl -Ls https://raw.githubusercontent.com/ospab/ostp/master/scripts/install.sh)"]) + .status() + .map_err(|e| anyhow!("Failed to run update: {e}"))?; - let script_path = script_candidates - .iter() - .find(|p| std::path::Path::new(p).exists()) - .copied(); - - if let Some(path) = script_path { - println!("[ostp] Running update script: {}", path); - let status = Command::new("bash") - .arg(path) - .status() - .map_err(|e| anyhow!("Failed to execute install script: {e}"))?; - - if !status.success() { - anyhow::bail!("Install script exited with status: {}", status); - } - println!("[ostp] Update complete."); - } else { - // Download and run the script on the fly - println!("[ostp] install.sh not found locally – downloading from GitHub..."); - let status = Command::new("bash") - .args(["-c", "curl -fsSL https://raw.githubusercontent.com/ospab/ostp/main/scripts/install.sh | bash"]) - .status() - .map_err(|e| anyhow!("Failed to download/run install script: {e}"))?; - - if !status.success() { - anyhow::bail!("Update script exited with status: {}", status); - } - println!("[ostp] Update complete."); + if !status.success() { + anyhow::bail!("Update script exited with status: {}", status); } - Ok(()) }