From 1b86445b6a50e68dc75af676ae875c59932267a2 Mon Sep 17 00:00:00 2001 From: szaimen Date: Thu, 17 Mar 2022 10:13:21 +0100 Subject: [PATCH] add onlyoffice and allow to disable talk and collabora Signed-off-by: szaimen --- .github/dependabot.yml | 9 +++ Containers/apache/Caddyfile | 6 ++ Containers/nextcloud/entrypoint.sh | 68 +++++++++++++------ Containers/onlyoffice/Dockerfile | 2 + php/containers.json | 34 ++++++++-- php/public/disable-collabora.js | 5 ++ php/public/disable-onlyoffice.js | 5 ++ php/public/disable-talk.js | 5 ++ php/public/index.php | 3 + php/public/options-form-submit.js | 12 ++++ php/src/ContainerDefinitionFetcher.php | 24 +++++++ .../Controller/ConfigurationController.php | 18 +++++ php/src/Data/ConfigurationManager.php | 45 ++++++++++++ php/src/Docker/DockerActionManager.php | 18 +++++ php/templates/containers.twig | 20 ++++++ 15 files changed, 250 insertions(+), 24 deletions(-) create mode 100644 Containers/onlyoffice/Dockerfile create mode 100644 php/public/disable-collabora.js create mode 100644 php/public/disable-onlyoffice.js create mode 100644 php/public/disable-talk.js diff --git a/.github/dependabot.yml b/.github/dependabot.yml index db70933d..1432216d 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -117,3 +117,12 @@ updates: labels: - 3. to review - dependencies +- package-ecosystem: "docker" + directory: "/Containers/onlyoffice" + schedule: + interval: "daily" + time: "12:00" + open-pull-requests-limit: 10 + labels: + - 3. to review + - dependencies diff --git a/Containers/apache/Caddyfile b/Containers/apache/Caddyfile index 3bc33022..875e6a07 100644 --- a/Containers/apache/Caddyfile +++ b/Containers/apache/Caddyfile @@ -31,6 +31,12 @@ reverse_proxy {$COLLABORA_HOST}:9980 } + # Onlyoffice + route /onlyoffice/* { + uri strip_prefix /onlyoffice + reverse_proxy {$ONLYOFFICE_HOST}:80 + } + # Nextcloud route { rewrite /.well-known/carddav /remote.php/dav diff --git a/Containers/nextcloud/entrypoint.sh b/Containers/nextcloud/entrypoint.sh index 9508cc09..63df5b76 100644 --- a/Containers/nextcloud/entrypoint.sh +++ b/Containers/nextcloud/entrypoint.sh @@ -277,32 +277,60 @@ php /var/www/html/occ config:system:set trusted_proxies 0 --value="127.0.0.1" php /var/www/html/occ config:app:set notify_push base_endpoint --value="https://$NC_DOMAIN/push" # Collabora -if ! [ -d "/var/www/html/custom_apps/richdocuments" ]; then - php /var/www/html/occ app:install richdocuments -elif [ "$(php /var/www/html/occ config:app:get richdocuments enabled)" = "no" ]; then - php /var/www/html/occ app:enable richdocuments +if [ "$COLLABORA_ENABLED" = 'yes' ]; then + if ! [ -d "/var/www/html/custom_apps/richdocuments" ]; then + php /var/www/html/occ app:install richdocuments + elif [ "$(php /var/www/html/occ config:app:get richdocuments enabled)" = "no" ]; then + php /var/www/html/occ app:enable richdocuments + else + php /var/www/html/occ app:update richdocuments + fi + php /var/www/html/occ config:app:set richdocuments wopi_url --value="https://$NC_DOMAIN/" + # php /var/www/html/occ richdocuments:activate-config + # Fix https://github.com/nextcloud/all-in-one/issues/188: + php /var/www/html/occ config:system:set allow_local_remote_servers --type=bool --value=true else - php /var/www/html/occ app:update richdocuments + if [ -d "/var/www/html/custom_apps/richdocuments" ]; then + php /var/www/html/occ app:remove richdocuments + fi +fi + +# OnlyOffice +if [ "$ONLYOFFICE_ENABLED" = 'yes' ]; then + if ! [ -d "/var/www/html/custom_apps/onlyoffice" ]; then + php /var/www/html/occ app:install onlyoffice + elif [ "$(php /var/www/html/occ config:app:get onlyoffice enabled)" = "no" ]; then + php /var/www/html/occ app:enable onlyoffice + else + php /var/www/html/occ app:update onlyoffice + fi + php /var/www/html/occ config:app:set onlyoffice DocumentServerUrl --value="https://$NC_DOMAIN/onlyoffice" +else + if [ -d "/var/www/html/custom_apps/onlyoffice" ]; then + php /var/www/html/occ app:remove onlyoffice + fi fi -php /var/www/html/occ config:app:set richdocuments wopi_url --value="https://$NC_DOMAIN/" -# php /var/www/html/occ richdocuments:activate-config -# Fix https://github.com/nextcloud/all-in-one/issues/188: -php /var/www/html/occ config:system:set allow_local_remote_servers --type=bool --value=true # Talk -if ! [ -d "/var/www/html/custom_apps/spreed" ]; then - php /var/www/html/occ app:install spreed -elif [ "$(php /var/www/html/occ config:app:get spreed enabled)" = "no" ]; then - php /var/www/html/occ app:enable spreed +if [ "$TALK_ENABLED" = 'yes' ]; then + if ! [ -d "/var/www/html/custom_apps/spreed" ]; then + php /var/www/html/occ app:install spreed + elif [ "$(php /var/www/html/occ config:app:get spreed enabled)" = "no" ]; then + php /var/www/html/occ app:enable spreed + else + php /var/www/html/occ app:update spreed + fi + STUN_SERVERS="[\"$NC_DOMAIN:3478\"]" + TURN_SERVERS="[{\"server\":\"$NC_DOMAIN:3478\",\"secret\":\"$TURN_SECRET\",\"protocols\":\"udp,tcp\"}]" + SIGNALING_SERVERS="{\"servers\":[{\"server\":\"https://$NC_DOMAIN/standalone-signaling/\",\"verify\":true}],\"secret\":\"$SIGNALING_SECRET\"}" + php /var/www/html/occ config:app:set spreed stun_servers --value="$STUN_SERVERS" --output json + php /var/www/html/occ config:app:set spreed turn_servers --value="$TURN_SERVERS" --output json + php /var/www/html/occ config:app:set spreed signaling_servers --value="$SIGNALING_SERVERS" --output json else - php /var/www/html/occ app:update spreed + if [ -d "/var/www/html/custom_apps/spreed" ]; then + php /var/www/html/occ app:remove spreed + fi fi -STUN_SERVERS="[\"$NC_DOMAIN:3478\"]" -TURN_SERVERS="[{\"server\":\"$NC_DOMAIN:3478\",\"secret\":\"$TURN_SECRET\",\"protocols\":\"udp,tcp\"}]" -SIGNALING_SERVERS="{\"servers\":[{\"server\":\"https://$NC_DOMAIN/standalone-signaling/\",\"verify\":true}],\"secret\":\"$SIGNALING_SECRET\"}" -php /var/www/html/occ config:app:set spreed stun_servers --value="$STUN_SERVERS" --output json -php /var/www/html/occ config:app:set spreed turn_servers --value="$TURN_SERVERS" --output json -php /var/www/html/occ config:app:set spreed signaling_servers --value="$SIGNALING_SERVERS" --output json # Clamav if [ "$CLAMAV_ENABLED" = 'yes' ]; then diff --git a/Containers/onlyoffice/Dockerfile b/Containers/onlyoffice/Dockerfile new file mode 100644 index 00000000..550c0bd1 --- /dev/null +++ b/Containers/onlyoffice/Dockerfile @@ -0,0 +1,2 @@ +# From https://github.com/ONLYOFFICE/Docker-DocumentServer/blob/master/Dockerfile +FROM onlyoffice/documentserver:7.0.1.37 diff --git a/php/containers.json b/php/containers.json index 756cd987..93b429ce 100644 --- a/php/containers.json +++ b/php/containers.json @@ -2,10 +2,11 @@ "production": [ { "dependsOn": [ - "nextcloud-aio-nextcloud", + "nextcloud-aio-onlyoffice", "nextcloud-aio-collabora", + "nextcloud-aio-clamav", "nextcloud-aio-talk", - "nextcloud-aio-clamav" + "nextcloud-aio-nextcloud" ], "identifier": "nextcloud-aio-apache", "displayName": "Apache", @@ -22,7 +23,8 @@ "NEXTCLOUD_HOST=nextcloud-aio-nextcloud", "COLLABORA_HOST=nextcloud-aio-collabora", "TALK_HOST=nextcloud-aio-talk", - "APACHE_PORT=%APACHE_PORT%" + "APACHE_PORT=%APACHE_PORT%", + "ONLYOFFICE_HOST=nextcloud-aio-onlyoffice" ], "volumes": [ { @@ -126,7 +128,10 @@ "AIO_URL=%AIO_URL%", "NEXTCLOUD_MOUNT=%NEXTCLOUD_MOUNT%", "CLAMAV_ENABLED=%CLAMAV_ENABLED%", - "CLAMAV_HOST=nextcloud-aio-clamav" + "CLAMAV_HOST=nextcloud-aio-clamav", + "ONLYOFFICE_ENABLED=%ONLYOFFICE_ENABLED%", + "COLLABORA_ENABLED=%COLLABORA_ENABLED%", + "TALK_ENABLED=%TALK_ENABLED%" ], "maxShutdownTime": 10, "restartPolicy": "unless-stopped" @@ -316,6 +321,27 @@ "secrets": [], "maxShutdownTime": 10, "restartPolicy": "unless-stopped" + }, + { + "dependsOn": [], + "identifier": "nextcloud-aio-onlyoffice", + "displayName": "OnlyOffice", + "containerName": "nextcloud/aio-onlyoffice", + "ports": [], + "internalPorts": [ + "80" + ], + "environmentVariables": [], + "volumes": [ + { + "name": "nextcloud_aio_onlyoffice", + "location": "/var/lib/onlyoffice", + "writeable": true + } + ], + "secrets": [], + "maxShutdownTime": 10, + "restartPolicy": "unless-stopped" } ] } diff --git a/php/public/disable-collabora.js b/php/public/disable-collabora.js new file mode 100644 index 00000000..d6a4ce02 --- /dev/null +++ b/php/public/disable-collabora.js @@ -0,0 +1,5 @@ +document.addEventListener("DOMContentLoaded", function(event) { + // Collabora + var collabora = document.getElementById("collabora"); + collabora.disabled = true; +}); \ No newline at end of file diff --git a/php/public/disable-onlyoffice.js b/php/public/disable-onlyoffice.js new file mode 100644 index 00000000..9dd5b532 --- /dev/null +++ b/php/public/disable-onlyoffice.js @@ -0,0 +1,5 @@ +document.addEventListener("DOMContentLoaded", function(event) { + // OnlyOffice + var onlyoffice = document.getElementById("onlyoffice"); + onlyoffice.disabled = true; +}); \ No newline at end of file diff --git a/php/public/disable-talk.js b/php/public/disable-talk.js new file mode 100644 index 00000000..7b4a8719 --- /dev/null +++ b/php/public/disable-talk.js @@ -0,0 +1,5 @@ +document.addEventListener("DOMContentLoaded", function(event) { + // Talk + var talk = document.getElementById("talk"); + talk.disabled = true; +}); \ No newline at end of file diff --git a/php/public/index.php b/php/public/index.php index c5752a79..bb6aaf20 100644 --- a/php/public/index.php +++ b/php/public/index.php @@ -87,6 +87,9 @@ $app->get('/containers', function ($request, $response, $args) use ($container) 'current_channel' => $dockerActionManger->GetCurrentChannel(), 'is_x64_platform' => $configurationManager->isx64Platform(), 'is_clamav_enabled' => $configurationManager->isClamavEnabled(), + 'is_onlyoffice_enabled' => $configurationManager->isOnlyofficeEnabled(), + 'is_collabora_enabled' => $configurationManager->isCollaboraEnabled(), + 'is_talk_enabled' => $configurationManager->isTalkEnabled(), ]); })->setName('profile'); $app->get('/login', function ($request, $response, $args) use ($container) { diff --git a/php/public/options-form-submit.js b/php/public/options-form-submit.js index f09e71cf..fc63fb29 100644 --- a/php/public/options-form-submit.js +++ b/php/public/options-form-submit.js @@ -11,4 +11,16 @@ document.addEventListener("DOMContentLoaded", function(event) { // Clamav var clamav = document.getElementById("clamav"); clamav.addEventListener('change', makeOptionsFormSubmitVisible); + + // OnlyOffice + var onlyoffice = document.getElementById("onlyoffice"); + onlyoffice.addEventListener('change', makeOptionsFormSubmitVisible); + + // Collabora + var collabora = document.getElementById("collabora"); + collabora.addEventListener('change', makeOptionsFormSubmitVisible); + + // Talk + var talk = document.getElementById("talk"); + talk.addEventListener('change', makeOptionsFormSubmitVisible); }); diff --git a/php/src/ContainerDefinitionFetcher.php b/php/src/ContainerDefinitionFetcher.php index 32e1d8ba..92744df7 100644 --- a/php/src/ContainerDefinitionFetcher.php +++ b/php/src/ContainerDefinitionFetcher.php @@ -53,6 +53,18 @@ class ContainerDefinitionFetcher if (!$this->configurationManager->isClamavEnabled()) { continue; } + } elseif ($entry['identifier'] === 'nextcloud-aio-onlyoffice') { + if (!$this->configurationManager->isOnlyofficeEnabled()) { + continue; + } + } elseif ($entry['identifier'] === 'nextcloud-aio-collabora') { + if (!$this->configurationManager->isCollaboraEnabled()) { + continue; + } + } elseif ($entry['identifier'] === 'nextcloud-aio-talk') { + if (!$this->configurationManager->isTalkEnabled()) { + continue; + } } $ports = new ContainerPorts(); @@ -111,6 +123,18 @@ class ContainerDefinitionFetcher if (!$this->configurationManager->isClamavEnabled()) { continue; } + } elseif ($value === 'nextcloud-aio-onlyoffice') { + if (!$this->configurationManager->isOnlyofficeEnabled()) { + continue; + } + } elseif ($value === 'nextcloud-aio-collabora') { + if (!$this->configurationManager->isCollaboraEnabled()) { + continue; + } + } elseif ($value === 'nextcloud-aio-talk') { + if (!$this->configurationManager->isTalkEnabled()) { + continue; + } } $dependsOn[] = $value; } diff --git a/php/src/Controller/ConfigurationController.php b/php/src/Controller/ConfigurationController.php index 78261ad4..d17db27d 100644 --- a/php/src/Controller/ConfigurationController.php +++ b/php/src/Controller/ConfigurationController.php @@ -36,11 +36,29 @@ class ConfigurationController } if (isset($request->getParsedBody()['options-form'])) { + if (isset($request->getParsedBody()['collabora']) && isset($request->getParsedBody()['onlyoffice'])) { + throw new InvalidSettingConfigurationException("Collabora and Onlyoffice are not allowed to be enabled at the same time!"); + } if (isset($request->getParsedBody()['clamav'])) { $this->configurationManager->SetClamavEnabledState(1); } else { $this->configurationManager->SetClamavEnabledState(0); } + if (isset($request->getParsedBody()['onlyoffice'])) { + $this->configurationManager->SetOnlyofficeEnabledState(1); + } else { + $this->configurationManager->SetOnlyofficeEnabledState(0); + } + if (isset($request->getParsedBody()['collabora'])) { + $this->configurationManager->SetCollaboraEnabledState(1); + } else { + $this->configurationManager->SetCollaboraEnabledState(0); + } + if (isset($request->getParsedBody()['talk'])) { + $this->configurationManager->SetTalkEnabledState(1); + } else { + $this->configurationManager->SetTalkEnabledState(0); + } } return $response->withStatus(201)->withHeader('Location', '/'); diff --git a/php/src/Data/ConfigurationManager.php b/php/src/Data/ConfigurationManager.php index 434c572d..e1423790 100644 --- a/php/src/Data/ConfigurationManager.php +++ b/php/src/Data/ConfigurationManager.php @@ -139,6 +139,51 @@ class ConfigurationManager $this->WriteConfig($config); } + public function isOnlyofficeEnabled() : bool { + $config = $this->GetConfig(); + if (isset($config['isOnlyofficeEnabled']) && $config['isOnlyofficeEnabled'] === 1) { + return true; + } else { + return false; + } + } + + public function SetOnlyofficeEnabledState(int $value) : void { + $config = $this->GetConfig(); + $config['isOnlyofficeEnabled'] = $value; + $this->WriteConfig($config); + } + + public function isCollaboraEnabled() : bool { + $config = $this->GetConfig(); + if (isset($config['isCollaboraEnabled']) && $config['isCollaboraEnabled'] === 0) { + return false; + } else { + return true; + } + } + + public function SetCollaboraEnabledState(int $value) : void { + $config = $this->GetConfig(); + $config['isCollaboraEnabled'] = $value; + $this->WriteConfig($config); + } + + public function isTalkEnabled() : bool { + $config = $this->GetConfig(); + if (isset($config['isTalkEnabled']) && $config['isTalkEnabled'] === 0) { + return false; + } else { + return true; + } + } + + public function SetTalkEnabledState(int $value) : void { + $config = $this->GetConfig(); + $config['isTalkEnabled'] = $value; + $this->WriteConfig($config); + } + /** * @throws InvalidSettingConfigurationException */ diff --git a/php/src/Docker/DockerActionManager.php b/php/src/Docker/DockerActionManager.php index d9c1ee51..c84279ea 100644 --- a/php/src/Docker/DockerActionManager.php +++ b/php/src/Docker/DockerActionManager.php @@ -247,6 +247,24 @@ class DockerActionManager } else { $replacements[1] = ''; } + } elseif ($out[1] === 'ONLYOFFICE_ENABLED') { + if ($this->configurationManager->isOnlyofficeEnabled()) { + $replacements[1] = 'yes'; + } else { + $replacements[1] = ''; + } + } elseif ($out[1] === 'COLLABORA_ENABLED') { + if ($this->configurationManager->isCollaboraEnabled()) { + $replacements[1] = 'yes'; + } else { + $replacements[1] = ''; + } + } elseif ($out[1] === 'TALK_ENABLED') { + if ($this->configurationManager->isTalkEnabled()) { + $replacements[1] = 'yes'; + } else { + $replacements[1] = ''; + } } else { $replacements[1] = $this->configurationManager->GetSecret($out[1]); } diff --git a/php/templates/containers.twig b/php/templates/containers.twig index 2526e7b0..e8946a9b 100644 --- a/php/templates/containers.twig +++ b/php/templates/containers.twig @@ -299,10 +299,30 @@ {% else %} {% endif %} + {% if is_collabora_enabled == true %} + + {% else %} + + {% endif %} + {% if is_onlyoffice_enabled == true %} + + {% else %} + + {% endif %} + {% if is_talk_enabled == true %} + + {% else %} + + {% endif %} {% if isAnyRunning == true or is_x64_platform == false %} + + {% endif %} + {% if isAnyRunning == true %} + + {% endif %} {% endif %} {% endif %}