diff --git a/controllers/dashboard.js b/controllers/dashboard.js index 8261226..a886154 100644 --- a/controllers/dashboard.js +++ b/controllers/dashboard.js @@ -1,5 +1,5 @@ import { Readable } from 'stream'; -import { Permission, User } from '../database/models.js'; +import { Permission, User, ServerSettings } from '../database/models.js'; import { docker } from '../server.js'; import { readFileSync } from 'fs'; import { currentLoad, mem, networkStats, fsSize, dockerContainerStats } from 'systeminformation'; @@ -31,6 +31,7 @@ export const DashboardAction = async (req, res) => { let value = req.header('hx-trigger'); let action = req.params.action; let modal = ''; + let hostip = req.connection.remoteAddress; switch (action) { case 'permissions': diff --git a/controllers/settings.js b/controllers/settings.js index ea3a3e5..3f348a5 100644 --- a/controllers/settings.js +++ b/controllers/settings.js @@ -15,25 +15,39 @@ export const settingsAction = async (req, res) => { let action = req.params.action; let name = req.header('hx-trigger-name'); let value = req.header('hx-trigger'); - - console.log(`action: ${action}`); - console.log(`name: ${name}`); - console.log(`value: ${value}`); + let ip = req.body.ip; if ((action == 'links') && (req.body.links == 'on')) { let exists = await ServerSettings.findOne({ where: {key: 'links'}}); - if (!exists) { const newSetting = await ServerSettings.create({ key: 'links', value: 'on'}); } - const setting = await ServerSettings.update({value: 'on'}, {where: {key: 'links'}}); + if (exists) { + const setting = await ServerSettings.update({value: ip}, {where: {key: 'links'}}); + } else { + const newSetting = await ServerSettings.create({ key: 'links', value: ip}); + } + console.log('Custom links on'); } else if ((action == 'links') && (!req.body.links)) { let exists = await ServerSettings.findOne({ where: {key: 'links'}}); - if (!exists) { const newSetting = await ServerSettings.create({ key: 'links', value: 'off'}); } - const setting = await ServerSettings.update({value: 'off'}, {where: {key: 'links'}}); + if (exists) { + const setting = await ServerSettings.update({value: 'localhost'}, {where: {key: 'links'}}); + } + console.log('Custom links off'); } if ((action == 'registration') && (req.body.registration == 'on')) { - console.log(`registration on and secret: ${req.body.secret}`); + let exists = await ServerSettings.findOne({ where: {key: 'registration'}}); + if (exists) { + const setting = await ServerSettings.update({value: req.body.secret}, {where: {key: 'registration'}}); + } else { + const newSetting = await ServerSettings.create({ key: 'registration', value: req.body.secret}); + } + console.log('registration on'); + } else if ((action == 'registration') && (!req.body.registration)) { + let exists = await ServerSettings.findOne({ where: {key: 'registration'}}); + if (exists) { + const setting = await ServerSettings.update({value: 'off'}, {where: {key: 'registration'}}); + } console.log('registration off'); } diff --git a/database/models.js b/database/models.js index a453b9e..925d2f2 100644 --- a/database/models.js +++ b/database/models.js @@ -238,7 +238,7 @@ export const ServerSettings = sequelize.define('ServerSettings', { }, value: { type: DataTypes.STRING, - allowNull: false + allowNull: true } }); diff --git a/views/settings.html b/views/settings.html index 8b23d36..2477840 100644 --- a/views/settings.html +++ b/views/settings.html @@ -45,37 +45,42 @@

Settings

-

Configure server below

+ -
+ -

Container Links

-

Set the default behaviour for container links.

-