From b3d018c506e9f351e8a80cb4da1b71c56f71e52c Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Wed, 25 Apr 2018 12:27:40 +0200 Subject: [PATCH] corrected usage of default redirect code from settings; fixes #546 Signed-off-by: Michael Kaufmann --- lib/functions/output/function.RedirectCode.php | 18 ++++++++++++++---- scripts/jobs/cron_tasks.inc.http.10.apache.php | 2 +- .../jobs/cron_tasks.inc.http.20.lighttpd.php | 2 +- scripts/jobs/cron_tasks.inc.http.30.nginx.php | 2 +- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/functions/output/function.RedirectCode.php b/lib/functions/output/function.RedirectCode.php index c5df262c..5a8cd57d 100644 --- a/lib/functions/output/function.RedirectCode.php +++ b/lib/functions/output/function.RedirectCode.php @@ -36,9 +36,11 @@ function getRedirectCodesArray() { * return an array of all enabled redirect-codes * for the settings form * + * @param bool $add_desc optional, default true, add the code-description + * * @return array array of enabled redirect-codes */ -function getRedirectCodes() { +function getRedirectCodes($add_desc = true) { global $lng; @@ -47,7 +49,10 @@ function getRedirectCodes() { $codes = array(); while ($rc = $result_stmt->fetch(PDO::FETCH_ASSOC)) { - $codes[$rc['id']] = $rc['code']. ' ('.$lng['redirect_desc'][$rc['desc']].')'; + $codes[$rc['id']] = $rc['code']; + if ($add_desc) { + $codes[$rc['id']] .= ' ('.$lng['redirect_desc'][$rc['desc']].')'; + } } return $codes; @@ -58,12 +63,17 @@ function getRedirectCodes() { * domain-id * * @param integer $domainid id of the domain - * @param string $default * * @return string redirect-code */ -function getDomainRedirectCode($domainid = 0, $default = '') { +function getDomainRedirectCode($domainid = 0) { + // get system default + $default = '301'; + if (Settings::Get('customredirect.enabled') == '1') { + $all_codes = getRedirectCodes(false); + $default = $all_codes[Settings::Get('customredirect.default')]; + } $code = $default; if ($domainid > 0) { diff --git a/scripts/jobs/cron_tasks.inc.http.10.apache.php b/scripts/jobs/cron_tasks.inc.http.10.apache.php index 21225125..fc436219 100644 --- a/scripts/jobs/cron_tasks.inc.http.10.apache.php +++ b/scripts/jobs/cron_tasks.inc.http.10.apache.php @@ -964,7 +964,7 @@ class apache extends HttpConfigBase $corrected_docroot = $domain['documentroot']; // Get domain's redirect code - $code = getDomainRedirectCode($domain['id'], '301'); + $code = getDomainRedirectCode($domain['id']); $modrew_red = ''; if ($code != '') { $modrew_red = ' [R=' . $code . ';L,NE]'; diff --git a/scripts/jobs/cron_tasks.inc.http.20.lighttpd.php b/scripts/jobs/cron_tasks.inc.http.20.lighttpd.php index 84b88400..661005f6 100644 --- a/scripts/jobs/cron_tasks.inc.http.20.lighttpd.php +++ b/scripts/jobs/cron_tasks.inc.http.20.lighttpd.php @@ -467,7 +467,7 @@ class lighttpd extends HttpConfigBase $uri = $domain['documentroot']; // Get domain's redirect code - $code = getDomainRedirectCode($domain['id'], '301'); + $code = getDomainRedirectCode($domain['id']); $vhost_content .= ' url.redirect-code = ' . $code. "\n"; $vhost_content .= ' url.redirect = (' . "\n"; diff --git a/scripts/jobs/cron_tasks.inc.http.30.nginx.php b/scripts/jobs/cron_tasks.inc.http.30.nginx.php index e2eac04d..a979463b 100644 --- a/scripts/jobs/cron_tasks.inc.http.30.nginx.php +++ b/scripts/jobs/cron_tasks.inc.http.30.nginx.php @@ -486,7 +486,7 @@ class nginx extends HttpConfigBase } // Get domain's redirect code - $code = getDomainRedirectCode($domain['id'], '301'); + $code = getDomainRedirectCode($domain['id']); $vhost_content .= "\t" . 'if ($request_uri !~ ^/.well-known/acme-challenge/\w+$) {' . "\n"; $vhost_content .= "\t\t" . 'return ' . $code .' ' . $uri . '$request_uri;' . "\n";