diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..15413b1 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +.github +api +.gitignore +.dockerignore +Dockerfile* +node_modules diff --git a/.github/workflows/build_images.yml b/.github/workflows/build_images.yml new file mode 100644 index 0000000..970874f --- /dev/null +++ b/.github/workflows/build_images.yml @@ -0,0 +1,49 @@ +--- +name: 'build images' +# See https://itnext.io/building-multi-cpu-architecture-docker-images-for-arm-and-x86-3-building-in-github-action-ci-a382feab5af9 + +on: + push: + branches: + - master + workflow_dispatch: + +jobs: + build-docker-images: + name: Build Docker Images + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Login to GitHub Package Registry + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + - name: Build & Push Docker image for web UI + run: docker buildx build -t ghcr.io/${{ github.repository_owner }}/linkwarden:${GITHUB_SHA} -f ./Dockerfile.prod --push --platform=linux/arm64,linux/amd64 . + - name: Build & Push Docker image for API + run: docker buildx build -t ghcr.io/${{ github.repository_owner }}/linkwarden-api:${GITHUB_SHA} -f ./api/Dockerfile --push --platform=linux/arm64,linux/amd64 ./api + - name: Login to Docker Hub + env: + DH_TOKEN: ${{ secrets.DOCKER_HUB_PASSWORD }} + run: docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} -p ${DH_TOKEN} + - name: Re-tag & Push Docker Image to Docker Hub Web + run: | + # make config.json avaiable to regclient in docker container + chmod +r $HOME/.docker/config.json + # Run regclient in docker image + docker container run --rm --net host \ + -v regctl-conf:/home/appuser/.regctl/ \ + -v $HOME/.docker/config.json:/home/appuser/.docker/config.json \ + regclient/regctl:v0.3.9 image copy ghcr.io/${{ github.repository_owner }}/linkwarden:${GITHUB_SHA} docker.io/${{ secrets.DOCKER_HUB_USERNAME }}/linkwarden:latest + - name: Re-tag & Push Docker Image to Docker Hub API + run: | + # make config.json avaiable to regclient in docker container + chmod +r $HOME/.docker/config.json + # Run regclient in docker image + docker container run --rm --net host \ + -v regctl-conf:/home/appuser/.regctl/ \ + -v $HOME/.docker/config.json:/home/appuser/.docker/config.json \ + regclient/regctl:v0.3.9 image copy ghcr.io/${{ github.repository_owner }}/linkwarden-api:${GITHUB_SHA} docker.io/${{ secrets.DOCKER_HUB_USERNAME }}/linkwarden-api:latest diff --git a/.gitignore b/.gitignore index e351ff4..af27d6f 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,11 @@ npm-debug.log* yarn-debug.log* yarn-error.log* +media +api/.ash_history +api/.config +api/.cache/ +api/.pki/ api/node_modules api/..pnp api/.pnp.js @@ -24,4 +29,4 @@ api/.env.test.local api/.env.production.local api/npm-debug.log* api/yarn-debug.log* -api/yarn-error.log* \ No newline at end of file +api/yarn-error.log* diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2884faa --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +# Development image for React app +FROM node:18-alpine + +WORKDIR /home/node + +VOLUME /home/node/node_modules + +COPY package*.json . + +RUN npm i -g npm@latest \ + && npm ci --legacy-peer-deps \ No newline at end of file diff --git a/Dockerfile.prod b/Dockerfile.prod new file mode 100644 index 0000000..ef5693b --- /dev/null +++ b/Dockerfile.prod @@ -0,0 +1,16 @@ +# Production image for React app +FROM node:18-alpine AS builder + +WORKDIR /home/node + +VOLUME /home/node/node_modules + +COPY . . + +RUN npm i -g npm@latest \ + && npm ci --legacy-peer-deps \ + && npm run build + + +FROM nginx:alpine +COPY --from=builder /home/node/build /usr/share/nginx/html diff --git a/api/Dockerfile b/api/Dockerfile new file mode 100644 index 0000000..e1acea5 --- /dev/null +++ b/api/Dockerfile @@ -0,0 +1,29 @@ +# Production image for api +# See https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#running-on-alpine + +FROM node:18-alpine +ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \ + PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser + +WORKDIR /home/node +VOLUME /home/node/node_modules + +RUN apk add --no-cache \ + chromium \ + nss \ + freetype \ + harfbuzz \ + ca-certificates \ + ttf-freefont + +COPY . . +RUN npm ci && mkdir -p /media + +# The collowing command fails when attempting to chown the node_modules directory. +# Running it in its own layer allows it to modify the volume. +RUN chown -R node:node /home/node /media + +USER node + +EXPOSE 5000 +CMD node server.js diff --git a/api/config.js b/api/config.js new file mode 100644 index 0000000..1ac18cd --- /dev/null +++ b/api/config.js @@ -0,0 +1,9 @@ +const fs = require("fs"); + +module.exports.port = process.env.PORT || 5000; +module.exports.URI = process.env.MONGODB_URI || 'mongodb://localhost:27017'; +module.exports.database = process.env.DB_NAME || 'sample_db'; +module.exports.collection = process.env.COLLECTION_NAME || 'list'; +const storageLocation = process.env.STORAGE_LOCATION || '/media'; +module.exports.screenshotDirectory = storageLocation + '/screenshots'; +module.exports.pdfDirectory = storageLocation + '/pdfs'; diff --git a/api/modules/getData.js b/api/modules/getData.js index 3626753..dcb6567 100644 --- a/api/modules/getData.js +++ b/api/modules/getData.js @@ -1,23 +1,13 @@ const puppeteer = require("puppeteer"); const { PuppeteerBlocker } = require("@cliqz/adblocker-puppeteer"); const fetch = require("cross-fetch"); -const config = require("../../src/config.js"); -const fs = require("fs"); - -const screenshotDirectory = - config.API.STORAGE_LOCATION + "/LinkWarden/screenshot's/"; -const pdfDirectory = config.API.STORAGE_LOCATION + "/LinkWarden/pdf's/"; - -if (!fs.existsSync(screenshotDirectory)) { - fs.mkdirSync(screenshotDirectory, { recursive: true }); -} - -if (!fs.existsSync(pdfDirectory)) { - fs.mkdirSync(pdfDirectory, { recursive: true }); -} +const { screenshotDirectory, pdfDirectory } = require("../config.js"); module.exports = async (link, id) => { - const browser = await puppeteer.launch(); + const browser = await puppeteer.launch({ + args: ['--no-sandbox'], + timeout: 10000, + }); const page = await browser.newPage(); await PuppeteerBlocker.fromPrebuiltAdsAndTracking(fetch).then((blocker) => { @@ -27,10 +17,10 @@ module.exports = async (link, id) => { await page.goto(link, { waitUntil: "load", timeout: 0 }); await page.screenshot({ - path: screenshotDirectory + id + ".png", + path: screenshotDirectory + "/" + id + ".png", fullPage: true, }); - await page.pdf({ path: pdfDirectory + id + ".pdf", format: "a4" }); + await page.pdf({ path: pdfDirectory + "/" + id + ".pdf", format: "a4" }); await browser.close(); }; diff --git a/api/package-lock.json b/api/package-lock.json index b119dd1..edbea55 100644 --- a/api/package-lock.json +++ b/api/package-lock.json @@ -15,6 +15,7 @@ "express": "^4.17.3", "mongodb": "^4.5.0", "puppeteer": "^14.1.1", + "sanitize-filename": "^1.6.3", "uuid": "^8.3.2" }, "devDependencies": { @@ -2106,6 +2107,14 @@ "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, + "node_modules/sanitize-filename": { + "version": "1.6.3", + "resolved": "https://registry.npmjs.org/sanitize-filename/-/sanitize-filename-1.6.3.tgz", + "integrity": "sha512-y/52Mcy7aw3gRm7IrcGDFx/bCk4AhRh2eI9luHOQM86nZsqwiRkkq2GekHXBBD+SmPidc8i2PqtYZl+pWJ8Oeg==", + "dependencies": { + "truncate-utf8-bytes": "^1.0.0" + } + }, "node_modules/saslprep": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/saslprep/-/saslprep-1.0.3.tgz", @@ -2391,6 +2400,14 @@ "node": ">=12" } }, + "node_modules/truncate-utf8-bytes": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/truncate-utf8-bytes/-/truncate-utf8-bytes-1.0.2.tgz", + "integrity": "sha512-95Pu1QXQvruGEhv62XCMO3Mm90GscOCClvrIUwCM0PYOXK3kaF3l3sIHxx71ThJfcbM2O5Au6SO3AWCSEfW4mQ==", + "dependencies": { + "utf8-byte-length": "^1.0.1" + } + }, "node_modules/type-fest": { "version": "0.20.2", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", @@ -2514,6 +2531,11 @@ "node": ">=4" } }, + "node_modules/utf8-byte-length": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/utf8-byte-length/-/utf8-byte-length-1.0.4.tgz", + "integrity": "sha512-4+wkEYLBbWxqTahEsWrhxepcoVOJ+1z5PGIjPZxRkytcdSUaNjIjBM7Xn8E+pdSuV7SzvWovBFA54FO0JSoqhA==" + }, "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", @@ -4224,6 +4246,14 @@ "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, + "sanitize-filename": { + "version": "1.6.3", + "resolved": "https://registry.npmjs.org/sanitize-filename/-/sanitize-filename-1.6.3.tgz", + "integrity": "sha512-y/52Mcy7aw3gRm7IrcGDFx/bCk4AhRh2eI9luHOQM86nZsqwiRkkq2GekHXBBD+SmPidc8i2PqtYZl+pWJ8Oeg==", + "requires": { + "truncate-utf8-bytes": "^1.0.0" + } + }, "saslprep": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/saslprep/-/saslprep-1.0.3.tgz", @@ -4454,6 +4484,14 @@ "punycode": "^2.1.1" } }, + "truncate-utf8-bytes": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/truncate-utf8-bytes/-/truncate-utf8-bytes-1.0.2.tgz", + "integrity": "sha512-95Pu1QXQvruGEhv62XCMO3Mm90GscOCClvrIUwCM0PYOXK3kaF3l3sIHxx71ThJfcbM2O5Au6SO3AWCSEfW4mQ==", + "requires": { + "utf8-byte-length": "^1.0.1" + } + }, "type-fest": { "version": "0.20.2", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", @@ -4549,6 +4587,11 @@ "prepend-http": "^2.0.0" } }, + "utf8-byte-length": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/utf8-byte-length/-/utf8-byte-length-1.0.4.tgz", + "integrity": "sha512-4+wkEYLBbWxqTahEsWrhxepcoVOJ+1z5PGIjPZxRkytcdSUaNjIjBM7Xn8E+pdSuV7SzvWovBFA54FO0JSoqhA==" + }, "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", diff --git a/api/package.json b/api/package.json index baac0a2..e25ccf7 100644 --- a/api/package.json +++ b/api/package.json @@ -15,6 +15,7 @@ "express": "^4.17.3", "mongodb": "^4.5.0", "puppeteer": "^14.1.1", + "sanitize-filename": "^1.6.3", "uuid": "^8.3.2" }, "devDependencies": { diff --git a/api/security/chrome.json b/api/security/chrome.json new file mode 100644 index 0000000..e5b0f2d --- /dev/null +++ b/api/security/chrome.json @@ -0,0 +1,1535 @@ +{ + "defaultAction": "SCMP_ACT_ERRNO", + "syscalls": [ + { + "name": "accept", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "accept4", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "access", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "alarm", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "arch_prctl", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "bind", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "brk", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "capget", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "capset", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "chdir", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "chmod", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "chown", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "chown32", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "chroot", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "clock_getres", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "clock_gettime", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "clock_nanosleep", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "clone", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "close", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "connect", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "creat", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "dup", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "dup2", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "dup3", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "epoll_create", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "epoll_create1", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "epoll_ctl", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "epoll_ctl_old", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "epoll_pwait", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "epoll_wait", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "epoll_wait_old", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "eventfd", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "eventfd2", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "execve", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "execveat", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "exit", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "exit_group", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "faccessat", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "fadvise64", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "fadvise64_64", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "fallocate", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "fanotify_init", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "fanotify_mark", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "fchdir", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "fchmod", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "fchmodat", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "fchown", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "fchown32", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "fchownat", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "fcntl", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "fcntl64", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "fdatasync", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "fgetxattr", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "flistxattr", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "flock", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "fork", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "fremovexattr", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "fsetxattr", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "fstat", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "fstat64", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "fstatat64", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "fstatfs", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "fstatfs64", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "fsync", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "ftruncate", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "ftruncate64", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "futex", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "futimesat", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "getcpu", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "getcwd", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "getdents", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "getdents64", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "getegid", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "getegid32", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "geteuid", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "geteuid32", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "getgid", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "getgid32", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "getgroups", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "getgroups32", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "getitimer", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "getpeername", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "getpgid", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "getpgrp", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "getpid", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "getppid", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "getpriority", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "getrandom", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "getresgid", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "getresgid32", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "getresuid", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "getresuid32", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "getrlimit", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "get_robust_list", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "getrusage", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "getsid", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "getsockname", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "getsockopt", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "get_thread_area", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "gettid", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "gettimeofday", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "getuid", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "getuid32", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "getxattr", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "inotify_add_watch", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "inotify_init", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "inotify_init1", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "inotify_rm_watch", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "io_cancel", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "ioctl", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "io_destroy", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "io_getevents", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "ioprio_get", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "ioprio_set", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "io_setup", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "io_submit", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "kill", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "lchown", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "lchown32", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "lgetxattr", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "link", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "linkat", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "listen", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "listxattr", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "llistxattr", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "_llseek", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "lremovexattr", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "lseek", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "lsetxattr", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "lstat", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "lstat64", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "madvise", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "memfd_create", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "mincore", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "mkdir", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "mkdirat", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "mknod", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "mknodat", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "mlock", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "mlockall", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "mmap", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "mmap2", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "mprotect", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "mq_getsetattr", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "mq_notify", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "mq_open", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "mq_timedreceive", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "mq_timedsend", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "mq_unlink", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "mremap", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "msgctl", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "msgget", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "msgrcv", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "msgsnd", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "msync", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "munlock", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "munlockall", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "munmap", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "name_to_handle_at", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "nanosleep", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "newfstatat", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "_newselect", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "open", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "open_by_handle_at", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "openat", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "pause", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "pipe", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "pipe2", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "poll", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "ppoll", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "prctl", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "pread64", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "preadv", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "prlimit64", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "pselect6", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "pwrite64", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "pwritev", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "read", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "readahead", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "readlink", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "readlinkat", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "readv", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "recvfrom", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "recvmmsg", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "recvmsg", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "remap_file_pages", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "removexattr", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "rename", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "renameat", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "renameat2", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "rmdir", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "rt_sigaction", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "rt_sigpending", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "rt_sigprocmask", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "rt_sigqueueinfo", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "rt_sigreturn", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "rt_sigsuspend", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "rt_sigtimedwait", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "rt_tgsigqueueinfo", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "sched_getaffinity", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "sched_getattr", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "sched_getparam", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "sched_get_priority_max", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "sched_get_priority_min", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "sched_getscheduler", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "sched_rr_get_interval", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "sched_setaffinity", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "sched_setattr", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "sched_setparam", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "sched_setscheduler", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "sched_yield", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "seccomp", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "select", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "semctl", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "semget", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "semop", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "semtimedop", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "sendfile", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "sendfile64", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "sendmmsg", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "sendmsg", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "sendto", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "setdomainname", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "setfsgid", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "setfsgid32", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "setfsuid", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "setfsuid32", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "setgid", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "setgid32", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "setgroups", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "setgroups32", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "sethostname", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "setitimer", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "setns", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "setpgid", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "setpriority", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "setregid", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "setregid32", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "setresgid", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "setresgid32", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "setresuid", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "setresuid32", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "setreuid", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "setreuid32", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "setrlimit", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "set_robust_list", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "setsid", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "setsockopt", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "set_thread_area", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "set_tid_address", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "setuid", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "setuid32", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "setxattr", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "shmat", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "shmctl", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "shmdt", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "shmget", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "shutdown", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "sigaltstack", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "signalfd", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "signalfd4", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "socket", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "socketpair", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "splice", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "stat", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "stat64", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "statfs", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "statfs64", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "symlink", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "symlinkat", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "sync", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "sync_file_range", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "syncfs", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "sysinfo", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "syslog", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "tee", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "tgkill", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "time", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "timer_create", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "timer_delete", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "timerfd_create", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "timerfd_gettime", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "timerfd_settime", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "timer_getoverrun", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "timer_gettime", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "timer_settime", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "times", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "tkill", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "truncate", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "truncate64", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "ugetrlimit", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "umask", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "uname", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "unlink", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "unlinkat", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "unshare", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "utime", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "utimensat", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "utimes", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "vfork", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "vhangup", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "vmsplice", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "wait4", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "waitid", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "write", + "action": "SCMP_ACT_ALLOW", + "args": null + }, + { + "name": "writev", + "action": "SCMP_ACT_ALLOW", + "args": null + } + ] +} diff --git a/api/server.js b/api/server.js index b234173..2e587b6 100644 --- a/api/server.js +++ b/api/server.js @@ -2,21 +2,26 @@ const express = require("express"); const app = express(); const { MongoClient } = require("mongodb"); const cors = require("cors"); -const config = require("../src/config.js"); const getData = require("./modules/getData.js"); const fs = require("fs"); +const { port, URI, database, collection, screenshotDirectory, pdfDirectory } = require("./config.js"); const fetch = require("cross-fetch"); - -const port = config.API.PORT; - -const URI = config.API.MONGODB_URI; -const database = config.API.DB_NAME; -const collection = config.API.COLLECTION_NAME; +const sanitize = require("sanitize-filename"); const client = new MongoClient(URI); const db = client.db(database); const list = db.collection(collection); +// Create the storage directories if they do ot exist +if (!fs.existsSync(screenshotDirectory)) { + fs.mkdirSync(screenshotDirectory, { recursive: true }); +} + +if (!fs.existsSync(pdfDirectory)) { + fs.mkdirSync(pdfDirectory, { recursive: true }); +} + + app.use(cors()); app.use(express.json()); @@ -28,7 +33,7 @@ app.get("/api", async (req, res) => { app.get("/screenshots/:id", async (req, res) => { res.sendFile( - config.API.STORAGE_LOCATION + "/LinkWarden/screenshot's/" + req.params.id, + screenshotDirectory + "/" + sanitize(req.params.id), (err) => { if (err) { res.sendFile(__dirname + "/pages/404.html"); @@ -39,7 +44,7 @@ app.get("/screenshots/:id", async (req, res) => { app.get("/pdfs/:id", async (req, res) => { res.sendFile( - config.API.STORAGE_LOCATION + "/LinkWarden/pdf's/" + req.params.id, + pdfDirectory + "/" + sanitize(req.params.id), (err) => { if (err) { res.sendFile(__dirname + "/pages/404.html"); @@ -57,7 +62,7 @@ app.post("/api", async (req, res) => { .then((res) => res.text()) .then((text) => (body = text)); // regular expression to parse contents of the