diff --git a/src/main/java/stirling/software/SPDF/SPdfApplication.java b/src/main/java/stirling/software/SPDF/SPdfApplication.java index 0d3299c843c..1e66e1cec1e 100644 --- a/src/main/java/stirling/software/SPDF/SPdfApplication.java +++ b/src/main/java/stirling/software/SPDF/SPdfApplication.java @@ -23,6 +23,7 @@ import org.springframework.scheduling.annotation.EnableScheduling; import io.github.pixee.security.SystemCommand; + import jakarta.annotation.PostConstruct; import jakarta.annotation.PreDestroy; import lombok.extern.slf4j.Slf4j; @@ -154,7 +155,7 @@ public void init() { && Boolean.parseBoolean(System.getProperty("STIRLING_PDF_DESKTOP_UI", "false"))) { webBrowser.initWebUI(url); } else { - String browserOpenEnv = env.getProperty("BROWSER_OPEN"); + String browserOpenEnv = env.getProperty("BROWSER_OPEN"); boolean browserOpen = browserOpenEnv != null && "true".equalsIgnoreCase(browserOpenEnv); if (browserOpen) { try { @@ -173,7 +174,7 @@ public void init() { } } } - logger.info("Running configs {}", applicationProperties.toString()); + logger.info("Running configs {}", applicationProperties.toString()); } @PreDestroy diff --git a/src/main/java/stirling/software/SPDF/config/AppConfig.java b/src/main/java/stirling/software/SPDF/config/AppConfig.java index 75497dba103..e45a750bee9 100644 --- a/src/main/java/stirling/software/SPDF/config/AppConfig.java +++ b/src/main/java/stirling/software/SPDF/config/AppConfig.java @@ -101,6 +101,27 @@ public boolean runningInDocker() { return Files.exists(Paths.get("/.dockerenv")); } + @Bean(name = "configDirMounted") + public boolean isRunningInDockerWithConfig() { + Path dockerEnv = Paths.get("/.dockerenv"); + // default to true if not docker + if (!Files.exists(dockerEnv)) { + return true; + } + + Path mountInfo = Paths.get("/proc/1/mountinfo"); + // this should always exist, if not some unknown usecase + if (!Files.exists(mountInfo)) { + return true; + } + + try { + return Files.lines(mountInfo).anyMatch(line -> line.contains(" /configs ")); + } catch (IOException e) { + return false; + } + } + @Bean(name = "bookAndHtmlFormatsInstalled") public boolean bookAndHtmlFormatsInstalled() { String installOps = System.getProperty("INSTALL_BOOK_AND_ADVANCED_HTML_OPS"); diff --git a/src/main/java/stirling/software/SPDF/controller/api/security/PasswordController.java b/src/main/java/stirling/software/SPDF/controller/api/security/PasswordController.java index be6b5019bba..d738ae795ba 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/security/PasswordController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/security/PasswordController.java @@ -39,7 +39,10 @@ public PasswordController(CustomPDDocumentFactory pdfDocumentFactory) { } @PostMapping(consumes = "multipart/form-data", value = "/remove-password") - @Operation(summary = "Remove password from a PDF file", description = "This endpoint removes the password from a protected PDF file. Users need to provide the existing password. Input:PDF Output:PDF Type:SISO") + @Operation( + summary = "Remove password from a PDF file", + description = + "This endpoint removes the password from a protected PDF file. Users need to provide the existing password. Input:PDF Output:PDF Type:SISO") public ResponseEntity removePassword(@ModelAttribute PDFPasswordRequest request) throws IOException { MultipartFile fileInput = request.getFileInput(); @@ -49,12 +52,15 @@ public ResponseEntity removePassword(@ModelAttribute PDFPasswordRequest return WebResponseUtils.pdfDocToWebResponse( document, Filenames.toSimpleFileName(fileInput.getOriginalFilename()) - .replaceFirst("[.][^.]+$", "") + .replaceFirst("[.][^.]+$", "") + "_password_removed.pdf"); } @PostMapping(consumes = "multipart/form-data", value = "/add-password") - @Operation(summary = "Add password to a PDF file", description = "This endpoint adds password protection to a PDF file. Users can specify a set of permissions that should be applied to the file. Input:PDF Output:PDF") + @Operation( + summary = "Add password to a PDF file", + description = + "This endpoint adds password protection to a PDF file. Users can specify a set of permissions that should be applied to the file. Input:PDF Output:PDF") public ResponseEntity addPassword(@ModelAttribute AddPasswordRequest request) throws IOException { MultipartFile fileInput = request.getFileInput(); @@ -92,12 +98,12 @@ public ResponseEntity addPassword(@ModelAttribute AddPasswordRequest req return WebResponseUtils.pdfDocToWebResponse( document, Filenames.toSimpleFileName(fileInput.getOriginalFilename()) - .replaceFirst("[.][^.]+$", "") + .replaceFirst("[.][^.]+$", "") + "_permissions.pdf"); return WebResponseUtils.pdfDocToWebResponse( document, Filenames.toSimpleFileName(fileInput.getOriginalFilename()) - .replaceFirst("[.][^.]+$", "") + .replaceFirst("[.][^.]+$", "") + "_passworded.pdf"); } } diff --git a/src/main/java/stirling/software/SPDF/service/PostHogService.java b/src/main/java/stirling/software/SPDF/service/PostHogService.java index a2d3d485f5d..3127e2af541 100644 --- a/src/main/java/stirling/software/SPDF/service/PostHogService.java +++ b/src/main/java/stirling/software/SPDF/service/PostHogService.java @@ -31,11 +31,13 @@ public class PostHogService { private final ApplicationProperties applicationProperties; private final UserServiceInterface userService; private final Environment env; + private boolean configDirMounted; @Autowired public PostHogService( PostHog postHog, @Qualifier("UUID") String uuid, + @Qualifier("configDirMounted") boolean configDirMounted, @Qualifier("appVersion") String appVersion, ApplicationProperties applicationProperties, @Autowired(required = false) UserServiceInterface userService, @@ -46,6 +48,7 @@ public PostHogService( this.applicationProperties = applicationProperties; this.userService = userService; this.env = env; + this.configDirMounted = configDirMounted; captureSystemInfo(); } @@ -80,6 +83,7 @@ public Map captureServerMetrics() { deploymentType = "DOCKER"; } metrics.put("deployment_type", deploymentType); + metrics.put("mounted_config_dir", configDirMounted); // System info metrics.put("os_name", System.getProperty("os.name")); diff --git a/src/main/java/stirling/software/SPDF/utils/GeneralUtils.java b/src/main/java/stirling/software/SPDF/utils/GeneralUtils.java index 1494b785ea6..bb3bbc04d87 100644 --- a/src/main/java/stirling/software/SPDF/utils/GeneralUtils.java +++ b/src/main/java/stirling/software/SPDF/utils/GeneralUtils.java @@ -121,10 +121,15 @@ private static boolean isLocalAddress(String host) { InetAddress address = InetAddress.getByName(host); // Check for local addresses - return address.isAnyLocalAddress() || // Matches 0.0.0.0 or similar - address.isLoopbackAddress() || // Matches 127.0.0.1 or ::1 - address.isSiteLocalAddress() || // Matches private IPv4 ranges: 192.168.x.x, 10.x.x.x, 172.16.x.x to 172.31.x.x - address.getHostAddress().startsWith("fe80:"); // Matches link-local IPv6 addresses + return address.isAnyLocalAddress() + || // Matches 0.0.0.0 or similar + address.isLoopbackAddress() + || // Matches 127.0.0.1 or ::1 + address.isSiteLocalAddress() + || // Matches private IPv4 ranges: 192.168.x.x, 10.x.x.x, 172.16.x.x to + // 172.31.x.x + address.getHostAddress() + .startsWith("fe80:"); // Matches link-local IPv6 addresses } catch (Exception e) { return false; // Return false for invalid or unresolved addresses }