From 2155732d1414e451b4b5fc95514e50f51871bb1b Mon Sep 17 00:00:00 2001 From: subnub Date: Fri, 15 May 2020 14:21:36 -0400 Subject: [PATCH] added webUI for entering encryption password --- backend/key/getKey.ts | 3 +- backend/key/getWebUIKey.ts | 53 +++++++++++++++++++++++++ package.json | 3 +- tsconfig.json | 4 +- webUI.config.js | 37 ++++++++++++++++++ webUI/index.html | 37 ++++++++++++++++++ webUI/src/index.js | 28 ++++++++++++++ webUI/src/styles.css | 79 ++++++++++++++++++++++++++++++++++++++ 8 files changed, 241 insertions(+), 3 deletions(-) create mode 100644 backend/key/getWebUIKey.ts create mode 100644 webUI.config.js create mode 100644 webUI/index.html create mode 100644 webUI/src/index.js create mode 100644 webUI/src/styles.css diff --git a/backend/key/getKey.ts b/backend/key/getKey.ts index deab46d..ddef6fd 100644 --- a/backend/key/getKey.ts +++ b/backend/key/getKey.ts @@ -1,6 +1,7 @@ const prompt = require('password-prompt') import env from "../enviroment/env"; import crypto from "crypto"; +import getWebUIKey from "./getWebUIKey"; const getKey = async() => { @@ -13,7 +14,7 @@ const getKey = async() => { } else if (process.env.NODE_ENV === "production") { - let password: string = await prompt("Enter Server Encryption Password: ", {method: "hide"}); + let password = await getWebUIKey(); password = crypto.createHash("md5").update(password).digest("hex"); diff --git a/backend/key/getWebUIKey.ts b/backend/key/getWebUIKey.ts new file mode 100644 index 0000000..83bd914 --- /dev/null +++ b/backend/key/getWebUIKey.ts @@ -0,0 +1,53 @@ +import express, {Request, Response} from "express"; +import http from "http"; +import path from "path"; +import bodyParser from "body-parser"; +const app = express(); + +const getWebUIKey = () => { + + const publicPath = path.join(__dirname, "..", "..", "webUI"); + + + return new Promise((resolve, reject) => { + + app.use(express.static(publicPath)); + app.use(express.json()); + app.use(bodyParser.json({limit: "50mb"})); + app.use(bodyParser.urlencoded({limit: "50mb", extended: true, parameterLimit:50000})) + + app.post("/submit", (req: Request, res: Response) => { + + const password = req.body.password; + + if (password && password.length > 0) { + + console.log("Got WebUI key"); + res.send(); + server.close(); + resolve(password); + } + }) + + app.get("*", (req: Request, res: Response) => { + + res.sendFile(path.join(publicPath, "index.html")); + + }) + + const port = process.env.HTTP_PORT || process.env.PORT; + const url = process.env.URL; + + const server = http.createServer(app) as any; + + server.listen(port, url, () => { + + const fullURL = `${url!}:${port!}`; + + console.log("\nPlease Navigate To", fullURL, "To Enter Encryption Password\n") + }); + + }) +} + +export default getWebUIKey; \ No newline at end of file diff --git a/package.json b/package.json index e1e0c1e..db48b65 100755 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ }, "scripts": { "server": "live-server public/", - "build": "tsc && webpack -p --env production", + "build": "tsc && webpack -p --env production && webpack --config webUI.config.js", + "build:webUI": "webpack --config webUI.config.js", "build:dev": "tsc && webpack --env development", "dev-server": "webpack-dev-server", "test": "NODE_ENV=test env-cmd -f ./config/test.env jest --config=jest.config.json --watchAll --runInBand", diff --git a/tsconfig.json b/tsconfig.json index 5d5c7f0..33aa9f1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -69,6 +69,8 @@ "public", "node_modules", "webpack.config.js", - "dist" + "dist", + "webUI", + "webUI.config.js" ] } diff --git a/webUI.config.js b/webUI.config.js new file mode 100644 index 0000000..1be3a22 --- /dev/null +++ b/webUI.config.js @@ -0,0 +1,37 @@ +const path = require('path'); +const webpack = require("webpack") +const MiniCssExtractPlugin = require('mini-css-extract-plugin'); + +module.exports = (env) => { + + if (env === "test") { + + console.log("Loading test env variables") + require("dotenv").config({path: ".env.test"}) + + } else if (env === "development") { + + console.log("Loading development env variables") + require("dotenv").config({path: ".env.development"}) + + } else { + + console.log("Loading production env variables") + require("dotenv").config({path: ".env.production"}); + } + + return { + entry: './webUI/src/index.js', + output: { + path: path.resolve(__dirname, 'webUI', "dist"), + filename: 'bundle.js' + }, + plugins: [ + new webpack.DefinePlugin({ + "process.env.PORT": JSON.stringify(process.env.PORT), + "process.env.REMOTE_URL": JSON.stringify(process.env.REMOTE_URL), + "process.env.ENABLE_VIDEO_TRANSCODING": JSON.stringify(process.env.ENABLE_VIDEO_TRANSCODING), + "process.env.DISABLE_STORAGE": JSON.stringify(process.env.DISABLE_STORAGE) + }), + ], +}}; \ No newline at end of file diff --git a/webUI/index.html b/webUI/index.html new file mode 100644 index 0000000..adb46ca --- /dev/null +++ b/webUI/index.html @@ -0,0 +1,37 @@ + + + + + + + + MyDrive + + + + + + + + + + + +
+ +
+ +

