include_sefurl.php 2.61 KB
Newer Older
1
<?php
2
// (c) Copyright 2002-2013 by authors of the Tiki Wiki CMS Groupware Project
3
//
4 5
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
changi67's avatar
changi67 committed
6
// $Id$
7

changi67's avatar
changi67 committed
8 9
require_once ('tiki-setup.php');
$access->check_script($_SERVER["SCRIPT_NAME"], basename(__FILE__));
10
if (isset($_REQUEST['save'])) {
11 12 13
	check_ticket('admin-inc-sefurl');
	$_REQUEST['feature_sefurl_paths'] = preg_split('/ *[,\/] */', $_REQUEST['feature_sefurl_paths']);
	simple_set_value('feature_sefurl_paths');
14
}
15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
if (TikiInit::isIIS()) {
	$httpd = 'IIS';
	if (TikiInit::hasIIS_UrlRewriteModule()) {
		$smarty->assign('IIS_UrlRewriteModule', true);
		$enabledFileName = 'web.config';
		$referenceFileName = 'web_config';
	} else {
		$smarty->assign('IIS_UrlRewriteModule', false);
	}
} else {
	$enabledFileName = '.htaccess';
	$referenceFileName = '_htaccess';
	$httpd = 'Apache';
}
$smarty->assign('httpd', $httpd);
31

32 33 34
// Check if the URL rewriting configuration file is present and current
$configurationFile = "missing";
if (isset($enabledFileName)) {
35
	$enabledFile = @fopen($enabledFileName, "r");
36 37 38
	if ($enabledFile) {
		$referenceFile = fopen($referenceFileName, "r");
		if ($referenceFile) {
39 40
			if ($httpd == 'IIS') {
				// On IIS, the Id line is the second line, rather than the first as in Apache.
41 42
				fgets($referenceFile);
				fgets($enabledFile);
43
			}
44
			$referenceIdLine = fgets($referenceFile);
45
			$enabledIdLine = fgets($enabledFile);
46 47 48 49 50 51
			if (!strstr($enabledIdLine, 'This line is used to check that this configuration file is up to date.')) {
				$configurationFile = 'unexpected';
			} elseif ($referenceIdLine == $enabledIdLine) { // Do not warn if the Id line of each file is identical. Id lines contain configuration file revision.
				$configurationFile = 'current';
			} else {
				$configurationFile = 'outdated';
52
			}
53 54
			if ($httpd === 'Apache') {
				// work out if RewriteBase is set up properly
55 56 57
				global $url_path;
				$rewritebase = '/';
				while ($nextLine = fgets($enabledFile)) {
58
					if (preg_match('/^\s*?RewriteBase\s*[\'"]?(.*?)[\'"]?$/', $nextLine, $m)) {
59 60 61 62 63 64 65 66
						$rewritebase = substr($m[1], -1) !== '/' ? $m[1] . '/' : $m[1];
						break;
					}
				}
				if ($url_path != $rewritebase) {
					$smarty->assign('rewritebaseSetting', $rewritebase);
				}
			}
67
			fclose($referenceFile);
68
		} else {
69
			$configurationFile = 'no reference';
70
		}
71
		fclose($enabledFile);
chealer's avatar
chealer committed
72
	}
73 74 75
	$smarty->assign('referenceFileName', $referenceFileName);
	$smarty->assign('enabledFileName', $enabledFileName);
	$smarty->assign('configurationFile', $configurationFile);
76
}
chealer's avatar
chealer committed
77

78
ask_ticket('admin-inc-sefurl');