Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 44
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
tao_install_checks_ModRewrite
0.00% covered (danger)
0.00%
0 / 44
0.00% covered (danger)
0.00%
0 / 1
240
0.00% covered (danger)
0.00%
0 / 1
 check
0.00% covered (danger)
0.00%
0 / 44
0.00% covered (danger)
0.00%
0 / 1
240
1<?php
2
3/*
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; under version 2
7 * of the License (non-upgradable).
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 *
18 * Copyright (c) 2002-2008 (original work) Public Research Centre Henri Tudor & University of Luxembourg
19 *                         (under the project TAO & TAO2);
20 *               2008-2010 (update and modification) Deutsche Institut für Internationale Pädagogische Forschung
21 *                         (under the project TAO-TRANSFER);
22 *               2009-2012 (update and modification) Public Research Centre Henri Tudor
23 *                         (under the project TAO-SUSTAIN & TAO-DEV);
24 *
25 */
26
27class tao_install_checks_ModRewrite extends common_configuration_Component
28{
29    public function check()
30    {
31        $status = null;
32        $message = '';
33        $modRewrite = false;
34        $report = null;
35
36        if (function_exists('apache_get_modules')) {
37            $modules = apache_get_modules();
38            if (in_array('mod_rewrite', $modules)) {
39                $modRewrite = true;
40            }
41        // TAO Main .htaccess file sets the HTTP_MOD_REWRITE.
42        } elseif ((getenv('HTTP_MOD_REWRITE') == 'On' ? true : false) == true) {
43            $modRewrite = true;
44        // apache does weird things to environement variables
45        } elseif ((getenv('REDIRECT_HTTP_MOD_REWRITE') == 'On' ? true : false) == true) {
46            $modRewrite = true;
47        // else test the behaviour
48        } elseif (php_sapi_name() != 'cli' && function_exists("curl_init")) {
49            $server =
50                ((isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") ? 'https' : 'http')
51                . "://" . $_SERVER['SERVER_NAME']
52                . (($_SERVER["SERVER_PORT"] != "80") ? ":" . $_SERVER["SERVER_PORT"] : '');
53
54            $request = $_SERVER["REQUEST_URI"];
55            if (strpos($request, '?') !== false) {
56                $request = substr($request, 0, strpos($request, '?'));
57            }
58            $request = substr($request, 0, strrpos($request, '/'));
59
60            $url = $server . $request . '/checks/testRewrite/notworking';
61            $ch = curl_init();
62            curl_setopt($ch, CURLOPT_URL, $url);
63            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
64            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
65            curl_setopt($ch, CURLOPT_TIMEOUT, 1);
66            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
67            $output = @curl_exec($ch);
68            curl_close($ch);
69
70            if ($output == 'working') {
71                $modRewrite = true;
72            }
73        }
74
75        if ($modRewrite == true) {
76            $report = new common_configuration_Report(
77                common_configuration_Report::VALID,
78                'URL rewriting is enabled.',
79                $this
80            );
81        } else {
82            $report = new common_configuration_Report(
83                common_configuration_Report::INVALID,
84                'URL rewriting is disabled.',
85                $this
86            );
87        }
88
89        return $report;
90    }
91}