Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
CommandLineIngestSettingsPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2019-2021 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.commandlineingest;
20 
21 import java.awt.BorderLayout;
22 import java.awt.Cursor;
23 import java.util.List;
24 import java.util.Set;
25 import javax.swing.DefaultComboBoxModel;
26 import javax.swing.JOptionPane;
27 import org.openide.util.NbBundle.Messages;
30 import org.openide.windows.WindowManager;
34 
38 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
39 public class CommandLineIngestSettingsPanel extends javax.swing.JPanel {
40 
41  private static final long serialVersionUID = 1L;
42  private static final Logger logger = Logger.getLogger(CommandLineIngestSettingsPanel.class.getName());
43 
44  private static final String REPORTING_CONFIGURATION_NAME = "CommandLineIngest";
45  private static final boolean DISPLAY_CASE_SPECIFIC_DATA = false; // do not try to display case specific data
46  private static final boolean RUN_REPORTS = false; // do not generate reports as part of running the report wizard
47 
54  initComponents();
55  setupReportList();
56  }
57 
61  public static String getDefaultReportingConfigName() {
62  return REPORTING_CONFIGURATION_NAME;
63  }
64 
66  this.getParent().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
67 
69  showWarnings(ingestJobSettings);
70  IngestJobSettingsPanel ingestJobSettingsPanel = new IngestJobSettingsPanel(ingestJobSettings);
71 
72  add(ingestJobSettingsPanel, BorderLayout.PAGE_START);
73 
74  if (JOptionPane.showConfirmDialog(this, ingestJobSettingsPanel, "Ingest Module Configuration", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE) == JOptionPane.OK_OPTION) {
75  // store the updated settings
76  ingestJobSettings = ingestJobSettingsPanel.getSettings();
77  ingestJobSettings.save();
78  showWarnings(ingestJobSettings);
79  }
80 
81  this.getParent().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
82  }
83 
84  private static void showWarnings(IngestJobSettings ingestJobSettings) {
85  List<String> warnings = ingestJobSettings.getWarnings();
86  if (warnings.isEmpty() == false) {
87  StringBuilder warningMessage = new StringBuilder();
88  for (String warning : warnings) {
89  warningMessage.append(warning).append("\n");
90  }
91  JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), warningMessage.toString());
92  }
93  }
94 
95  @Messages({
96  "CommandListIngestSettingsPanel_Default_Report_DisplayName=Default",
97  "CommandListIngestSettingsPanel_Make_Config=Make new profile..."
98  })
102  private void setupReportList() {
103  Set<String> configNames = ReportWizardAction.getReportConfigNames();
104  configNames.remove(REPORTING_CONFIGURATION_NAME);
105 
106  DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>();
107  model.addElement(Bundle.CommandListIngestSettingsPanel_Default_Report_DisplayName());
108  for (String name : configNames) {
109  model.addElement(name);
110  }
111 
112  model.addElement(Bundle.CommandListIngestSettingsPanel_Make_Config());
113 
114  reportProfileCB.setModel(model);
115  reportProfileCB.setSelectedIndex(0);
116  }
117 
125  private boolean doesReportProfileNameExist(String name) {
126  Set<String> configNames = ReportWizardAction.getReportConfigNames();
127  return configNames.contains(name);
128  }
129 
137  private String getReportName() {
138  String reportName = (String) reportProfileCB.getSelectedItem();
139 
140  if (reportName.equals(Bundle.CommandListIngestSettingsPanel_Default_Report_DisplayName())) {
141  reportName = REPORTING_CONFIGURATION_NAME;
142  }
143 
144  return reportName;
145  }
146 
152  @SuppressWarnings("unchecked")
153  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
154  private void initComponents() {
155  java.awt.GridBagConstraints gridBagConstraints;
156 
157  nodePanel = new javax.swing.JPanel();
158  bnEditIngestSettings = new javax.swing.JButton();
159  bnEditReportSettings = new javax.swing.JButton();
160  javax.swing.JTextPane ingestDescriptionTextPane = new javax.swing.JTextPane();
161  javax.swing.JLabel ingestProfileLabel = new javax.swing.JLabel();
162  ingestProfileCB = new javax.swing.JComboBox<>();
163  javax.swing.JTextPane reportDescriptionTextPane = new javax.swing.JTextPane();
164  javax.swing.JLabel reportProfileLabel = new javax.swing.JLabel();
165  reportProfileCB = new javax.swing.JComboBox<>();
166  javax.swing.Box.Filler bottomFiller = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0));
167  jTextPane1 = new javax.swing.JTextPane();
168 
169  setPreferredSize(new java.awt.Dimension(810, 422));
170  setLayout(new java.awt.BorderLayout());
171 
172  nodePanel.setMinimumSize(new java.awt.Dimension(100, 100));
173  nodePanel.setPreferredSize(new java.awt.Dimension(801, 551));
174  nodePanel.setLayout(new java.awt.GridBagLayout());
175 
176  org.openide.awt.Mnemonics.setLocalizedText(bnEditIngestSettings, org.openide.util.NbBundle.getMessage(CommandLineIngestSettingsPanel.class, "CommandLineIngestSettingsPanel.bnEditIngestSettings.text")); // NOI18N
177  bnEditIngestSettings.setToolTipText(org.openide.util.NbBundle.getMessage(CommandLineIngestSettingsPanel.class, "CommandLineIngestSettingsPanel.bnEditIngestSettings.toolTipText")); // NOI18N
178  bnEditIngestSettings.setActionCommand(org.openide.util.NbBundle.getMessage(CommandLineIngestSettingsPanel.class, "CommandLineIngestSettingsPanel.bnEditIngestSettings.text")); // NOI18N
179  bnEditIngestSettings.addActionListener(new java.awt.event.ActionListener() {
180  public void actionPerformed(java.awt.event.ActionEvent evt) {
181  bnEditIngestSettingsActionPerformed(evt);
182  }
183  });
184  gridBagConstraints = new java.awt.GridBagConstraints();
185  gridBagConstraints.gridx = 2;
186  gridBagConstraints.gridy = 2;
187  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
188  gridBagConstraints.insets = new java.awt.Insets(0, 9, 0, 0);
189  nodePanel.add(bnEditIngestSettings, gridBagConstraints);
190 
191  org.openide.awt.Mnemonics.setLocalizedText(bnEditReportSettings, org.openide.util.NbBundle.getMessage(CommandLineIngestSettingsPanel.class, "CommandLineIngestSettingsPanel.bnEditReportSettings.text")); // NOI18N
192  bnEditReportSettings.setToolTipText(org.openide.util.NbBundle.getMessage(CommandLineIngestSettingsPanel.class, "CommandLineIngestSettingsPanel.bnEditReportSettings.toolTipText")); // NOI18N
193  bnEditReportSettings.setActionCommand(org.openide.util.NbBundle.getMessage(CommandLineIngestSettingsPanel.class, "CommandLineIngestSettingsPanel.bnEditReportSettings.actionCommand")); // NOI18N
194  bnEditReportSettings.addActionListener(new java.awt.event.ActionListener() {
195  public void actionPerformed(java.awt.event.ActionEvent evt) {
196  bnEditReportSettingsActionPerformed(evt);
197  }
198  });
199  gridBagConstraints = new java.awt.GridBagConstraints();
200  gridBagConstraints.gridx = 2;
201  gridBagConstraints.gridy = 4;
202  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
203  gridBagConstraints.insets = new java.awt.Insets(0, 9, 0, 0);
204  nodePanel.add(bnEditReportSettings, gridBagConstraints);
205  bnEditReportSettings.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(CommandLineIngestSettingsPanel.class, "CommandLineIngestSettingsPanel.bnEditReportSettings.AccessibleContext.accessibleName")); // NOI18N
206 
207  ingestDescriptionTextPane.setEditable(false);
208  ingestDescriptionTextPane.setBackground(javax.swing.UIManager.getDefaults().getColor("Label.background"));
209  ingestDescriptionTextPane.setText(org.openide.util.NbBundle.getMessage(CommandLineIngestSettingsPanel.class, "CommandLineIngestSettingsPanel.ingestDescriptionTextPane.text")); // NOI18N
210  gridBagConstraints = new java.awt.GridBagConstraints();
211  gridBagConstraints.gridx = 0;
212  gridBagConstraints.gridy = 0;
213  gridBagConstraints.gridwidth = 3;
214  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
215  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
216  gridBagConstraints.weightx = 1.0;
217  gridBagConstraints.insets = new java.awt.Insets(5, 5, 10, 5);
218  nodePanel.add(ingestDescriptionTextPane, gridBagConstraints);
219 
220  org.openide.awt.Mnemonics.setLocalizedText(ingestProfileLabel, org.openide.util.NbBundle.getMessage(CommandLineIngestSettingsPanel.class, "CommandLineIngestSettingsPanel.ingestProfileLabel.text")); // NOI18N
221  gridBagConstraints = new java.awt.GridBagConstraints();
222  gridBagConstraints.gridx = 0;
223  gridBagConstraints.gridy = 2;
224  gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
225  gridBagConstraints.insets = new java.awt.Insets(0, 25, 0, 0);
226  nodePanel.add(ingestProfileLabel, gridBagConstraints);
227 
228  ingestProfileCB.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Default" }));
229  ingestProfileCB.setEnabled(false);
230  gridBagConstraints = new java.awt.GridBagConstraints();
231  gridBagConstraints.gridx = 1;
232  gridBagConstraints.gridy = 2;
233  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
234  gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 0);
235  nodePanel.add(ingestProfileCB, gridBagConstraints);
236 
237  reportDescriptionTextPane.setEditable(false);
238  reportDescriptionTextPane.setBackground(javax.swing.UIManager.getDefaults().getColor("Label.background"));
239  reportDescriptionTextPane.setText(org.openide.util.NbBundle.getMessage(CommandLineIngestSettingsPanel.class, "CommandLineIngestSettingsPanel.reportDescriptionTextPane.text")); // NOI18N
240  gridBagConstraints = new java.awt.GridBagConstraints();
241  gridBagConstraints.gridx = 0;
242  gridBagConstraints.gridy = 3;
243  gridBagConstraints.gridwidth = 3;
244  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
245  gridBagConstraints.insets = new java.awt.Insets(15, 5, 5, 5);
246  nodePanel.add(reportDescriptionTextPane, gridBagConstraints);
247 
248  org.openide.awt.Mnemonics.setLocalizedText(reportProfileLabel, org.openide.util.NbBundle.getMessage(CommandLineIngestSettingsPanel.class, "CommandLineIngestSettingsPanel.reportProfileLabel.text")); // NOI18N
249  gridBagConstraints = new java.awt.GridBagConstraints();
250  gridBagConstraints.gridx = 0;
251  gridBagConstraints.gridy = 4;
252  gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
253  gridBagConstraints.insets = new java.awt.Insets(0, 25, 0, 0);
254  nodePanel.add(reportProfileLabel, gridBagConstraints);
255 
256  gridBagConstraints = new java.awt.GridBagConstraints();
257  gridBagConstraints.gridx = 1;
258  gridBagConstraints.gridy = 4;
259  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
260  gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 0);
261  nodePanel.add(reportProfileCB, gridBagConstraints);
262  gridBagConstraints = new java.awt.GridBagConstraints();
263  gridBagConstraints.gridx = 0;
264  gridBagConstraints.gridy = 5;
265  gridBagConstraints.weighty = 1.0;
266  nodePanel.add(bottomFiller, gridBagConstraints);
267 
268  jTextPane1.setEditable(false);
269  jTextPane1.setBackground(javax.swing.UIManager.getDefaults().getColor("Label.background"));
270  jTextPane1.setText(org.openide.util.NbBundle.getMessage(CommandLineIngestSettingsPanel.class, "CommandLineIngestSettingsPanel.jTextPane1.text")); // NOI18N
271  gridBagConstraints = new java.awt.GridBagConstraints();
272  gridBagConstraints.gridx = 0;
273  gridBagConstraints.gridy = 1;
274  gridBagConstraints.gridwidth = 3;
275  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
276  gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
277  gridBagConstraints.insets = new java.awt.Insets(10, 5, 5, 5);
278  nodePanel.add(jTextPane1, gridBagConstraints);
279 
280  add(nodePanel, java.awt.BorderLayout.CENTER);
281  }// </editor-fold>//GEN-END:initComponents
282  @Messages({
283  "CommandListIngestSettingsPanel_Report_Name_Msg=Please supply a report profile name (letters, digits, and underscore characters only):",
284  "CommandLineIngestSettingPanel_empty_report_name_mgs=Report profile name was empty, no profile created.",
285  "CommandLineIngestSettingPanel_existing_report_name_mgs=Report profile name was already exists, no profile created.",
286  "CommandLineIngestSettingPanel_invalid_report_name_mgs=Report profile name contained illegal characters, no profile created."
287  })
288  private void bnEditReportSettingsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnEditReportSettingsActionPerformed
289  String reportName = getReportName();
290  if (reportName.equals(Bundle.CommandListIngestSettingsPanel_Make_Config())) {
291  reportName = JOptionPane.showInputDialog(this, Bundle.CommandListIngestSettingsPanel_Report_Name_Msg());
292 
293  // User hit cancel
294  if (reportName == null) {
295  return;
296  } else if (reportName.isEmpty()) {
297  JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), Bundle.CommandLineIngestSettingPanel_empty_report_name_mgs());
298  return;
299  } else if (doesReportProfileNameExist(reportName)) {
300  JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), Bundle.CommandLineIngestSettingPanel_existing_report_name_mgs());
301  return;
302  } else {
303  // sanitize report name
304  String originalReportName = reportName;
305  reportName = reportName.replaceAll("[^A-Za-z0-9_]", "");
306  if (reportName.isEmpty() || (!(originalReportName.equals(reportName)))) {
307  // report name contained only invalid characters, display error
308  JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), Bundle.CommandLineIngestSettingPanel_invalid_report_name_mgs());
309  return;
310  }
311  }
312  }
313 
314  this.getParent().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
315  doReportWizard(reportName, DISPLAY_CASE_SPECIFIC_DATA, RUN_REPORTS);
316 
317  setupReportList();
318 
319  if (((DefaultComboBoxModel) reportProfileCB.getModel()).getIndexOf(reportName) >= 0) {
320  reportProfileCB.setSelectedItem(reportName);
321  }
322 
323  this.getParent().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
324  }//GEN-LAST:event_bnEditReportSettingsActionPerformed
325 
326  private void bnEditIngestSettingsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnEditIngestSettingsActionPerformed
327  displayIngestJobSettingsPanel();
328  }//GEN-LAST:event_bnEditIngestSettingsActionPerformed
329 
330  // Variables declaration - do not modify//GEN-BEGIN:variables
331  private javax.swing.JButton bnEditIngestSettings;
332  private javax.swing.JButton bnEditReportSettings;
333  private javax.swing.JComboBox<String> ingestProfileCB;
334  private javax.swing.JTextPane jTextPane1;
335  private javax.swing.JPanel nodePanel;
336  private javax.swing.JComboBox<String> reportProfileCB;
337  // End of variables declaration//GEN-END:variables
338 }
static void doReportWizard(String configName, boolean displayCaseSpecificData, boolean runReports)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
CommandLineIngestSettingsPanel(CommandLineIngestSettingsPanelController theController)

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