mirror of
https://github.com/Alvin-Zilverstand/nginx-proxy-manager.git
synced 2026-11-28 00:47:54 +01:00
Use fs module for credential file operations
Refactor (from the review) credential file handling to use fs module for directory creation and file writing
This commit is contained in:
1 parent
46bf3274d8
commit
6629abed32
1 file changed
+4
-7
+4
-7
@@ -6,6 +6,7 @@ import certificateModel from "./models/certificate.js";
|
|||||||
import settingModel from "./models/setting.js";
|
import settingModel from "./models/setting.js";
|
||||||
import userModel from "./models/user.js";
|
import userModel from "./models/user.js";
|
||||||
import userPermissionModel from "./models/user_permission.js";
|
import userPermissionModel from "./models/user_permission.js";
|
||||||
|
import fs from "fs";
|
||||||
|
|
||||||
export const isSetup = async () => {
|
export const isSetup = async () => {
|
||||||
const row = await userModel.query().select("id").where("is_deleted", 0).first();
|
const row = await userModel.query().select("id").where("is_deleted", 0).first();
|
||||||
@@ -120,18 +121,14 @@ const setupCertbotPlugins = async () => {
|
|||||||
|
|
||||||
// Make sure credentials file exists
|
// Make sure credentials file exists
|
||||||
const credentials_loc = `/etc/letsencrypt/credentials/credentials-${certificate.id}`;
|
const credentials_loc = `/etc/letsencrypt/credentials/credentials-${certificate.id}`;
|
||||||
// Escape single quotes and backslashes
|
|
||||||
if (typeof certificate.meta.dns_provider_credentials === "string") {
|
if (typeof certificate.meta.dns_provider_credentials === "string") {
|
||||||
const escapedCredentials = certificate.meta.dns_provider_credentials
|
promises.push(fs.mkdir("/etc/letsencrypt/credentials", { recursive: true })
|
||||||
.replaceAll("\\", "\\\\")
|
.then(() => fs.writeFile(credentials_loc, certificate.meta.dns_provider_credentials, { mode: 0o600, flag: "wx" })));
|
||||||
.replaceAll("'", "\\'");
|
|
||||||
const credentials_cmd = `[ -f '${credentials_loc}' ] || { mkdir -p /etc/letsencrypt/credentials 2> /dev/null; echo '${escapedCredentials}' > '${credentials_loc}' && chmod 600 '${credentials_loc}'; }`;
|
|
||||||
promises.push(utils.exec(credentials_cmd));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
await installPlugins(plugins);
|
await installPlugins(plugins);
|
||||||
|
|
||||||
if (promises.length) {
|
if (promises.length) {
|
||||||
|
|||||||
Reference in new issue
Block a user