19 package org.sleuthkit.autopsy.keywordsearch;
21 import java.io.IOException;
22 import java.util.HashMap;
23 import org.apache.solr.client.solrj.SolrServerException;
24 import org.apache.solr.client.solrj.impl.HttpSolrServer;
29 import org.apache.solr.common.util.ContentStreamBase.StringStream;
30 import org.openide.util.lookup.ServiceProvider;
36 import org.openide.util.NbBundle;
37 import java.net.InetAddress;
38 import java.util.MissingResourceException;
45 @ServiceProvider(service = KeywordSearchService.class)
48 private static final String BAD_IP_ADDRESS_FORMAT =
"ioexception occurred when talking to server";
49 private static final String SERVER_REFUSED_CONNECTION =
"server refused connection";
50 private static final int IS_REACHABLE_TIMEOUT_MS = 1000;
53 public void indexArtifact(BlackboardArtifact artifact)
throws TskCoreException {
54 if (artifact == null) {
60 long artifactId = artifact.getArtifactID();
69 }
catch (IllegalStateException ignore) {
75 if (sleuthkitCase == null) {
80 AbstractFile abstractFile = sleuthkitCase.getAbstractFileById(artifact.getObjectID());
81 if (abstractFile != null) {
82 dataSource = abstractFile.getDataSource();
84 dataSource = sleuthkitCase.getContentById(artifact.getObjectID());
87 if (dataSource == null) {
93 StringBuilder artifactContents =
new StringBuilder();
95 for (BlackboardAttribute attribute : artifact.getAttributes()) {
96 artifactContents.append(attribute.getAttributeType().getDisplayName());
97 artifactContents.append(
" : ");
111 if (attribute.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME.getTypeID()
112 || attribute.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_ACCESSED.getTypeID()
113 || attribute.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_CREATED.getTypeID()
114 || attribute.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_MODIFIED.getTypeID()
115 || attribute.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_RCVD.getTypeID()
116 || attribute.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_SENT.getTypeID()
117 || attribute.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_START.getTypeID()
118 || attribute.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_END.getTypeID()) {
122 artifactContents.append(attribute.getDisplayString());
124 artifactContents.append(System.lineSeparator());
127 if (artifactContents.length() == 0) {
137 HashMap<String, String> solrFields =
new HashMap<>();
138 String documentId = Long.toString(artifactId);
140 solrFields.put(
Server.
Schema.ID.toString(), documentId);
143 solrFields.put(
Server.
Schema.IMAGE_ID.toString(), Long.toString(dataSource.getId()));
146 Ingester.getDefault().ingest(
new StringStream(
""), solrFields, 0);
147 }
catch (Ingester.IngesterException ex) {
148 throw new TskCoreException(ex.getCause().getMessage(), ex);
156 documentId +=
"_" + Long.toString(chunkId);
157 solrFields.replace(
Server.
Schema.ID.toString(), documentId);
159 StringStream contentStream =
new StringStream(artifactContents.toString());
162 Ingester.getDefault().ingest(contentStream, solrFields, contentStream.getSize());
163 }
catch (Ingester.IngesterException ex) {
164 throw new TskCoreException(ex.getCause().getMessage(), ex);
187 HttpSolrServer solrServer = null;
188 if (host == null || host.isEmpty()) {
192 solrServer =
new HttpSolrServer(
"http://" + host +
":" + Integer.toString(port) +
"/solr");
194 }
catch (SolrServerException ex) {
196 }
catch (IOException ex) {
197 String result = NbBundle.getMessage(
SolrSearchService.class,
"SolrConnectionCheck.HostnameOrPort");
198 String message = ex.getCause().getMessage().toLowerCase();
199 if (message.startsWith(SERVER_REFUSED_CONNECTION)) {
201 if (InetAddress.getByName(host).isReachable(IS_REACHABLE_TIMEOUT_MS)) {
203 result = Bundle.SolrConnectionCheck_Port();
205 result = NbBundle.getMessage(
SolrSearchService.class,
"SolrConnectionCheck.HostnameOrPort");
207 }
catch (IOException | MissingResourceException any) {
209 result = NbBundle.getMessage(
SolrSearchService.class,
"SolrConnectionCheck.HostnameOrPort");
211 }
else if (message.startsWith(BAD_IP_ADDRESS_FORMAT)) {
212 result = NbBundle.getMessage(
SolrSearchService.class,
"SolrConnectionCheck.Hostname");
215 }
catch (NumberFormatException ex) {
217 }
catch (IllegalArgumentException ex) {
220 if (null != solrServer) {
221 solrServer.shutdown();
227 public void close() throws IOException {
static String getStringTime(long epochSeconds, TimeZone tzone)
void indexArtifact(BlackboardArtifact artifact)
static synchronized Server getServer()
SleuthkitCase getSleuthkitCase()
static Case getCurrentCase()
void tryConnect(String host, int port)