Added 'Hide' to containers. need to build unhide.

This commit is contained in:
lllllllillllllillll 2023-12-12 19:38:11 -08:00
parent 7515592564
commit a396764880
4 changed files with 54 additions and 8 deletions

25
app.js
View file

@ -8,10 +8,13 @@ const PORT = process.env.PORT || 8000;
const routes = require("./routes");
// Functions and variables
const { serverStats, containerList, containerStats, containerAction, containerLogs } = require('./functions/system');
const { serverStats, containerList, containerStats, containerAction, containerLogs, hiddenContainers } = require('./functions/system');
let sentList, clicked;
app.locals.site_list = '';
const Containers = require('./database/ContainerSettings');
// Configure Session
const sessionMiddleware = session({
secret: "keyboard cat",
@ -90,6 +93,26 @@ io.on('connection', (socket) => {
clicked = false;
});
socket.on('hide', async (data) => {
console.log(`Hide ${data.container}`);
let containerExists = await Containers.findOne({ where: {name:data.container}});
if(!containerExists){
const container = await Containers.create({
name: data.container,
visibility: false
});
hiddenContainers();
console.log(`[Created] Container ${data.container} hidden`)
} else {
containerExists.update({ visibility: false });
console.log(`[Updated] Container ${data.container} hidden`)
hiddenContainers();
}
});
// Container logs
socket.on('logs', (data) => {

View file

@ -148,10 +148,10 @@ module.exports.dashCard = function dashCard(data) {
</div>
<div class="dropdown">
<a href="#" class="btn-action dropdown-toggle" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><!-- Download SVG icon from http://tabler-icons.io/i/dots-vertical -->
<svg xmlns="http://www.w3.org/2000/svg" class="icon-tabler icon-tabler-eye" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="#2c3e50" fill="none" stroke-linecap="round" stroke-linejoin="round"> <path stroke="none" d="M0 0h24v24H0z" fill="none"/> <path d="M10 12a2 2 0 1 0 4 0a2 2 0 0 0 -4 0" /> <path d="M21 12c-2.4 4 -5.4 6 -9 6c-3.6 0 -6.6 -2 -9 -6c2.4 -4 5.4 -6 9 -6c3.6 0 6.6 2 9 6" /> </svg>
<svg xmlns="http://www.w3.org/2000/svg" class="icon-tabler icon-tabler-eye" width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"> <path stroke="none" d="M0 0h24v24H0z" fill="none"/> <path d="M10 12a2 2 0 1 0 4 0a2 2 0 0 0 -4 0" /> <path d="M21 12c-2.4 4 -5.4 6 -9 6c-3.6 0 -6.6 -2 -9 -6c2.4 -4 5.4 -6 9 -6c3.6 0 6.6 2 9 6" /> </svg>
</a>
<div class="dropdown-menu dropdown-menu-end">
<a class="dropdown-item" href="#">Hide</a>
<a class="dropdown-item" onclick="hideContainer(this)" name="${name}" href="#">Hide</a>
</div>
</div>
</div>

View file

@ -1,9 +1,22 @@
const { currentLoad, mem, networkStats, fsSize, dockerContainerStats } = require('systeminformation');
const { currentLoad, mem, networkStats, fsSize, dockerContainerStats, networkInterfaces } = require('systeminformation');
var Docker = require('dockerode');
var docker = new Docker({ socketPath: '/var/run/docker.sock' });
const { dashCard } = require('../components/dashCard');
const { Readable } = require('stream');
const Containers = require('../database/ContainerSettings');
let hidden = '';
module.exports.hiddenContainers = async function () {
hidden = await Containers.findAll({ where: {visibility:false}});
hidden = hidden.map(a => a.name);
}
async () => {
let netif = await networkInterfaces();
console.log(netif);
}
// export docker
module.exports.docker = docker;
@ -33,7 +46,7 @@ module.exports.containerList = async function () {
for (const container of data) {
if (container.Names[0].slice(1) != 'dweebui') {
if (!hidden.includes(container.Names[0].slice(1))) {
let imageVersion = container.Image.split('/');
let service = imageVersion[imageVersion.length - 1].split(':')[0];
@ -53,7 +66,9 @@ module.exports.containerList = async function () {
}
ports_list.push(ports);
}
} catch { console.log('no ports') }
} catch {
// console.log('no ports')
}
for (let i = 0; i < 12; i++) {
if (ports_list[i] == undefined) {
@ -78,7 +93,9 @@ module.exports.containerList = async function () {
readwrite: value.split(':')[2]
}
volumes_list.push(volumes);
}} catch { console.log('no volumes') }
}} catch {
// console.log('no volumes')
}
for (let i = 0; i < 12; i++) {
if (volumes_list[i] == undefined) {
let volumes = {
@ -172,7 +189,7 @@ module.exports.containerStats = async function () {
for (const container of data) {
if (container.Names[0].slice(1) != 'dweebui') {
if (!hidden.includes(container.Names[0].slice(1))) {
const stats = await dockerContainerStats(container.Id);
let container_stat = {

View file

@ -115,6 +115,12 @@ function buttonAction(button) {
socket.emit('clicked', {container: button.name, state: button.id, action: button.value});
}
// container button actions
function hideContainer(button) {
socket.emit('hide', {container: button.name});
}
let containerLogs;