Merge branch '8425e-desktopSnap' of github.com:gdicristofaro/autopsy into 25_01_17_outstandingPrs

This commit is contained in:
Greg DiCristofaro 2025-01-17 11:05:35 -05:00
commit 6d33ea084d
No known key found for this signature in database
23 changed files with 209 additions and 56 deletions

View File

@ -18,7 +18,7 @@
*/ */
package com.basistech.df.cybertriage.autopsy; package com.basistech.df.cybertriage.autopsy;
import java.awt.Desktop; import org.sleuthkit.autopsy.coreutils.Desktop;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;

View File

@ -28,7 +28,7 @@ import com.basistech.df.cybertriage.autopsy.ctapi.json.LicenseLimitType;
import com.basistech.df.cybertriage.autopsy.ctapi.json.LicenseResponse; import com.basistech.df.cybertriage.autopsy.ctapi.json.LicenseResponse;
import com.basistech.df.cybertriage.autopsy.ctapi.util.LicenseDecryptorUtil; import com.basistech.df.cybertriage.autopsy.ctapi.util.LicenseDecryptorUtil;
import com.basistech.df.cybertriage.autopsy.ctapi.util.LicenseDecryptorUtil.InvalidLicenseException; import com.basistech.df.cybertriage.autopsy.ctapi.util.LicenseDecryptorUtil.InvalidLicenseException;
import java.awt.Desktop; import org.sleuthkit.autopsy.coreutils.Desktop;
import java.awt.event.ComponentAdapter; import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent; import java.awt.event.ComponentEvent;
import java.io.IOException; import java.io.IOException;

View File

@ -18,7 +18,7 @@
*/ */
package org.sleuthkit.autopsy.actions; package org.sleuthkit.autopsy.actions;
import java.awt.Desktop; import org.sleuthkit.autopsy.coreutils.Desktop;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.io.File; import java.io.File;

View File

@ -18,7 +18,7 @@
*/ */
package org.sleuthkit.autopsy.actions; package org.sleuthkit.autopsy.actions;
import java.awt.Desktop; import org.sleuthkit.autopsy.coreutils.Desktop;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.logging.Level; import java.util.logging.Level;

View File

@ -18,7 +18,7 @@
*/ */
package org.sleuthkit.autopsy.actions; package org.sleuthkit.autopsy.actions;
import java.awt.Desktop; import org.sleuthkit.autopsy.coreutils.Desktop;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.io.File; import java.io.File;

View File

@ -18,7 +18,7 @@
*/ */
package org.sleuthkit.autopsy.actions; package org.sleuthkit.autopsy.actions;
import java.awt.Desktop; import org.sleuthkit.autopsy.coreutils.Desktop;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File; import java.io.File;

View File

@ -41,7 +41,7 @@ import com.mxgraph.view.mxGraph;
import com.mxgraph.view.mxGraphView; import com.mxgraph.view.mxGraphView;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Color; import java.awt.Color;
import java.awt.Desktop; import org.sleuthkit.autopsy.coreutils.Desktop;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Font; import java.awt.Font;
import java.awt.Frame; import java.awt.Frame;

View File

@ -19,7 +19,7 @@
package org.sleuthkit.autopsy.corecomponents; package org.sleuthkit.autopsy.corecomponents;
import java.awt.Cursor; import java.awt.Cursor;
import java.awt.Desktop; import org.sleuthkit.autopsy.coreutils.Desktop;
import java.awt.Window; import java.awt.Window;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;

View File

