urlGenerator = $urlGenerator; $this->trans = $trans; $this->logger = $logger; $this->config = $config; $this->crypt = $crypt; } /** * Print config section * * @return TemplateResponse */ public function index() { $data = [ "documentserver" => $this->config->GetDocumentServerUrl(), "documentserverInternal" => $this->config->GetDocumentServerInternalUrl(true), "storageUrl" => $this->config->GetStorageUrl(), "secret" => $this->config->GetDocumentServerSecret(), "currentServer" => $this->urlGenerator->getAbsoluteURL("/"), "formats" => $this->config->FormatsSetting(), "sameTab" => $this->config->GetSameTab(), "limitGroups" => $this->config->GetLimitGroups(), "chat" => $this->config->GetCustomizationChat(), "compactHeader" => $this->config->GetCustomizationCompactHeader(), "feedback" => $this->config->GetCustomizationFeedback(), "help" => $this->config->GetCustomizationHelp(), "toolbarNoTabs" => $this->config->GetCustomizationToolbarNoTabs(), "successful" => $this->config->SettingsAreSuccessful() ]; return new TemplateResponse($this->appName, "settings", $data, "blank"); } /** * Save address settings * * @param string $documentserver - document service address * @param string $documentserverInternal - document service address available from Nextcloud * @param string $storageUrl - Nextcloud address available from document server * @param string $secret - secret key for signature * * @return array */ public function SaveAddress($documentserver, $documentserverInternal, $storageUrl, $secret ) { $this->config->SetDocumentServerUrl($documentserver); $this->config->SetDocumentServerInternalUrl($documentserverInternal); $this->config->SetStorageUrl($storageUrl); $this->config->SetDocumentServerSecret($secret); $documentserver = $this->config->GetDocumentServerUrl(); $error = NULL; if (!empty($documentserver)) { $error = $this->checkDocServiceUrl(); $this->config->SetSettingsError($error); } return [ "documentserver" => $this->config->GetDocumentServerUrl(), "documentserverInternal" => $this->config->GetDocumentServerInternalUrl(true), "storageUrl" => $this->config->GetStorageUrl(), "secret" => $this->config->GetDocumentServerSecret(), "error" => $error ]; } /** * Save common settings * * @param array $defFormats - formats array with default action * @param array $editFormats - editable formats array * @param bool $sameTab - open in the same tab * @param array $limitGroups - list of groups * @param bool $chat - display chat * @param bool $compactHeader - display compact header * @param bool $feedback - display feedback * @param bool $help - display help * @param bool $toolbarNoTabs - display toolbar tab * * @return array */ public function SaveCommon($defFormats, $editFormats, $sameTab, $limitGroups, $chat, $compactHeader, $feedback, $help, $toolbarNoTabs ) { $this->config->SetDefaultFormats($defFormats); $this->config->SetEditableFormats($editFormats); $this->config->SetSameTab($sameTab); $this->config->SetLimitGroups($limitGroups); $this->config->SetCustomizationChat($chat); $this->config->SetCustomizationCompactHeader($compactHeader); $this->config->SetCustomizationFeedback($feedback); $this->config->SetCustomizationHelp($help); $this->config->SetCustomizationToolbarNoTabs($toolbarNoTabs); return [ ]; } /** * Get app settings * * @return array * * @NoAdminRequired * @PublicPage */ public function GetSettings() { $result = [ "formats" => $this->config->FormatsSetting(), "sameTab" => $this->config->GetSameTab() ]; return $result; } /** * Checking document service location * * @return string */ private function checkDocServiceUrl() { try { if (preg_match("/^https:\/\//i", $this->urlGenerator->getAbsoluteURL("/")) && preg_match("/^http:\/\//i", $this->config->GetDocumentServerUrl())) { throw new \Exception($this->trans->t("Mixed Active Content is not allowed. HTTPS address for Document Server is required.")); } } catch (\Exception $e) { $this->logger->error("Protocol on check error: " . $e->getMessage(), array("app" => $this->appName)); return $e->getMessage(); } try { $documentService = new DocumentService($this->trans, $this->config); $healthcheckResponse = $documentService->HealthcheckRequest(); if (!$healthcheckResponse) { throw new \Exception($this->trans->t("Bad healthcheck status")); } } catch (\Exception $e) { $this->logger->error("HealthcheckRequest on check error: " . $e->getMessage(), array("app" => $this->appName)); return $e->getMessage(); } try { $documentService = new DocumentService($this->trans, $this->config); $commandResponse = $documentService->CommandRequest("version"); $this->logger->debug("CommandRequest on check: " . json_encode($commandResponse), array("app" => $this->appName)); if (empty($commandResponse)) { throw new \Exception($this->trans->t("Error occurred in the document service")); } $version = floatval($commandResponse->version); if ($version > 0.0 && $version < 4.2) { throw new \Exception($this->trans->t("Not supported version")); } } catch (\Exception $e) { $this->logger->error("CommandRequest on check error: " . $e->getMessage(), array("app" => $this->appName)); return $e->getMessage(); } $convertedFileUri; try { $hashUrl = $this->crypt->GetHash(["action" => "empty"]); $fileUrl = $this->urlGenerator->linkToRouteAbsolute($this->appName . ".callback.emptyfile", ["doc" => $hashUrl]); if (!empty($this->config->GetStorageUrl())) { $fileUrl = str_replace($this->urlGenerator->getAbsoluteURL("/"), $this->config->GetStorageUrl(), $fileUrl); } $convertedFileUri = $documentService->GetConvertedUri($fileUrl, "docx", "docx", "check_" . rand()); } catch (\Exception $e) { $this->logger->error("GetConvertedUri on check error: " . $e->getMessage(), array("app" => $this->appName)); return $e->getMessage(); } try { $documentService->Request($convertedFileUri); } catch (\Exception $e) { $this->logger->error("Request converted file on check error: " . $convertedFileUri . " " . $e->getMessage(), array("app" => $this->appName)); return $e->getMessage(); } return ""; } }