Skip to main content

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