-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
91 lines (73 loc) · 2.18 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
error_reporting(E_ALL);
ini_set('display_errors', 1);
*/
chdir(__DIR__);
define('SW_INDEX', 1);
require_once './bootstrap.php';
$module = trim(strtolower(@$_REQUEST['m']));
if ('' === $module) {
$module = 'whiteboard';
}
$moduleDir = @realpath(SW_DIR_MODULES);
if (!@is_dir($moduleDir)) {
http_response_code(404); // module directory not found
die();
}
$moduleFile = @realpath(SW_DIR_MODULES . $module . '.php');
if (!@is_file($moduleFile)) {
http_response_code(404); // module file not found
die();
}
if (0 !== strpos($moduleFile, $moduleDir . DIRECTORY_SEPARATOR)) {
http_response_code(404); // not inside module directory
die();
}
$app = [
'config' => $SW_CONFIG,
'headers' => array(),
'module' => $module,
'moduleResult' => true,
'showHeader' => true,
'showFooter' => true,
];
$content = sw_executed_buffered(function() use (&$app, $moduleFile) {
return require $moduleFile;
}, $app['moduleResult']);
if (false === $app['moduleResult']) {
http_response_code(404); // module says: not found
die();
}
$header = sw_executed_buffered(function() use (&$app) {
require __DIR__ . '/header.php';
});
$footer = sw_executed_buffered(function() use (&$app) {
require __DIR__ . '/footer.php';
});
if (!empty($app['headers'])) {
foreach ($app['headers'] as $httpKey => $httpValue) {
header($httpKey . ': ' . $httpValue, true);
}
}
if ($app['showHeader']) {
echo $header;
}
if ('' !== $content) {
echo $content;
}
if ($app['showFooter']) {
echo $footer;
}