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

Copyright © 2012-2020 Basis Technology. Generated on: Wed Apr 8 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.