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;
33 import java.util.Objects;
34 import java.util.logging.Level;
35 import org.openide.util.NbBundle;
36 import org.openide.util.io.NbObjectInputStream;
37 import org.openide.util.io.NbObjectOutputStream;
38 import org.python.util.PythonObjectInputStream;
76 if (fileIngestFilter == null) {
88 void setFileIngestFilter(
FilesSet fileIngestFilter) {
122 this.moduleTemplates =
new ArrayList<>();
123 this.warnings =
new ArrayList<>();
141 this.executionContext = context;
143 this.executionContext = context +
"." + this.ingestType.name();
146 this.moduleTemplates =
new ArrayList<>();
148 this.warnings =
new ArrayList<>();
167 void saveAs(String executionContext) {
181 String getExecutionContext() {
192 List<String> warningMessages =
new ArrayList<>(this.
warnings);
193 this.warnings.clear();
194 return warningMessages;
202 List<IngestModuleTemplate> getIngestModuleTemplates() {
203 return Collections.unmodifiableList(this.moduleTemplates);
212 List<IngestModuleTemplate> getEnabledIngestModuleTemplates() {
213 List<IngestModuleTemplate> enabledModuleTemplates =
new ArrayList<>();
214 for (IngestModuleTemplate moduleTemplate : this.moduleTemplates) {
215 if (moduleTemplate.isEnabled()) {
216 enabledModuleTemplates.add(moduleTemplate);
219 return enabledModuleTemplates;
227 void setIngestModuleTemplates(List<IngestModuleTemplate> moduleTemplates) {
228 this.moduleTemplates.clear();
229 this.moduleTemplates.addAll(moduleTemplates);
239 boolean getProcessUnallocatedSpace() {
246 boolean processUnallocated =
true;
247 if (!Objects.isNull(
this.fileIngestFilter)) {
250 return processUnallocated;
281 Files.createDirectories(folder);
282 this.moduleSettingsFolderPath = folder.toAbsolutePath().toString();
283 }
catch (IOException | SecurityException ex) {
284 LOGGER.log(Level.SEVERE,
"Failed to create ingest module settings directory " +
this.moduleSettingsFolderPath, ex);
285 this.warnings.add(NbBundle.getMessage(
IngestJobSettings.class,
"IngestJobSettings.createModuleSettingsFolder.warning"));
297 List<IngestModuleFactory> moduleFactories =
new ArrayList<>();
298 List<IngestModuleFactory> allModuleFactories = IngestModuleFactoryLoader.getIngestModuleFactories();
299 HashSet<String> loadedModuleNames =
new HashSet<>();
304 moduleFactories.add(moduleFactory);
306 moduleFactories.add(moduleFactory);
307 }
else if (this.ingestType.equals(
IngestType.
FILES_ONLY) && moduleFactory.isFileIngestModuleFactory()) {
308 moduleFactories.add(moduleFactory);
313 loadedModuleNames.add(moduleFactory.getModuleDisplayName());
326 List<String> missingModuleNames =
new ArrayList<>();
327 for (String moduleName : enabledModuleNames) {
328 if (!loadedModuleNames.contains(moduleName)) {
329 missingModuleNames.add(moduleName);
332 for (String moduleName : disabledModuleNames) {
333 if (!loadedModuleNames.contains(moduleName)) {
334 missingModuleNames.add(moduleName);
337 for (String moduleName : missingModuleNames) {
338 enabledModuleNames.remove(moduleName);
339 disabledModuleNames.remove(moduleName);
340 String warning = NbBundle.getMessage(
IngestJobSettings.class,
"IngestJobSettings.missingModule.warning", moduleName);
341 LOGGER.log(Level.WARNING, warning);
342 this.warnings.add(warning);
350 IngestModuleTemplate moduleTemplate =
new IngestModuleTemplate(moduleFactory,
loadModuleSettings(moduleFactory));
351 String moduleName = moduleTemplate.getModuleName();
352 if (enabledModuleNames.contains(moduleName)) {
353 moduleTemplate.setEnabled(
true);
354 }
else if (disabledModuleNames.contains(moduleName)) {
355 moduleTemplate.setEnabled(
false);
360 moduleTemplate.setEnabled(
true);
361 enabledModuleNames.add(moduleName);
363 this.moduleTemplates.add(moduleTemplate);
383 fileIngestFilters.put(fSet.getName(), fSet);
389 LOGGER.log(Level.SEVERE,
"Failed to get file ingest filter from .properties file, default filter being used", ex);
405 HashSet<String> moduleNames =
new HashSet<>();
407 if (!modulesSetting.isEmpty()) {
408 String[] settingNames = modulesSetting.split(
", ");
409 for (String name : settingNames) {
412 case "Thunderbird Parser":
414 moduleNames.add(
"Email Parser");
416 case "File Extension Mismatch Detection":
417 moduleNames.add(
"Extension Mismatch Detector");
421 moduleNames.add(
"E01 Verifier");
423 case "Archive Extractor":
424 moduleNames.add(
"Embedded File Extractor");
427 moduleNames.add(name);
442 static List<String> getEnabledModules(String context) {
457 return moduleSettingsFilePath.contains(pythonModuleSettingsPrefixCS);
471 File settingsFile =
new File(moduleSettingsFilePath);
472 if (settingsFile.
exists()) {
474 try (NbObjectInputStream in =
new NbObjectInputStream(
new FileInputStream(settingsFile.getAbsolutePath()))) {
476 }
catch (IOException | ClassNotFoundException ex) {
478 LOGGER.log(Level.WARNING, warning, ex);
479 this.warnings.add(warning);
482 try (PythonObjectInputStream in =
new PythonObjectInputStream(
new FileInputStream(settingsFile.getAbsolutePath()))) {
484 }
catch (IOException | ClassNotFoundException exception) {
486 LOGGER.log(Level.WARNING, warning, exception);
487 this.warnings.add(warning);
491 if (settings == null) {
507 Path path = Paths.get(this.moduleSettingsFolderPath, fileName);
508 return path.toAbsolutePath().toString();
518 HashSet<String> enabledModuleNames =
new HashSet<>();
519 HashSet<String> disabledModuleNames =
new HashSet<>();
520 for (IngestModuleTemplate moduleTemplate : moduleTemplates) {
521 saveModuleSettings(moduleTemplate.getModuleFactory(), moduleTemplate.getModuleSettings());
522 String moduleName = moduleTemplate.getModuleName();
523 if (moduleTemplate.isEnabled()) {
524 enabledModuleNames.add(moduleName);
526 disabledModuleNames.add(moduleName);
546 String moduleSettingsFilePath = Paths.get(this.moduleSettingsFolderPath, FactoryClassNameNormalizer.normalize(factory.getClass().getCanonicalName()) + MODULE_SETTINGS_FILE_EXT).toString();
547 try (NbObjectOutputStream out =
new NbObjectOutputStream(
new FileOutputStream(moduleSettingsFilePath))) {
548 out.writeObject(settings);
549 }
catch (IOException ex) {
551 LOGGER.log(Level.SEVERE, warning, ex);
552 this.warnings.add(warning);
565 if (input == null || input.isEmpty()) {
569 ArrayList<String> list =
new ArrayList<>();
571 StringBuilder csvList =
new StringBuilder();
572 for (
int i = 0; i < list.size() - 1; ++i) {
573 csvList.append(list.get(i)).append(
", ");
575 csvList.append(list.get(list.size() - 1));
576 return csvList.toString();
static final String DISABLED_MODULES_KEY
static List< FilesSet > getStandardFileIngestFilters()
void saveModuleSettings(IngestModuleFactory factory, IngestModuleIngestJobSettings settings)
final IngestType ingestType
static final Logger LOGGER
String moduleSettingsFolderPath
static synchronized FilesSetsManager getInstance()
static String makeCommaSeparatedValuesList(HashSet< String > input)
IngestModuleIngestJobSettings getDefaultIngestJobSettings()
static final String MODULE_SETTINGS_FILE_EXT
Map< String, FilesSet > getCustomFileIngestFilters()
static final String MODULE_SETTINGS_FOLDER
FilesSet fileIngestFilter
static final String MODULE_SETTINGS_FOLDER_PATH
final List< IngestModuleTemplate > moduleTemplates
static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
IngestModuleIngestJobSettings loadModuleSettings(IngestModuleFactory factory)
Path getSavedModuleSettingsFolder()
void createSavedModuleSettingsFolder()
static FilesSet getDefaultFilter()
final List< String > warnings
IngestJobSettings(String executionContext)
static HashSet< String > getModulesNamesFromSetting(String context, String key, String defaultSetting)
String getModuleSettingsFilePath(IngestModuleFactory factory)
static String getConfigSetting(String moduleName, String settingName)
List< String > getWarnings()
static final String ENABLED_MODULES_KEY
synchronized static Logger getLogger(String name)
String getModuleDisplayName()
static final String LAST_FILE_INGEST_FILTER_KEY
static final CharSequence pythonModuleSettingsPrefixCS
boolean isPythonModuleSettingsFile(String moduleSettingsFilePath)
boolean ingoresUnallocatedSpace()
static boolean settingExists(String moduleName, String settingName)
IngestJobSettings(String context, IngestType ingestType)