From a4780521940a77fca088e01a9aa574b16ce019de Mon Sep 17 00:00:00 2001 From: Florian Zirker Date: Fri, 23 Feb 2024 18:20:41 +0100 Subject: [PATCH 1/5] paperless: move script to this git --- .editorconfig | 6 ++ .gitignore | 3 +- paperless/docker-compose.yaml | 2 +- paperless/scripts/removePdfPassword.py | 79 ++++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 paperless/scripts/removePdfPassword.py diff --git a/.editorconfig b/.editorconfig index ec07101..b7a329e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -16,3 +16,9 @@ tab_width = 2 [*.md] trim_trailing_whitespace = false + +[*.py] +end_of_line = lf +indent_style = space +indent_size = 4 +tab_width = 4 diff --git a/.gitignore b/.gitignore index 8682eff..ba238b6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .env -**/.vscode/* \ No newline at end of file +**/.vscode/* +paperless/scripts/passwords.txt diff --git a/paperless/docker-compose.yaml b/paperless/docker-compose.yaml index 9e77420..53c1caf 100644 --- a/paperless/docker-compose.yaml +++ b/paperless/docker-compose.yaml @@ -40,7 +40,7 @@ services: retries: 5 volumes: - ${VOLUMES_PATH}/paperless/data:/usr/src/paperless/data - - ${VOLUMES_PATH}/paperless/scripts:/usr/src/paperless/scripts + - ./scripts:/usr/src/paperless/scripts - ${MEDIA_PATH}:/usr/src/paperless/media - ${EXPORT_PATH}:/usr/src/paperless/export - ${CONSUME_PATH}:/usr/src/paperless/consume diff --git a/paperless/scripts/removePdfPassword.py b/paperless/scripts/removePdfPassword.py new file mode 100644 index 0000000..4931931 --- /dev/null +++ b/paperless/scripts/removePdfPassword.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python + +"""Script for papeless-ngx to decrypt pdf files secured with a password +Passwords to check ar in file /usr/src/paperless/scripts/passwords.txt +Original from https://piep.tech/posts/automatic-password-removal-in-paperless-ngx/ +""" + +import sys +import os +import pikepdf + + +PWD_PATH = "/usr/src/paperless/scripts/passwords.txt" +#PWD_PATH = "input/passwords.txt" + + +def read_passwords_from_file(): + """Read Paswors from file""" + passwords = [] + + with open(PWD_PATH, "r", encoding="utf-8") as f: + passwords = f.readlines() + + passwords = list(filter(len, map(str.strip, passwords))) + if not passwords: + print("Empty password file") + + return passwords + + +def unlock_pdf(file_path, password_list): + """Removes Password from PDF. A list of passwords is tried through.""" + for pwd in password_list: + try: + with pikepdf.open(file_path, password=pwd, allow_overwriting_input=True) as pdf: + pdf.save(file_path) + return True + except pikepdf.PasswordError: + continue + return False + + +def is_pdf_encrypted(file_path): + """Checks if a PDF file is encrypted""" + try: + with pikepdf.open(file_path) as pdf: + return pdf.is_encrypted + except pikepdf.PasswordError: + return True + + +def is_pdf(file_path): + """Check if Filename ends with PDF. File is not opened""" + return os.path.splitext(file_path)[-1].lower() == ".pdf" + + +if __name__ == "__main__": + + doc_path = os.environ.get('DOCUMENT_WORKING_PATH') + + if not os.path.exists(doc_path): + print(f"Document {doc_path} not found.") + sys.exit(1) + + if not is_pdf(doc_path): + print(f"Document {doc_path} is not a PDF. So no decryption needed.") + sys.exit(0) + + if not is_pdf_encrypted(doc_path): + print(f"Document {doc_path} was already decrypted and no password needed.") + sys.exit(0) + + pwds = read_passwords_from_file() + if unlock_pdf(doc_path, pwds): + print(f"Document {doc_path} successfull decrypted.") + sys.exit(0) + else: + print(f"Document {doc_path} could not be decrypted.") + sys.exit(1) From 2aa5edf2acc79a57b89ce989ddf2cbcb792df427 Mon Sep 17 00:00:00 2001 From: Florian Zirker Date: Fri, 23 Feb 2024 18:35:00 +0100 Subject: [PATCH 2/5] fix pdf password script --- paperless/scripts/removePdfPassword.py | 8 ++++++++ 1 file changed, 8 insertions(+) mode change 100644 => 100755 paperless/scripts/removePdfPassword.py diff --git a/paperless/scripts/removePdfPassword.py b/paperless/scripts/removePdfPassword.py old mode 100644 new mode 100755 index 4931931..57942e6 --- a/paperless/scripts/removePdfPassword.py +++ b/paperless/scripts/removePdfPassword.py @@ -25,6 +25,7 @@ def read_passwords_from_file(): if not passwords: print("Empty password file") + passwords.append("") # some PDFs are encrypted with empty password return passwords @@ -58,6 +59,13 @@ if __name__ == "__main__": doc_path = os.environ.get('DOCUMENT_WORKING_PATH') + if not doc_path: + doc_path = sys.argv[1] + + if not doc_path: + print("Neither DOCUMENT_WORKING_PATH set nor document passed by parameter.") + sys.exit(1) + if not os.path.exists(doc_path): print(f"Document {doc_path} not found.") sys.exit(1) From 94523768738292b1c1ce98dfbc453655e6cebab1 Mon Sep 17 00:00:00 2001 From: Florian Zirker Date: Tue, 9 Apr 2024 15:36:15 +0200 Subject: [PATCH 3/5] heimdall -> homer --- dashboard/docker-compose.yaml | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/dashboard/docker-compose.yaml b/dashboard/docker-compose.yaml index f13d8aa..a6b4896 100644 --- a/dashboard/docker-compose.yaml +++ b/dashboard/docker-compose.yaml @@ -1,22 +1,19 @@ services: - app: - image: linuxserver/heimdall:${HEIMDALL_VERSION} - environment: - - PUID=1000 - - PGID=1000 - - TZ=Europe/Berlin + homer: + image: b4bz/homer volumes: - - ${VOLUMES_PATH}/dashboard/heimdall:/config - expose: - - "80" + - ${VOLUMES_PATH}/dashboard/homer:/www/assets networks: - web + user: 1000:1000 + environment: + - INIT_ASSETS=1 labels: - "traefik.enable=true" - - "traefik.http.routers.heimdall.rule=Host(`dashboard.${DOMAIN}`)" - - "traefik.http.routers.heimdall.entrypoints=web" - - "traefik.http.services.heimdall.loadbalancer.server.port=80" + - "traefik.http.routers.homer.rule=Host(`dashboard.${DOMAIN}`)" + - "traefik.http.routers.homer.entrypoints=web" + - "traefik.http.services.homer.loadbalancer.server.port=8080" - "docker.group=dashboard" restart: unless-stopped From 1f70a4f6aa607b5d937884cd503582ebb83e0ac9 Mon Sep 17 00:00:00 2001 From: Florian Zirker Date: Fri, 17 May 2024 09:09:27 +0200 Subject: [PATCH 4/5] set versions in smartHome --- smartHome/docker-compose.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/smartHome/docker-compose.yaml b/smartHome/docker-compose.yaml index 5e15c6e..52b697a 100644 --- a/smartHome/docker-compose.yaml +++ b/smartHome/docker-compose.yaml @@ -1,7 +1,7 @@ services: homeassistant: - image: ghcr.io/home-assistant/home-assistant:stable + image: ghcr.io/home-assistant/home-assistant:${HASSI_VERSION} volumes: - ${VOLUMES_PATH}/smartHome/homeassistent:/config - /run/dbus:/run/dbus:ro @@ -17,7 +17,7 @@ services: - "docker.group=smartHome" mqttbroker: - image: eclipse-mosquitto:2.0 + image: eclipse-mosquitto:${MOSQUITTO_VERSION} restart: unless-stopped network_mode: host expose: From 8632430a4aea138888038adf11511af33e1926fd Mon Sep 17 00:00:00 2001 From: Florian Zirker Date: Fri, 17 May 2024 09:09:46 +0200 Subject: [PATCH 5/5] add manual --- doc/manual.md | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 doc/manual.md diff --git a/doc/manual.md b/doc/manual.md new file mode 100644 index 0000000..a613734 --- /dev/null +++ b/doc/manual.md @@ -0,0 +1,62 @@ +# Manual and Help + +## Upgrade Postgrs to newer Version (i.e. 15 to 16) + + +### 1. Copy Service + +1.1 Copy whole service definition in docker-compose.yaml +1.2 Rename old service to *-old +1.3 Move path from new service to i.e postgres16 +1.4 Set postgres version explicit to new version + +Example: +``` + databasedb-old: + image: postgres:${POSTGRES_VERSION} + volumes: + - ${VOLUMES_PATH}/databasedb:/var/lib/postgresql/data + environment: + - POSTGRES_DB=${POSTGRES_DB} + - POSTGRES_USER=${POSTGRES_USER} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + + databasedb: + image: postgres:16 + volumes: + - ${VOLUMES_PATH}/databasedb16:/var/lib/postgresql/data + environment: + - POSTGRES_DB=${POSTGRES_DB} + - POSTGRES_USER=${POSTGRES_USER} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} +``` + +### 2. Move data +Backup data from service one to new servic with the following command: +``` +docker exec old-service pg_dumpall -U dbuser | docker exec -i new-service psql -U dbuser -d database +``` + +### 3. Set password +``` +docker exec -i monitoring-databasedb-1 psql -U dbuser -d database -c "ALTER USER \"dbuser\" PASSWORD 'secret';" +``` + +### 4. Test +```docker compose up -d``` and check if service is correctly running. + +### 5. Cleanup +5.1 Remove old service in docker-compose.yaml +5.2 Set explicit version again to ${POSTGRES_VERSION} and adopt .env file +5.4 remove old volume dir + + +### 6. May be move Data dir +6.1. ```docker compose down``` +6.2 ```mv /mnt/dockervolumes/databasedb16 /mnt/dockervolumes/databasedb``` +6.3 docker-compose.yaml anpassen +6.1. ```docker compose up -d``` + + + +