mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-06 21:00:22 +00:00
Additional modifications to case, recentcases, and hashdb to use AutopsyPropFile
This commit is contained in:
parent
3ed04eedf3
commit
736149f3dd
@ -37,8 +37,6 @@ import org.openide.util.Lookup;
|
||||
import org.sleuthkit.autopsy.coreutils.AutopsyPropFile;
|
||||
import org.sleuthkit.autopsy.coreutils.Log;
|
||||
import org.sleuthkit.autopsy.hashdatabase.HashDbSettings;
|
||||
import org.sleuthkit.datamodel.SleuthkitJNI;
|
||||
import org.sleuthkit.datamodel.SleuthkitJNI.CaseDbHandle.AddImageProcess;
|
||||
|
||||
/**
|
||||
* The "Add Image" wizard panel1 handling the logic of selecting image file(s)
|
||||
|
@ -35,8 +35,10 @@ import javax.swing.SwingWorker;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import org.openide.WizardDescriptor;
|
||||
import org.openide.util.Exceptions;
|
||||
import org.openide.util.HelpCtx;
|
||||
import org.openide.util.Lookup;
|
||||
import org.sleuthkit.autopsy.coreutils.AutopsyPropFile;
|
||||
import org.sleuthkit.autopsy.coreutils.Log;
|
||||
import org.sleuthkit.autopsy.hashdatabase.HashDbSettings;
|
||||
import org.sleuthkit.datamodel.SleuthkitCase;
|
||||
@ -200,6 +202,16 @@ class AddImageWizardPanel2 implements WizardDescriptor.Panel<WizardDescriptor> {
|
||||
imgPaths = (String[]) settings.getProperty(AddImageAction.IMGPATHS_PROP);
|
||||
timeZone = settings.getProperty(AddImageAction.TIMEZONE_PROP).toString();
|
||||
lookupFilesCheckboxChecked = (Boolean) settings.getProperty(AddImageAction.LOOKUPFILES_PROP);
|
||||
if(lookupFilesCheckboxChecked){
|
||||
try {
|
||||
HashDbSettings hashDbSettings;
|
||||
hashDbSettings = HashDbSettings.getHashDbSettings();
|
||||
NSRLPath = hashDbSettings.getNSRLDatabasePath();
|
||||
knownBadPath = hashDbSettings.getKnownBadDatabasePath();
|
||||
} catch (IOException ex) {
|
||||
Log.get(AddImageWizardPanel2.class).log(Level.WARNING, "Couldn't get hash db settings", ex);
|
||||
}
|
||||
}
|
||||
|
||||
component.changeProgressBarTextAndColor("", 0, Color.black);
|
||||
|
||||
|
@ -24,16 +24,12 @@ import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.beans.PropertyChangeSupport;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
import java.util.logging.Level;
|
||||
@ -46,6 +42,7 @@ import org.openide.util.actions.CallableSystemAction;
|
||||
import org.openide.util.actions.SystemAction;
|
||||
import org.openide.windows.WindowManager;
|
||||
import org.sleuthkit.autopsy.corecomponentinterfaces.CoreComponentControl;
|
||||
import org.sleuthkit.autopsy.coreutils.AutopsyPropFile;
|
||||
import org.sleuthkit.autopsy.coreutils.Log;
|
||||
import org.sleuthkit.datamodel.*;
|
||||
import org.sleuthkit.datamodel.SleuthkitJNI.CaseDbHandle.AddImageProcess;
|
||||
@ -89,8 +86,7 @@ public class Case {
|
||||
* Name for the property that determines whether to show the dialog at
|
||||
* startup
|
||||
*/
|
||||
static final String propStartup = "LBL_StartupDialog";
|
||||
private static Properties properties = new Properties();
|
||||
public static final String propStartup = "LBL_StartupDialog";
|
||||
|
||||
// pcs is initialized in CaseListener constructor
|
||||
private static PropertyChangeSupport pcs;
|
||||
@ -647,62 +643,12 @@ public class Case {
|
||||
*/
|
||||
static public void invokeStartupDialog() {
|
||||
boolean showDialog = true;
|
||||
String propFilePath = RecentCases.getPropertiesFilePath();
|
||||
|
||||
// before showing the startup dialog, check if it has been disabled or not by the user
|
||||
try {
|
||||
// try to load the property from the properties file in the home directory
|
||||
InputStream inputStream = new FileInputStream(propFilePath);
|
||||
//InputStream inputStream = getClass().getResourceAsStream("Case.properties"); // old variable (can be deleted if no longer needed)
|
||||
properties.load(inputStream);
|
||||
|
||||
String temp = properties.getProperty(propStartup);
|
||||
AutopsyPropFile apf = AutopsyPropFile.getInstance();
|
||||
String temp = apf.getProperty(propStartup);
|
||||
if (temp != null) {
|
||||
showDialog = !temp.equals("false");
|
||||
} else {
|
||||
// if it's null, we have to write the properties
|
||||
|
||||
// update the properties
|
||||
properties.setProperty(propStartup, "true");
|
||||
|
||||
// write the properties file
|
||||
try {
|
||||
properties.store(new FileOutputStream(new File(RecentCases.getPropertiesFilePath())), "");
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(Case.class.getName()).log(Level.WARNING, "Error: Could not update the properties file.", ex);
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
// if cannot load it, we create a new properties file without any data inside it
|
||||
properties.setProperty(propStartup, "true");
|
||||
|
||||
try {
|
||||
// create the directory and property file to store it
|
||||
File output = new File(propFilePath);
|
||||
|
||||
// if the properties file doesn't exist, we create a new one.
|
||||
if (!output.exists()) {
|
||||
File parent = new File(output.getParent());
|
||||
if (!parent.exists()) {
|
||||
parent.mkdirs(); // create the parent directory if it doesn't exist
|
||||
}
|
||||
output.createNewFile(); // create the properties file
|
||||
FileOutputStream fos = new FileOutputStream(output);
|
||||
properties.store(fos, "");
|
||||
} // if the output exist, we just add the properties
|
||||
else {
|
||||
properties.setProperty(propStartup, "true");
|
||||
|
||||
// write the properties file
|
||||
try {
|
||||
properties.store(new FileOutputStream(new File(RecentCases.getPropertiesFilePath())), "");
|
||||
} catch (Exception ex3) {
|
||||
Logger.getLogger(Case.class.getName()).log(Level.WARNING, "Error: Could not update the properties file.", ex3);
|
||||
}
|
||||
}
|
||||
} catch (Exception ex2) {
|
||||
Logger.getLogger(Case.class.getName()).log(Level.WARNING, "Error: Could not create the property file.", ex2);
|
||||
}
|
||||
apf.setProperty(propStartup, "true");
|
||||
}
|
||||
|
||||
if (showDialog) {
|
||||
@ -728,14 +674,6 @@ public class Case {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the properties.
|
||||
*
|
||||
* @return properties
|
||||
*/
|
||||
public Properties getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a String is a valid case name
|
||||
|
@ -32,6 +32,7 @@ import javax.swing.JDialog;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import org.openide.util.Lookup;
|
||||
import org.sleuthkit.autopsy.coreutils.AutopsyPropFile;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -280,20 +281,8 @@ public class CueBannerPanel extends javax.swing.JPanel {
|
||||
|
||||
private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed
|
||||
if(this.startupCheckBox.isSelected()){
|
||||
|
||||
Case current = Case.getCurrentCase();
|
||||
Properties properties = current.getProperties();
|
||||
|
||||
// update the properties
|
||||
properties.setProperty(current.propStartup, "false");
|
||||
|
||||
// write the properties file
|
||||
try{
|
||||
properties.store(new FileOutputStream(new File(RecentCases.getPropertiesFilePath())), "");
|
||||
}
|
||||
catch(Exception ex){
|
||||
Logger.getLogger(this.className).log(Level.WARNING, "Error: Could not update the properties file.", ex);
|
||||
}
|
||||
AutopsyPropFile.getInstance().setProperty(Case.propStartup, "false");
|
||||
}
|
||||
}//GEN-LAST:event_closeButtonActionPerformed
|
||||
|
||||
|
@ -52,11 +52,10 @@ public final class RecentCases extends CallableSystemAction implements Presenter
|
||||
static final String PATH_PROP_KEY = "LBL_RecentCase_Path";
|
||||
static final RecentCase BLANK_RECENTCASE = new RecentCase("", "");
|
||||
// get the path of the case.properties file in the user directory
|
||||
private final static String propFilePath = AutopsyPropFile.getPropertiesFilePath();
|
||||
private final static AutopsyPropFile apf = AutopsyPropFile.getInstance();
|
||||
|
||||
private final static RecentCases INSTANCE = new RecentCases();
|
||||
|
||||
private Properties properties;
|
||||
private Deque<RecentCase> recentCases; // newest case is last case
|
||||
|
||||
|
||||
@ -70,47 +69,13 @@ public final class RecentCases extends CallableSystemAction implements Presenter
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
static private Properties makeDefaults() {
|
||||
Properties temp = new Properties();
|
||||
for (int i = 0; i < LENGTH; i++) {
|
||||
temp.setProperty(nameKey(i), "");
|
||||
temp.setProperty(pathKey(i), "");
|
||||
}
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
/** the constructor */
|
||||
private RecentCases() {
|
||||
properties = new Properties(makeDefaults());
|
||||
try {
|
||||
// try to load all the recent cases from the properties file in the home directory
|
||||
InputStream inputStream = new FileInputStream(propFilePath);
|
||||
properties.load(inputStream);
|
||||
inputStream.close();
|
||||
} catch (Exception ignore) {
|
||||
// if cannot load it, we create a new properties file without any data inside it
|
||||
try {
|
||||
// create the directory and property file to store it
|
||||
File output = new File(propFilePath);
|
||||
if (!output.exists()) {
|
||||
File parent = new File(output.getParent());
|
||||
if (!parent.exists()) {
|
||||
parent.mkdirs();
|
||||
}
|
||||
output.createNewFile();
|
||||
FileOutputStream fos = new FileOutputStream(output);
|
||||
properties.store(fos, "");
|
||||
fos.close();
|
||||
} else {
|
||||
// if the property file already exist, throw an error that says cannot load that file
|
||||
Logger.getLogger(RecentCases.class.getName()).log(Level.WARNING, "Error: Could not load the property file.", new Exception("The properties file already exist and can't load that file."));
|
||||
}
|
||||
} catch (IOException ex2) {
|
||||
Logger.getLogger(RecentCases.class.getName()).log(Level.WARNING, "Error: Could not create the property file.", ex2);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < LENGTH; i++) {
|
||||
apf.setProperty(nameKey(i), "");
|
||||
apf.setProperty(pathKey(i), "");
|
||||
}
|
||||
|
||||
// Load recentCases from properties
|
||||
recentCases = new LinkedList<RecentCase>();
|
||||
@ -140,19 +105,19 @@ public final class RecentCases extends CallableSystemAction implements Presenter
|
||||
}
|
||||
|
||||
private String getName(int i) {
|
||||
return properties.getProperty(nameKey(i));
|
||||
return apf.getProperty(nameKey(i));
|
||||
}
|
||||
|
||||
private String getPath(int i) {
|
||||
return properties.getProperty(pathKey(i));
|
||||
return apf.getProperty(pathKey(i));
|
||||
}
|
||||
|
||||
private void setName(int i, String name) {
|
||||
properties.setProperty(nameKey(i), name);
|
||||
apf.setProperty(nameKey(i), name);
|
||||
}
|
||||
|
||||
private void setPath(int i, String path) {
|
||||
properties.setProperty(pathKey(i), path);
|
||||
apf.setProperty(pathKey(i), path);
|
||||
}
|
||||
|
||||
private void setRecentCase(int i, RecentCase rc) {
|
||||
@ -212,10 +177,6 @@ public final class RecentCases extends CallableSystemAction implements Presenter
|
||||
}
|
||||
}
|
||||
|
||||
private void storeProperties() throws IOException {
|
||||
properties.store(new FileOutputStream(new File(propFilePath)), "");
|
||||
}
|
||||
|
||||
private void storeRecentCases() throws IOException {
|
||||
int i = 0;
|
||||
|
||||
@ -231,7 +192,6 @@ public final class RecentCases extends CallableSystemAction implements Presenter
|
||||
i++;
|
||||
}
|
||||
|
||||
storeProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -404,17 +364,6 @@ public final class RecentCases extends CallableSystemAction implements Presenter
|
||||
return casePaths;
|
||||
}
|
||||
|
||||
|
||||
// TODO: really shouldn't be done like this; need one common properties tracker
|
||||
/**
|
||||
* Gets the properties file paths.
|
||||
*
|
||||
* @return propertyPath
|
||||
*/
|
||||
public static String getPropertiesFilePath() {
|
||||
return propFilePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method does nothing. Use the actionPerformed instead of this method.
|
||||
*/
|
||||
|
@ -48,7 +48,7 @@ class HashDbMgmtAction extends CallableSystemAction {
|
||||
|
||||
try {
|
||||
// Load settings from the property file
|
||||
HashDbSettings hashDatabaseSettings = new HashDbSettings(AutopsyPropFile.getPropertyFile());
|
||||
HashDbSettings hashDatabaseSettings = HashDbSettings.getHashDbSettings();
|
||||
|
||||
// create the popUp window for it
|
||||
final JFrame frame = new JFrame(ACTION_NAME);
|
||||
|
@ -22,11 +22,13 @@ import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import javax.swing.Box;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import org.sleuthkit.autopsy.coreutils.Log;
|
||||
|
||||
/**
|
||||
* Panel for displaying and editing the Hash Database settings.
|
||||
|
@ -18,15 +18,11 @@
|
||||
*/
|
||||
package org.sleuthkit.autopsy.hashdatabase;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
import org.sleuthkit.autopsy.coreutils.AutopsyPropFile;
|
||||
import org.sleuthkit.autopsy.coreutils.Log;
|
||||
|
||||
/**
|
||||
* Loads and stores Hash Database settings from/to a property file
|
||||
@ -34,10 +30,10 @@ import org.sleuthkit.autopsy.coreutils.AutopsyPropFile;
|
||||
*/
|
||||
public class HashDbSettings {
|
||||
|
||||
private static final String PROP_PREFIX = "HASHDB";
|
||||
private static final String PROP_PREFIX = "LBL_HashDB";
|
||||
private static final String NSRL_PROP = "NSRL";
|
||||
private static final String KNOWN_BAD_PROP = "KNOWN_BAD";
|
||||
private File propertyFile;
|
||||
private static final AutopsyPropFile apf = AutopsyPropFile.getInstance();
|
||||
private HashDb NSRLDatabase, knownBadDatabase;
|
||||
|
||||
/**
|
||||
@ -45,22 +41,15 @@ public class HashDbSettings {
|
||||
* @throws IOException if there's an error loading the property file
|
||||
* @throws FileNotFoundException if the property file can't be found
|
||||
*/
|
||||
public HashDbSettings(File propertyFile) throws IOException, FileNotFoundException {
|
||||
this.propertyFile = propertyFile;
|
||||
public HashDbSettings() throws IOException, FileNotFoundException {
|
||||
String NSRL = getNSRL();
|
||||
String knownBad = getKnownBad();
|
||||
|
||||
Properties temp = new Properties();
|
||||
InputStream loadStream = new FileInputStream(propertyFile);
|
||||
temp.load(loadStream);
|
||||
loadStream.close();
|
||||
|
||||
String NSRL = getNSRL(temp);
|
||||
String knownBad = getKnownBad(temp);
|
||||
|
||||
if (!NSRL.equals("")) {
|
||||
if (NSRL != null && !NSRL.equals("")) {
|
||||
this.NSRLDatabase = new HashDb(NSRL);
|
||||
}
|
||||
|
||||
if (!knownBad.equals("")) {
|
||||
if (knownBad != null && !knownBad.equals("")) {
|
||||
this.knownBadDatabase = new HashDb(knownBad);
|
||||
}
|
||||
}
|
||||
@ -72,18 +61,8 @@ public class HashDbSettings {
|
||||
* @throws FileNotFoundException if the property file can't be found
|
||||
*/
|
||||
void save() throws IOException, FileNotFoundException {
|
||||
Properties temp = new Properties();
|
||||
InputStream loadStream = new FileInputStream(propertyFile);
|
||||
temp.load(loadStream);
|
||||
loadStream.close();
|
||||
|
||||
setNSRL(temp, this.NSRLDatabase != null ? this.NSRLDatabase.databasePath : "");
|
||||
setKnownBad(temp, this.knownBadDatabase != null ? this.knownBadDatabase.databasePath : "");
|
||||
|
||||
String comments = "";
|
||||
OutputStream storeStream = new FileOutputStream(propertyFile);
|
||||
temp.store(storeStream, comments);
|
||||
storeStream.close();
|
||||
setNSRL(this.NSRLDatabase != null ? this.NSRLDatabase.databasePath : "");
|
||||
setKnownBad(this.knownBadDatabase != null ? this.knownBadDatabase.databasePath : "");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -118,7 +97,7 @@ public class HashDbSettings {
|
||||
* @throws IOException if the property file can't be found
|
||||
*/
|
||||
public static HashDbSettings getHashDbSettings() throws IOException {
|
||||
return new HashDbSettings(AutopsyPropFile.getPropertyFile());
|
||||
return new HashDbSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -146,28 +125,20 @@ public class HashDbSettings {
|
||||
}
|
||||
|
||||
// helper functions:
|
||||
private static void setNSRL(Properties props, String databasePath) {
|
||||
setProp(props, NSRL_PROP, databasePath);
|
||||
private static void setNSRL(String databasePath) {
|
||||
apf.setProperty(fullProp(NSRL_PROP), databasePath);
|
||||
}
|
||||
|
||||
private static void setKnownBad(Properties props, String databasePath) {
|
||||
setProp(props, KNOWN_BAD_PROP, databasePath);
|
||||
private static void setKnownBad(String databasePath) {
|
||||
apf.setProperty(fullProp(KNOWN_BAD_PROP), databasePath);
|
||||
}
|
||||
|
||||
private static String getNSRL(Properties props) {
|
||||
return getProp(props, NSRL_PROP);
|
||||
private static String getNSRL() {
|
||||
return apf.getProperty(fullProp(NSRL_PROP));
|
||||
}
|
||||
|
||||
private static String getKnownBad(Properties props) {
|
||||
return getProp(props, KNOWN_BAD_PROP);
|
||||
}
|
||||
|
||||
private static void setProp(Properties props, String propName, String propValue) {
|
||||
props.setProperty(fullProp(propName), propValue);
|
||||
}
|
||||
|
||||
private static String getProp(Properties props, String propName) {
|
||||
return props.getProperty(fullProp(propName), "");
|
||||
private static String getKnownBad() {
|
||||
return apf.getProperty(fullProp(KNOWN_BAD_PROP));
|
||||
}
|
||||
|
||||
private static String fullProp(String propName) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user