19 package org.sleuthkit.autopsy.commandlineingest;
22 import java.util.ArrayList;
23 import java.util.HashSet;
24 import java.util.List;
27 import java.util.logging.Level;
29 import org.netbeans.api.sendopts.CommandException;
30 import org.netbeans.spi.sendopts.Env;
31 import org.netbeans.spi.sendopts.Option;
32 import org.netbeans.spi.sendopts.OptionProcessor;
33 import org.openide.util.lookup.ServiceProvider;
38 @ServiceProvider(service = OptionProcessor.class)
42 private final Option caseNameOption = Option.requiredArgument(
'n',
"caseName");
43 private final Option caseBaseDirOption = Option.requiredArgument(
'o',
"caseBaseDir");
44 private final Option createCaseCommandOption = Option.withoutArgument(
'c',
"createCase");
45 private final Option dataSourcePathOption = Option.requiredArgument(
's',
"dataSourcePath");
46 private final Option dataSourceObjectIdOption = Option.requiredArgument(
'i',
"dataSourceObjectId");
47 private final Option addDataSourceCommandOption = Option.withoutArgument(
'a',
"addDataSource");
48 private final Option caseDirOption = Option.requiredArgument(
'd',
"caseDir");
49 private final Option runIngestCommandOption = Option.withoutArgument(
'r',
"runIngest");
50 private final Option ingestProfileOption = Option.requiredArgument(
'p',
"ingestProfile");
51 private final Option listAllDataSourcesCommandOption = Option.withoutArgument(
'l',
"listAllDataSources");
52 private final Option generateReportsOption = Option.withoutArgument(
'g',
"generateReports");
54 private boolean runFromCommandLine =
false;
56 private final List<CommandLineCommand> commands =
new ArrayList<>();
60 Set<Option> set =
new HashSet<>();
61 set.add(createCaseCommandOption);
62 set.add(caseNameOption);
63 set.add(caseBaseDirOption);
64 set.add(dataSourcePathOption);
65 set.add(addDataSourceCommandOption);
66 set.add(dataSourceObjectIdOption);
67 set.add(caseDirOption);
68 set.add(runIngestCommandOption);
69 set.add(ingestProfileOption);
70 set.add(listAllDataSourcesCommandOption);
71 set.add(generateReportsOption);
76 protected void process(Env env, Map<Option, String[]> values) throws CommandException {
77 logger.log(Level.INFO,
"Processing Autopsy command line options");
78 System.out.println(
"Processing Autopsy command line options");
79 runFromCommandLine =
false;
82 if (!(values.containsKey(createCaseCommandOption) || values.containsKey(addDataSourceCommandOption)
83 || values.containsKey(runIngestCommandOption) || values.containsKey(listAllDataSourcesCommandOption)
84 || values.containsKey(generateReportsOption))) {
86 logger.log(Level.INFO,
"No command line commands passed in as inputs. Not running from command line.");
87 System.err.println(
"No command line commands passed in as inputs. Not running from command line.");
93 String inputCaseName =
"";
94 if (values.containsKey(caseNameOption)) {
95 argDirs = values.get(caseNameOption);
96 if (argDirs.length < 1) {
97 logger.log(Level.SEVERE,
"Missing argument 'caseName'");
98 System.err.println(
"Missing argument 'caseName'");
101 inputCaseName = argDirs[0];
103 if (inputCaseName == null || inputCaseName.isEmpty()) {
104 logger.log(Level.SEVERE,
"'caseName' argument is empty");
105 System.err.println(
"'caseName' argument is empty");
110 String caseBaseDir =
"";
111 if (values.containsKey(caseBaseDirOption)) {
112 argDirs = values.get(caseBaseDirOption);
113 if (argDirs.length < 1) {
114 logger.log(Level.SEVERE,
"Missing argument 'caseBaseDir'");
115 System.err.println(
"Missing argument 'caseBaseDir'");
118 caseBaseDir = argDirs[0];
120 if (caseBaseDir == null || caseBaseDir.isEmpty()) {
121 logger.log(Level.SEVERE,
"Missing argument 'caseBaseDir'");
122 System.err.println(
"Missing argument 'caseBaseDir'");
126 if (!(
new File(caseBaseDir).exists()) || !(
new File(caseBaseDir).isDirectory())) {
127 logger.log(Level.SEVERE,
"''caseBaseDir'' {0} directory doesn''t exist or is not a directory", caseBaseDir);
128 System.err.println(
"'caseBaseDir' directory doesn't exist or is not a directory: " + caseBaseDir);
133 String dataSourcePath =
"";
134 if (values.containsKey(dataSourcePathOption)) {
136 argDirs = values.get(dataSourcePathOption);
137 if (argDirs.length < 1) {
138 logger.log(Level.SEVERE,
"Missing argument 'dataSourcePath'");
139 System.err.println(
"Missing argument 'dataSourcePath'");
142 dataSourcePath = argDirs[0];
145 if (dataSourcePath == null || dataSourcePath.isEmpty()) {
146 logger.log(Level.SEVERE,
"Missing argument 'dataSourcePath'");
147 System.err.println(
"Missing argument 'dataSourcePath'");
151 if (!(
new File(dataSourcePath).exists())) {
152 logger.log(Level.SEVERE,
"Input data source file {0} doesn''t exist", dataSourcePath);
153 System.err.println(
"Input data source file " + dataSourcePath +
" doesn't exist");
158 String dataSourceId =
"";
159 if (values.containsKey(dataSourceObjectIdOption)) {
161 argDirs = values.get(dataSourceObjectIdOption);
162 if (argDirs.length < 1) {
163 logger.log(Level.SEVERE,
"Missing argument 'dataSourceObjectIdOption'");
164 System.err.println(
"Missing argument 'dataSourceObjectIdOption'");
167 dataSourceId = argDirs[0];
170 if (dataSourceId == null || dataSourceId.isEmpty()) {
171 logger.log(Level.SEVERE,
"Input data source id is empty");
172 System.err.println(
"Input data source id is empty");
178 if (values.containsKey(caseDirOption)) {
180 argDirs = values.get(caseDirOption);
181 if (argDirs.length < 1) {
182 logger.log(Level.SEVERE,
"Missing argument 'caseDirOption'");
183 System.err.println(
"Missing argument 'caseDirOption'");
186 caseDir = argDirs[0];
189 if (caseDir == null || caseDir.isEmpty()) {
190 logger.log(Level.SEVERE,
"Missing argument 'caseDirOption'");
191 System.err.println(
"Missing argument 'caseDirOption'");
195 if (!(
new File(caseDir).exists()) || !(
new File(caseDir).isDirectory())) {
196 logger.log(Level.SEVERE,
"Case directory {0} doesn''t exist or is not a directory", caseDir);
197 System.err.println(
"Case directory " + caseDir +
" doesn't exist or is not a directory");
202 String ingestProfile =
"";
203 if (values.containsKey(ingestProfileOption)) {
205 argDirs = values.get(ingestProfileOption);
206 if (argDirs.length < 1) {
207 logger.log(Level.SEVERE,
"Missing argument 'ingestProfile'");
208 System.err.println(
"Missing argument 'ingestProfile'");
211 ingestProfile = argDirs[0];
214 if (ingestProfile == null || ingestProfile.isEmpty()) {
215 logger.log(Level.SEVERE,
"Missing argument 'ingestProfile'");
216 System.err.println(
"Missing argument 'ingestProfile'");
223 if (values.containsKey(createCaseCommandOption)) {
226 if (inputCaseName.isEmpty()) {
227 logger.log(Level.SEVERE,
"'caseName' argument is empty");
228 System.out.println(
"'caseName' argument is empty");
229 runFromCommandLine =
false;
234 if (caseBaseDir.isEmpty()) {
235 logger.log(Level.SEVERE,
"'caseBaseDir' argument is empty");
236 System.err.println(
"'caseBaseDir' argument is empty");
237 runFromCommandLine =
false;
241 CommandLineCommand newCommand =
new CommandLineCommand(CommandLineCommand.CommandType.CREATE_CASE);
242 newCommand.addInputValue(CommandLineCommand.InputType.CASE_NAME.name(), inputCaseName);
243 newCommand.addInputValue(CommandLineCommand.InputType.CASES_BASE_DIR_PATH.name(), caseBaseDir);
244 commands.add(newCommand);
245 runFromCommandLine =
true;
249 if (values.containsKey(addDataSourceCommandOption)) {
252 if (!values.containsKey(createCaseCommandOption) && caseDir.isEmpty()) {
254 logger.log(Level.SEVERE,
"'caseDir' argument is empty");
255 System.err.println(
"'caseDir' argument is empty");
256 runFromCommandLine =
false;
261 if (dataSourcePath.isEmpty()) {
262 logger.log(Level.SEVERE,
"'dataSourcePath' argument is empty");
263 System.err.println(
"'dataSourcePath' argument is empty");
264 runFromCommandLine =
false;
268 CommandLineCommand newCommand =
new CommandLineCommand(CommandLineCommand.CommandType.ADD_DATA_SOURCE);
269 newCommand.addInputValue(CommandLineCommand.InputType.CASE_FOLDER_PATH.name(), caseDir);
270 newCommand.addInputValue(CommandLineCommand.InputType.DATA_SOURCE_PATH.name(), dataSourcePath);
271 commands.add(newCommand);
272 runFromCommandLine =
true;
276 if (values.containsKey(runIngestCommandOption)) {
279 if (!values.containsKey(createCaseCommandOption) && caseDir.isEmpty()) {
281 logger.log(Level.SEVERE,
"'caseDir' argument is empty");
282 System.err.println(
"'caseDir' argument is empty");
283 runFromCommandLine =
false;
288 if (!values.containsKey(addDataSourceCommandOption) && dataSourceId.isEmpty()) {
290 logger.log(Level.SEVERE,
"'dataSourceId' argument is empty");
291 System.err.println(
"'dataSourceId' argument is empty");
292 runFromCommandLine =
false;
296 CommandLineCommand newCommand =
new CommandLineCommand(CommandLineCommand.CommandType.RUN_INGEST);
297 newCommand.addInputValue(CommandLineCommand.InputType.CASE_FOLDER_PATH.name(), caseDir);
298 newCommand.addInputValue(CommandLineCommand.InputType.DATA_SOURCE_ID.name(), dataSourceId);
299 newCommand.addInputValue(CommandLineCommand.InputType.INGEST_PROFILE_NAME.name(), ingestProfile);
300 commands.add(newCommand);
301 runFromCommandLine =
true;
305 if (values.containsKey(listAllDataSourcesCommandOption)) {
308 if (!values.containsKey(createCaseCommandOption) && caseDir.isEmpty()) {
310 logger.log(Level.SEVERE,
"'caseDir' argument is empty");
311 System.err.println(
"'caseDir' argument is empty");
312 runFromCommandLine =
false;
316 CommandLineCommand newCommand =
new CommandLineCommand(CommandLineCommand.CommandType.LIST_ALL_DATA_SOURCES);
317 newCommand.addInputValue(CommandLineCommand.InputType.CASE_FOLDER_PATH.name(), caseDir);
318 commands.add(newCommand);
319 runFromCommandLine =
true;
323 if (values.containsKey(generateReportsOption)) {
326 if (!values.containsKey(createCaseCommandOption) && caseDir.isEmpty()) {
328 logger.log(Level.SEVERE,
"'caseDir' argument is empty");
329 System.err.println(
"'caseDir' argument is empty");
330 runFromCommandLine =
false;
334 CommandLineCommand newCommand =
new CommandLineCommand(CommandLineCommand.CommandType.GENERATE_REPORTS);
335 newCommand.addInputValue(CommandLineCommand.InputType.CASE_FOLDER_PATH.name(), caseDir);
336 commands.add(newCommand);
337 runFromCommandLine =
true;
347 return runFromCommandLine;
355 List<CommandLineCommand> getCommands() {
boolean isRunFromCommandLine()
synchronized static Logger getLogger(String name)
Set< Option > getOptions()
void process(Env env, Map< Option, String[]> values)