Autopsy  4.19.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  noChangeRadioButton = new javax.swing.JRadioButton();
202 
203  setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
204 
205  org.openide.awt.Mnemonics.setLocalizedText(saveAsButton, org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.saveAsButton.text")); // NOI18N
206  saveAsButton.addActionListener(new java.awt.event.ActionListener() {
207  public void actionPerformed(java.awt.event.ActionEvent evt) {
208  saveAsButtonActionPerformed(evt);
209  }
210  });
211 
212  org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.cancelButton.text")); // NOI18N
213  cancelButton.addActionListener(new java.awt.event.ActionListener() {
214  public void actionPerformed(java.awt.event.ActionEvent evt) {
215  cancelButtonActionPerformed(evt);
216  }
217  });
218 
219  buttonGroup1.add(knownRadioButton);
220  org.openide.awt.Mnemonics.setLocalizedText(knownRadioButton, org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.knownRadioButton.text")); // NOI18N
221  knownRadioButton.addActionListener(new java.awt.event.ActionListener() {
222  public void actionPerformed(java.awt.event.ActionEvent evt) {
223  knownRadioButtonActionPerformed(evt);
224  }
225  });
226 
227  buttonGroup1.add(knownBadRadioButton);
228  knownBadRadioButton.setSelected(true);
229  org.openide.awt.Mnemonics.setLocalizedText(knownBadRadioButton, org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.knownBadRadioButton.text")); // NOI18N
230  knownBadRadioButton.addActionListener(new java.awt.event.ActionListener() {
231  public void actionPerformed(java.awt.event.ActionEvent evt) {
232  knownBadRadioButtonActionPerformed(evt);
233  }
234  });
235 
236  org.openide.awt.Mnemonics.setLocalizedText(databasePathLabel, org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.databasePathLabel.text")); // NOI18N
237 
238  hashSetNameTextField.setText(org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.hashSetNameTextField.text")); // NOI18N
239 
240  org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.jLabel2.text")); // NOI18N
241 
242  sendIngestMessagesCheckbox.setSelected(true);
243  org.openide.awt.Mnemonics.setLocalizedText(sendIngestMessagesCheckbox, org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.sendIngestMessagesCheckbox.text")); // NOI18N
244  sendIngestMessagesCheckbox.addActionListener(new java.awt.event.ActionListener() {
245  public void actionPerformed(java.awt.event.ActionEvent evt) {
246  sendIngestMessagesCheckboxActionPerformed(evt);
247  }
248  });
249 
250  org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.jLabel3.text")); // NOI18N
251 
252  databasePathTextField.setEditable(false);
253  databasePathTextField.setText(org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.databasePathTextField.text")); // NOI18N
254 
255  org.openide.awt.Mnemonics.setLocalizedText(okButton, org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.okButton.text")); // NOI18N
256  okButton.addActionListener(new java.awt.event.ActionListener() {
257  public void actionPerformed(java.awt.event.ActionEvent evt) {
258  okButtonActionPerformed(evt);
259  }
260  });
261 
262  org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.jLabel4.text")); // NOI18N
263 
264  storageTypeButtonGroup.add(fileTypeRadioButton);
265  fileTypeRadioButton.setSelected(true);
266  org.openide.awt.Mnemonics.setLocalizedText(fileTypeRadioButton, org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.fileTypeRadioButton.text")); // NOI18N
267  fileTypeRadioButton.addActionListener(new java.awt.event.ActionListener() {
268  public void actionPerformed(java.awt.event.ActionEvent evt) {
269  fileTypeRadioButtonActionPerformed(evt);
270  }
271  });
272 
273  storageTypeButtonGroup.add(centralRepoRadioButton);
274  org.openide.awt.Mnemonics.setLocalizedText(centralRepoRadioButton, org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.centralRepoRadioButton.text")); // NOI18N
275  centralRepoRadioButton.addActionListener(new java.awt.event.ActionListener() {
276  public void actionPerformed(java.awt.event.ActionEvent evt) {
277  centralRepoRadioButtonActionPerformed(evt);
278  }
279  });
280 
281  org.openide.awt.Mnemonics.setLocalizedText(lbOrg, org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.lbOrg.text")); // NOI18N
282 
283  orgComboBox.addActionListener(new java.awt.event.ActionListener() {
284  public void actionPerformed(java.awt.event.ActionEvent evt) {
285  orgComboBoxActionPerformed(evt);
286  }
287  });
288 
289  org.openide.awt.Mnemonics.setLocalizedText(orgButton, org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.orgButton.text")); // NOI18N
290  orgButton.addActionListener(new java.awt.event.ActionListener() {
291  public void actionPerformed(java.awt.event.ActionEvent evt) {
292  orgButtonActionPerformed(evt);
293  }
294  });
295 
296  buttonGroup1.add(noChangeRadioButton);
297  org.openide.awt.Mnemonics.setLocalizedText(noChangeRadioButton, org.openide.util.NbBundle.getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.noChangeRadioButton.text")); // NOI18N
298  noChangeRadioButton.addActionListener(new java.awt.event.ActionListener() {
299  public void actionPerformed(java.awt.event.ActionEvent evt) {
300  noChangeRadioButtonActionPerformed(evt);
301  }
302  });
303 
304  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
305  getContentPane().setLayout(layout);
306  layout.setHorizontalGroup(
307  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
308  .addGroup(layout.createSequentialGroup()
309  .addContainerGap()
310  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
311  .addGroup(layout.createSequentialGroup()
312  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
313  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
314  .addComponent(lbOrg)
315  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
316  .addComponent(orgComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
317  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
318  .addComponent(orgButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
319  .addGroup(layout.createSequentialGroup()
320  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
321  .addComponent(jLabel3)
322  .addComponent(jLabel4)
323  .addComponent(databasePathLabel))
324  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
325  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
326  .addGroup(layout.createSequentialGroup()
327  .addComponent(fileTypeRadioButton)
328  .addGap(22, 22, 22)
329  .addComponent(centralRepoRadioButton))
330  .addComponent(hashSetNameTextField)
331  .addComponent(databasePathTextField))))
332  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
333  .addComponent(saveAsButton))
334  .addGroup(layout.createSequentialGroup()
335  .addGap(0, 0, Short.MAX_VALUE)
336  .addComponent(okButton)
337  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
338  .addComponent(cancelButton)))
339  .addGap(88, 88, 88))
340  .addGroup(layout.createSequentialGroup()
341  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
342  .addGroup(layout.createSequentialGroup()
343  .addGap(32, 32, 32)
344  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
345  .addComponent(knownRadioButton)
346  .addComponent(knownBadRadioButton)
347  .addComponent(noChangeRadioButton)))
348  .addGroup(layout.createSequentialGroup()
349  .addGap(12, 12, 12)
350  .addComponent(jLabel2))
351  .addGroup(layout.createSequentialGroup()
352  .addGap(12, 12, 12)
353  .addComponent(sendIngestMessagesCheckbox)))
354  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
355  );
356 
357  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelButton, okButton});
358 
359  layout.setVerticalGroup(
360  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
361  .addGroup(layout.createSequentialGroup()
362  .addContainerGap()
363  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
364  .addComponent(jLabel4)
365  .addComponent(fileTypeRadioButton)
366  .addComponent(centralRepoRadioButton))
367  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
368  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
369  .addComponent(jLabel3)
370  .addComponent(hashSetNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
371  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
372  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
373  .addComponent(databasePathLabel)
374  .addComponent(databasePathTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
375  .addComponent(saveAsButton))
376  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
377  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
378  .addComponent(lbOrg)
379  .addComponent(orgComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
380  .addComponent(orgButton))
381  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
382  .addComponent(jLabel2)
383  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
384  .addComponent(knownRadioButton)
385  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
386  .addComponent(knownBadRadioButton)
387  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
388  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
389  .addGroup(layout.createSequentialGroup()
390  .addGap(0, 0, Short.MAX_VALUE)
391  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
392  .addComponent(cancelButton)
393  .addComponent(okButton)))
394  .addGroup(layout.createSequentialGroup()
395  .addComponent(noChangeRadioButton)
396  .addGap(24, 24, 24)
397  .addComponent(sendIngestMessagesCheckbox)
398  .addGap(0, 0, Short.MAX_VALUE)))
399  .addContainerGap())
400  );
401 
402  pack();
403  }// </editor-fold>//GEN-END:initComponents
404 
405  private void knownRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_knownRadioButtonActionPerformed
406  sendIngestMessagesCheckbox.setSelected(KnownFilesType.KNOWN.isDefaultInboxMessages());
407  sendIngestMessagesCheckbox.setEnabled(KnownFilesType.KNOWN.isInboxMessagesAllowed());
408  }//GEN-LAST:event_knownRadioButtonActionPerformed
409 
410  private void knownBadRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_knownBadRadioButtonActionPerformed
411  sendIngestMessagesCheckbox.setSelected(KnownFilesType.KNOWN_BAD.isDefaultInboxMessages());
412  sendIngestMessagesCheckbox.setEnabled(KnownFilesType.KNOWN_BAD.isInboxMessagesAllowed());
413  }//GEN-LAST:event_knownBadRadioButtonActionPerformed
414 
415  private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
416  dispose();
417  }//GEN-LAST:event_cancelButtonActionPerformed
418 
419  private void saveAsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveAsButtonActionPerformed
420  try {
421  String lastBaseDirectory = Paths.get(PlatformUtil.getUserConfigDirectory(), HASH_DATABASE_DIR_NAME).toString();
422  if (ModuleSettings.settingExists(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY)) {
423  lastBaseDirectory = ModuleSettings.getConfigSetting(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY);
424  }
425  StringBuilder path = new StringBuilder();
426  path.append(lastBaseDirectory);
427  File hashDbFolder = new File(path.toString());
428  // create the folder if it doesn't exist
429  if (!hashDbFolder.exists()) {
430  hashDbFolder.mkdir();
431  }
432  if (!hashSetNameTextField.getText().isEmpty()) {
433  path.append(File.separator).append(hashSetNameTextField.getText());
434  } else {
435  path.append(File.separator).append(DEFAULT_FILE_NAME);
436  }
437  path.append(".").append(HashDbManager.getHashDatabaseFileExtension());
438  fileChooser.setSelectedFile(new File(path.toString()));
439  if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
440  File databaseFile = fileChooser.getSelectedFile();
441  databasePathTextField.setText(databaseFile.getCanonicalPath());
442  ModuleSettings.setConfigSetting(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY, databaseFile.getParent());
443  }
444  } catch (IOException ex) {
445  Logger.getLogger(HashDbCreateDatabaseDialog.class.getName()).log(Level.WARNING, "Couldn't get selected file path.", ex); //NON-NLS
446  }
447  }//GEN-LAST:event_saveAsButtonActionPerformed
448 
449  @NbBundle.Messages({"HashDbCreateDatabaseDialog.missingOrg=An organization must be selected",
450  "HashDbCreateDatabaseDialog.duplicateName=A hashset with this name already exists",
451  "HashDbCreateDatabaseDialog.databaseLookupError=Error accessing central repository",
452  "HashDbCreateDatabaseDialog.databaseCreationError=Error creating new hash set"
453  })
454  private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
455  // Note that the error handlers in this method call return without disposing of the
456  // dialog to allow the user to try again, if desired.
457 
458  if (hashSetNameTextField.getText().isEmpty()) {
459  JOptionPane.showMessageDialog(this,
460  NbBundle.getMessage(this.getClass(),
461  "HashDbCreateDatabaseDialog.mustEnterHashSetNameMsg"),
462  NbBundle.getMessage(this.getClass(),
463  "HashDbCreateDatabaseDialog.createHashDbErr"),
464  JOptionPane.ERROR_MESSAGE);
465  return;
466  }
467 
468  if (fileTypeRadioButton.isSelected()) {
469  if (databasePathTextField.getText().isEmpty()) {
470  JOptionPane.showMessageDialog(this,
471  NbBundle.getMessage(this.getClass(),
472  "HashDbCreateDatabaseDialog.mustEnterHashDbPathMsg"),
473  NbBundle.getMessage(this.getClass(),
474  "HashDbCreateDatabaseDialog.createHashDbErr"),
475  JOptionPane.ERROR_MESSAGE);
476  return;
477  }
478  } else {
479  if (selectedOrg == null) {
480  JOptionPane.showMessageDialog(this,
481  NbBundle.getMessage(this.getClass(),
482  "HashDbCreateDatabaseDialog.missingOrg"),
483  NbBundle.getMessage(this.getClass(),
484  "HashDbCreateDatabaseDialog.createHashDbErr"),
485  JOptionPane.ERROR_MESSAGE);
486  return;
487  }
488  }
489 
490  KnownFilesType type;
491 
492  if (knownRadioButton.isSelected()) {
493  type = KnownFilesType.KNOWN;
494  } else if (noChangeRadioButton.isSelected()) {
495  type = KnownFilesType.NO_CHANGE;
496  } else {
497  type = KnownFilesType.KNOWN_BAD;
498  }
499 
500  TskData.FileKnown fileKnown = type.getFileKnown();
501 
502  String errorMessage = NbBundle
503  .getMessage(this.getClass(), "HashDbCreateDatabaseDialog.errMsg.hashDbCreationErr");
504 
505  if (fileTypeRadioButton.isSelected()) {
506  try {
507  newHashDb = HashDbManager.getInstance().addNewHashDatabaseNoSave(hashSetNameTextField.getText(), fileChooser.getSelectedFile().getCanonicalPath(), true, sendIngestMessagesCheckbox.isSelected(), type);
508  } catch (IOException ex) {
509  Logger.getLogger(HashDbCreateDatabaseDialog.class.getName()).log(Level.WARNING, errorMessage, ex);
510  JOptionPane.showMessageDialog(this,
511  NbBundle.getMessage(this.getClass(),
512  "HashDbCreateDatabaseDialog.cannotCreateFileAtLocMsg"),
513  NbBundle.getMessage(this.getClass(),
514  "HashDbCreateDatabaseDialog.createHashDbErr"),
515  JOptionPane.ERROR_MESSAGE);
516  return;
517  } catch (HashDbManagerException ex) {
518  Logger.getLogger(HashDbCreateDatabaseDialog.class.getName()).log(Level.WARNING, errorMessage, ex);
519  JOptionPane.showMessageDialog(this,
520  ex.getMessage(),
521  NbBundle.getMessage(this.getClass(),
522  "HashDbCreateDatabaseDialog.createHashDbErr"),
523  JOptionPane.ERROR_MESSAGE);
524  return;
525  }
526  } else {
527  // Check if a hash set with the same name/version already exists
528  try {
529  if (CentralRepository.getInstance().referenceSetExists(hashSetNameTextField.getText(), "")) {
530  JOptionPane.showMessageDialog(this,
531  NbBundle.getMessage(this.getClass(),
532  "HashDbCreateDatabaseDialog.duplicateName"),
533  NbBundle.getMessage(this.getClass(),
534  "HashDbCreateDatabaseDialog.createHashDbErr"),
535  JOptionPane.ERROR_MESSAGE);
536  return;
537  }
538  } catch (CentralRepoException ex) {
539  Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.SEVERE, "Error looking up reference set", ex);
540  JOptionPane.showMessageDialog(this,
541  NbBundle.getMessage(this.getClass(),
542  "HashDbCreateDatabaseDialog.databaseLookupError"),
543  NbBundle.getMessage(this.getClass(),
544  "HashDbCreateDatabaseDialog.createHashDbErr"),
545  JOptionPane.ERROR_MESSAGE);
546  return;
547  }
548 
549  try {
550  int referenceSetID = CentralRepository.getInstance().newReferenceSet(new CentralRepoFileSet(selectedOrg.getOrgID(), hashSetNameTextField.getText(),
551  "", fileKnown, false, CentralRepository.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.FILES_TYPE_ID)));
552  newHashDb = HashDbManager.getInstance().addExistingCentralRepoHashSet(hashSetNameTextField.getText(),
553  "", referenceSetID,
554  true, sendIngestMessagesCheckbox.isSelected(), type, false);
555  } catch (CentralRepoException | TskCoreException ex) {
556  Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.SEVERE, "Error creating new reference set", ex);
557  JOptionPane.showMessageDialog(this,
558  NbBundle.getMessage(this.getClass(),
559  "HashDbCreateDatabaseDialog.databaseCreationError"),
560  NbBundle.getMessage(this.getClass(),
561  "HashDbCreateDatabaseDialog.createHashDbErr"),
562  JOptionPane.ERROR_MESSAGE);
563  return;
564  }
565  }
566 
567  dispose();
568  }//GEN-LAST:event_okButtonActionPerformed
569 
570  private void sendIngestMessagesCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendIngestMessagesCheckboxActionPerformed
571  // TODO add your handling code here:
572  }//GEN-LAST:event_sendIngestMessagesCheckboxActionPerformed
573 
574  private void orgButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_orgButtonActionPerformed
575  ManageOrganizationsDialog dialog = new ManageOrganizationsDialog();
576  // update the combobox options
577  if (dialog.isChanged()) {
578  populateCombobox();
579  }
580  }//GEN-LAST:event_orgButtonActionPerformed
581 
582  private void orgComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_orgComboBoxActionPerformed
583  if (null == orgComboBox.getSelectedItem()) {
584  return;
585  }
586  String orgName = this.orgComboBox.getSelectedItem().toString();
587  for (CentralRepoOrganization org : orgs) {
588  if (org.getName().equals(orgName)) {
589  selectedOrg = org;
590  return;
591  }
592  }
593  }//GEN-LAST:event_orgComboBoxActionPerformed
594 
595  private void fileTypeRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileTypeRadioButtonActionPerformed
596  enableComponents();
597  }//GEN-LAST:event_fileTypeRadioButtonActionPerformed
598 
599  private void centralRepoRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_centralRepoRadioButtonActionPerformed
600  enableComponents();
601  }//GEN-LAST:event_centralRepoRadioButtonActionPerformed
602 
603  private void noChangeRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_noChangeRadioButtonActionPerformed
604  sendIngestMessagesCheckbox.setSelected(KnownFilesType.NO_CHANGE.isDefaultInboxMessages());
605  sendIngestMessagesCheckbox.setEnabled(KnownFilesType.NO_CHANGE.isInboxMessagesAllowed());
606  }//GEN-LAST:event_noChangeRadioButtonActionPerformed
607 
608  // Variables declaration - do not modify//GEN-BEGIN:variables
609  private javax.swing.ButtonGroup buttonGroup1;
610  private javax.swing.JButton cancelButton;
611  private javax.swing.JRadioButton centralRepoRadioButton;
612  private javax.swing.JLabel databasePathLabel;
613  private javax.swing.JTextField databasePathTextField;
614  private javax.swing.JRadioButton fileTypeRadioButton;
615  private javax.swing.JTextField hashSetNameTextField;
616  private javax.swing.JLabel jLabel2;
617  private javax.swing.JLabel jLabel3;
618  private javax.swing.JLabel jLabel4;
619  private javax.swing.JRadioButton knownBadRadioButton;
620  private javax.swing.JRadioButton knownRadioButton;
621  private javax.swing.JLabel lbOrg;
622  private javax.swing.JRadioButton noChangeRadioButton;
623  private javax.swing.JButton okButton;
624  private javax.swing.JButton orgButton;
625  private javax.swing.JComboBox<String> orgComboBox;
626  private javax.swing.JButton saveAsButton;
627  private javax.swing.JCheckBox sendIngestMessagesCheckbox;
628  private javax.swing.ButtonGroup storageTypeButtonGroup;
629  // End of variables declaration//GEN-END:variables
630 }

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