Autopsy  4.20.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
HashDbCreateDatabaseDialog.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013-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.modules.hashdatabase;
20 
21 import java.io.File;
22 import java.io.IOException;
23 import java.nio.file.Paths;
24 import java.util.List;
25 import java.util.logging.Level;
26 import javax.swing.JFileChooser;
27 import javax.swing.JFrame;
28 import javax.swing.JOptionPane;
29 import org.apache.commons.io.FilenameUtils;
30 import org.openide.util.NbBundle;
31 import org.openide.windows.WindowManager;
43 import org.sleuthkit.datamodel.TskData;
44 import org.sleuthkit.datamodel.TskCoreException;
48 
54 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
55 final class HashDbCreateDatabaseDialog extends javax.swing.JDialog {
56 
57  private static final String DEFAULT_FILE_NAME = NbBundle
58  .getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.defaultFileName");
59  private static final long serialVersionUID = 1L;
60  private JFileChooser fileChooser = null;
61  private HashDb newHashDb = null;
62  private final static String LAST_FILE_PATH_KEY = "HashDbCreate_Path";
63  private CentralRepoOrganization selectedOrg = null;
64  private List<CentralRepoOrganization> orgs = null;
65  static final String HASH_DATABASE_DIR_NAME = "HashDatabases";
66  private final JFileChooserFactory chooserFactory;
67 
73  HashDbCreateDatabaseDialog() {
74  super((JFrame) WindowManager.getDefault().getMainWindow(), NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.createHashDbMsg"), true);
75  initComponents();
76  chooserFactory = new JFileChooserFactory(CustomFileChooser.class);
77  enableComponents();
78  display();
79 
80  }
81 
87  HashDb getHashDatabase() {
88  return newHashDb;
89  }
90 
91  private void display() {
92  setLocationRelativeTo(getOwner());
93  setVisible(true);
94  }
95 
96  private void enableComponents() {
97 
98  if (!CentralRepository.isEnabled() || !FeatureAccessUtils.canAddHashSetsToCentralRepo()) {
99  centralRepoRadioButton.setEnabled(false);
100  fileTypeRadioButton.setSelected(true);
101  } else {
102  populateCombobox();
103  }
104 
105  boolean isFileType = fileTypeRadioButton.isSelected();
106 
107  // Type type only
108  databasePathLabel.setEnabled(isFileType);
109  databasePathTextField.setEnabled(isFileType);
110  saveAsButton.setEnabled(isFileType);
111 
112  // Central repo only
113  lbOrg.setEnabled(!isFileType);
114  orgButton.setEnabled(!isFileType);
115  orgComboBox.setEnabled(!isFileType);
116  }
117 
118  @NbBundle.Messages({"HashDbCreateDatabaseDialog.populateOrgsError.message=Failure loading organizations."})
119  private void populateCombobox() {
120  orgComboBox.removeAllItems();
121  try {
122  CentralRepository dbManager = CentralRepository.getInstance();
123  orgs = dbManager.getOrganizations();
124  orgs.forEach((org) -> {
125  orgComboBox.addItem(org.getName());
126  if (CentralRepoDbUtil.isDefaultOrg(org)) {
127  orgComboBox.setSelectedItem(org.getName());
128  selectedOrg = org;
129  }
130  });
131  if ((selectedOrg == null) && (!orgs.isEmpty())) {
132  selectedOrg = orgs.get(0);
133  }
134  } catch (CentralRepoException ex) {
135  JOptionPane.showMessageDialog(this, Bundle.HashDbCreateDatabaseDialog_populateOrgsError_message());
136  Logger.getLogger(ImportCentralRepoDbProgressDialog.class.getName()).log(Level.SEVERE, "Failure loading organizations", ex);
137  }
138  }
139 
143  public static class CustomFileChooser extends JFileChooser {
144 
145  private static final long serialVersionUID = 1L;
146 
147  @Override
148  public void approveSelection() {
149  File selectedFile = getSelectedFile();
150  if (!FilenameUtils.getExtension(selectedFile.getName()).equalsIgnoreCase(HashDbManager.getHashDatabaseFileExtension())) {
151  if (JOptionPane.showConfirmDialog(this,
152  NbBundle.getMessage(this.getClass(),
153  "HashDbCreateDatabaseDialog.hashDbMustHaveFileExtensionMsg",
154  HashDbManager.getHashDatabaseFileExtension()),
155  NbBundle.getMessage(this.getClass(),
156  "HashDbCreateDatabaseDialog.fileNameErr"),
157  JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) {
158  cancelSelection();
159  }
160  return;
161  }
162  if (selectedFile.exists()) {
163  if (JOptionPane.showConfirmDialog(this,
164  NbBundle.getMessage(this.getClass(),
165  "HashDbCreateDatabaseDialog.fileNameAlreadyExistsMsg"),
166  NbBundle.getMessage(this.getClass(),
167  "HashDbCreateDatabaseDialog.fileExistsErr"),
168  JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) {
169  cancelSelection();
170  }
171  return;
172  }
173  super.approveSelection();
174  }
175  }
176 
182  @SuppressWarnings("unchecked")
183  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
184  private void initComponents() {
185 
186  buttonGroup1 = new javax.swing.ButtonGroup();
187  storageTypeButtonGroup = new javax.swing.ButtonGroup();
188  saveAsButton = new javax.swing.JButton();
189  cancelButton = new javax.swing.JButton();
190  knownRadioButton = new javax.swing.JRadioButton();
191  knownBadRadioButton = new javax.swing.JRadioButton();
192  databasePathLabel = new javax.swing.JLabel();
193  hashSetNameTextField = new javax.swing.JTextField();
194  jLabel2 = new javax.swing.JLabel();
195  sendIngestMessagesCheckbox = new javax.swing.JCheckBox();
196  jLabel3 = new javax.swing.JLabel();
197  databasePathTextField = new javax.swing.JTextField();
198  okButton = new javax.swing.JButton();
199  jLabel4 = new javax.swing.JLabel();
200  fileTypeRadioButton = new javax.swing.JRadioButton();
201  centralRepoRadioButton = new javax.swing.JRadioButton();
202  lbOrg = new javax.swing.JLabel();
203  orgComboBox = new javax.swing.JComboBox<>();
204  orgButton = new javax.swing.JButton();
205  noChangeRadioButton = new javax.swing.JRadioButton();
206 
207  setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
208 
209  org.openide.awt.Mnemonics.setLocalizedText(saveAsButton, org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.saveAsButton.text")); // NOI18N
210  saveAsButton.addActionListener(new java.awt.event.ActionListener() {
211  public void actionPerformed(java.awt.event.ActionEvent evt) {
212  saveAsButtonActionPerformed(evt);
213  }
214  });
215 
216  org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.cancelButton.text")); // NOI18N
217  cancelButton.addActionListener(new java.awt.event.ActionListener() {
218  public void actionPerformed(java.awt.event.ActionEvent evt) {
219  cancelButtonActionPerformed(evt);
220  }
221  });
222 
223  buttonGroup1.add(knownRadioButton);
224  org.openide.awt.Mnemonics.setLocalizedText(knownRadioButton, org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.knownRadioButton.text")); // NOI18N
225  knownRadioButton.addActionListener(new java.awt.event.ActionListener() {
226  public void actionPerformed(java.awt.event.ActionEvent evt) {
227  knownRadioButtonActionPerformed(evt);
228  }
229  });
230 
231  buttonGroup1.add(knownBadRadioButton);
232  knownBadRadioButton.setSelected(true);
233  org.openide.awt.Mnemonics.setLocalizedText(knownBadRadioButton, org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.knownBadRadioButton.text")); // NOI18N
234  knownBadRadioButton.addActionListener(new java.awt.event.ActionListener() {
235  public void actionPerformed(java.awt.event.ActionEvent evt) {
236  knownBadRadioButtonActionPerformed(evt);
237  }
238  });
239 
240  org.openide.awt.Mnemonics.setLocalizedText(databasePathLabel, org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.databasePathLabel.text")); // NOI18N
241 
242  hashSetNameTextField.setText(org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.hashSetNameTextField.text")); // NOI18N
243 
244  org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.jLabel2.text")); // NOI18N
245 
246  sendIngestMessagesCheckbox.setSelected(true);
247  org.openide.awt.Mnemonics.setLocalizedText(sendIngestMessagesCheckbox, org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.sendIngestMessagesCheckbox.text")); // NOI18N
248  sendIngestMessagesCheckbox.addActionListener(new java.awt.event.ActionListener() {
249  public void actionPerformed(java.awt.event.ActionEvent evt) {
250  sendIngestMessagesCheckboxActionPerformed(evt);
251  }
252  });
253 
254  org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.jLabel3.text")); // NOI18N
255 
256  databasePathTextField.setEditable(false);
257  databasePathTextField.setText(org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.databasePathTextField.text")); // NOI18N
258 
259  org.openide.awt.Mnemonics.setLocalizedText(okButton, org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.okButton.text")); // NOI18N
260  okButton.addActionListener(new java.awt.event.ActionListener() {
261  public void actionPerformed(java.awt.event.ActionEvent evt) {
262  okButtonActionPerformed(evt);
263  }
264  });
265 
266  org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.jLabel4.text")); // NOI18N
267 
268  storageTypeButtonGroup.add(fileTypeRadioButton);
269  fileTypeRadioButton.setSelected(true);
270  org.openide.awt.Mnemonics.setLocalizedText(fileTypeRadioButton, org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.fileTypeRadioButton.text")); // NOI18N
271  fileTypeRadioButton.addActionListener(new java.awt.event.ActionListener() {
272  public void actionPerformed(java.awt.event.ActionEvent evt) {
273  fileTypeRadioButtonActionPerformed(evt);
274  }
275  });
276 
277  storageTypeButtonGroup.add(centralRepoRadioButton);
278  org.openide.awt.Mnemonics.setLocalizedText(centralRepoRadioButton, org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.centralRepoRadioButton.text")); // NOI18N
279  centralRepoRadioButton.addActionListener(new java.awt.event.ActionListener() {
280  public void actionPerformed(java.awt.event.ActionEvent evt) {
281  centralRepoRadioButtonActionPerformed(evt);
282  }
283  });
284 
285  org.openide.awt.Mnemonics.setLocalizedText(lbOrg, org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.lbOrg.text")); // NOI18N
286 
287  orgComboBox.addActionListener(new java.awt.event.ActionListener() {
288  public void actionPerformed(java.awt.event.ActionEvent evt) {
289  orgComboBoxActionPerformed(evt);
290  }
291  });
292 
293  org.openide.awt.Mnemonics.setLocalizedText(orgButton, org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.orgButton.text")); // NOI18N
294  orgButton.addActionListener(new java.awt.event.ActionListener() {
295  public void actionPerformed(java.awt.event.ActionEvent evt) {
296  orgButtonActionPerformed(evt);
297  }
298  });
299 
300  buttonGroup1.add(noChangeRadioButton);
301  org.openide.awt.Mnemonics.setLocalizedText(noChangeRadioButton, org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.noChangeRadioButton.text")); // NOI18N
302  noChangeRadioButton.addActionListener(new java.awt.event.ActionListener() {
303  public void actionPerformed(java.awt.event.ActionEvent evt) {
304  noChangeRadioButtonActionPerformed(evt);
305  }
306  });
307 
308  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
309  getContentPane().setLayout(layout);
310  layout.setHorizontalGroup(
311  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
312  .addGroup(layout.createSequentialGroup()
313  .addContainerGap()
314  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
315  .addGroup(layout.createSequentialGroup()
316  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
317  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
318  .addComponent(lbOrg)
319  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
320  .addComponent(orgComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
321  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
322  .addComponent(orgButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
323  .addGroup(layout.createSequentialGroup()
324  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
325  .addComponent(jLabel3)
326  .addComponent(jLabel4)
327  .addComponent(databasePathLabel))
328  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
329  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
330  .addGroup(layout.createSequentialGroup()
331  .addComponent(fileTypeRadioButton)
332  .addGap(22, 22, 22)
333  .addComponent(centralRepoRadioButton))
334  .addComponent(hashSetNameTextField)
335  .addComponent(databasePathTextField))))
336  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
337  .addComponent(saveAsButton))
338  .addGroup(layout.createSequentialGroup()
339  .addGap(0, 0, Short.MAX_VALUE)
340  .addComponent(okButton)
341  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
342  .addComponent(cancelButton)))
343  .addGap(88, 88, 88))
344  .addGroup(layout.createSequentialGroup()
345  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
346  .addGroup(layout.createSequentialGroup()
347  .addGap(32, 32, 32)
348  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
349  .addComponent(knownRadioButton)
350  .addComponent(knownBadRadioButton)
351  .addComponent(noChangeRadioButton)))
352  .addGroup(layout.createSequentialGroup()
353  .addGap(12, 12, 12)
354  .addComponent(jLabel2))
355  .addGroup(layout.createSequentialGroup()
356  .addGap(12, 12, 12)
357  .addComponent(sendIngestMessagesCheckbox)))
358  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
359  );
360 
361  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelButton, okButton});
362 
363  layout.setVerticalGroup(
364  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
365  .addGroup(layout.createSequentialGroup()
366  .addContainerGap()
367  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
368  .addComponent(jLabel4)
369  .addComponent(fileTypeRadioButton)
370  .addComponent(centralRepoRadioButton))
371  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
372  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
373  .addComponent(jLabel3)
374  .addComponent(hashSetNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
375  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
376  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
377  .addComponent(databasePathLabel)
378  .addComponent(databasePathTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
379  .addComponent(saveAsButton))
380  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
381  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
382  .addComponent(lbOrg)
383  .addComponent(orgComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
384  .addComponent(orgButton))
385  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
386  .addComponent(jLabel2)
387  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
388  .addComponent(knownRadioButton)
389  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
390  .addComponent(knownBadRadioButton)
391  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
392  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
393  .addGroup(layout.createSequentialGroup()
394  .addGap(0, 0, Short.MAX_VALUE)
395  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
396  .addComponent(cancelButton)
397  .addComponent(okButton)))
398  .addGroup(layout.createSequentialGroup()
399  .addComponent(noChangeRadioButton)
400  .addGap(24, 24, 24)
401  .addComponent(sendIngestMessagesCheckbox)
402  .addGap(0, 0, Short.MAX_VALUE)))
403  .addContainerGap())
404  );
405 
406  pack();
407  }// </editor-fold>//GEN-END:initComponents
408 
409  private void knownRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_knownRadioButtonActionPerformed
410  sendIngestMessagesCheckbox.setSelected(KnownFilesType.KNOWN.isDefaultInboxMessages());
411  sendIngestMessagesCheckbox.setEnabled(KnownFilesType.KNOWN.isInboxMessagesAllowed());
412  }//GEN-LAST:event_knownRadioButtonActionPerformed
413 
414  private void knownBadRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_knownBadRadioButtonActionPerformed
415  sendIngestMessagesCheckbox.setSelected(KnownFilesType.KNOWN_BAD.isDefaultInboxMessages());
416  sendIngestMessagesCheckbox.setEnabled(KnownFilesType.KNOWN_BAD.isInboxMessagesAllowed());
417  }//GEN-LAST:event_knownBadRadioButtonActionPerformed
418 
419  private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
420  dispose();
421  }//GEN-LAST:event_cancelButtonActionPerformed
422 
423  private void saveAsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveAsButtonActionPerformed
424  try {
425  String lastBaseDirectory = HashLookupSettings.getDefaultDbPath();
426  if (ModuleSettings.settingExists(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY)) {
427  lastBaseDirectory = ModuleSettings.getConfigSetting(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY);
428  }
429  StringBuilder path = new StringBuilder();
430  path.append(lastBaseDirectory);
431  File hashDbFolder = new File(path.toString());
432  // create the folder if it doesn't exist
433  if (!hashDbFolder.exists()) {
434  hashDbFolder.mkdirs();
435  }
436  if (!hashSetNameTextField.getText().isEmpty()) {
437  path.append(File.separator).append(hashSetNameTextField.getText());
438  } else {
439  path.append(File.separator).append(DEFAULT_FILE_NAME);
440  }
441  path.append(".").append(HashDbManager.getHashDatabaseFileExtension());
442 
443  if(fileChooser == null) {
444  fileChooser = chooserFactory.getChooser();
445 
446  fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
447  fileChooser.setDragEnabled(false);
448  fileChooser.setMultiSelectionEnabled(false);
449  }
450 
451 
452  fileChooser.setSelectedFile(new File(path.toString()));
453  if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
454  File databaseFile = fileChooser.getSelectedFile();
455  databasePathTextField.setText(databaseFile.getCanonicalPath());
456  ModuleSettings.setConfigSetting(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY, databaseFile.getParent());
457  }
458  } catch (IOException ex) {
459  Logger.getLogger(HashDbCreateDatabaseDialog.class.getName()).log(Level.WARNING, "Couldn't get selected file path.", ex); //NON-NLS
460  }
461  }//GEN-LAST:event_saveAsButtonActionPerformed
462 
463  @NbBundle.Messages({"HashDbCreateDatabaseDialog.missingOrg=An organization must be selected",
464  "HashDbCreateDatabaseDialog.duplicateName=A hashset with this name already exists",
465  "HashDbCreateDatabaseDialog.databaseLookupError=Error accessing central repository",
466  "HashDbCreateDatabaseDialog.databaseCreationError=Error creating new hash set"
467  })
468  private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
469  // Note that the error handlers in this method call return without disposing of the
470  // dialog to allow the user to try again, if desired.
471 
472  if (hashSetNameTextField.getText().isEmpty()) {
473  JOptionPane.showMessageDialog(this,
474  NbBundle.getMessage(this.getClass(),
475  "HashDbCreateDatabaseDialog.mustEnterHashSetNameMsg"),
476  NbBundle.getMessage(this.getClass(),
477  "HashDbCreateDatabaseDialog.createHashDbErr"),
478  JOptionPane.ERROR_MESSAGE);
479  return;
480  }
481 
482  if (fileTypeRadioButton.isSelected()) {
483  if (databasePathTextField.getText().isEmpty()) {
484  JOptionPane.showMessageDialog(this,
485  NbBundle.getMessage(this.getClass(),
486  "HashDbCreateDatabaseDialog.mustEnterHashDbPathMsg"),
487  NbBundle.getMessage(this.getClass(),
488  "HashDbCreateDatabaseDialog.createHashDbErr"),
489  JOptionPane.ERROR_MESSAGE);
490  return;
491  }
492  } else {
493  if (selectedOrg == null) {
494  JOptionPane.showMessageDialog(this,
495  NbBundle.getMessage(this.getClass(),
496  "HashDbCreateDatabaseDialog.missingOrg"),
497  NbBundle.getMessage(this.getClass(),
498  "HashDbCreateDatabaseDialog.createHashDbErr"),
499  JOptionPane.ERROR_MESSAGE);
500  return;
501  }
502  }
503 
504  KnownFilesType type;
505 
506  if (knownRadioButton.isSelected()) {
507  type = KnownFilesType.KNOWN;
508  } else if (noChangeRadioButton.isSelected()) {
509  type = KnownFilesType.NO_CHANGE;
510  } else {
511  type = KnownFilesType.KNOWN_BAD;
512  }
513 
514  TskData.FileKnown fileKnown = type.getFileKnown();
515 
516  String errorMessage = NbBundle
517  .getMessage(this.getClass(), "HashDbCreateDatabaseDialog.errMsg.hashDbCreationErr");
518 
519  if (fileTypeRadioButton.isSelected()) {
520  try {
521  newHashDb = HashDbManager.getInstance().addNewHashDatabaseNoSave(hashSetNameTextField.getText(), fileChooser.getSelectedFile().getCanonicalPath(), true, sendIngestMessagesCheckbox.isSelected(), type);
522  } catch (IOException ex) {
523  Logger.getLogger(HashDbCreateDatabaseDialog.class.getName()).log(Level.WARNING, errorMessage, ex);
524  JOptionPane.showMessageDialog(this,
525  NbBundle.getMessage(this.getClass(),
526  "HashDbCreateDatabaseDialog.cannotCreateFileAtLocMsg"),
527  NbBundle.getMessage(this.getClass(),
528  "HashDbCreateDatabaseDialog.createHashDbErr"),
529  JOptionPane.ERROR_MESSAGE);
530  return;
531  } catch (HashDbManagerException ex) {
532  Logger.getLogger(HashDbCreateDatabaseDialog.class.getName()).log(Level.WARNING, errorMessage, ex);
533  JOptionPane.showMessageDialog(this,
534  ex.getMessage(),
535  NbBundle.getMessage(this.getClass(),
536  "HashDbCreateDatabaseDialog.createHashDbErr"),
537  JOptionPane.ERROR_MESSAGE);
538  return;
539  }
540  } else {
541  // Check if a hash set with the same name/version already exists
542  try {
543  if (CentralRepository.getInstance().referenceSetExists(hashSetNameTextField.getText(), "")) {
544  JOptionPane.showMessageDialog(this,
545  NbBundle.getMessage(this.getClass(),
546  "HashDbCreateDatabaseDialog.duplicateName"),
547  NbBundle.getMessage(this.getClass(),
548  "HashDbCreateDatabaseDialog.createHashDbErr"),
549  JOptionPane.ERROR_MESSAGE);
550  return;
551  }
552  } catch (CentralRepoException ex) {
553  Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.SEVERE, "Error looking up reference set", ex);
554  JOptionPane.showMessageDialog(this,
555  NbBundle.getMessage(this.getClass(),
556  "HashDbCreateDatabaseDialog.databaseLookupError"),
557  NbBundle.getMessage(this.getClass(),
558  "HashDbCreateDatabaseDialog.createHashDbErr"),
559  JOptionPane.ERROR_MESSAGE);
560  return;
561  }
562 
563  try {
564  int referenceSetID = CentralRepository.getInstance().newReferenceSet(new CentralRepoFileSet(selectedOrg.getOrgID(), hashSetNameTextField.getText(),
565  "", fileKnown, false, CentralRepository.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.FILES_TYPE_ID)));
566  newHashDb = HashDbManager.getInstance().addExistingCentralRepoHashSet(hashSetNameTextField.getText(),
567  "", referenceSetID,
568  true, sendIngestMessagesCheckbox.isSelected(), type, false);
569  } catch (CentralRepoException | TskCoreException ex) {
570  Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.SEVERE, "Error creating new reference set", ex);
571  JOptionPane.showMessageDialog(this,
572  NbBundle.getMessage(this.getClass(),
573  "HashDbCreateDatabaseDialog.databaseCreationError"),
574  NbBundle.getMessage(this.getClass(),
575  "HashDbCreateDatabaseDialog.createHashDbErr"),
576  JOptionPane.ERROR_MESSAGE);
577  return;
578  }
579  }
580 
581  dispose();
582  }//GEN-LAST:event_okButtonActionPerformed
583 
584  private void sendIngestMessagesCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendIngestMessagesCheckboxActionPerformed
585  // TODO add your handling code here:
586  }//GEN-LAST:event_sendIngestMessagesCheckboxActionPerformed
587 
588  private void orgButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_orgButtonActionPerformed
589  ManageOrganizationsDialog dialog = new ManageOrganizationsDialog();
590  // update the combobox options
591  if (dialog.isChanged()) {
592  populateCombobox();
593  }
594  }//GEN-LAST:event_orgButtonActionPerformed
595 
596  private void orgComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_orgComboBoxActionPerformed
597  if (null == orgComboBox.getSelectedItem()) {
598  return;
599  }
600  String orgName = this.orgComboBox.getSelectedItem().toString();
601  for (CentralRepoOrganization org : orgs) {
602  if (org.getName().equals(orgName)) {
603  selectedOrg = org;
604  return;
605  }
606  }
607  }//GEN-LAST:event_orgComboBoxActionPerformed
608 
609  private void fileTypeRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileTypeRadioButtonActionPerformed
610  enableComponents();
611  }//GEN-LAST:event_fileTypeRadioButtonActionPerformed
612 
613  private void centralRepoRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_centralRepoRadioButtonActionPerformed
614  enableComponents();
615  }//GEN-LAST:event_centralRepoRadioButtonActionPerformed
616 
617  private void noChangeRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_noChangeRadioButtonActionPerformed
618  sendIngestMessagesCheckbox.setSelected(KnownFilesType.NO_CHANGE.isDefaultInboxMessages());
619  sendIngestMessagesCheckbox.setEnabled(KnownFilesType.NO_CHANGE.isInboxMessagesAllowed());
620  }//GEN-LAST:event_noChangeRadioButtonActionPerformed
621 
622  // Variables declaration - do not modify//GEN-BEGIN:variables
623  private javax.swing.ButtonGroup buttonGroup1;
624  private javax.swing.JButton cancelButton;
625  private javax.swing.JRadioButton centralRepoRadioButton;
626  private javax.swing.JLabel databasePathLabel;
627  private javax.swing.JTextField databasePathTextField;
628  private javax.swing.JRadioButton fileTypeRadioButton;
629  private javax.swing.JTextField hashSetNameTextField;
630  private javax.swing.JLabel jLabel2;
631  private javax.swing.JLabel jLabel3;
632  private javax.swing.JLabel jLabel4;
633  private javax.swing.JRadioButton knownBadRadioButton;
634  private javax.swing.JRadioButton knownRadioButton;
635  private javax.swing.JLabel lbOrg;
636  private javax.swing.JRadioButton noChangeRadioButton;
637  private javax.swing.JButton okButton;
638  private javax.swing.JButton orgButton;
639  private javax.swing.JComboBox<String> orgComboBox;
640  private javax.swing.JButton saveAsButton;
641  private javax.swing.JCheckBox sendIngestMessagesCheckbox;
642  private javax.swing.ButtonGroup storageTypeButtonGroup;
643  // End of variables declaration//GEN-END:variables
644 }

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