Skip to content

Commit

Permalink
added jwt token and refined styling
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelAngelo13 committed Apr 1, 2023
1 parent f3b014f commit 4b19ed4
Show file tree
Hide file tree
Showing 50 changed files with 758 additions and 854 deletions.
12 changes: 6 additions & 6 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ services:
image: docketeerxi/postgres
restart: always
ports:
- '${POSTGRES_PORT}:5432'
- '5432:5432'
volumes:
- ./imageConfigs/postgres/docketeerdb:/var/lib/postgresql/data/

environment:
POSTGRES_DB: ${POSTGRES_NAME}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASS}
POSTGRES_DB: 'docketeer-db'
POSTGRES_USER: 'postgres'
POSTGRES_PASSWORD: 'postgres'

cadvisor:
image: gcr.io/cadvisor/cadvisor:v0.47.1
Expand Down Expand Up @@ -82,7 +82,7 @@ services:
image: docketeerxi/docketeer-dev
container_name: docketeer-dev
build:
dockerfile: dockerfile-dev
dockerfile: dockerfile.dev
ports:
- 4000:4000
volumes:
Expand All @@ -92,4 +92,4 @@ services:
command: npm run dev

volumes:
node_modules:
node_modules:
39 changes: 7 additions & 32 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@ services:
image: docketeerxi/postgres
restart: always
ports:
- '${POSTGRES_PORT}:5432'
- '5432:5432'
volumes:
- ./imageConfigs/postgres/docketeerdb:/var/lib/postgresql/data/

environment:
POSTGRES_DB: ${POSTGRES_NAME}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASS}

# networks:
# - my-network
POSTGRES_DB: 'docketeer-db'
POSTGRES_USER: 'postgres'
POSTGRES_PASSWORD: 'postgres'

cadvisor:
image: gcr.io/cadvisor/cadvisor:v0.47.1
Expand All @@ -34,9 +31,6 @@ services:
org_prometheus_starter: 'true'
org_prometheus_starter_path: '/metrics'

# networks:
# - my-network

node-exporter:
image: docketeerxi/nodeex
container_name: node-exporter
Expand All @@ -51,8 +45,6 @@ services:
- /:/rootfs:ro
depends_on:
- db
# networks:
# - my-network

prometheus:
image: docketeerxi/prometheus
Expand All @@ -67,8 +59,9 @@ services:
org_prometheus_starter: 'true'
org_prometheus_starter_port: '9090'
org_prometheus_starter_path: '/metrics'
# networks:
# - my-network

volumes:
- ./imageConfigs/prometheus/promData:/prometheus

grafana:
image: grafana/grafana:latest
Expand All @@ -86,9 +79,6 @@ services:
- ./imageConfigs/grafana/grafana.ini:/etc/grafana/grafana.ini
- ./imageConfigs/grafana/plugins:/var/lib/grafana/plugins

# networks:
# - my-network

depends_on:
- prometheus

Expand All @@ -97,20 +87,5 @@ services:
container_name: docketeer
ports:
- 4000:4000
- 3000:3000
volumes:
- /var/run/docker.sock:/var/run/docker.sock
command: npm run dev
# networks:
# - my-network
# depends_on:
# - grafana

# networks:
# my-network:
# driver: bridge
# driver_opts:
# com.docker.network.bridge.name: my-bridge
# com.docker.network.bridge.enable_icc: "true"
# subnet: "172.16.238.0/24"
# gateway: "172.16.238.1"
14 changes: 5 additions & 9 deletions dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ FROM node
# Set the working directory to /app
WORKDIR /app

COPY package*.json ./

# Run npm install to install app dependencies
RUN npm install

# Set the PATH env variable
# ENV PATH="/usr/local/bin:${PATH}"
# COPY /usr/local/bin/docker /usr/local/bin/docker
Expand All @@ -16,15 +11,16 @@ RUN curl -fsSLO https://download.docker.com/linux/static/stable/x86_64/docker-${
&& tar xzvf docker-${DOCKERVERSION}.tgz --strip 1 -C /usr/local/bin docker/docker \
&& rm docker-${DOCKERVERSION}.tgz

