diff --git a/Cargo.toml b/Cargo.toml index a1dabad..1afad5e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rustguac" -version = "0.6.2" +version = "0.7.0" edition = "2021" description = "Lightweight Rust replacement for Apache Guacamole client" diff --git a/src/api.rs b/src/api.rs index e7940b7..1b96143 100644 --- a/src/api.rs +++ b/src/api.rs @@ -195,6 +195,27 @@ pub async fn delete_session( } } +/// GET /api/login-scripts — List available login scripts. Requires operator+. +pub async fn list_login_scripts(State(manager): State) -> impl IntoResponse { + let scripts_dir = std::path::Path::new(&manager.config().login_scripts_dir); + let mut scripts: Vec = Vec::new(); + if let Ok(entries) = std::fs::read_dir(scripts_dir) { + for entry in entries.flatten() { + let path = entry.path(); + if path.is_file() { + if let Some(name) = path.file_name().and_then(|n| n.to_str()) { + // Only list executable-looking scripts, skip hidden files + if !name.starts_with('.') { + scripts.push(name.to_string()); + } + } + } + } + } + scripts.sort(); + Json(json!({ "scripts": scripts })) +} + /// GET /api/health — Health check. pub async fn health() -> impl IntoResponse { Json(json!({ "status": "ok" })) diff --git a/src/main.rs b/src/main.rs index dda62c0..594b264 100644 --- a/src/main.rs +++ b/src/main.rs @@ -733,6 +733,8 @@ async fn run_server(config: Config, database: Db) { delete(api::admin_revoke_user_token), ) .route("/api/admin/token-audit", get(api::admin_token_audit)) + // Login scripts listing + .route("/api/login-scripts", get(api::list_login_scripts)) // Address book routes .route("/api/addressbook", get(api::ab_list_all)) .route("/api/addressbook/folders", get(api::ab_list_folders)) diff --git a/src/session.rs b/src/session.rs index 5941f90..f80920e 100644 --- a/src/session.rs +++ b/src/session.rs @@ -284,6 +284,11 @@ impl SessionManager { } } + /// Read-only access to the config. + pub fn config(&self) -> &Config { + &self.config + } + /// Create a new session: connect to guacd, perform handshake, return session info. pub async fn create_session( &self, diff --git a/static/addressbook.html b/static/addressbook.html index 3b2cd20..55ee2b2 100644 --- a/static/addressbook.html +++ b/static/addressbook.html @@ -453,9 +453,11 @@ -
Server-side script in the scripts directory. Receives CDP port and credentials as env vars. Runs after Chromium spawns.
+
Server-side script from the scripts directory. Receives CDP port and credentials as env vars. Runs after Chromium spawns.