rusthound_ce/json/maker/
mod.rs

1use std::collections::HashMap;
2use std::error::Error;
3
4extern crate zip;
5use crate::api::ADResults;
6use crate::args::Options;
7use crate::utils::date::return_current_fulldate;
8pub mod common;
9
10/// This function will create json output and zip output
11pub fn make_result(common_args: &Options, ad_results: ADResults) -> Result<String, Box<dyn Error>> {
12   // Format domain name
13   let filename = common_args.domain.replace(".", "-").to_lowercase();
14
15   // Hashmap for json files
16   let mut json_result: HashMap<String, String> = HashMap::new();
17
18   // Datetime for output file
19   let datetime = return_current_fulldate();
20
21   // Add all in json files
22   common::add_file(
23      &datetime,
24      "users".to_string(),
25		&filename,
26      ad_results.users,
27      &mut json_result,
28      common_args,
29   )?;
30   common::add_file(
31      &datetime,
32      "groups".to_string(),
33		&filename,
34      ad_results.groups,
35      &mut json_result,
36      common_args,
37   )?;
38   common::add_file(
39      &datetime,
40      "computers".to_string(),
41		&filename,
42      ad_results.computers,
43      &mut json_result,
44      common_args,
45   )?;
46   common::add_file(
47      &datetime,
48      "ous".to_string(),
49		&filename,
50      ad_results.ous,
51      &mut json_result,
52      common_args,
53   )?;
54   common::add_file(
55      &datetime,
56      "domains".to_string(),
57		&filename,
58      ad_results.domains,
59      &mut json_result,
60      common_args,
61   )?;
62   common::add_file(
63      &datetime,
64      "gpos".to_string(),
65      &filename,
66      ad_results.gpos,
67      &mut json_result,
68      common_args,
69   )?;
70   // }
71   common::add_file(
72      &datetime,
73      "containers".to_string(),
74		&filename,
75      ad_results.containers,
76      &mut json_result,
77      common_args,
78   )?;
79   common::add_file(
80      &datetime,
81      "ntauthstores".to_string(),
82		&filename,
83      ad_results.ntauthstores,
84      &mut json_result,
85      common_args,
86   )?;
87   common::add_file(
88      &datetime,
89      "aiacas".to_string(),
90		&filename,
91      ad_results.aiacas,
92      &mut json_result,
93      common_args,
94   )?;
95   common::add_file(
96      &datetime,
97      "rootcas".to_string(),
98		&filename,
99      ad_results.rootcas,
100      &mut json_result,
101      common_args,
102   )?;
103   common::add_file(
104      &datetime,
105      "enterprisecas".to_string(),
106		&filename,
107      ad_results.enterprisecas,
108      &mut json_result,
109      common_args,
110   )?;
111   common::add_file(
112      &datetime,
113      "certtemplates".to_string(),
114		&filename,
115      ad_results.certtemplates,
116      &mut json_result,
117      common_args,
118   )?;
119   common::add_file(
120      &datetime,
121      "issuancepolicies".to_string(),
122		&filename,
123      ad_results.issuancepolicies,
124      &mut json_result,
125      common_args,
126   )?;
127   // All in zip file
128   if common_args.zip {
129      return Ok(common::make_a_zip(
130         &datetime,
131         &filename,
132         &common_args.path,
133         &json_result)?)
134   }
135   Ok(String::from("No zip full path"))
136}