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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
<?php
require_once 'config.php';
if (CONFIG_SQL_PASS === '%MYSQL_OPENSLX_PASS%') {
Header('Content-Type: text/plain; charset=utf-8');
die("The server has not been configured yet. Please log in to the server via console/SSH and follow the instructions."
. "\n\n"
. "Der Server wurde noch nicht konfiguriert. Bitte loggen Sie sich auf der Konsole oder per SSH auf dem Server ein"
. " und folgen Sie den Instruktionen.");
}
require_once('inc/user.inc.php');
/**
* Page class which all module's pages must be extending from
*/
abstract class Page
{
protected function doPreprocess()
{
}
protected function doRender()
{
}
protected function doAjax()
{
}
public static function preprocess()
{
self::$instance->doPreprocess();
}
public static function render()
{
$pageTitle = self::$module->getPageTitle();
if ($pageTitle !== false) {
Render::setTitle($pageTitle);
}
self::$instance->doRender();
}
public static function ajax()
{
self::$instance->doAjax();
}
public static function translate($tag, $section = 'module')
{
return self::$module->translate($tag, $section);
}
public static function getModule()
{
return self::$module;
}
/**
* @var \Page
*/
private static $instance = false;
/**
* @var \Module
*/
private static $module = false;
public static function init()
{
$name = empty($_REQUEST['do']) ? 'Main' : $_REQUEST['do'];
$name = preg_replace('/[^A-Za-z]/', '', $name);
$name = strtolower($name);
Module::init();
self::$module = Module::get($name);
if (self::$module === false) {
Util::traceError('Invalid Module: ' . $name);
}
self::$module->activate();
self::$instance = self::$module->newPage();
}
}
// Error reporting (hopefully goind to stderr, not being printed on pages)
error_reporting(E_ALL);
// Set variable if this is an ajax request
if ((isset($_REQUEST['async'])) || (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest')) {
define('AJAX', true);
} else {
define('AJAX', false);
}
define('API', false);
// Autoload classes from ./inc which adhere to naming scheme <lowercasename>.inc.php
function slxAutoloader($class)
{
$file = 'inc/' . preg_replace('/[^a-z0-9]/', '', mb_strtolower($class)) . '.inc.php';
if (!file_exists($file))
return;
require_once $file;
}
spl_autoload_register('slxAutoloader');
// Now determine which module to run
Page::init();
// Deserialize any messages to display
if (!AJAX && isset($_REQUEST['message'])) {
Message::fromRequest();
}
// CSRF/XSS check
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
User::load();
if (!Util::verifyToken()) {
if (AJAX) {
die('CSRF/XSS? Missing token in POST request!');
} else {
Util::redirect('?do=Main');
}
}
}
// AJAX Stuff? Just do so. Otherwise, run preprocessing
if (AJAX) {
Page::ajax();
exit(0);
}
// Normal mode - preprocess first....
Page::preprocess();
// Generate Main menu
Dashboard::createMenu();
Message::renderList();
// Render page. If the module wants to output anything, it will be done here...
Page::render();
if (defined('CONFIG_DEBUG') && CONFIG_DEBUG) {
Message::addWarning('debug-mode');
}
if (defined('CONFIG_FOOTER')) {
Render::addTemplate('footer', array('text' => CONFIG_FOOTER), 'main');
}
Render::addTemplate('tm-callback-trigger', array(), 'main');
// Send page to client.
Render::output();
|