diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java index 25efc9ed30..5032cce74a 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -27,6 +27,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.util.Date; import java.util.GregorianCalendar; import java.util.HashMap; import java.util.HashSet; @@ -309,13 +310,23 @@ public class Case implements SleuthkitCase.ErrorObserver { String configFilePath = caseDir + File.separator + caseName + CASE_DOT_EXTENSION; XMLCaseManagement xmlcm = new XMLCaseManagement(); - xmlcm.create(caseDir, caseName, examiner, caseNumber, caseType); // create a new XML config file + + String dbName=null; + // figure out the database name + if (caseType == CaseType.LOCAL) { + dbName = caseDir + File.separator + "autopsy.db"; //NON-NLS + } else if (caseType == CaseType.SHARED) { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss"); + dbName = caseName + "_" + dateFormat.format(new Date()); + } + + xmlcm.create(caseDir, caseName, examiner, caseNumber, caseType, dbName); // create a new XML config file xmlcm.writeFile(); - String dbPath = caseDir + File.separator + "autopsy.db"; //NON-NLS + SleuthkitCase db = null; try { - db = SleuthkitCase.newCase(dbPath); + db = SleuthkitCase.newCase(dbName); /// KDM } catch (TskCoreException ex) { logger.log(Level.SEVERE, "Error creating a case: " + caseName + " in dir " + caseDir, ex); //NON-NLS throw new CaseActionException( @@ -353,7 +364,7 @@ public class Case implements SleuthkitCase.ErrorObserver { String caseDir = xmlcm.getCaseDirectory(); String dbPath = caseDir + File.separator + "autopsy.db"; //NON-NLS - SleuthkitCase db = SleuthkitCase.openCase(dbPath); + SleuthkitCase db = SleuthkitCase.openCase(dbPath); // KDM if (null != db.getBackupDatabasePath()) { JOptionPane.showMessageDialog(null, NbBundle.getMessage(Case.class, "Case.open.msgDlg.updated.msg", diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java b/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java index 02f28f115d..ec850af83a 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java @@ -16,7 +16,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.sleuthkit.autopsy.casemodule; import org.openide.util.NbBundle; @@ -36,20 +35,29 @@ import org.sleuthkit.autopsy.core.UserPreferences; * * @author jantonius */ -final class NewCaseVisualPanel1 extends JPanel implements DocumentListener{ +final class NewCaseVisualPanel1 extends JPanel implements DocumentListener { private JFileChooser fc = new JFileChooser(); private NewCaseWizardPanel1 wizPanel; NewCaseVisualPanel1(NewCaseWizardPanel1 wizPanel) { initComponents(); - this.wizPanel = wizPanel; + this.wizPanel = wizPanel; caseNameTextField.getDocument().addDocumentListener(this); caseParentDirTextField.getDocument().addDocumentListener(this); - if (UserPreferences.newCaseType() == CaseType.LOCAL.ordinal()) { - rbLocalCase.setSelected(true); + boolean databaseConnectionSettingsOkay = true; /// KDM this becomes a static call in the TSK code. + // if we cannot connect to the shared database, don't present the option + // but do not change the setting stored in the preferences file + if (true == databaseConnectionSettingsOkay) { + if (UserPreferences.newCaseType() == CaseType.LOCAL.ordinal()) { + rbLocalCase.setSelected(true); + } else { + rbSharedCase.setSelected(true); + } } else { - rbSharedCase.setSelected(true); + rbLocalCase.setSelected(true); + rbLocalCase.setEnabled(false); + rbSharedCase.setEnabled(false); } } @@ -57,7 +65,7 @@ final class NewCaseVisualPanel1 extends JPanel implements DocumentListener{ * Returns the name of the this panel. This name will be shown on the left * panel of the "New Case" wizard panel. * - * @return name the name of this panel + * @return name the name of this panel */ @Override public String getName() { @@ -67,32 +75,32 @@ final class NewCaseVisualPanel1 extends JPanel implements DocumentListener{ /** * Gets the case name that the user types on the case name text field. * - * @return caseName the case name from the case name text field + * @return caseName the case name from the case name text field */ - public String getCaseName(){ + public String getCaseName() { return this.caseNameTextField.getText(); } /** - * Gets the base directory that the user typed on the base directory text field. - * Will add file separator if it was not added. + * Gets the base directory that the user typed on the base directory text + * field. Will add file separator if it was not added. * - * @return baseDirectory the base directory from the case dir text field + * @return baseDirectory the base directory from the case dir text field */ - public String getCaseParentDir(){ + public String getCaseParentDir() { String parentDir = this.caseParentDirTextField.getText(); - + if (parentDir.endsWith(File.separator) == false) { parentDir = parentDir + File.separator; } return parentDir; } - - public JTextField getCaseParentDirTextField(){ + + public JTextField getCaseParentDirTextField() { return this.caseParentDirTextField; } - - /** + + /** * Gets the case type. * * @return CaseType as set via radio buttons @@ -108,7 +116,8 @@ final class NewCaseVisualPanel1 extends JPanel implements DocumentListener{ return value; } - /** This method is called from within the constructor to initialize the form. + /** + * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @@ -213,27 +222,27 @@ final class NewCaseVisualPanel1 extends JPanel implements DocumentListener{ /** * The action when the Browse button is pressed. The browse button will pop - * up the file chooser window to choose where the user wants to save the + * up the file chooser window to choose where the user wants to save the * case directory. * - * @param evt the action event + * @param evt the action event */ private void caseDirBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_caseDirBrowseButtonActionPerformed // show the directory chooser where the case directory will be created fc.setDragEnabled(false); - if(!caseParentDirTextField.getText().trim().equals("")){ + if (!caseParentDirTextField.getText().trim().equals("")) { fc.setCurrentDirectory(new File(caseParentDirTextField.getText())); } fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); //fc.setSelectedFile(new File("C:\\Program Files\\")); //disableTextField(fc); // disable all the text field on the file chooser - int returnValue = fc.showDialog((Component)evt.getSource(), NbBundle.getMessage(this.getClass(), - "NewCaseVisualPanel1.caseDirBrowse.selectButton.text")); - if(returnValue == JFileChooser.APPROVE_OPTION){ + int returnValue = fc.showDialog((Component) evt.getSource(), NbBundle.getMessage(this.getClass(), + "NewCaseVisualPanel1.caseDirBrowse.selectButton.text")); + if (returnValue == JFileChooser.APPROVE_OPTION) { String path = fc.getSelectedFile().getPath(); caseParentDirTextField.setText(path); // put the path to the textfield - } + } }//GEN-LAST:event_caseDirBrowseButtonActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables @@ -251,10 +260,10 @@ final class NewCaseVisualPanel1 extends JPanel implements DocumentListener{ // End of variables declaration//GEN-END:variables /** - * Gives notification that there was an insert into the document. The - * range given by the DocumentEvent bounds the freshly inserted region. + * Gives notification that there was an insert into the document. The range + * given by the DocumentEvent bounds the freshly inserted region. * - * @param e the document event + * @param e the document event */ @Override public void insertUpdate(DocumentEvent e) { @@ -263,11 +272,11 @@ final class NewCaseVisualPanel1 extends JPanel implements DocumentListener{ } /** - * Gives notification that a portion of the document has been - * removed. The range is given in terms of what the view last - * saw (that is, before updating sticky positions). + * Gives notification that a portion of the document has been removed. The + * range is given in terms of what the view last saw (that is, before + * updating sticky positions). * - * @param e the document event + * @param e the document event */ @Override public void removeUpdate(DocumentEvent e) { @@ -278,7 +287,7 @@ final class NewCaseVisualPanel1 extends JPanel implements DocumentListener{ /** * Gives notification that an attribute or set of attributes changed. * - * @param e the document event + * @param e the document event */ @Override public void changedUpdate(DocumentEvent e) { @@ -288,20 +297,20 @@ final class NewCaseVisualPanel1 extends JPanel implements DocumentListener{ /** * The "listener" that listens when the fields in this form are updated. - * This method is used to determine when to enable / disable the "Finish" button. + * This method is used to determine when to enable / disable the "Finish" + * button. * - * @param e the document event + * @param e the document event */ public void updateUI(DocumentEvent e) { String caseName = getCaseName(); String parentDir = getCaseParentDir(); - if(!caseName.equals("") && !parentDir.equals("")){ - caseDirTextField.setText( parentDir + caseName); + if (!caseName.equals("") && !parentDir.equals("")) { + caseDirTextField.setText(parentDir + caseName); wizPanel.setIsFinish(true); - } - else{ + } else { caseDirTextField.setText(""); wizPanel.setIsFinish(false); } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/XMLCaseManagement.java b/Core/src/org/sleuthkit/autopsy/casemodule/XMLCaseManagement.java index 60411b0b6d..96bc930b1e 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/XMLCaseManagement.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/XMLCaseManagement.java @@ -71,6 +71,7 @@ import org.xml.sax.SAXException; final static String CACHE_FOLDER_NAME = "CacheFolder"; //NON-NLS final static String CACHE_FOLDER_RELPATH = "Cache"; //NON-NLS final static String CASE_TYPE = "CaseType"; //NON-NLS + final static String DATABASE_NAME = "DatabaseName"; //NON-NLS // folders attribute final static String RELATIVE_NAME = "Relative"; // relevant path info NON-NLS // folder attr values @@ -82,11 +83,13 @@ import org.xml.sax.SAXException; private DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss (z)"); private String caseDirPath; // case directory path private String caseName; // case name - private String caseNumber; // case number + private String caseNumber; // case number private String examiner; // examiner name private String schemaVersion = "1.0"; private String autopsySavedVersion; private CaseType caseType; // The type of case: local or shared + private String dbName; // The name of the database + // for error handling private JPanel caller; private String className = this.getClass().toString(); @@ -198,6 +201,15 @@ import org.xml.sax.SAXException; private void setCaseType(CaseType givenCaseType) { caseType = givenCaseType; // change this to change the xml file if needed } + + /** + * Sets the database name internally (on local variable in this class) + * + * @param givenDbName the new db name + */ + private void setDbName(String givenDbName) { + dbName= givenDbName; // change this to change the xml file if needed + } /** * Sets the examiner name internally (on local variable in this class) @@ -454,8 +466,10 @@ import org.xml.sax.SAXException; * directory * @param examiner examiner for the case (optional, can be empty string * @param caseNumber case number (optional), can be empty + * @param dbName the name of the database. Could be a local path, could be + * a Postgre db name. */ - protected void create(String dirPath, String caseName, String examiner, String caseNumber, CaseType caseType) throws CaseActionException { + protected void create(String dirPath, String caseName, String examiner, String caseNumber, CaseType caseType, String dbName) throws CaseActionException { clear(); // clear the previous data // set the case Name and Directory and the parent directory @@ -464,6 +478,7 @@ import org.xml.sax.SAXException; setExaminer(examiner); setNumber(caseNumber); setCaseType(caseType); + setDbName(dbName); DocumentBuilder docBuilder; DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); @@ -539,6 +554,10 @@ import org.xml.sax.SAXException; typeElement.appendChild(doc.createTextNode(caseType.toString())); caseElement.appendChild(typeElement); + Element dbNameElement = doc.createElement(DATABASE_NAME); // ... + dbNameElement.appendChild(doc.createTextNode(dbName)); + caseElement.appendChild(dbNameElement); + // write more code if needed ... } @@ -706,5 +725,6 @@ import org.xml.sax.SAXException; caseNumber = ""; examiner = ""; caseType = CaseType.LOCAL; + dbName = ""; } }