@ -18,12 +18,13 @@
*/ */
package org.sleuthkit.autopsy.corecomponents; package org.sleuthkit.autopsy.corecomponents;
import java.awt.Desktop; import org.sleuthkit.autopsy.coreutils.Desktop;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI; import java.nio.file.Paths;
import org.netbeans.core.actions.HTMLViewAction; import org.netbeans.core.actions.HTMLViewAction;
import org.openide.awt.ActionID; import org.openide.awt.ActionID;
import org.openide.awt.ActionReference; import org.openide.awt.ActionReference;
@ -33,6 +34,7 @@ import org.openide.awt.HtmlBrowser;
import org.openide.util.NbBundle; import org.openide.util.NbBundle;
import org.openide.util.NbBundle.Messages; import org.openide.util.NbBundle.Messages;
import java.util.logging.Level; import java.util.logging.Level;
import org.openide.modules.InstalledFileLocator;
import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.Logger;
/** /**
@ -52,6 +54,10 @@ import org.sleuthkit.autopsy.coreutils.Logger;
@Messages("CTL_OfflineHelpAction=Offline Autopsy Documentation") @Messages("CTL_OfflineHelpAction=Offline Autopsy Documentation")
public final class OfflineHelpAction implements ActionListener { public final class OfflineHelpAction implements ActionListener {
private static final String DOCS_FOLDER = "docs";
private static final String HELP_HTML_FILE = "index.html";
private static final String HELP_REL_PATH = Paths.get("..", DOCS_FOLDER, HELP_HTML_FILE).toString();
private static final Logger logger private static final Logger logger
= org.sleuthkit.autopsy.coreutils.Logger.getLogger(AboutWindowPanel.class.getName()); = org.sleuthkit.autopsy.coreutils.Logger.getLogger(AboutWindowPanel.class.getName());
@ -67,41 +73,42 @@ public final class OfflineHelpAction implements ActionListener {
* Tested and working: Chrome, Firefox, IE Not tested: Opera, Safari * Tested and working: Chrome, Firefox, IE Not tested: Opera, Safari
*/ */
private void viewOfflineHelp() { private void viewOfflineHelp() {
String fileForHelp = "";
String indexForHelp = "";
String currentDirectory = "";
URI uri = null;
try { File systemHelpFile = getOfflineHelpFile();
// Match the form: file:///C:/some/directory/AutopsyXYZ/docs/index.html if (systemHelpFile == null) {
fileForHelp = NbBundle.getMessage(OfflineHelpAction.class, "FILE_FOR_LOCAL_HELP"); logger.log(Level.SEVERE, "Unable to load Offline Documentation file at relative path: " + HELP_REL_PATH);
indexForHelp = NbBundle.getMessage(OfflineHelpAction.class, "INDEX_FOR_LOCAL_HELP"); return;
currentDirectory = System.getProperty("user.dir").replace("\\", "/").replace(" ", "%20"); //NON-NLS
uri = new URI(fileForHelp + currentDirectory + indexForHelp);
} catch (Exception ex) {
logger.log(Level.SEVERE, "Unable to load Offline Documentation: "
+ fileForHelp + currentDirectory + indexForHelp, ex); //NON-NLS
} }
if (uri != null) {
// Display URL in the System browser // Display URL in the System browser
if (Desktop.isDesktopSupported()) { if (Desktop.isDesktopSupported()) {
Desktop desktop = Desktop.getDesktop(); Desktop desktop = Desktop.getDesktop();
try { try {
desktop.browse(uri); desktop.open(systemHelpFile);
return;
} catch (IOException ex) { } catch (IOException ex) {
logger.log(Level.SEVERE, "Unable to launch the system browser: " logger.log(Level.SEVERE, "Unable to launch the system browser: "
+ fileForHelp + currentDirectory + indexForHelp, ex); //NON-NLS + systemHelpFile, ex); //NON-NLS
} }
} else { }
org.openide.awt.StatusDisplayer.getDefault().setStatusText( org.openide.awt.StatusDisplayer.getDefault().setStatusText(
NbBundle.getMessage(HTMLViewAction.class, "CTL_OpeningBrowser")); //NON-NLS NbBundle.getMessage(HTMLViewAction.class, "CTL_OpeningBrowser")); //NON-NLS
try { try {
HtmlBrowser.URLDisplayer.getDefault().showURL(uri.toURL()); HtmlBrowser.URLDisplayer.getDefault().showURL(systemHelpFile.toURI().toURL());
} catch (MalformedURLException ex) { } catch (MalformedURLException ex) {
logger.log(Level.SEVERE, "Unable to launch the built-in browser: " logger.log(Level.SEVERE, "Unable to launch the built-in browser: "
+ fileForHelp + currentDirectory + indexForHelp, ex); //NON-NLS + systemHelpFile, ex); //NON-NLS
}
} }
} }
private File getOfflineHelpFile() {
return InstalledFileLocator.getDefault().locate(
HELP_REL_PATH,
OfflineHelpAction.class.getPackage().getName(),
false);
} }
} }

