Autopsy  4.22.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
Installer.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2021 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.ingest;
20 
21 import java.awt.GraphicsEnvironment;
22 import java.io.File;
23 import java.io.FileInputStream;
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.nio.file.Path;
27 import java.nio.file.Paths;
28 import java.util.Map;
29 import java.util.Properties;
30 import java.util.logging.Level;
31 import java.util.stream.Collectors;
32 import org.apache.commons.io.FileUtils;
33 import org.openide.modules.ModuleInstall;
37 
41 public class Installer extends ModuleInstall {
42 
43  private static final String LEGACY_INGEST_SETTINGS_PATH = Paths.get(PlatformUtil.getUserConfigDirectory(), "IngestModuleSettings").toString();
44  private static final String LEGACY_INGEST_PROFILES_PATH = Paths.get(PlatformUtil.getUserConfigDirectory(), "IngestProfiles").toString();
45  private static final String PROPERTIES_EXT = ".properties";
46 
47  private static final Logger logger = Logger.getLogger(Installer.class.getName());
48 
49  private static Installer instance;
50 
51  public synchronized static Installer getDefault() {
52  if (instance == null) {
53  instance = new Installer();
54  }
55  return instance;
56  }
57 
58  private Installer() {
59  super();
60  }
61 
62  @Override
63  public void restored() {
65  // initialize ingest manager
67  }
68 
69  @Override
70  public boolean closing() {
71  //force ingest inbox closed on exit and save state as such
72  if (!GraphicsEnvironment.isHeadless()) {
73  IngestMessageTopComponent.findInstance().close();
74  }
75  return true;
76  }
77 
78  private void upgradeSettings() {
79  File settingsFolder = new File(IngestJobSettings.getBaseSettingsPath());
80  File legacySettingsFolder = new File(LEGACY_INGEST_SETTINGS_PATH);
81  if (legacySettingsFolder.exists() && !settingsFolder.exists()) {
82  for (File moduleSettingsFolder : legacySettingsFolder.listFiles()) {
83  if (moduleSettingsFolder.isDirectory()) {
84  // get the settings name from the folder name (will be the same for any properties files).
85  String settingsName = moduleSettingsFolder.getName();
86 
87  try {
88  Path configPropsPath = Paths.get(PlatformUtil.getUserConfigDirectory(), settingsName + PROPERTIES_EXT);
89  Path profilePropsPath = Paths.get(LEGACY_INGEST_PROFILES_PATH, settingsName + PROPERTIES_EXT);
90  boolean isProfile = profilePropsPath.toFile().exists();
91 
92  // load properties
93  Properties configProps = loadProps(configPropsPath.toFile());
94 
95  if (isProfile) {
96  configProps.putAll(loadProps(profilePropsPath.toFile()));
97  }
98 
99  Map<String, String> moduleSettingsToSave = configProps.entrySet().stream()
100  .filter(e -> e.getKey() != null)
101  .collect(Collectors.toMap(e -> e.getKey().toString(), e -> e.getValue() == null ? null : e.getValue().toString(), (v1, v2) -> v1));
102 
103  String resourceName = isProfile ? IngestProfiles.getExecutionContext(settingsName) : settingsName;
104  ModuleSettings.setConfigSettings(IngestJobSettings.getModuleSettingsResource(resourceName), moduleSettingsToSave);
105 
106  FileUtils.copyDirectory(moduleSettingsFolder, IngestJobSettings.getSavedModuleSettingsFolder(settingsName).toFile());
107  } catch (IOException ex) {
108  logger.log(Level.WARNING, "There was an error upgrading settings for: " + settingsName, ex);
109  }
110  }
111  }
112  }
113  }
114 
115  private static Properties loadProps(File propFile) throws IOException {
116  Properties props = new Properties();
117  if (propFile.exists()) {
118  try (InputStream inputStream = new FileInputStream(propFile)) {
119  props.load(inputStream);
120  }
121  }
122  return props;
123  }
124 }
static final String LEGACY_INGEST_PROFILES_PATH
Definition: Installer.java:44
static synchronized IngestManager getInstance()
static Properties loadProps(File propFile)
Definition: Installer.java:115
static synchronized void setConfigSettings(String moduleName, Map< String, String > settings)
static final String LEGACY_INGEST_SETTINGS_PATH
Definition: Installer.java:43
static synchronized Installer getDefault()
Definition: Installer.java:51
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2024 Sleuth Kit Labs. Generated on: Mon Mar 17 2025
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.