mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-06-23 07:55:07 +00:00

# Description of Changes Please provide a summary of the changes, including: - Enable user to add custom JAVA ops with env JAVA_CUSTOM_OPTS - Added support for prometheus (enabled via JAVA_CUSTOM_OPTS + enterprise license) - Changed settings from enterprise naming to 'Premium' - KeygenLicense Check to support offline licenses - Disable URL-to-PDF due to huge security bug - Remove loud Split PDF logs - addUsers renamed to adminSettings - Added Usage analytics page - Add user button to only be enabled based on total users free - Improve Merge memory usage Closes #(issue_number) --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md) (if applicable) - [ ] I have performed a self-review of my own code - [ ] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] 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) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: a <a> Co-authored-by: pixeebot[bot] <104101892+pixeebot[bot]@users.noreply.github.com> Co-authored-by: Connor Yoh <con.yoh13@gmail.com>
125 lines
5.7 KiB
Java
125 lines
5.7 KiB
Java
package stirling.software.SPDF.config;
|
|
|
|
import java.io.FileNotFoundException;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.net.URISyntaxException;
|
|
import java.net.URL;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Path;
|
|
import java.nio.file.Paths;
|
|
import java.nio.file.StandardCopyOption;
|
|
import java.util.List;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
/**
|
|
* A naive, line-based approach to merging "settings.yml" with "settings.yml.template" while
|
|
* preserving exact whitespace, blank lines, and inline comments -- but we only rewrite the file if
|
|
* the merged content actually differs.
|
|
*/
|
|
@Slf4j
|
|
public class ConfigInitializer {
|
|
|
|
public void ensureConfigExists() throws IOException, URISyntaxException {
|
|
// 1) If settings file doesn't exist, create from template
|
|
Path destPath = Paths.get(InstallationPathConfig.getSettingsPath());
|
|
if (Files.notExists(destPath)) {
|
|
Files.createDirectories(destPath.getParent());
|
|
try (InputStream in =
|
|
getClass().getClassLoader().getResourceAsStream("settings.yml.template")) {
|
|
if (in == null) {
|
|
throw new FileNotFoundException(
|
|
"Resource file not found: settings.yml.template");
|
|
}
|
|
Files.copy(in, destPath);
|
|
}
|
|
log.info("Created settings file from template");
|
|
} else {
|
|
// 2) Merge existing file with the template
|
|
URL templateResource = getClass().getClassLoader().getResource("settings.yml.template");
|
|
if (templateResource == null) {
|
|
throw new IOException("Resource not found: settings.yml.template");
|
|
}
|
|
|
|
// Copy template to a temp location so we can read lines
|
|
Path tempTemplatePath = Files.createTempFile("settings.yml", ".template");
|
|
try (InputStream in = templateResource.openStream()) {
|
|
Files.copy(in, tempTemplatePath, StandardCopyOption.REPLACE_EXISTING);
|
|
}
|
|
|
|
// Copy setting.yaml to a temp location so we can read lines
|
|
Path settingTempPath = Files.createTempFile("settings", ".yaml");
|
|
try (InputStream in = Files.newInputStream(destPath)) {
|
|
Files.copy(in, settingTempPath, StandardCopyOption.REPLACE_EXISTING);
|
|
}
|
|
|
|
YamlHelper settingsTemplateFile = new YamlHelper(tempTemplatePath);
|
|
YamlHelper settingsFile = new YamlHelper(settingTempPath);
|
|
|
|
migrateEnterpriseEditionToPremium(settingsFile, settingsTemplateFile);
|
|
|
|
boolean changesMade =
|
|
settingsTemplateFile.updateValuesFromYaml(settingsFile, settingsTemplateFile);
|
|
if (changesMade) {
|
|
settingsTemplateFile.save(destPath);
|
|
log.info("Settings file updated based on template changes.");
|
|
} else {
|
|
log.info("No changes detected; settings file left as-is.");
|
|
}
|
|
|
|
Files.deleteIfExists(tempTemplatePath);
|
|
Files.deleteIfExists(settingTempPath);
|
|
}
|
|
|
|
// 3) Ensure custom settings file exists
|
|
Path customSettingsPath = Paths.get(InstallationPathConfig.getCustomSettingsPath());
|
|
if (Files.notExists(customSettingsPath)) {
|
|
Files.createFile(customSettingsPath);
|
|
log.info("Created custom_settings file: {}", customSettingsPath.toString());
|
|
}
|
|
}
|
|
|
|
// TODO: Remove post migration
|
|
private void migrateEnterpriseEditionToPremium(YamlHelper yaml, YamlHelper template) {
|
|
if (yaml.getValueByExactKeyPath("enterpriseEdition", "enabled") != null) {
|
|
template.updateValue(
|
|
List.of("premium", "enabled"),
|
|
yaml.getValueByExactKeyPath("enterpriseEdition", "enabled"));
|
|
}
|
|
if (yaml.getValueByExactKeyPath("enterpriseEdition", "key") != null) {
|
|
template.updateValue(
|
|
List.of("premium", "key"),
|
|
yaml.getValueByExactKeyPath("enterpriseEdition", "key"));
|
|
}
|
|
if (yaml.getValueByExactKeyPath("enterpriseEdition", "SSOAutoLogin") != null) {
|
|
template.updateValue(
|
|
List.of("premium", "proFeatures", "SSOAutoLogin"),
|
|
yaml.getValueByExactKeyPath("enterpriseEdition", "SSOAutoLogin"));
|
|
}
|
|
if (yaml.getValueByExactKeyPath("enterpriseEdition", "CustomMetadata", "autoUpdateMetadata")
|
|
!= null) {
|
|
template.updateValue(
|
|
List.of("premium", "proFeatures", "CustomMetadata", "autoUpdateMetadata"),
|
|
yaml.getValueByExactKeyPath(
|
|
"enterpriseEdition", "CustomMetadata", "autoUpdateMetadata"));
|
|
}
|
|
if (yaml.getValueByExactKeyPath("enterpriseEdition", "CustomMetadata", "author") != null) {
|
|
template.updateValue(
|
|
List.of("premium", "proFeatures", "CustomMetadata", "author"),
|
|
yaml.getValueByExactKeyPath("enterpriseEdition", "CustomMetadata", "author"));
|
|
}
|
|
if (yaml.getValueByExactKeyPath("enterpriseEdition", "CustomMetadata", "creator") != null) {
|
|
template.updateValue(
|
|
List.of("premium", "proFeatures", "CustomMetadata", "creator"),
|
|
yaml.getValueByExactKeyPath("enterpriseEdition", "CustomMetadata", "creator"));
|
|
}
|
|
if (yaml.getValueByExactKeyPath("enterpriseEdition", "CustomMetadata", "producer")
|
|
!= null) {
|
|
template.updateValue(
|
|
List.of("premium", "proFeatures", "CustomMetadata", "producer"),
|
|
yaml.getValueByExactKeyPath("enterpriseEdition", "CustomMetadata", "producer"));
|
|
}
|
|
}
|
|
}
|