View File

@ -20,7 +20,7 @@ package org.sleuthkit.autopsy.corecomponents;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.Desktop; import org.sleuthkit.autopsy.coreutils.Desktop;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URISyntaxException; import java.net.URISyntaxException;

View File

@ -0,0 +1,146 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2023 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.sleuthkit.autopsy.coreutils;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import org.apache.commons.lang3.SystemUtils;
/**
* Wrapper for java.awt.Desktop to handle some situations that java.awt.Desktop
* doesn't.
*/
public class Desktop {
private static final Logger LOGGER = Logger.getLogger(Desktop.class.getName());
private static final long XDG_TIMEOUT_SECS = 30;
private static Boolean xdgSupported = null;
private static boolean isXdgSupported() {
if (xdgSupported == null) {
xdgSupported = false;
if (SystemUtils.IS_OS_LINUX) {
try {
xdgSupported = Runtime.getRuntime().exec(new String[]{"which", "xdg-open"}).getInputStream().read() != -1;
} catch (IOException ex) {
LOGGER.log(Level.WARNING, "There was an error running 'which xdg-open' ", ex);
}
}
}
return xdgSupported;
}
/**
* @return True if this class's external calls can be used on this operating
* system.
*/
public static boolean isDesktopSupported() {
return java.awt.Desktop.isDesktopSupported() || isXdgSupported();
}
private static Desktop instance = null;
/**
* @return A singleton instance of this class.
*/
public static Desktop getDesktop() {
if (instance == null) {
instance = new Desktop(java.awt.Desktop.getDesktop());
}
return instance;
}
private final java.awt.Desktop awtDesktop;
/**
* Private constructor for this wrapper.
*
* @param awtDesktop The delegate java.awt.Desktop.
*/
private Desktop(java.awt.Desktop awtDesktop) {
this.awtDesktop = awtDesktop;
}
/**
* Opens a given path using `xdg-open` on linux.
*
* @param path The path.
* @throws IOException
*/
private void xdgOpen(String path) throws IOException {
Process process = Runtime.getRuntime().exec(new String[]{"xdg-open", path});
try {
process.waitFor(XDG_TIMEOUT_SECS, TimeUnit.SECONDS);
} catch (InterruptedException ex) {
throw new IOException("xdg-open timed out", ex);
}
int exitCode = process.exitValue();
if (exitCode != 0) {
throw new IOException("Received non-zero exit code from xdg-open: " + exitCode);
}
}
/**
* Triggers the OS to navigate to the given uri.
*
* @param uri The uri.
* @throws IOException
*/
public void browse(URI uri) throws IOException {
if (!awtDesktop.isSupported(java.awt.Desktop.Action.BROWSE) && isXdgSupported()) {
xdgOpen(uri.toString());
} else {
awtDesktop.browse(uri);
}
}
/**
* Triggers the OS to open the given file.
*
* @param file The file.
* @throws IOException
*/
public void open(File file) throws IOException {
if (!awtDesktop.isSupported(java.awt.Desktop.Action.OPEN) && isXdgSupported()) {
xdgOpen(file.getAbsolutePath());
} else {
awtDesktop.open(file);
}
}
/**
* Triggers the OS to edit the given file.
*
* @param file The file.
* @throws IOException
*/
public void edit(File file) throws IOException {
if (!awtDesktop.isSupported(java.awt.Desktop.Action.EDIT) && isXdgSupported()) {
xdgOpen(file.getAbsolutePath());
} else {
awtDesktop.edit(file);
}
}
}

View File

@ -18,7 +18,7 @@
*/ */
package org.sleuthkit.autopsy.directorytree; package org.sleuthkit.autopsy.directorytree;
import java.awt.Desktop; import org.sleuthkit.autopsy.coreutils.Desktop;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;

View File

