831 |
florian |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
////////////////////////////////////////////////////////////////////////////////
|
|
|
4 |
// //
|
|
|
5 |
// Copyright (C) 2006 Phorum Development Team //
|
|
|
6 |
// http://www.phorum.org //
|
|
|
7 |
// //
|
|
|
8 |
// This program is free software. You can redistribute it and/or modify //
|
|
|
9 |
// it under the terms of either the current Phorum License (viewable at //
|
|
|
10 |
// phorum.org) or the Phorum License that was distributed with this file //
|
|
|
11 |
// //
|
|
|
12 |
// This program is distributed in the hope that it will be useful, //
|
|
|
13 |
// but WITHOUT ANY WARRANTY, without even the implied warranty of //
|
|
|
14 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. //
|
|
|
15 |
// //
|
|
|
16 |
// You should have received a copy of the Phorum License //
|
|
|
17 |
// along with this program. //
|
|
|
18 |
////////////////////////////////////////////////////////////////////////////////
|
|
|
19 |
|
|
|
20 |
include_once "./include/admin/PhorumInputForm.php";
|
|
|
21 |
|
|
|
22 |
// The place where our sanity checking modules are.
|
|
|
23 |
$sanity_checks_dir = "./include/admin/sanity_checks";
|
|
|
24 |
|
|
|
25 |
// ========================================================================
|
|
|
26 |
// Load in the available sanity checks.
|
|
|
27 |
// ========================================================================
|
|
|
28 |
|
|
|
29 |
$sanity_checks = array();
|
|
|
30 |
$dh = opendir ($sanity_checks_dir);
|
|
|
31 |
if (! $dh) die("Could not open sanity checks directory");
|
|
|
32 |
while ($file = readdir($dh)) {
|
|
|
33 |
if (preg_match('/^(.+)\.php$/', $file, $m)) {
|
|
|
34 |
unset($phorum_check);
|
|
|
35 |
include("$sanity_checks_dir/$file");
|
|
|
36 |
$func = "phorum_check_$m[1]";
|
|
|
37 |
if (! isset($phorum_check) || ! function_exists($func)) {
|
|
|
38 |
die("$sanity_checks_dir/$file is no valid check file! " .
|
|
|
39 |
"Either \$phorum_check is not set or the " .
|
|
|
40 |
"function " . htmlspecialchars($func) . " does not exist");
|
|
|
41 |
continue;
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
$sanity_checks[] = array (
|
|
|
45 |
'function' => $func,
|
|
|
46 |
'description' => $phorum_check,
|
|
|
47 |
);
|
|
|
48 |
}
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
// Give module writers a possiblity to write custom sanity checks.
|
|
|
52 |
$sanity_checks = phorum_hook("sanity_checks", $sanity_checks);
|
|
|
53 |
|
|
|
54 |
// ========================================================================
|
|
|
55 |
// Build the sanity checking page and run all checks.
|
|
|
56 |
// ========================================================================
|
|
|
57 |
|
|
|
58 |
// Mapping of status to display representation.
|
|
|
59 |
$status2display = array(
|
|
|
60 |
// STATUS BACKGROUND FONT TEXT
|
|
|
61 |
PHORUM_SANITY_OK => array('green', 'white', 'ALL IS OK'),
|
|
|
62 |
PHORUM_SANITY_WARN => array('darkorange', 'white', 'WARNING'),
|
|
|
63 |
PHORUM_SANITY_CRIT => array('red', 'white', 'ERROR'),
|
|
|
64 |
);
|
|
|
65 |
|
|
|
66 |
$frm = new PhorumInputForm ("", "post", "Restart sanity checks");
|
|
|
67 |
$frm->hidden("module", "sanity_checks");
|
|
|
68 |
$frm->addbreak("Phorum System Sanity Checks");
|
|
|
69 |
$frm->addmessage(
|
|
|
70 |
"Below you will find the results for a number of sanity checks
|
|
|
71 |
that have been performed on your system. If you see any
|
|
|
72 |
warnings or errors, then read the comments for them and
|
|
|
73 |
try to resolve the issues."
|
|
|
74 |
);
|
|
|
75 |
|
|
|
76 |
// Make using $php_errormsg possible for the checks.
|
|
|
77 |
ini_set('track_errors', 1);
|
|
|
78 |
|
|
|
79 |
// In the case checks take a little while, we want the user
|
|
|
80 |
// to have visible feedback.
|
|
|
81 |
ob_flush();
|
|
|
82 |
|
|
|
83 |
// Run the sanity checks.
|
|
|
84 |
foreach ($sanity_checks as $check)
|
|
|
85 |
{
|
|
|
86 |
// Call the sanity check function. This function is expected
|
|
|
87 |
// to return an array containing the following elements:
|
|
|
88 |
//
|
|
|
89 |
// [1] A status, which can be one of
|
|
|
90 |
// PHORUM_SANITY_OK No problem found
|
|
|
91 |
// PHORUM_SANITY_WARN Problem found, but no fatal one
|
|
|
92 |
// PHORUM_SANITY_CRIT Critical problem found
|
|
|
93 |
//
|
|
|
94 |
// [2] A description of the problem that was found or NULL.
|
|
|
95 |
//
|
|
|
96 |
// [3] A solution for the problem or NULL.
|
|
|
97 |
//
|
|
|
98 |
list($status, $error, $solution) = call_user_func($check["function"]);
|
|
|
99 |
if (isset($error)) $error = str_replace("\n", " ", $error);
|
|
|
100 |
if (isset($solution)) $solution = str_replace("\n", " ", $solution);
|
|
|
101 |
$display = $status2display[$status];
|
|
|
102 |
$block = "<div style=\"color:{$display[1]};background-color:{$display[0]};text-align:center;border:1px solid black;\">{$display[2]}</div>";
|
|
|
103 |
$row = $frm->addrow($check['description'], $block);
|
|
|
104 |
if (! empty($error)) {
|
|
|
105 |
if (! empty($solution))
|
|
|
106 |
$error .= "<br/><br/>" .
|
|
|
107 |
"<strong>Possible solution:</strong>" .
|
|
|
108 |
"<br/><br/>" .
|
|
|
109 |
$solution;
|
|
|
110 |
$frm->addhelp($row,"Sanity check failed",$error);
|
|
|
111 |
}
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
$frm->show();
|
|
|
115 |
|
|
|
116 |
?>
|