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;
39 @ServiceProvider(service = OptionProcessor.class)
43 private final Option caseNameOption = Option.requiredArgument(
'n',
"caseName");
44 private final Option caseTypeOption = Option.requiredArgument(
't',
"caseType");
45 private final Option caseBaseDirOption = Option.requiredArgument(
'o',
"caseBaseDir");
46 private final Option createCaseCommandOption = Option.withoutArgument(
'c',
"createCase");
47 private final Option dataSourcePathOption = Option.requiredArgument(
's',
"dataSourcePath");
48 private final Option dataSourceObjectIdOption = Option.requiredArgument(
'i',
"dataSourceObjectId");
49 private final Option addDataSourceCommandOption = Option.withoutArgument(
'a',
"addDataSource");
50 private final Option caseDirOption = Option.requiredArgument(
'd',
"caseDir");
51 private final Option runIngestCommandOption = Option.withoutArgument(
'r',
"runIngest");
52 private final Option ingestProfileOption = Option.requiredArgument(
'p',
"ingestProfile");
53 private final Option listAllDataSourcesCommandOption = Option.withoutArgument(
'l',
"listAllDataSources");
54 private final Option generateReportsOption = Option.withoutArgument(
'g',
"generateReports");
56 private boolean runFromCommandLine =
false;
58 private final List<CommandLineCommand> commands =
new ArrayList<>();
60 final static String CASETYPE_MULTI =
"multi";
61 final static String CASETYPE_SINGLE =
"single";
65 Set<Option> set =
new HashSet<>();
66 set.add(createCaseCommandOption);
67 set.add(caseNameOption);
68 set.add(caseTypeOption);
69 set.add(caseBaseDirOption);
70 set.add(dataSourcePathOption);
71 set.add(addDataSourceCommandOption);
72 set.add(dataSourceObjectIdOption);
73 set.add(caseDirOption);
74 set.add(runIngestCommandOption);
75 set.add(ingestProfileOption);
76 set.add(listAllDataSourcesCommandOption);
77 set.add(generateReportsOption);
82 protected void process(Env env, Map<Option, String[]> values) throws CommandException {
83 logger.log(Level.INFO,
"Processing Autopsy command line options");
84 System.out.println(
"Processing Autopsy command line options");
85 runFromCommandLine =
false;
88 if (!(values.containsKey(createCaseCommandOption) || values.containsKey(addDataSourceCommandOption)
89 || values.containsKey(runIngestCommandOption) || values.containsKey(listAllDataSourcesCommandOption)
90 || values.containsKey(generateReportsOption))) {
92 logger.log(Level.INFO,
"No command line commands passed in as inputs. Not running from command line.");
93 System.err.println(
"No command line commands passed in as inputs. Not running from command line.");
99 String inputCaseName =
"";
100 if (values.containsKey(caseNameOption)) {
101 argDirs = values.get(caseNameOption);
102 if (argDirs.length < 1) {
103 logger.log(Level.SEVERE,
"Missing argument 'caseName'");
104 System.err.println(
"Missing argument 'caseName'");
107 inputCaseName = argDirs[0];
109 if (inputCaseName == null || inputCaseName.isEmpty()) {
110 logger.log(Level.SEVERE,
"'caseName' argument is empty");
111 System.err.println(
"'caseName' argument is empty");
117 String caseType =
"";
118 if (values.containsKey(caseTypeOption)) {
119 argDirs = values.get(caseTypeOption);
121 if (argDirs.length < 1) {
122 logger.log(Level.SEVERE,
"Missing argument 'caseType'");
123 System.err.println(
"Missing argument 'caseType'");
126 caseType = argDirs[0];
128 if (caseType == null || caseType.isEmpty()) {
129 logger.log(Level.SEVERE,
"'caseType' argument is empty");
130 System.err.println(
"'caseType' argument is empty");
134 if (!caseType.equalsIgnoreCase(CASETYPE_MULTI) && !caseType.equalsIgnoreCase(CASETYPE_SINGLE)) {
135 logger.log(Level.SEVERE,
"'caseType' argument is invalid");
136 System.err.println(
"'caseType' argument is invalid");
141 logger.log(Level.SEVERE,
"Unable to create multi user case.");
142 System.err.println(
"Unable to create multi user case. Confirm that multi user settings are configured correctly.");
147 String caseBaseDir =
"";
148 if (values.containsKey(caseBaseDirOption)) {
149 argDirs = values.get(caseBaseDirOption);
150 if (argDirs.length < 1) {
151 logger.log(Level.SEVERE,
"Missing argument 'caseBaseDir'");
152 System.err.println(
"Missing argument 'caseBaseDir'");
155 caseBaseDir = argDirs[0];
157 if (caseBaseDir == null || caseBaseDir.isEmpty()) {
158 logger.log(Level.SEVERE,
"Missing argument 'caseBaseDir'");
159 System.err.println(
"Missing argument 'caseBaseDir'");
163 if (!(
new File(caseBaseDir).exists()) || !(
new File(caseBaseDir).isDirectory())) {
164 logger.log(Level.SEVERE,
"''caseBaseDir'' {0} directory doesn''t exist or is not a directory", caseBaseDir);
165 System.err.println(
"'caseBaseDir' directory doesn't exist or is not a directory: " + caseBaseDir);
170 String dataSourcePath =
"";
171 if (values.containsKey(dataSourcePathOption)) {
173 argDirs = values.get(dataSourcePathOption);
174 if (argDirs.length < 1) {
175 logger.log(Level.SEVERE,
"Missing argument 'dataSourcePath'");
176 System.err.println(
"Missing argument 'dataSourcePath'");
179 dataSourcePath = argDirs[0];
182 if (dataSourcePath == null || dataSourcePath.isEmpty()) {
183 logger.log(Level.SEVERE,
"Missing argument 'dataSourcePath'");
184 System.err.println(
"Missing argument 'dataSourcePath'");
188 if (!(
new File(dataSourcePath).exists())) {
189 logger.log(Level.SEVERE,
"Input data source file {0} doesn''t exist", dataSourcePath);
190 System.err.println(
"Input data source file " + dataSourcePath +
" doesn't exist");
195 String dataSourceId =
"";
196 if (values.containsKey(dataSourceObjectIdOption)) {
198 argDirs = values.get(dataSourceObjectIdOption);
199 if (argDirs.length < 1) {
200 logger.log(Level.SEVERE,
"Missing argument 'dataSourceObjectIdOption'");
201 System.err.println(
"Missing argument 'dataSourceObjectIdOption'");
204 dataSourceId = argDirs[0];
207 if (dataSourceId == null || dataSourceId.isEmpty()) {
208 logger.log(Level.SEVERE,
"Input data source id is empty");
209 System.err.println(
"Input data source id is empty");
215 if (values.containsKey(caseDirOption)) {
217 argDirs = values.get(caseDirOption);
218 if (argDirs.length < 1) {
219 logger.log(Level.SEVERE,
"Missing argument 'caseDirOption'");
220 System.err.println(
"Missing argument 'caseDirOption'");
223 caseDir = argDirs[0];
226 if (caseDir == null || caseDir.isEmpty()) {
227 logger.log(Level.SEVERE,
"Missing argument 'caseDirOption'");
228 System.err.println(
"Missing argument 'caseDirOption'");
232 if (!(
new File(caseDir).exists()) || !(
new File(caseDir).isDirectory())) {
233 logger.log(Level.SEVERE,
"Case directory {0} doesn''t exist or is not a directory", caseDir);
234 System.err.println(
"Case directory " + caseDir +
" doesn't exist or is not a directory");
239 String ingestProfile =
"";
240 if (values.containsKey(ingestProfileOption)) {
242 argDirs = values.get(ingestProfileOption);
243 if (argDirs.length < 1) {
244 logger.log(Level.SEVERE,
"Missing argument 'ingestProfile'");
245 System.err.println(
"Missing argument 'ingestProfile'");
248 ingestProfile = argDirs[0];
251 if (ingestProfile == null || ingestProfile.isEmpty()) {
252 logger.log(Level.SEVERE,
"Missing argument 'ingestProfile'");
253 System.err.println(
"Missing argument 'ingestProfile'");
260 if (values.containsKey(createCaseCommandOption)) {
263 if (inputCaseName.isEmpty()) {
264 logger.log(Level.SEVERE,
"'caseName' argument is empty");
265 System.out.println(
"'caseName' argument is empty");
266 runFromCommandLine =
false;
271 if (caseBaseDir.isEmpty()) {
272 logger.log(Level.SEVERE,
"'caseBaseDir' argument is empty");
273 System.err.println(
"'caseBaseDir' argument is empty");
274 runFromCommandLine =
false;
278 CommandLineCommand newCommand =
new CommandLineCommand(CommandLineCommand.CommandType.CREATE_CASE);
279 newCommand.addInputValue(CommandLineCommand.InputType.CASE_NAME.name(), inputCaseName);
280 newCommand.addInputValue(CommandLineCommand.InputType.CASES_BASE_DIR_PATH.name(), caseBaseDir);
281 newCommand.addInputValue(CommandLineCommand.InputType.CASE_TYPE.name(), caseType);
282 commands.add(newCommand);
283 runFromCommandLine =
true;
287 if (values.containsKey(addDataSourceCommandOption)) {
290 if (!values.containsKey(createCaseCommandOption) && caseDir.isEmpty()) {
292 logger.log(Level.SEVERE,
"'caseDir' argument is empty");
293 System.err.println(
"'caseDir' argument is empty");
294 runFromCommandLine =
false;
299 if (dataSourcePath.isEmpty()) {
300 logger.log(Level.SEVERE,
"'dataSourcePath' argument is empty");
301 System.err.println(
"'dataSourcePath' argument is empty");
302 runFromCommandLine =
false;
306 CommandLineCommand newCommand =
new CommandLineCommand(CommandLineCommand.CommandType.ADD_DATA_SOURCE);
307 newCommand.addInputValue(CommandLineCommand.InputType.CASE_FOLDER_PATH.name(), caseDir);
308 newCommand.addInputValue(CommandLineCommand.InputType.DATA_SOURCE_PATH.name(), dataSourcePath);
309 commands.add(newCommand);
310 runFromCommandLine =
true;
314 if (values.containsKey(runIngestCommandOption)) {
317 if (!values.containsKey(createCaseCommandOption) && caseDir.isEmpty()) {
319 logger.log(Level.SEVERE,
"'caseDir' argument is empty");
320 System.err.println(
"'caseDir' argument is empty");
321 runFromCommandLine =
false;
326 if (!values.containsKey(addDataSourceCommandOption) && dataSourceId.isEmpty()) {
328 logger.log(Level.SEVERE,
"'dataSourceId' argument is empty");
329 System.err.println(
"'dataSourceId' argument is empty");
330 runFromCommandLine =
false;
334 CommandLineCommand newCommand =
new CommandLineCommand(CommandLineCommand.CommandType.RUN_INGEST);
335 newCommand.addInputValue(CommandLineCommand.InputType.CASE_FOLDER_PATH.name(), caseDir);
336 newCommand.addInputValue(CommandLineCommand.InputType.DATA_SOURCE_ID.name(), dataSourceId);
337 newCommand.addInputValue(CommandLineCommand.InputType.INGEST_PROFILE_NAME.name(), ingestProfile);
338 commands.add(newCommand);
339 runFromCommandLine =
true;
343 if (values.containsKey(listAllDataSourcesCommandOption)) {
346 if (!values.containsKey(createCaseCommandOption) && caseDir.isEmpty()) {
348 logger.log(Level.SEVERE,
"'caseDir' argument is empty");
349 System.err.println(
"'caseDir' argument is empty");
350 runFromCommandLine =
false;
354 CommandLineCommand newCommand =
new CommandLineCommand(CommandLineCommand.CommandType.LIST_ALL_DATA_SOURCES);
355 newCommand.addInputValue(CommandLineCommand.InputType.CASE_FOLDER_PATH.name(), caseDir);
356 commands.add(newCommand);
357 runFromCommandLine =
true;
361 if (values.containsKey(generateReportsOption)) {
364 if (!values.containsKey(createCaseCommandOption) && caseDir.isEmpty()) {
366 logger.log(Level.SEVERE,
"'caseDir' argument is empty");
367 System.err.println(
"'caseDir' argument is empty");
368 runFromCommandLine =
false;
372 CommandLineCommand newCommand =
new CommandLineCommand(CommandLineCommand.CommandType.GENERATE_REPORTS);
373 newCommand.addInputValue(CommandLineCommand.InputType.CASE_FOLDER_PATH.name(), caseDir);
374 commands.add(newCommand);
375 runFromCommandLine =
true;
385 return runFromCommandLine;
393 List<CommandLineCommand> getCommands() {
boolean isRunFromCommandLine()
static boolean canCreateMultiUserCases()
synchronized static Logger getLogger(String name)
Set< Option > getOptions()
void process(Env env, Map< Option, String[]> values)