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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
use crate::custom_deserializers;
use crate::fake_hash_map;
use crate::ftl_types::*;
use chrono::prelude::*;
use serde::{Deserialize, Serialize};
use serde_tuple::*;
use std::collections::HashMap;
use std::net::IpAddr;
use std::time::Duration;

/// Summary Raw Struct
#[derive(Deserialize, Serialize, Debug)]
pub struct SummaryRaw {
    /// Number of domains being blocked
    pub domains_being_blocked: u64,

    /// Number of DNS queries today
    pub dns_queries_today: u64,

    /// Number of Ads blocked today
    pub ads_blocked_today: u64,

    /// Percentage of queries blocked today
    pub ads_percentage_today: f64,

    /// Number of unique domains
    pub unique_domains: u64,

    /// Number of queries forwarded
    pub queries_forwarded: u64,

    /// Number of queries cached
    pub queries_cached: u64,

    /// Number of clients ever seen
    pub clients_ever_seen: u64,

    /// Number of unique clients
    pub unique_clients: u64,

    /// Number of DNS queries of all types
    pub dns_queries_all_types: u64,

    /// Number of NODATA replies
    #[serde(rename = "reply_NODATA")]
    pub reply_nodata: u64,

    /// Number of NXDOMAIN replies
    #[serde(rename = "reply_NXDOMAIN")]
    pub reply_nxdomain: u64,

    /// Number of CNAME replies
    #[serde(rename = "reply_CNAME")]
    pub reply_cname: u64,

    /// Number of IP replies
    #[serde(rename = "reply_IP")]
    pub reply_ip: u64,

    /// Privacy level
    pub privacy_level: u64,

    /// Pi Hole status
    pub status: String,
}

/// Summary Struct
#[derive(Deserialize, Serialize, Debug)]
pub struct Summary {
    /// Formatted number of domains being blocked
    pub domains_being_blocked: String,

    /// Formatted number of DNS queries today
    pub dns_queries_today: String,

    /// Formatted number of Ads blocked today
    pub ads_blocked_today: String,

    /// Formatted percentage of queries blocked today
    pub ads_percentage_today: String,

    /// Formatted number of unique domains
    pub unique_domains: String,

    /// Formatted number of queries forwarded
    pub queries_forwarded: String,

    /// Formatted number of queries cached
    pub queries_cached: String,

    /// Formatted number of clients ever seen
    pub clients_ever_seen: String,

    /// Formatted number of unique clients
    pub unique_clients: String,

    /// Formatted number of DNS queries of all types
    pub dns_queries_all_types: String,

    /// Formatted number of NODATA replies
    #[serde(rename = "reply_NODATA")]
    pub reply_nodata: String,

    /// Formatted number of NXDOMAIN replies
    #[serde(rename = "reply_NXDOMAIN")]
    pub reply_nxdomain: String,

    /// Formatted number of CNAME replies
    #[serde(rename = "reply_CNAME")]
    pub reply_cname: String,

    /// Formatted number of IP replies
    #[serde(rename = "reply_IP")]
    pub reply_ip: String,

    /// Privacy level
    pub privacy_level: String,

    /// Pi Hole status
    pub status: String,
}

/// Over Time Data Struct
#[derive(Deserialize, Serialize, Debug)]
pub struct OverTimeData {
    /// Mapping from time to number of domains
    #[serde(deserialize_with = "fake_hash_map::deserialize_fake_hash_map")]
    pub domains_over_time: HashMap<String, u64>,

    /// Mapping from time to number of ads
    #[serde(deserialize_with = "fake_hash_map::deserialize_fake_hash_map")]
    pub ads_over_time: HashMap<String, u64>,
}

/// Top Items Struct
#[derive(Deserialize, Serialize, Debug)]
pub struct TopItems {
    /// Top queries mapping from domain to number of requests
    #[serde(deserialize_with = "fake_hash_map::deserialize_fake_hash_map")]
    pub top_queries: HashMap<String, u64>,

