shell_tunnel/lib.rs
1//! # shell-tunnel
2//!
3//! Ultra-lightweight remote shell gateway with a REST/WebSocket API.
4//!
5//! This crate provides a cross-platform API for programmatic interaction
6//! with system shells. It supports both Windows (ConPTY) and Unix (PTY)
7//! terminals through a unified interface.
8//!
9//! ## Features
10//!
11//! - **Cross-platform PTY**: Unified interface for Windows ConPTY and Unix PTY
12//! - **Async I/O**: Non-blocking operations using tokio
13//! - **Session Management**: Stateful shell sessions with lifecycle tracking
14//! - **REST API**: HTTP endpoints for command execution
15//! - **WebSocket**: Real-time streaming of command output
16//! - **Lightweight**: Minimal dependencies, small binary size
17//!
18//! ## Quick Start
19//!
20//! ```no_run
21//! use shell_tunnel::{NativePty, PtySize, SessionStore, SessionConfig};
22//!
23//! #[tokio::main]
24//! async fn main() -> shell_tunnel::Result<()> {
25//! // Initialize logging
26//! shell_tunnel::logging::try_init().ok();
27//!
28//! // Create a session store
29//! let store = SessionStore::new();
30//!
31//! // Create a new session
32//! let session_id = store.create(SessionConfig::default())?;
33//!
34//! // Spawn a PTY
35//! let pty = NativePty::new();
36//! let handle = pty.spawn_default(PtySize::default())?;
37//!
38//! println!("Session {} created with PID {}", session_id, handle.pid);
39//!
40//! Ok(())
41//! }
42//! ```
43//!
44//! ## API Server
45//!
46//! ```no_run
47//! use shell_tunnel::api::{ServerConfig, serve};
48//!
49//! #[tokio::main]
50//! async fn main() -> shell_tunnel::Result<()> {
51//! shell_tunnel::logging::try_init().ok();
52//! let config = ServerConfig::new("127.0.0.1", 3000);
53//! serve(config).await
54//! }
55//! ```
56
57pub mod api;
58pub mod audit;
59pub mod cli;
60pub mod config;
61pub mod error;
62pub mod execution;
63#[cfg(any(feature = "tls", feature = "relay-client"))]
64pub mod fingerprint;
65pub mod fs;
66pub mod logging;
67pub mod output;
68mod process;
69pub mod pty;
70pub mod relay;
71pub mod security;
72pub mod session;
73#[cfg(feature = "tls")]
74pub mod tls;
75pub mod tunnel;
76#[cfg(feature = "self-update")]
77pub mod update;
78
79// Re-export commonly used types
80pub use error::{Result, ShellTunnelError};
81pub use execution::{Command, CommandExecutor, ExecutionResult};
82pub use fs::{FsError, FsRoot};
83pub use output::{OutputSanitizer, VirtualScreen};
84pub use pty::{AsyncPtyReader, AsyncPtyWriter, NativePty, PtyHandle, PtySize};
85pub use session::{
86 Session, SessionConfig, SessionContext, SessionId, SessionState, SessionStore, StateProbe,
87};
88
89// Re-export API types
90pub use api::{AppState, ServerConfig};
91
92// Re-export security types
93pub use security::{
94 ApiKeyStore, AuthConfig, CapabilitySet, CommandValidator, RateLimiter, TokenRecord,
95 ValidationConfig,
96};
97
98// Re-export reachability types
99pub use relay::{RelayConfig, RelayState};
100pub use tunnel::{TunnelHandle, TunnelProvider};
101
102// Re-export CLI and config types
103pub use cli::{parse_args, print_help, print_version, Args};
104pub use config::{Config, ConfigError};