From c6c5acba0fb58e4f045f9a1232f328e18cf5bae3 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Fri, 11 Aug 2017 13:58:16 -0400 Subject: [PATCH 01/13] 2934 changes to Central Repo Options panel and config dialog --- .../optionspanel/Bundle.properties | 15 +- .../optionspanel/EamDbSettingsDialog.form | 549 +++++--------- .../optionspanel/EamDbSettingsDialog.java | 697 +++++++----------- .../optionspanel/GlobalSettingsPanel.form | 19 +- .../optionspanel/GlobalSettingsPanel.java | 46 +- 5 files changed, 503 insertions(+), 823 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/Bundle.properties b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/Bundle.properties index 22a0ed7a5c..f05ff2b915 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/Bundle.properties @@ -13,7 +13,7 @@ EamSqliteSettingsDialog.bnCancel.text=Cancel EamSqliteSettingsDialog.lbTestDatabase.text= EamSqliteSettingsDialog.bnTestDatabase.text=Test Connection EamSqliteSettingsDialog.lbTestDatabaseWarning.text= -EamSqliteSettingsDialog.bnDatabasePathFileOpen.text=Open... +EamSqliteSettingsDialog.bnDatabasePathFileOpen.text=Browse... EamSqliteSettingsDialog.tfDatabasePath.toolTipText=Filename and path to store SQLite db file EamSqliteSettingsDialog.tfDatabasePath.text= EamSqliteSettingsDialog.lbDatabasePath.text=Database Path : @@ -52,24 +52,16 @@ ManageTagsDialog.cancelButton.text=Cancel ManageArtifactTypesDialog.taInstructionsMsg.text=Enable one or more correlation properties to use for correlation during ingest. Note, these properties are global and impact all users of the central repository. EamSqliteSettingsDialog.bnOk.text=OK EamPostgresSettingsDialog.bnSave.text=Save -EamDbSettingsDialog.pnDatabaseConnectionSettings.border.title=Database Settings -EamDbSettingsDialog.rdioBnPostgreSQL.text=PostgreSQL -EamDbSettingsDialog.rdioBnSQLite.text=SQLite -EamDbSettingsDialog.bnDatabasePathFileOpen.text=Open... +EamDbSettingsDialog.bnDatabasePathFileOpen.text=Browse... EamDbSettingsDialog.tfDatabasePath.toolTipText=Filename and path to store SQLite db file EamDbSettingsDialog.tfDatabasePath.text= EamDbSettingsDialog.lbDatabasePath.text=Database Path : -EamDbSettingsDialog.rdioBnDisabled.text=Disabled EamDbSettingsDialog.bnCancel.text=Cancel EamDbSettingsDialog.bnOk.text=OK -EamDbSettingsDialog.bnTest.text=Test EamDbSettingsDialog.lbHostName.text=Host Name / IP : -EamDbSettingsDialog.lbDatabaseName.text=Database name : EamDbSettingsDialog.lbUserPassword.text=User Password : EamDbSettingsDialog.lbUserName.text=User Name : EamDbSettingsDialog.lbPort.text=Port : -EamDbSettingsDialog.bnCreateDb.text=Create -EamDbSettingsDialog.pnSetupGuidance.border.title=Setup Guidance GlobalSettingsPanel.pnDatabaseConfiguration.title=Database Configuration GlobalSettingsPanel.lbDbPlatformTypeLabel.text=Type: GlobalSettingsPanel.lbDbNameLabel.text=Name: @@ -82,3 +74,6 @@ GlobalSettingsPanel.bnManageProperties.text=Manage Correlation Properties ImportHashDatabaseDialog.lbInstructions.text=Choose an .idx file to import into the central repository. ImportHashDatabaseDialog.lbFilePath.text=File Path: ImportHashDatabaseDialog.tfFilePath.text= +EamDbSettingsDialog.jLabel1.text=SQLite should only be used by one examiner at a time. +EamDbSettingsDialog.jLabel2.text=Database type: +GlobalSettingsPanel.jCheckBox1.text=Use a Central Repository diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.form b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.form index 93bfa8f3fd..81eb19ce47 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.form +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.form @@ -29,12 +29,11 @@ - - - - - - + + + + + @@ -43,303 +42,22 @@ - - + + - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -352,20 +70,11 @@ - - - - - - - - - - - - + + + - + @@ -391,40 +100,13 @@ - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - + + @@ -434,55 +116,186 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java index b3c282b607..81b4af2bd7 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java @@ -25,6 +25,7 @@ import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import org.netbeans.spi.options.OptionsPanelController; import org.openide.util.ImageUtilities; +import org.openide.util.NbBundle; import org.openide.util.NbBundle.Messages; import org.openide.windows.WindowManager; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb; @@ -32,6 +33,7 @@ import org.sleuthkit.autopsy.corecomponents.TextPrompt; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbPlatformEnum; +import static org.sleuthkit.autopsy.centralrepository.datamodel.EamDbPlatformEnum.SQLITE; import org.sleuthkit.autopsy.centralrepository.datamodel.PostgresEamDbSettings; import org.sleuthkit.autopsy.centralrepository.datamodel.SqliteEamDbSettings; @@ -40,7 +42,10 @@ import org.sleuthkit.autopsy.centralrepository.datamodel.SqliteEamDbSettings; * @author nick */ public class EamDbSettingsDialog extends JDialog { + private static final Logger LOGGER = Logger.getLogger(EamDbSettingsDialog.class.getName()); + private static final String CENTRAL_REPO_DB_NAME = "central_repository"; + private static final String CENTRAL_REPO_SQLITE_EXT = ".db"; private final Collection textBoxes; private final TextBoxChangedListener textBoxChangedListener; private final ImageIcon goodIcon; @@ -57,22 +62,29 @@ public class EamDbSettingsDialog extends JDialog { @Messages({"EamDbSettingsDialog.title.text=Central Repository Database Configuration"}) public EamDbSettingsDialog() { super((JFrame) WindowManager.getDefault().getMainWindow(), - Bundle.EamDbSettingsDialog_title_text(), - true); // NON-NLS + Bundle.EamDbSettingsDialog_title_text(), + true); // NON-NLS textBoxes = new ArrayList<>(); textBoxChangedListener = new TextBoxChangedListener(); goodIcon = new ImageIcon(ImageUtilities.loadImage("org/sleuthkit/autopsy/images/good.png", false)); // NON-NLS badIcon = new ImageIcon(ImageUtilities.loadImage("org/sleuthkit/autopsy/images/bad.png", false)); // NON-NLS - dbSettingsPostgres = new PostgresEamDbSettings(); dbSettingsSqlite = new SqliteEamDbSettings(); selectedPlatform = EamDbPlatformEnum.getSelectedPlatform(); - + if (selectedPlatform == null || selectedPlatform.equals(EamDbPlatformEnum.DISABLED)) { + selectedPlatform = EamDbPlatformEnum.POSTGRESQL; + } else { + System.out.println("selectedPlatform = " + selectedPlatform); + } + initComponents(); + fcDatabasePath.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + jComboBox1.setSelectedItem(selectedPlatform); customizeComponents(); valid(); display(); + } /** @@ -86,40 +98,61 @@ public class EamDbSettingsDialog extends JDialog { bnGrpDatabasePlatforms = new javax.swing.ButtonGroup(); fcDatabasePath = new javax.swing.JFileChooser(); - pnDatabaseConnectionSettings = new javax.swing.JPanel(); + pnButtons = new javax.swing.JPanel(); + bnCancel = new javax.swing.JButton(); + bnOk = new javax.swing.JButton(); pnSQLiteSettings = new javax.swing.JPanel(); lbDatabasePath = new javax.swing.JLabel(); tfDatabasePath = new javax.swing.JTextField(); bnDatabasePathFileOpen = new javax.swing.JButton(); - pnPostgreSQLSettings = new javax.swing.JPanel(); lbHostName = new javax.swing.JLabel(); - lbPort = new javax.swing.JLabel(); - lbUserName = new javax.swing.JLabel(); - lbUserPassword = new javax.swing.JLabel(); - lbDatabaseName = new javax.swing.JLabel(); tbDbHostname = new javax.swing.JTextField(); + lbPort = new javax.swing.JLabel(); tbDbPort = new javax.swing.JTextField(); - tbDbName = new javax.swing.JTextField(); + lbUserName = new javax.swing.JLabel(); tbDbUsername = new javax.swing.JTextField(); + lbUserPassword = new javax.swing.JLabel(); jpDbPassword = new javax.swing.JPasswordField(); - rdioBnSQLite = new javax.swing.JRadioButton(); - rdioBnPostgreSQL = new javax.swing.JRadioButton(); - rdioBnDisabled = new javax.swing.JRadioButton(); - pnButtons = new javax.swing.JPanel(); - bnCancel = new javax.swing.JButton(); - bnOk = new javax.swing.JButton(); - bnTest = new javax.swing.JButton(); - bnCreateDb = new javax.swing.JButton(); - lbTestIcon = new javax.swing.JLabel(); - lbCreateIcon = new javax.swing.JLabel(); - pnSetupGuidance = new javax.swing.JPanel(); - jScrollPane1 = new javax.swing.JScrollPane(); - taSetupGuidance = new javax.swing.JTextArea(); + jComboBox1 = new javax.swing.JComboBox<>(); + jLabel1 = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); - pnDatabaseConnectionSettings.setBorder(javax.swing.BorderFactory.createTitledBorder(null, org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.pnDatabaseConnectionSettings.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N - pnDatabaseConnectionSettings.setName(""); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(bnCancel, org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.bnCancel.text")); // NOI18N + bnCancel.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + bnCancelActionPerformed(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(bnOk, org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.bnOk.text")); // NOI18N + bnOk.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + bnOkActionPerformed(evt); + } + }); + + javax.swing.GroupLayout pnButtonsLayout = new javax.swing.GroupLayout(pnButtons); + pnButtons.setLayout(pnButtonsLayout); + pnButtonsLayout.setHorizontalGroup( + pnButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(pnButtonsLayout.createSequentialGroup() + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(bnOk) + .addGap(11, 11, 11) + .addComponent(bnCancel) + .addContainerGap()) + ); + pnButtonsLayout.setVerticalGroup( + pnButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(pnButtonsLayout.createSequentialGroup() + .addGap(0, 0, 0) + .addGroup(pnButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(bnOk) + .addComponent(bnCancel)) + .addGap(0, 0, 0)) + ); pnSQLiteSettings.setBorder(javax.swing.BorderFactory.createEtchedBorder()); @@ -140,32 +173,6 @@ public class EamDbSettingsDialog extends JDialog { } }); - javax.swing.GroupLayout pnSQLiteSettingsLayout = new javax.swing.GroupLayout(pnSQLiteSettings); - pnSQLiteSettings.setLayout(pnSQLiteSettingsLayout); - pnSQLiteSettingsLayout.setHorizontalGroup( - pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(pnSQLiteSettingsLayout.createSequentialGroup() - .addContainerGap() - .addComponent(lbDatabasePath) - .addGap(18, 18, 18) - .addComponent(tfDatabasePath, javax.swing.GroupLayout.PREFERRED_SIZE, 343, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(bnDatabasePathFileOpen) - .addContainerGap()) - ); - pnSQLiteSettingsLayout.setVerticalGroup( - pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(pnSQLiteSettingsLayout.createSequentialGroup() - .addContainerGap() - .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(lbDatabasePath, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(tfDatabasePath, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(bnDatabasePathFileOpen)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - - pnPostgreSQLSettings.setBorder(javax.swing.BorderFactory.createEtchedBorder()); - org.openide.awt.Mnemonics.setLocalizedText(lbHostName, org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.lbHostName.text")); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(lbPort, org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.lbPort.text")); // NOI18N @@ -174,286 +181,151 @@ public class EamDbSettingsDialog extends JDialog { org.openide.awt.Mnemonics.setLocalizedText(lbUserPassword, org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.lbUserPassword.text")); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(lbDatabaseName, org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.lbDatabaseName.text")); // NOI18N + jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new EamDbPlatformEnum[]{EamDbPlatformEnum.POSTGRESQL, EamDbPlatformEnum.SQLITE})); + jComboBox1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jComboBox1ActionPerformed(evt); + } + }); - javax.swing.GroupLayout pnPostgreSQLSettingsLayout = new javax.swing.GroupLayout(pnPostgreSQLSettings); - pnPostgreSQLSettings.setLayout(pnPostgreSQLSettingsLayout); - pnPostgreSQLSettingsLayout.setHorizontalGroup( - pnPostgreSQLSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(pnPostgreSQLSettingsLayout.createSequentialGroup() + org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.jLabel1.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.jLabel2.text")); // NOI18N + + javax.swing.GroupLayout pnSQLiteSettingsLayout = new javax.swing.GroupLayout(pnSQLiteSettings); + pnSQLiteSettings.setLayout(pnSQLiteSettingsLayout); + pnSQLiteSettingsLayout.setHorizontalGroup( + pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(pnSQLiteSettingsLayout.createSequentialGroup() .addContainerGap() - .addGroup(pnPostgreSQLSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(lbHostName) - .addComponent(lbPort) - .addComponent(lbDatabaseName) - .addComponent(lbUserName) - .addComponent(lbUserPassword)) - .addGap(18, 18, 18) - .addGroup(pnPostgreSQLSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(tbDbUsername, javax.swing.GroupLayout.DEFAULT_SIZE, 439, Short.MAX_VALUE) - .addComponent(tbDbName) - .addComponent(tbDbPort) - .addComponent(tbDbHostname) - .addComponent(jpDbPassword)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(pnSQLiteSettingsLayout.createSequentialGroup() + .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(lbHostName) + .addComponent(lbPort) + .addComponent(lbUserName) + .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(10, 10, 10)) + .addGroup(pnSQLiteSettingsLayout.createSequentialGroup() + .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(lbDatabasePath) + .addComponent(lbUserPassword, javax.swing.GroupLayout.Alignment.TRAILING)) + .addGap(14, 14, 14))) + .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(pnSQLiteSettingsLayout.createSequentialGroup() + .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 467, Short.MAX_VALUE) + .addGap(9, 9, 9)) + .addGroup(pnSQLiteSettingsLayout.createSequentialGroup() + .addComponent(tfDatabasePath) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(bnDatabasePathFileOpen) + .addGap(11, 11, 11)) + .addGroup(pnSQLiteSettingsLayout.createSequentialGroup() + .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(tbDbHostname) + .addComponent(jpDbPassword) + .addComponent(tbDbUsername, javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(tbDbPort)) + .addGap(10, 10, 10)))) ); - pnPostgreSQLSettingsLayout.setVerticalGroup( - pnPostgreSQLSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(pnPostgreSQLSettingsLayout.createSequentialGroup() - .addContainerGap() - .addGroup(pnPostgreSQLSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + pnSQLiteSettingsLayout.setVerticalGroup( + pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(pnSQLiteSettingsLayout.createSequentialGroup() + .addGap(6, 6, 6) + .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel1)) + .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(lbDatabasePath, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(tfDatabasePath, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(bnDatabasePathFileOpen)) + .addGap(0, 0, 0) + .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(tbDbHostname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(lbHostName, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(pnPostgreSQLSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(tbDbPort) + .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(tbDbPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(lbPort, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(pnPostgreSQLSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(tbDbName) - .addComponent(lbDatabaseName, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(pnPostgreSQLSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(tbDbUsername) + .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(tbDbUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(lbUserName, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(pnPostgreSQLSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(lbUserPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jpDbPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addContainerGap(19, Short.MAX_VALUE)) - ); - - org.openide.awt.Mnemonics.setLocalizedText(rdioBnSQLite, org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.rdioBnSQLite.text")); // NOI18N - rdioBnSQLite.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - rdioBnSQLiteActionPerformed(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(rdioBnPostgreSQL, org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.rdioBnPostgreSQL.text")); // NOI18N - rdioBnPostgreSQL.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - rdioBnPostgreSQLActionPerformed(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(rdioBnDisabled, org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.rdioBnDisabled.text")); // NOI18N - rdioBnDisabled.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - rdioBnDisabledActionPerformed(evt); - } - }); - - javax.swing.GroupLayout pnDatabaseConnectionSettingsLayout = new javax.swing.GroupLayout(pnDatabaseConnectionSettings); - pnDatabaseConnectionSettings.setLayout(pnDatabaseConnectionSettingsLayout); - pnDatabaseConnectionSettingsLayout.setHorizontalGroup( - pnDatabaseConnectionSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(pnDatabaseConnectionSettingsLayout.createSequentialGroup() - .addComponent(rdioBnPostgreSQL) - .addGap(0, 0, Short.MAX_VALUE)) - .addGroup(pnDatabaseConnectionSettingsLayout.createSequentialGroup() - .addGroup(pnDatabaseConnectionSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(rdioBnSQLite) - .addComponent(rdioBnDisabled)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGroup(pnDatabaseConnectionSettingsLayout.createSequentialGroup() - .addContainerGap() - .addGroup(pnDatabaseConnectionSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(pnSQLiteSettings, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(pnPostgreSQLSettings, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) - ); - pnDatabaseConnectionSettingsLayout.setVerticalGroup( - pnDatabaseConnectionSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnDatabaseConnectionSettingsLayout.createSequentialGroup() - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(rdioBnDisabled) - .addGap(13, 13, 13) - .addComponent(rdioBnSQLite) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(pnSQLiteSettings, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(12, 12, 12) - .addComponent(rdioBnPostgreSQL) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(pnPostgreSQLSettings, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(329, 329, 329)) - ); - - org.openide.awt.Mnemonics.setLocalizedText(bnCancel, org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.bnCancel.text")); // NOI18N - bnCancel.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - bnCancelActionPerformed(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(bnOk, org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.bnOk.text")); // NOI18N - bnOk.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - bnOkActionPerformed(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(bnTest, org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.bnTest.text")); // NOI18N - bnTest.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - bnTestActionPerformed(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(bnCreateDb, org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.bnCreateDb.text")); // NOI18N - bnCreateDb.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - bnCreateDbActionPerformed(evt); - } - }); - - javax.swing.GroupLayout pnButtonsLayout = new javax.swing.GroupLayout(pnButtons); - pnButtons.setLayout(pnButtonsLayout); - pnButtonsLayout.setHorizontalGroup( - pnButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(pnButtonsLayout.createSequentialGroup() - .addContainerGap() - .addComponent(bnTest) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(lbTestIcon, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(18, 18, 18) - .addComponent(bnCreateDb) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(lbCreateIcon, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(bnOk) - .addGap(11, 11, 11) - .addComponent(bnCancel) - .addContainerGap()) - ); - pnButtonsLayout.setVerticalGroup( - pnButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(pnButtonsLayout.createSequentialGroup() - .addGap(0, 0, 0) - .addGroup(pnButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(lbCreateIcon, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(lbTestIcon, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(pnButtonsLayout.createSequentialGroup() - .addGroup(pnButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(bnOk) - .addComponent(bnCancel) - .addComponent(bnTest) - .addComponent(bnCreateDb)) - .addGap(0, 0, Short.MAX_VALUE))) - .addContainerGap()) - ); - - pnSetupGuidance.setBorder(javax.swing.BorderFactory.createTitledBorder(null, org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.pnSetupGuidance.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N - - jScrollPane1.setBorder(null); - - taSetupGuidance.setEditable(false); - taSetupGuidance.setBackground(new java.awt.Color(240, 240, 240)); - taSetupGuidance.setColumns(20); - taSetupGuidance.setFont(new java.awt.Font("Monospaced", 0, 12)); // NOI18N - taSetupGuidance.setLineWrap(true); - taSetupGuidance.setRows(3); - taSetupGuidance.setTabSize(4); - taSetupGuidance.setWrapStyleWord(true); - taSetupGuidance.setAutoscrolls(false); - taSetupGuidance.setBorder(null); - taSetupGuidance.setRequestFocusEnabled(false); - taSetupGuidance.setVerifyInputWhenFocusTarget(false); - jScrollPane1.setViewportView(taSetupGuidance); - - javax.swing.GroupLayout pnSetupGuidanceLayout = new javax.swing.GroupLayout(pnSetupGuidance); - pnSetupGuidance.setLayout(pnSetupGuidanceLayout); - pnSetupGuidanceLayout.setHorizontalGroup( - pnSetupGuidanceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(pnSetupGuidanceLayout.createSequentialGroup() - .addContainerGap() - .addComponent(jScrollPane1) - .addContainerGap()) - ); - pnSetupGuidanceLayout.setVerticalGroup( - pnSetupGuidanceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(pnSetupGuidanceLayout.createSequentialGroup() - .addContainerGap() - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGap(10, 10, 10)) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGroup(layout.createSequentialGroup() .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(pnSetupGuidance, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(pnDatabaseConnectionSettings, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(pnButtons, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(pnButtons, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(pnSQLiteSettings, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(pnSetupGuidance, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(10, 10, 10) + .addComponent(pnSQLiteSettings, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(pnDatabaseConnectionSettings, javax.swing.GroupLayout.PREFERRED_SIZE, 348, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(pnButtons, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(0, 0, 0)) + .addGap(10, 10, 10)) ); pack(); }// //GEN-END:initComponents private void customizeComponents() { - bnGrpDatabasePlatforms.add(rdioBnDisabled); - bnGrpDatabasePlatforms.add(rdioBnPostgreSQL); - bnGrpDatabasePlatforms.add(rdioBnSQLite); - + setTextPrompts(); + setTextBoxListeners(); switch (selectedPlatform) { - case POSTGRESQL: - rdioBnPostgreSQL.setSelected(true); - testingStatus = DatabaseTestResult.UNTESTED; - updatePostgresFields(true); - updateSqliteFields(false); - break; case SQLITE: - rdioBnSQLite.setSelected(true); testingStatus = DatabaseTestResult.UNTESTED; updatePostgresFields(false); updateSqliteFields(true); break; default: - rdioBnDisabled.setSelected(true); - testingStatus = DatabaseTestResult.TESTEDOK; - updatePostgresFields(false); + POSTGRESQL: + testingStatus = DatabaseTestResult.UNTESTED; + updatePostgresFields(true); updateSqliteFields(false); break; - } - setTextPrompts(); - setTextBoxListeners(); - lbTestIcon.setIcon(null); + } + displayDatabaseSettings(selectedPlatform.equals(EamDbPlatformEnum.POSTGRESQL)); } - + private void display() { Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize(); setLocation((screenDimension.width - getSize().width) / 2, (screenDimension.height - getSize().height) / 2); setVisible(true); } + private void setGuidanceMessage(String message, boolean isError) { - taSetupGuidance.setText(message); + if (isError) { - taSetupGuidance.setForeground(new Color(255, 102, 102)); // light red color + } else { - taSetupGuidance.setForeground(new Color(0, 0, 0)); // black color + } } - + private void clearIcons() { - lbTestIcon.setIcon(null); - lbCreateIcon.setIcon(null); + } - + @Messages({"EamDbSettingsDialog.chooserPath.failedToGetDbPathMsg=Selected database path is invalid. Try again."}) private void bnDatabasePathFileOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnDatabasePathFileOpenActionPerformed fcDatabasePath.setCurrentDirectory(new File(dbSettingsSqlite.getDbDirectory())); @@ -461,11 +333,7 @@ public class EamDbSettingsDialog extends JDialog { if (fcDatabasePath.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { File databaseFile = fcDatabasePath.getSelectedFile(); try { - String fullPath = databaseFile.getCanonicalPath(); - if (!fullPath.endsWith(".db")) { - fullPath = fullPath + ".db"; // NON-NLS - } - tfDatabasePath.setText(fullPath); + tfDatabasePath.setText(databaseFile.getCanonicalPath()); valid(); } catch (IOException ex) { LOGGER.log(Level.SEVERE, "Failed to get path of selected database file", ex); // NON-NLS @@ -474,9 +342,7 @@ public class EamDbSettingsDialog extends JDialog { } }//GEN-LAST:event_bnDatabasePathFileOpenActionPerformed - private void bnTestActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnTestActionPerformed - setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - + private void testDbSettings() { switch (selectedPlatform) { case POSTGRESQL: if (dbSettingsPostgres.verifyConnection()) { @@ -484,39 +350,30 @@ public class EamDbSettingsDialog extends JDialog { && dbSettingsPostgres.verifyDatabaseSchema()) { testingStatus = DatabaseTestResult.TESTEDOK; } else { - testingStatus = DatabaseTestResult.SCHEMA_INVALID; + testingStatus = DatabaseTestResult.SCHEMA_INVALID; } } else { testingStatus = DatabaseTestResult.CONNECTION_FAILED; - } + } break; case SQLITE: if (dbSettingsSqlite.dbDirectoryExists() && dbSettingsSqlite.verifyConnection()) { if (dbSettingsSqlite.verifyDatabaseSchema()) { - testingStatus = DatabaseTestResult.TESTEDOK; - } else { - testingStatus = DatabaseTestResult.SCHEMA_INVALID; + testingStatus = DatabaseTestResult.TESTEDOK; + } else { + testingStatus = DatabaseTestResult.SCHEMA_INVALID; } } else { - testingStatus = DatabaseTestResult.SCHEMA_INVALID; + testingStatus = DatabaseTestResult.SCHEMA_INVALID; } break; } - setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - if (testingStatus == DatabaseTestResult.TESTEDOK) { - lbTestIcon.setIcon(goodIcon); - } else { - lbTestIcon.setIcon(badIcon); - } valid(); - }//GEN-LAST:event_bnTestActionPerformed + } - @Messages({"EamDbSettingsDialog.creation.failed=Database initialization failed."}) - private void bnCreateDbActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnCreateDbActionPerformed - - setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + private void createDb() { clearIcons(); boolean result = false; switch (selectedPlatform) { @@ -526,7 +383,7 @@ public class EamDbSettingsDialog extends JDialog { } result = dbSettingsPostgres.initializeDatabaseSchema() && dbSettingsPostgres.insertDefaultDatabaseContent(); - + break; case SQLITE: if (!dbSettingsSqlite.dbDirectoryExists()) { @@ -536,26 +393,45 @@ public class EamDbSettingsDialog extends JDialog { && dbSettingsSqlite.insertDefaultDatabaseContent(); break; } - setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + if (false == result) { - setGuidanceMessage(Bundle.EamDbSettingsDialog_creation_failed(), true); - lbCreateIcon.setIcon(badIcon); } else { testingStatus = DatabaseTestResult.TESTEDOK; - lbCreateIcon.setIcon(goodIcon); valid(); } - }//GEN-LAST:event_bnCreateDbActionPerformed + } @Messages({"EamDbSettingsDialog.okButton.errorTitle.text=Restart Required.", "EamDbSettingsDialog.okButton.errorMsg.text=Please restart Autopsy to begin using the new database platform.", "EamDbSettingsDialog.okButton.connectionErrorMsg.text=Failed to connect to Central Repository database."}) private void bnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnOkActionPerformed + setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + testDbSettings(); + if (testingStatus == DatabaseTestResult.CONNECTION_FAILED) { + JOptionPane.showConfirmDialog(WindowManager.getDefault().getMainWindow(), + "Connection to database failed, check your settings", + "Connection failed", + JOptionPane.OK_OPTION); + } else if (testingStatus == DatabaseTestResult.SCHEMA_INVALID) { + //database doesn't exist do you want to create + if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(WindowManager.getDefault().getMainWindow(), + "DO YOU WANT TO CREATE DB", + "DB DOESNT EXIST", + JOptionPane.YES_NO_OPTION)) { + createDb(); + } + } + + if (testingStatus != DatabaseTestResult.TESTEDOK) { + setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + return; + } + /** * We have to shutdown the previous platform's connection pool first; * assuming it wasn't DISABLED. This will close any existing idle * connections. - * + * * The next use of an EamDb API method will start a new connection pool * using those new settings. */ @@ -568,7 +444,7 @@ public class EamDbSettingsDialog extends JDialog { } catch (EamDbException ex) { LOGGER.log(Level.SEVERE, "Failed to close database connections in previously selected platform.", ex); // NON-NLS SwingUtilities.invokeLater(() -> { - JOptionPane.showMessageDialog(null, + JOptionPane.showMessageDialog(null, Bundle.EamDbSettingsDialog_okButton_errorMsg_text(), Bundle.EamDbSettingsDialog_okButton_errorTitle_text(), JOptionPane.WARNING_MESSAGE); @@ -592,6 +468,7 @@ public class EamDbSettingsDialog extends JDialog { } catch (EamDbException ex) { LOGGER.log(Level.SEVERE, "Failed to connect to Central Repository database.", ex); setGuidanceMessage(Bundle.EamDbSettingsDialog_okButton_connectionErrorMsg_text(), true); + setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); return; } @@ -606,6 +483,7 @@ public class EamDbSettingsDialog extends JDialog { } catch (EamDbException ex) { LOGGER.log(Level.SEVERE, "Failed to connect to Central Repository database.", ex); setGuidanceMessage(Bundle.EamDbSettingsDialog_okButton_connectionErrorMsg_text(), true); + setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); return; } break; @@ -613,6 +491,7 @@ public class EamDbSettingsDialog extends JDialog { break; } + setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); dispose(); }//GEN-LAST:event_bnOkActionPerformed @@ -620,31 +499,6 @@ public class EamDbSettingsDialog extends JDialog { dispose(); }//GEN-LAST:event_bnCancelActionPerformed - private void rdioBnDisabledActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdioBnDisabledActionPerformed - selectedPlatform = EamDbPlatformEnum.DISABLED; - testingStatus = DatabaseTestResult.TESTEDOK; - - updateSqliteFields(false); - updatePostgresFields(false); - }//GEN-LAST:event_rdioBnDisabledActionPerformed - - - private void rdioBnPostgreSQLActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdioBnPostgreSQLActionPerformed - selectedPlatform = EamDbPlatformEnum.POSTGRESQL; - testingStatus = DatabaseTestResult.UNTESTED; - - updateSqliteFields(false); - updatePostgresFields(true); - }//GEN-LAST:event_rdioBnPostgreSQLActionPerformed - - private void rdioBnSQLiteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdioBnSQLiteActionPerformed - selectedPlatform = EamDbPlatformEnum.SQLITE; - testingStatus = DatabaseTestResult.UNTESTED; - - updateSqliteFields(true); - updatePostgresFields(false); - - }//GEN-LAST:event_rdioBnSQLiteActionPerformed private void tfDatabasePathFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfDatabasePathFocusLost String fullPath = tfDatabasePath.getText(); @@ -654,37 +508,35 @@ public class EamDbSettingsDialog extends JDialog { tfDatabasePath.setText(fullPath); }//GEN-LAST:event_tfDatabasePathFocusLost - /** - * Update the fields for the Postgres platform depending on whether the - * Postgres radioButton is enabled. - * - * @param enabled - */ - private void updatePostgresFields(boolean enabled) { - tbDbHostname.setText(enabled ? dbSettingsPostgres.getHost() : ""); - tbDbHostname.setEnabled(enabled); - tbDbPort.setText(enabled ? Integer.toString(dbSettingsPostgres.getPort()) : ""); - tbDbPort.setEnabled(enabled); - tbDbName.setText(enabled ? dbSettingsPostgres.getDbName() : ""); - tbDbName.setEnabled(enabled); - tbDbUsername.setText(enabled ? dbSettingsPostgres.getUserName() : ""); - tbDbUsername.setEnabled(enabled); - jpDbPassword.setText(enabled ? dbSettingsPostgres.getPassword() : ""); - jpDbPassword.setEnabled(enabled); + private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed + selectedPlatform = (EamDbPlatformEnum) jComboBox1.getSelectedItem(); + customizeComponents(); + //displayDatabaseSettings(selectedPlatform.equals(EamDbPlatformEnum.POSTGRESQL)); + // toggleWaitCursor(jComboBox1.getSelectedItem().equals(EamDbPlatformEnum.POSTGRESQL)); + }//GEN-LAST:event_jComboBox1ActionPerformed + +// private void toggleWaitCursor(boolean off) { +// if (!off) { +// setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); +// } else { +// setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); +// } +// } + private void displayDatabaseSettings(boolean isPostgres) { + lbDatabasePath.setVisible(!isPostgres); + tfDatabasePath.setVisible(!isPostgres); + jLabel1.setVisible(!isPostgres); + bnDatabasePathFileOpen.setVisible(!isPostgres); + lbHostName.setVisible(isPostgres); + tbDbHostname.setVisible(isPostgres); + lbPort.setVisible(isPostgres); + tbDbPort.setVisible(isPostgres); + lbUserName.setVisible(isPostgres); + tbDbUsername.setVisible(isPostgres); + lbUserPassword.setVisible(isPostgres); + jpDbPassword.setVisible(isPostgres); } - - /** - * Update the fields for the SQLite platform depending on whether the - * SQLite radioButton is enabled. - * - * @param enabled - */ - private void updateSqliteFields(boolean enabled) { - tfDatabasePath.setText(enabled ? dbSettingsSqlite.getFileNameWithPath() : ""); - tfDatabasePath.setEnabled(enabled); - bnDatabasePathFileOpen.setEnabled(enabled); - } - + /** * Add text prompts to all of the text fields. */ @@ -697,11 +549,36 @@ public class EamDbSettingsDialog extends JDialog { Collection textPrompts = new ArrayList<>(); textPrompts.add(new TextPrompt(Bundle.EamDbSettingsDialog_textPrompt_hostnameOrIP(), tbDbHostname)); textPrompts.add(new TextPrompt(Bundle.EamDbSettingsDialog_textPrompt_port(), tbDbPort)); - textPrompts.add(new TextPrompt(Bundle.EamDbSettingsDialog_textPrompt_dbName(), tbDbName)); + // textPrompts.add(new TextPrompt(Bundle.EamDbSettingsDialog_textPrompt_dbName(), tbDbName)); textPrompts.add(new TextPrompt(Bundle.EamDbSettingsDialog_textPrompt_user(), tbDbUsername)); configureTextPrompts(textPrompts); } + private void updatePostgresFields(boolean enabled) { + tbDbHostname.setText(enabled ? dbSettingsPostgres.getHost() : ""); + tbDbHostname.setEnabled(enabled); + tbDbPort.setText(enabled ? Integer.toString(dbSettingsPostgres.getPort()) : ""); + tbDbPort.setEnabled(enabled); + // tbDbName.setText(enabled ? dbSettingsPostgres.getDbName() : ""); + // tbDbName.setEnabled(enabled); + tbDbUsername.setText(enabled ? dbSettingsPostgres.getUserName() : ""); + tbDbUsername.setEnabled(enabled); + jpDbPassword.setText(enabled ? dbSettingsPostgres.getPassword() : ""); + jpDbPassword.setEnabled(enabled); + } + + /** + * Update the fields for the SQLite platform depending on whether the SQLite + * radioButton is enabled. + * + * @param enabled + */ + private void updateSqliteFields(boolean enabled) { + tfDatabasePath.setText(enabled ? dbSettingsSqlite.getFileNameWithPath() : ""); + tfDatabasePath.setEnabled(enabled); + bnDatabasePathFileOpen.setEnabled(enabled); + } + /** * Register for notifications when the text boxes get updated. */ @@ -709,7 +586,7 @@ public class EamDbSettingsDialog extends JDialog { textBoxes.add(tfDatabasePath); textBoxes.add(tbDbHostname); textBoxes.add(tbDbPort); - textBoxes.add(tbDbName); + // textBoxes.add(tbDbName); textBoxes.add(tbDbUsername); textBoxes.add(jpDbPassword); addDocumentListeners(textBoxes, textBoxChangedListener); @@ -754,17 +631,17 @@ public class EamDbSettingsDialog extends JDialog { case POSTGRESQL: result = !tbDbHostname.getText().trim().isEmpty() && !tbDbPort.getText().trim().isEmpty() - && !tbDbName.getText().trim().isEmpty() + // && !tbDbName.getText().trim().isEmpty() && !tbDbUsername.getText().trim().isEmpty() && 0 < jpDbPassword.getPassword().length; break; - + case SQLITE: result = !tfDatabasePath.getText().trim().isEmpty(); break; } - + if (!result) { setGuidanceMessage(Bundle.EamDbSettingsDialog_validation_incompleteFields(), true); } @@ -808,7 +685,7 @@ public class EamDbSettingsDialog extends JDialog { } try { - dbSettingsPostgres.setDbName(tbDbName.getText().trim()); + dbSettingsPostgres.setDbName(CENTRAL_REPO_DB_NAME); } catch (EamDbException ex) { guidanceText.append(ex.getMessage()); result = false; @@ -831,7 +708,7 @@ public class EamDbSettingsDialog extends JDialog { case SQLITE: try { File databasePath = new File(tfDatabasePath.getText()); - dbSettingsSqlite.setDbName(databasePath.getName()); + dbSettingsSqlite.setDbName(CENTRAL_REPO_DB_NAME + CENTRAL_REPO_SQLITE_EXT); dbSettingsSqlite.setDbDirectory(databasePath.getParent()); } catch (EamDbException ex) { guidanceText.append(ex.getMessage()); @@ -850,65 +727,27 @@ public class EamDbSettingsDialog extends JDialog { * @return true if it's okay, false otherwise. */ private boolean valid() { - taSetupGuidance.setText(""); - return enableTestButton(checkFields()) - && enableCreateButton() - && enableOkButton(); + return enableOkButton(checkFields()); } /** - * Enable the "Test" button once all fields are valid. - * - * @return true - */ - @Messages({"EamDbSettingsDialog.validation.mustTest=Once you are statisfied with the database settings, click the Test button to test the database connection, settings, and schema. SQLite should only be used by one examiner at a time.", - "EamDbSettingsDialog.validation.failedConnection=The connection to the database failed. Update the settings and try the Test again."}) - private boolean enableTestButton(boolean isValidInput) { - if (selectedPlatform != EamDbPlatformEnum.DISABLED && isValidInput) { - bnTest.setEnabled(true); - if (testingStatus == DatabaseTestResult.UNTESTED) { - setGuidanceMessage(Bundle.EamDbSettingsDialog_validation_mustTest(), false); - } else if (testingStatus == DatabaseTestResult.CONNECTION_FAILED) { - setGuidanceMessage(Bundle.EamDbSettingsDialog_validation_failedConnection(), true); - } - } else { - bnTest.setEnabled(false); - } - return true; - } - - /** - * Enable the "Create" button if the db is not created. - * - * @return true if db is created, else false - */ - @Messages({"EamDbSettingsDialog.validation.dbNotCreated=The database does not exist. Click the Create button to create and initialize the database."}) - private boolean enableCreateButton() { - if (testingStatus == DatabaseTestResult.SCHEMA_INVALID) { - bnCreateDb.setEnabled(true); - setGuidanceMessage(Bundle.EamDbSettingsDialog_validation_dbNotCreated(), false); - } else { - bnCreateDb.setEnabled(false); - } - return true; - } - - /** - * Enable the "OK" button if the db test passed. Disabled defaults to db test passed. - * + * Enable the "OK" button if the db test passed. Disabled defaults to db + * test passed. + * * @return true */ @Messages({"EamDbSettingsDialog.validation.finished=Click OK to save your database settings and return to the Options. Or select a different database type."}) - private boolean enableOkButton() { - if (testingStatus == DatabaseTestResult.TESTEDOK || selectedPlatform == EamDbPlatformEnum.DISABLED) { + private boolean enableOkButton(boolean isValidInput) { + if (isValidInput) { bnOk.setEnabled(true); setGuidanceMessage(Bundle.EamDbSettingsDialog_validation_finished(), false); } else { bnOk.setEnabled(false); } return true; + } - + /** * Used to listen for changes in text boxes. It lets the panel know things * have been updated and that validation needs to happen. @@ -937,45 +776,35 @@ public class EamDbSettingsDialog extends JDialog { clearIcons(); testingStatus = DatabaseTestResult.UNTESTED; valid(); + } } - + private enum DatabaseTestResult { UNTESTED, CONNECTION_FAILED, SCHEMA_INVALID, - TESTEDOK; + TESTEDOK; } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton bnCancel; - private javax.swing.JButton bnCreateDb; private javax.swing.JButton bnDatabasePathFileOpen; private javax.swing.ButtonGroup bnGrpDatabasePlatforms; private javax.swing.JButton bnOk; - private javax.swing.JButton bnTest; private javax.swing.JFileChooser fcDatabasePath; - private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JComboBox jComboBox1; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; private javax.swing.JPasswordField jpDbPassword; - private javax.swing.JLabel lbCreateIcon; - private javax.swing.JLabel lbDatabaseName; private javax.swing.JLabel lbDatabasePath; private javax.swing.JLabel lbHostName; private javax.swing.JLabel lbPort; - private javax.swing.JLabel lbTestIcon; private javax.swing.JLabel lbUserName; private javax.swing.JLabel lbUserPassword; private javax.swing.JPanel pnButtons; - private javax.swing.JPanel pnDatabaseConnectionSettings; - private javax.swing.JPanel pnPostgreSQLSettings; private javax.swing.JPanel pnSQLiteSettings; - private javax.swing.JPanel pnSetupGuidance; - private javax.swing.JRadioButton rdioBnDisabled; - private javax.swing.JRadioButton rdioBnPostgreSQL; - private javax.swing.JRadioButton rdioBnSQLite; - private javax.swing.JTextArea taSetupGuidance; private javax.swing.JTextField tbDbHostname; - private javax.swing.JTextField tbDbName; private javax.swing.JTextField tbDbPort; private javax.swing.JTextField tbDbUsername; private javax.swing.JTextField tfDatabasePath; diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.form b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.form index ec0056d904..ab0b5922fb 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.form +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.form @@ -25,6 +25,10 @@ + + + + @@ -33,13 +37,14 @@ - + + - + @@ -240,5 +245,15 @@ + + + + + + + + + + diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java index d6e5873319..ba54241a66 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java @@ -29,6 +29,7 @@ import org.sleuthkit.autopsy.events.AutopsyEvent; import org.sleuthkit.autopsy.ingest.IngestManager; import org.sleuthkit.autopsy.ingest.IngestModuleGlobalSettingsPanel; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbPlatformEnum; +import static org.sleuthkit.autopsy.centralrepository.datamodel.EamDbPlatformEnum.DISABLED; import org.sleuthkit.autopsy.centralrepository.datamodel.PostgresEamDbSettings; import org.sleuthkit.autopsy.centralrepository.datamodel.SqliteEamDbSettings; @@ -85,6 +86,7 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i bnManageTags = new javax.swing.JButton(); bnManageTypes = new javax.swing.JButton(); tbOops = new javax.swing.JTextField(); + jCheckBox1 = new javax.swing.JCheckBox(); setName(""); // NOI18N @@ -198,6 +200,13 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i tbOops.setText(org.openide.util.NbBundle.getMessage(GlobalSettingsPanel.class, "GlobalSettingsPanel.tbOops.text")); // NOI18N tbOops.setBorder(null); + org.openide.awt.Mnemonics.setLocalizedText(jCheckBox1, org.openide.util.NbBundle.getMessage(GlobalSettingsPanel.class, "GlobalSettingsPanel.jCheckBox1.text")); // NOI18N + jCheckBox1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jCheckBox1ActionPerformed(evt); + } + }); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( @@ -207,19 +216,23 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(pnDatabaseContentButtons, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(tbOops, javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(pnDatabaseConfiguration, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(pnDatabaseConfiguration, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(layout.createSequentialGroup() + .addComponent(jCheckBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addContainerGap() + .addComponent(jCheckBox1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(pnDatabaseConfiguration, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(tbOops, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(pnDatabaseContentButtons, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(0, 18, Short.MAX_VALUE)) + .addContainerGap()) ); }// //GEN-END:initComponents @@ -243,6 +256,12 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i load(); // reload db settings content and update buttons }//GEN-LAST:event_bnDbConfigureActionPerformed + private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed + //if saved setting is disabled checkbox should be disabled already + enableDatabaseConfigureButton(jCheckBox1.isSelected()); + enableButtonSubComponents(jCheckBox1.isSelected() && !EamDbPlatformEnum.getSelectedPlatform().equals(DISABLED)); + }//GEN-LAST:event_jCheckBox1ActionPerformed + @Override @Messages({"GlobalSettingsPanel.validationerrMsg.mustConfigure=Configure the database to enable this module."}) public void load() { @@ -250,7 +269,7 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i enableAllSubComponents(false); EamDbPlatformEnum selectedPlatform = EamDbPlatformEnum.getSelectedPlatform(); - + switch (selectedPlatform) { case POSTGRESQL: PostgresEamDbSettings dbSettingsPg = new PostgresEamDbSettings(); @@ -270,7 +289,7 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i lbDbPlatformValue.setText(EamDbPlatformEnum.DISABLED.toString()); lbDbNameValue.setText(""); lbDbLocationValue.setText(""); - enableDatabaseConfigureButton(true); + enableDatabaseConfigureButton(jCheckBox1.isSelected()); tbOops.setText(Bundle.GlobalSettingsPanel_validationerrMsg_mustConfigure()); break; } @@ -347,8 +366,8 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i * @return True */ private boolean enableAllSubComponents(Boolean enable) { - enableDatabaseConfigureButton(enable); - enableButtonSubComponents(enable); + enableDatabaseConfigureButton(jCheckBox1.isSelected() && enable); + enableButtonSubComponents(jCheckBox1.isSelected() && enable); return true; } @@ -359,9 +378,17 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i * * @return True */ - private boolean enableDatabaseConfigureButton(Boolean enable) { + private void enableDatabaseConfigureButton(Boolean enable) { + pnDatabaseConfiguration.setEnabled(enable); + pnDatabaseContentButtons.setEnabled(enable); bnDbConfigure.setEnabled(enable); - return true; + lbDbLocationLabel.setEnabled(enable); + lbDbLocationValue.setEnabled(enable); + lbDbNameLabel.setEnabled(enable); + lbDbNameValue.setEnabled(enable); + lbDbPlatformTypeLabel.setEnabled(enable); + lbDbPlatformValue.setEnabled(enable); + tbOops.setEnabled(enable); } /** @@ -384,6 +411,7 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i private javax.swing.JButton bnImportDatabase; private javax.swing.JButton bnManageTags; private javax.swing.JButton bnManageTypes; + private javax.swing.JCheckBox jCheckBox1; private javax.swing.JLabel lbDbLocationLabel; private javax.swing.JLabel lbDbLocationValue; private javax.swing.JLabel lbDbNameLabel; From 6586cc4af661d5251341330307b7ea9d4c05fe73 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Fri, 11 Aug 2017 14:37:07 -0400 Subject: [PATCH 02/13] 2934 save the enabling of new checkbox to modulesettings --- .../optionspanel/Bundle.properties | 2 +- .../optionspanel/GlobalSettingsPanel.form | 10 +++--- .../optionspanel/GlobalSettingsPanel.java | 34 +++++++++++-------- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/Bundle.properties b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/Bundle.properties index f05ff2b915..8703a8a83c 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/Bundle.properties @@ -76,4 +76,4 @@ ImportHashDatabaseDialog.lbFilePath.text=File Path: ImportHashDatabaseDialog.tfFilePath.text= EamDbSettingsDialog.jLabel1.text=SQLite should only be used by one examiner at a time. EamDbSettingsDialog.jLabel2.text=Database type: -GlobalSettingsPanel.jCheckBox1.text=Use a Central Repository +GlobalSettingsPanel.cbUseCentralRepo.text=Use a Central Repository diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.form b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.form index ab0b5922fb..2e87f1d5a4 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.form +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.form @@ -26,7 +26,7 @@ - + @@ -37,7 +37,7 @@ - + @@ -245,14 +245,14 @@ - + - + - + diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java index ba54241a66..2384a6fc24 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java @@ -32,6 +32,8 @@ import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbPlatformEnum; import static org.sleuthkit.autopsy.centralrepository.datamodel.EamDbPlatformEnum.DISABLED; import org.sleuthkit.autopsy.centralrepository.datamodel.PostgresEamDbSettings; import org.sleuthkit.autopsy.centralrepository.datamodel.SqliteEamDbSettings; +import org.sleuthkit.autopsy.core.UserPreferences; +import org.sleuthkit.autopsy.coreutils.ModuleSettings; /** * Main settings panel for the Central Repository @@ -52,6 +54,7 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i initComponents(); customizeComponents(); addIngestJobEventsListener(); + cbUseCentralRepo.setSelected(Boolean.parseBoolean(ModuleSettings.getConfigSetting("CentralRepository", "db.useCentralRepo"))); // NON-NLS } @Messages({"GlobalSettingsPanel.title=Central Repository Settings"}) @@ -86,7 +89,7 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i bnManageTags = new javax.swing.JButton(); bnManageTypes = new javax.swing.JButton(); tbOops = new javax.swing.JTextField(); - jCheckBox1 = new javax.swing.JCheckBox(); + cbUseCentralRepo = new javax.swing.JCheckBox(); setName(""); // NOI18N @@ -200,10 +203,10 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i tbOops.setText(org.openide.util.NbBundle.getMessage(GlobalSettingsPanel.class, "GlobalSettingsPanel.tbOops.text")); // NOI18N tbOops.setBorder(null); - org.openide.awt.Mnemonics.setLocalizedText(jCheckBox1, org.openide.util.NbBundle.getMessage(GlobalSettingsPanel.class, "GlobalSettingsPanel.jCheckBox1.text")); // NOI18N - jCheckBox1.addActionListener(new java.awt.event.ActionListener() { + org.openide.awt.Mnemonics.setLocalizedText(cbUseCentralRepo, org.openide.util.NbBundle.getMessage(GlobalSettingsPanel.class, "GlobalSettingsPanel.cbUseCentralRepo.text")); // NOI18N + cbUseCentralRepo.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { - jCheckBox1ActionPerformed(evt); + cbUseCentralRepoActionPerformed(evt); } }); @@ -218,14 +221,14 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i .addComponent(tbOops, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(pnDatabaseConfiguration, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() - .addComponent(jCheckBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(cbUseCentralRepo, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addComponent(jCheckBox1) + .addComponent(cbUseCentralRepo) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(pnDatabaseConfiguration, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) @@ -256,11 +259,11 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i load(); // reload db settings content and update buttons }//GEN-LAST:event_bnDbConfigureActionPerformed - private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed + private void cbUseCentralRepoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbUseCentralRepoActionPerformed //if saved setting is disabled checkbox should be disabled already - enableDatabaseConfigureButton(jCheckBox1.isSelected()); - enableButtonSubComponents(jCheckBox1.isSelected() && !EamDbPlatformEnum.getSelectedPlatform().equals(DISABLED)); - }//GEN-LAST:event_jCheckBox1ActionPerformed + enableDatabaseConfigureButton(cbUseCentralRepo.isSelected()); + enableButtonSubComponents(cbUseCentralRepo.isSelected() && !EamDbPlatformEnum.getSelectedPlatform().equals(DISABLED)); + }//GEN-LAST:event_cbUseCentralRepoActionPerformed @Override @Messages({"GlobalSettingsPanel.validationerrMsg.mustConfigure=Configure the database to enable this module."}) @@ -269,7 +272,6 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i enableAllSubComponents(false); EamDbPlatformEnum selectedPlatform = EamDbPlatformEnum.getSelectedPlatform(); - switch (selectedPlatform) { case POSTGRESQL: PostgresEamDbSettings dbSettingsPg = new PostgresEamDbSettings(); @@ -289,7 +291,7 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i lbDbPlatformValue.setText(EamDbPlatformEnum.DISABLED.toString()); lbDbNameValue.setText(""); lbDbLocationValue.setText(""); - enableDatabaseConfigureButton(jCheckBox1.isSelected()); + enableDatabaseConfigureButton(cbUseCentralRepo.isSelected()); tbOops.setText(Bundle.GlobalSettingsPanel_validationerrMsg_mustConfigure()); break; } @@ -299,6 +301,7 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i @Override public void store() { // Click OK or Apply on Options Panel + ModuleSettings.setConfigSetting("CentralRepository", "db.useCentralRepo", Boolean.toString(cbUseCentralRepo.isSelected())); } /** @@ -312,6 +315,7 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i @Override public void saveSettings() { // Click OK on Global Settings Panel + store(); } @Override @@ -366,8 +370,8 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i * @return True */ private boolean enableAllSubComponents(Boolean enable) { - enableDatabaseConfigureButton(jCheckBox1.isSelected() && enable); - enableButtonSubComponents(jCheckBox1.isSelected() && enable); + enableDatabaseConfigureButton(cbUseCentralRepo.isSelected() && enable); + enableButtonSubComponents(cbUseCentralRepo.isSelected() && enable); return true; } @@ -411,7 +415,7 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i private javax.swing.JButton bnImportDatabase; private javax.swing.JButton bnManageTags; private javax.swing.JButton bnManageTypes; - private javax.swing.JCheckBox jCheckBox1; + private javax.swing.JCheckBox cbUseCentralRepo; private javax.swing.JLabel lbDbLocationLabel; private javax.swing.JLabel lbDbLocationValue; private javax.swing.JLabel lbDbNameLabel; From 29047dc5897c775ba828d9c467fdea2b037b76a4 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Fri, 11 Aug 2017 16:03:23 -0400 Subject: [PATCH 03/13] 2934 fix the enabling and disabling of Central Repo in new gui --- .../autopsy/centralrepository/datamodel/EamDb.java | 11 ++++++++--- .../optionspanel/GlobalSettingsPanel.java | 6 +++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java index dc52ea6a1f..b6be667a62 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java @@ -20,6 +20,7 @@ package org.sleuthkit.autopsy.centralrepository.datamodel; import java.util.List; import java.util.Set; +import org.sleuthkit.autopsy.coreutils.ModuleSettings; /** * Main interface for interacting with the database @@ -36,8 +37,11 @@ public interface EamDb { * @throws EamDbException */ static EamDb getInstance() throws EamDbException { - EamDbPlatformEnum selectedPlatform = EamDbPlatformEnum.getSelectedPlatform(); - + + EamDbPlatformEnum selectedPlatform = EamDbPlatformEnum.DISABLED; + if (Boolean.parseBoolean(ModuleSettings.getConfigSetting("CentralRepository", "db.useCentralRepo"))){ + selectedPlatform = EamDbPlatformEnum.getSelectedPlatform(); + } switch (selectedPlatform) { case POSTGRESQL: return PostgresEamDb.getInstance(); @@ -86,7 +90,8 @@ public interface EamDb { * @return Is the database enabled */ static boolean isEnabled() { - return EamDbPlatformEnum.getSelectedPlatform() != EamDbPlatformEnum.DISABLED; + return Boolean.parseBoolean(ModuleSettings.getConfigSetting("CentralRepository", "db.useCentralRepo")) + && EamDbPlatformEnum.getSelectedPlatform() != EamDbPlatformEnum.DISABLED; } /** diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java index 2384a6fc24..e502a5c218 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java @@ -32,7 +32,6 @@ import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbPlatformEnum; import static org.sleuthkit.autopsy.centralrepository.datamodel.EamDbPlatformEnum.DISABLED; import org.sleuthkit.autopsy.centralrepository.datamodel.PostgresEamDbSettings; import org.sleuthkit.autopsy.centralrepository.datamodel.SqliteEamDbSettings; -import org.sleuthkit.autopsy.core.UserPreferences; import org.sleuthkit.autopsy.coreutils.ModuleSettings; /** @@ -54,7 +53,7 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i initComponents(); customizeComponents(); addIngestJobEventsListener(); - cbUseCentralRepo.setSelected(Boolean.parseBoolean(ModuleSettings.getConfigSetting("CentralRepository", "db.useCentralRepo"))); // NON-NLS + } @Messages({"GlobalSettingsPanel.title=Central Repository Settings"}) @@ -255,6 +254,7 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i }//GEN-LAST:event_bnManageTypesActionPerformed private void bnDbConfigureActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnDbConfigureActionPerformed + store(); EamDbSettingsDialog dialog = new EamDbSettingsDialog(); load(); // reload db settings content and update buttons }//GEN-LAST:event_bnDbConfigureActionPerformed @@ -269,9 +269,9 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i @Messages({"GlobalSettingsPanel.validationerrMsg.mustConfigure=Configure the database to enable this module."}) public void load() { tbOops.setText(""); - enableAllSubComponents(false); EamDbPlatformEnum selectedPlatform = EamDbPlatformEnum.getSelectedPlatform(); + cbUseCentralRepo.setSelected(Boolean.parseBoolean(ModuleSettings.getConfigSetting("CentralRepository", "db.useCentralRepo"))); // NON-NLS switch (selectedPlatform) { case POSTGRESQL: PostgresEamDbSettings dbSettingsPg = new PostgresEamDbSettings(); From f4842a1ca865e947b66599842ccb0a6e176db829 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Mon, 14 Aug 2017 16:53:41 -0400 Subject: [PATCH 04/13] 2934-valid path checking for SQLite DB and minor clean up --- .../datamodel/SqliteEamDbSettings.java | 3 +- .../optionspanel/EamDbSettingsDialog.form | 24 ++--- .../optionspanel/EamDbSettingsDialog.java | 96 +++++++++---------- .../optionspanel/GlobalSettingsPanel.java | 11 ++- 4 files changed, 68 insertions(+), 66 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDbSettings.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDbSettings.java index e472a357f1..177db2d1ae 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDbSettings.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDbSettings.java @@ -21,6 +21,7 @@ package org.sleuthkit.autopsy.centralrepository.datamodel; import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.InvalidPathException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; @@ -139,7 +140,7 @@ public final class SqliteEamDbSettings { File dbDir = new File(getDbDirectory()); Files.createDirectories(dbDir.toPath()); LOGGER.log(Level.INFO, "sqlite directory did not exist, created it at {0}.", getDbDirectory()); // NON-NLS - } catch (IOException ex) { + } catch (IOException | InvalidPathException ex) { LOGGER.log(Level.SEVERE, "Failed to create sqlite database directory.", ex); // NON-NLS return false; } diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.form b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.form index 81eb19ce47..ee8c05590a 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.form +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.form @@ -117,23 +117,16 @@ - - - - - - - - - - - - - - - + + + + + + + + @@ -221,6 +214,7 @@ + diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java index 81b4af2bd7..98640d9d8a 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java @@ -25,7 +25,6 @@ import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import org.netbeans.spi.options.OptionsPanelController; import org.openide.util.ImageUtilities; -import org.openide.util.NbBundle; import org.openide.util.NbBundle.Messages; import org.openide.windows.WindowManager; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb; @@ -63,7 +62,7 @@ public class EamDbSettingsDialog extends JDialog { public EamDbSettingsDialog() { super((JFrame) WindowManager.getDefault().getMainWindow(), Bundle.EamDbSettingsDialog_title_text(), - true); // NON-NLS + true); textBoxes = new ArrayList<>(); textBoxChangedListener = new TextBoxChangedListener(); @@ -74,8 +73,6 @@ public class EamDbSettingsDialog extends JDialog { selectedPlatform = EamDbPlatformEnum.getSelectedPlatform(); if (selectedPlatform == null || selectedPlatform.equals(EamDbPlatformEnum.DISABLED)) { selectedPlatform = EamDbPlatformEnum.POSTGRESQL; - } else { - System.out.println("selectedPlatform = " + selectedPlatform); } initComponents(); @@ -165,6 +162,11 @@ public class EamDbSettingsDialog extends JDialog { tfDatabasePathFocusLost(evt); } }); + tfDatabasePath.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + tfDatabasePathActionPerformed(evt); + } + }); org.openide.awt.Mnemonics.setLocalizedText(bnDatabasePathFileOpen, org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.bnDatabasePathFileOpen.text")); // NOI18N bnDatabasePathFileOpen.addActionListener(new java.awt.event.ActionListener() { @@ -199,18 +201,14 @@ public class EamDbSettingsDialog extends JDialog { .addGroup(pnSQLiteSettingsLayout.createSequentialGroup() .addContainerGap() .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(pnSQLiteSettingsLayout.createSequentialGroup() - .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(lbHostName) - .addComponent(lbPort) - .addComponent(lbUserName) - .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(10, 10, 10)) - .addGroup(pnSQLiteSettingsLayout.createSequentialGroup() - .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(lbDatabasePath) - .addComponent(lbUserPassword, javax.swing.GroupLayout.Alignment.TRAILING)) - .addGap(14, 14, 14))) + .addComponent(lbHostName) + .addComponent(lbPort) + .addComponent(lbUserName) + .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(lbDatabasePath) + .addComponent(lbUserPassword, javax.swing.GroupLayout.Alignment.TRAILING))) + .addGap(10, 10, 10) .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnSQLiteSettingsLayout.createSequentialGroup() .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) @@ -329,7 +327,7 @@ public class EamDbSettingsDialog extends JDialog { @Messages({"EamDbSettingsDialog.chooserPath.failedToGetDbPathMsg=Selected database path is invalid. Try again."}) private void bnDatabasePathFileOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnDatabasePathFileOpenActionPerformed fcDatabasePath.setCurrentDirectory(new File(dbSettingsSqlite.getDbDirectory())); - fcDatabasePath.setSelectedFile(new File(dbSettingsSqlite.getFileNameWithPath())); + fcDatabasePath.setSelectedFile(new File(dbSettingsSqlite.getDbDirectory())); if (fcDatabasePath.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { File databaseFile = fcDatabasePath.getSelectedFile(); try { @@ -373,13 +371,16 @@ public class EamDbSettingsDialog extends JDialog { valid(); } + @Messages({"EamDbSettingsDialog.okButton.createDbError.title=Unable to Create Database", + "EamDbSettingsDialog.okButton.createDbError.message=Unable to create Database, please ensure location was valid and try again."}) private void createDb() { clearIcons(); boolean result = false; + boolean dbCreated = true; switch (selectedPlatform) { case POSTGRESQL: if (!dbSettingsPostgres.verifyDatabaseExists()) { - dbSettingsPostgres.createDatabase(); + dbCreated = dbSettingsPostgres.createDatabase(); } result = dbSettingsPostgres.initializeDatabaseSchema() && dbSettingsPostgres.insertDefaultDatabaseContent(); @@ -387,14 +388,19 @@ public class EamDbSettingsDialog extends JDialog { break; case SQLITE: if (!dbSettingsSqlite.dbDirectoryExists()) { - dbSettingsSqlite.createDbDirectory(); + dbCreated = dbSettingsSqlite.createDbDirectory(); } result = dbSettingsSqlite.initializeDatabaseSchema() && dbSettingsSqlite.insertDefaultDatabaseContent(); break; } - - if (false == result) { + if (false == dbCreated) { + JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), + Bundle.EamDbSettingsDialog_okButton_createDbError_message(), + Bundle.EamDbSettingsDialog_okButton_createDbError_title(), + JOptionPane.WARNING_MESSAGE); + } else if (false == result) { + LOGGER.severe("Unable to initialize database schema or insert contents into Central Repository."); } else { testingStatus = DatabaseTestResult.TESTEDOK; valid(); @@ -403,20 +409,24 @@ public class EamDbSettingsDialog extends JDialog { @Messages({"EamDbSettingsDialog.okButton.errorTitle.text=Restart Required.", "EamDbSettingsDialog.okButton.errorMsg.text=Please restart Autopsy to begin using the new database platform.", - "EamDbSettingsDialog.okButton.connectionErrorMsg.text=Failed to connect to Central Repository database."}) + "EamDbSettingsDialog.okButton.connectionErrorMsg.text=Failed to connect to Central Repository database.", + "EamDbSettingsDialog.okButton.createDbDialog.title=Database Does Not Exist", + "EamDbSettingsDialog.okButton.createDbDialog.message=Database does not exist, would you like to create it?", + "EamDbSettingsDialog.okButton.databaseConnectionFailed.title=Database Connection Failed", + "EamDbSettingsDialog.okButton.databaseConnectionFailed.message=Unable to connect to database please check your settings and try again."}) private void bnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnOkActionPerformed setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); testDbSettings(); if (testingStatus == DatabaseTestResult.CONNECTION_FAILED) { - JOptionPane.showConfirmDialog(WindowManager.getDefault().getMainWindow(), - "Connection to database failed, check your settings", - "Connection failed", - JOptionPane.OK_OPTION); + JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), + Bundle.EamDbSettingsDialog_okButton_databaseConnectionFailed_message(), + Bundle.EamDbSettingsDialog_okButton_databaseConnectionFailed_title(), + JOptionPane.WARNING_MESSAGE); } else if (testingStatus == DatabaseTestResult.SCHEMA_INVALID) { //database doesn't exist do you want to create if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(WindowManager.getDefault().getMainWindow(), - "DO YOU WANT TO CREATE DB", - "DB DOESNT EXIST", + Bundle.EamDbSettingsDialog_okButton_createDbDialog_message(), + Bundle.EamDbSettingsDialog_okButton_createDbDialog_title(), JOptionPane.YES_NO_OPTION)) { createDb(); } @@ -466,7 +476,7 @@ public class EamDbSettingsDialog extends JDialog { try { EamDb.getInstance().updateSettings(); } catch (EamDbException ex) { - LOGGER.log(Level.SEVERE, "Failed to connect to Central Repository database.", ex); + LOGGER.log(Level.SEVERE, Bundle.EamDbSettingsDialog_okButton_connectionErrorMsg_text(), ex); //NON-NLS setGuidanceMessage(Bundle.EamDbSettingsDialog_okButton_connectionErrorMsg_text(), true); setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); return; @@ -481,7 +491,7 @@ public class EamDbSettingsDialog extends JDialog { try { EamDb.getInstance().updateSettings(); } catch (EamDbException ex) { - LOGGER.log(Level.SEVERE, "Failed to connect to Central Repository database.", ex); + LOGGER.log(Level.SEVERE, Bundle.EamDbSettingsDialog_okButton_connectionErrorMsg_text(), ex); //NON-NLS setGuidanceMessage(Bundle.EamDbSettingsDialog_okButton_connectionErrorMsg_text(), true); setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); return; @@ -501,27 +511,18 @@ public class EamDbSettingsDialog extends JDialog { private void tfDatabasePathFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfDatabasePathFocusLost - String fullPath = tfDatabasePath.getText(); - if (!fullPath.endsWith(".db")) { - fullPath = fullPath + ".db"; // NON-NLS - } - tfDatabasePath.setText(fullPath); + }//GEN-LAST:event_tfDatabasePathFocusLost private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed selectedPlatform = (EamDbPlatformEnum) jComboBox1.getSelectedItem(); customizeComponents(); - //displayDatabaseSettings(selectedPlatform.equals(EamDbPlatformEnum.POSTGRESQL)); - // toggleWaitCursor(jComboBox1.getSelectedItem().equals(EamDbPlatformEnum.POSTGRESQL)); }//GEN-LAST:event_jComboBox1ActionPerformed -// private void toggleWaitCursor(boolean off) { -// if (!off) { -// setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); -// } else { -// setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); -// } -// } + private void tfDatabasePathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfDatabasePathActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_tfDatabasePathActionPerformed + private void displayDatabaseSettings(boolean isPostgres) { lbDatabasePath.setVisible(!isPostgres); tfDatabasePath.setVisible(!isPostgres); @@ -549,7 +550,6 @@ public class EamDbSettingsDialog extends JDialog { Collection textPrompts = new ArrayList<>(); textPrompts.add(new TextPrompt(Bundle.EamDbSettingsDialog_textPrompt_hostnameOrIP(), tbDbHostname)); textPrompts.add(new TextPrompt(Bundle.EamDbSettingsDialog_textPrompt_port(), tbDbPort)); - // textPrompts.add(new TextPrompt(Bundle.EamDbSettingsDialog_textPrompt_dbName(), tbDbName)); textPrompts.add(new TextPrompt(Bundle.EamDbSettingsDialog_textPrompt_user(), tbDbUsername)); configureTextPrompts(textPrompts); } @@ -559,8 +559,6 @@ public class EamDbSettingsDialog extends JDialog { tbDbHostname.setEnabled(enabled); tbDbPort.setText(enabled ? Integer.toString(dbSettingsPostgres.getPort()) : ""); tbDbPort.setEnabled(enabled); - // tbDbName.setText(enabled ? dbSettingsPostgres.getDbName() : ""); - // tbDbName.setEnabled(enabled); tbDbUsername.setText(enabled ? dbSettingsPostgres.getUserName() : ""); tbDbUsername.setEnabled(enabled); jpDbPassword.setText(enabled ? dbSettingsPostgres.getPassword() : ""); @@ -574,7 +572,7 @@ public class EamDbSettingsDialog extends JDialog { * @param enabled */ private void updateSqliteFields(boolean enabled) { - tfDatabasePath.setText(enabled ? dbSettingsSqlite.getFileNameWithPath() : ""); + tfDatabasePath.setText(enabled ? dbSettingsSqlite.getDbDirectory() : ""); tfDatabasePath.setEnabled(enabled); bnDatabasePathFileOpen.setEnabled(enabled); } @@ -709,7 +707,7 @@ public class EamDbSettingsDialog extends JDialog { try { File databasePath = new File(tfDatabasePath.getText()); dbSettingsSqlite.setDbName(CENTRAL_REPO_DB_NAME + CENTRAL_REPO_SQLITE_EXT); - dbSettingsSqlite.setDbDirectory(databasePath.getParent()); + dbSettingsSqlite.setDbDirectory(databasePath.getPath()); } catch (EamDbException ex) { guidanceText.append(ex.getMessage()); result = false; diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java index e502a5c218..2fe4b1a300 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java @@ -239,16 +239,19 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i }// //GEN-END:initComponents private void bnImportDatabaseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnImportDatabaseActionPerformed + store(); ImportHashDatabaseDialog dialog = new ImportHashDatabaseDialog(); firePropertyChange(OptionsPanelController.PROP_VALID, null, null); }//GEN-LAST:event_bnImportDatabaseActionPerformed private void bnManageTagsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnManageTagsActionPerformed + store(); ManageTagsDialog dialog = new ManageTagsDialog(); firePropertyChange(OptionsPanelController.PROP_VALID, null, null); }//GEN-LAST:event_bnManageTagsActionPerformed private void bnManageTypesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnManageTypesActionPerformed + store(); ManageCorrelationPropertiesDialog dialog = new ManageCorrelationPropertiesDialog(); firePropertyChange(OptionsPanelController.PROP_VALID, null, null); }//GEN-LAST:event_bnManageTypesActionPerformed @@ -263,6 +266,8 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i //if saved setting is disabled checkbox should be disabled already enableDatabaseConfigureButton(cbUseCentralRepo.isSelected()); enableButtonSubComponents(cbUseCentralRepo.isSelected() && !EamDbPlatformEnum.getSelectedPlatform().equals(DISABLED)); + this.ingestStateUpdated(); + firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null); }//GEN-LAST:event_cbUseCentralRepoActionPerformed @Override @@ -296,7 +301,6 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i break; } - this.ingestStateUpdated(); } @Override @@ -358,6 +362,11 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i if (IngestManager.getInstance().isIngestRunning()) { tbOops.setText(Bundle.GlobalSettingsPanel_validationErrMsg_ingestRunning()); enableAllSubComponents(false); + cbUseCentralRepo.setEnabled(false); + } + else if (!cbUseCentralRepo.isEnabled()){ + cbUseCentralRepo.setEnabled(true); + load(); } } From 13a497753593bb2fcf3580b9ab7dcb68cefe2715 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Mon, 14 Aug 2017 17:38:54 -0400 Subject: [PATCH 05/13] 2934 cleaned up reading/saving of Central Repo enabled setting --- .../centralrepository/datamodel/EamDb.java | 7 +++--- .../datamodel/EamDbUtil.java | 24 +++++++++++++++++-- .../optionspanel/GlobalSettingsPanel.java | 5 ++-- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java index b6be667a62..d0264eab54 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java @@ -20,7 +20,6 @@ package org.sleuthkit.autopsy.centralrepository.datamodel; import java.util.List; import java.util.Set; -import org.sleuthkit.autopsy.coreutils.ModuleSettings; /** * Main interface for interacting with the database @@ -37,9 +36,9 @@ public interface EamDb { * @throws EamDbException */ static EamDb getInstance() throws EamDbException { - + EamDbPlatformEnum selectedPlatform = EamDbPlatformEnum.DISABLED; - if (Boolean.parseBoolean(ModuleSettings.getConfigSetting("CentralRepository", "db.useCentralRepo"))){ + if (EamDbUtil.useCentralRepo()) { selectedPlatform = EamDbPlatformEnum.getSelectedPlatform(); } switch (selectedPlatform) { @@ -90,7 +89,7 @@ public interface EamDb { * @return Is the database enabled */ static boolean isEnabled() { - return Boolean.parseBoolean(ModuleSettings.getConfigSetting("CentralRepository", "db.useCentralRepo")) + return EamDbUtil.useCentralRepo() && EamDbPlatformEnum.getSelectedPlatform() != EamDbPlatformEnum.DISABLED; } diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDbUtil.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDbUtil.java index c663fe04f9..cfc9293721 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDbUtil.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDbUtil.java @@ -15,13 +15,15 @@ import java.util.List; import java.util.logging.Level; import static org.sleuthkit.autopsy.centralrepository.datamodel.EamDb.SCHEMA_VERSION; import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.coreutils.ModuleSettings; /** * */ public class EamDbUtil { private final static Logger LOGGER = Logger.getLogger(EamDbUtil.class.getName()); - + private static final String CENTRAL_REPO_NAME= "CentralRepository"; + private static final String CENTRAL_REPO_USE_KEY="db.useCentralRepo"; /** * Close the prepared statement. * @@ -156,7 +158,25 @@ public class EamDbUtil { } return true; } - + + /** + * If the Central Repos use has been enabled. + * + * @return true if the Central Repo may be configured, false if it should not be able to be + */ + public static boolean useCentralRepo(){ + return Boolean.parseBoolean(ModuleSettings.getConfigSetting(CENTRAL_REPO_NAME, CENTRAL_REPO_USE_KEY)); + } + + /** + * Saves the setting for whether the Central Repo should be able to be configured. + * + * @param centralRepoCheckBoxIsSelected - true if the central repo can be used + */ + public static void setUseCentralRepo(boolean centralRepoCheckBoxIsSelected){ + ModuleSettings.setConfigSetting(CENTRAL_REPO_NAME, CENTRAL_REPO_USE_KEY, Boolean.toString(centralRepoCheckBoxIsSelected)); + } + /** * Use the current settings and the validation query * to test the connection to the database. diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java index 2fe4b1a300..d2f15e4a1e 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java @@ -30,6 +30,7 @@ import org.sleuthkit.autopsy.ingest.IngestManager; import org.sleuthkit.autopsy.ingest.IngestModuleGlobalSettingsPanel; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbPlatformEnum; import static org.sleuthkit.autopsy.centralrepository.datamodel.EamDbPlatformEnum.DISABLED; +import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbUtil; import org.sleuthkit.autopsy.centralrepository.datamodel.PostgresEamDbSettings; import org.sleuthkit.autopsy.centralrepository.datamodel.SqliteEamDbSettings; import org.sleuthkit.autopsy.coreutils.ModuleSettings; @@ -276,7 +277,7 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i tbOops.setText(""); enableAllSubComponents(false); EamDbPlatformEnum selectedPlatform = EamDbPlatformEnum.getSelectedPlatform(); - cbUseCentralRepo.setSelected(Boolean.parseBoolean(ModuleSettings.getConfigSetting("CentralRepository", "db.useCentralRepo"))); // NON-NLS + cbUseCentralRepo.setSelected(EamDbUtil.useCentralRepo()); // NON-NLS switch (selectedPlatform) { case POSTGRESQL: PostgresEamDbSettings dbSettingsPg = new PostgresEamDbSettings(); @@ -305,7 +306,7 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i @Override public void store() { // Click OK or Apply on Options Panel - ModuleSettings.setConfigSetting("CentralRepository", "db.useCentralRepo", Boolean.toString(cbUseCentralRepo.isSelected())); + EamDbUtil.setUseCentralRepo(cbUseCentralRepo.isSelected()); } /** From c38cdc3e9868a8d96ebedfa8b567b208fa588334 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Mon, 14 Aug 2017 17:50:18 -0400 Subject: [PATCH 06/13] 2934 remove un-used import --- .../centralrepository/optionspanel/GlobalSettingsPanel.java | 1 - 1 file changed, 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java index d2f15e4a1e..4b6ad6b408 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java @@ -33,7 +33,6 @@ import static org.sleuthkit.autopsy.centralrepository.datamodel.EamDbPlatformEnu import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbUtil; import org.sleuthkit.autopsy.centralrepository.datamodel.PostgresEamDbSettings; import org.sleuthkit.autopsy.centralrepository.datamodel.SqliteEamDbSettings; -import org.sleuthkit.autopsy.coreutils.ModuleSettings; /** * Main settings panel for the Central Repository From 5b3a3204c838e0d72c0d912afefaa47b04366265 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Mon, 14 Aug 2017 18:07:15 -0400 Subject: [PATCH 07/13] Clean up Central GUI changes, remove un-used code, refactor some names --- .../optionspanel/Bundle.properties | 4 +- .../optionspanel/EamDbSettingsDialog.form | 28 +++--- .../optionspanel/EamDbSettingsDialog.java | 91 ++++++------------- .../optionspanel/GlobalSettingsPanel.java | 1 - 4 files changed, 41 insertions(+), 83 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/Bundle.properties b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/Bundle.properties index 8703a8a83c..c126b4e4dc 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/Bundle.properties @@ -74,6 +74,6 @@ GlobalSettingsPanel.bnManageProperties.text=Manage Correlation Properties ImportHashDatabaseDialog.lbInstructions.text=Choose an .idx file to import into the central repository. ImportHashDatabaseDialog.lbFilePath.text=File Path: ImportHashDatabaseDialog.tfFilePath.text= -EamDbSettingsDialog.jLabel1.text=SQLite should only be used by one examiner at a time. -EamDbSettingsDialog.jLabel2.text=Database type: GlobalSettingsPanel.cbUseCentralRepo.text=Use a Central Repository +EamDbSettingsDialog.lbDatabaseType.text=Database type: +EamDbSettingsDialog.lbSingleUserSqLite.text=SQLite should only be used by one examiner at a time. diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.form b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.form index ee8c05590a..a3ff6584b0 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.form +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.form @@ -120,7 +120,7 @@ - + @@ -129,9 +129,9 @@ - + - + @@ -159,10 +159,10 @@ - - + + - + @@ -212,10 +212,6 @@ - - - - @@ -263,30 +259,30 @@ - + - + - + - + - + - + diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java index 98640d9d8a..af33b50ba7 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java @@ -58,7 +58,11 @@ public class EamDbSettingsDialog extends JDialog { /** * Creates new form EamDbSettingsDialog */ - @Messages({"EamDbSettingsDialog.title.text=Central Repository Database Configuration"}) + @Messages({"EamDbSettingsDialog.title.text=Central Repository Database Configuration", + "EamDbSettingsDialog.lbSingleUserSqLite=SQLite should only be used by one examiner at a time.", + "EamDbSettingsDialog.lbDatabaseType=Database type :", + "EamDbSettingsDialog.cbUseCentralRepo.text=Use a Central Repo"}) + public EamDbSettingsDialog() { super((JFrame) WindowManager.getDefault().getMainWindow(), Bundle.EamDbSettingsDialog_title_text(), @@ -77,7 +81,7 @@ public class EamDbSettingsDialog extends JDialog { initComponents(); fcDatabasePath.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - jComboBox1.setSelectedItem(selectedPlatform); + cbDatabaseType.setSelectedItem(selectedPlatform); customizeComponents(); valid(); display(); @@ -110,9 +114,9 @@ public class EamDbSettingsDialog extends JDialog { tbDbUsername = new javax.swing.JTextField(); lbUserPassword = new javax.swing.JLabel(); jpDbPassword = new javax.swing.JPasswordField(); - jComboBox1 = new javax.swing.JComboBox<>(); - jLabel1 = new javax.swing.JLabel(); - jLabel2 = new javax.swing.JLabel(); + cbDatabaseType = new javax.swing.JComboBox<>(); + lbSingleUserSqLite = new javax.swing.JLabel(); + lbDatabaseType = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); @@ -157,16 +161,6 @@ public class EamDbSettingsDialog extends JDialog { tfDatabasePath.setText(org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.tfDatabasePath.text")); // NOI18N tfDatabasePath.setToolTipText(org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.tfDatabasePath.toolTipText")); // NOI18N - tfDatabasePath.addFocusListener(new java.awt.event.FocusAdapter() { - public void focusLost(java.awt.event.FocusEvent evt) { - tfDatabasePathFocusLost(evt); - } - }); - tfDatabasePath.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - tfDatabasePathActionPerformed(evt); - } - }); org.openide.awt.Mnemonics.setLocalizedText(bnDatabasePathFileOpen, org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.bnDatabasePathFileOpen.text")); // NOI18N bnDatabasePathFileOpen.addActionListener(new java.awt.event.ActionListener() { @@ -183,16 +177,16 @@ public class EamDbSettingsDialog extends JDialog { org.openide.awt.Mnemonics.setLocalizedText(lbUserPassword, org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.lbUserPassword.text")); // NOI18N - jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new EamDbPlatformEnum[]{EamDbPlatformEnum.POSTGRESQL, EamDbPlatformEnum.SQLITE})); - jComboBox1.addActionListener(new java.awt.event.ActionListener() { + cbDatabaseType.setModel(new javax.swing.DefaultComboBoxModel<>(new EamDbPlatformEnum[]{EamDbPlatformEnum.POSTGRESQL, EamDbPlatformEnum.SQLITE})); + cbDatabaseType.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { - jComboBox1ActionPerformed(evt); + cbDatabaseTypeActionPerformed(evt); } }); - org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.jLabel1.text")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(lbSingleUserSqLite, org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.lbSingleUserSqLite.text")); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.jLabel2.text")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(lbDatabaseType, org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.lbDatabaseType.text")); // NOI18N javax.swing.GroupLayout pnSQLiteSettingsLayout = new javax.swing.GroupLayout(pnSQLiteSettings); pnSQLiteSettings.setLayout(pnSQLiteSettingsLayout); @@ -204,16 +198,16 @@ public class EamDbSettingsDialog extends JDialog { .addComponent(lbHostName) .addComponent(lbPort) .addComponent(lbUserName) - .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(lbDatabaseType, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(lbDatabasePath) .addComponent(lbUserPassword, javax.swing.GroupLayout.Alignment.TRAILING))) .addGap(10, 10, 10) .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnSQLiteSettingsLayout.createSequentialGroup() - .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(cbDatabaseType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 467, Short.MAX_VALUE) + .addComponent(lbSingleUserSqLite, javax.swing.GroupLayout.DEFAULT_SIZE, 467, Short.MAX_VALUE) .addGap(9, 9, 9)) .addGroup(pnSQLiteSettingsLayout.createSequentialGroup() .addComponent(tfDatabasePath) @@ -234,9 +228,9 @@ public class EamDbSettingsDialog extends JDialog { .addGap(6, 6, 6) .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel1)) - .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)) + .addComponent(cbDatabaseType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(lbSingleUserSqLite)) + .addComponent(lbDatabaseType, javax.swing.GroupLayout.Alignment.TRAILING)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(lbDatabasePath, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) @@ -311,19 +305,6 @@ public class EamDbSettingsDialog extends JDialog { setVisible(true); } - private void setGuidanceMessage(String message, boolean isError) { - - if (isError) { - - } else { - - } - } - - private void clearIcons() { - - } - @Messages({"EamDbSettingsDialog.chooserPath.failedToGetDbPathMsg=Selected database path is invalid. Try again."}) private void bnDatabasePathFileOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnDatabasePathFileOpenActionPerformed fcDatabasePath.setCurrentDirectory(new File(dbSettingsSqlite.getDbDirectory())); @@ -335,7 +316,6 @@ public class EamDbSettingsDialog extends JDialog { valid(); } catch (IOException ex) { LOGGER.log(Level.SEVERE, "Failed to get path of selected database file", ex); // NON-NLS - setGuidanceMessage(Bundle.EamDbSettingsDialog_chooserPath_failedToGetDbPathMsg(), true); } } }//GEN-LAST:event_bnDatabasePathFileOpenActionPerformed @@ -374,7 +354,6 @@ public class EamDbSettingsDialog extends JDialog { @Messages({"EamDbSettingsDialog.okButton.createDbError.title=Unable to Create Database", "EamDbSettingsDialog.okButton.createDbError.message=Unable to create Database, please ensure location was valid and try again."}) private void createDb() { - clearIcons(); boolean result = false; boolean dbCreated = true; switch (selectedPlatform) { @@ -477,7 +456,6 @@ public class EamDbSettingsDialog extends JDialog { EamDb.getInstance().updateSettings(); } catch (EamDbException ex) { LOGGER.log(Level.SEVERE, Bundle.EamDbSettingsDialog_okButton_connectionErrorMsg_text(), ex); //NON-NLS - setGuidanceMessage(Bundle.EamDbSettingsDialog_okButton_connectionErrorMsg_text(), true); setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); return; } @@ -492,7 +470,6 @@ public class EamDbSettingsDialog extends JDialog { EamDb.getInstance().updateSettings(); } catch (EamDbException ex) { LOGGER.log(Level.SEVERE, Bundle.EamDbSettingsDialog_okButton_connectionErrorMsg_text(), ex); //NON-NLS - setGuidanceMessage(Bundle.EamDbSettingsDialog_okButton_connectionErrorMsg_text(), true); setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); return; } @@ -510,23 +487,15 @@ public class EamDbSettingsDialog extends JDialog { }//GEN-LAST:event_bnCancelActionPerformed - private void tfDatabasePathFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfDatabasePathFocusLost - - }//GEN-LAST:event_tfDatabasePathFocusLost - - private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed - selectedPlatform = (EamDbPlatformEnum) jComboBox1.getSelectedItem(); + private void cbDatabaseTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbDatabaseTypeActionPerformed + selectedPlatform = (EamDbPlatformEnum) cbDatabaseType.getSelectedItem(); customizeComponents(); - }//GEN-LAST:event_jComboBox1ActionPerformed - - private void tfDatabasePathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfDatabasePathActionPerformed - // TODO add your handling code here: - }//GEN-LAST:event_tfDatabasePathActionPerformed + }//GEN-LAST:event_cbDatabaseTypeActionPerformed private void displayDatabaseSettings(boolean isPostgres) { lbDatabasePath.setVisible(!isPostgres); tfDatabasePath.setVisible(!isPostgres); - jLabel1.setVisible(!isPostgres); + lbSingleUserSqLite.setVisible(!isPostgres); bnDatabasePathFileOpen.setVisible(!isPostgres); lbHostName.setVisible(isPostgres); tbDbHostname.setVisible(isPostgres); @@ -641,7 +610,6 @@ public class EamDbSettingsDialog extends JDialog { } if (!result) { - setGuidanceMessage(Bundle.EamDbSettingsDialog_validation_incompleteFields(), true); } return result; @@ -715,7 +683,6 @@ public class EamDbSettingsDialog extends JDialog { break; } - setGuidanceMessage(guidanceText.toString(), true); return result; } @@ -738,7 +705,6 @@ public class EamDbSettingsDialog extends JDialog { private boolean enableOkButton(boolean isValidInput) { if (isValidInput) { bnOk.setEnabled(true); - setGuidanceMessage(Bundle.EamDbSettingsDialog_validation_finished(), false); } else { bnOk.setEnabled(false); } @@ -755,7 +721,6 @@ public class EamDbSettingsDialog extends JDialog { @Override public void changedUpdate(DocumentEvent e) { firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null); - clearIcons(); testingStatus = DatabaseTestResult.UNTESTED; valid(); } @@ -763,7 +728,6 @@ public class EamDbSettingsDialog extends JDialog { @Override public void insertUpdate(DocumentEvent e) { firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null); - clearIcons(); testingStatus = DatabaseTestResult.UNTESTED; valid(); } @@ -771,7 +735,6 @@ public class EamDbSettingsDialog extends JDialog { @Override public void removeUpdate(DocumentEvent e) { firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null); - clearIcons(); testingStatus = DatabaseTestResult.UNTESTED; valid(); @@ -790,14 +753,14 @@ public class EamDbSettingsDialog extends JDialog { private javax.swing.JButton bnDatabasePathFileOpen; private javax.swing.ButtonGroup bnGrpDatabasePlatforms; private javax.swing.JButton bnOk; + private javax.swing.JComboBox cbDatabaseType; private javax.swing.JFileChooser fcDatabasePath; - private javax.swing.JComboBox jComboBox1; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel2; private javax.swing.JPasswordField jpDbPassword; private javax.swing.JLabel lbDatabasePath; + private javax.swing.JLabel lbDatabaseType; private javax.swing.JLabel lbHostName; private javax.swing.JLabel lbPort; + private javax.swing.JLabel lbSingleUserSqLite; private javax.swing.JLabel lbUserName; private javax.swing.JLabel lbUserPassword; private javax.swing.JPanel pnButtons; diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java index 4b6ad6b408..f2506df04e 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java @@ -53,7 +53,6 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i initComponents(); customizeComponents(); addIngestJobEventsListener(); - } @Messages({"GlobalSettingsPanel.title=Central Repository Settings"}) From f28900ac2afccd1d0b007b22064438e2ef4d5ee1 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Mon, 14 Aug 2017 18:28:52 -0400 Subject: [PATCH 08/13] 2934 fixed bundle messages for labels on Central repo GUI --- .../centralrepository/optionspanel/Bundle.properties | 3 --- .../centralrepository/optionspanel/EamDbSettingsDialog.java | 5 ++--- .../centralrepository/optionspanel/GlobalSettingsPanel.java | 6 +++--- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/Bundle.properties b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/Bundle.properties index c126b4e4dc..ed1de3ea5b 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/Bundle.properties @@ -74,6 +74,3 @@ GlobalSettingsPanel.bnManageProperties.text=Manage Correlation Properties ImportHashDatabaseDialog.lbInstructions.text=Choose an .idx file to import into the central repository. ImportHashDatabaseDialog.lbFilePath.text=File Path: ImportHashDatabaseDialog.tfFilePath.text= -GlobalSettingsPanel.cbUseCentralRepo.text=Use a Central Repository -EamDbSettingsDialog.lbDatabaseType.text=Database type: -EamDbSettingsDialog.lbSingleUserSqLite.text=SQLite should only be used by one examiner at a time. diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java index af33b50ba7..aa27652009 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java @@ -59,9 +59,8 @@ public class EamDbSettingsDialog extends JDialog { * Creates new form EamDbSettingsDialog */ @Messages({"EamDbSettingsDialog.title.text=Central Repository Database Configuration", - "EamDbSettingsDialog.lbSingleUserSqLite=SQLite should only be used by one examiner at a time.", - "EamDbSettingsDialog.lbDatabaseType=Database type :", - "EamDbSettingsDialog.cbUseCentralRepo.text=Use a Central Repo"}) + "EamDbSettingsDialog.lbSingleUserSqLite.text=SQLite should only be used by one examiner at a time.", + "EamDbSettingsDialog.lbDatabaseType.text=Database type :"}) public EamDbSettingsDialog() { super((JFrame) WindowManager.getDefault().getMainWindow(), diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java index f2506df04e..8716c1d4ce 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java @@ -55,7 +55,8 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i addIngestJobEventsListener(); } - @Messages({"GlobalSettingsPanel.title=Central Repository Settings"}) + @Messages({"GlobalSettingsPanel.title=Central Repository Settings", + "GlobalSettingsPanel.cbUseCentralRepo.text=Use a Central Repository"}) private void customizeComponents() { setName(Bundle.GlobalSettingsPanel_title()); } @@ -362,8 +363,7 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i tbOops.setText(Bundle.GlobalSettingsPanel_validationErrMsg_ingestRunning()); enableAllSubComponents(false); cbUseCentralRepo.setEnabled(false); - } - else if (!cbUseCentralRepo.isEnabled()){ + } else if (!cbUseCentralRepo.isEnabled()) { cbUseCentralRepo.setEnabled(true); load(); } From a0d9fb00c2c93d93038141c951eefef79ce434c8 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Tue, 15 Aug 2017 10:01:46 -0400 Subject: [PATCH 09/13] 2934-remove un-used code from central repo code --- .../centralrepository/optionspanel/EamDbSettingsDialog.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java index aa27652009..608bad40d3 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java @@ -47,8 +47,6 @@ public class EamDbSettingsDialog extends JDialog { private static final String CENTRAL_REPO_SQLITE_EXT = ".db"; private final Collection textBoxes; private final TextBoxChangedListener textBoxChangedListener; - private final ImageIcon goodIcon; - private final ImageIcon badIcon; private final PostgresEamDbSettings dbSettingsPostgres; private final SqliteEamDbSettings dbSettingsSqlite; @@ -69,8 +67,6 @@ public class EamDbSettingsDialog extends JDialog { textBoxes = new ArrayList<>(); textBoxChangedListener = new TextBoxChangedListener(); - goodIcon = new ImageIcon(ImageUtilities.loadImage("org/sleuthkit/autopsy/images/good.png", false)); // NON-NLS - badIcon = new ImageIcon(ImageUtilities.loadImage("org/sleuthkit/autopsy/images/bad.png", false)); // NON-NLS dbSettingsPostgres = new PostgresEamDbSettings(); dbSettingsSqlite = new SqliteEamDbSettings(); selectedPlatform = EamDbPlatformEnum.getSelectedPlatform(); From f8490ed1f0461672cbe911a44bc0d4a5b6e3dc66 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Tue, 15 Aug 2017 10:07:09 -0400 Subject: [PATCH 10/13] 2934 minor formatting and removing unused import fixes for central repo gui --- .../datamodel/EamDbUtil.java | 63 ++++++++++--------- .../datamodel/SqliteEamDbSettings.java | 37 ++++++----- .../optionspanel/EamDbSettingsDialog.java | 9 ++- 3 files changed, 57 insertions(+), 52 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDbUtil.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDbUtil.java index cfc9293721..489f4cb12e 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDbUtil.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDbUtil.java @@ -3,7 +3,6 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ - package org.sleuthkit.autopsy.centralrepository.datamodel; import java.sql.Connection; @@ -21,9 +20,11 @@ import org.sleuthkit.autopsy.coreutils.ModuleSettings; * */ public class EamDbUtil { + private final static Logger LOGGER = Logger.getLogger(EamDbUtil.class.getName()); - private static final String CENTRAL_REPO_NAME= "CentralRepository"; - private static final String CENTRAL_REPO_USE_KEY="db.useCentralRepo"; + private static final String CENTRAL_REPO_NAME = "CentralRepository"; + private static final String CENTRAL_REPO_USE_KEY = "db.useCentralRepo"; + /** * Close the prepared statement. * @@ -74,11 +75,12 @@ public class EamDbUtil { } } } - + /** * Insert the default correlation types into the database. - * + * * @param conn Open connection to use. + * * @return true on success, else false */ public static boolean insertDefaultCorrelationTypes(Connection conn) { @@ -106,7 +108,7 @@ public class EamDbUtil { } return true; } - + /** * Store the schema version into the db_info table. * @@ -114,6 +116,7 @@ public class EamDbUtil { * loaded. * * @param conn Open connection to use. + * * @return true on success, else false */ public static boolean insertSchemaVersion(Connection conn) { @@ -135,14 +138,14 @@ public class EamDbUtil { /** * Query to see if the SCHEMA_VERSION is set in the db. - * + * * @return true if set, else false. */ public static boolean schemaVersionIsSet(Connection conn) { if (null == conn) { return false; } - + ResultSet resultSet = null; try { Statement tester = conn.createStatement(); @@ -158,36 +161,39 @@ public class EamDbUtil { } return true; } - + /** * If the Central Repos use has been enabled. - * - * @return true if the Central Repo may be configured, false if it should not be able to be + * + * @return true if the Central Repo may be configured, false if it should + * not be able to be */ - public static boolean useCentralRepo(){ + public static boolean useCentralRepo() { return Boolean.parseBoolean(ModuleSettings.getConfigSetting(CENTRAL_REPO_NAME, CENTRAL_REPO_USE_KEY)); } - + /** - * Saves the setting for whether the Central Repo should be able to be configured. - * - * @param centralRepoCheckBoxIsSelected - true if the central repo can be used + * Saves the setting for whether the Central Repo should be able to be + * configured. + * + * @param centralRepoCheckBoxIsSelected - true if the central repo can be + * used */ - public static void setUseCentralRepo(boolean centralRepoCheckBoxIsSelected){ + public static void setUseCentralRepo(boolean centralRepoCheckBoxIsSelected) { ModuleSettings.setConfigSetting(CENTRAL_REPO_NAME, CENTRAL_REPO_USE_KEY, Boolean.toString(centralRepoCheckBoxIsSelected)); } - - /** - * Use the current settings and the validation query - * to test the connection to the database. - * + + /** + * Use the current settings and the validation query to test the connection + * to the database. + * * @return true if successfull query execution, else false. */ public static boolean executeValidationQuery(Connection conn, String validationQuery) { if (null == conn) { return false; } - + ResultSet resultSet = null; try { Statement tester = conn.createStatement(); @@ -203,22 +209,23 @@ public class EamDbUtil { return false; } - /** * Conver thte Type's DbTableName string to the *_instances table name. - * + * * @param type Correlation Type - * @return Instance table name for this Type. + * + * @return Instance table name for this Type. */ public static String correlationTypeToInstanceTableName(EamArtifact.Type type) { return type.getDbTableName() + "_instances"; } - + /** * Convert the Type's DbTableName string to the reference_* table name. - * + * * @param type Correlation Type + * * @return Reference table name for this Type. */ public static String correlationTypeToReferenceTableName(EamArtifact.Type type) { diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDbSettings.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDbSettings.java index 177db2d1ae..590e572499 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDbSettings.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDbSettings.java @@ -94,7 +94,7 @@ public final class SqliteEamDbSettings { if (badTagsStr == null) { badTagsStr = DEFAULT_BAD_TAGS; } - if(badTagsStr.isEmpty()){ + if (badTagsStr.isEmpty()) { badTags = new ArrayList<>(); } else { badTags = new ArrayList<>(Arrays.asList(badTagsStr.split(","))); @@ -112,13 +112,13 @@ public final class SqliteEamDbSettings { /** * Verify that the db directory path exists. - * + * * @return true if exists, else false */ public boolean dbDirectoryExists() { // Ensure dbDirectory is a valid directory File dbDir = new File(getDbDirectory()); - + if (!dbDir.exists()) { return false; } else if (!dbDir.isDirectory()) { @@ -131,7 +131,7 @@ public final class SqliteEamDbSettings { /** * Create the db directory if it does not exist. - * + * * @return true is successfully created or already exists, else false */ public boolean createDbDirectory() { @@ -163,10 +163,11 @@ public final class SqliteEamDbSettings { } /** - * Use the current settings to get an ephemeral client connection for testing. - * + * Use the current settings to get an ephemeral client connection for + * testing. + * * If the directory path does not exist, it will return null. - * + * * @return Connection or null. */ private Connection getEphemeralConnection() { @@ -187,9 +188,9 @@ public final class SqliteEamDbSettings { } /** - * Use the current settings and the validation query - * to test the connection to the database. - * + * Use the current settings and the validation query to test the connection + * to the database. + * * @return true if successfull connection, else false. */ public boolean verifyConnection() { @@ -197,16 +198,16 @@ public final class SqliteEamDbSettings { if (null == conn) { return false; } - + boolean result = EamDbUtil.executeValidationQuery(conn, VALIDATION_QUERY); EamDbUtil.closeConnection(conn); return result; } /** - * Use the current settings and the schema version query - * to test the database schema. - * + * Use the current settings and the schema version query to test the + * database schema. + * * @return true if successfull connection, else false. */ public boolean verifyDatabaseSchema() { @@ -248,7 +249,6 @@ public final class SqliteEamDbSettings { // NOTE: The organizations will only have a small number of rows, so // an index is probably not worthwhile. - StringBuilder createCasesTable = new StringBuilder(); createCasesTable.append("CREATE TABLE IF NOT EXISTS cases ("); createCasesTable.append("id integer primary key autoincrement NOT NULL,"); @@ -347,7 +347,6 @@ public final class SqliteEamDbSettings { // NOTE: the db_info table currenly only has 1 row, so having an index // provides no benefit. - Connection conn = null; try { conn = getEphemeralConnection(); @@ -386,7 +385,7 @@ public final class SqliteEamDbSettings { for (EamArtifact.Type type : DEFAULT_CORRELATION_TYPES) { reference_type_dbname = EamDbUtil.correlationTypeToReferenceTableName(type); instance_type_dbname = EamDbUtil.correlationTypeToInstanceTableName(type); - + stmt.execute(String.format(createArtifactInstancesTableTemplate.toString(), instance_type_dbname, instance_type_dbname)); stmt.execute(String.format(instancesIdx1, instance_type_dbname, instance_type_dbname)); stmt.execute(String.format(instancesIdx2, instance_type_dbname, instance_type_dbname)); @@ -398,7 +397,7 @@ public final class SqliteEamDbSettings { stmt.execute(String.format(createReferenceTypesTableTemplate.toString(), reference_type_dbname, reference_type_dbname)); stmt.execute(String.format(referenceTypesIdx1, reference_type_dbname, reference_type_dbname)); stmt.execute(String.format(referenceTypesIdx2, reference_type_dbname, reference_type_dbname)); - } + } } } catch (SQLException ex) { LOGGER.log(Level.SEVERE, "Error initializing db schema.", ex); // NON-NLS @@ -423,7 +422,7 @@ public final class SqliteEamDbSettings { EamDbUtil.closeConnection(conn); return result; } - + public boolean isChanged() { String dbNameString = ModuleSettings.getConfigSetting("CentralRepository", "db.sqlite.dbName"); // NON-NLS String dbDirectoryString = ModuleSettings.getConfigSetting("CentralRepository", "db.sqlite.dbDirectory"); // NON-NLS diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java index 608bad40d3..38a79584df 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java @@ -14,7 +14,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.logging.Level; -import javax.swing.ImageIcon; import javax.swing.JDialog; import javax.swing.JFileChooser; import javax.swing.JFrame; @@ -24,7 +23,6 @@ import javax.swing.SwingUtilities; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import org.netbeans.spi.options.OptionsPanelController; -import org.openide.util.ImageUtilities; import org.openide.util.NbBundle.Messages; import org.openide.windows.WindowManager; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb; @@ -45,6 +43,7 @@ public class EamDbSettingsDialog extends JDialog { private static final Logger LOGGER = Logger.getLogger(EamDbSettingsDialog.class.getName()); private static final String CENTRAL_REPO_DB_NAME = "central_repository"; private static final String CENTRAL_REPO_SQLITE_EXT = ".db"; + private static final long serialVersionUID = 1L; private final Collection textBoxes; private final TextBoxChangedListener textBoxChangedListener; @@ -57,9 +56,9 @@ public class EamDbSettingsDialog extends JDialog { * Creates new form EamDbSettingsDialog */ @Messages({"EamDbSettingsDialog.title.text=Central Repository Database Configuration", - "EamDbSettingsDialog.lbSingleUserSqLite.text=SQLite should only be used by one examiner at a time.", - "EamDbSettingsDialog.lbDatabaseType.text=Database type :"}) - + "EamDbSettingsDialog.lbSingleUserSqLite.text=SQLite should only be used by one examiner at a time.", + "EamDbSettingsDialog.lbDatabaseType.text=Database type :"}) + public EamDbSettingsDialog() { super((JFrame) WindowManager.getDefault().getMainWindow(), Bundle.EamDbSettingsDialog_title_text(), From f93f6694f327e286496764f224938a23668afde9 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Tue, 15 Aug 2017 14:33:42 -0400 Subject: [PATCH 11/13] 2934 Central repo option stay disabled during ingest now --- .../optionspanel/GlobalSettingsPanel.java | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java index 8716c1d4ce..c0be22bf90 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java @@ -361,7 +361,6 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i if (IngestManager.getInstance().isIngestRunning()) { tbOops.setText(Bundle.GlobalSettingsPanel_validationErrMsg_ingestRunning()); - enableAllSubComponents(false); cbUseCentralRepo.setEnabled(false); } else if (!cbUseCentralRepo.isEnabled()) { cbUseCentralRepo.setEnabled(true); @@ -391,16 +390,17 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i * @return True */ private void enableDatabaseConfigureButton(Boolean enable) { - pnDatabaseConfiguration.setEnabled(enable); - pnDatabaseContentButtons.setEnabled(enable); - bnDbConfigure.setEnabled(enable); - lbDbLocationLabel.setEnabled(enable); - lbDbLocationValue.setEnabled(enable); - lbDbNameLabel.setEnabled(enable); - lbDbNameValue.setEnabled(enable); - lbDbPlatformTypeLabel.setEnabled(enable); - lbDbPlatformValue.setEnabled(enable); - tbOops.setEnabled(enable); + boolean ingestRunning = IngestManager.getInstance().isIngestRunning(); + pnDatabaseConfiguration.setEnabled(enable && !ingestRunning); + pnDatabaseContentButtons.setEnabled(enable && !ingestRunning); + bnDbConfigure.setEnabled(enable && !ingestRunning); + lbDbLocationLabel.setEnabled(enable && !ingestRunning); + lbDbLocationValue.setEnabled(enable && !ingestRunning); + lbDbNameLabel.setEnabled(enable && !ingestRunning); + lbDbNameValue.setEnabled(enable && !ingestRunning); + lbDbPlatformTypeLabel.setEnabled(enable && !ingestRunning); + lbDbPlatformValue.setEnabled(enable && !ingestRunning); + tbOops.setEnabled(enable && !ingestRunning); } /** @@ -412,9 +412,10 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i * @return True */ private boolean enableButtonSubComponents(Boolean enable) { - bnManageTypes.setEnabled(enable); - bnImportDatabase.setEnabled(enable); - bnManageTags.setEnabled(enable); + boolean ingestRunning = IngestManager.getInstance().isIngestRunning(); + bnManageTypes.setEnabled(enable && !ingestRunning); + bnImportDatabase.setEnabled(enable && !ingestRunning); + bnManageTags.setEnabled(enable && !ingestRunning); return true; } From 7dcf39698bd6358ed598d59d26c3d4ec990eeaa3 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Thu, 17 Aug 2017 10:24:47 -0400 Subject: [PATCH 12/13] 2934 fixed issue with SQLite db creation for CR not handling SecurityExceptions --- .../datamodel/SqliteEamDbSettings.java | 2 +- .../optionspanel/EamDbSettingsDialog.java | 33 ++++++++++++------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDbSettings.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDbSettings.java index 590e572499..5c02d17ea0 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDbSettings.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDbSettings.java @@ -140,7 +140,7 @@ public final class SqliteEamDbSettings { File dbDir = new File(getDbDirectory()); Files.createDirectories(dbDir.toPath()); LOGGER.log(Level.INFO, "sqlite directory did not exist, created it at {0}.", getDbDirectory()); // NON-NLS - } catch (IOException | InvalidPathException ex) { + } catch (IOException | InvalidPathException | SecurityException ex) { LOGGER.log(Level.SEVERE, "Failed to create sqlite database directory.", ex); // NON-NLS return false; } diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java index 38a79584df..14b107e27b 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java @@ -346,7 +346,8 @@ public class EamDbSettingsDialog extends JDialog { } @Messages({"EamDbSettingsDialog.okButton.createDbError.title=Unable to Create Database", - "EamDbSettingsDialog.okButton.createDbError.message=Unable to create Database, please ensure location was valid and try again."}) + "EamDbSettingsDialog.okButton.createSQLiteDbError.message=Unable to create SQLite Database, please ensure location exists and you have write permissions and try again.", + "EamDbSettingsDialog.okButton.createPostgresDbError.message=Unable to create Postgres Database, please ensure address, port, and login credentials are correct for Postgres server and try again."}) private void createDb() { boolean result = false; boolean dbCreated = true; @@ -355,24 +356,32 @@ public class EamDbSettingsDialog extends JDialog { if (!dbSettingsPostgres.verifyDatabaseExists()) { dbCreated = dbSettingsPostgres.createDatabase(); } - result = dbSettingsPostgres.initializeDatabaseSchema() - && dbSettingsPostgres.insertDefaultDatabaseContent(); - + if (!dbCreated) { + JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), + Bundle.EamDbSettingsDialog_okButton_createPostgresDbError_message(), + Bundle.EamDbSettingsDialog_okButton_createDbError_title(), + JOptionPane.WARNING_MESSAGE); + } else { + result = dbSettingsPostgres.initializeDatabaseSchema() + && dbSettingsPostgres.insertDefaultDatabaseContent(); + } break; case SQLITE: if (!dbSettingsSqlite.dbDirectoryExists()) { dbCreated = dbSettingsSqlite.createDbDirectory(); } - result = dbSettingsSqlite.initializeDatabaseSchema() - && dbSettingsSqlite.insertDefaultDatabaseContent(); + if (!dbCreated) { + JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), + Bundle.EamDbSettingsDialog_okButton_createSQLiteDbError_message(), + Bundle.EamDbSettingsDialog_okButton_createDbError_title(), + JOptionPane.WARNING_MESSAGE); + } else { + result = dbSettingsSqlite.initializeDatabaseSchema() + && dbSettingsSqlite.insertDefaultDatabaseContent(); + } break; } - if (false == dbCreated) { - JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), - Bundle.EamDbSettingsDialog_okButton_createDbError_message(), - Bundle.EamDbSettingsDialog_okButton_createDbError_title(), - JOptionPane.WARNING_MESSAGE); - } else if (false == result) { + if (false == result) { LOGGER.severe("Unable to initialize database schema or insert contents into Central Repository."); } else { testingStatus = DatabaseTestResult.TESTEDOK; From df831d3f8009981751fd07af3817e0aedd7192cb Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Thu, 17 Aug 2017 11:34:56 -0400 Subject: [PATCH 13/13] 2934 fixed case with SQLite CR creation where directory exists but is protected --- .../optionspanel/EamDbSettingsDialog.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java index 14b107e27b..6ef345ac4f 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java @@ -356,37 +356,39 @@ public class EamDbSettingsDialog extends JDialog { if (!dbSettingsPostgres.verifyDatabaseExists()) { dbCreated = dbSettingsPostgres.createDatabase(); } - if (!dbCreated) { + if (dbCreated) { + result = dbSettingsPostgres.initializeDatabaseSchema() + && dbSettingsPostgres.insertDefaultDatabaseContent(); + } + if (!result) { JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), Bundle.EamDbSettingsDialog_okButton_createPostgresDbError_message(), Bundle.EamDbSettingsDialog_okButton_createDbError_title(), JOptionPane.WARNING_MESSAGE); - } else { - result = dbSettingsPostgres.initializeDatabaseSchema() - && dbSettingsPostgres.insertDefaultDatabaseContent(); + LOGGER.severe("Unable to initialize database schema or insert contents into Central Repository."); + return; } break; case SQLITE: if (!dbSettingsSqlite.dbDirectoryExists()) { dbCreated = dbSettingsSqlite.createDbDirectory(); } - if (!dbCreated) { + if (dbCreated) { + result = dbSettingsSqlite.initializeDatabaseSchema() + && dbSettingsSqlite.insertDefaultDatabaseContent(); + } + if (!result) { JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), Bundle.EamDbSettingsDialog_okButton_createSQLiteDbError_message(), Bundle.EamDbSettingsDialog_okButton_createDbError_title(), JOptionPane.WARNING_MESSAGE); - } else { - result = dbSettingsSqlite.initializeDatabaseSchema() - && dbSettingsSqlite.insertDefaultDatabaseContent(); + LOGGER.severe("Unable to initialize database schema or insert contents into Central Repository."); + return; } break; } - if (false == result) { - LOGGER.severe("Unable to initialize database schema or insert contents into Central Repository."); - } else { - testingStatus = DatabaseTestResult.TESTEDOK; - valid(); - } + testingStatus = DatabaseTestResult.TESTEDOK; + valid(); } @Messages({"EamDbSettingsDialog.okButton.errorTitle.text=Restart Required.",