Autopsy  4.17.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;
35 
41 public class Installer extends ModuleInstall {
42 
43  private static final Logger logger = Logger.getLogger(Installer.class.getName());
44  private static final long serialVersionUID = 1L;
45  private static Installer instance;
46 
55  public synchronized static Installer getDefault() {
56  if (instance == null) {
57  instance = new Installer();
58  }
59  return instance;
60  }
61 
67  private Installer() {
68  super();
69  }
70 
71  /*
72  * Sets up a default, single-user SQLite central
73  * repository if no central repository is configured.
74  *
75  * Called by the registered Installer for the Autopsy-Core module located in
76  * the org.sleuthkit.autopsy.core package when the already installed
77  * Autopsy-Core module is restored (during application startup).
78  */
79  @Override
80  public void restored() {
82  }
83 
91  Map<String, String> centralRepoSettings = ModuleSettings.getConfigSettings("CentralRepository");
92  String initializedStr = centralRepoSettings.get("initialized");
93 
94  // check to see if the repo has been initialized asking to setup cr
95  boolean initialized = Boolean.parseBoolean(initializedStr);
96 
97  // if it hasn't received that flag, check for a previous install where cr is already setup
98  if (!initialized) {
99  boolean prevRepo = Boolean.parseBoolean(centralRepoSettings.get("db.useCentralRepo"));
100  // if it has been previously set up and is in use, mark as previously initialized and save the settings
101  if (prevRepo) {
102  initialized = true;
103  ModuleSettings.setConfigSetting("CentralRepository", "initialized", "true");
104  }
105  }
106 
107  if(initialized) {
108  return; // Nothing to do
109  }
110 
111  if (CentralRepositoryNotificationDialog.shouldDisplay()) {
113  }
114 
115  try {
118  // Set up using existing multi-user settings.
120  } else {
121  manager.setupDefaultSqliteDb();
122  }
123  } catch (CentralRepoException ex) {
124  logger.log(Level.SEVERE, "There was an error while initializing the central repository database", ex);
125 
127  }
128 
129  ModuleSettings.setConfigSetting("CentralRepository", "initialized", "true");
130  }
131 
138  @NbBundle.Messages({"Installer.centralRepoUpgradeFailed.title=Central repository disabled"})
141  try {
142  SwingUtilities.invokeAndWait(() -> {
143  JOptionPane.showMessageDialog(null,
144  ex.getUserMessage(),
145  NbBundle.getMessage(this.getClass(), "Installer.centralRepoUpgradeFailed.title"),
146  JOptionPane.ERROR_MESSAGE);
147  });
148  } catch (InterruptedException | InvocationTargetException e) {
149  logger.log(Level.WARNING, e.getMessage(), e);
150  }
151  }
152  }
153 
154  @Override
155  public void uninstalled() {
156  /*
157  * TODO (Jira-6108): This code is erronoeous. As documented at
158  * http://bits.netbeans.org/dev/javadoc/org-openide-modules/org/openide/modules/ModuleInstall.html#uninstalled--
159  *
160  * "Called when the module is disabled while the application is still
161  * running. Should remove whatever functionality that it had registered
162  * in ModuleInstall.restored().
163  *
164  * Beware: in practice there is no way to
165  * ensure that this method will really be called. The module might
166  * simply be deleted or disabled while the application is not running.
167  * In fact this is always the case in NetBeans 6.0; the Plugin Manager
168  * only uninstalls or disables modules between restarts. This method
169  * will still be called if you reload a module during development."
170  *
171  * THIS CODE IS NEVER EXECUTED.
172  */
173  }
174 }
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-2021 Basis Technology. Generated on: Tue Jan 19 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.