From a9afbcb7c1aa9c63f96fd5d0abd2c45d3155b77c Mon Sep 17 00:00:00 2001 From: Younes Barrad Date: Mon, 26 Sep 2022 21:24:28 +0100 Subject: [PATCH] added Password Protect input --- .github/workflows/release.yml | 26 ++--------------- Dockerfile | 6 ++-- README.md | 7 +++++ jsconfig.json | 8 ++++-- nuxt.config.js | 8 +++--- pages/index.vue | 47 +++++++++++++++++++++++++++++-- server-middleware/website-shot.js | 19 +++++++++++-- 7 files changed, 83 insertions(+), 38 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 108948d..b3b6337 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,8 +8,6 @@ on: jobs: docker: runs-on: ubuntu-latest - needs: - - build steps: - name: "⛏️ Set up QEMU" @@ -29,27 +27,8 @@ jobs: with: push: true tags: flowko1/website-shot:latest - - build: - name: Build application - runs-on: ubuntu-latest - steps: - - name: "☁️ checkout repository" - uses: actions/checkout@v3 - - - name: "🔧 setup node" - uses: actions/setup-node@v2.1.5 - with: - node-version: 16 - - - name: "🔧 install npm@latest" - run: npm i -g npm@latest - - - name: "📦 install dependencies" - uses: bahmutov/npm-install@v1 - - - name: "🚀 static app" - run: npm run build + cache-from: type=gha, scope=${{ github.workflow }} + cache-to: type=gha, scope=${{ github.workflow }} release: environment: @@ -58,7 +37,6 @@ jobs: name: Semantic release needs: - docker - - build runs-on: ubuntu-latest steps: - name: "☁️ checkout repository" diff --git a/Dockerfile b/Dockerfile index 68ce117..8635201 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,7 +18,9 @@ RUN npm run build EXPOSE 3000 -ENV NUXT_HOST=0.0.0.0 -ENV NUXT_PORT=3000 +ENV NUXT_HOST 0.0.0.0 +ENV NUXT_PORT 3000 +ENV PASSWORD_PROTECT 0 +ENV PASSWORD null CMD [ "npm", "start" ] diff --git a/README.md b/README.md index 829d7d2..462836f 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,13 @@ Website Shot is an open source cross-platform screenshot app, powered by a nodej ```bash docker pull flowko1/website-shot docker run -it -d -p 3000:3000 flowko1/website-shot + +# to enable password protection | to disabled it set PASSWORD_PROTECT to 0 +# default password is admin +docker run -it -d -p 3000:3000 -e PASSWORD_PROTECT=1 -e PASSWORD=yourpassword flowko1/website-shot + +# you'll notice a password field on the homepage, make sure to add the password there as well + ``` # Build Setup diff --git a/jsconfig.json b/jsconfig.json index 29037a6..429871a 100644 --- a/jsconfig.json +++ b/jsconfig.json @@ -6,7 +6,11 @@ "@/*": ["./*"], "~~/*": ["./*"], "@@/*": ["./*"] - } + }, + "jsx": "preserve" + }, + "exclude": ["node_modules", ".nuxt", "dist"], + "vueCompilerOptions": { + "experimentalDisableTemplateSupport": true }, - "exclude": ["node_modules", ".nuxt", "dist"] } diff --git a/nuxt.config.js b/nuxt.config.js index 1fbc096..14b3c8a 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -53,6 +53,10 @@ export default { "@nuxtjs/axios", ], + publicRuntimeConfig: { + passwordEnabled: Boolean(Number(process.env.PASSWORD_PROTECT || 0)), + }, + // Axios module configuration: https://go.nuxtjs.dev/config-axios axios: { // Workaround to avoid enforcing hard-coded localhost:3000: https://github.com/nuxt-community/axios-module/issues/308 @@ -78,8 +82,4 @@ export default { prefetch: true, preconnect: true, }, - - publicRuntimeConfig: { - runningHeroku: process.env.RUNNING_HEROKU, - }, }; diff --git a/pages/index.vue b/pages/index.vue index 0d2cb2d..58473f0 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -3,7 +3,17 @@
+
+
+ +
+ +
+
+
@@ -679,6 +718,7 @@ export default { "Legal", ], disableBtn: true, + password: null, }; }, mounted() {}, @@ -704,6 +744,7 @@ export default { size: [this.params.size], type: selectedType, mimeType, + password: this.password, }) .then(({ base64, filename, success }) => { const blob = new window.Blob([this.convertBase64ToBlob(base64)], { diff --git a/server-middleware/website-shot.js b/server-middleware/website-shot.js index c56b50f..051e173 100644 --- a/server-middleware/website-shot.js +++ b/server-middleware/website-shot.js @@ -13,6 +13,21 @@ app.use(bodyParser.urlencoded({ extended: true })); app.post("/screenshot", async (req, res) => { const params = req.body; + const password = params.password; + + if ( + process.env.PASSWORD_PROTECT && + Boolean(Number(process.env.PASSWORD_PROTECT)) + ) { + if (!password || password !== process.env.PASSWORD) { + res.status(401).send({ + error: "Unauthorized", + success: false, + }); + return; + } + } + const url = params.url ? params.url.toString().trim() : null; const urls = params.urls .filter((url) => { @@ -92,9 +107,7 @@ app.post("/screenshot", async (req, res) => { }, }; - if (process.env.RUNNING_HEROKU == null) { - options.launchOptions.executablePath = "/usr/bin/chromium-browser"; - } + options.launchOptions.executablePath = "/usr/bin/chromium-browser"; const mimeType = params.mimeType;