diff --git a/README.md b/README.md index 2b8a206..21af889 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@

-

DweebUI Beta v0.50 ( :fire: Experimental :fire: )

+

DweebUI Beta v0.50 (:fire: Experimental :fire:)

Free and Open-Source WebUI For Managing Your Containers.

- -

@@ -12,13 +10,11 @@

+

-

screenshot

-
- ## About -* I started this as a personal project to get more familiar with Javascript and Node.js. There may be some rough edges and spaghetti code . +* I started this as a personal project to get more familiar with Javascript and Node.js, so there may be some rough edges and spaghetti code. * I'm open to any contributions but you may want to wait until I reach v1.0 first. * Please post issues and discussions so I know what bugs and features to focus on. * DweebUI is a management interface and should not be directly exposed to the internet diff --git a/controllers/dashboard.js b/controllers/dashboard.js index 99e035a..25c6f05 100644 --- a/controllers/dashboard.js +++ b/controllers/dashboard.js @@ -1,12 +1,15 @@ import { Readable } from 'stream'; -import { Permission, Container } from '../database/models.js'; +import { Permission, Container, User } from '../database/models.js'; import { docker } from '../server.js'; import { dockerContainerStats } from 'systeminformation'; import { readFileSync } from 'fs'; import { currentLoad, mem, networkStats, fsSize } from 'systeminformation'; +let hidden = ''; + // The actual page export const Dashboard = (req, res) => { + res.render("dashboard", { name: req.session.user, role: req.session.role, @@ -33,12 +36,15 @@ export const Stats = async (req, res) => { case 'NET': let down = 0; let up = 0; + let percent = 0; await networkStats().then(data => { down = Math.round(data[0].rx_bytes / (1024 * 1024)); up = Math.round(data[0].tx_bytes / (1024 * 1024)); + // percent of download vs max download if max download was 1GB + percent = Math.round((down / 1000) * 100); }); let net = `
- +
@@ -143,10 +149,6 @@ async function createCard (details) { let [ cardList, newCards, containersArray, sentArray, updatesArray ] = [ '', '', [], [], [] ]; -let hidden = await Container.findAll({ where: {visibility:false}}); -hidden = hidden.map((container) => container.name); - - export async function addCard (name, state) { console.log(`Adding card for ${name}: ${state}`); @@ -321,15 +323,195 @@ export const Logs = (req, res) => { export const Modals = async (req, res) => { let name = req.header('hx-trigger-name'); let id = req.header('hx-trigger'); + let title = name.charAt(0).toUpperCase() + name.slice(1); if (id == 'permissions') { let modal = readFileSync('./views/modals/permissions.html', 'utf8'); - modal = modal.replace(/AppName/g, name); - // let containerPermissions = await Permission.findAll({ where: {containerName: name}}); + let permissions_list = ''; + modal = modal.replace(/AppName/g, title); + let users = await User.findAll({ attributes: ['username', 'UUID']}); + + for (let i = 0; i < users.length; i++) { + // check if user Permission contains an entry for this container for this user. If not, create one. + let exists = await Permission.findOne({ where: {containerName: name, user: users[i].username}}); + if (!exists) { + const newPermission = await Permission.create({ containerName: name, user: users[i].username, userID: users[i].UUID}); + } + + let user_permissions = ` + +
+

+ +

+
+
+ + +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ + +
+
+ +
+
+ +
+
+ +
+ +
+ + +
+
+ +
+
+
`; + + permissions_list += user_permissions; + } + + modal = modal.replace(/PermissionsList/g, permissions_list); res.send(modal); return; } + + if (id == 'uninstall') { let modal = readFileSync('./views/modals/uninstall.html', 'utf8'); modal = modal.replace(/AppName/g, name); diff --git a/controllers/register.js b/controllers/register.js index 01a9c56..1b4e62b 100644 --- a/controllers/register.js +++ b/controllers/register.js @@ -1,4 +1,4 @@ -import { User, Syslog } from '../database/models.js'; +import { User, Syslog, Permission } from '../database/models.js'; import bcrypt from 'bcrypt'; let SECRET = process.env.SECRET || "MrWiskers" @@ -67,6 +67,11 @@ export const submitRegister = async function(req,res){ req.session.UUID = newUser.UUID; req.session.role = newUser.role; + const permission = await Permission.create({ + user: newUser.username, + userID: newUser.UUID + }); + const syslog = await Syslog.create({ user: req.session.user, email: email, diff --git a/database/models.js b/database/models.js index 6a66019..c12ad50 100644 --- a/database/models.js +++ b/database/models.js @@ -110,11 +110,9 @@ export const Permission = sequelize.define('Permission', { }, containerName: { type: DataTypes.STRING, - allowNull: false }, containerID: { type: DataTypes.STRING, - allowNull: false }, user: { type: DataTypes.STRING, diff --git a/router/index.js b/router/index.js index 7b77270..023b2fc 100644 --- a/router/index.js +++ b/router/index.js @@ -22,7 +22,7 @@ const auth = (req, res, next) => { if (req.session.role == "admin") { next(); } else { - res.redirect("/login"); + res.redirect("/portal"); } }; diff --git a/screenshots/dashboard1.png b/screenshots/dashboard1.png index 37b414e..cf5949c 100644 Binary files a/screenshots/dashboard1.png and b/screenshots/dashboard1.png differ diff --git a/server.js b/server.js index c01581f..976bbaf 100644 --- a/server.js +++ b/server.js @@ -10,6 +10,7 @@ export var docker = new Docker(); const app = express(); const MemoryStore = memorystore(session); const port = process.env.PORT || 8000; +const connection = process.env.HTTPS || false; // Session middleware const sessionMiddleware = session({ @@ -18,8 +19,8 @@ const sessionMiddleware = session({ resave: false, saveUninitialized: false, cookie:{ - secure: process.env.HTTPS || false, // Only set to true if you are using HTTPS. - httpOnly: process.env.HTTPS || false, // Only set to true if you are using HTTPS. + secure: connection, + httpOnly: connection, maxAge:3600000 * 8 // Session max age in milliseconds. 3600000 = 1 hour. } }); @@ -29,7 +30,6 @@ app.set('view engine', 'html'); app.engine('html', ejs.renderFile); app.use([ express.static('public'), - express.json(), express.urlencoded({ extended: true }), sessionMiddleware, router diff --git a/views/modals/permissions.html b/views/modals/permissions.html index 6c46c72..8be4dba 100644 --- a/views/modals/permissions.html +++ b/views/modals/permissions.html @@ -1,179 +1,13 @@