Autopsy  4.19.3
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.io.File;
22 import java.io.FileInputStream;
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.nio.file.Path;
26 import java.nio.file.Paths;
27 import java.util.Map;
28 import java.util.Properties;
29 import java.util.logging.Level;
30 import java.util.stream.Collectors;
31 import org.apache.commons.io.FileUtils;
32 import org.openide.modules.ModuleInstall;
36 
40 public class Installer extends ModuleInstall {
41 
42  private static final String LEGACY_INGEST_SETTINGS_PATH = Paths.get(PlatformUtil.getUserConfigDirectory(), "IngestModuleSettings").toString();
43  private static final String LEGACY_INGEST_PROFILES_PATH = Paths.get(PlatformUtil.getUserConfigDirectory(), "IngestProfiles").toString();
44  private static final String PROPERTIES_EXT = ".properties";
45 
46  private static final Logger logger = Logger.getLogger(Installer.class.getName());
47 
48  private static Installer instance;
49 
50  public synchronized static Installer getDefault() {
51  if (instance == null) {
52  instance = new Installer();
53  }
54  return instance;
55  }
56 
57  private Installer() {
58  super();
59  }
60 
61  @Override
62  public void restored() {
64  // initialize ingest manager
66  }
67 
68  @Override
69  public boolean closing() {
70  //force ingest inbox closed on exit and save state as such
71  IngestMessageTopComponent.findInstance().close();
72  return true;
73  }
74 
75  private void upgradeSettings() {
76  File settingsFolder = new File(IngestJobSettings.getBaseSettingsPath());
77  File legacySettingsFolder = new File(LEGACY_INGEST_SETTINGS_PATH);
78  if (legacySettingsFolder.exists() && !settingsFolder.exists()) {
79  for (File moduleSettingsFolder : legacySettingsFolder.listFiles()) {
80  if (moduleSettingsFolder.isDirectory()) {
81  // get the settings name from the folder name (will be the same for any properties files).
82  String settingsName = moduleSettingsFolder.getName();
83 
84  try {
85  Path configPropsPath = Paths.get(PlatformUtil.getUserConfigDirectory(), settingsName + PROPERTIES_EXT);
86  Path profilePropsPath = Paths.get(LEGACY_INGEST_PROFILES_PATH, settingsName + PROPERTIES_EXT);
87  boolean isProfile = profilePropsPath.toFile().exists();
88 
89  // load properties
90  Properties configProps = loadProps(configPropsPath.toFile());
91 
92  if (isProfile) {
93  configProps.putAll(loadProps(profilePropsPath.toFile()));
94  }
95 
96  Map<String, String> moduleSettingsToSave = configProps.entrySet().stream()
97  .filter(e -> e.getKey() != null)
98  .collect(Collectors.toMap(e -> e.getKey().toString(), e -> e.getValue() == null ? null : e.getValue().toString(), (v1, v2) -> v1));
99 
100  String resourceName = isProfile ? IngestProfiles.getExecutionContext(settingsName) : settingsName;
101  ModuleSettings.setConfigSettings(IngestJobSettings.getModuleSettingsResource(resourceName), moduleSettingsToSave);
102 
103  FileUtils.copyDirectory(moduleSettingsFolder, IngestJobSettings.getSavedModuleSettingsFolder(settingsName).toFile());
104  } catch (IOException ex) {
105  logger.log(Level.WARNING, "There was an error upgrading settings for: " + settingsName, ex);
106  }
107  }
108  }
109  }
110  }
111 
112  private static Properties loadProps(File propFile) throws IOException {
113  Properties props = new Properties();
114  if (propFile.exists()) {
115  try (InputStream inputStream = new FileInputStream(propFile)) {
116  props.load(inputStream);
117  }
118  }
119  return props;
120  }
121 }
static final String LEGACY_INGEST_PROFILES_PATH
Definition: Installer.java:43
static synchronized IngestManager getInstance()
static Properties loadProps(File propFile)
Definition: Installer.java:112
static synchronized void setConfigSettings(String moduleName, Map< String, String > settings)
static final String LEGACY_INGEST_SETTINGS_PATH
Definition: Installer.java:42
static synchronized Installer getDefault()
Definition: Installer.java:50
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2022 Basis Technology. Generated on: Wed Oct 5 2022
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.