commit 9d0e64797a69a46d97ae89aff59e779a488fd9aa Author: bvn13 Date: Sun Feb 25 14:03:04 2024 +0300 nextcoud starter diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..a1cb2ee --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,73 @@ +version: '3.7' + +networks: + nextcloud: + external: true + +services: + + nextcloud: + build: ./src/nextcloud/ + container_name: nextcloud + environment: + - TZ=Europe/Moscow + - POSTGRES_HOST=postgres-nextcloud + - POSTGRES_DB=nextcloud + - POSTGRES_USER=nextcloud + - POSTGRES_PASSWORD=dsfjhskdjfhskWER! + volumes: + - ./nextcloud/apps:/var/www/html/apps + - ./nextcloud/custom_apps:/var/www/html/custom_apps + - ./nextcloud/config:/var/www/html/config + - ./nextcloud/data:/var/www/html/data + networks: + - nextcloud + restart: unless-stopped + depends_on: + - postgres-nextcloud + + postgres-nextcloud: + image: postgres:14.1-alpine + container_name: postgres-nextcloud + restart: unless-stopped + environment: + - POSTGRES_DB=nextcloud + - POSTGRES_USER=nextcloud + - POSTGRES_PASSWORD=dsfjhskdjfhskWER! + volumes: + - ./database:/var/lib/postgresql/data + networks: + - nextcloud + + onlyoffice: + image: onlyoffice/documentserver + #build: ./src/onlyoffice/ + #stdin_open: true + #tty: true + #entrypoint: [ '/usr/bin/tail', '--follow', '/dev/null' ] + container_name: onlyoffice + restart: always + environment: + - DB_TYPE=postgres + - DB_HOST=postgres-nextcloud + - DB_PORT=5432 + - DB_NAME=nextcloud + - DB_USER=nextcloud + - DB_PWD=dsfjhskdjfhskWER! + volumes: + - ./onlyoffice/logs:/var/log/onlyoffice + - ./onlyoffice/data:/var/www/onlyoffice/Data + - ./onlyoffice/lib:/var/lib/onlyoffice + networks: + - nextcloud + + + + + + + + + + + diff --git a/rebuild.sh b/rebuild.sh new file mode 100755 index 0000000..b1c0e3e --- /dev/null +++ b/rebuild.sh @@ -0,0 +1,4 @@ +#!/bin/bash +docker-compose down +docker-compose up -d --no-deps --build +docker-compose logs nextcloud diff --git a/src/nextcloud/Dockerfile b/src/nextcloud/Dockerfile new file mode 100644 index 0000000..cd1002d --- /dev/null +++ b/src/nextcloud/Dockerfile @@ -0,0 +1,8 @@ +FROM nextcloud:24.0.4-apache + +WORKDIR /var/www/html + +COPY ./script/cron.sh /app/cron.sh + +ENTRYPOINT ["/entrypoint.sh"] +CMD ["apache2-foreground"] \ No newline at end of file diff --git a/src/nextcloud/Dockerfile~ b/src/nextcloud/Dockerfile~ new file mode 100644 index 0000000..48652d7 --- /dev/null +++ b/src/nextcloud/Dockerfile~ @@ -0,0 +1,8 @@ +FROM nextcloud:23.0.3-apache + +WORKDIR /var/www/html + +COPY ./script/cron.sh /app/cron.sh + +ENTRYPOINT ["/entrypoint.sh"] +CMD ["apache2-foreground"] \ No newline at end of file diff --git a/src/nextcloud/script/cron.sh b/src/nextcloud/script/cron.sh new file mode 100644 index 0000000..bbd80a5 --- /dev/null +++ b/src/nextcloud/script/cron.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +run_as() { + if [ "$(id -u)" = 0 ]; then + su -p www-data -s /bin/sh -c "$1" + else + sh -c "$1" + fi +} + +run_as ' \ + php /var/www/html/cron.php +' + +echo $? diff --git a/src/nextcloud/script/enable-apps.sh b/src/nextcloud/script/enable-apps.sh new file mode 100644 index 0000000..58c8bfa --- /dev/null +++ b/src/nextcloud/script/enable-apps.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +run_as() { + if [ "$(id -u)" = 0 ]; then + su -p www-data -s /bin/sh -c "$1" + else + sh -c "$1" + fi +} + +while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:80/index.php/login)" != "200" ]]; do sleep 5; done + +run_as ' \ +for app in $(ls /var/www/html/apps/); do \ + echo "Disabling $app..." + php /var/www/html/occ app:disable $app + echo "Installing $app..." + php /var/www/html/occ app:install $app + echo "Enabling $app..." + php /var/www/html/occ app:enable $app +done' diff --git a/src/onlyoffice/Dockerfile b/src/onlyoffice/Dockerfile new file mode 100644 index 0000000..2ed4317 --- /dev/null +++ b/src/onlyoffice/Dockerfile @@ -0,0 +1,5 @@ +FROM onlyoffice/documentserver + +COPY ./script/licencing.sh /app/licencing.sh + +ENTRYPOINT [ "/bin/bash", "/app/licencing.sh" ] diff --git a/src/onlyoffice/script/licencing.sh b/src/onlyoffice/script/licencing.sh new file mode 100644 index 0000000..06077e6 --- /dev/null +++ b/src/onlyoffice/script/licencing.sh @@ -0,0 +1,101 @@ +#!/bin/bash + +apt-get update +apt-get -y install build-essential python3-dev + +FILE=OO_PubKey +if test -f "$FILE"; then + echo Patch has already been applied. Starting DocumentServer... +else + apt-get update && apt-get install -y python3.8-dev + wget https://bootstrap.pypa.io/get-pip.py + python3.8 get-pip.py + pip install pycryptodome + rm -f /var/www/onlyoffice/Data/license.lic + + cat < index.py +from Crypto.Hash import SHA, SHA256 +from Crypto.Signature import PKCS1_v1_5 +from Crypto.PublicKey import RSA +from shutil import copyfile +import json +import codecs + +hexlify = codecs.getencoder('hex') + +licenseFile = { + "branding": False, + "connections": 9999, + "customization": False, + "end_date": "2099-01-01T23:59:59.000Z", + "light": "False", + "mode": "", + "portal_count": "0", + "process": 2, + "ssbranding": False, + "test": "False", + "trial": "False", + "user_quota": "0", + "users_count": 9999, + "users_expire": 99999, + "whiteLabel": False, + "customer_id": "customerID", + "start_date": "2020-01-01T00:00:00.000Z", + "users": [], + "version": 2 +} + +jsonLicenseFile = codecs.encode(json.dumps(licenseFile, separators=(',', ':')), encoding='utf-8') + +privKey = RSA.generate(1024) +publKey = privKey.publickey().exportKey('PEM') + +digest = SHA.new(jsonLicenseFile) +signer = PKCS1_v1_5.new(privKey) +signature = signer.sign(digest) + +finalSignature = signature.hex() + +licenseFile['signature'] = finalSignature + +f = open("OO_License", "w+") +f.write(json.dumps(licenseFile)) +f.close + +f = open("OO_PubKey", "w+") +f.write(publKey.decode('utf-8')) +f.close() + +print("The license file has been saved to OO_License. Here's the content :") +print(json.dumps(licenseFile)) +print("It will be placed automatically in the Data directory of OnlyOffice") + +copyfile("OO_License", "/var/www/onlyoffice/Data/license.lic") + +print("Patching docservice and converter...") + +basePath = "/var/www/onlyoffice/documentserver/server/" +files = ["DocService/docservice", "FileConverter/converter"] + +for file in files: + f = open(basePath+file, 'rb') + data = f.read() + f.close() + + replacedData = data.replace(b"-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDRhGF7X4A0ZVlEg594WmODVVUI\niiPQs04aLmvfg8SborHss5gQXu0aIdUT6nb5rTh5hD2yfpF2WIW6M8z0WxRhwicg\nXwi80H1aLPf6lEPPLvN29EhQNjBpkFkAJUbS8uuhJEeKw0cE49g80eBBF4BCqSL6\nPFQbP9/rByxdxEoAIQIDAQAB\n-----END PUBLIC KEY-----", bytes(publKey)) + # replacedData = bytes(publKey) + + f = open(basePath+file, 'wb') + f.write(replacedData) + f.close() + +EOF + + python3.8 index.py + + echo Patching docservice and converter completed. + + echo Done! Running Document Server... +fi + +/app/ds/run-document-server.sh diff --git a/test.sh b/test.sh new file mode 100644 index 0000000..85563bd --- /dev/null +++ b/test.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +run_as() { + if [ "$(id -u)" = 0 ]; then + su -p www-data -s /bin/sh -c "$1" + else + sh -c "$1" + fi +} + +run_as ' \ + php occ app:list +' + +echo $?