mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-06-06 18:30:57 +00:00
mounted_config_dir
This commit is contained in:
parent
faf3454a02
commit
8a5d9f9a95
@ -23,6 +23,7 @@ import org.springframework.core.env.Environment;
|
|||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
|
||||||
import io.github.pixee.security.SystemCommand;
|
import io.github.pixee.security.SystemCommand;
|
||||||
|
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import jakarta.annotation.PreDestroy;
|
import jakarta.annotation.PreDestroy;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
@ -101,6 +101,27 @@ public class AppConfig {
|
|||||||
return Files.exists(Paths.get("/.dockerenv"));
|
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")
|
@Bean(name = "bookAndHtmlFormatsInstalled")
|
||||||
public boolean bookAndHtmlFormatsInstalled() {
|
public boolean bookAndHtmlFormatsInstalled() {
|
||||||
String installOps = System.getProperty("INSTALL_BOOK_AND_ADVANCED_HTML_OPS");
|
String installOps = System.getProperty("INSTALL_BOOK_AND_ADVANCED_HTML_OPS");
|
||||||
|
@ -39,7 +39,10 @@ public class PasswordController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(consumes = "multipart/form-data", value = "/remove-password")
|
@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<byte[]> removePassword(@ModelAttribute PDFPasswordRequest request)
|
public ResponseEntity<byte[]> removePassword(@ModelAttribute PDFPasswordRequest request)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
MultipartFile fileInput = request.getFileInput();
|
MultipartFile fileInput = request.getFileInput();
|
||||||
@ -54,7 +57,10 @@ public class PasswordController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(consumes = "multipart/form-data", value = "/add-password")
|
@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<byte[]> addPassword(@ModelAttribute AddPasswordRequest request)
|
public ResponseEntity<byte[]> addPassword(@ModelAttribute AddPasswordRequest request)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
MultipartFile fileInput = request.getFileInput();
|
MultipartFile fileInput = request.getFileInput();
|
||||||
|
@ -31,11 +31,13 @@ public class PostHogService {
|
|||||||
private final ApplicationProperties applicationProperties;
|
private final ApplicationProperties applicationProperties;
|
||||||
private final UserServiceInterface userService;
|
private final UserServiceInterface userService;
|
||||||
private final Environment env;
|
private final Environment env;
|
||||||
|
private boolean configDirMounted;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public PostHogService(
|
public PostHogService(
|
||||||
PostHog postHog,
|
PostHog postHog,
|
||||||
@Qualifier("UUID") String uuid,
|
@Qualifier("UUID") String uuid,
|
||||||
|
@Qualifier("configDirMounted") boolean configDirMounted,
|
||||||
@Qualifier("appVersion") String appVersion,
|
@Qualifier("appVersion") String appVersion,
|
||||||
ApplicationProperties applicationProperties,
|
ApplicationProperties applicationProperties,
|
||||||
@Autowired(required = false) UserServiceInterface userService,
|
@Autowired(required = false) UserServiceInterface userService,
|
||||||
@ -46,6 +48,7 @@ public class PostHogService {
|
|||||||
this.applicationProperties = applicationProperties;
|
this.applicationProperties = applicationProperties;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
this.env = env;
|
this.env = env;
|
||||||
|
this.configDirMounted = configDirMounted;
|
||||||
captureSystemInfo();
|
captureSystemInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,6 +83,7 @@ public class PostHogService {
|
|||||||
deploymentType = "DOCKER";
|
deploymentType = "DOCKER";
|
||||||
}
|
}
|
||||||
metrics.put("deployment_type", deploymentType);
|
metrics.put("deployment_type", deploymentType);
|
||||||
|
metrics.put("mounted_config_dir", configDirMounted);
|
||||||
|
|
||||||
// System info
|
// System info
|
||||||
metrics.put("os_name", System.getProperty("os.name"));
|
metrics.put("os_name", System.getProperty("os.name"));
|
||||||
|
@ -121,10 +121,15 @@ public class GeneralUtils {
|
|||||||
InetAddress address = InetAddress.getByName(host);
|
InetAddress address = InetAddress.getByName(host);
|
||||||
|
|
||||||
// Check for local addresses
|
// Check for local addresses
|
||||||
return address.isAnyLocalAddress() || // Matches 0.0.0.0 or similar
|
return address.isAnyLocalAddress()
|
||||||
address.isLoopbackAddress() || // Matches 127.0.0.1 or ::1
|
|| // Matches 0.0.0.0 or similar
|
||||||
address.isSiteLocalAddress() || // Matches private IPv4 ranges: 192.168.x.x, 10.x.x.x, 172.16.x.x to 172.31.x.x
|
address.isLoopbackAddress()
|
||||||
address.getHostAddress().startsWith("fe80:"); // Matches link-local IPv6 addresses
|
|| // 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) {
|
} catch (Exception e) {
|
||||||
return false; // Return false for invalid or unresolved addresses
|
return false; // Return false for invalid or unresolved addresses
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user