Autopsy  4.16.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 2017-2020 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.centralrepository.eventlisteners;
20 
21 import java.lang.reflect.InvocationTargetException;
22 import java.util.Map;
23 import java.util.logging.Level;
24 import javax.swing.JOptionPane;
25 import javax.swing.SwingUtilities;
26 import org.openide.modules.ModuleInstall;
27 import org.openide.util.NbBundle;
28 import org.openide.windows.WindowManager;
36 
43 public class Installer extends ModuleInstall {
44 
45  private static final Logger logger = Logger.getLogger(Installer.class.getName());
46  private static final long serialVersionUID = 1L;
47  private static Installer instance;
48  private final CaseEventListener caseEventListener = new CaseEventListener();
50 
59  public synchronized static Installer getDefault() {
60  if (instance == null) {
61  instance = new Installer();
62  }
63  return instance;
64  }
65 
71  private Installer() {
72  super();
73  }
74 
75  /*
76  * Adds/removes application event listeners responsible for adding data to
77  * the central repository and sets up a default, single-user SQLite central
78  * repository if no central repository is configured.
79  *
80  * Called by the registered Installer for the Autopsy-Core module located in
81  * the org.sleuthkit.autopsy.core package when the already installed
82  * Autopsy-Core module is restored (during application startup).
83  */
84  @NbBundle.Messages({
85  "Installer.initialCreateSqlite.title=Enable Central Repository?",
86  "Installer.initialCreateSqlite.messageHeader=The Central Repository is not enabled. Would you like to enable it?",
87  "Installer.initialCreateSqlite.messageDesc=It will store information about all hashes and identifiers that you process. "
88  + "You can use this to ignore previously seen files and make connections between cases."
89  })
90  @Override
91  public void restored() {
93 
96  }
97  }
98 
104  caseEventListener.installListeners();
105  ingestEventListener.installListeners();
106  }
107 
115  Map<String, String> centralRepoSettings = ModuleSettings.getConfigSettings("CentralRepository");
116  String initializedStr = centralRepoSettings.get("initialized");
117 
118  // check to see if the repo has been initialized asking to setup cr
119  boolean initialized = Boolean.parseBoolean(initializedStr);
120 
121  // if it hasn't received that flag, check for a previous install where cr is already setup
122  if (!initialized) {
123  boolean prevRepo = Boolean.parseBoolean(centralRepoSettings.get("db.useCentralRepo"));
124  // if it has been previously set up and is in use, mark as previously initialized and save the settings
125  if (prevRepo) {
126  initialized = true;
127  ModuleSettings.setConfigSetting("CentralRepository", "initialized", "true");
128  }
129  }
130 
131  // if central repository hasn't been previously initialized, initialize it
132  if (!initialized) {
133  // if running with a GUI, prompt the user
135  try {
136  SwingUtilities.invokeAndWait(() -> {
137  try {
138  String dialogText
139  = "<html><body>"
140  + "<div style='width: 400px;'>"
141  + "<p>" + NbBundle.getMessage(this.getClass(), "Installer.initialCreateSqlite.messageHeader") + "</p>"
142  + "<p style='margin-top: 10px'>" + NbBundle.getMessage(this.getClass(), "Installer.initialCreateSqlite.messageDesc") + "</p>"
143  + "</div>"
144  + "</body></html>";
145 
146  if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(WindowManager.getDefault().getMainWindow(),
147  dialogText,
148  NbBundle.getMessage(this.getClass(), "Installer.initialCreateSqlite.title"),
149  JOptionPane.YES_NO_OPTION)) {
150 
152  }
153  } catch (CentralRepoException ex) {
154  logger.log(Level.SEVERE, "There was an error while initializing the central repository database", ex);
155 
157  }
158  });
159  } catch (InterruptedException | InvocationTargetException ex) {
160  logger.log(Level.SEVERE, "There was an error while running the swing utility invoke later while creating the central repository database", ex);
161  }
162  } // if no GUI, just initialize
163  else {
164  try {
166  } catch (CentralRepoException ex) {
167  logger.log(Level.SEVERE, "There was an error while initializing the central repository database", ex);
168 
170  }
171  }
172 
173  ModuleSettings.setConfigSetting("CentralRepository", "initialized", "true");
174  }
175  }
176 
185  manager.setupDefaultSqliteDb();
186  }
187 
194  @NbBundle.Messages({"Installer.centralRepoUpgradeFailed.title=Central repository disabled"})
197  try {
198  SwingUtilities.invokeAndWait(() -> {
199  JOptionPane.showMessageDialog(null,
200  ex.getUserMessage(),
201  NbBundle.getMessage(this.getClass(), "Installer.centralRepoUpgradeFailed.title"),
202  JOptionPane.ERROR_MESSAGE);
203  });
204  } catch (InterruptedException | InvocationTargetException e) {
205  logger.log(Level.WARNING, e.getMessage(), e);
206  }
207  }
208  }
209 
210  @Override
211  public void uninstalled() {
212  /*
213  * TODO (Jira-6108): This code is erronoeous. As documented at
214  * http://bits.netbeans.org/dev/javadoc/org-openide-modules/org/openide/modules/ModuleInstall.html#uninstalled--
215  *
216  * "Called when the module is disabled while the application is still
217  * running. Should remove whatever functionality that it had registered
218  * in ModuleInstall.restored().
219  *
220  * Beware: in practice there is no way to
221  * ensure that this method will really be called. The module might
222  * simply be deleted or disabled while the application is not running.
223  * In fact this is always the case in NetBeans 6.0; the Plugin Manager
224  * only uninstalls or disables modules between restarts. This method
225  * will still be called if you reload a module during development."
226  *
227  * THIS CODE IS NEVER EXECUTED.
228  */
229  caseEventListener.uninstallListeners();
230  caseEventListener.shutdown();
231  ingestEventListener.shutdown();
232  ingestEventListener.uninstallListeners();
233  }
234 }
static Version.Type getBuildType()
Definition: Version.java:87
static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static synchronized Map< String, String > getConfigSettings(String moduleName)

Copyright © 2012-2020 Basis Technology. Generated on: Tue Sep 22 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.