From 0018ffd465bae6afd96a995f36401f737f59ea3f Mon Sep 17 00:00:00 2001 From: Matteus Date: Sat, 7 Aug 2021 15:47:22 +0200 Subject: [PATCH 01/16] Popup added (#43) --- public/Scripts/Main.js | 4 +++- public/Scripts/Toast.js | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/public/Scripts/Main.js b/public/Scripts/Main.js index 22b4d91..00ba9c0 100644 --- a/public/Scripts/Main.js +++ b/public/Scripts/Main.js @@ -15,4 +15,6 @@ function Copy(text) document.execCommand("copy"); document.body.removeChild(textArea); -} \ No newline at end of file +} + +Notification.requestPermission(); \ No newline at end of file diff --git a/public/Scripts/Toast.js b/public/Scripts/Toast.js index 1def158..523efdf 100644 --- a/public/Scripts/Toast.js +++ b/public/Scripts/Toast.js @@ -21,10 +21,13 @@ function Toast(msg, status, title) $(document).ready(function(){ $('.toast').toast('show'); }); + + new Notification(`DMCD | ${status} | ${title}`, { body: msg, icon: "https://cdn.tolfix.com/images/TX-Small.png" }); + let tempCount = toastCount; document.querySelector(`#toast-button-${toastCount}`).addEventListener("click", (msg) => { document.querySelector(`#toast-${tempCount}`).remove() }) toastCount++ -} \ No newline at end of file +} From 795df53e5089c72c9da6d46565f8bf22a1821aee Mon Sep 17 00:00:00 2001 From: Matteus Date: Sat, 7 Aug 2021 15:55:29 +0200 Subject: [PATCH 02/16] JSDocs for < Server & Config > (#13) --- src/Config.ts | 11 +++++++++++ src/Server.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/Config.ts b/src/Config.ts index 1651c35..3cb0d49 100644 --- a/src/Config.ts +++ b/src/Config.ts @@ -8,6 +8,13 @@ export const DebugMode = process.env.DEBUG === "true" ? true : false; export const MongoDB_URI = process.env.MONGODB_URI ?? "mongodb://localhost/dmcd"; export const PORT = 56251; export const Session_Secret = process.env.SESSION_SECRET ?? undefined; + +/** + * + * @returns {ISMTP} + * @description + * Gives the SMTP configs from database. + */ export const GetSMTPConfig = () => { return new Promise(async (resolve, reject) => { @@ -25,6 +32,10 @@ export const GetSMTPConfig = () => { return resolve(c) }) }; +/** + * @description + * Contains all "general" configs in a map + */ export const ConfigMap = new Map(); export const Dir = ((__dirname.replace("\\build", "")).replace("/build", "")); export const DockerDir = Dir+"/Docker"; diff --git a/src/Server.ts b/src/Server.ts index c803ce7..6abbf28 100644 --- a/src/Server.ts +++ b/src/Server.ts @@ -21,17 +21,38 @@ import SocketHandler from "./Socket/SocketHandler"; import { GenStringBetter } from "./Lib/Generator"; import reCache from "./Setup/reCache"; +/** + * @description + * The express server + */ const server = express(); +/** + * @description + * Connecting to database + */ mongoose.connect(MongoDB_URI, { useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true, }); +/** + * @description + * Mongoose client; + */ const db = mongoose.connection; +/** + * @description + * Load all mongoose events + */ MongodbEvent(db); + +/** + * @description + * Passport local auth + */ Auth(passport); server.use(expressLayout); @@ -94,6 +115,9 @@ server.use((req, res, next) => { const sv = server.listen(PORT, () => log.info(`Server listing on ${ConfigMap.get("http")}://${ConfigMap.get("domain")}${ConfigMap.get("domain") === "localhost" ? ":"+PORT : ""}/`)); const io = (new SocketIo(sv)).io; +/* + * All of the routes gets loaded here + */ new MainRouter(server); new ConfigRouter(server); new CDRouter(server); @@ -105,6 +129,10 @@ if(process.platform === "win32" && !DebugMode) process.exit(1); } +/** + * @description + * Caches everything + */ reCache(); const SOCKET = new SocketHandler(io, db); From 27c900aa8663ecfe6284f1f4e9c6276f686a27a5 Mon Sep 17 00:00:00 2001 From: Matteus Date: Sat, 7 Aug 2021 15:58:22 +0200 Subject: [PATCH 03/16] JSDocs for < SocketHandler > (#13) --- src/Socket/SocketHandler.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/Socket/SocketHandler.ts b/src/Socket/SocketHandler.ts index 907365c..7745bea 100644 --- a/src/Socket/SocketHandler.ts +++ b/src/Socket/SocketHandler.ts @@ -18,6 +18,10 @@ export default class SocketHandler this.db = db; } + /** + * @description + * Checks if the string is a cd + */ private isCD(aString: string): Boolean { if(aString.includes("cd-")) @@ -25,11 +29,19 @@ export default class SocketHandler return false; } + /** + * @description + * Splits a string to get a cd from + */ private getCD(aString: string): string { return (((aString.split("-"))[1])) } + /** + * @description + * Sends a email if that event is enabled. + */ private EmailCD(cd: IDCD, status: Statues | "log" | string, ...content: string[]) { // Are we allowed to send emails for this CD? @@ -61,6 +73,11 @@ export default class SocketHandler } + /** + * @description + * Logs to the database. + * As well emitting it to the socket. + */ private logToDB(type: CDEmitLog | "log", ...msg: any[]): Promise { return new Promise(async (resolve, reject) => { @@ -98,6 +115,11 @@ export default class SocketHandler }) } + /** + * + * @description + * Emits. + */ public emit(event: any, ...args: any[]): void { this.io.emit(event, args); From 9392f64fc2ee0b744cf3ab4cd7a8abb975cd03e5 Mon Sep 17 00:00:00 2001 From: Matteus Date: Sat, 7 Aug 2021 16:03:52 +0200 Subject: [PATCH 04/16] JSDocs on < Interfaces/CD > (#13) --- src/Interfaces/CD.ts | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/Interfaces/CD.ts b/src/Interfaces/CD.ts index 874e28f..84df5d5 100644 --- a/src/Interfaces/CD.ts +++ b/src/Interfaces/CD.ts @@ -1,17 +1,55 @@ import { Document } from "mongoose" +/** + * @description + * ICD but extended with Doucment + */ export interface IDCD extends ICD, Document {}; +/** + * @description + * CD object. + */ export interface ICD { + /** + * The name for the CD + */ name: string; + /** + * Image for CD + */ image: string; + /** + * Env variables for CD + */ env?: Array; + /** + * Ports for cd + */ ports?: Array; + /** + * The webhook endpoint which is linked to this CD + */ webhookUrl: string; + /** + * The current status for this CD + */ status: string; + /** + * The logs for this CD + */ logs: Array; + /** + * If this CD should send emails on notifications + */ email: Boolean; + /** + * What kind of emails should we send when a event happens + */ email_noti: EmailNoti; + /** + * The email which should recieve the notification + */ email_reciever: string; restartPolicy: "always" | "never" | "on_failure" | "unless_stopped"; } @@ -30,6 +68,11 @@ export interface PORTS export interface ICDLog { + /** + * @description + * If someone has read it. + * @deprecated + */ read: Boolean; msg: string; date: Date; From 03788d90cd2593d35e7805a6443973b850aecbec Mon Sep 17 00:00:00 2001 From: Matteus Date: Sat, 7 Aug 2021 16:04:09 +0200 Subject: [PATCH 05/16] JSDocs on < reCache > (#13) --- src/Setup/reCache.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Setup/reCache.ts b/src/Setup/reCache.ts index 9b26592..8e36a41 100644 --- a/src/Setup/reCache.ts +++ b/src/Setup/reCache.ts @@ -4,6 +4,10 @@ import AW from "../Lib/Async"; import log from "../Lib/Logger"; import ConfigModel from "../Models/Config"; +/** + * @description + * Caches general stuff from our database. + */ export default async function reCache() { const [Config, C_Error] = await AW(ConfigModel.find()); From a4c13359f6cf5a0e522314570a64f713548fef2d Mon Sep 17 00:00:00 2001 From: Matteus Date: Sat, 7 Aug 2021 16:15:49 +0200 Subject: [PATCH 06/16] JSDocs for < DockerCompose > (#13) --- src/Docker/DockerCompose.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Docker/DockerCompose.ts b/src/Docker/DockerCompose.ts index 6019952..e76cf7a 100644 --- a/src/Docker/DockerCompose.ts +++ b/src/Docker/DockerCompose.ts @@ -1,5 +1,4 @@ import { stripIndent } from "common-tags" -import { ICD } from "../Interfaces/CD"; import docker from "docker-compose"; import log from "../Lib/Logger"; import AW from "../Lib/Async"; @@ -8,6 +7,10 @@ import SOCKET from "../Server"; import { getCDSocketActive, getCDSocketFail } from "../Lib/CDSocket"; import { DebugMode } from "../Config"; +/** + * @description + * ----> "docker-compose up -d" <---- + */ export function DockerCompose(dir: string, cdName?: string): Promise { return new Promise(async (resolve, reject) => { @@ -33,6 +36,11 @@ export function DockerCompose(dir: string, cdName?: string): Promise }); } +/** + * + * @description + * Gives a string formated for a `docker-compose.yml` file. + */ export function CreateDockerCompose(options: ICreateDockerCompose): string { From ae9f9938dfd622a5aba8a769961f25a06f00a205 Mon Sep 17 00:00:00 2001 From: Matteus Date: Sat, 7 Aug 2021 16:15:58 +0200 Subject: [PATCH 07/16] JSDocs for < DockerDown > (#13) --- src/Docker/DockerDown.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Docker/DockerDown.ts b/src/Docker/DockerDown.ts index f0e5e7d..4a9a43e 100644 --- a/src/Docker/DockerDown.ts +++ b/src/Docker/DockerDown.ts @@ -2,6 +2,10 @@ import docker from "docker-compose"; import AW from "../Lib/Async"; import log from "../Lib/Logger"; +/** + * @description + * Removes a container + */ export default function DockerRemove(dir: string): Promise { return new Promise(async (resolve, reject) => { From 011831d74ecd5639f6d1f6e6410d3d10b5e886ee Mon Sep 17 00:00:00 2001 From: Matteus Date: Sat, 7 Aug 2021 16:16:06 +0200 Subject: [PATCH 08/16] JSDocs for < Pull > (#13) --- src/Docker/Pull.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Docker/Pull.ts b/src/Docker/Pull.ts index 22f3244..e42ef92 100644 --- a/src/Docker/Pull.ts +++ b/src/Docker/Pull.ts @@ -4,6 +4,10 @@ import { getCDSocketLogs } from "../Lib/CDSocket"; import log from "../Lib/Logger"; import SOCKET from "../Server"; +/** + * @description + * Pulls a image from a CD + */ export default function PullImage(dir: string, cdName?: string): Promise { return new Promise(async (resolve, reject) => { From 638b0549905567a0ca5c828b3c159f87eccb86ce Mon Sep 17 00:00:00 2001 From: Matteus Date: Sat, 7 Aug 2021 16:16:12 +0200 Subject: [PATCH 09/16] JSDocs for < Docker/Setup > (#13) --- src/Docker/Setup.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Docker/Setup.ts b/src/Docker/Setup.ts index 4f05048..7e07ff3 100644 --- a/src/Docker/Setup.ts +++ b/src/Docker/Setup.ts @@ -6,8 +6,11 @@ import { CreateDockerCompose, DockerCompose } from "./DockerCompose"; import AW from "../Lib/Async"; import PullImage from "./Pull"; import { getCDSocketActive, getCDSocketBuild, getCDSocketFail } from "../Lib/CDSocket";import SOCKET from "../Server"; -; +/** + * @description + * Setups a CD + */ export default function SetupDocker(options: ISetupDocker, mong: any): Promise { return new Promise(async (resolve, reject) => { From cfeb70ff6154f3e05194de729f8721c815d1deb8 Mon Sep 17 00:00:00 2001 From: Matteus Date: Sat, 7 Aug 2021 16:16:22 +0200 Subject: [PATCH 10/16] JSDocs for < ENV > (#13) --- src/Interfaces/ENV.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Interfaces/ENV.ts b/src/Interfaces/ENV.ts index e15e0af..aea09f5 100644 --- a/src/Interfaces/ENV.ts +++ b/src/Interfaces/ENV.ts @@ -1,4 +1,9 @@ -export interface IENV { +/** + * @description + * All ENV that is being used. + */ +export interface IENV +{ SESSION_SECRET: string; TITLE: string; MONGODB_URI: string; From d473596df662bdffd88f0003a1fbeb0a994b9293 Mon Sep 17 00:00:00 2001 From: Matteus Date: Sat, 7 Aug 2021 16:16:31 +0200 Subject: [PATCH 11/16] JSDocs for < Async > (#13) --- src/Lib/Async.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Lib/Async.ts b/src/Lib/Async.ts index ba97a4b..63f9442 100644 --- a/src/Lib/Async.ts +++ b/src/Lib/Async.ts @@ -1,4 +1,11 @@ -// Promise

extends P ? P extends P ? any : Promise

: any +/** + * @description + * Used for async code, to skip `.catch` or `try {...}` + * @async + * ```ts + * const [Returns, ReturnsError] = await AW(Promise.resolve("hello")); + * ``` + */ export default async function AW

(data: Promise

extends P ? P extends P ? any : Promise

: any) : Promise<[P | null, PromiseRejectedResult | null]> From b4493ee127f5f82c610ec86c94193815c6c5f132 Mon Sep 17 00:00:00 2001 From: Matteus Date: Sat, 7 Aug 2021 16:16:40 +0200 Subject: [PATCH 12/16] JSDocs for < EditEnv > (#13) --- src/Lib/EditEnv.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Lib/EditEnv.ts b/src/Lib/EditEnv.ts index ab6d317..cdd4e0e 100644 --- a/src/Lib/EditEnv.ts +++ b/src/Lib/EditEnv.ts @@ -3,6 +3,10 @@ import { Dir } from "../Config"; import { IENV } from "../Interfaces/ENV"; import { env_seperator } from "./Seperator"; +/** + * @description + * Edits the .env file on the machine. + */ export function EditEnvFile(envOptions: Partial) { // Get our file and parse through each. From fad8fd79fb97863b8fa1b4b1aa9f5ef42dc14703 Mon Sep 17 00:00:00 2001 From: Matteus Date: Sat, 7 Aug 2021 16:16:46 +0200 Subject: [PATCH 13/16] JSDocs for < Email > (#13) --- src/Lib/Email.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Lib/Email.ts b/src/Lib/Email.ts index 38abef5..ba640d9 100644 --- a/src/Lib/Email.ts +++ b/src/Lib/Email.ts @@ -3,6 +3,10 @@ import mail from "nodemailer"; import AW from "./Async"; import { GetSMTPConfig } from "../Config"; +/** + * @description + * Send a email + */ export async function SendEmail( reciever: string, subject: string, From 7eb77e389fd47fdc598376219b02b0e43dcbdcb2 Mon Sep 17 00:00:00 2001 From: Matteus Date: Sat, 7 Aug 2021 16:17:03 +0200 Subject: [PATCH 14/16] JSDocs for < Seperator#env_seperator > (#13) --- src/Lib/Seperator.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Lib/Seperator.ts b/src/Lib/Seperator.ts index 0599216..c74adc3 100644 --- a/src/Lib/Seperator.ts +++ b/src/Lib/Seperator.ts @@ -1,3 +1,14 @@ +/** + * @description + * Seperates a .env value + * + * ``` + * ENV=VALUE => { + * value: VALUE, + * name: ENV + * } + * ``` + */ export function env_seperator (env: string): { value: Value, name: Key } From 9c4fb4523e0a44a79b7cff1886c845c2d42aa294 Mon Sep 17 00:00:00 2001 From: Matteus Date: Sat, 7 Aug 2021 16:17:12 +0200 Subject: [PATCH 15/16] JSDocs for < EnsureAuth > (#13) --- src/Middlewares/EnsureAuth.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Middlewares/EnsureAuth.ts b/src/Middlewares/EnsureAuth.ts index 1377340..5fc63a2 100644 --- a/src/Middlewares/EnsureAuth.ts +++ b/src/Middlewares/EnsureAuth.ts @@ -1,5 +1,9 @@ import { Request, Response, NextFunction } from "express" +/** + * @description + * Ensures a user is auth. + */ export default function EnsureAuth(req: Request, res: Response, next: NextFunction) { if (req.isAuthenticated()) { From b1207513a258024116330b2a8f1fa98c73aa0eb3 Mon Sep 17 00:00:00 2001 From: Matteus Date: Sat, 7 Aug 2021 16:17:26 +0200 Subject: [PATCH 16/16] Small changes --- src/Passport/Auth.ts | 10 ++++++---- src/Routers/CD.ts | 1 - src/Routers/Main.ts | 1 - src/Routers/Webhook.ts | 3 +-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Passport/Auth.ts b/src/Passport/Auth.ts index 41a18d2..59a2170 100644 --- a/src/Passport/Auth.ts +++ b/src/Passport/Auth.ts @@ -6,13 +6,15 @@ import { PassportStatic } from 'passport'; // Load User model import User from '../Models/User'; -export default function Auth(passport: PassportStatic) { +export default function Auth(passport: PassportStatic) +{ passport.use( new LocalStrategy({ usernameField: 'username' }, (username, password, done) => { User.findOne({ username: username, - }).then((user) => { + }).then((user) => + { if (!user) { return done(null, false, { message: 'That username is not registered' }); } @@ -28,8 +30,8 @@ export default function Auth(passport: PassportStatic) { return done(null, user); }); }); - }) -); + }) + ); passport.serializeUser((user, done) => { //@ts-ignore diff --git a/src/Routers/CD.ts b/src/Routers/CD.ts index aaa7076..2943339 100644 --- a/src/Routers/CD.ts +++ b/src/Routers/CD.ts @@ -1,6 +1,5 @@ import { Router, Application } from "express"; import EnsureAuth from "../Middlewares/EnsureAuth"; -import { Server } from "socket.io"; import fs from "fs"; import { ENV, ICD, IDCD, PORTS } from "../Interfaces/CD"; import AW from "../Lib/Async"; diff --git a/src/Routers/Main.ts b/src/Routers/Main.ts index 5009554..af7cccc 100644 --- a/src/Routers/Main.ts +++ b/src/Routers/Main.ts @@ -1,7 +1,6 @@ import { Router, Application } from "express"; import passport from "passport"; import EnsureAuth from "../Middlewares/EnsureAuth"; -import { Server } from "socket.io"; import AW from "../Lib/Async"; import CDModel from "../Models/CD"; diff --git a/src/Routers/Webhook.ts b/src/Routers/Webhook.ts index f67fb17..26f06ef 100644 --- a/src/Routers/Webhook.ts +++ b/src/Routers/Webhook.ts @@ -1,11 +1,10 @@ import { Router, Application } from "express"; -import { Server } from "socket.io"; import { DockerDir } from "../Config"; import { DockerCompose } from "../Docker/DockerCompose"; import PullImage from "../Docker/Pull"; import { ICD } from "../Interfaces/CD"; import AW from "../Lib/Async"; -import { getCDSocketBuild, getCDSocketFail, getCDSocketLogs } from "../Lib/CDSocket"; +import { getCDSocketBuild, getCDSocketLogs } from "../Lib/CDSocket"; import log from "../Lib/Logger"; import CDModel from "../Models/CD"; import SOCKET from "../Server";