mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-15 09:17:42 +00:00
Creating, sanitizing, and storing Solr core names
This commit is contained in:
parent
056bf25a2d
commit
af5199df4b
@ -662,6 +662,18 @@ public class Case implements SleuthkitCase.ErrorObserver {
|
|||||||
public String getTextIndexName() {
|
public String getTextIndexName() {
|
||||||
return getCaseMetadata().getTextIndexName();
|
return getCaseMetadata().getTextIndexName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the name of the keyword search index for the case.
|
||||||
|
*
|
||||||
|
* @param indexName The index name.
|
||||||
|
*
|
||||||
|
* @throws
|
||||||
|
* org.sleuthkit.autopsy.casemodule.CaseMetadata.CaseMetadataException
|
||||||
|
*/
|
||||||
|
public void setTextIndexName(String indexName) throws CaseMetadataException {
|
||||||
|
caseMetadata.setTextIndexName(indexName);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queries whether or not the case has data, i.e., whether or not at least
|
* Queries whether or not the case has data, i.e., whether or not at least
|
||||||
@ -984,19 +996,17 @@ public class Case implements SleuthkitCase.ErrorObserver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sanitize the case name, create a unique keyword search index name,
|
* Sanitize the case name, and create a standard (single-user) or
|
||||||
* and create a standard (single-user) or unique (multi-user) case
|
* unique (multi-user) case database name.
|
||||||
* database name.
|
|
||||||
*/
|
*/
|
||||||
String santizedCaseName = sanitizeCaseName(caseName);
|
String santizedCaseName = sanitizeCaseName(caseName);
|
||||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss");
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss");
|
||||||
Date date = new Date();
|
Date date = new Date();
|
||||||
String indexName = santizedCaseName + "_" + dateFormat.format(date);
|
|
||||||
String dbName = null;
|
String dbName = null;
|
||||||
if (caseType == CaseType.SINGLE_USER_CASE) {
|
if (caseType == CaseType.SINGLE_USER_CASE) {
|
||||||
dbName = caseDir + File.separator + "autopsy.db"; //NON-NLS
|
dbName = caseDir + File.separator + "autopsy.db"; //NON-NLS
|
||||||
} else if (caseType == CaseType.MULTI_USER_CASE) {
|
} else if (caseType == CaseType.MULTI_USER_CASE) {
|
||||||
dbName = indexName;
|
dbName = santizedCaseName + "_" + dateFormat.format(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
try{
|
try{
|
||||||
@ -1037,7 +1047,7 @@ public class Case implements SleuthkitCase.ErrorObserver {
|
|||||||
*/
|
*/
|
||||||
CaseMetadata metadata;
|
CaseMetadata metadata;
|
||||||
try {
|
try {
|
||||||
metadata = new CaseMetadata(caseDir, caseType, caseName, caseNumber, examiner, dbName, indexName);
|
metadata = new CaseMetadata(caseDir, caseType, caseName, caseNumber, examiner, dbName);
|
||||||
} catch (CaseMetadataException ex) {
|
} catch (CaseMetadataException ex) {
|
||||||
throw new CaseActionException(Bundle.Case_creationException(), ex);
|
throw new CaseActionException(Bundle.Case_creationException(), ex);
|
||||||
}
|
}
|
||||||
|
@ -102,19 +102,17 @@ public final class CaseMetadata {
|
|||||||
* @param caseDatabase For a single-user case, the full path to the
|
* @param caseDatabase For a single-user case, the full path to the
|
||||||
* case database file. For a multi-user case, the
|
* case database file. For a multi-user case, the
|
||||||
* case database name.
|
* case database name.
|
||||||
* @param caseTextIndexName The text index name.
|
|
||||||
*
|
*
|
||||||
* @throws CaseMetadataException If the new case metadata file cannot be
|
* @throws CaseMetadataException If the new case metadata file cannot be
|
||||||
* created.
|
* created.
|
||||||
*/
|
*/
|
||||||
CaseMetadata(String caseDirectory, Case.CaseType caseType, String caseName, String caseNumber, String examiner, String caseDatabase, String caseTextIndexName) throws CaseMetadataException {
|
CaseMetadata(String caseDirectory, Case.CaseType caseType, String caseName, String caseNumber, String examiner, String caseDatabase) throws CaseMetadataException {
|
||||||
metadataFilePath = Paths.get(caseDirectory, caseName + FILE_EXTENSION);
|
metadataFilePath = Paths.get(caseDirectory, caseName + FILE_EXTENSION);
|
||||||
this.caseType = caseType;
|
this.caseType = caseType;
|
||||||
this.caseName = caseName;
|
this.caseName = caseName;
|
||||||
this.caseNumber = caseNumber;
|
this.caseNumber = caseNumber;
|
||||||
this.examiner = examiner;
|
this.examiner = examiner;
|
||||||
this.caseDatabase = caseDatabase;
|
this.caseDatabase = caseDatabase;
|
||||||
this.textIndexName = caseTextIndexName;
|
|
||||||
createdByVersion = Version.getVersion();
|
createdByVersion = Version.getVersion();
|
||||||
createdDate = CaseMetadata.DATE_FORMAT.format(new Date());
|
createdDate = CaseMetadata.DATE_FORMAT.format(new Date());
|
||||||
writeToFile();
|
writeToFile();
|
||||||
@ -186,6 +184,22 @@ public final class CaseMetadata {
|
|||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the text index name.
|
||||||
|
*
|
||||||
|
* @param caseTextIndexName The text index name.
|
||||||
|
*/
|
||||||
|
void setTextIndexName(String caseTextIndexName) throws CaseMetadataException {
|
||||||
|
String oldIndexName = caseTextIndexName;
|
||||||
|
this.textIndexName = caseTextIndexName;
|
||||||
|
try {
|
||||||
|
writeToFile();
|
||||||
|
} catch (CaseMetadataException ex) {
|
||||||
|
this.textIndexName = oldIndexName;
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the case number.
|
* Gets the case number.
|
||||||
|
@ -176,7 +176,6 @@ public class SingleUserCaseConverter {
|
|||||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss"); //NON-NLS
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss"); //NON-NLS
|
||||||
Date date = new Date();
|
Date date = new Date();
|
||||||
String dbName = Case.sanitizeCaseName(icd.getNewCaseName()) + "_" + dateFormat.format(date); //NON-NLS
|
String dbName = Case.sanitizeCaseName(icd.getNewCaseName()) + "_" + dateFormat.format(date); //NON-NLS
|
||||||
String solrName = dbName;
|
|
||||||
icd.setPostgreSQLDbName(dbName);
|
icd.setPostgreSQLDbName(dbName);
|
||||||
|
|
||||||
// Copy items to new hostname folder structure
|
// Copy items to new hostname folder structure
|
||||||
@ -197,7 +196,7 @@ public class SingleUserCaseConverter {
|
|||||||
icd.getNewCaseName(),
|
icd.getNewCaseName(),
|
||||||
oldCaseMetadata.getCaseNumber(),
|
oldCaseMetadata.getCaseNumber(),
|
||||||
oldCaseMetadata.getExaminer(),
|
oldCaseMetadata.getExaminer(),
|
||||||
dbName, solrName);
|
dbName);
|
||||||
// Set created date. This calls writefile, no need to call it again
|
// Set created date. This calls writefile, no need to call it again
|
||||||
newCaseMetadata.setCreatedDate(oldCaseMetadata.getCreatedDate());
|
newCaseMetadata.setCreatedDate(oldCaseMetadata.getCreatedDate());
|
||||||
newCaseMetadata.setCreatedByVersion(oldCaseMetadata.getCreatedByVersion());
|
newCaseMetadata.setCreatedByVersion(oldCaseMetadata.getCreatedByVersion());
|
||||||
|
@ -65,6 +65,7 @@ import org.openide.modules.Places;
|
|||||||
import org.openide.util.NbBundle;
|
import org.openide.util.NbBundle;
|
||||||
import org.sleuthkit.autopsy.casemodule.Case;
|
import org.sleuthkit.autopsy.casemodule.Case;
|
||||||
import org.sleuthkit.autopsy.casemodule.Case.CaseType;
|
import org.sleuthkit.autopsy.casemodule.Case.CaseType;
|
||||||
|
import org.sleuthkit.autopsy.casemodule.CaseMetadata;
|
||||||
import org.sleuthkit.autopsy.core.UserPreferences;
|
import org.sleuthkit.autopsy.core.UserPreferences;
|
||||||
import org.sleuthkit.autopsy.coreutils.Logger;
|
import org.sleuthkit.autopsy.coreutils.Logger;
|
||||||
import org.sleuthkit.autopsy.coreutils.ModuleSettings;
|
import org.sleuthkit.autopsy.coreutils.ModuleSettings;
|
||||||
@ -742,15 +743,7 @@ public class Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
CaseType caseType = theCase.getCaseType();
|
String coreName = getCoreName(index, theCase);
|
||||||
String coreName;
|
|
||||||
if (index.isNewIndex()) {
|
|
||||||
// come up with a new core name
|
|
||||||
coreName = createCoreName(theCase.getName());
|
|
||||||
} else {
|
|
||||||
// ELTODO get core name
|
|
||||||
coreName = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
File dataDir = new File(new File(index.getIndexPath()).getParent()); // "data dir" is the parent of the index directory
|
File dataDir = new File(new File(index.getIndexPath()).getParent()); // "data dir" is the parent of the index directory
|
||||||
if (!dataDir.exists()) {
|
if (!dataDir.exists()) {
|
||||||
@ -771,7 +764,7 @@ public class Server {
|
|||||||
|
|
||||||
// In single user mode, if there is a core.properties file already,
|
// In single user mode, if there is a core.properties file already,
|
||||||
// we've hit a solr bug. Compensate by deleting it.
|
// we've hit a solr bug. Compensate by deleting it.
|
||||||
if (caseType == CaseType.SINGLE_USER_CASE) {
|
if (theCase.getCaseType() == CaseType.SINGLE_USER_CASE) {
|
||||||
Path corePropertiesFile = Paths.get(solrFolder.toString(), SOLR, coreName, CORE_PROPERTIES);
|
Path corePropertiesFile = Paths.get(solrFolder.toString(), SOLR, coreName, CORE_PROPERTIES);
|
||||||
if (corePropertiesFile.toFile().exists()) {
|
if (corePropertiesFile.toFile().exists()) {
|
||||||
try {
|
try {
|
||||||
@ -795,13 +788,48 @@ public class Server {
|
|||||||
throw new KeywordSearchModuleException(NbBundle.getMessage(this.getClass(), "Server.openCore.exception.noIndexDir.msg"));
|
throw new KeywordSearchModuleException(NbBundle.getMessage(this.getClass(), "Server.openCore.exception.noIndexDir.msg"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Core(coreName, caseType, index);
|
return new Core(coreName, theCase.getCaseType(), index);
|
||||||
|
|
||||||
} catch (SolrServerException | SolrException | IOException ex) {
|
} catch (SolrServerException | SolrException | IOException | CaseMetadata.CaseMetadataException ex) {
|
||||||
throw new KeywordSearchModuleException(NbBundle.getMessage(this.getClass(), "Server.openCore.exception.cantOpen.msg"), ex);
|
throw new KeywordSearchModuleException(NbBundle.getMessage(this.getClass(), "Server.openCore.exception.cantOpen.msg"), ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get or create a sanitized Solr core name. Stores the core name if needed.
|
||||||
|
*
|
||||||
|
* @param index Index object
|
||||||
|
* @param theCase Case object
|
||||||
|
*
|
||||||
|
* @return The sanitized Solr core name
|
||||||
|
*/
|
||||||
|
private String getCoreName(Index index, Case theCase) throws CaseMetadata.CaseMetadataException {
|
||||||
|
String coreName = "";
|
||||||
|
if (index.isNewIndex()) {
|
||||||
|
// come up with a new core name
|
||||||
|
coreName = createCoreName(theCase.getName());
|
||||||
|
// store the new core name
|
||||||
|
theCase.setTextIndexName(coreName);
|
||||||
|
} else {
|
||||||
|
// get core name
|
||||||
|
coreName = theCase.getTextIndexName();
|
||||||
|
if (coreName.isEmpty()) {
|
||||||
|
// come up with a new core name
|
||||||
|
coreName = createCoreName(theCase.getName());
|
||||||
|
// store the new core name
|
||||||
|
theCase.setTextIndexName(coreName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return coreName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create and sanitize a core name.
|
||||||
|
*
|
||||||
|
* @param caseName Case name
|
||||||
|
*
|
||||||
|
* @return The sanitized Solr core name
|
||||||
|
*/
|
||||||
private String createCoreName(String caseName) {
|
private String createCoreName(String caseName) {
|
||||||
if (caseName.isEmpty()) {
|
if (caseName.isEmpty()) {
|
||||||
caseName = DEFAULT_CORE_NAME;
|
caseName = DEFAULT_CORE_NAME;
|
||||||
@ -809,7 +837,47 @@ public class Server {
|
|||||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss");
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss");
|
||||||
Date date = new Date();
|
Date date = new Date();
|
||||||
String coreName = caseName + "_" + dateFormat.format(date);
|
String coreName = caseName + "_" + dateFormat.format(date);
|
||||||
return coreName;
|
return sanitizeCoreName(coreName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sanitizes the case name for Solr cores.
|
||||||
|
*
|
||||||
|
* Solr:
|
||||||
|
* http://stackoverflow.com/questions/29977519/what-makes-an-invalid-core-name
|
||||||
|
* may not be / \ :
|
||||||
|
* Starting Solr6: core names must consist entirely of periods, underscores, hyphens, and alphanumerics as well not start with a hyphen. may not contain space characters.
|
||||||
|
*
|
||||||
|
* @param coreName A candidate core name.
|
||||||
|
*
|
||||||
|
* @return The sanitized core name.
|
||||||
|
*/
|
||||||
|
static private String sanitizeCoreName(String coreName) {
|
||||||
|
|
||||||
|
String result;
|
||||||
|
|
||||||
|
// Remove all non-ASCII characters
|
||||||
|
result = coreName.replaceAll("[^\\p{ASCII}]", "_"); //NON-NLS
|
||||||
|
|
||||||
|
// Remove all control characters
|
||||||
|
result = result.replaceAll("[\\p{Cntrl}]", "_"); //NON-NLS
|
||||||
|
|
||||||
|
// Remove spaces / \ : ? ' "
|
||||||
|
result = result.replaceAll("[ /?:'\"\\\\]", "_"); //NON-NLS
|
||||||
|
|
||||||
|
// Make it all lowercase
|
||||||
|
result = result.toLowerCase();
|
||||||
|
|
||||||
|
// Must not start with hyphen
|
||||||
|
if (result.length() > 0 && !(Character.isLetter(result.codePointAt(0))) && !(result.codePointAt(0) == '-')) {
|
||||||
|
result = "_" + result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.isEmpty()) {
|
||||||
|
result = DEFAULT_CORE_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -196,6 +196,8 @@ public class SolrSearchService implements KeywordSearchService, AutopsyService
|
|||||||
}
|
}
|
||||||
// proceed with case open
|
// proceed with case open
|
||||||
currentVersionIndex = indexToUpgrade;
|
currentVersionIndex = indexToUpgrade;
|
||||||
|
|
||||||
|
currentVersionIndex.setNewIndex(true);// ELTODO remove
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// index needs to be upgraded to latest supported version of Solr
|
// index needs to be upgraded to latest supported version of Solr
|
||||||
|
Loading…
x
Reference in New Issue
Block a user