Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 37 additions & 44 deletions roundcube/lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -72,66 +74,49 @@ 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) {
return $k !== '' && $v !== '';
},
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);
Expand All @@ -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)
));
}
}
2 changes: 1 addition & 1 deletion roundcube/lib/InternalAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down