mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-06 21:00:22 +00:00
Merge pull request #7637 from kellykelly3/8364-command-line-profile-option
Added listprofiles option to CL
This commit is contained in:
commit
0212f46811
@ -35,7 +35,8 @@ class CommandLineCommand {
|
||||
RUN_INGEST,
|
||||
LIST_ALL_DATA_SOURCES,
|
||||
GENERATE_REPORTS,
|
||||
OPEN_CASE_IN_UI;
|
||||
OPEN_CASE_IN_UI,
|
||||
LIST_ALL_INGEST_PROFILES;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -18,6 +18,7 @@
|
||||
*/
|
||||
package org.sleuthkit.autopsy.commandlineingest;
|
||||
|
||||
import com.google.gson.GsonBuilder;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.nio.file.Paths;
|
||||
@ -54,6 +55,7 @@ import org.sleuthkit.autopsy.ingest.IngestJobStartResult;
|
||||
import org.sleuthkit.autopsy.ingest.IngestManager;
|
||||
import org.sleuthkit.autopsy.ingest.IngestModuleError;
|
||||
import org.sleuthkit.autopsy.ingest.IngestProfiles;
|
||||
import org.sleuthkit.autopsy.ingest.IngestProfiles.IngestProfile;
|
||||
import org.sleuthkit.autopsy.modules.interestingitems.FilesSet;
|
||||
import org.sleuthkit.autopsy.modules.interestingitems.FilesSetsManager;
|
||||
import org.sleuthkit.autopsy.report.infrastructure.ReportGenerator;
|
||||
@ -311,6 +313,16 @@ public class CommandLineIngestManager extends CommandLineManager {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case LIST_ALL_INGEST_PROFILES:
|
||||
List<IngestProfile> profiles = IngestProfiles.getIngestProfiles();
|
||||
GsonBuilder gb = new GsonBuilder();
|
||||
System.out.println("Listing ingest profiles");
|
||||
for(IngestProfile profile: profiles) {
|
||||
String jsonText = gb.create().toJson(profile);
|
||||
System.out.println(jsonText);
|
||||
}
|
||||
System.out.println("Ingest profile list complete");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -55,6 +55,7 @@ public class CommandLineOptionProcessor extends OptionProcessor {
|
||||
private final Option runIngestCommandOption = Option.optionalArgument('r', "runIngest");
|
||||
private final Option listAllDataSourcesCommandOption = Option.withoutArgument('l', "listAllDataSources");
|
||||
private final Option generateReportsOption = Option.optionalArgument('g', "generateReports");
|
||||
private final Option listAllIngestProfileOption = Option.withoutArgument('p', "listAllIngestProfiles");
|
||||
private final Option defaultArgument = Option.defaultArguments();
|
||||
|
||||
private boolean runFromCommandLine = false;
|
||||
@ -91,6 +92,7 @@ public class CommandLineOptionProcessor extends OptionProcessor {
|
||||
set.add(runIngestCommandOption);
|
||||
set.add(listAllDataSourcesCommandOption);
|
||||
set.add(generateReportsOption);
|
||||
set.add(listAllIngestProfileOption);
|
||||
set.add(defaultArgument);
|
||||
return set;
|
||||
}
|
||||
@ -111,7 +113,7 @@ public class CommandLineOptionProcessor extends OptionProcessor {
|
||||
// input arguments must contain at least one command
|
||||
if (!(values.containsKey(createCaseCommandOption) || values.containsKey(addDataSourceCommandOption)
|
||||
|| values.containsKey(runIngestCommandOption) || values.containsKey(listAllDataSourcesCommandOption)
|
||||
|| values.containsKey(generateReportsOption))) {
|
||||
|| values.containsKey(generateReportsOption) || values.containsKey(listAllIngestProfileOption))) {
|
||||
// not running from command line
|
||||
handleError("Invalid command line, an input option must be supplied.");
|
||||
}
|
||||
@ -119,197 +121,204 @@ public class CommandLineOptionProcessor extends OptionProcessor {
|
||||
// parse input parameters
|
||||
String[] argDirs;
|
||||
String inputCaseName = "";
|
||||
if (values.containsKey(caseNameOption)) {
|
||||
argDirs = values.get(caseNameOption);
|
||||
if (argDirs.length < 1) {
|
||||
handleError("Missing argument 'caseName'");
|
||||
}
|
||||
inputCaseName = argDirs[0];
|
||||
|
||||
if(values.containsKey(listAllIngestProfileOption)) {
|
||||
CommandLineCommand newCommand = new CommandLineCommand(CommandLineCommand.CommandType.LIST_ALL_INGEST_PROFILES);
|
||||
commands.add(newCommand);
|
||||
runFromCommandLine(true);
|
||||
} else {
|
||||
if (values.containsKey(caseNameOption)) {
|
||||
argDirs = values.get(caseNameOption);
|
||||
if (argDirs.length < 1) {
|
||||
handleError("Missing argument 'caseName'");
|
||||
}
|
||||
inputCaseName = argDirs[0];
|
||||
|
||||
if (inputCaseName == null || inputCaseName.isEmpty()) {
|
||||
handleError("'caseName' argument is empty");
|
||||
}
|
||||
}
|
||||
|
||||
// 'caseName' must always be specified
|
||||
if (inputCaseName == null || inputCaseName.isEmpty()) {
|
||||
handleError("'caseName' argument is empty");
|
||||
}
|
||||
}
|
||||
|
||||
// 'caseName' must always be specified
|
||||
if (inputCaseName == null || inputCaseName.isEmpty()) {
|
||||
handleError("'caseName' argument is empty");
|
||||
}
|
||||
String caseType = "";
|
||||
if (values.containsKey(caseTypeOption)) {
|
||||
argDirs = values.get(caseTypeOption);
|
||||
|
||||
String caseType = "";
|
||||
if (values.containsKey(caseTypeOption)) {
|
||||
argDirs = values.get(caseTypeOption);
|
||||
if (argDirs.length < 1) {
|
||||
handleError("Missing argument 'caseType'");
|
||||
}
|
||||
caseType = argDirs[0];
|
||||
|
||||
if (argDirs.length < 1) {
|
||||
handleError("Missing argument 'caseType'");
|
||||
}
|
||||
caseType = argDirs[0];
|
||||
if (caseType == null || caseType.isEmpty()) {
|
||||
handleError("'caseType' argument is empty");
|
||||
} else if (!caseType.equalsIgnoreCase(CASETYPE_MULTI) && !caseType.equalsIgnoreCase(CASETYPE_SINGLE)) {
|
||||
handleError("'caseType' argument is invalid");
|
||||
} else if (caseType.equalsIgnoreCase(CASETYPE_MULTI) && !FeatureAccessUtils.canCreateMultiUserCases()) {
|
||||
handleError("Unable to create multi user case. Confirm that multi user settings are configured correctly.");
|
||||
}
|
||||
}
|
||||
|
||||
if (caseType == null || caseType.isEmpty()) {
|
||||
handleError("'caseType' argument is empty");
|
||||
} else if (!caseType.equalsIgnoreCase(CASETYPE_MULTI) && !caseType.equalsIgnoreCase(CASETYPE_SINGLE)) {
|
||||
handleError("'caseType' argument is invalid");
|
||||
} else if (caseType.equalsIgnoreCase(CASETYPE_MULTI) && !FeatureAccessUtils.canCreateMultiUserCases()) {
|
||||
handleError("Unable to create multi user case. Confirm that multi user settings are configured correctly.");
|
||||
}
|
||||
}
|
||||
String caseBaseDir = "";
|
||||
if (values.containsKey(caseBaseDirOption)) {
|
||||
argDirs = values.get(caseBaseDirOption);
|
||||
if (argDirs.length < 1) {
|
||||
handleError("Missing argument 'caseBaseDir'");
|
||||
}
|
||||
caseBaseDir = argDirs[0];
|
||||
|
||||
String caseBaseDir = "";
|
||||
if (values.containsKey(caseBaseDirOption)) {
|
||||
argDirs = values.get(caseBaseDirOption);
|
||||
if (argDirs.length < 1) {
|
||||
handleError("Missing argument 'caseBaseDir'");
|
||||
}
|
||||
caseBaseDir = argDirs[0];
|
||||
if (caseBaseDir == null || caseBaseDir.isEmpty()) {
|
||||
handleError("Missing argument 'caseBaseDir' option");
|
||||
}
|
||||
|
||||
if (!(new File(caseBaseDir).exists()) || !(new File(caseBaseDir).isDirectory())) {
|
||||
handleError("'caseBaseDir' directory doesn't exist or is not a directory: " + caseBaseDir);
|
||||
}
|
||||
}
|
||||
|
||||
// 'caseBaseDir' must always be specified
|
||||
if (caseBaseDir == null || caseBaseDir.isEmpty()) {
|
||||
handleError("Missing argument 'caseBaseDir' option");
|
||||
}
|
||||
|
||||
if (!(new File(caseBaseDir).exists()) || !(new File(caseBaseDir).isDirectory())) {
|
||||
handleError("'caseBaseDir' directory doesn't exist or is not a directory: " + caseBaseDir);
|
||||
}
|
||||
}
|
||||
|
||||
// 'caseBaseDir' must always be specified
|
||||
if (caseBaseDir == null || caseBaseDir.isEmpty()) {
|
||||
handleError("Missing argument 'caseBaseDir' option");
|
||||
}
|
||||
String dataSourcePath = "";
|
||||
if (values.containsKey(dataSourcePathOption)) {
|
||||
|
||||
String dataSourcePath = "";
|
||||
if (values.containsKey(dataSourcePathOption)) {
|
||||
argDirs = values.get(dataSourcePathOption);
|
||||
if (argDirs.length < 1) {
|
||||
handleError("Missing argument 'dataSourcePath'");
|
||||
}
|
||||
dataSourcePath = argDirs[0];
|
||||
|
||||
argDirs = values.get(dataSourcePathOption);
|
||||
if (argDirs.length < 1) {
|
||||
handleError("Missing argument 'dataSourcePath'");
|
||||
}
|
||||
dataSourcePath = argDirs[0];
|
||||
|
||||
// verify inputs
|
||||
if (dataSourcePath == null || dataSourcePath.isEmpty()) {
|
||||
handleError("Missing argument 'dataSourcePath'");
|
||||
}
|
||||
|
||||
if (!(new File(dataSourcePath).exists())) {
|
||||
handleError("Input data source file " + dataSourcePath + " doesn't exist");
|
||||
}
|
||||
}
|
||||
|
||||
String dataSourceId = "";
|
||||
if (values.containsKey(dataSourceObjectIdOption)) {
|
||||
|
||||
argDirs = values.get(dataSourceObjectIdOption);
|
||||
if (argDirs.length < 1) {
|
||||
handleError("Missing argument 'dataSourceObjectIdOption'");
|
||||
}
|
||||
dataSourceId = argDirs[0];
|
||||
|
||||
// verify inputs
|
||||
if (dataSourceId == null || dataSourceId.isEmpty()) {
|
||||
handleError("Input data source id is empty");
|
||||
}
|
||||
}
|
||||
|
||||
// Create commands in order in which they should be executed:
|
||||
// First create the "CREATE_CASE" command, if present
|
||||
if (values.containsKey(createCaseCommandOption)) {
|
||||
|
||||
// 'caseName' must always be specified for "CREATE_CASE" command
|
||||
if (inputCaseName == null || inputCaseName.isEmpty()) {
|
||||
handleError("'caseName' argument is empty");
|
||||
}
|
||||
|
||||
CommandLineCommand newCommand = new CommandLineCommand(CommandLineCommand.CommandType.CREATE_CASE);
|
||||
newCommand.addInputValue(CommandLineCommand.InputType.CASE_NAME.name(), inputCaseName);
|
||||
newCommand.addInputValue(CommandLineCommand.InputType.CASES_BASE_DIR_PATH.name(), caseBaseDir);
|
||||
newCommand.addInputValue(CommandLineCommand.InputType.CASE_TYPE.name(), caseType);
|
||||
commands.add(newCommand);
|
||||
runFromCommandLine(true);
|
||||
}
|
||||
|
||||
// Add ADD_DATA_SOURCE command, if present
|
||||
if (values.containsKey(addDataSourceCommandOption)) {
|
||||
|
||||
// 'dataSourcePath' must always be specified for "ADD_DATA_SOURCE" command
|
||||
if (dataSourcePath == null || dataSourcePath.isEmpty()) {
|
||||
handleError("'dataSourcePath' argument is empty");
|
||||
}
|
||||
|
||||
CommandLineCommand newCommand = new CommandLineCommand(CommandLineCommand.CommandType.ADD_DATA_SOURCE);
|
||||
newCommand.addInputValue(CommandLineCommand.InputType.CASE_NAME.name(), inputCaseName);
|
||||
newCommand.addInputValue(CommandLineCommand.InputType.CASES_BASE_DIR_PATH.name(), caseBaseDir);
|
||||
newCommand.addInputValue(CommandLineCommand.InputType.DATA_SOURCE_PATH.name(), dataSourcePath);
|
||||
commands.add(newCommand);
|
||||
runFromCommandLine(true);
|
||||
}
|
||||
|
||||
String ingestProfile = "";
|
||||
// Add RUN_INGEST command, if present
|
||||
if (values.containsKey(runIngestCommandOption)) {
|
||||
|
||||
argDirs = values.get(runIngestCommandOption);
|
||||
if(argDirs != null && argDirs.length > 0) {
|
||||
ingestProfile = argDirs[0];
|
||||
}
|
||||
|
||||
// if new data source is being added during this run, then 'dataSourceId' is not specified
|
||||
if (!values.containsKey(addDataSourceCommandOption) && dataSourceId.isEmpty()) {
|
||||
// data source is not being added during this run, so 'dataSourceId' should have been specified
|
||||
handleError("'dataSourceId' argument is empty");
|
||||
}
|
||||
|
||||
CommandLineCommand newCommand = new CommandLineCommand(CommandLineCommand.CommandType.RUN_INGEST);
|
||||
newCommand.addInputValue(CommandLineCommand.InputType.CASE_NAME.name(), inputCaseName);
|
||||
newCommand.addInputValue(CommandLineCommand.InputType.CASES_BASE_DIR_PATH.name(), caseBaseDir);
|
||||
newCommand.addInputValue(CommandLineCommand.InputType.DATA_SOURCE_ID.name(), dataSourceId);
|
||||
newCommand.addInputValue(CommandLineCommand.InputType.INGEST_PROFILE_NAME.name(), ingestProfile);
|
||||
commands.add(newCommand);
|
||||
runFromCommandLine(true);
|
||||
}
|
||||
|
||||
// Add "LIST_ALL_DATA_SOURCES" command, if present
|
||||
if (values.containsKey(listAllDataSourcesCommandOption)) {
|
||||
|
||||
CommandLineCommand newCommand = new CommandLineCommand(CommandLineCommand.CommandType.LIST_ALL_DATA_SOURCES);
|
||||
newCommand.addInputValue(CommandLineCommand.InputType.CASE_NAME.name(), inputCaseName);
|
||||
newCommand.addInputValue(CommandLineCommand.InputType.CASES_BASE_DIR_PATH.name(), caseBaseDir);
|
||||
commands.add(newCommand);
|
||||
runFromCommandLine(true);
|
||||
}
|
||||
|
||||
// Add "GENERATE_REPORTS" command, if present
|
||||
if (values.containsKey(generateReportsOption)) {
|
||||
List<String> reportProfiles;
|
||||
argDirs = values.get(generateReportsOption);
|
||||
if (argDirs.length > 0) {
|
||||
// use custom report configuration(s)
|
||||
reportProfiles = Stream.of(argDirs[0].split(","))
|
||||
.map(String::trim)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (reportProfiles == null || reportProfiles.isEmpty()) {
|
||||
handleError("'generateReports' argument is empty");
|
||||
// verify inputs
|
||||
if (dataSourcePath == null || dataSourcePath.isEmpty()) {
|
||||
handleError("Missing argument 'dataSourcePath'");
|
||||
}
|
||||
|
||||
for (String reportProfile : reportProfiles) {
|
||||
if (reportProfile.isEmpty()) {
|
||||
handleError("Empty report profile name");
|
||||
}
|
||||
CommandLineCommand newCommand = new CommandLineCommand(CommandLineCommand.CommandType.GENERATE_REPORTS);
|
||||
newCommand.addInputValue(CommandLineCommand.InputType.CASE_NAME.name(), inputCaseName);
|
||||
newCommand.addInputValue(CommandLineCommand.InputType.CASES_BASE_DIR_PATH.name(), caseBaseDir);
|
||||
newCommand.addInputValue(CommandLineCommand.InputType.REPORT_PROFILE_NAME.name(), reportProfile);
|
||||
commands.add(newCommand);
|
||||
if (!(new File(dataSourcePath).exists())) {
|
||||
handleError("Input data source file " + dataSourcePath + " doesn't exist");
|
||||
}
|
||||
} else {
|
||||
// use default report configuration
|
||||
CommandLineCommand newCommand = new CommandLineCommand(CommandLineCommand.CommandType.GENERATE_REPORTS);
|
||||
}
|
||||
|
||||
String dataSourceId = "";
|
||||
if (values.containsKey(dataSourceObjectIdOption)) {
|
||||
|
||||
argDirs = values.get(dataSourceObjectIdOption);
|
||||
if (argDirs.length < 1) {
|
||||
handleError("Missing argument 'dataSourceObjectIdOption'");
|
||||
}
|
||||
dataSourceId = argDirs[0];
|
||||
|
||||
// verify inputs
|
||||
if (dataSourceId == null || dataSourceId.isEmpty()) {
|
||||
handleError("Input data source id is empty");
|
||||
}
|
||||
}
|
||||
|
||||
// Create commands in order in which they should be executed:
|
||||
// First create the "CREATE_CASE" command, if present
|
||||
if (values.containsKey(createCaseCommandOption)) {
|
||||
|
||||
// 'caseName' must always be specified for "CREATE_CASE" command
|
||||
if (inputCaseName == null || inputCaseName.isEmpty()) {
|
||||
handleError("'caseName' argument is empty");
|
||||
}
|
||||
|
||||
CommandLineCommand newCommand = new CommandLineCommand(CommandLineCommand.CommandType.CREATE_CASE);
|
||||
newCommand.addInputValue(CommandLineCommand.InputType.CASE_NAME.name(), inputCaseName);
|
||||
newCommand.addInputValue(CommandLineCommand.InputType.CASES_BASE_DIR_PATH.name(), caseBaseDir);
|
||||
newCommand.addInputValue(CommandLineCommand.InputType.CASE_TYPE.name(), caseType);
|
||||
commands.add(newCommand);
|
||||
runFromCommandLine(true);
|
||||
}
|
||||
|
||||
// Add ADD_DATA_SOURCE command, if present
|
||||
if (values.containsKey(addDataSourceCommandOption)) {
|
||||
|
||||
// 'dataSourcePath' must always be specified for "ADD_DATA_SOURCE" command
|
||||
if (dataSourcePath == null || dataSourcePath.isEmpty()) {
|
||||
handleError("'dataSourcePath' argument is empty");
|
||||
}
|
||||
|
||||
CommandLineCommand newCommand = new CommandLineCommand(CommandLineCommand.CommandType.ADD_DATA_SOURCE);
|
||||
newCommand.addInputValue(CommandLineCommand.InputType.CASE_NAME.name(), inputCaseName);
|
||||
newCommand.addInputValue(CommandLineCommand.InputType.CASES_BASE_DIR_PATH.name(), caseBaseDir);
|
||||
newCommand.addInputValue(CommandLineCommand.InputType.DATA_SOURCE_PATH.name(), dataSourcePath);
|
||||
commands.add(newCommand);
|
||||
runFromCommandLine(true);
|
||||
}
|
||||
|
||||
String ingestProfile = "";
|
||||
// Add RUN_INGEST command, if present
|
||||
if (values.containsKey(runIngestCommandOption)) {
|
||||
|
||||
argDirs = values.get(runIngestCommandOption);
|
||||
if(argDirs != null && argDirs.length > 0) {
|
||||
ingestProfile = argDirs[0];
|
||||
}
|
||||
|
||||
// if new data source is being added during this run, then 'dataSourceId' is not specified
|
||||
if (!values.containsKey(addDataSourceCommandOption) && dataSourceId.isEmpty()) {
|
||||
// data source is not being added during this run, so 'dataSourceId' should have been specified
|
||||
handleError("'dataSourceId' argument is empty");
|
||||
}
|
||||
|
||||
CommandLineCommand newCommand = new CommandLineCommand(CommandLineCommand.CommandType.RUN_INGEST);
|
||||
newCommand.addInputValue(CommandLineCommand.InputType.CASE_NAME.name(), inputCaseName);
|
||||
newCommand.addInputValue(CommandLineCommand.InputType.CASES_BASE_DIR_PATH.name(), caseBaseDir);
|
||||
newCommand.addInputValue(CommandLineCommand.InputType.DATA_SOURCE_ID.name(), dataSourceId);
|
||||
newCommand.addInputValue(CommandLineCommand.InputType.INGEST_PROFILE_NAME.name(), ingestProfile);
|
||||
commands.add(newCommand);
|
||||
runFromCommandLine(true);
|
||||
}
|
||||
|
||||
// Add "LIST_ALL_DATA_SOURCES" command, if present
|
||||
if (values.containsKey(listAllDataSourcesCommandOption)) {
|
||||
|
||||
CommandLineCommand newCommand = new CommandLineCommand(CommandLineCommand.CommandType.LIST_ALL_DATA_SOURCES);
|
||||
newCommand.addInputValue(CommandLineCommand.InputType.CASE_NAME.name(), inputCaseName);
|
||||
newCommand.addInputValue(CommandLineCommand.InputType.CASES_BASE_DIR_PATH.name(), caseBaseDir);
|
||||
commands.add(newCommand);
|
||||
}
|
||||
runFromCommandLine(true);
|
||||
}
|
||||
|
||||
runFromCommandLine(true);
|
||||
// Add "GENERATE_REPORTS" command, if present
|
||||
if (values.containsKey(generateReportsOption)) {
|
||||
List<String> reportProfiles;
|
||||
argDirs = values.get(generateReportsOption);
|
||||
if (argDirs.length > 0) {
|
||||
// use custom report configuration(s)
|
||||
reportProfiles = Stream.of(argDirs[0].split(","))
|
||||
.map(String::trim)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (reportProfiles == null || reportProfiles.isEmpty()) {
|
||||
handleError("'generateReports' argument is empty");
|
||||
}
|
||||
|
||||
for (String reportProfile : reportProfiles) {
|
||||
if (reportProfile.isEmpty()) {
|
||||
handleError("Empty report profile name");
|
||||
}
|
||||
CommandLineCommand newCommand = new CommandLineCommand(CommandLineCommand.CommandType.GENERATE_REPORTS);
|
||||
newCommand.addInputValue(CommandLineCommand.InputType.CASE_NAME.name(), inputCaseName);
|
||||
newCommand.addInputValue(CommandLineCommand.InputType.CASES_BASE_DIR_PATH.name(), caseBaseDir);
|
||||
newCommand.addInputValue(CommandLineCommand.InputType.REPORT_PROFILE_NAME.name(), reportProfile);
|
||||
commands.add(newCommand);
|
||||
}
|
||||
} else {
|
||||
// use default report configuration
|
||||
CommandLineCommand newCommand = new CommandLineCommand(CommandLineCommand.CommandType.GENERATE_REPORTS);
|
||||
newCommand.addInputValue(CommandLineCommand.InputType.CASE_NAME.name(), inputCaseName);
|
||||
newCommand.addInputValue(CommandLineCommand.InputType.CASES_BASE_DIR_PATH.name(), caseBaseDir);
|
||||
commands.add(newCommand);
|
||||
}
|
||||
|
||||
runFromCommandLine(true);
|
||||
}
|
||||
}
|
||||
|
||||
setState(ProcessState.COMPLETED);
|
||||
|
Loading…
x
Reference in New Issue
Block a user