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 logging;
66pub mod output;
67mod process;
68pub mod pty;
69pub mod relay;
70pub mod security;
71pub mod session;
72#[cfg(feature = "tls")]
73pub mod tls;
74pub mod tunnel;
75#[cfg(feature = "self-update")]
76pub mod update;
77
78// Re-export commonly used types
79pub use error::{Result, ShellTunnelError};
80pub use execution::{Command, CommandExecutor, ExecutionResult};
81pub use output::{OutputSanitizer, VirtualScreen};
82pub use pty::{AsyncPtyReader, AsyncPtyWriter, NativePty, PtyHandle, PtySize};
83pub use session::{
84 Session, SessionConfig, SessionContext, SessionId, SessionState, SessionStore, StateProbe,
85};
86
87// Re-export API types
88pub use api::{AppState, ServerConfig};
89
90// Re-export security types
91pub use security::{
92 ApiKeyStore, AuthConfig, CapabilitySet, CommandValidator, RateLimiter, TokenRecord,
93 ValidationConfig,
94};
95
96// Re-export reachability types
97pub use relay::{RelayConfig, RelayState};
98pub use tunnel::{TunnelHandle, TunnelProvider};
99
100// Re-export CLI and config types
101pub use cli::{parse_args, print_help, print_version, Args};
102pub use config::{Config, ConfigError};