    /// Top ads mapping from domain to number of requests
    #[serde(deserialize_with = "fake_hash_map::deserialize_fake_hash_map")]
    pub top_ads: HashMap<String, u64>,
}

/// Top Clients Struct
#[derive(Deserialize, Serialize, Debug)]
pub struct TopClients {
    /// Top sources mapping from "IP" or "hostname|IP" to number of requests.
    #[serde(deserialize_with = "fake_hash_map::deserialize_fake_hash_map")]
    pub top_sources: HashMap<String, u64>,
}

/// Top Clients Blocked Struct
#[derive(Deserialize, Serialize, Debug)]
pub struct TopClientsBlocked {
    /// Top sources blocked mapping from "IP" or "hostname|IP" to number of blocked requests.
    #[serde(deserialize_with = "fake_hash_map::deserialize_fake_hash_map")]
    pub top_sources_blocked: HashMap<String, u64>,
}

/// Forward Destinations Struct
#[derive(Deserialize, Serialize, Debug)]
pub struct ForwardDestinations {
    /// Forward destinations mapping from "human_readable_name|IP" to the percentage of requests answered.
    #[serde(deserialize_with = "fake_hash_map::deserialize_fake_hash_map")]
    pub forward_destinations: HashMap<String, f64>,
}

/// Query Types Struct
#[derive(Deserialize, Serialize, Debug)]
pub struct QueryTypes {
    /// Query types mapping from query type (A, AAAA, PTR, etc.) to the percentage of queries which are of that type.
    #[serde(deserialize_with = "fake_hash_map::deserialize_fake_hash_map")]
    pub querytypes: HashMap<String, f64>,
}

/// Query Struct
#[derive(Deserialize, Serialize_tuple, Debug)]
pub struct Query {
    /// Timestamp of query
    #[serde(deserialize_with = "custom_deserializers::deserialize_string_to_naive_datetime")]
    pub timestring: NaiveDateTime,

    /// Type of query (A, AAAA, PTR, etc.)
    pub query_type: QueryType,

    /// Requested domain name
    pub domain: String,

    /// Requesting client IP or hostname
    pub client: String,

    /// Status as String
    #[serde(deserialize_with = "custom_deserializers::deserialize_string_to_query_status")]
    pub status: QueryStatus,

    /// DNSSEC Status
    #[serde(deserialize_with = "custom_deserializers::deserialize_string_to_dnssec_status")]
    pub dnssec_status: DNSSECStatus,

    /// Reply Type
    #[serde(deserialize_with = "custom_deserializers::deserialize_string_to_reply_type")]
    pub reply_type: ReplyType,

    /// Response time
    #[serde(
        deserialize_with = "custom_deserializers::deserialize_string_to_duration_100_microseconds"
    )]
    pub response_time: Duration,

    /// CNAME domain
    pub cname_domain: String,

    /// Regex ID
    #[serde(deserialize_with = "custom_deserializers::deserialize_string_to_i32")]
    pub regex_id: i32,

    /// Upstream Destination
    pub upstream_destination: String,

    /// EDE
    pub ede: String,
}

/// All Queries Struct
#[derive(Deserialize, Serialize, Debug)]
pub struct AllQueries {
    /// List of queries
    pub data: Vec<Query>,
}

/// Status Struct
#[derive(Deserialize, Serialize, Debug)]
pub struct Status {
    /// Status, "enabled" or "disabled"
    pub status: String,
}

/// Version Struct
#[derive(Deserialize, Serialize, Debug)]
pub struct Version {
    /// Version
    pub version: u32,
}

/// Versions Struct
#[derive(Deserialize, Serialize, Debug)]
pub struct Versions {
    /// Is there an update available for Pi-hole core
    pub core_update: bool,
    /// Is there an update available for Pi-hole web
    pub web_update: bool,
    /// Is there an update available for Pi-hole FTL
    #[serde(rename = "FTL_update")]
    pub ftl_update: bool,
    /// Current Pi-hole core version
    pub core_current: String,
    /// Current Pi-hole web version
    pub web_current: String,
    /// Current Pi-hole FTL version
    #[serde(rename = "FTL_current")]
    pub ftl_current: String,
    /// Latest Pi-hole core version
    pub core_latest: String,
    /// Latest Pi-hole web version
    pub web_latest: String,
    /// Latest Pi-hole FTL version
    #[serde(rename = "FTL_latest")]
    pub ftl_latest: String,
    /// Current Pi-hole core branch
    pub core_branch: String,
    /// Current Pi-hole web branch
    pub web_branch: String,
    /// Current Pi-hole FTL branch
    #[serde(rename = "FTL_branch")]
    pub ftl_branch: String,
}

