container link and registration switch saves to db

This commit is contained in:
lllllllillllllillll 2024-06-18 00:57:04 -07:00
parent da9692bdb1
commit c31131fef5
4 changed files with 48 additions and 28 deletions

View File

@ -1,5 +1,5 @@
import { Readable } from 'stream'; 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 { docker } from '../server.js';
import { readFileSync } from 'fs'; import { readFileSync } from 'fs';
import { currentLoad, mem, networkStats, fsSize, dockerContainerStats } from 'systeminformation'; 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 value = req.header('hx-trigger');
let action = req.params.action; let action = req.params.action;
let modal = ''; let modal = '';
let hostip = req.connection.remoteAddress;
switch (action) { switch (action) {
case 'permissions': case 'permissions':

View File

@ -15,25 +15,39 @@ export const settingsAction = async (req, res) => {
let action = req.params.action; let action = req.params.action;
let name = req.header('hx-trigger-name'); let name = req.header('hx-trigger-name');
let value = req.header('hx-trigger'); let value = req.header('hx-trigger');
let ip = req.body.ip;
console.log(`action: ${action}`);
console.log(`name: ${name}`);
console.log(`value: ${value}`);
if ((action == 'links') && (req.body.links == 'on')) { if ((action == 'links') && (req.body.links == 'on')) {
let exists = await ServerSettings.findOne({ where: {key: 'links'}}); let exists = await ServerSettings.findOne({ where: {key: 'links'}});
if (!exists) { const newSetting = await ServerSettings.create({ key: 'links', value: 'on'}); } if (exists) {
const setting = await ServerSettings.update({value: 'on'}, {where: {key: 'links'}}); 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)) { } else if ((action == 'links') && (!req.body.links)) {
let exists = await ServerSettings.findOne({ where: {key: 'links'}}); let exists = await ServerSettings.findOne({ where: {key: 'links'}});
if (!exists) { const newSetting = await ServerSettings.create({ key: 'links', value: 'off'}); } if (exists) {
const setting = await ServerSettings.update({value: 'off'}, {where: {key: 'links'}}); const setting = await ServerSettings.update({value: 'localhost'}, {where: {key: 'links'}});
}
console.log('Custom links off');
} }
if ((action == 'registration') && (req.body.registration == 'on')) { 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)) { } 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'); console.log('registration off');
} }

View File

@ -238,7 +238,7 @@ export const ServerSettings = sequelize.define('ServerSettings', {
}, },
value: { value: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false allowNull: true
} }
}); });

View File

@ -45,37 +45,42 @@
<div class="card-body"> <div class="card-body">
<h2 class="">Settings</h2> <h2 class="">Settings</h2>
<p class="text-muted mb-4">Configure server below</p> <!-- <p class="text-muted mb-4">Configure server below</p> -->
<div class="row align-items-center"> <!-- <div class="row align-items-center">
<div class="col"> <div class="col">
<a href="./QuickConnect.bat" class="btn" download="QuickConnect.bat"> <a href="./QuickConnect.bat" class="btn" download="QuickConnect.bat">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-brand-windows" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"> <path stroke="none" d="M0 0h24v24H0z" fill="none"></path> <path d="M17.8 20l-12 -1.5c-1 -.1 -1.8 -.9 -1.8 -1.9v-9.2c0 -1 .8 -1.8 1.8 -1.9l12 -1.5c1.2 -.1 2.2 .8 2.2 1.9v12.1c0 1.2 -1.1 2.1 -2.2 1.9z"></path> <path d="M12 5l0 14"></path> <path d="M4 12l16 0"></path> </svg> <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-brand-windows" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"> <path stroke="none" d="M0 0h24v24H0z" fill="none"></path> <path d="M17.8 20l-12 -1.5c-1 -.1 -1.8 -.9 -1.8 -1.9v-9.2c0 -1 .8 -1.8 1.8 -1.9l12 -1.5c1.2 -.1 2.2 .8 2.2 1.9v12.1c0 1.2 -1.1 2.1 -2.2 1.9z"></path> <path d="M12 5l0 14"></path> <path d="M4 12l16 0"></path> </svg>
Windows QuickConnect Windows QuickConnect
</a> </a>
</div> </div>
</div> </div> -->
<h3 class="card-title mt-6">Container Links</h3> <h3 class="mt-5">Container Links</h3>
<p class="card-subtitle"> Set the default behaviour for container links. </p> <label class="text-muted mb-2">Choose the default behaviour for container links. Enter IP address or Domain before enabling.</label>
<form id="container-links"> <form id="container_links">
<div> <div class="row align-items-center">
<label class="form-check form-switch form-switch-lg"> <div class="col-auto">
<input class="form-check-input" type="checkbox" id="submit" name="links" hx-trigger="click" hx-post="/settings/links" hx-swap="none"> <label class="form-check form-switch form-switch-lg">
<span class="form-check-label form-check-label-on"> <input class="form-check-input" type="checkbox" id="submit" name="links" hx-trigger="click" hx-post="/settings/links" hx-swap="none">
Host IP <span class="form-check-label form-check-label-on text-warning">
</span> Custom
<span class="form-check-label form-check-label-off"> </span>
Localhost <span class="form-check-label form-check-label-off text-success">
</span> Localhost
</label> </span>
</label>
</div>
<div class="col-6">
<input type="text" class="form-control" name="ip" placeholder="IP Address or Domain">
</div>
</div> </div>
</form> </form>
<h3 class="mt-6">User Registration</h3> <h3 class="mt-5">User Registration</h3>
<label class="text-muted mb-2">Allow other users to register.</label> <label class="text-muted mb-2">Allow other users to register.</label>
<form id="registration"> <form id="registration">
<div class="row align-items-center"> <div class="row align-items-center">