1<?php
2
3/**
4 * This file is part of the Froxlor project.
5 * Copyright (c) 2010 the Froxlor Team (see authors).
6 *
7 * For the full copyright and license information, please view the COPYING
8 * file that was distributed with this source code. You can also view the
9 * COPYING file online at http://files.froxlor.org/misc/COPYING.txt
10 *
11 * @copyright  (c) the authors
12 * @author     Froxlor team <team@froxlor.org> (2010-)
13 * @license    GPLv2 http://files.froxlor.org/misc/COPYING.txt
14 * @package    Functions
15 *
16 */
17
18/**
19 * this functions validates a given value as ErrorDocument
20 * refs #267
21 *
22 * @param string error-document-string
23 *
24 * @return string error-document-string
25 *
26 */
27function correctErrorDocument($errdoc = null) {
28
29	global $idna_convert;
30
31	if ($errdoc !== null && $errdoc != '') {
32		// not a URL
33		if ((strtoupper(substr($errdoc, 0, 5)) != 'HTTP:'
34				&& strtoupper(substr($errdoc, 0, 6)) != 'HTTPS:')
35				|| !validateUrl($errdoc)
36		) {
37			// a file
38			if (substr($errdoc, 0, 1) != '"') {
39				$errdoc = makeCorrectFile($errdoc);
40				// apache needs a starting-slash (starting at the domains-docroot)
41				if (!substr($errdoc, 0, 1) == '/') {
42					$errdoc = '/'.$errdoc;
43				}
44			}
45			// a string (check for ending ")
46			else {
47				// string won't work for lighty
48				if (Settings::Get('system.webserver') == 'lighttpd') {
49					standard_error('stringerrordocumentnotvalidforlighty');
50				} elseif(substr($errdoc, -1) != '"') {
51					$errdoc .= '"';
52				}
53			}
54		} else {
55			if (Settings::Get('system.webserver') == 'lighttpd') {
56				standard_error('urlerrordocumentnotvalidforlighty');
57			}
58		}
59	}
60	return $errdoc;
61}
62