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  setLayout(new java.awt.GridBagLayout());
165 
166  incidentTextPanel.setLayout(new java.awt.GridBagLayout());
167 
168  org.openide.awt.Mnemonics.setLocalizedText(incidentTextLabel, org.openide.util.NbBundle.getMessage(CTIncidentImportOptionsPanel.class, "CTIncidentImportOptionsPanel.incidentTextLabel.text")); // NOI18N
169  gridBagConstraints = new java.awt.GridBagConstraints();
170  gridBagConstraints.gridx = 0;
171  gridBagConstraints.gridy = 0;
172  gridBagConstraints.gridwidth = 2;
173  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
174  gridBagConstraints.weightx = 1.0;
175  gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
176  incidentTextPanel.add(incidentTextLabel, gridBagConstraints);
177 
178  org.openide.awt.Mnemonics.setLocalizedText(importModule, org.openide.util.NbBundle.getMessage(CTIncidentImportOptionsPanel.class, "CTIncidentImportOptionsPanel.importModule.text")); // NOI18N
179  gridBagConstraints = new java.awt.GridBagConstraints();
180  gridBagConstraints.gridx = 0;
181  gridBagConstraints.gridy = 1;
182  gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 3);
183  incidentTextPanel.add(importModule, gridBagConstraints);
184 
185  org.openide.awt.Mnemonics.setLocalizedText(importModuleDetected, org.openide.util.NbBundle.getMessage(CTIncidentImportOptionsPanel.class, "CTIncidentImportOptionsPanel.importModuleDetected.text")); // NOI18N
186  gridBagConstraints = new java.awt.GridBagConstraints();
187  gridBagConstraints.gridx = 1;
188  gridBagConstraints.gridy = 1;
189  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
190  gridBagConstraints.weightx = 1.0;
191  gridBagConstraints.insets = new java.awt.Insets(5, 0, 5, 5);
192  incidentTextPanel.add(importModuleDetected, gridBagConstraints);
193 
194  gridBagConstraints = new java.awt.GridBagConstraints();
195  gridBagConstraints.gridx = 0;
196  gridBagConstraints.gridy = 0;
197  add(incidentTextPanel, gridBagConstraints);
198 
199  instructionsPanel.setLayout(new java.awt.GridBagLayout());
200 
201  org.openide.awt.Mnemonics.setLocalizedText(instructionsTextLabel, org.openide.util.NbBundle.getMessage(CTIncidentImportOptionsPanel.class, "CTIncidentImportOptionsPanel.instructionsTextLabel.text")); // NOI18N
202  gridBagConstraints = new java.awt.GridBagConstraints();
203  gridBagConstraints.gridx = 0;
204  gridBagConstraints.gridy = 0;
205  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
206  gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 0);
207  instructionsPanel.add(instructionsTextLabel, gridBagConstraints);
208  instructionsTextLabel.getAccessibleContext().setAccessibleName("For instructions on obtaining the module refer to:");
209 
210  org.openide.awt.Mnemonics.setLocalizedText(instructionsLinkLabel, getHtmlLink(CT_IMPORTER_DOC_LINK));
211  instructionsLinkLabel.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
212  instructionsLinkLabel.addMouseListener(new java.awt.event.MouseAdapter() {
213  public void mouseClicked(java.awt.event.MouseEvent evt) {
214  instructionsLinkLabelMouseClicked(evt);
215  }
216  });
217  gridBagConstraints = new java.awt.GridBagConstraints();
218  gridBagConstraints.gridx = 1;
219  gridBagConstraints.gridy = 0;
220  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
221  gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
222  instructionsPanel.add(instructionsLinkLabel, gridBagConstraints);
223 
224  gridBagConstraints = new java.awt.GridBagConstraints();
225  gridBagConstraints.gridx = 0;
226  gridBagConstraints.gridy = 1;
227  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
228  add(instructionsPanel, gridBagConstraints);
229 
230  repoPanel.setLayout(new java.awt.GridBagLayout());
231 
232  org.openide.awt.Mnemonics.setLocalizedText(fileRepoPathLabel, org.openide.util.NbBundle.getMessage(CTIncidentImportOptionsPanel.class, "CTIncidentImportOptionsPanel.fileRepoPathLabel.text")); // NOI18N
233  gridBagConstraints = new java.awt.GridBagConstraints();
234  gridBagConstraints.gridx = 0;
235  gridBagConstraints.gridy = 0;
236  gridBagConstraints.gridwidth = 2;
237  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
238  gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
239  repoPanel.add(fileRepoPathLabel, gridBagConstraints);
240 
241  fileRepoPathField.setText(org.openide.util.NbBundle.getMessage(CTIncidentImportOptionsPanel.class, "CTIncidentImportOptionsPanel.fileRepoPathField.text")); // NOI18N
242  fileRepoPathField.addActionListener(new java.awt.event.ActionListener() {
243  public void actionPerformed(java.awt.event.ActionEvent evt) {
244  fileRepoPathFieldActionPerformed(evt);
245  }
246  });
247  gridBagConstraints = new java.awt.GridBagConstraints();
248  gridBagConstraints.gridx = 0;
249  gridBagConstraints.gridy = 1;
250  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
251  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
252  gridBagConstraints.weightx = 1.0;
253  gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
254  repoPanel.add(fileRepoPathField, gridBagConstraints);
255  fileRepoPathField.getAccessibleContext().setAccessibleName("");
256 
257  org.openide.awt.Mnemonics.setLocalizedText(fileRepoBrowseButton, org.openide.util.NbBundle.getMessage(CTIncidentImportOptionsPanel.class, "CTIncidentImportOptionsPanel.fileRepoBrowseButton.text")); // NOI18N
258  fileRepoBrowseButton.addActionListener(new java.awt.event.ActionListener() {
259  public void actionPerformed(java.awt.event.ActionEvent evt) {
260  fileRepoBrowseButtonActionPerformed(evt);
261  }
262  });
263  gridBagConstraints = new java.awt.GridBagConstraints();
264  gridBagConstraints.gridx = 1;
265  gridBagConstraints.gridy = 1;
266  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
267  gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
268  repoPanel.add(fileRepoBrowseButton, gridBagConstraints);
269 
270  caseOpenWarningLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/modules/hashdatabase/warning16.png"))); // NOI18N
271  org.openide.awt.Mnemonics.setLocalizedText(caseOpenWarningLabel, org.openide.util.NbBundle.getMessage(CTIncidentImportOptionsPanel.class, "CTIncidentImportOptionsPanel.caseOpenWarningLabel.text")); // NOI18N
272  gridBagConstraints = new java.awt.GridBagConstraints();
273  gridBagConstraints.gridx = 0;
274  gridBagConstraints.gridy = 2;
275  gridBagConstraints.gridwidth = 2;
276  gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
277  gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
278  repoPanel.add(caseOpenWarningLabel, gridBagConstraints);
279 
280  gridBagConstraints = new java.awt.GridBagConstraints();
281  gridBagConstraints.gridx = 0;
282  gridBagConstraints.gridy = 2;
283  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
284  add(repoPanel, gridBagConstraints);
285  }// </editor-fold>//GEN-END:initComponents
286  private void fileRepoBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileRepoBrowseButtonActionPerformed
287  JFileChooser fileChooser = fileRepoChooserFactory.getChooser();
288  fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
289  fileChooser.setMultiSelectionEnabled(false);
290 
291  File curSelectedDir = StringUtils.isBlank(this.fileRepoPathField.getText()) ? null : new File(this.fileRepoPathField.getText());
292  if (curSelectedDir == null || !curSelectedDir.isDirectory()) {
293  curSelectedDir = new File(CTSettings.getDefaultFileRepoPath());
294  }
295 
296  fileChooser.setCurrentDirectory(curSelectedDir);
297  fileChooser.setDialogTitle(org.openide.util.NbBundle.getMessage(CTIncidentImportOptionsPanel.class, "CTIncidentImportOptionsPanel.fileRepoFileChooser.title"));
298  int retVal = fileChooser.showOpenDialog(this);
299  if (retVal == JFileChooser.APPROVE_OPTION) {
300  this.fileRepoPathField.setText(fileChooser.getSelectedFile().getAbsolutePath());
301  }
302  }//GEN-LAST:event_fileRepoBrowseButtonActionPerformed
303 
304  private void fileRepoPathFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileRepoPathFieldActionPerformed
305  // TODO add your handling code here:
306  }//GEN-LAST:event_fileRepoPathFieldActionPerformed
307 
308  private void instructionsLinkLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_instructionsLinkLabelMouseClicked
309  gotoLink(CT_IMPORTER_DOC_LINK);
310  }//GEN-LAST:event_instructionsLinkLabelMouseClicked
311 
312  private void gotoLink(String url) {
313  if (Desktop.isDesktopSupported()) {
314  try {
315  Desktop.getDesktop().browse(new URI(url));
316  } catch (IOException | URISyntaxException e) {
317  logger.log(Level.SEVERE, "Error opening link to: " + url, e);
318  }
319  } else {
320  logger.log(Level.WARNING, "Desktop API is not supported. Link cannot be opened.");
321  }
322  }
323 
324  // Variables declaration - do not modify//GEN-BEGIN:variables
325  private javax.swing.JLabel caseOpenWarningLabel;
326  private javax.swing.JButton fileRepoBrowseButton;
327  private javax.swing.JTextField fileRepoPathField;
328  private javax.swing.JLabel importModuleDetected;
329  private javax.swing.JLabel incidentTextLabel;
330  private javax.swing.JPanel incidentTextPanel;
331  private javax.swing.JLabel instructionsLinkLabel;
332  private javax.swing.JPanel instructionsPanel;
333  private javax.swing.JLabel instructionsTextLabel;
334  private javax.swing.JPanel repoPanel;
335  // End of variables declaration//GEN-END:variables
336 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:708

Copyright © 2012-2022 Basis Technology. Generated on: Tue Feb 6 2024
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.