mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-01-19 00:07:17 +01:00
install paths dynmaic (#2668)
# Description Please provide a summary of the changes, including relevant motivation and context. Closes #(issue_number) ## Checklist - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have performed a self-review of my own code - [ ] I have attached images of the change if it is UI based - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] If my code has heavily changed functionality I have updated relevant docs on [Stirling-PDFs doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) - [ ] My changes generate no new warnings - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only)
This commit is contained in:
parent
76cbf94fdc
commit
1bd7e420e5
@ -22,6 +22,7 @@ public class InstallationPathConfig {
|
|||||||
// Pipeline paths
|
// Pipeline paths
|
||||||
private static final String PIPELINE_WATCHED_FOLDERS_PATH;
|
private static final String PIPELINE_WATCHED_FOLDERS_PATH;
|
||||||
private static final String PIPELINE_FINISHED_FOLDERS_PATH;
|
private static final String PIPELINE_FINISHED_FOLDERS_PATH;
|
||||||
|
private static final String PIPELINE_DEFAULT_WEB_UI_CONFIGS;
|
||||||
|
|
||||||
// Custom file paths
|
// Custom file paths
|
||||||
private static final String STATIC_PATH;
|
private static final String STATIC_PATH;
|
||||||
@ -45,6 +46,7 @@ public class InstallationPathConfig {
|
|||||||
// Initialize pipeline paths
|
// Initialize pipeline paths
|
||||||
PIPELINE_WATCHED_FOLDERS_PATH = PIPELINE_PATH + "watchedFolders" + File.separator;
|
PIPELINE_WATCHED_FOLDERS_PATH = PIPELINE_PATH + "watchedFolders" + File.separator;
|
||||||
PIPELINE_FINISHED_FOLDERS_PATH = PIPELINE_PATH + "finishedFolders" + File.separator;
|
PIPELINE_FINISHED_FOLDERS_PATH = PIPELINE_PATH + "finishedFolders" + File.separator;
|
||||||
|
PIPELINE_DEFAULT_WEB_UI_CONFIGS = PIPELINE_PATH + "defaultWebUIConfigs" + File.separator;
|
||||||
|
|
||||||
// Initialize custom file paths
|
// Initialize custom file paths
|
||||||
STATIC_PATH = CUSTOM_FILES_PATH + "static" + File.separator;
|
STATIC_PATH = CUSTOM_FILES_PATH + "static" + File.separator;
|
||||||
@ -118,6 +120,10 @@ public class InstallationPathConfig {
|
|||||||
return PIPELINE_FINISHED_FOLDERS_PATH;
|
return PIPELINE_FINISHED_FOLDERS_PATH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getPipelineDefaultWebUIConfigsDir() {
|
||||||
|
return PIPELINE_DEFAULT_WEB_UI_CONFIGS;
|
||||||
|
}
|
||||||
|
|
||||||
public static String getStaticPath() {
|
public static String getStaticPath() {
|
||||||
return STATIC_PATH;
|
return STATIC_PATH;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package stirling.software.SPDF.config.security.database;
|
package stirling.software.SPDF.config.security.database;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
@ -9,6 +11,7 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import stirling.software.SPDF.config.InstallationPathConfig;
|
||||||
import stirling.software.SPDF.model.ApplicationProperties;
|
import stirling.software.SPDF.model.ApplicationProperties;
|
||||||
import stirling.software.SPDF.model.provider.UnsupportedProviderException;
|
import stirling.software.SPDF.model.provider.UnsupportedProviderException;
|
||||||
|
|
||||||
@ -17,8 +20,8 @@ import stirling.software.SPDF.model.provider.UnsupportedProviderException;
|
|||||||
@Configuration
|
@Configuration
|
||||||
public class DatabaseConfig {
|
public class DatabaseConfig {
|
||||||
|
|
||||||
public static final String DATASOURCE_DEFAULT_URL =
|
public final String DATASOURCE_DEFAULT_URL;
|
||||||
"jdbc:h2:file:./configs/stirling-pdf-DB-2.3.232;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE";
|
|
||||||
public static final String DATASOURCE_URL_TEMPLATE = "jdbc:%s://%s:%4d/%s";
|
public static final String DATASOURCE_URL_TEMPLATE = "jdbc:%s://%s:%4d/%s";
|
||||||
public static final String DEFAULT_DRIVER = "org.h2.Driver";
|
public static final String DEFAULT_DRIVER = "org.h2.Driver";
|
||||||
public static final String DEFAULT_USERNAME = "sa";
|
public static final String DEFAULT_USERNAME = "sa";
|
||||||
@ -30,6 +33,7 @@ public class DatabaseConfig {
|
|||||||
public DatabaseConfig(
|
public DatabaseConfig(
|
||||||
ApplicationProperties applicationProperties,
|
ApplicationProperties applicationProperties,
|
||||||
@Qualifier("runningEE") boolean runningEE) {
|
@Qualifier("runningEE") boolean runningEE) {
|
||||||
|
DATASOURCE_DEFAULT_URL = "jdbc:h2:file:" + InstallationPathConfig.getConfigPath() + File.separator + "stirling-pdf-DB-2.3.232;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE";
|
||||||
this.applicationProperties = applicationProperties;
|
this.applicationProperties = applicationProperties;
|
||||||
this.runningEE = runningEE;
|
this.runningEE = runningEE;
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ import org.springframework.jdbc.datasource.init.ScriptException;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import stirling.software.SPDF.config.InstallationPathConfig;
|
||||||
import stirling.software.SPDF.config.interfaces.DatabaseInterface;
|
import stirling.software.SPDF.config.interfaces.DatabaseInterface;
|
||||||
import stirling.software.SPDF.model.ApplicationProperties;
|
import stirling.software.SPDF.model.ApplicationProperties;
|
||||||
import stirling.software.SPDF.model.exception.BackupNotFoundException;
|
import stirling.software.SPDF.model.exception.BackupNotFoundException;
|
||||||
@ -37,12 +38,14 @@ public class DatabaseService implements DatabaseInterface {
|
|||||||
|
|
||||||
public static final String BACKUP_PREFIX = "backup_";
|
public static final String BACKUP_PREFIX = "backup_";
|
||||||
public static final String SQL_SUFFIX = ".sql";
|
public static final String SQL_SUFFIX = ".sql";
|
||||||
private static final String BACKUP_DIR = "configs/db/backup/";
|
private final Path BACKUP_DIR;
|
||||||
|
|
||||||
private final ApplicationProperties applicationProperties;
|
private final ApplicationProperties applicationProperties;
|
||||||
private final DataSource dataSource;
|
private final DataSource dataSource;
|
||||||
|
|
||||||
public DatabaseService(ApplicationProperties applicationProperties, DataSource dataSource) {
|
public DatabaseService(ApplicationProperties applicationProperties, DataSource dataSource) {
|
||||||
|
this.BACKUP_DIR =
|
||||||
|
Paths.get(InstallationPathConfig.getConfigPath(), "db", "backup").normalize();
|
||||||
this.applicationProperties = applicationProperties;
|
this.applicationProperties = applicationProperties;
|
||||||
this.dataSource = dataSource;
|
this.dataSource = dataSource;
|
||||||
}
|
}
|
||||||
@ -56,9 +59,8 @@ public class DatabaseService implements DatabaseInterface {
|
|||||||
@Override
|
@Override
|
||||||
public boolean hasBackup() {
|
public boolean hasBackup() {
|
||||||
createBackupDirectory();
|
createBackupDirectory();
|
||||||
Path filePath = Paths.get(BACKUP_DIR);
|
|
||||||
|
|
||||||
if (Files.exists(filePath)) {
|
if (Files.exists(BACKUP_DIR)) {
|
||||||
return !getBackupList().isEmpty();
|
return !getBackupList().isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,11 +79,9 @@ public class DatabaseService implements DatabaseInterface {
|
|||||||
if (isH2Database()) {
|
if (isH2Database()) {
|
||||||
createBackupDirectory();
|
createBackupDirectory();
|
||||||
|
|
||||||
Path backupPath = Paths.get(BACKUP_DIR);
|
|
||||||
|
|
||||||
try (DirectoryStream<Path> stream =
|
try (DirectoryStream<Path> stream =
|
||||||
Files.newDirectoryStream(
|
Files.newDirectoryStream(
|
||||||
backupPath,
|
BACKUP_DIR,
|
||||||
path ->
|
path ->
|
||||||
path.getFileName().toString().startsWith(BACKUP_PREFIX)
|
path.getFileName().toString().startsWith(BACKUP_PREFIX)
|
||||||
&& path.getFileName()
|
&& path.getFileName()
|
||||||
@ -114,10 +114,9 @@ public class DatabaseService implements DatabaseInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void createBackupDirectory() {
|
private void createBackupDirectory() {
|
||||||
Path backupPath = Paths.get(BACKUP_DIR);
|
if (!Files.exists(BACKUP_DIR)) {
|
||||||
if (!Files.exists(backupPath)) {
|
|
||||||
try {
|
try {
|
||||||
Files.createDirectories(backupPath);
|
Files.createDirectories(BACKUP_DIR);
|
||||||
log.debug("create backup directory: {}", BACKUP_DIR);
|
log.debug("create backup directory: {}", BACKUP_DIR);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("Error create backup directory: {}", e.getMessage(), e);
|
log.error("Error create backup directory: {}", e.getMessage(), e);
|
||||||
@ -271,7 +270,7 @@ public class DatabaseService implements DatabaseInterface {
|
|||||||
*/
|
*/
|
||||||
public Path getBackupFilePath(String fileName) {
|
public Path getBackupFilePath(String fileName) {
|
||||||
createBackupDirectory();
|
createBackupDirectory();
|
||||||
Path filePath = Paths.get(BACKUP_DIR, fileName).normalize();
|
Path filePath = BACKUP_DIR.resolve(fileName).normalize();
|
||||||
if (!filePath.startsWith(BACKUP_DIR)) {
|
if (!filePath.startsWith(BACKUP_DIR)) {
|
||||||
throw new SecurityException("Path traversal detected");
|
throw new SecurityException("Path traversal detected");
|
||||||
}
|
}
|
||||||
|
@ -54,8 +54,8 @@ public class GeneralWebController {
|
|||||||
model.addAttribute("currentPage", "pipeline");
|
model.addAttribute("currentPage", "pipeline");
|
||||||
List<String> pipelineConfigs = new ArrayList<>();
|
List<String> pipelineConfigs = new ArrayList<>();
|
||||||
List<Map<String, String>> pipelineConfigsWithNames = new ArrayList<>();
|
List<Map<String, String>> pipelineConfigsWithNames = new ArrayList<>();
|
||||||
if (new File("./pipeline/defaultWebUIConfigs/").exists()) {
|
if (new File(InstallationPathConfig.getPipelineDefaultWebUIConfigsDir()).exists()) {
|
||||||
try (Stream<Path> paths = Files.walk(Paths.get("./pipeline/defaultWebUIConfigs/"))) {
|
try (Stream<Path> paths = Files.walk(Paths.get(InstallationPathConfig.getPipelineDefaultWebUIConfigsDir()))) {
|
||||||
List<Path> jsonFiles =
|
List<Path> jsonFiles =
|
||||||
paths.filter(Files::isRegularFile)
|
paths.filter(Files::isRegularFile)
|
||||||
.filter(p -> p.toString().endsWith(".json"))
|
.filter(p -> p.toString().endsWith(".json"))
|
||||||
|
Loading…
Reference in New Issue
Block a user