19 package org.sleuthkit.autopsy.ingest;
22 import java.io.FileInputStream;
23 import java.io.FileOutputStream;
24 import java.io.IOException;
25 import java.nio.file.Files;
26 import java.nio.file.Path;
27 import java.nio.file.Paths;
28 import java.util.ArrayList;
29 import java.util.Collections;
30 import java.util.HashSet;
31 import java.util.List;
32 import java.util.logging.Level;
33 import org.openide.util.NbBundle;
34 import org.openide.util.io.NbObjectInputStream;
35 import org.openide.util.io.NbObjectOutputStream;
39 import org.python.util.PythonObjectInputStream;
69 this.moduleTemplates =
new ArrayList<>();
71 this.warnings =
new ArrayList<>();
90 List<String> warningMessages =
new ArrayList<>(this.
warnings);
91 this.warnings.clear();
92 return warningMessages;
100 List<IngestModuleTemplate> getIngestModuleTemplates() {
101 return Collections.unmodifiableList(this.moduleTemplates);
110 List<IngestModuleTemplate> getEnabledIngestModuleTemplates() {
111 List<IngestModuleTemplate> enabledModuleTemplates =
new ArrayList<>();
112 for (IngestModuleTemplate moduleTemplate : this.moduleTemplates) {
113 if (moduleTemplate.isEnabled()) {
114 enabledModuleTemplates.add(moduleTemplate);
117 return enabledModuleTemplates;
125 void setIngestModuleTemplates(List<IngestModuleTemplate> moduleTemplates) {
126 this.moduleTemplates.clear();
127 this.moduleTemplates.addAll(moduleTemplates);
136 boolean getProcessUnallocatedSpace() {
145 void setProcessUnallocatedSpace(
boolean processUnallocatedSpace) {
156 Files.createDirectories(folder);
157 this.moduleSettingsFolderPath = folder.toAbsolutePath().toString();
158 }
catch (IOException | SecurityException ex) {
159 logger.log(Level.SEVERE,
"Failed to create ingest module settings directory " +
this.moduleSettingsFolderPath, ex);
160 this.warnings.add(NbBundle.getMessage(
IngestJobSettings.class,
"IngestJobSettings.createModuleSettingsFolder.warning"));
172 List<IngestModuleFactory> moduleFactories = IngestModuleFactoryLoader.getIngestModuleFactories();
173 HashSet<String> loadedModuleNames =
new HashSet<>();
175 loadedModuleNames.add(moduleFactory.getModuleDisplayName());
188 List<String> missingModuleNames =
new ArrayList<>();
189 for (String moduleName : enabledModuleNames) {
190 if (!loadedModuleNames.contains(moduleName)) {
191 missingModuleNames.add(moduleName);
194 for (String moduleName : disabledModuleNames) {
195 if (!loadedModuleNames.contains(moduleName)) {
196 missingModuleNames.add(moduleName);
199 for (String moduleName : missingModuleNames) {
200 enabledModuleNames.remove(moduleName);
201 disabledModuleNames.remove(moduleName);
202 String warning = NbBundle.getMessage(
IngestJobSettings.class,
"IngestJobSettings.missingModule.warning", moduleName);
203 logger.log(Level.WARNING, warning);
204 this.warnings.add(warning);
212 IngestModuleTemplate moduleTemplate =
new IngestModuleTemplate(moduleFactory,
loadModuleSettings(moduleFactory));
213 String moduleName = moduleTemplate.getModuleName();
214 if (enabledModuleNames.contains(moduleName)) {
215 moduleTemplate.setEnabled(
true);
216 }
else if (disabledModuleNames.contains(moduleName)) {
217 moduleTemplate.setEnabled(
false);
222 moduleTemplate.setEnabled(
true);
223 enabledModuleNames.add(moduleName);
225 this.moduleTemplates.add(moduleTemplate);
254 HashSet<String> moduleNames =
new HashSet<>();
256 if (!modulesSetting.isEmpty()) {
257 String[] settingNames = modulesSetting.split(
", ");
258 for (String name : settingNames) {
261 case "Thunderbird Parser":
263 moduleNames.add(
"Email Parser");
265 case "File Extension Mismatch Detection":
266 moduleNames.add(
"Extension Mismatch Detector");
270 moduleNames.add(
"E01 Verifier");
272 case "Archive Extractor":
273 moduleNames.add(
"Embedded File Extractor");
276 moduleNames.add(name);
291 return moduleSettingsFilePath.contains(pythonModuleSettingsPrefixCS);
304 File settingsFile =
new File(moduleSettingsFilePath);
305 if (settingsFile.
exists()) {
307 try (NbObjectInputStream in =
new NbObjectInputStream(
new FileInputStream(settingsFile.getAbsolutePath()))) {
309 }
catch (IOException | ClassNotFoundException ex) {
311 logger.log(Level.WARNING, warning, ex);
312 this.warnings.add(warning);
315 try (PythonObjectInputStream in =
new PythonObjectInputStream(
new FileInputStream(settingsFile.getAbsolutePath()))) {
317 }
catch (IOException | ClassNotFoundException exception) {
319 logger.log(Level.WARNING, warning, exception);
320 this.warnings.add(warning);
324 if (settings == null) {
339 Path path = Paths.get(this.moduleSettingsFolderPath, fileName);
340 return path.toAbsolutePath().toString();
350 HashSet<String> enabledModuleNames =
new HashSet<>();
351 HashSet<String> disabledModuleNames =
new HashSet<>();
352 for (IngestModuleTemplate moduleTemplate : moduleTemplates) {
353 saveModuleSettings(moduleTemplate.getModuleFactory(), moduleTemplate.getModuleSettings());
354 String moduleName = moduleTemplate.getModuleName();
355 if (moduleTemplate.isEnabled()) {
356 enabledModuleNames.add(moduleName);
358 disabledModuleNames.add(moduleName);
367 String processUnalloc = Boolean.toString(this.processUnallocatedSpace);
385 moduleSettingsFilePath.replaceAll(
"[$][\\d]+.settings$",
"\\$.settings");
387 try (NbObjectOutputStream out =
new NbObjectOutputStream(
new FileOutputStream(moduleSettingsFilePath))) {
388 out.writeObject(settings);
390 }
catch (IOException ex) {
392 logger.log(Level.SEVERE, warning, ex);
393 this.warnings.add(warning);
405 if (input == null || input.isEmpty()) {
409 ArrayList<String> list =
new ArrayList<>();
411 StringBuilder csvList =
new StringBuilder();
412 for (
int i = 0; i < list.size() - 1; ++i) {
413 csvList.append(list.get(i)).append(
", ");
415 csvList.append(list.get(list.size() - 1));
416 return csvList.toString();
static final String DISABLED_MODULES_KEY
void saveModuleSettings(IngestModuleFactory factory, IngestModuleIngestJobSettings settings)
boolean processUnallocatedSpace
String moduleSettingsFolderPath
static String makeCommaSeparatedValuesList(HashSet< String > input)
IngestModuleIngestJobSettings getDefaultIngestJobSettings()
static final String MODULE_SETTINGS_FILE_EXT
static final String PARSE_UNALLOC_SPACE_KEY
HashSet< String > getModulesNamesFromSetting(String key, String defaultSetting)
static final String MODULE_SETTINGS_FOLDER
IngestJobSettings(String context)
static final String MODULE_SETTINGS_FOLDER_PATH
final List< IngestModuleTemplate > moduleTemplates
static final String PROCESS_UNALLOC_SPACE_DEFAULT
static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
IngestModuleIngestJobSettings loadModuleSettings(IngestModuleFactory factory)
void createSavedModuleSettingsFolder()
final List< String > warnings
String getModuleSettingsFilePath(IngestModuleFactory factory)
static String getConfigSetting(String moduleName, String settingName)
List< String > getWarnings()
static final String ENABLED_MODULES_KEY
static final Logger logger
String getModuleDisplayName()
static final CharSequence pythonModuleSettingsPrefixCS
boolean isPythonModuleSettingsFile(String moduleSettingsFilePath)
static boolean settingExists(String moduleName, String settingName)
static Logger getLogger(String name)