Enter Encryption Password

+
+ + +
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/webUI/src/index.js b/webUI/src/index.js new file mode 100644 index 0000000..46f5f29 --- /dev/null +++ b/webUI/src/index.js @@ -0,0 +1,28 @@ +console.log("Hello, there", process.env.PORT); +import axios from "axios"; + +const formElement = document.getElementById("form-submit") +const inputElement = document.getElementById("input-password"); +const mainDiv = document.getElementById("main-div") + +formElement.addEventListener("submit", async (e) => { + + e.preventDefault(); + + const fullURL = process.env.REMOTE_URL; + + const value = inputElement.value; + + const data = {password: value} + + axios.post(fullURL + "/submit", data).then(() => { + + inputElement.value = ""; + mainDiv.style.display = "none"; + + }).catch((err) => { + console.log("Error", err); + }); + + +}) \ No newline at end of file diff --git a/webUI/src/styles.css b/webUI/src/styles.css new file mode 100644 index 0000000..c07cad8 --- /dev/null +++ b/webUI/src/styles.css @@ -0,0 +1,79 @@ +* { + margin: 0; + padding: 0; +} + +html { + font-size: 62.5%; +} + +#main-div { + height: 100vh; + width: 100vw; + /* background: blue; */ + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; +} + +#box-div { + height: 30%; + width: 90%; + /* background: purple; */ + display: flex; + flex-direction: column; + align-items: center; + justify-content: space-around; + border: .5px; + border-style: groove; +} + +@media (min-width:600px) { + #box-div { + + height: 30%; + width: 400px; + /* background: purple; */ + display: flex; + flex-direction: column; + align-items: center; + justify-content: space-around; + border: .5px; + border-style: groove; + } + } + +#input-password { + border: 1px solid #cacccd; + border-radius: 2px; + height: 43px; + font-size: 1.8rem; + font-weight: 300; + padding: 1.2rem; + margin: 0 0 1.2rem 0; + width: -webkit-fill-available; + margin-top: -17px; +} + +#submit-button { + color: #fff; + background: #3c85ed; + font-size: 1.8rem; + padding: 1.2rem; + border: none; + display: inline-block; + text-decoration: none; + line-height: 1; + border-radius: 2px; +} + +#title { + margin: 0 0 3rem 0; + line-height: 1; + font-family: Arial,Helvetica,sans-serif; + font-weight: 500; + color: #666; + font-size: 2em; + margin-top: 24px; +} \ No newline at end of file