@ -20,7 +20,7 @@ package org.sleuthkit.autopsy.modules.photoreccarver;
import java.awt.Color; import java.awt.Color;
import java.awt.Cursor; import java.awt.Cursor;
import java.awt.Desktop; import org.sleuthkit.autopsy.coreutils.Desktop;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.io.IOException; import java.io.IOException;

View File

@ -19,7 +19,7 @@
package org.sleuthkit.autopsy.modules.yara.ui; package org.sleuthkit.autopsy.modules.yara.ui;
import java.awt.Component; import java.awt.Component;
import java.awt.Desktop; import org.sleuthkit.autopsy.coreutils.Desktop;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;

View File

@ -21,7 +21,7 @@ package org.sleuthkit.autopsy.report;
import org.openide.util.NbBundle; import org.openide.util.NbBundle;
import java.awt.Color; import java.awt.Color;
import java.awt.Cursor; import java.awt.Cursor;
import java.awt.Desktop; import org.sleuthkit.autopsy.coreutils.Desktop;
import java.awt.EventQueue; import java.awt.EventQueue;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;

View File

@ -29,7 +29,7 @@ import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener; import javax.swing.event.DocumentListener;
import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener; import javax.swing.event.HyperlinkListener;
import java.awt.Desktop; import org.sleuthkit.autopsy.coreutils.Desktop;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import okhttp3.MediaType; import okhttp3.MediaType;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;

View File

@ -24,7 +24,7 @@ import com.google.cloud.translate.Language;
import com.google.cloud.translate.Translate; import com.google.cloud.translate.Translate;
import com.google.cloud.translate.TranslateOptions; import com.google.cloud.translate.TranslateOptions;
import com.google.cloud.translate.Translation; import com.google.cloud.translate.Translation;
import java.awt.Desktop; import org.sleuthkit.autopsy.coreutils.Desktop;
import java.awt.event.ItemListener; import java.awt.event.ItemListener;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;

View File

@ -18,7 +18,7 @@
*/ */
package org.sleuthkit.autopsy.timeline.actions; package org.sleuthkit.autopsy.timeline.actions;
import java.awt.Desktop; import org.sleuthkit.autopsy.coreutils.Desktop;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.IOException; import java.io.IOException;
import java.nio.file.InvalidPathException; import java.nio.file.InvalidPathException;

View File

@ -19,7 +19,7 @@
package org.sleuthkit.autopsy.experimental.autoingest; package org.sleuthkit.autopsy.experimental.autoingest;
import java.awt.Cursor; import java.awt.Cursor;
import java.awt.Desktop; import org.sleuthkit.autopsy.coreutils.Desktop;
import java.awt.EventQueue; import java.awt.EventQueue;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.io.IOException; import java.io.IOException;

View File

@ -20,7 +20,7 @@ package org.sleuthkit.autopsy.experimental.autoingest;
import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.awt.Cursor; import java.awt.Cursor;
import java.awt.Desktop; import org.sleuthkit.autopsy.coreutils.Desktop;
import java.awt.EventQueue; import java.awt.EventQueue;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;

View File

@ -19,7 +19,7 @@
package org.sleuthkit.autopsy.experimental.autoingest; package org.sleuthkit.autopsy.experimental.autoingest;
import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.awt.Desktop; import org.sleuthkit.autopsy.coreutils.Desktop;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.io.BufferedWriter; import java.io.BufferedWriter;

View File

@ -19,7 +19,7 @@
package org.sleuthkit.autopsy.experimental.autoingest; package org.sleuthkit.autopsy.experimental.autoingest;
import java.awt.Color; import java.awt.Color;
import java.awt.Desktop; import org.sleuthkit.autopsy.coreutils.Desktop;
import java.awt.EventQueue; import java.awt.EventQueue;
import java.awt.Font; import java.awt.Font;
import java.io.File; import java.io.File;

View File

@ -18,7 +18,7 @@
*/ */
package org.sleuthkit.autopsy.experimental.autoingest; package org.sleuthkit.autopsy.experimental.autoingest;
import java.awt.Desktop; import org.sleuthkit.autopsy.coreutils.Desktop;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;