From 2aea63e8b504b58ea40731d6f3b03adf95667dc0 Mon Sep 17 00:00:00 2001 From: Igor Matheus Andrade Torrente Date: Tue, 3 Aug 2021 18:54:43 -0300 Subject: [PATCH 1/2] Rework the setAdminSettings function at SettingsController.php This rework fixes the error bellow: Error: array_filter() expects parameter 1 to be array, null given at /var/www/nextcloud/apps/roundcube/lib/Controller/SettingsController.php#149 This error log happens when the admin tries to save the config without setting the 'Per email domain RC installations'. Signed-off-by: Igor Matheus Andrade Torrente --- .../lib/Controller/SettingsController.php | 81 +++++++++---------- 1 file changed, 37 insertions(+), 44 deletions(-) diff --git a/roundcube/lib/Controller/SettingsController.php b/roundcube/lib/Controller/SettingsController.php index 3362250..94ac1de 100644 --- a/roundcube/lib/Controller/SettingsController.php +++ b/roundcube/lib/Controller/SettingsController.php @@ -37,7 +37,9 @@ class SettingsController extends Controller /** @var config */ private $config; - public function __construct(string $AppName, IRequest $request, IConfig $config, IURLGenerator $urlGenerator, IL10N $l) { + public function __construct(string $AppName, IRequest $request, IConfig $config, + IURLGenerator $urlGenerator, IL10N $l) + { parent::__construct($AppName, $request); $this->urlGenerator = $urlGenerator; $this->config = $config; @@ -72,57 +74,37 @@ public function setAdminSettings() { $enableSSLVerify = $req->getParam('enableSSLVerify', null); // Validate and do a first fix of some values. - $validation = array(); if (!is_string($defaultRCPath) || $defaultRCPath === '') - $validation[] = $l->t("Default RC installation path can't be an empty string."); - elseif (preg_match('/^([a-zA-Z]+:)?\/\//', $defaultRCPath) === 1) - $validation[] = $l->t("Default path must be a url relative to this server."); - else - $defaultRCPath = trim($defaultRCPath); - - if(isset($rcDomains) && is_array($rcDomains)) { - foreach ($rcDomains as &$dom) { - if (!is_string($dom) || preg_match('/(@|\/)/', $dom) === 1) { - $validation[] = $l->t("A domain is not valid."); - break; - } else { - $dom = trim($dom); - } - } + return self::error_response($l->t("Default RC installation path can't be an empty string.")); + else if (preg_match('/^([a-zA-Z]+:)?\/\//', $defaultRCPath) === 1) + return self::error_response($l->t("Default path must be a url relative to this server.")); + + $defaultRCPath = ltrim(trim($defaultRCPath)); + + if (!is_array($rcDomains) || !is_array($rcPaths)) { + $this->config->setAppValue($appName, 'domainPath', array()); + goto success_output; + } + + foreach ($rcDomains as &$dom) { + if (!is_string($dom) || preg_match('/(@|\/)/', $dom) === 1) + return self::error_response($l->t("A domain is not valid.")); + else + $dom = trim($dom); } - if(isset($rcPaths) && is_array($rcPaths)) foreach ($rcPaths as &$path) { - if (!is_string($path)) { - $validation[] = $l->t("A path is not valid."); - break; - } + foreach ($rcPaths as &$path) { + if (!is_string($path)) + return self::error_response($l->t("A path is not valid.")); $path = trim($path); - if (preg_match('/^([a-zA-Z]+:)?\/\//', $path) === 1 || $path === '') { - $validation[] = $l->t("Paths must be urls relative to this server."); - break; - } else { + if (preg_match('/^([a-zA-Z]+:)?\/\//', $path) === 1 || $path === '') + return self::error_response($l->t("Paths must be urls relative to this server.")); + else $path = ltrim($path, " /"); - } - } - - $rcDomains !== $rcPaths; - if (is_iterable($rcDomains)) { - $validation[] = $l->t("Unpaired domains and paths."); - } - - // Won't change anything if validation fails. - if (!empty($validation)) { - return new JSONResponse(array( - 'status' => 'error', - 'message' => $l->t("Some inputs are not valid."), - 'invalid' => $validation - )); } // Passed validation. - $defaultRCPath = ltrim($defaultRCPath, " /"); - $this->config->setAppValue($appName, 'defaultRCPath', $defaultRCPath); $domainPath = json_encode(array_filter( array_combine($rcDomains, $rcPaths), function($v, $k) { @@ -130,8 +112,11 @@ function($v, $k) { }, ARRAY_FILTER_USE_BOTH )); - $this->config->setAppValue($appName, 'domainPath', $domainPath); + +success_output: + $this->config->setAppValue($appName, 'defaultRCPath', $defaultRCPath); + $checkBoxes = array('showTopLine', 'enableSSLVerify'); foreach ($checkBoxes as $c) { $this->config->setAppValue($appName, $c, $$c !== null); @@ -143,4 +128,12 @@ function($v, $k) { 'config' => array('defaultRCPath' => $defaultRCPath) )); } + + protected function error_response(string $validation): JSONResponse { + return new JSONResponse(array( + 'status' => 'error', + 'message' => $this->l->t("Some inputs are not valid."), + 'invalid' => array($validation) + )); + } } From e2b1e5a03d2769affdd60776830cdc6e718aff9a Mon Sep 17 00:00:00 2001 From: Igor Matheus Andrade Torrente Date: Tue, 3 Aug 2021 18:43:50 -0300 Subject: [PATCH 2/2] Adjust a log level in the InternalAddress.php If the admin doesn't configure the 'Per email domain installation', a log was emittied every time that someone logged into the Roundcube. This is annoying and unnecessary. I adjusted the log to not be visible unless under a more sensible log level. Signed-off-by: Igor Matheus Andrade Torrente --- roundcube/lib/InternalAddress.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roundcube/lib/InternalAddress.php b/roundcube/lib/InternalAddress.php index fbc9164..377d137 100644 --- a/roundcube/lib/InternalAddress.php +++ b/roundcube/lib/InternalAddress.php @@ -89,7 +89,7 @@ private function getRCPath($domain) { $domainPath = json_decode($jsonDomainPath, true); if (!is_array($domainPath)) { - Utils::log_warning($this->logger, "Json decoded is not an array."); + Utils::log_notice($this->logger, "Json decoded is not an array."); return $defaultRCPath; }