Fix configuration template

This commit is contained in:
Samuel Oechsler 2024-09-19 19:39:17 +02:00
parent 0b09f03f49
commit 8b841176fa
No known key found for this signature in database
4 changed files with 71 additions and 55 deletions

View File

@ -75,54 +75,56 @@ const setupDefaultUser = () => {
* @returns {Promise} * @returns {Promise}
*/ */
const setupDefaultSettings = () => { const setupDefaultSettings = () => {
return Promise.all([settingModel return Promise.all([
.query() settingModel
.select(settingModel.raw('COUNT(`id`) as `count`')) .query()
.where({id: 'default-site'}) .select(settingModel.raw('COUNT(`id`) as `count`'))
.first() .where({id: 'default-site'})
.then((row) => { .first()
if (!row.count) { .then((row) => {
settingModel if (!row.count) {
.query() settingModel
.insert({ .query()
id: 'default-site', .insert({
name: 'Default Site', id: 'default-site',
description: 'What to show when Nginx is hit with an unknown Host', name: 'Default Site',
value: 'congratulations', description: 'What to show when Nginx is hit with an unknown Host',
meta: {}, value: 'congratulations',
}) meta: {},
.then(() => { })
logger.info('Added default-site setting'); .then(() => {
}); logger.info('Added default-site setting');
} });
if (config.debug()) { }
logger.info('Default setting setup not required'); if (config.debug()) {
} logger.info('Default setting setup not required');
}), }
settingModel }),
.query() settingModel
.select(settingModel.raw('COUNT(`id`) as `count`')) .query()
.where({id: 'oidc-config'}) .select(settingModel.raw('COUNT(`id`) as `count`'))
.first() .where({id: 'oidc-config'})
.then((row) => { .first()
if (!row.count) { .then((row) => {
settingModel if (!row.count) {
.query() settingModel
.insert({ .query()
id: 'oidc-config', .insert({
name: 'Open ID Connect', id: 'oidc-config',
description: 'Sign in to Nginx Proxy Manager with an external Identity Provider', name: 'Open ID Connect',
value: 'metadata', description: 'Sign in to Nginx Proxy Manager with an external Identity Provider',
meta: {}, value: 'metadata',
}) meta: {},
.then(() => { })
logger.info('Added oidc-config setting'); .then(() => {
}); logger.info('Added oidc-config setting');
} });
if (debug_mode) { }
logger.debug('Default setting setup not required'); if (config.debug()) {
} logger.info('Default setting setup not required');
})]); }
})
]);
}; };
/** /**

View File

@ -1,7 +1,19 @@
<td> <td>
<div><%- i18n('settings', 'default-site') %></div> <div>
<% if (id === 'default-site') { %>
<%- i18n('settings', 'default-site') %>
<% } %>
<% if (id === 'oidc-config') { %>
<%- i18n('settings', 'oidc-config') %>
<% } %>
</div>
<div class="small text-muted"> <div class="small text-muted">
<%- i18n('settings', 'default-site-description') %> <% if (id === 'default-site') { %>
<%- i18n('settings', 'default-site-description') %>
<% } %>
<% if (id === 'oidc-config') { %>
<%- i18n('settings', 'oidc-config-description') %>
<% } %>
</div> </div>
</td> </td>
<td> <td>
@ -12,10 +24,10 @@
<% if (id === 'oidc-config' && meta && meta.name && meta.clientID && meta.clientSecret && meta.issuerURL && meta.redirectURL) { %> <% if (id === 'oidc-config' && meta && meta.name && meta.clientID && meta.clientSecret && meta.issuerURL && meta.redirectURL) { %>
<%- meta.name %> <%- meta.name %>
<% if (!meta.enabled) { %> <% if (!meta.enabled) { %>
(Disabled) (<%- i18n('str', 'disabled') %>)
<% } %> <% } %>
<% } else if (id === 'oidc-config') { %> <% } else if (id === 'oidc-config') { %>
Not configured <%- i18n('settings', 'oidc-not-configured') %>
<% } %> <% } %>
</div> </div>
</td> </td>

View File

@ -15,7 +15,7 @@
</div> </div>
<div class="custom-controls-stacked"> <div class="custom-controls-stacked">
<div class="form-group"> <div class="form-group">
<label class="form-label">Name <span class="form-required">*</span> <label class="form-label"><%- i18n('str', 'name') %> <span class="form-required">*</span>
<input class="form-control name-input" name="meta[name]" required type="text" value="<%- meta && typeof meta.name !== 'undefined' ? meta.name : '' %>"> <input class="form-control name-input" name="meta[name]" required type="text" value="<%- meta && typeof meta.name !== 'undefined' ? meta.name : '' %>">
</label> </label>
</div> </div>
@ -40,7 +40,7 @@
</label> </label>
</div> </div>
<div class="form-group"> <div class="form-group">
<div class="form-label">Enabled</div> <div class="form-label"><%- i18n('str', 'enable') %></div>
<input class="form-check enabled-input" name="meta[enabled]" placeholder="" type="checkbox" <%- meta && (typeof meta.enabled !== 'undefined' && meta.enabled === true) || (JSON.stringify(meta) === '{}') ? 'checked="checked"' : '' %> > <input class="form-check enabled-input" name="meta[enabled]" placeholder="" type="checkbox" <%- meta && (typeof meta.enabled !== 'undefined' && meta.enabled === true) || (JSON.stringify(meta) === '{}') ? 'checked="checked"' : '' %> >
</div> </div>
</div> </div>

View File

@ -293,6 +293,8 @@
"default-site-html": "Custom Page", "default-site-html": "Custom Page",
"default-site-redirect": "Redirect", "default-site-redirect": "Redirect",
"oidc-config": "Open ID Conncect Configuration", "oidc-config": "Open ID Conncect Configuration",
"oidc-config-description": "Sign in to Nginx Proxy Manager with an external Identity Provider",
"oidc-not-configured": "Not configured",
"oidc-config-hint-1": "Provide configuration for an IdP that supports Open ID Connect Discovery.", "oidc-config-hint-1": "Provide configuration for an IdP that supports Open ID Connect Discovery.",
"oidc-config-hint-2": "The 'RedirectURL' must be set to '[base URL]/api/oidc/callback', the IdP must send the 'email' claim and a user with matching email address must exist in Nginx Proxy Manager." "oidc-config-hint-2": "The 'RedirectURL' must be set to '[base URL]/api/oidc/callback', the IdP must send the 'email' claim and a user with matching email address must exist in Nginx Proxy Manager."
} }