COPY package*.json ./

# Run npm install to install app dependencies
RUN npm install

# Copy the current directory contents into the container at /app
COPY . .

# Make port 4000 available to the world outside this container
EXPOSE 4000
# EXPOSE 3000

# Start the app
CMD ["npm", "start"]



14 changes: 5 additions & 9 deletions dockerfile-dev → dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ FROM node
# Set the working directory to /app
WORKDIR /app

COPY package*.json ./

# Run npm install to install app dependencies
RUN npm install

# Set the PATH env variable
# ENV PATH="/usr/local/bin:${PATH}"
# COPY /usr/local/bin/docker /usr/local/bin/docker
Expand All @@ -17,14 +12,15 @@ RUN curl -fsSLO https://download.docker.com/linux/static/stable/x86_64/docker-${
&& tar xzvf docker-${DOCKERVERSION}.tgz --strip 1 -C /usr/local/bin docker/docker \
&& rm docker-${DOCKERVERSION}.tgz

COPY package*.json ./

# Run npm install to install app dependencies
RUN npm install

# Copy the current directory contents into the container at /app
COPY . .

# Make port 4000 available to the world outside this container
EXPOSE 4000
# EXPOSE 3000

# Start the app
# CMD ["npm", "run", "dev"]
# attempt to hot load (though not hot module reloading)
# CMD ["nodemon", "--watch", "/usr/src/app", "--exec", "ts-node", "/usr/src/renderer/index.tsx"]
Binary file modified imageConfigs/grafana/data/grafana.db
Binary file not shown.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"@types/cookie-parser": "^1.4.3",
"@types/cors": "^2.8.13",
"@types/jest": "^29.2.3",
"@types/jsonwebtoken": "^9.0.1",
"@types/node": "^18.11.18",
"@types/nodemailer": "^6.4.7",
"@types/os-utils": "^0.0.1",
Expand Down Expand Up @@ -88,6 +89,7 @@
"jest": "^29.3.1",
"jest-environment-jsdom": "^29.2.1",
"jest-fetch-mock": "^3.0.3",
"jsonwebtoken": "^9.0.0",
"node-fetch": "^3.2.10",
"nodemailer": "^6.8.0",
"nodemon": "^2.0.20",
Expand Down
4 changes: 3 additions & 1 deletion server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import express, { Request, Response } from 'express';
import { ServerError, GlobalErrorObject } from '../types';
import cors from 'cors';
import { exec } from 'child_process';
// import cookieParser from 'cookie-parser'; // for when cookies get implemented
import cookieParser from 'cookie-parser'; // for when cookies get implemented

const app = express();

// allow requests from other domains
app.use(cors());

app.use(cookieParser());

// run commands in an exec (terminal instance); restarts containers running from the docketeerx/docketeer image using their ID
exec(
'docker container ls -a --format "table {{.ID}}\t{{.Names}}" | grep docketeerx/docketeer | cut -d" " -f1 | cut -f1 | xargs -I{} docker container restart -t 0 {}',
Expand Down
15 changes: 3 additions & 12 deletions server/controllers/bcryptController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { BcryptController } from '../../types';
* @description A controller to handle hashing of passwords and cookies
*/
const bcryptController: BcryptController = {

hashPassword: (req: Request, res: Response, next: NextFunction): void => {
const { password }: { password: string } = req.body;
const saltRounds = 10;
Expand All @@ -29,16 +28,8 @@ const bcryptController: BcryptController = {
});
});
},

