1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
//! # cpanel-rs
//!
//! An unofficial Rust client for the [cPanel](https://cpanel.net/) &
//! [WHM](https://www.cpanel.net/products/whm/) APIs. This crate lets you manage
//! hosting accounts, DNS records, email, databases, files, SSL certificates, and
//! backups programmatically via UAPI and WHM JSON API endpoints.
//!
//! **This project is not affiliated with or endorsed by WebPros.**
//!
//! # Quick Start
//!
//! ```toml
//! # Cargo.toml
//! [dependencies]
//! cpanel-rs = "0.3"
//! ```
//!
//! ```
//! use cpanel_rs::{CpanelClient, CpanelBuilder};
//!
//! // Simple construction
//! let client = CpanelClient::simple("server.example.com", 2087, "root", "yourpass").unwrap();
//!
//! // Or with the builder for full control
//! let client = CpanelBuilder::new("server.example.com", 2087, "root")
//! .password("secret")
//! .timeout(std::time::Duration::from_secs(30))
//! .disable_tls_verification()
//! .build()
//! .unwrap();
//! ```
//!
//! # Supported Operations
//!
//! | Module | Functionality |
//! |--------|---------------|
//! | [`account`] | List, create, delete, suspend, modify accounts (WHM) |
//! | [`backup`] | Backup creation, listing, restoration, scheduling (UAPI) |
//! | [`cron`] | List, add, edit, delete scheduled cron jobs (UAPI) |
//! | [`database`] | MySQL databases, users, and privileges (UAPI) |
//! | [`dns`] | List, add, delete DNS records; import/export zones (UAPI) |
//! | [`domains`] | Addon domains, parked domains (aliases), and subdomains (UAPI) |
//! | [`email`] | Email accounts, forwarders, autoresponders, mailing lists (UAPI) |
//! | [`filemanager`] | List, create, delete, upload, download, compress files (UAPI) |
//! | [`ftp`] | FTP account management: list, create, modify, delete (UAPI) |
//! | [`security`] | ModSecurity rules and IP blocker (blacklist/whitelist) (UAPI) |
//! | [`ssl`] | SSL certificate management and Let's Encrypt issuance (UAPI) |
//! | [`resources`] | Disk/quota usage, PHP version management (UAPI) |
//!
//! # Authentication
//!
//! Three auth methods are supported:
//!
//! - **Password** — Basic HTTP auth. Works for both cPanel (2083) and WHM (2087).
//! - **Raw Key** — `WHM user:key` header. Requires WHM access and a raw access key
//! generated in WHM > Manage Remote Access Key.
//! - **API Token** — `Authorization: cpanel <user>:<token>`. Generates granular,
//! scoped permissions without requiring a full account password or root access.
//! Create tokens in cPanel > Home > Security Center > API Tokens.
//!
//! ```no_run
//! use cpanel_rs::CpanelBuilder;
//!
//! // Password auth
//! let client = CpanelBuilder::new("myhost.com", 2087, "user").password("pass").build().unwrap();
//!
//! // Raw key auth (WHM only)
//! let client = CpanelBuilder::new("myhost.com", 2087, "root").key("abc123...").build().unwrap();
//!
//! // API Token auth (cPanel UAPI)
//! let client = CpanelBuilder::new("myhost.com", 2083, "user").token("uI7fX2aB9cD...").build().unwrap();
//! ```
//!
//! # Retry & Backoff
//!
//! Enable the `retry` feature for automatic exponential backoff on transient errors
//! (429 rate limits, 503 service unavailable, connection resets):
//!
//! ```toml
//! [dependencies]
//! cpanel-rs = { version = "0.3", features = ["retry"] }
//! ```
//!
//! ```
//! use cpanel_rs::{CpanelClient, RetryPolicy};
//!
//! let client = CpanelClient::simple("server.example.com", 2087, "root", "pass").unwrap();
//! let client = client.with_retry_policy(
//! RetryPolicy::default().max_retries(5).base_delay(std::time::Duration::from_millis(500)),
//! );
//! ```
//!
//! # Auto-Paginating Streams
//!
//! Enable the `stream` feature to use async streams for large listings:
//!
//! ```toml
//! [dependencies]
//! cpanel-rs = { version = "0.3", features = ["stream"] }
//! ```
//!
//! ```no_run
//! #[cfg(feature = "stream")]
//! {
//! use cpanel_rs::CpanelClient;
//! use futures::StreamExt;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), cpanel_rs::CpanelError> {
//! let client = CpanelClient::simple("server.example.com", 2087, "root", "pass").unwrap();
//!
//! // Stream all accounts without manual pagination
//! let mut stream = client.stream_accounts();
//! while let Some(acct) = stream.next().await {
//! let acct = acct?;
//! println!("{} @ {}", acct.username, acct.domain);
//! }
//! Ok(())
//! }
//! }
//! ```
//!
//! # Streaming File Operations
//!
//! Upload large files from an async reader without loading them entirely into memory:
//!
//! ```no_run
//! use cpanel_rs::CpanelClient;
//! use tokio::fs::File;
//! use tokio::io::AsyncReadExt;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), cpanel_rs::CpanelError> {
//! let client = CpanelClient::simple("server.example.com", 2083, "user", "pass").unwrap();
//! let mut file = File::open("large_upload.zip").await?;
//! client.upload_file_from_reader("user", "/public_html/large_upload.zip", &mut file, "large_upload.zip", 1024 * 1024).await?;
//! Ok(())
//! }
//! ```
//!
//! # Environment Variables (opt-in)
//!
//! Enable the `dotenv` feature to load credentials from a `.env` file:
//!
//! ```toml
//! [dependencies]
//! cpanel-rs = { version = "0.3", features = ["dotenv"] }
//! ```
//!
//! Then create a `.env` file:
//!
//! ```text
//! CPANEL_HOST=server.example.com
//! CPANEL_PORT=2087
//! CPANEL_USER=root
//! CPANEL_PASSWORD=yourpass
//! ```
//!
//! # Error Handling
//!
//! All methods return [`Result<_, CpanelError>`]. Errors fall into these categories:
//!
//! - **[`CpanelError::Http`]** — network or connection failure
//! - **[`CpanelError::ApiError`]** — the API returned a non-success status
//! - **[`CpanelError::ApiWarning`]** — the API returned success but with warnings
//! - **[`CpanelError::Auth`]** — missing or invalid credentials
//! - **[`CpanelError::Serialization`]** — invalid JSON response
//!
//! Use [`CpanelError::ApiError`] to inspect structured
//! failure details including all error messages, warnings, and stack traces.
/// cPanel & WHM account management (WHM API).
/// Backup management (UAPI).
/// Core client: [`CpanelClient`], [`CpanelBuilder`], [`AuthMethod`], and [`RetryPolicy`].
/// Cron job management (UAPI).
/// MySQL database management (UAPI).
/// DNS record management (UAPI).
/// Domain and subdomain management (UAPI).
/// Email account management (UAPI).
/// File manager operations (UAPI).
/// FTP account management (UAPI).
/// Data models shared across modules.
/// Resource usage and PHP version management (UAPI).
/// Security: ModSecurity rules and IP blocker (UAPI).
/// SSL certificate management (UAPI).
/// Auto-paginating async streams for large listings (requires `stream` feature).
/// Core types: errors, response envelopes, and query builders.
pub use ;
pub use CpanelError;