/// Cache Info Struct
#[derive(Deserialize, Serialize, Debug)]
pub struct CacheInfo {
    /// Cache size
    #[serde(rename = "cache-size")]
    pub cache_size: u64,

    /// Number of evicted cache entries
    #[serde(rename = "cache-live-freed")]
    pub cache_live_freed: u64,

    /// Number of cache entries inserted
    #[serde(rename = "cache-inserted")]
    pub cache_inserted: u64,
}

/// Client Name Struct
#[derive(Deserialize, Serialize, Debug)]
pub struct ClientName {
    /// Client name
    pub name: String,

    /// Client IP
    pub ip: IpAddr,
}

/// Network Client Struct
#[derive(Deserialize, Serialize, Debug)]
pub struct NetworkClient {
    /// Client ID
    pub id: u64,

    /// IP addresses of client
    pub ip: Vec<IpAddr>,

    /// Hardware address
    pub hwaddr: String,

    /// Interface
    pub interface: String,

    /// Hostname
    pub name: Vec<String>,

    /// Time first seen
    #[serde(rename = "firstSeen", with = "chrono::naive::serde::ts_seconds")]
    pub first_seen: NaiveDateTime,

    /// Time of last query
    #[serde(rename = "lastQuery", with = "chrono::naive::serde::ts_seconds")]
    pub last_query: NaiveDateTime,

    /// Number of queries
    #[serde(rename = "numQueries")]
    pub num_queries: u64,

    /// MAC Vendor
    #[serde(rename = "macVendor")]
    pub mac_vendor: String,
}

/// Network Struct
#[derive(Deserialize, Serialize, Debug)]
pub struct Network {
    /// List of network clients
    pub network: Vec<NetworkClient>,
}

/// List Modification Response Struct
#[derive(Deserialize, Serialize, Debug)]
pub struct ListModificationResponse {
    /// If request was successful
    pub success: bool,
    /// Optional message about request
    pub message: Option<String>,
}

/// Custom List Domain Struct
#[derive(Deserialize, Serialize, Debug)]
pub struct CustomListDomainDetails {
    /// Entry ID
    pub id: u64,
    /// Type
    #[serde(rename = "type")]
    pub domain_type: u64,
    /// Domain
    pub domain: String,
    /// Enabled
    #[serde(deserialize_with = "custom_deserializers::deserialize_uint_to_bool")]
    pub enabled: bool,
    /// Date added
    #[serde(with = "chrono::naive::serde::ts_seconds")]
    pub date_added: NaiveDateTime,
    /// Date modified
    #[serde(with = "chrono::naive::serde::ts_seconds")]
    pub date_modified: NaiveDateTime,
    /// Comments
    pub comment: String,
    /// Groups
    pub groups: Vec<u64>,
}

/// Local/Custom List Domain Struct
#[derive(Deserialize, Serialize, Debug)]
pub struct CustomDNSRecord {
    /// Domain of record
    pub domain: String,
    /// IP Address
    pub ip_address: IpAddr,
}

/// Local/Custom List CNAME Struct
#[derive(Deserialize, Serialize, Debug)]
pub struct CustomCNAMERecord {
    /// Domain of record
    pub domain: String,
    /// Target domain
    pub target_domain: String,
}

/// Response format when requesting information from the FTL while it is not running
#[derive(Deserialize, Serialize, Debug)]
pub struct FTLNotRunning {
    /// Not running flag
    #[serde(rename = "FTLnotrunning")]
    pub ftl_not_running: bool,
}