From 345b0c0c464a793b1eaca0dd50352c8a2487f769 Mon Sep 17 00:00:00 2001 From: kai-yin Date: Tue, 1 Jun 2021 16:47:27 +0800 Subject: [PATCH 1/3] Check the file url into a complete url to support onlyoffice documentservice behind a reverse proxy with extra parts in url. --- lib/documentservice.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/documentservice.php b/lib/documentservice.php index 308d1d68..e9d8ce1d 100644 --- a/lib/documentservice.php +++ b/lib/documentservice.php @@ -97,7 +97,12 @@ function GetConvertedUri($document_uri, $from_extension, $to_extension, $documen $isEndConvert = $responceFromConvertService->EndConvert; if ($isEndConvert !== null && strtolower($isEndConvert) === "true") { - return $responceFromConvertService->FileUrl; + $fileUrl = $responceFromConvertService->FileUrl; + if ( strpos($fileUrl, "http://") !== 0 && strpos($fileUrl, "https://") !== 0 ){ + $url = parse_url($document_uri); + $fileUrl = $url["scheme"]."://".$url['host'].$fileUrl ; + } + return $fileUrl; } return ""; From 9cd412d084e8aac5943415fb580e32cd66dda81b Mon Sep 17 00:00:00 2001 From: kai-yin Date: Thu, 3 Jun 2021 10:43:57 +0800 Subject: [PATCH 2/3] Optimise the judge of incomplete url and add the port part of url. --- lib/documentservice.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/documentservice.php b/lib/documentservice.php index e9d8ce1d..cda97d99 100644 --- a/lib/documentservice.php +++ b/lib/documentservice.php @@ -98,10 +98,11 @@ function GetConvertedUri($document_uri, $from_extension, $to_extension, $documen if ($isEndConvert !== null && strtolower($isEndConvert) === "true") { $fileUrl = $responceFromConvertService->FileUrl; - if ( strpos($fileUrl, "http://") !== 0 && strpos($fileUrl, "https://") !== 0 ){ + if ( !preg_match("/^https?:\/\//i", $fileUrl) ){ $url = parse_url($document_uri); - $fileUrl = $url["scheme"]."://".$url['host'].$fileUrl ; + $fileUrl = $url["scheme"] . "://" . $url['host'] . (array_key_exists("port", $url) ? (":" . $url["port"]) : "") . $fileUrl ; } + return $fileUrl; } From 90ebcbd3842ca4d7fa9b21c9eeaf1b5a421edd71 Mon Sep 17 00:00:00 2001 From: kai-yin Date: Thu, 3 Jun 2021 10:45:47 +0800 Subject: [PATCH 3/3] Convert an incomplete url into a complete one. --- lib/appconfig.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/appconfig.php b/lib/appconfig.php index 3d0d6f34..c33cbe6c 100644 --- a/lib/appconfig.php +++ b/lib/appconfig.php @@ -457,11 +457,27 @@ public function GetDocumentServerInternalUrl($origin = false) { * @return string */ public function ReplaceDocumentServerUrlToInternal($url) { + // GetDocumentServerInternalUrl() will be the same with GetDocumentServerUrl() if internal url is not specified. $documentServerUrl = $this->GetDocumentServerInternalUrl(); + if (!empty($documentServerUrl)) { $from = $this->GetDocumentServerUrl(); + if (!preg_match("/^https?:\/\//i", $url)){ + // $url is not a complete url. Form it with $from + $parsedUrl = parse_url($from); + + // $url may include VPATH. Judge it to avoid dupe. + // https://github.com/ONLYOFFICE/document-server-proxy/blob/master/apache/proxy-to-virtual-path.conf + $vpath = $parsedUrl["path"]; + if (empty($vpath)){ + $vpath = "/"; + } + $url = $from.preg_filter("#^$vpath#i", "", $url, 1); + } + if (!preg_match("/^https?:\/\//i", $from)) { + // Frontend forbids input incomplete url, so this will never happen? $parsedUrl = parse_url($url); $from = $parsedUrl["scheme"] . "://" . $parsedUrl["host"] . (array_key_exists("port", $parsedUrl) ? (":" . $parsedUrl["port"]) : "") . $from; }