From 3f0d4965af25275115ea6e9980324db227d153b4 Mon Sep 17 00:00:00 2001 From: Greg DiCristofaro Date: Tue, 8 Aug 2023 12:03:44 -0400 Subject: [PATCH 1/6] desktop wrapper --- .../cybertriage/autopsy/ctoptions/LicenseDisclaimerPanel.java | 2 +- Core/src/org/sleuthkit/autopsy/actions/OpenLogFolderAction.java | 2 +- .../org/sleuthkit/autopsy/actions/OpenOutputFolderAction.java | 2 +- .../autopsy/actions/OpenPythonModulesFolderAction.java | 2 +- Core/src/org/sleuthkit/autopsy/actions/ThreadDumpAction.java | 2 +- .../sleuthkit/autopsy/communications/VisualizationPanel.java | 2 +- .../org/sleuthkit/autopsy/corecomponents/AboutWindowPanel.java | 2 +- .../org/sleuthkit/autopsy/corecomponents/OfflineHelpAction.java | 2 +- .../org/sleuthkit/autopsy/corecomponents/OnlineHelpAction.java | 2 +- .../sleuthkit/autopsy/directorytree/ExternalViewerAction.java | 2 +- .../photoreccarver/PhotoRecCarverIngestJobSettingsPanel.java | 2 +- .../sleuthkit/autopsy/modules/yara/ui/RuleSetDetailsPanel.java | 2 +- Core/src/org/sleuthkit/autopsy/report/ReportProgressPanel.java | 2 +- .../translators/BingTranslatorSettingsPanel.java | 2 +- .../translators/GoogleTranslatorSettingsPanel.java | 2 +- .../autopsy/timeline/actions/SaveSnapshotAsReport.java | 2 +- .../autopsy/experimental/autoingest/AutoIngestAdminActions.java | 2 +- .../autopsy/experimental/autoingest/AutoIngestControlPanel.java | 2 +- .../autopsy/experimental/autoingest/AutoIngestMonitor.java | 2 +- .../autopsy/experimental/autoingest/CaseImportPanel.java | 2 +- .../experimental/autoingest/OpenAutoIngestLogAction.java | 2 +- 21 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Core/src/com/basistech/df/cybertriage/autopsy/ctoptions/LicenseDisclaimerPanel.java b/Core/src/com/basistech/df/cybertriage/autopsy/ctoptions/LicenseDisclaimerPanel.java index 4299f02d620..93c857004bd 100644 --- a/Core/src/com/basistech/df/cybertriage/autopsy/ctoptions/LicenseDisclaimerPanel.java +++ b/Core/src/com/basistech/df/cybertriage/autopsy/ctoptions/LicenseDisclaimerPanel.java @@ -18,7 +18,7 @@ */ package com.basistech.df.cybertriage.autopsy.ctoptions; -import java.awt.Desktop; +import org.sleuthkit.autopsy.coreutils.Desktop; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; diff --git a/Core/src/org/sleuthkit/autopsy/actions/OpenLogFolderAction.java b/Core/src/org/sleuthkit/autopsy/actions/OpenLogFolderAction.java index 92b04140c3f..e583326cc47 100644 --- a/Core/src/org/sleuthkit/autopsy/actions/OpenLogFolderAction.java +++ b/Core/src/org/sleuthkit/autopsy/actions/OpenLogFolderAction.java @@ -18,7 +18,7 @@ */ package org.sleuthkit.autopsy.actions; -import java.awt.Desktop; +import org.sleuthkit.autopsy.coreutils.Desktop; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; diff --git a/Core/src/org/sleuthkit/autopsy/actions/OpenOutputFolderAction.java b/Core/src/org/sleuthkit/autopsy/actions/OpenOutputFolderAction.java index efbbe111358..08e43d14123 100644 --- a/Core/src/org/sleuthkit/autopsy/actions/OpenOutputFolderAction.java +++ b/Core/src/org/sleuthkit/autopsy/actions/OpenOutputFolderAction.java @@ -18,7 +18,7 @@ */ package org.sleuthkit.autopsy.actions; -import java.awt.Desktop; +import org.sleuthkit.autopsy.coreutils.Desktop; import java.io.File; import java.io.IOException; import java.util.logging.Level; diff --git a/Core/src/org/sleuthkit/autopsy/actions/OpenPythonModulesFolderAction.java b/Core/src/org/sleuthkit/autopsy/actions/OpenPythonModulesFolderAction.java index 16a3ea18916..3675903bb84 100644 --- a/Core/src/org/sleuthkit/autopsy/actions/OpenPythonModulesFolderAction.java +++ b/Core/src/org/sleuthkit/autopsy/actions/OpenPythonModulesFolderAction.java @@ -18,7 +18,7 @@ */ package org.sleuthkit.autopsy.actions; -import java.awt.Desktop; +import org.sleuthkit.autopsy.coreutils.Desktop; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; diff --git a/Core/src/org/sleuthkit/autopsy/actions/ThreadDumpAction.java b/Core/src/org/sleuthkit/autopsy/actions/ThreadDumpAction.java index dad577e8cba..07991f9d83d 100755 --- a/Core/src/org/sleuthkit/autopsy/actions/ThreadDumpAction.java +++ b/Core/src/org/sleuthkit/autopsy/actions/ThreadDumpAction.java @@ -18,7 +18,7 @@ */ package org.sleuthkit.autopsy.actions; -import java.awt.Desktop; +import org.sleuthkit.autopsy.coreutils.Desktop; import java.awt.event.ActionListener; import java.io.BufferedWriter; import java.io.File; diff --git a/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.java b/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.java index f3ed2a66cdd..e3d2fc6fcf6 100644 --- a/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.java +++ b/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.java @@ -41,7 +41,7 @@ import com.mxgraph.view.mxGraphView; import java.awt.BorderLayout; import java.awt.Color; -import java.awt.Desktop; +import org.sleuthkit.autopsy.coreutils.Desktop; import java.awt.Dimension; import java.awt.Font; import java.awt.Frame; diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/AboutWindowPanel.java b/Core/src/org/sleuthkit/autopsy/corecomponents/AboutWindowPanel.java index 200b04a6bb6..720f0dd4623 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/AboutWindowPanel.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/AboutWindowPanel.java @@ -19,7 +19,7 @@ package org.sleuthkit.autopsy.corecomponents; import java.awt.Cursor; -import java.awt.Desktop; +import org.sleuthkit.autopsy.coreutils.Desktop; import java.awt.Window; import java.io.File; import java.io.IOException; diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/OfflineHelpAction.java b/Core/src/org/sleuthkit/autopsy/corecomponents/OfflineHelpAction.java index 3981ac63b92..919bdd255f8 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/OfflineHelpAction.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/OfflineHelpAction.java @@ -18,7 +18,7 @@ */ package org.sleuthkit.autopsy.corecomponents; -import java.awt.Desktop; +import org.sleuthkit.autopsy.coreutils.Desktop; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/OnlineHelpAction.java b/Core/src/org/sleuthkit/autopsy/corecomponents/OnlineHelpAction.java index e75a421b3a9..ced8ad8c352 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/OnlineHelpAction.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/OnlineHelpAction.java @@ -20,7 +20,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.awt.Desktop; +import org.sleuthkit.autopsy.coreutils.Desktop; import java.io.IOException; import java.net.MalformedURLException; import java.net.URISyntaxException; diff --git a/Core/src/org/sleuthkit/autopsy/directorytree/ExternalViewerAction.java b/Core/src/org/sleuthkit/autopsy/directorytree/ExternalViewerAction.java index 020a2499fa0..7435caaf87c 100644 --- a/Core/src/org/sleuthkit/autopsy/directorytree/ExternalViewerAction.java +++ b/Core/src/org/sleuthkit/autopsy/directorytree/ExternalViewerAction.java @@ -18,7 +18,7 @@ */ package org.sleuthkit.autopsy.directorytree; -import java.awt.Desktop; +import org.sleuthkit.autopsy.coreutils.Desktop; import java.awt.event.ActionEvent; import java.io.File; import java.io.IOException; diff --git a/Core/src/org/sleuthkit/autopsy/modules/photoreccarver/PhotoRecCarverIngestJobSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/modules/photoreccarver/PhotoRecCarverIngestJobSettingsPanel.java index 1efafafd247..5fe1f1b76bb 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/photoreccarver/PhotoRecCarverIngestJobSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/modules/photoreccarver/PhotoRecCarverIngestJobSettingsPanel.java @@ -20,7 +20,7 @@ import java.awt.Color; import java.awt.Cursor; -import java.awt.Desktop; +import org.sleuthkit.autopsy.coreutils.Desktop; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.io.IOException; diff --git a/Core/src/org/sleuthkit/autopsy/modules/yara/ui/RuleSetDetailsPanel.java b/Core/src/org/sleuthkit/autopsy/modules/yara/ui/RuleSetDetailsPanel.java index ef6a3479219..bc241acd9e7 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/yara/ui/RuleSetDetailsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/modules/yara/ui/RuleSetDetailsPanel.java @@ -19,7 +19,7 @@ package org.sleuthkit.autopsy.modules.yara.ui; import java.awt.Component; -import java.awt.Desktop; +import org.sleuthkit.autopsy.coreutils.Desktop; import java.io.File; import java.io.IOException; import java.util.List; diff --git a/Core/src/org/sleuthkit/autopsy/report/ReportProgressPanel.java b/Core/src/org/sleuthkit/autopsy/report/ReportProgressPanel.java index f5d8e58aab0..b167d2b1b5c 100644 --- a/Core/src/org/sleuthkit/autopsy/report/ReportProgressPanel.java +++ b/Core/src/org/sleuthkit/autopsy/report/ReportProgressPanel.java @@ -21,7 +21,7 @@ import org.openide.util.NbBundle; import java.awt.Color; import java.awt.Cursor; -import java.awt.Desktop; +import org.sleuthkit.autopsy.coreutils.Desktop; import java.awt.EventQueue; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; diff --git a/Core/src/org/sleuthkit/autopsy/texttranslation/translators/BingTranslatorSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/texttranslation/translators/BingTranslatorSettingsPanel.java index a679dccd132..46a5394bb21 100644 --- a/Core/src/org/sleuthkit/autopsy/texttranslation/translators/BingTranslatorSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/texttranslation/translators/BingTranslatorSettingsPanel.java @@ -34,7 +34,7 @@ import javax.swing.event.DocumentListener; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; -import java.awt.Desktop; +import org.sleuthkit.autopsy.coreutils.Desktop; import java.net.URISyntaxException; import org.apache.commons.lang3.StringUtils; import org.openide.util.NbBundle.Messages; diff --git a/Core/src/org/sleuthkit/autopsy/texttranslation/translators/GoogleTranslatorSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/texttranslation/translators/GoogleTranslatorSettingsPanel.java index f790a9541b8..df42b732cf6 100644 --- a/Core/src/org/sleuthkit/autopsy/texttranslation/translators/GoogleTranslatorSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/texttranslation/translators/GoogleTranslatorSettingsPanel.java @@ -24,7 +24,7 @@ import com.google.cloud.translate.Translate; import com.google.cloud.translate.TranslateOptions; import com.google.cloud.translate.Translation; -import java.awt.Desktop; +import org.sleuthkit.autopsy.coreutils.Desktop; import java.awt.event.ItemListener; import java.io.File; import java.io.FileInputStream; diff --git a/Core/src/org/sleuthkit/autopsy/timeline/actions/SaveSnapshotAsReport.java b/Core/src/org/sleuthkit/autopsy/timeline/actions/SaveSnapshotAsReport.java index c713f73ef19..c3aa59cd8c8 100755 --- a/Core/src/org/sleuthkit/autopsy/timeline/actions/SaveSnapshotAsReport.java +++ b/Core/src/org/sleuthkit/autopsy/timeline/actions/SaveSnapshotAsReport.java @@ -18,7 +18,7 @@ */ package org.sleuthkit.autopsy.timeline.actions; -import java.awt.Desktop; +import org.sleuthkit.autopsy.coreutils.Desktop; import java.awt.image.BufferedImage; import java.io.IOException; import java.nio.file.InvalidPathException; diff --git a/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/AutoIngestAdminActions.java b/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/AutoIngestAdminActions.java index 6680074a17d..3171785909b 100644 --- a/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/AutoIngestAdminActions.java +++ b/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/AutoIngestAdminActions.java @@ -19,7 +19,7 @@ package org.sleuthkit.autopsy.experimental.autoingest; import java.awt.Cursor; -import java.awt.Desktop; +import org.sleuthkit.autopsy.coreutils.Desktop; import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.io.IOException; diff --git a/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/AutoIngestControlPanel.java b/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/AutoIngestControlPanel.java index fdecd191f3b..2de909ddb9a 100644 --- a/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/AutoIngestControlPanel.java +++ b/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/AutoIngestControlPanel.java @@ -20,7 +20,7 @@ import com.google.common.util.concurrent.ThreadFactoryBuilder; import java.awt.Cursor; -import java.awt.Desktop; +import org.sleuthkit.autopsy.coreutils.Desktop; import java.awt.EventQueue; import java.io.IOException; import java.nio.file.Path; diff --git a/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/AutoIngestMonitor.java b/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/AutoIngestMonitor.java index 0022cf6609a..fa5d770eb05 100644 --- a/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/AutoIngestMonitor.java +++ b/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/AutoIngestMonitor.java @@ -19,7 +19,7 @@ package org.sleuthkit.autopsy.experimental.autoingest; import com.google.common.util.concurrent.ThreadFactoryBuilder; -import java.awt.Desktop; +import org.sleuthkit.autopsy.coreutils.Desktop; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.BufferedWriter; diff --git a/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/CaseImportPanel.java b/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/CaseImportPanel.java index 7216f16816b..30e35c57ad0 100644 --- a/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/CaseImportPanel.java +++ b/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/CaseImportPanel.java @@ -19,7 +19,7 @@ package org.sleuthkit.autopsy.experimental.autoingest; import java.awt.Color; -import java.awt.Desktop; +import org.sleuthkit.autopsy.coreutils.Desktop; import java.awt.EventQueue; import java.awt.Font; import java.io.File; diff --git a/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/OpenAutoIngestLogAction.java b/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/OpenAutoIngestLogAction.java index d88f7fdd242..5cc7d2c723d 100755 --- a/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/OpenAutoIngestLogAction.java +++ b/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/OpenAutoIngestLogAction.java @@ -18,7 +18,7 @@ */ package org.sleuthkit.autopsy.experimental.autoingest; -import java.awt.Desktop; +import org.sleuthkit.autopsy.coreutils.Desktop; import java.awt.event.ActionEvent; import java.io.IOException; import java.nio.file.Path; From 2d32df628c5d6e8853cdbcb9c2681c986a177626 Mon Sep 17 00:00:00 2001 From: Greg DiCristofaro Date: Tue, 8 Aug 2023 12:04:06 -0400 Subject: [PATCH 2/6] desktop wrapper --- .../sleuthkit/autopsy/coreutils/Desktop.java | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 Core/src/org/sleuthkit/autopsy/coreutils/Desktop.java diff --git a/Core/src/org/sleuthkit/autopsy/coreutils/Desktop.java b/Core/src/org/sleuthkit/autopsy/coreutils/Desktop.java new file mode 100644 index 00000000000..60e72074525 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/coreutils/Desktop.java @@ -0,0 +1,99 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2023 Basis Technology Corp. + * Contact: carrier sleuthkit 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.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 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; + } + + public static boolean isDesktopSupported() { + return java.awt.Desktop.isDesktopSupported() || isXdgSupported(); + } + + private static Desktop instance = null; + + public static Desktop getDesktop() { + if (instance == null) { + instance = new Desktop(java.awt.Desktop.getDesktop()); + } + + return instance; + } + + private final java.awt.Desktop awtDesktop; + + private Desktop(java.awt.Desktop awtDesktop) { + this.awtDesktop = awtDesktop; + } + + private void xdgOpen(String path) throws IOException { + Runtime.getRuntime().exec(new String[]{"xdg-open", path}); + } + + public void browse(URI uri) throws IOException { + if (!awtDesktop.isSupported(java.awt.Desktop.Action.BROWSE) && isXdgSupported()) { + xdgOpen(uri.toString()); + } else { + awtDesktop.browse(uri); + } + } + + public void open(File file) throws IOException { + if (!awtDesktop.isSupported(java.awt.Desktop.Action.OPEN) && isXdgSupported()) { + xdgOpen(file.getAbsolutePath()); + } else { + awtDesktop.open(file); + } + } + + public void edit(File file) throws IOException { + if (!awtDesktop.isSupported(java.awt.Desktop.Action.EDIT) && isXdgSupported()) { + xdgOpen(file.getAbsolutePath()); + } else { + awtDesktop.edit(file); + } + } +} From 5662187b2d44b10ec01bd7c5d3fd329b6d4bb310 Mon Sep 17 00:00:00 2001 From: Greg DiCristofaro Date: Tue, 8 Aug 2023 13:04:30 -0400 Subject: [PATCH 3/6] commenting --- .../sleuthkit/autopsy/coreutils/Desktop.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Core/src/org/sleuthkit/autopsy/coreutils/Desktop.java b/Core/src/org/sleuthkit/autopsy/coreutils/Desktop.java index 60e72074525..84a218d6f7b 100644 --- a/Core/src/org/sleuthkit/autopsy/coreutils/Desktop.java +++ b/Core/src/org/sleuthkit/autopsy/coreutils/Desktop.java @@ -49,12 +49,19 @@ private static boolean isXdgSupported() { 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()); @@ -65,14 +72,28 @@ public static Desktop getDesktop() { 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 { Runtime.getRuntime().exec(new String[]{"xdg-open", path}); } + /** + * 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()); @@ -81,6 +102,11 @@ public void browse(URI uri) throws IOException { } } + /** + * 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()); @@ -89,6 +115,11 @@ public void open(File file) throws IOException { } } + /** + * 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()); From 854a2bae8a76225f31097ed9a5d51ccd74726d6f Mon Sep 17 00:00:00 2001 From: Greg DiCristofaro Date: Tue, 8 Aug 2023 15:09:50 -0400 Subject: [PATCH 4/6] offline help fix --- .../corecomponents/OfflineHelpAction.java | 72 ++++++++++--------- .../sleuthkit/autopsy/coreutils/Desktop.java | 26 +++++-- 2 files changed, 59 insertions(+), 39 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/OfflineHelpAction.java b/Core/src/org/sleuthkit/autopsy/corecomponents/OfflineHelpAction.java index 919bdd255f8..be018cff3b9 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/OfflineHelpAction.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/OfflineHelpAction.java @@ -21,9 +21,10 @@ import org.sleuthkit.autopsy.coreutils.Desktop; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.io.File; import java.io.IOException; import java.net.MalformedURLException; -import java.net.URI; +import java.nio.file.Paths; import org.netbeans.core.actions.HTMLViewAction; import org.openide.awt.ActionID; import org.openide.awt.ActionReference; @@ -33,6 +34,7 @@ import org.openide.util.NbBundle; import org.openide.util.NbBundle.Messages; import java.util.logging.Level; +import org.openide.modules.InstalledFileLocator; import org.sleuthkit.autopsy.coreutils.Logger; /** @@ -52,6 +54,9 @@ @Messages("CTL_OfflineHelpAction=Offline Autopsy Documentation") 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 Logger logger = org.sleuthkit.autopsy.coreutils.Logger.getLogger(AboutWindowPanel.class.getName()); @@ -67,41 +72,40 @@ public void actionPerformed(ActionEvent e) { * Tested and working: Chrome, Firefox, IE Not tested: Opera, Safari */ private void viewOfflineHelp() { - String fileForHelp = ""; - String indexForHelp = ""; - String currentDirectory = ""; - URI uri = null; - - try { - // Match the form: file:///C:/some/directory/AutopsyXYZ/docs/index.html - fileForHelp = NbBundle.getMessage(OfflineHelpAction.class, "FILE_FOR_LOCAL_HELP"); - indexForHelp = NbBundle.getMessage(OfflineHelpAction.class, "INDEX_FOR_LOCAL_HELP"); - 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 + + File systemHelpFile = getOfflineHelpFile(); + if (systemHelpFile == null) { + logger.log(Level.SEVERE, "Unable to load Offline Documentation file"); + return; } - if (uri != null) { - // Display URL in the System browser - if (Desktop.isDesktopSupported()) { - Desktop desktop = Desktop.getDesktop(); - try { - desktop.browse(uri); - } catch (IOException ex) { - logger.log(Level.SEVERE, "Unable to launch the system browser: " - + fileForHelp + currentDirectory + indexForHelp, ex); //NON-NLS - } - } else { - org.openide.awt.StatusDisplayer.getDefault().setStatusText( - NbBundle.getMessage(HTMLViewAction.class, "CTL_OpeningBrowser")); //NON-NLS - try { - HtmlBrowser.URLDisplayer.getDefault().showURL(uri.toURL()); - } catch (MalformedURLException ex) { - logger.log(Level.SEVERE, "Unable to launch the built-in browser: " - + fileForHelp + currentDirectory + indexForHelp, ex); //NON-NLS - } + + // Display URL in the System browser + if (Desktop.isDesktopSupported()) { + Desktop desktop = Desktop.getDesktop(); + try { + desktop.open(systemHelpFile); + return; + } catch (IOException ex) { + logger.log(Level.SEVERE, "Unable to launch the system browser: " + + systemHelpFile, ex); //NON-NLS } } + + org.openide.awt.StatusDisplayer.getDefault().setStatusText( + NbBundle.getMessage(HTMLViewAction.class, "CTL_OpeningBrowser")); //NON-NLS + try { + HtmlBrowser.URLDisplayer.getDefault().showURL(systemHelpFile.toURI().toURL()); + } catch (MalformedURLException ex) { + logger.log(Level.SEVERE, "Unable to launch the built-in browser: " + + systemHelpFile, ex); //NON-NLS + } + + } + + private File getOfflineHelpFile() { + return InstalledFileLocator.getDefault().getDefault().locate( + Paths.get(DOCS_FOLDER, HELP_HTML_FILE).toString(), + OfflineHelpAction.class.getPackage().getName(), + false); } } diff --git a/Core/src/org/sleuthkit/autopsy/coreutils/Desktop.java b/Core/src/org/sleuthkit/autopsy/coreutils/Desktop.java index 84a218d6f7b..bb7302ba98c 100644 --- a/Core/src/org/sleuthkit/autopsy/coreutils/Desktop.java +++ b/Core/src/org/sleuthkit/autopsy/coreutils/Desktop.java @@ -21,6 +21,7 @@ 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; @@ -31,6 +32,7 @@ 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; @@ -74,6 +76,7 @@ public static Desktop getDesktop() { /** * Private constructor for this wrapper. + * * @param awtDesktop The delegate java.awt.Desktop. */ private Desktop(java.awt.Desktop awtDesktop) { @@ -82,17 +85,28 @@ private Desktop(java.awt.Desktop awtDesktop) { /** * Opens a given path using `xdg-open` on linux. + * * @param path The path. - * @throws IOException + * @throws IOException */ private void xdgOpen(String path) throws IOException { - Runtime.getRuntime().exec(new String[]{"xdg-open", path}); + 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 + * @throws IOException */ public void browse(URI uri) throws IOException { if (!awtDesktop.isSupported(java.awt.Desktop.Action.BROWSE) && isXdgSupported()) { @@ -104,8 +118,9 @@ public void browse(URI uri) throws IOException { /** * Triggers the OS to open the given file. + * * @param file The file. - * @throws IOException + * @throws IOException */ public void open(File file) throws IOException { if (!awtDesktop.isSupported(java.awt.Desktop.Action.OPEN) && isXdgSupported()) { @@ -117,8 +132,9 @@ public void open(File file) throws IOException { /** * Triggers the OS to edit the given file. + * * @param file The file. - * @throws IOException + * @throws IOException */ public void edit(File file) throws IOException { if (!awtDesktop.isSupported(java.awt.Desktop.Action.EDIT) && isXdgSupported()) { From 03e3ec49c44f05d6236e23c10066d64e4704f20b Mon Sep 17 00:00:00 2001 From: Greg DiCristofaro Date: Tue, 8 Aug 2023 19:03:12 -0400 Subject: [PATCH 5/6] fixes --- .../autopsy/corecomponents/OfflineHelpAction.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/OfflineHelpAction.java b/Core/src/org/sleuthkit/autopsy/corecomponents/OfflineHelpAction.java index be018cff3b9..2aee2852cc5 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/OfflineHelpAction.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/OfflineHelpAction.java @@ -56,6 +56,7 @@ 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 = org.sleuthkit.autopsy.coreutils.Logger.getLogger(AboutWindowPanel.class.getName()); @@ -75,7 +76,7 @@ private void viewOfflineHelp() { File systemHelpFile = getOfflineHelpFile(); if (systemHelpFile == null) { - logger.log(Level.SEVERE, "Unable to load Offline Documentation file"); + logger.log(Level.SEVERE, "Unable to load Offline Documentation file at relative path: " + HELP_REL_PATH); return; } @@ -101,10 +102,12 @@ private void viewOfflineHelp() { } } + + private File getOfflineHelpFile() { - return InstalledFileLocator.getDefault().getDefault().locate( - Paths.get(DOCS_FOLDER, HELP_HTML_FILE).toString(), + return InstalledFileLocator.getDefault().locate( + HELP_REL_PATH, OfflineHelpAction.class.getPackage().getName(), false); } From 748e22d263f52d3831f1a0f3c4b71a9a40b28348 Mon Sep 17 00:00:00 2001 From: Greg DiCristofaro Date: Wed, 30 Aug 2023 14:17:00 -0400 Subject: [PATCH 6/6] fix from merge --- .../df/cybertriage/autopsy/CTIntegrationMissingDialog.java | 2 +- .../autopsy/ctoptions/ctcloud/CTMalwareScannerOptionsPanel.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/src/com/basistech/df/cybertriage/autopsy/CTIntegrationMissingDialog.java b/Core/src/com/basistech/df/cybertriage/autopsy/CTIntegrationMissingDialog.java index 9e534c98332..cc27d2e5e36 100644 --- a/Core/src/com/basistech/df/cybertriage/autopsy/CTIntegrationMissingDialog.java +++ b/Core/src/com/basistech/df/cybertriage/autopsy/CTIntegrationMissingDialog.java @@ -18,7 +18,7 @@ */ package com.basistech.df.cybertriage.autopsy; -import java.awt.Desktop; +import org.sleuthkit.autopsy.coreutils.Desktop; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; diff --git a/Core/src/com/basistech/df/cybertriage/autopsy/ctoptions/ctcloud/CTMalwareScannerOptionsPanel.java b/Core/src/com/basistech/df/cybertriage/autopsy/ctoptions/ctcloud/CTMalwareScannerOptionsPanel.java index deff21d4230..f1a9037d333 100644 --- a/Core/src/com/basistech/df/cybertriage/autopsy/ctoptions/ctcloud/CTMalwareScannerOptionsPanel.java +++ b/Core/src/com/basistech/df/cybertriage/autopsy/ctoptions/ctcloud/CTMalwareScannerOptionsPanel.java @@ -28,7 +28,7 @@ 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.InvalidLicenseException; -import java.awt.Desktop; +import org.sleuthkit.autopsy.coreutils.Desktop; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import java.io.IOException;