Autopsy  4.21.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
CTIncidentImportOptionsPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2023 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 com.basistech.df.cybertriage.autopsy.incidentoptions;
20 
22 import java.awt.Desktop;
23 import java.io.File;
24 import java.io.IOException;
25 import java.net.URI;
26 import java.net.URISyntaxException;
27 import java.util.Collection;
28 import java.util.Collections;
29 import java.util.logging.Level;
30 import java.util.stream.Stream;
32 import javax.swing.JFileChooser;
33 import javax.swing.event.DocumentEvent;
34 import javax.swing.event.DocumentListener;
35 import org.apache.commons.lang3.StringUtils;
36 import org.netbeans.spi.options.OptionsPanelController;
37 import org.openide.util.Lookup;
38 import org.openide.util.NbBundle.Messages;
39 import org.openide.util.lookup.ServiceProvider;
43 
47 @ServiceProvider(service = CTOptionsSubPanel.class)
49 
50  private static final Logger logger = Logger.getLogger(CTIncidentImportOptionsPanel.class.getName());
51 
52  private static final String CT_IMPORTER_DOC_LINK = "https://docs.cybertriage.com/en/latest/chapters/integrations/autopsy.html";
53 
54  private static final String CT_STANDARD_CONTENT_PROVIDER_NAME = "CTStandardContentProvider";
55 
56  private final JFileChooserFactory fileRepoChooserFactory = new JFileChooserFactory();
57  private final CTSettingsPersistence ctPersistence = CTSettingsPersistence.getInstance();
58 
59  private static String getHtmlLink(String url) {
60  return "<html><span style=\"color: blue; text-decoration: underline\">" + url + "</span></html>";
61  }
62 
67  initComponents();
68  this.fileRepoPathField.getDocument().addDocumentListener(new DocumentListener() {
69  @Override
70  public void changedUpdate(DocumentEvent e) {
71  fireSettingsChanged();
72  }
73 
74  @Override
75  public void insertUpdate(DocumentEvent e) {
76  fireSettingsChanged();
77  }
78 
79  @Override
80  public void removeUpdate(DocumentEvent e) {
81  fireSettingsChanged();
82  }
83  });
84 
85  Case.addEventTypeSubscriber(Collections.singleton(Case.Events.CURRENT_CASE), (evt) -> {
86  CTIncidentImportOptionsPanel.this.setEnabledItems(evt.getNewValue() != null);
87  });
88  }
89 
90  private void setCTSettingsDisplay(CTSettings ctSettings) {
91  this.fileRepoPathField.setText(ctSettings.getFileRepoPath());
92  }
93 
94  @Override
95  public synchronized void saveSettings() {
96  ctPersistence.saveCTSettings(getSettings());
97  }
98 
99  @Override
100  public synchronized void loadSettings() {
101  CTSettings ctSettings = ctPersistence.loadCTSettings();
102  setCTSettingsDisplay(ctSettings);
103  setModuleDetected();
104  setEnabledItems(Case.isCaseOpen());
105  }
106 
107  @Messages({
108  "CTIncidentImportOptionsPanel_setModuleDetected_detected=Detected",
109  "CTIncidentImportOptionsPanel_setModuleDetected_notDetected=Not Detected"
110  })
111  private void setModuleDetected() {
112  Collection<? extends AutopsyContentProvider> contentProviders = Lookup.getDefault().lookupAll(AutopsyContentProvider.class);
113  boolean detected = ((Collection<? extends AutopsyContentProvider>) (contentProviders != null ? contentProviders : Collections.emptyList())).stream()
114  .anyMatch(p -> p != null && StringUtils.defaultString(p.getName()).toUpperCase().startsWith(CT_STANDARD_CONTENT_PROVIDER_NAME.toUpperCase()));
115 
116  this.importModuleDetected.setText(detected
117  ? Bundle.CTIncidentImportOptionsPanel_setModuleDetected_detected()
118  : Bundle.CTIncidentImportOptionsPanel_setModuleDetected_notDetected());
119  }
120 
121  private void setEnabledItems(boolean caseOpen) {
122  this.caseOpenWarningLabel.setVisible(caseOpen);
123  this.fileRepoBrowseButton.setEnabled(!caseOpen);
124  this.fileRepoPathField.setEnabled(!caseOpen);
125  }
126 
127  private void fireSettingsChanged() {
128  this.firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
129  }
130 
132  return new CTSettings().setFileRepoPath(this.fileRepoPathField.getText());
133  }
134 
135  @Override
136  public boolean valid() {
137  return new File(this.fileRepoPathField.getText()).isDirectory();
138  }
139 
145  @SuppressWarnings("unchecked")
146  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
147  private void initComponents() {
148  java.awt.GridBagConstraints gridBagConstraints;
149 
150  incidentTextPanel = new javax.swing.JPanel();
151  incidentTextLabel = new javax.swing.JLabel();
152  javax.swing.JLabel importModule = new javax.swing.JLabel();
153  importModuleDetected = new javax.swing.JLabel();
154  instructionsPanel = new javax.swing.JPanel();
155  instructionsTextLabel = new javax.swing.JLabel();
156  instructionsLinkLabel = new javax.swing.JLabel();
157  repoPanel = new javax.swing.JPanel();
158  javax.swing.JLabel fileRepoPathLabel = new javax.swing.JLabel();
159  fileRepoPathField = new javax.swing.JTextField();
160  fileRepoBrowseButton = new javax.swing.JButton();
161  caseOpenWarningLabel = new javax.swing.JLabel();
162 
163  setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(CTIncidentImportOptionsPanel.class, "CTIncidentImportOptionsPanel.border.title_1"))); // NOI18N
164  setMaximumSize(new java.awt.Dimension(650, 2147483647));
165  setMinimumSize(new java.awt.Dimension(650, 206));
166  setPreferredSize(new java.awt.Dimension(650, 206));
167  setLayout(new java.awt.GridBagLayout());
168 
169  incidentTextPanel.setLayout(new java.awt.GridBagLayout());
170 
171  org.openide.awt.Mnemonics.setLocalizedText(incidentTextLabel, org.openide.util.NbBundle.getMessage(CTIncidentImportOptionsPanel.class, "CTIncidentImportOptionsPanel.incidentTextLabel.text")); // NOI18N
172  incidentTextLabel.setMaximumSize(new java.awt.Dimension(600, 32));
173  incidentTextLabel.setPreferredSize(null);
174  gridBagConstraints = new java.awt.GridBagConstraints();
175  gridBagConstraints.gridx = 0;
176  gridBagConstraints.gridy = 0;
177  gridBagConstraints.gridwidth = 2;
178  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
179  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
180  gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
181  incidentTextPanel.add(incidentTextLabel, gridBagConstraints);
182 
183  org.openide.awt.Mnemonics.setLocalizedText(importModule, org.openide.util.NbBundle.getMessage(CTIncidentImportOptionsPanel.class, "CTIncidentImportOptionsPanel.importModule.text")); // NOI18N
184  importModule.setPreferredSize(null);
185  gridBagConstraints = new java.awt.GridBagConstraints();
186  gridBagConstraints.gridx = 0;
187  gridBagConstraints.gridy = 1;
188  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
189  gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 3);
190  incidentTextPanel.add(importModule, gridBagConstraints);
191 
192  org.openide.awt.Mnemonics.setLocalizedText(importModuleDetected, org.openide.util.NbBundle.getMessage(CTIncidentImportOptionsPanel.class, "CTIncidentImportOptionsPanel.importModuleDetected.text")); // NOI18N
193  gridBagConstraints = new java.awt.GridBagConstraints();
194  gridBagConstraints.gridx = 1;
195  gridBagConstraints.gridy = 1;
196  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
197  gridBagConstraints.weightx = 1.0;
198  gridBagConstraints.insets = new java.awt.Insets(5, 0, 5, 5);
199  incidentTextPanel.add(importModuleDetected, gridBagConstraints);
200 
201  gridBagConstraints = new java.awt.GridBagConstraints();
202  gridBagConstraints.gridx = 0;
203  gridBagConstraints.gridy = 0;
204  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
205  gridBagConstraints.weightx = 1.0;
206  add(incidentTextPanel, gridBagConstraints);
207 
208  instructionsPanel.setLayout(new java.awt.GridBagLayout());
209 
210  org.openide.awt.Mnemonics.setLocalizedText(instructionsTextLabel, org.openide.util.NbBundle.getMessage(CTIncidentImportOptionsPanel.class, "CTIncidentImportOptionsPanel.instructionsTextLabel.text")); // NOI18N
211  instructionsTextLabel.setPreferredSize(null);
212  gridBagConstraints = new java.awt.GridBagConstraints();
213  gridBagConstraints.gridx = 0;
214  gridBagConstraints.gridy = 0;
215  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
216  gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 0);
217  instructionsPanel.add(instructionsTextLabel, gridBagConstraints);
218  instructionsTextLabel.getAccessibleContext().setAccessibleName("For instructions on obtaining the module refer to:");
219 
220  org.openide.awt.Mnemonics.setLocalizedText(instructionsLinkLabel, getHtmlLink(CT_IMPORTER_DOC_LINK));
221  instructionsLinkLabel.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
222  instructionsLinkLabel.setPreferredSize(null);
223  instructionsLinkLabel.addMouseListener(new java.awt.event.MouseAdapter() {
224  public void mouseClicked(java.awt.event.MouseEvent evt) {
225  instructionsLinkLabelMouseClicked(evt);
226  }
227  });
228  gridBagConstraints = new java.awt.GridBagConstraints();
229  gridBagConstraints.gridx = 1;
230  gridBagConstraints.gridy = 0;
231  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
232  gridBagConstraints.weightx = 1.0;
233  gridBagConstraints.insets = new java.awt.Insets(5, 2, 5, 5);
234  instructionsPanel.add(instructionsLinkLabel, gridBagConstraints);
235 
236  gridBagConstraints = new java.awt.GridBagConstraints();
237  gridBagConstraints.gridx = 0;
238  gridBagConstraints.gridy = 1;
239  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
240  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
241  gridBagConstraints.weightx = 1.0;
242  add(instructionsPanel, gridBagConstraints);
243 
244  repoPanel.setMaximumSize(new java.awt.Dimension(650, 2147483647));
245  repoPanel.setPreferredSize(new java.awt.Dimension(650, 75));
246  repoPanel.setLayout(new java.awt.GridBagLayout());
247 
248  org.openide.awt.Mnemonics.setLocalizedText(fileRepoPathLabel, org.openide.util.NbBundle.getMessage(CTIncidentImportOptionsPanel.class, "CTIncidentImportOptionsPanel.fileRepoPathLabel.text")); // NOI18N
249  fileRepoPathLabel.setMaximumSize(new java.awt.Dimension(600, 16));
250  fileRepoPathLabel.setPreferredSize(null);
251  gridBagConstraints = new java.awt.GridBagConstraints();
252  gridBagConstraints.gridx = 0;
253  gridBagConstraints.gridy = 0;
254  gridBagConstraints.gridwidth = 2;
255  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
256  gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
257  repoPanel.add(fileRepoPathLabel, gridBagConstraints);
258 
259  fileRepoPathField.setText(org.openide.util.NbBundle.getMessage(CTIncidentImportOptionsPanel.class, "CTIncidentImportOptionsPanel.fileRepoPathField.text")); // NOI18N
260  fileRepoPathField.setPreferredSize(null);
261  fileRepoPathField.addActionListener(new java.awt.event.ActionListener() {
262  public void actionPerformed(java.awt.event.ActionEvent evt) {
263  fileRepoPathFieldActionPerformed(evt);
264  }
265  });
266  gridBagConstraints = new java.awt.GridBagConstraints();
267  gridBagConstraints.gridx = 0;
268  gridBagConstraints.gridy = 1;
269  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
270  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
271  gridBagConstraints.weightx = 1.0;
272  gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
273  repoPanel.add(fileRepoPathField, gridBagConstraints);
274  fileRepoPathField.getAccessibleContext().setAccessibleName("");
275 
276  org.openide.awt.Mnemonics.setLocalizedText(fileRepoBrowseButton, org.openide.util.NbBundle.getMessage(CTIncidentImportOptionsPanel.class, "CTIncidentImportOptionsPanel.fileRepoBrowseButton.text")); // NOI18N
277  fileRepoBrowseButton.addActionListener(new java.awt.event.ActionListener() {
278  public void actionPerformed(java.awt.event.ActionEvent evt) {
279  fileRepoBrowseButtonActionPerformed(evt);
280  }
281  });
282  gridBagConstraints = new java.awt.GridBagConstraints();
283  gridBagConstraints.gridx = 1;
284  gridBagConstraints.gridy = 1;
285  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
286  gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
287  repoPanel.add(fileRepoBrowseButton, gridBagConstraints);
288 
289  caseOpenWarningLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/modules/hashdatabase/warning16.png"))); // NOI18N
290  org.openide.awt.Mnemonics.setLocalizedText(caseOpenWarningLabel, org.openide.util.NbBundle.getMessage(CTIncidentImportOptionsPanel.class, "CTIncidentImportOptionsPanel.caseOpenWarningLabel.text")); // NOI18N
291  gridBagConstraints = new java.awt.GridBagConstraints();
292  gridBagConstraints.gridx = 0;
293  gridBagConstraints.gridy = 2;
294  gridBagConstraints.gridwidth = 2;
295  gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
296  gridBagConstraints.weightx = 1.0;
297  gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
298  repoPanel.add(caseOpenWarningLabel, gridBagConstraints);
299 
300  gridBagConstraints = new java.awt.GridBagConstraints();
301  gridBagConstraints.gridx = 0;
302  gridBagConstraints.gridy = 2;
303  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
304  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
305  gridBagConstraints.weightx = 1.0;
306  add(repoPanel, gridBagConstraints);
307  }// </editor-fold>//GEN-END:initComponents
308  private void fileRepoBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileRepoBrowseButtonActionPerformed
309  JFileChooser fileChooser = fileRepoChooserFactory.getChooser();
310  fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
311  fileChooser.setMultiSelectionEnabled(false);
312 
313  File curSelectedDir = StringUtils.isBlank(this.fileRepoPathField.getText()) ? null : new File(this.fileRepoPathField.getText());
314  if (curSelectedDir == null || !curSelectedDir.isDirectory()) {
315  curSelectedDir = new File(CTSettings.getDefaultFileRepoPath());
316  }
317 
318  fileChooser.setCurrentDirectory(curSelectedDir);
319  fileChooser.setDialogTitle(org.openide.util.NbBundle.getMessage(CTIncidentImportOptionsPanel.class, "CTIncidentImportOptionsPanel.fileRepoFileChooser.title"));
320  int retVal = fileChooser.showOpenDialog(this);
321  if (retVal == JFileChooser.APPROVE_OPTION) {
322  this.fileRepoPathField.setText(fileChooser.getSelectedFile().getAbsolutePath());
323  }
324  }//GEN-LAST:event_fileRepoBrowseButtonActionPerformed
325 
326  private void fileRepoPathFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileRepoPathFieldActionPerformed
327  // TODO add your handling code here:
328  }//GEN-LAST:event_fileRepoPathFieldActionPerformed
329 
330  private void instructionsLinkLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_instructionsLinkLabelMouseClicked
331  gotoLink(CT_IMPORTER_DOC_LINK);
332  }//GEN-LAST:event_instructionsLinkLabelMouseClicked
333 
334  private void gotoLink(String url) {
335  if (Desktop.isDesktopSupported()) {
336  try {
337  Desktop.getDesktop().browse(new URI(url));
338  } catch (IOException | URISyntaxException e) {
339  logger.log(Level.SEVERE, "Error opening link to: " + url, e);
340  }
341  } else {
342  logger.log(Level.WARNING, "Desktop API is not supported. Link cannot be opened.");
343  }
344  }
345 
346  // Variables declaration - do not modify//GEN-BEGIN:variables
347  private javax.swing.JLabel caseOpenWarningLabel;
348  private javax.swing.JButton fileRepoBrowseButton;
349  private javax.swing.JTextField fileRepoPathField;
350  private javax.swing.JLabel importModuleDetected;
351  private javax.swing.JLabel incidentTextLabel;
352  private javax.swing.JPanel incidentTextPanel;
353  private javax.swing.JLabel instructionsLinkLabel;
354  private javax.swing.JPanel instructionsPanel;
355  private javax.swing.JLabel instructionsTextLabel;
356  private javax.swing.JPanel repoPanel;
357  // End of variables declaration//GEN-END:variables
358 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:712

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.