19 package com.basistech.df.cybertriage.autopsy.incidentoptions;
22 import java.awt.Desktop;
24 import java.io.IOException;
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;
52 private static final String CT_IMPORTER_DOC_LINK =
"https://docs.cybertriage.com/en/latest/chapters/integrations/autopsy.html";
54 private static final String CT_STANDARD_CONTENT_PROVIDER_NAME =
"CTStandardContentProvider";
60 return "<html><span style=\"color: blue; text-decoration: underline\">" + url +
"</span></html>";
68 this.fileRepoPathField.getDocument().addDocumentListener(
new DocumentListener() {
70 public void changedUpdate(DocumentEvent e) {
71 fireSettingsChanged();
75 public void insertUpdate(DocumentEvent e) {
76 fireSettingsChanged();
80 public void removeUpdate(DocumentEvent e) {
81 fireSettingsChanged();
102 setCTSettingsDisplay(ctSettings);
108 "CTIncidentImportOptionsPanel_setModuleDetected_detected=Detected",
109 "CTIncidentImportOptionsPanel_setModuleDetected_notDetected=Not Detected"
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()));
116 this.importModuleDetected.setText(detected
117 ? Bundle.CTIncidentImportOptionsPanel_setModuleDetected_detected()
118 : Bundle.CTIncidentImportOptionsPanel_setModuleDetected_notDetected());
122 this.caseOpenWarningLabel.setVisible(caseOpen);
123 this.fileRepoBrowseButton.setEnabled(!caseOpen);
124 this.fileRepoPathField.setEnabled(!caseOpen);
128 this.firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
137 return new File(this.fileRepoPathField.getText()).isDirectory();
145 @SuppressWarnings(
"unchecked")
147 private
void initComponents() {
148 java.awt.GridBagConstraints gridBagConstraints;
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();
163 setBorder(javax.swing.BorderFactory.createTitledBorder(
org.openide.util.NbBundle.getMessage(
CTIncidentImportOptionsPanel.class,
"CTIncidentImportOptionsPanel.border.title_1")));
164 setLayout(
new java.awt.GridBagLayout());
166 incidentTextPanel.setLayout(
new java.awt.GridBagLayout());
168 org.openide.awt.Mnemonics.setLocalizedText(incidentTextLabel,
org.openide.util.NbBundle.getMessage(
CTIncidentImportOptionsPanel.class,
"CTIncidentImportOptionsPanel.incidentTextLabel.text"));
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);
178 org.openide.awt.Mnemonics.setLocalizedText(importModule,
org.openide.util.NbBundle.getMessage(
CTIncidentImportOptionsPanel.class,
"CTIncidentImportOptionsPanel.importModule.text"));
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);
185 org.openide.awt.Mnemonics.setLocalizedText(importModuleDetected,
org.openide.util.NbBundle.getMessage(
CTIncidentImportOptionsPanel.class,
"CTIncidentImportOptionsPanel.importModuleDetected.text"));
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);
194 gridBagConstraints =
new java.awt.GridBagConstraints();
195 gridBagConstraints.gridx = 0;
196 gridBagConstraints.gridy = 0;
197 add(incidentTextPanel, gridBagConstraints);
199 instructionsPanel.setLayout(
new java.awt.GridBagLayout());
201 org.openide.awt.Mnemonics.setLocalizedText(instructionsTextLabel,
org.openide.util.NbBundle.getMessage(
CTIncidentImportOptionsPanel.class,
"CTIncidentImportOptionsPanel.instructionsTextLabel.text"));
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:");
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);
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);
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);
230 repoPanel.setLayout(
new java.awt.GridBagLayout());
232 org.openide.awt.Mnemonics.setLocalizedText(fileRepoPathLabel,
org.openide.util.NbBundle.getMessage(
CTIncidentImportOptionsPanel.class,
"CTIncidentImportOptionsPanel.fileRepoPathLabel.text"));
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);
241 fileRepoPathField.setText(
org.openide.util.NbBundle.getMessage(
CTIncidentImportOptionsPanel.class,
"CTIncidentImportOptionsPanel.fileRepoPathField.text"));
242 fileRepoPathField.addActionListener(
new java.awt.event.ActionListener() {
243 public void actionPerformed(java.awt.event.ActionEvent evt) {
244 fileRepoPathFieldActionPerformed(evt);
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(
"");
257 org.openide.awt.Mnemonics.setLocalizedText(fileRepoBrowseButton,
org.openide.util.NbBundle.getMessage(
CTIncidentImportOptionsPanel.class,
"CTIncidentImportOptionsPanel.fileRepoBrowseButton.text"));
258 fileRepoBrowseButton.addActionListener(
new java.awt.event.ActionListener() {
259 public void actionPerformed(java.awt.event.ActionEvent evt) {
260 fileRepoBrowseButtonActionPerformed(evt);
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);
270 caseOpenWarningLabel.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/modules/hashdatabase/warning16.png")));
271 org.openide.awt.Mnemonics.setLocalizedText(caseOpenWarningLabel,
org.openide.util.NbBundle.getMessage(
CTIncidentImportOptionsPanel.class,
"CTIncidentImportOptionsPanel.caseOpenWarningLabel.text"));
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);
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);
287 JFileChooser fileChooser = fileRepoChooserFactory.
getChooser();
288 fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
289 fileChooser.setMultiSelectionEnabled(
false);
291 File curSelectedDir = StringUtils.isBlank(this.fileRepoPathField.getText()) ? null :
new File(this.fileRepoPathField.getText());
292 if (curSelectedDir == null || !curSelectedDir.isDirectory()) {
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());
309 gotoLink(CT_IMPORTER_DOC_LINK);
313 if (Desktop.isDesktopSupported()) {
315 Desktop.getDesktop().browse(
new URI(url));
316 }
catch (IOException | URISyntaxException e) {
317 logger.log(Level.SEVERE,
"Error opening link to: " + url, e);
320 logger.log(Level.WARNING,
"Desktop API is not supported. Link cannot be opened.");
void setEnabledItems(boolean caseOpen)
javax.swing.JLabel incidentTextLabel
static String getDefaultFileRepoPath()
javax.swing.JLabel importModuleDetected
void setCTSettingsDisplay(CTSettings ctSettings)
javax.swing.JPanel instructionsPanel
javax.swing.JButton fileRepoBrowseButton
synchronized void loadSettings()
void instructionsLinkLabelMouseClicked(java.awt.event.MouseEvent evt)
static String getHtmlLink(String url)
javax.swing.JLabel instructionsLinkLabel
javax.swing.JLabel caseOpenWarningLabel
void gotoLink(String url)
CTSettings setFileRepoPath(String fileRepoPath)
javax.swing.JPanel repoPanel
void fileRepoPathFieldActionPerformed(java.awt.event.ActionEvent evt)
JFileChooser getChooser()
synchronized void saveSettings()
void fileRepoBrowseButtonActionPerformed(java.awt.event.ActionEvent evt)
synchronized boolean saveCTSettings(CTSettings ctSettings)
javax.swing.JTextField fileRepoPathField
javax.swing.JLabel instructionsTextLabel
void fireSettingsChanged()
javax.swing.JPanel incidentTextPanel
static CTSettingsPersistence getInstance()
synchronized static Logger getLogger(String name)
CTIncidentImportOptionsPanel()
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
static boolean isCaseOpen()
synchronized CTSettings loadCTSettings()