pi_hole_api/
api_types.rs

1use crate::custom_deserializers;
2use crate::fake_hash_map;
3use crate::ftl_types::*;
4use chrono::prelude::*;
5use serde::{Deserialize, Serialize};
6use serde_tuple::*;
7use std::collections::HashMap;
8use std::net::IpAddr;
9use std::time::Duration;
10
11/// Summary Raw Struct
12#[derive(Deserialize, Serialize, Debug)]
13pub struct SummaryRaw {
14    /// Number of domains being blocked
15    pub domains_being_blocked: u64,
16
17    /// Number of DNS queries today
18    pub dns_queries_today: u64,
19
20    /// Number of Ads blocked today
21    pub ads_blocked_today: u64,
22
23    /// Percentage of queries blocked today
24    pub ads_percentage_today: f64,
25
26    /// Number of unique domains
27    pub unique_domains: u64,
28
29    /// Number of queries forwarded
30    pub queries_forwarded: u64,
31
32    /// Number of queries cached
33    pub queries_cached: u64,
34
35    /// Number of clients ever seen
36    pub clients_ever_seen: u64,
37
38    /// Number of unique clients
39    pub unique_clients: u64,
40
41    /// Number of DNS queries of all types
42    pub dns_queries_all_types: u64,
43
44    /// Number of NODATA replies
45    #[serde(rename = "reply_NODATA")]
46    pub reply_nodata: u64,
47
48    /// Number of NXDOMAIN replies
49    #[serde(rename = "reply_NXDOMAIN")]
50    pub reply_nxdomain: u64,
51
52    /// Number of CNAME replies
53    #[serde(rename = "reply_CNAME")]
54    pub reply_cname: u64,
55
56    /// Number of IP replies
57    #[serde(rename = "reply_IP")]
58    pub reply_ip: u64,
59
60    /// Privacy level
61    pub privacy_level: u64,
62
63    /// Pi Hole status
64    pub status: String,
65}
66
67/// Summary Struct
68#[derive(Deserialize, Serialize, Debug)]
69pub struct Summary {
70    /// Formatted number of domains being blocked
71    pub domains_being_blocked: String,
72
73    /// Formatted number of DNS queries today
74    pub dns_queries_today: String,
75
76    /// Formatted number of Ads blocked today
77    pub ads_blocked_today: String,
78
79    /// Formatted percentage of queries blocked today
80    pub ads_percentage_today: String,
81
82    /// Formatted number of unique domains
83    pub unique_domains: String,
84
85    /// Formatted number of queries forwarded
86    pub queries_forwarded: String,
87
88    /// Formatted number of queries cached
89    pub queries_cached: String,
90
91    /// Formatted number of clients ever seen
92    pub clients_ever_seen: String,
93
94    /// Formatted number of unique clients
95    pub unique_clients: String,
96
97    /// Formatted number of DNS queries of all types
98    pub dns_queries_all_types: String,
99
100    /// Formatted number of NODATA replies
101    #[serde(rename = "reply_NODATA")]
102    pub reply_nodata: String,
103
104    /// Formatted number of NXDOMAIN replies
105    #[serde(rename = "reply_NXDOMAIN")]
106    pub reply_nxdomain: String,
107
108    /// Formatted number of CNAME replies
109    #[serde(rename = "reply_CNAME")]
110    pub reply_cname: String,
111
112    /// Formatted number of IP replies
113    #[serde(rename = "reply_IP")]
114    pub reply_ip: String,
115
116    /// Privacy level
117    pub privacy_level: String,
118
119    /// Pi Hole status
120    pub status: String,
121}
122
123/// Over Time Data Struct
124#[derive(Deserialize, Serialize, Debug)]
125pub struct OverTimeData {
126    /// Mapping from time to number of domains
127    #[serde(deserialize_with = "fake_hash_map::deserialize_fake_hash_map")]
128    pub domains_over_time: HashMap<String, u64>,
129
130    /// Mapping from time to number of ads
131    #[serde(deserialize_with = "fake_hash_map::deserialize_fake_hash_map")]
132    pub ads_over_time: HashMap<String, u64>,
133}
134
135/// Top Items Struct
136#[derive(Deserialize, Serialize, Debug)]
137pub struct TopItems {
138    /// Top queries mapping from domain to number of requests
139    #[serde(deserialize_with = "fake_hash_map::deserialize_fake_hash_map")]
140    pub top_queries: HashMap<String, u64>,
141
142    /// Top ads mapping from domain to number of requests
143    #[serde(deserialize_with = "fake_hash_map::deserialize_fake_hash_map")]
144    pub top_ads: HashMap<String, u64>,
145}
146
147/// Top Clients Struct
148#[derive(Deserialize, Serialize, Debug)]
149pub struct TopClients {
150    /// Top sources mapping from "IP" or "hostname|IP" to number of requests.
151    #[serde(deserialize_with = "fake_hash_map::deserialize_fake_hash_map")]
152    pub top_sources: HashMap<String, u64>,
153}
154
155/// Top Clients Blocked Struct
156#[derive(Deserialize, Serialize, Debug)]
157pub struct TopClientsBlocked {
158    /// Top sources blocked mapping from "IP" or "hostname|IP" to number of blocked requests.
159    #[serde(deserialize_with = "fake_hash_map::deserialize_fake_hash_map")]
160    pub top_sources_blocked: HashMap<String, u64>,
161}
162
163/// Forward Destinations Struct
164#[derive(Deserialize, Serialize, Debug)]
165pub struct ForwardDestinations {
166    /// Forward destinations mapping from "human_readable_name|IP" to the percentage of requests answered.
167    #[serde(deserialize_with = "fake_hash_map::deserialize_fake_hash_map")]
168    pub forward_destinations: HashMap<String, f64>,
169}
170
171/// Query Types Struct
172#[derive(Deserialize, Serialize, Debug)]
173pub struct QueryTypes {
174    /// Query types mapping from query type (A, AAAA, PTR, etc.) to the percentage of queries which are of that type.
175    #[serde(deserialize_with = "fake_hash_map::deserialize_fake_hash_map")]
176    pub querytypes: HashMap<String, f64>,
177}
178
179/// Query Struct
180#[derive(Deserialize, Serialize_tuple, Debug)]
181pub struct Query {
182    /// Timestamp of query
183    #[serde(deserialize_with = "custom_deserializers::deserialize_string_to_naive_datetime")]
184    pub timestring: NaiveDateTime,
185
186    /// Type of query (A, AAAA, PTR, etc.)
187    pub query_type: QueryType,
188
189    /// Requested domain name
190    pub domain: String,
191
192    /// Requesting client IP or hostname
193    pub client: String,
194
195    /// Status as String
196    #[serde(deserialize_with = "custom_deserializers::deserialize_string_to_query_status")]
197    pub status: QueryStatus,
198
199    /// DNSSEC Status
200    #[serde(deserialize_with = "custom_deserializers::deserialize_string_to_dnssec_status")]
201    pub dnssec_status: DNSSECStatus,
202
203    /// Reply Type
204    #[serde(deserialize_with = "custom_deserializers::deserialize_string_to_reply_type")]
205    pub reply_type: ReplyType,
206
207    /// Response time
208    #[serde(
209        deserialize_with = "custom_deserializers::deserialize_string_to_duration_100_microseconds"
210    )]
211    pub response_time: Duration,
212
213    /// CNAME domain
214    pub cname_domain: String,
215
216    /// Regex ID
217    #[serde(deserialize_with = "custom_deserializers::deserialize_string_to_i32")]
218    pub regex_id: i32,
219
220    /// Upstream Destination
221    pub upstream_destination: String,
222
223    /// EDE
224    pub ede: String,
225}
226
227/// All Queries Struct
228#[derive(Deserialize, Serialize, Debug)]
229pub struct AllQueries {
230    /// List of queries
231    pub data: Vec<Query>,
232}
233
234/// Status Struct
235#[derive(Deserialize, Serialize, Debug)]
236pub struct Status {
237    /// Status, "enabled" or "disabled"
238    pub status: String,
239}
240
241/// Version Struct
242#[derive(Deserialize, Serialize, Debug)]
243pub struct Version {
244    /// Version
245    pub version: u32,
246}
247
248/// Versions Struct
249#[derive(Deserialize, Serialize, Debug)]
250pub struct Versions {
251    /// Is there an update available for Pi-hole core
252    pub core_update: bool,
253    /// Is there an update available for Pi-hole web
254    pub web_update: bool,
255    /// Is there an update available for Pi-hole FTL
256    #[serde(rename = "FTL_update")]
257    pub ftl_update: bool,
258    /// Current Pi-hole core version
259    pub core_current: String,
260    /// Current Pi-hole web version
261    pub web_current: String,
262    /// Current Pi-hole FTL version
263    #[serde(rename = "FTL_current")]
264    pub ftl_current: String,
265    /// Latest Pi-hole core version
266    pub core_latest: String,
267    /// Latest Pi-hole web version
268    pub web_latest: String,
269    /// Latest Pi-hole FTL version
270    #[serde(rename = "FTL_latest")]
271    pub ftl_latest: String,
272    /// Current Pi-hole core branch
273    pub core_branch: String,
274    /// Current Pi-hole web branch
275    pub web_branch: String,
276    /// Current Pi-hole FTL branch
277    #[serde(rename = "FTL_branch")]
278    pub ftl_branch: String,
279}
280
281/// Cache Info Struct
282#[derive(Deserialize, Serialize, Debug)]
283pub struct CacheInfo {
284    /// Cache size
285    #[serde(rename = "cache-size")]
286    pub cache_size: u64,
287
288    /// Number of evicted cache entries
289    #[serde(rename = "cache-live-freed")]
290    pub cache_live_freed: u64,
291
292    /// Number of cache entries inserted
293    #[serde(rename = "cache-inserted")]
294    pub cache_inserted: u64,
295}
296
297/// Client Name Struct
298#[derive(Deserialize, Serialize, Debug)]
299pub struct ClientName {
300    /// Client name
301    pub name: String,
302
303    /// Client IP
304    pub ip: IpAddr,
305}
306
307/// Network Client Struct
308#[derive(Deserialize, Serialize, Debug)]
309pub struct NetworkClient {
310    /// Client ID
311    pub id: u64,
312
313    /// IP addresses of client
314    pub ip: Vec<IpAddr>,
315
316    /// Hardware address
317    pub hwaddr: String,
318
319    /// Interface
320    pub interface: String,
321
322    /// Hostname
323    pub name: Vec<String>,
324
325    /// Time first seen
326    #[serde(rename = "firstSeen", with = "chrono::naive::serde::ts_seconds")]
327    pub first_seen: NaiveDateTime,
328
329    /// Time of last query
330    #[serde(rename = "lastQuery", with = "chrono::naive::serde::ts_seconds")]
331    pub last_query: NaiveDateTime,
332
333    /// Number of queries
334    #[serde(rename = "numQueries")]
335    pub num_queries: u64,
336
337    /// MAC Vendor
338    #[serde(rename = "macVendor")]
339    pub mac_vendor: String,
340}
341
342/// Network Struct
343#[derive(Deserialize, Serialize, Debug)]
344pub struct Network {
345    /// List of network clients
346    pub network: Vec<NetworkClient>,
347}
348
349/// List Modification Response Struct
350#[derive(Deserialize, Serialize, Debug)]
351pub struct ListModificationResponse {
352    /// If request was successful
353    pub success: bool,
354    /// Optional message about request
355    pub message: Option<String>,
356}
357
358/// Custom List Domain Struct
359#[derive(Deserialize, Serialize, Debug)]
360pub struct CustomListDomainDetails {
361    /// Entry ID
362    pub id: u64,
363    /// Type
364    #[serde(rename = "type")]
365    pub domain_type: u64,
366    /// Domain
367    pub domain: String,
368    /// Enabled
369    #[serde(deserialize_with = "custom_deserializers::deserialize_uint_to_bool")]
370    pub enabled: bool,
371    /// Date added
372    #[serde(with = "chrono::naive::serde::ts_seconds")]
373    pub date_added: NaiveDateTime,
374    /// Date modified
375    #[serde(with = "chrono::naive::serde::ts_seconds")]
376    pub date_modified: NaiveDateTime,
377    /// Comments
378    pub comment: String,
379    /// Groups
380    pub groups: Vec<u64>,
381}
382
383/// Local/Custom List Domain Struct
384#[derive(Deserialize, Serialize, Debug)]
385pub struct CustomDNSRecord {
386    /// Domain of record
387    pub domain: String,
388    /// IP Address
389    pub ip_address: IpAddr,
390}
391
392/// Local/Custom List CNAME Struct
393#[derive(Deserialize, Serialize, Debug)]
394pub struct CustomCNAMERecord {
395    /// Domain of record
396    pub domain: String,
397    /// Target domain
398    pub target_domain: String,
399}
400
401/// Response format when requesting information from the FTL while it is not running
402#[derive(Deserialize, Serialize, Debug)]
403pub struct FTLNotRunning {
404    /// Not running flag
405    #[serde(rename = "FTLnotrunning")]
406    pub ftl_not_running: bool,
407}