mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2026-09-24 13:40:19 +01:00
Updated backend packages
This commit is contained in:
+32
-35
@@ -1,3 +1,4 @@
|
||||
import fs from "node:fs/promises";
|
||||
import { installPlugins } from "./lib/certbot.js";
|
||||
import utils from "./lib/utils.js";
|
||||
import { setup as logger } from "./logger.js";
|
||||
@@ -6,12 +7,11 @@ import certificateModel from "./models/certificate.js";
|
||||
import settingModel from "./models/setting.js";
|
||||
import userModel from "./models/user.js";
|
||||
import userPermissionModel from "./models/user_permission.js";
|
||||
import fs from "fs/promises";
|
||||
|
||||
export const isSetup = async () => {
|
||||
const row = await userModel.query().select("id").where("is_deleted", 0).first();
|
||||
return row?.id > 0;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a default admin users if one doesn't already exist in the database
|
||||
@@ -45,18 +45,14 @@ const setupDefaultUser = async () => {
|
||||
roles: ["admin"],
|
||||
};
|
||||
|
||||
const user = await userModel
|
||||
.query()
|
||||
.insertAndFetch(data);
|
||||
const user = await userModel.query().insertAndFetch(data);
|
||||
|
||||
await authModel
|
||||
.query()
|
||||
.insert({
|
||||
user_id: user.id,
|
||||
type: "password",
|
||||
secret: initialAdminPassword,
|
||||
meta: {},
|
||||
});
|
||||
await authModel.query().insert({
|
||||
user_id: user.id,
|
||||
type: "password",
|
||||
secret: initialAdminPassword,
|
||||
meta: {},
|
||||
});
|
||||
|
||||
await userPermissionModel.query().insert({
|
||||
user_id: user.id,
|
||||
@@ -78,22 +74,16 @@ const setupDefaultUser = async () => {
|
||||
* @returns {Promise}
|
||||
*/
|
||||
const setupDefaultSettings = async () => {
|
||||
const row = await settingModel
|
||||
.query()
|
||||
.select("id")
|
||||
.where({ id: "default-site" })
|
||||
.first();
|
||||
const row = await settingModel.query().select("id").where({ id: "default-site" }).first();
|
||||
|
||||
if (!row?.id) {
|
||||
await settingModel
|
||||
.query()
|
||||
.insert({
|
||||
id: "default-site",
|
||||
name: "Default Site",
|
||||
description: "What to show when Nginx is hit with an unknown Host",
|
||||
value: "congratulations",
|
||||
meta: {},
|
||||
});
|
||||
await settingModel.query().insert({
|
||||
id: "default-site",
|
||||
name: "Default Site",
|
||||
description: "What to show when Nginx is hit with an unknown Host",
|
||||
value: "congratulations",
|
||||
meta: {},
|
||||
});
|
||||
logger.info("Default settings added");
|
||||
}
|
||||
};
|
||||
@@ -104,10 +94,7 @@ const setupDefaultSettings = async () => {
|
||||
* @returns {Promise}
|
||||
*/
|
||||
const setupCertbotPlugins = async () => {
|
||||
const certificates = await certificateModel
|
||||
.query()
|
||||
.where("is_deleted", 0)
|
||||
.andWhere("provider", "letsencrypt");
|
||||
const certificates = await certificateModel.query().where("is_deleted", 0).andWhere("provider", "letsencrypt");
|
||||
|
||||
if (certificates?.length) {
|
||||
const plugins = [];
|
||||
@@ -122,14 +109,24 @@ const setupCertbotPlugins = async () => {
|
||||
// Make sure credentials file exists
|
||||
const credentials_loc = `/etc/letsencrypt/credentials/credentials-${certificate.id}`;
|
||||
if (typeof certificate.meta.dns_provider_credentials === "string") {
|
||||
promises.push(fs.mkdir("/etc/letsencrypt/credentials", { recursive: true })
|
||||
.then(() => fs.writeFile(credentials_loc, certificate.meta.dns_provider_credentials, { mode: 0o600, flag: "wx" }))
|
||||
.catch((err) => { if (err.code !== "EEXIST") throw err; }));
|
||||
promises.push(
|
||||
fs
|
||||
.mkdir("/etc/letsencrypt/credentials", { recursive: true })
|
||||
.then(() =>
|
||||
fs.writeFile(credentials_loc, certificate.meta.dns_provider_credentials, {
|
||||
mode: 0o600,
|
||||
flag: "wx",
|
||||
}),
|
||||
)
|
||||
.catch((err) => {
|
||||
if (err.code !== "EEXIST") throw err;
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
|
||||
await installPlugins(plugins);
|
||||
|
||||
if (promises.length) {
|
||||
|
||||
Reference in New Issue
Block a user