hashNewPassword: (
req: Request,
res: Response,
next: NextFunction
): void => {
// if there is an error property on res.locals, return next(). i.e., incorrect password entered
if (res.locals.error) {
return next();
}

hashNewPassword: (req: Request, res: Response, next: NextFunction): void => {
// else bCrypt the new password and move to next middleware
const { newPassword }: { newPassword: string } = req.body;
const saltRounds = 10;
Expand Down Expand Up @@ -90,4 +81,4 @@ const bcryptController: BcryptController = {
},
};

export default bcryptController;
export default bcryptController;
52 changes: 44 additions & 8 deletions server/controllers/commandController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import { Request, Response, NextFunction } from 'express';
import {
CommandController,
LogObject,
composeStacksDockerObject
composeStacksDockerObject,
} from '../../types';
import { exec } from 'child_process';
import jwt from 'jsonwebtoken';
import { JWT_SECRET } from '../../config.js';
const secret = JWT_SECRET;

/**
* Parse all the stdout output into array to manipulate data properly.
Expand All @@ -31,7 +34,8 @@ const convert = (stdout: string): string[][] => {
*
* @param {string} containerId
* @returns {object} optionsObj
*/
*/

const makeArrayOfObjects = (
string: string,
containerName: string
Expand All @@ -51,19 +55,23 @@ const makeArrayOfObjects = (
const logArray = element.split(' ');

// extract timestamp from logArray
let timeStamp: string | undefined = logArray.find(el => el.endsWith('Z'));
let timeStamp: string | undefined = logArray.find((el) =>
el.endsWith('Z')
);

// if there is a timestamp, parse it (if statement isn't really neccessary, but TS complains)
if (timeStamp) {
timeStamp = timeStamp.replace(/t(s)?=/, '');

// parse GMT string to be readable local date and time
// this is hardcoded to EST, docker containers are set to UTC and have no way to knowing what your local time is
obj.timeStamp = new Date(timeStamp).toLocaleString('en-US', { timeZone: 'America/New_York' });
obj.timeStamp = new Date(timeStamp).toLocaleString('en-US', {
timeZone: 'America/New_York',
});
}

// parse remaining array to create readable message
let logMsg: string = logArray.filter(el => !el.endsWith('Z')).join(' ');
let logMsg: string = logArray.filter((el) => !el.endsWith('Z')).join(' ');

// messages with duplicate time&date have form: '<Time/Date> [num/notice] actual msg'
const closingIndex: number = logMsg.indexOf(']');
Expand Down Expand Up @@ -156,6 +164,34 @@ const convertArrToObj = (
* @description runs terminal commands through execs to interact with our containers, images, volumes, and networks
*/
const commandController: CommandController = {
checkAdmin: (req, res, next) => {
const token = req.cookies.admin || null;

if (token) {
jwt.verify(token, secret, (error, decoded) => {
if (error || decoded.verifiedRole !== 'system admin') {
return next({
log: 'Unauthorized access -- invalid permissions',
status: 401,
message: {
err: 'Unauthorized access --invalid permissions',
error,
},
});
}
return next();
});
} else {
return next({
log: 'Unauthorized access -- not logged in',
status: 401,
message: {
err: 'Unauthorized access -- not logged in',
},
});
}
},

getContainers: async (
req: Request,
res: Response,
Expand Down Expand Up @@ -316,7 +352,7 @@ const commandController: CommandController = {
if (error) {
console.log(
`${error.message}` +
'\nPlease stop running container first then remove.'
'\nPlease stop running container first then remove.'
);
return next(error);
}
Expand Down Expand Up @@ -442,7 +478,6 @@ const commandController: CommandController = {
res: Response,
next: NextFunction
): Promise<void> => {

// const nativeYmlFilenames: Set<string> = new Set([
// 'docker-compose.yml',
// 'docker-compose.yaml',
Expand Down Expand Up @@ -579,7 +614,8 @@ const commandController: CommandController = {
for (let i = 0; i < optionsObj.containerNames.length; i++) {
// build inputCommandString to get logs from command line
let inputCommandString = `docker logs ${optionsObj.containerNames[i]} -t `;
if (optionsObj.since) inputCommandString += `--since ${optionsObj.since} `;
if (optionsObj.since)
inputCommandString += `--since ${optionsObj.since} `;

exec(
inputCommandString,
Expand Down
Loading

0 comments on commit 4b19ed4

Please sign in to comment.