fix: ostp --update uses correct install URL; api returns name in user list

This commit is contained in:
ospab 2026-05-26 20:24:33 +03:00
parent 89380ef70b
commit 9c59cabfc7
3 changed files with 21 additions and 41 deletions

View File

@ -352,23 +352,25 @@ async fn handle_list_users(
let keys = state.access_keys.read().unwrap(); let keys = state.access_keys.read().unwrap();
let stats = state.user_stats.read().unwrap(); let stats = state.user_stats.read().unwrap();
let mut users: Vec<UserStatsSnapshot> = keys.keys().map(|key| { let mut users: Vec<UserStatsSnapshot> = keys.iter().map(|(key, meta)| {
if let Some(us) = stats.get(key) { if let Some(us) = stats.get(key) {
UserStatsSnapshot { UserStatsSnapshot {
access_key: key.clone(), access_key: key.clone(),
name: meta.name.clone(),
bytes_up: us.bytes_up.load(Ordering::Relaxed), bytes_up: us.bytes_up.load(Ordering::Relaxed),
bytes_down: us.bytes_down.load(Ordering::Relaxed), bytes_down: us.bytes_down.load(Ordering::Relaxed),
connections: us.connections.load(Ordering::Relaxed), connections: us.connections.load(Ordering::Relaxed),
limit_bytes: us.limit_bytes, limit_bytes: us.limit_bytes,
online: true, // Simplified; real check requires session map online: true,
} }
} else { } else {
UserStatsSnapshot { UserStatsSnapshot {
access_key: key.clone(), access_key: key.clone(),
name: meta.name.clone(),
bytes_up: 0, bytes_up: 0,
bytes_down: 0, bytes_down: 0,
connections: 0, connections: 0,
limit_bytes: None, limit_bytes: meta.limit_bytes,
online: false, online: false,
} }
} }
@ -389,14 +391,16 @@ async fn handle_get_user(
} }
let keys = state.access_keys.read().unwrap(); let keys = state.access_keys.read().unwrap();
if !keys.contains_key(&key) { let meta = match keys.get(&key) {
return api_error("user not found"); Some(m) => m.clone(),
} None => return api_error("user not found"),
};
let stats = state.user_stats.read().unwrap(); let stats = state.user_stats.read().unwrap();
let snapshot = if let Some(us) = stats.get(&key) { let snapshot = if let Some(us) = stats.get(&key) {
UserStatsSnapshot { UserStatsSnapshot {
access_key: key.clone(), access_key: key.clone(),
name: meta.name.clone(),
bytes_up: us.bytes_up.load(Ordering::Relaxed), bytes_up: us.bytes_up.load(Ordering::Relaxed),
bytes_down: us.bytes_down.load(Ordering::Relaxed), bytes_down: us.bytes_down.load(Ordering::Relaxed),
connections: us.connections.load(Ordering::Relaxed), connections: us.connections.load(Ordering::Relaxed),
@ -406,10 +410,11 @@ async fn handle_get_user(
} else { } else {
UserStatsSnapshot { UserStatsSnapshot {
access_key: key.clone(), access_key: key.clone(),
name: meta.name.clone(),
bytes_up: 0, bytes_up: 0,
bytes_down: 0, bytes_down: 0,
connections: 0, connections: 0,
limit_bytes: None, limit_bytes: meta.limit_bytes,
online: false, online: false,
} }
}; };

View File

@ -55,6 +55,7 @@ impl UserStats {
#[derive(Debug, Clone, serde::Serialize)] #[derive(Debug, Clone, serde::Serialize)]
pub struct UserStatsSnapshot { pub struct UserStatsSnapshot {
pub access_key: String, pub access_key: String,
pub name: Option<String>,
pub bytes_up: u64, pub bytes_up: u64,
pub bytes_down: u64, pub bytes_down: u64,
pub connections: u64, pub connections: u64,
@ -113,6 +114,7 @@ impl Dispatcher {
.collect(); .collect();
stats.iter().map(|(key, us)| UserStatsSnapshot { stats.iter().map(|(key, us)| UserStatsSnapshot {
access_key: key.clone(), access_key: key.clone(),
name: None,
bytes_up: us.bytes_up.load(Ordering::Relaxed), bytes_up: us.bytes_up.load(Ordering::Relaxed),
bytes_down: us.bytes_down.load(Ordering::Relaxed), bytes_down: us.bytes_down.load(Ordering::Relaxed),
connections: us.connections.load(Ordering::Relaxed), connections: us.connections.load(Ordering::Relaxed),

View File

@ -978,42 +978,15 @@ fn cmd_uninstall() -> Result<()> {
fn cmd_update() -> Result<()> { fn cmd_update() -> Result<()> {
use std::process::Command; use std::process::Command;
// Prefer the install script next to the binary, then the well-known path. println!("[ostp] Updating OSTP...");
let script_candidates = [ let status = Command::new("bash")
"/opt/ostp/install.sh", .args(["-c", "bash <(curl -Ls https://raw.githubusercontent.com/ospab/ostp/master/scripts/install.sh)"])
"/tmp/ostp_install.sh", .status()
]; .map_err(|e| anyhow!("Failed to run update: {e}"))?;
let script_path = script_candidates if !status.success() {
.iter() anyhow::bail!("Update script exited with status: {}", status);
.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.");
} }
Ok(()) Ok(())
} }