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

Copyright © 2012-2021 Basis Technology. Generated on: Thu Sep 30 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.