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.Collection;
30 import java.util.Collections;
31 import java.util.HashSet;
32 import java.util.List;
34 import java.util.Objects;
35 import java.util.logging.Level;
36 import org.openide.util.NbBundle;
37 import org.openide.util.io.NbObjectInputStream;
38 import org.openide.util.io.NbObjectOutputStream;
57 private static final CharSequence
PYTHON_CLASS_PROXY_PREFIX =
"org.python.proxies.".subSequence(0,
"org.python.proxies.".length() - 1);
61 private final List<String>
warnings =
new ArrayList<>();
116 this.executionContext = executionContext +
"." + this.ingestType.name();
140 this.executionContext = executionContext +
"." + this.ingestType.name();
142 this.moduleTemplates.addAll(moduleTemplates);
191 public void saveAs(String executionContext) {
204 List<String> warningMessages =
new ArrayList<>(this.
warnings);
205 this.warnings.clear();
206 return warningMessages;
228 if (fileFilter == null) {
240 this.fileFilter = fileIngestFilter;
249 return Collections.unmodifiableList(this.moduleTemplates);
258 this.moduleTemplates.clear();
259 this.moduleTemplates.addAll(moduleTemplates);
268 List<IngestModuleTemplate> enabledModuleTemplates =
new ArrayList<>();
270 if (moduleTemplate.isEnabled()) {
271 enabledModuleTemplates.add(moduleTemplate);
274 return enabledModuleTemplates;
284 boolean processUnallocated =
true;
285 if (!Objects.isNull(
this.fileFilter)) {
288 return processUnallocated;
298 Files.createDirectories(folder);
299 this.moduleSettingsFolderPath = folder.toAbsolutePath().toString();
300 }
catch (IOException | SecurityException ex) {
301 logger.log(Level.SEVERE,
"Failed to create ingest module settings directory " +
this.moduleSettingsFolderPath, ex);
302 this.warnings.add(NbBundle.getMessage(
IngestJobSettings.class,
"IngestJobSettings.createModuleSettingsFolder.warning"));
315 List<IngestModuleFactory> moduleFactories =
new ArrayList<>();
316 List<IngestModuleFactory> allModuleFactories = IngestModuleFactoryLoader.getIngestModuleFactories();
317 HashSet<String> loadedModuleNames =
new HashSet<>();
322 moduleFactories.add(moduleFactory);
324 moduleFactories.add(moduleFactory);
325 }
else if (this.ingestType.equals(
IngestType.
FILES_ONLY) && moduleFactory.isFileIngestModuleFactory()) {
326 moduleFactories.add(moduleFactory);
331 loadedModuleNames.add(moduleFactory.getModuleDisplayName());
341 final String plasoModuleName =
"Plaso";
342 boolean plasoLoaded = loadedModuleNames.contains(plasoModuleName);
344 loadedModuleNames.remove(plasoModuleName);
356 if (!enabledModuleNames.contains(plasoModuleName) && !disabledModuleNames.contains(plasoModuleName)) {
357 disabledModuleNames.add(plasoModuleName);
362 loadedModuleNames.add(plasoModuleName);
368 List<String> missingModuleNames =
new ArrayList<>();
369 for (String moduleName : enabledModuleNames) {
370 if (!loadedModuleNames.contains(moduleName)) {
371 missingModuleNames.add(moduleName);
374 for (String moduleName : disabledModuleNames) {
375 if (!loadedModuleNames.contains(moduleName)) {
376 missingModuleNames.add(moduleName);
379 for (String moduleName : missingModuleNames) {
380 enabledModuleNames.remove(moduleName);
381 disabledModuleNames.remove(moduleName);
382 String warning = NbBundle.getMessage(
IngestJobSettings.class,
"IngestJobSettings.missingModule.warning", moduleName);
383 logger.log(Level.WARNING, warning);
384 this.warnings.add(warning);
394 if (enabledModuleNames.contains(moduleName)) {
396 }
else if (disabledModuleNames.contains(moduleName)) {
403 enabledModuleNames.add(moduleName);
405 this.moduleTemplates.add(moduleTemplate);
425 fileIngestFilters.put(fSet.getName(), fSet);
430 logger.log(Level.SEVERE,
"Failed to get file filter from .properties file, default filter being used", ex);
445 private static HashSet<String>
getModulesNames(String executionContext, String propertyName, String defaultSetting) {
449 HashSet<String> moduleNames =
new HashSet<>();
451 if (!modulesSetting.isEmpty()) {
452 String[] settingNames = modulesSetting.split(
", ");
453 for (String name : settingNames) {
459 case "Thunderbird Parser":
461 moduleNames.add(
"Email Parser");
463 case "File Extension Mismatch Detection":
464 moduleNames.add(
"Extension Mismatch Detector");
469 moduleNames.add(
"Data Source Integrity");
471 case "Archive Extractor":
472 moduleNames.add(
"Embedded File Extractor");
474 case "Correlation Engine":
475 moduleNames.add(
"Central Repository");
478 moduleNames.add(
"Picture Analyzer");
481 moduleNames.add(name);
496 static List<String> getEnabledModules(String context) {
497 return new ArrayList<>(
getModulesNames(context, ENABLED_MODULES_PROPERTY,
""));
511 return moduleSettingsFilePath.contains(PYTHON_CLASS_PROXY_PREFIX);
524 File settingsFile =
new File(moduleSettingsFilePath);
525 if (settingsFile.exists()) {
526 try (NbObjectInputStream in =
new NbObjectInputStream(
new FileInputStream(settingsFile.getAbsolutePath()))) {
528 }
catch (IOException | ClassNotFoundException ex) {
530 logger.log(Level.WARNING, warning, ex);
531 this.warnings.add(warning);
534 if (settings == null) {
550 Path path = Paths.get(
this.moduleSettingsFolderPath, fileName);
551 return path.toAbsolutePath().toString();
561 HashSet<String> enabledModuleNames =
new HashSet<>();
562 HashSet<String> disabledModuleNames =
new HashSet<>();
564 saveModuleSettings(moduleTemplate.getModuleFactory(), moduleTemplate.getModuleSettings());
565 String moduleName = moduleTemplate.getModuleName();
566 if (moduleTemplate.isEnabled()) {
567 enabledModuleNames.add(moduleName);
569 disabledModuleNames.add(moduleName);
589 try (NbObjectOutputStream out =
new NbObjectOutputStream(
new FileOutputStream(moduleSettingsFilePath))) {
590 out.writeObject(settings);
591 }
catch (IOException ex) {
593 logger.log(Level.SEVERE, warning, ex);
594 this.warnings.add(warning);
606 private static String
makeCsvList(Collection<String> collection) {
607 if (collection == null || collection.isEmpty()) {
611 ArrayList<String> list =
new ArrayList<>();
612 list.addAll(collection);
613 StringBuilder csvList =
new StringBuilder();
614 for (
int i = 0; i < list.size() - 1; ++i) {
615 csvList.append(list.get(i)).append(
", ");
617 csvList.append(list.get(list.size() - 1));
618 return csvList.toString();
static synchronized String getConfigSetting(String moduleName, String settingName)
static final String DISABLED_MODULES_PROPERTY
IngestJobSettings(final String executionContext)
static final String LAST_FILE_INGEST_FILTER_PROPERTY
static List< FilesSet > getStandardFileIngestFilters()
static final String ENABLED_MODULES_PROPERTY
void saveModuleSettings(IngestModuleFactory factory, IngestModuleIngestJobSettings settings)
final IngestType ingestType
void setEnabled(boolean enabled)
List< IngestModuleTemplate > getEnabledIngestModuleTemplates()
String moduleSettingsFolderPath
static HashSet< String > getModulesNames(String executionContext, String propertyName, String defaultSetting)
String getExecutionContext()
static synchronized FilesSetsManager getInstance()
IngestModuleIngestJobSettings getDefaultIngestJobSettings()
static final String MODULE_SETTINGS_FILE_EXT
Map< String, FilesSet > getCustomFileIngestFilters()
static String makeCsvList(Collection< String > collection)
static final String MODULE_SETTINGS_FOLDER
void setIngestModuleTemplates(List< IngestModuleTemplate > moduleTemplates)
static synchronized boolean settingExists(String moduleName, String settingName)
static final String MODULE_SETTINGS_FOLDER_PATH
final List< IngestModuleTemplate > moduleTemplates
IngestJobSettings(String executionContext, IngestType ingestType, Collection< IngestModuleTemplate > moduleTemplates, FilesSet fileFilter)
static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
void setFileFilter(FilesSet fileIngestFilter)
IngestModuleIngestJobSettings loadModuleSettings(IngestModuleFactory factory)
Path getSavedModuleSettingsFolder()
boolean getProcessUnallocatedSpace()
void createSavedModuleSettingsFolder()
static FilesSet getDefaultFilter()
final List< String > warnings
String getModuleSettingsFilePath(IngestModuleFactory factory)
List< String > getWarnings()
List< IngestModuleTemplate > getIngestModuleTemplates()
static final Logger logger
synchronized static Logger getLogger(String name)
IngestJobSettings(String executionContext, IngestType ingestType, Collection< IngestModuleTemplate > moduleTemplates)
String getModuleDisplayName()
void saveAs(String executionContext)
boolean isPythonModuleSettingsFile(String moduleSettingsFilePath)
boolean ingoresUnallocatedSpace()
static final CharSequence PYTHON_CLASS_PROXY_PREFIX
IngestJobSettings(String executionContext, IngestType ingestType)
static String normalize(String canonicalClassName)