Autopsy  4.19.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
StartupWindowProvider.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013-2019 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.casemodule;
20 
21 import java.io.File;
22 import java.io.IOException;
23 import java.nio.charset.Charset;
24 import java.util.Collection;
25 import java.util.Iterator;
26 import java.util.logging.Level;
27 import javax.swing.SwingUtilities;
28 import org.apache.commons.io.FileUtils;
29 import org.apache.commons.lang3.StringUtils;
30 import org.openide.util.Lookup;
31 import org.openide.util.NbBundle;
41 
52 
53  private static volatile StartupWindowProvider instance;
54  private static final Logger logger = Logger.getLogger(StartupWindowProvider.class.getName());
56 
58  if (instance == null) {
59  synchronized (StartupWindowProvider.class) {
60  if (instance == null) {
61  instance = new StartupWindowProvider();
62  instance.init();
63  }
64  }
65  }
66 
67  return instance;
68  }
69 
70  @NbBundle.Messages({
71  "# {0} - autFilePath",
72  "StartupWindowProvider.openCase.noFile=Unable to open previously open case because metadata file not found at: {0}",
73  "# {0} - reOpenFilePath",
74  "StartupWindowProvider.openCase.deleteOpenFailure=Unable to open or delete file containing path {0} to previously open case. The previous case will not be opened.",
75  "# {0} - autFilePath",
76  "StartupWindowProvider.openCase.cantOpen=Unable to open previously open case with metadata file: {0}"})
77  private void init() {
78  if (startupWindowToUse == null) {
79  // first check whether we are running from command line
81 
82  String defaultArg = getDefaultArgument();
83  if (defaultArg != null) {
84  new CommandLineOpenCaseManager(defaultArg).start();
85  return;
86  } else {
87  // Autopsy is running from command line
88  logger.log(Level.INFO, "Running from command line"); //NON-NLS
89  startupWindowToUse = new CommandLineStartupWindow();
90  // kick off command line processing
92  return;
93  }
94  }
95 
97  checkSolr();
98  }
99  //discover the registered windows
100  Collection<? extends StartupWindowInterface> startupWindows
101  = Lookup.getDefault().lookupAll(StartupWindowInterface.class);
102 
103  int windowsCount = startupWindows.size();
104  switch (windowsCount) {
105  case 1:
106  startupWindowToUse = startupWindows.iterator().next();
107  logger.log(Level.INFO, "Will use the default startup window: {0}", startupWindowToUse.toString()); //NON-NLS
108  break;
109  case 2: {
110  //pick the non default one
111  Iterator<? extends StartupWindowInterface> it = startupWindows.iterator();
112  while (it.hasNext()) {
113  StartupWindowInterface window = it.next();
114  if (!org.sleuthkit.autopsy.casemodule.StartupWindow.class.isInstance(window)) {
115  startupWindowToUse = window;
116  logger.log(Level.INFO, "Will use the custom startup window: {0}", startupWindowToUse.toString()); //NON-NLS
117  break;
118  }
119  }
120  break;
121  }
122  default: {
123  // select first non-Autopsy start up window
124  Iterator<? extends StartupWindowInterface> it = startupWindows.iterator();
125  while (it.hasNext()) {
126  StartupWindowInterface window = it.next();
127  if (!window.getClass().getCanonicalName().startsWith("org.sleuthkit.autopsy")) {
128  startupWindowToUse = window;
129  logger.log(Level.INFO, "Will use the custom startup window: {0}", startupWindowToUse.toString()); //NON-NLS
130  break;
131  }
132  }
133  break;
134  }
135  }
136 
137  if (startupWindowToUse == null) {
138  logger.log(Level.SEVERE, "Unexpected error, no startup window chosen, using the default"); //NON-NLS
139  startupWindowToUse = new org.sleuthkit.autopsy.casemodule.StartupWindow();
140  }
141  }
142  File openPreviousCaseFile = new File(ResetWindowsAction.getCaseToReopenFilePath());
143 
144  if (openPreviousCaseFile.exists()) {
145  //do actual opening on another thread
146  new Thread(() -> {
147  String caseFilePath = "";
148  String unableToOpenMessage = null;
149  try {
150  //avoid readFileToString having ambiguous arguments
151  Charset encoding = null;
152  caseFilePath = FileUtils.readFileToString(openPreviousCaseFile, encoding);
153  if (new File(caseFilePath).exists()) {
154  FileUtils.forceDelete(openPreviousCaseFile);
155  //close the startup window as we attempt to open the case
156  close();
157  Case.openAsCurrentCase(caseFilePath);
158 
159  } else {
160  unableToOpenMessage = Bundle.StartupWindowProvider_openCase_noFile(caseFilePath);
161  logger.log(Level.WARNING, unableToOpenMessage);
162  }
163  } catch (IOException ex) {
164  unableToOpenMessage = Bundle.StartupWindowProvider_openCase_deleteOpenFailure(ResetWindowsAction.getCaseToReopenFilePath());
165  logger.log(Level.WARNING, unableToOpenMessage, ex);
166  } catch (CaseActionException ex) {
167  unableToOpenMessage = Bundle.StartupWindowProvider_openCase_cantOpen(caseFilePath);
168  logger.log(Level.WARNING, unableToOpenMessage, ex);
169  }
170 
171  if (RuntimeProperties.runningWithGUI() && !StringUtils.isBlank(unableToOpenMessage)) {
172  final String message = unableToOpenMessage;
173  SwingUtilities.invokeLater(() -> {
174  MessageNotifyUtil.Message.warn(message);
175  //the case was not opened restore the startup window
176  open();
177  });
178  }
179  }).start();
180  }
181  }
182 
183  private void checkSolr() {
184 
185  // if Multi-User settings are enabled and Solr8 server is not configured,
186  // display an error message and a dialog
188  // Solr 8 host name is not configured. This could be the first time user
189  // runs Autopsy with Solr 8. Display a message.
190  MessageNotifyUtil.Notify.error(NbBundle.getMessage(CueBannerPanel.class, "SolrNotConfiguredDialog.title"),
191  NbBundle.getMessage(SolrNotConfiguredDialog.class, "SolrNotConfiguredDialog.EmptyKeywordSearchHostName"));
192 
193  SolrNotConfiguredDialog dialog = new SolrNotConfiguredDialog();
194  dialog.setVisible(true);
195  }
196  }
197 
206  private boolean isRunningFromCommandLine() {
207 
208  CommandLineOptionProcessor processor = Lookup.getDefault().lookup(CommandLineOptionProcessor.class);
209  if (processor != null) {
210  return processor.isRunFromCommandLine();
211  }
212  return false;
213  }
214 
220  private String getDefaultArgument() {
221  CommandLineOptionProcessor processor = Lookup.getDefault().lookup(CommandLineOptionProcessor.class);
222  if (processor != null) {
223  return processor.getDefaultArgument();
224  }
225  return null;
226  }
227 
228  @Override
229  public void open() {
230  if (startupWindowToUse != null) {
231  startupWindowToUse.open();
232  }
233  }
234 
235  @Override
236  public void close() {
237  if (startupWindowToUse != null) {
238  startupWindowToUse.close();
239  }
240  }
241 
248  return startupWindowToUse;
249  }
250 }
static void openAsCurrentCase(String caseMetadataFilePath)
Definition: Case.java:855
static void error(String title, String message)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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