From 74da53c82275b14a7930e4f11db8b3a574b73c52 Mon Sep 17 00:00:00 2001 From: "Michael Kaufmann (d00p)" Date: Thu, 5 Aug 2010 07:10:27 +0000 Subject: [PATCH] - allow setting path-to-file or simple-string as error-document (only file is valid for lighttpd), fixes #267 --- customer_extras.php | 64 ++--------------- .../froxlor/function.CorrectErrorDocument.php | 68 +++++++++++++++++++ lng/english.lng.php | 11 +-- lng/german.lng.php | 11 +-- templates/customer/extras/htaccess_add.tpl | 6 +- templates/customer/extras/htaccess_edit.tpl | 6 +- 6 files changed, 94 insertions(+), 72 deletions(-) create mode 100644 lib/functions/froxlor/function.CorrectErrorDocument.php diff --git a/customer_extras.php b/customer_extras.php index af426067..3c35251a 100644 --- a/customer_extras.php +++ b/customer_extras.php @@ -309,35 +309,9 @@ elseif($page == 'htaccess') $options_cgi = '0'; } - if(($_POST['error404path'] === '') - || (validateUrl($idna_convert->encode($_POST['error404path'])))) - { - $error404path = $_POST['error404path']; - } - else - { - standard_error('mustbeurl'); - } - - if(($_POST['error403path'] === '') - || (validateUrl($idna_convert->encode($_POST['error403path'])))) - { - $error403path = $_POST['error403path']; - } - else - { - standard_error('mustbeurl'); - } - - if(($_POST['error500path'] === '') - || (validateUrl($idna_convert->encode($_POST['error500path'])))) - { - $error500path = $_POST['error500path']; - } - else - { - standard_error('mustbeurl'); - } + $error404path = correctErrorDocument($_POST['error404path']); + $error403path = correctErrorDocument($_POST['error403path']); + $error500path = correctErrorDocument($_POST['error500path']); if($path_dupe_check['path'] == $path) { @@ -397,35 +371,9 @@ elseif($page == 'htaccess') $options_cgi = '0'; } - if(($_POST['error404path'] === '') - || (validateUrl($idna_convert->encode($_POST['error404path'])))) - { - $error404path = $_POST['error404path']; - } - else - { - standard_error('mustbeurl'); - } - - if(($_POST['error403path'] === '') - || (validateUrl($idna_convert->encode($_POST['error403path'])))) - { - $error403path = $_POST['error403path']; - } - else - { - standard_error('mustbeurl'); - } - - if(($_POST['error500path'] === '') - || (validateUrl($idna_convert->encode($_POST['error500path'])))) - { - $error500path = $_POST['error500path']; - } - else - { - standard_error('mustbeurl'); - } + $error404path = correctErrorDocument($_POST['error404path']); + $error403path = correctErrorDocument($_POST['error403path']); + $error500path = correctErrorDocument($_POST['error500path']); if(($option_indexes != $result['options_indexes']) || ($error404path != $result['error404path']) diff --git a/lib/functions/froxlor/function.CorrectErrorDocument.php b/lib/functions/froxlor/function.CorrectErrorDocument.php new file mode 100644 index 00000000..09e86175 --- /dev/null +++ b/lib/functions/froxlor/function.CorrectErrorDocument.php @@ -0,0 +1,68 @@ + (2010-) + * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt + * @package Functions + * @version $Id$ + */ + +/* + * this functions validates a given value as ErrorDocument + * refs #267 + * + * @param string error-document-string + * + * @return string error-document-string + * + */ + function correctErrorDocument($errdoc = null) + { + global $idna_convert; + + if($errdoc !== null && $errdoc != '') + { + // not a URL + if(!validateUrl($idna_convert->encode($errdoc))) + { + // a file + if(substr($errdoc, 0, 1) != '"') + { + $errdoc = makeCorrectFile($errdoc); + // apache needs a starting-slash (starting at the domains-docroot) + if(!substr($errdoc, 0, 1) == '/') { + $errdoc = '/'.$errdoc; + } + } + // a string (check for ending ") + else + { + // string won't work for lighty + if($settings['system']['webserver'] == 'lighttpd') + { + standard_error('stringerrordocumentnotvalidforlighty'); + } + elseif(substr($errdoc, -1) != '"') + { + $errdoc .= '"'; + } + } + } + else + { + if($settings['system']['webserver'] == 'lighttpd') + { + standard_error('urlerrordocumentnotvalidforlighty'); + } + } + } + return $errdoc; + } diff --git a/lng/english.lng.php b/lng/english.lng.php index 74dda352..bb97b203 100644 --- a/lng/english.lng.php +++ b/lng/english.lng.php @@ -171,10 +171,10 @@ $lng['extras']['error404path'] = '404'; $lng['extras']['error403path'] = '403'; $lng['extras']['error500path'] = '500'; $lng['extras']['error401path'] = '401'; -$lng['extras']['errordocument404path'] = 'URL to ErrorDocument 404'; -$lng['extras']['errordocument403path'] = 'URL to ErrorDocument 403'; -$lng['extras']['errordocument500path'] = 'URL to ErrorDocument 500'; -$lng['extras']['errordocument401path'] = 'URL to ErrorDocument 401'; +$lng['extras']['errordocument404path'] = 'ErrorDocument 404'; +$lng['extras']['errordocument403path'] = 'ErrorDocument 403'; +$lng['extras']['errordocument500path'] = 'ErrorDocument 500'; +$lng['extras']['errordocument401path'] = 'ErrorDocument 401'; /** * Errors @@ -1464,5 +1464,8 @@ $lng['serversettings']['perl']['suexecworkaround']['title'] = 'Enable SuExec wor $lng['serversettings']['perl']['suexecworkaround']['description'] = 'Enable only if customer docroots are not within the apache suexec path.
If enabled, Froxlor will generate a symlink from the customers perl-enabled directory + /cgi-bin/ to the given path.
Note that perl will then only work in the folders subdirectory /cgi-bin/ and not in the folder itself (as it does without this fix!)'; $lng['serversettings']['perl']['suexeccgipath']['title'] = 'Path for customer perl-enabled directory symlinks'; $lng['serversettings']['perl']['suexeccgipath']['description'] = 'You only need to set this if the SuExec-workaround is enabled.
ATTENTION: Be sure this path is within the suexec path or else this workaround is uselsess'; +$lng['panel']['descriptionerrordocument'] = 'Can be an URL, path to a file or just a string wrapped around " "
Leave empty to use server default value.'; +$lng['error']['stringerrordocumentnotvalidforlighty'] = 'A string as ErrorDocument does not work in lighttpd, please specify a path to a file'; +$lng['error']['urlerrordocumentnotvalidforlighty'] = 'An URL as ErrorDocument does not work in lighttpd, please specify a path to a file'; ?> diff --git a/lng/german.lng.php b/lng/german.lng.php index b63adc7f..148f3248 100644 --- a/lng/german.lng.php +++ b/lng/german.lng.php @@ -171,10 +171,10 @@ $lng['extras']['error404path'] = '404'; $lng['extras']['error403path'] = '403'; $lng['extras']['error500path'] = '500'; $lng['extras']['error401path'] = '401'; -$lng['extras']['errordocument404path'] = 'URL zum Fehlerdokument 404'; -$lng['extras']['errordocument403path'] = 'URL zum Fehlerdokument 403'; -$lng['extras']['errordocument500path'] = 'URL zum Fehlerdokument 500'; -$lng['extras']['errordocument401path'] = 'URL zum Fehlerdokument 401'; +$lng['extras']['errordocument404path'] = 'Fehlerdokument 404'; +$lng['extras']['errordocument403path'] = 'Fehlerdokument 403'; +$lng['extras']['errordocument500path'] = 'Fehlerdokument 500'; +$lng['extras']['errordocument401path'] = 'Fehlerdokument 401'; /** * Errors @@ -1447,5 +1447,8 @@ $lng['serversettings']['perl']['suexecworkaround']['title'] = 'Aktiviere SuExec $lng['serversettings']['perl']['suexecworkaround']['description'] = 'Aktivieren Sie den Workaround nur, wenn die Kunden-Heimatverzeichnise sich nicht unterhalb des suexec-Pfades liegen.
Wenn aktiviert erstellt Froxlor eine Verknüpfung des vom Kunden für Perl aktiviertem Pfad + /cgi-bin/ im angegebenen suexec-Pfad.
Bitte beachten Sie, dass Perl dann nur im Unterordner /cgi-bin/ des Kunden-Ordners funktioniert und nicht direkt in diesem Ordner (wie es ohne den Workaround wäre!)'; $lng['serversettings']['perl']['suexeccgipath']['title'] = 'Pfad für Verknüpfungen zu Kunden-Perl-Verzeichnis'; $lng['serversettings']['perl']['suexeccgipath']['description'] = 'Diese Einstellung wird nur benötigt, wenn der SuExec-Workaround aktiviert ist.
ACHTUNG: Stellen Sie sicher, dass sich der angegebene Pfad innerhalb des Suexec-Pfades befindet ansonsten ist der Workaround nutzlos'; +$lng['panel']['descriptionerrordocument'] = 'Mögliche Werte sind: URL, Pfad zu einer Datei oder ein Text umgeben von Anführungszeichen (" ")
Leer für Server-Standardwerd.'; +$lng['error']['stringerrordocumentnotvalidforlighty'] = 'Ein Text als Fehlerdokument funktioniert leider in LigHTTPd nicht, bitte geben Sie einen Pfad zu einer Datei an'; +$lng['error']['urlerrordocumentnotvalidforlighty'] = 'Eine URL als Fehlerdokument funktioniert leider in LigHTTPd nicht, bitte geben Sie einen Pfad zu einer Datei an'; ?> diff --git a/templates/customer/extras/htaccess_add.tpl b/templates/customer/extras/htaccess_add.tpl index ed48db73..c7464364 100644 --- a/templates/customer/extras/htaccess_add.tpl +++ b/templates/customer/extras/htaccess_add.tpl @@ -19,17 +19,17 @@ $header $options_indexes - {$lng['extras']['errordocument404path']}:
{$lng['panel']['emptyfordefault']} + {$lng['extras']['errordocument404path']}:
{$lng['panel']['descriptionerrordocument']} - {$lng['extras']['errordocument403path']}:
{$lng['panel']['emptyfordefault']} + {$lng['extras']['errordocument403path']}:
{$lng['panel']['descriptionerrordocument']}
{$lng['panel']['not_supported']}lighttpd
- {$lng['extras']['errordocument500path']}:
{$lng['panel']['emptyfordefault']} + {$lng['extras']['errordocument500path']}:
{$lng['panel']['descriptionerrordocument']}
{$lng['panel']['not_supported']}lighttpd
diff --git a/templates/customer/extras/htaccess_edit.tpl b/templates/customer/extras/htaccess_edit.tpl index 6bc0385b..948f3b35 100644 --- a/templates/customer/extras/htaccess_edit.tpl +++ b/templates/customer/extras/htaccess_edit.tpl @@ -17,17 +17,17 @@ $header $options_indexes - {$lng['extras']['errordocument404path']}:
{$lng['panel']['emptyfordefault']} + {$lng['extras']['errordocument404path']}:
{$lng['panel']['descriptionerrordocument']} - {$lng['extras']['errordocument403path']}:
{$lng['panel']['emptyfordefault']} + {$lng['extras']['errordocument403path']}:
{$lng['panel']['descriptionerrordocument']}
{$lng['panel']['not_supported']}lighttpd
- {$lng['extras']['errordocument500path']}:
{$lng['panel']['emptyfordefault']} + {$lng['extras']['errordocument500path']}:
{$lng['panel']['descriptionerrordocument']}
{$lng['panel']['not_supported']}lighttpd