Issues (752)

grommunio.php (1 issue)

1
<?php
2
3
/**
4
 * This file is the dispatcher of the whole application, every request for data enters
5
 * here. JSON is received and send to the client.
6
 */
7
8
// Bootstrap the script
9
require_once 'server/includes/bootstrap.grommunio.php';
10
11
// Callback function for unserialize
12
// Notifier objects of the previous request are stored in the session. With this
13
// function they are restored to PHP objects.
14
ini_set("unserialize_callback_func", "sessionNotifierLoader");
15
16
// Try to authenticate the user
17
WebAppAuthentication::authenticate();
18
19
// Globals suck, but we use it still in many files, so we will
20
// store the mapisession as global
21
$GLOBALS["mapisession"] = WebAppAuthentication::getMAPISession();
22
23
// Get the language from the session
24
// before we close the session.
25
if (isset($_SESSION["lang"])) {
26
	$session_lang = $_SESSION["lang"];
27
}
28
else {
29
	$session_lang = LANG;
30
}
31
32
// Set headers for JSON
33
header("Content-Type: application/json; charset=utf-8");
34
header("Expires: " . gmdate("D, d M Y H:i:s") . "GMT");
35
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
36
header("Cache-Control: no-cache, must-revalidate");
37
header("Pragma: no-cache");
38
if (WebAppAuthentication::isAuthenticated()) {
39
	header("X-grommunio: " . trim(file_get_contents(BASE_PATH . 'version')));
40
}
41
42
// If a service request was sent (a REST call), the service controller will handle it.
43
if (isset($_GET['service'])) {
44
	require_once BASE_PATH . 'server/includes/controllers/service.php';
45
46
	exit;
47
}
48
49
// Close the session now, so we're not blocking other requests
50
session_write_close();
51
52
// If a ping request was sent, we the ping controller will handle it.
53
if (isset($_GET['ping'])) {
54
	require_once BASE_PATH . 'server/includes/controllers/ping.php';
55
56
	exit;
57
}
58
59
if (!WebAppAuthentication::isAuthenticated()) {
60
	if (WebAppAuthentication::getErrorCode() === MAPI_E_NETWORK_ERROR) {
61
		// The user is not logged in because the Gromox server could not be reached.
62
		// Return a HTTP 503 error so the client can act upon this event correctly.
63
		header('HTTP/1.1 503 Service unavailable');
64
		header("X-grommunio-Hresult: " . get_mapi_error_name(WebAppAuthentication::getErrorCode()));
65
	}
66
	else {
67
		// The session expired, or the user is otherwise not logged on.
68
		// Return a HTTP 401 error so the client can act upon this event correctly.
69
		header('HTTP/1.1 401 Unauthorized');
70
		header("X-grommunio-Hresult: " . get_mapi_error_name(WebAppAuthentication::getErrorCode()));
71
	}
72
73
	exit;
74
}
75
76
// Instantiate Plugin Manager
77
$GLOBALS['PluginManager'] = new PluginManager(ENABLE_PLUGINS);
78
$GLOBALS['PluginManager']->detectPlugins(DISABLED_PLUGINS_LIST);
79
80
// Initialize plugins and prevent any output which might be written as
81
// plugins might be uncleanly output white-space and other stuff. We must
82
// not allow this here as it can destroy the response data.
83
ob_start();
84
$GLOBALS['PluginManager']->initPlugins(DEBUG_LOADER);
85
ob_end_clean();
86
87
// Create global dispatcher object
88
$GLOBALS["dispatcher"] = new Dispatcher();
89
90
// Create global operations object
91
$GLOBALS["operations"] = new Operations();
92
93
// Create global language object
94
$Language = new Language();
95
96
// Create global settings object
97
$GLOBALS["settings"] = new Settings($Language);
0 ignored issues
show
The call to Settings::__construct() has too many arguments starting with $Language. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

97
$GLOBALS["settings"] = /** @scrutinizer ignore-call */ new Settings($Language);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
98
99
// Set the correct language
100
$Language->setLanguage($session_lang);
101
102
// Get the state information for this subsystem
103
$subsystem = sanitizeGetValue('subsystem', 'anonymous', ID_REGEX);
104
105
$state = new State($subsystem);
106
107
// Lock the state of this subsystem
108
$state->open();
109
110
// Get the bus object for this subsystem
111
$bus = $state->read("bus");
112
113
if (!$bus) {
114
	// Create global bus object
115
	$bus = new Bus();
116
}
117
118
// Make bus global
119
$GLOBALS["bus"] = $bus;
120
121
// Reset any spurious information in the bus state
122
$GLOBALS["bus"]->reset();
123
124
// Create global properties object
125
$properties = $state->read("properties");
126
127
if (!$properties) {
128
	$properties = new Properties();
129
}
130
$GLOBALS["properties"] = $properties;
131
132
// Reset any spurious information in the properties state
133
$GLOBALS["properties"]->reset();
134
135
// Create new request object
136
$request = new JSONRequest();
137
138
// Get the JSON that the client sent with the request
139
$json = readData();
140
141
if (DEBUG_JSONOUT) {
142
	dump_json($json, "in"); // debugging
143
}
144
145
// Execute the request
146
try {
147
	$json = $request->execute($json);
148
}
149
catch (Exception $e) {
150
	// invalid requestdata exception
151
	dump($e);
152
}
153
154
if (DEBUG_JSONOUT) {
155
	dump_json($json, "out"); // debugging
156
}
157
158
// Check if we can use gzip compression
159
if (ENABLE_RESPONSE_COMPRESSION && function_exists("gzencode") && isset($_SERVER["HTTP_ACCEPT_ENCODING"]) && str_contains((string) $_SERVER["HTTP_ACCEPT_ENCODING"], "gzip")) {
160
	// Set the correct header and compress the response
161
	header("Content-Encoding: gzip");
162
	echo gzencode($json);
163
}
164
else {
165
	echo $json;
166
}
167
168
// Reset the BUS, and save it to the state file
169
$GLOBALS["bus"]->reset();
170
$state->write("bus", $GLOBALS["bus"], false);
171
172
// Reset the properties and save it to the state file
173
$GLOBALS["properties"]->reset();
174
$state->write("properties", $GLOBALS["properties"], false);
175
176
// Write all changes to disk
177
$state->flush();
178
179
// You can skip this as well because the lock is freed after the PHP script ends
180
// anyway. (only for PHP < 5.3.2)
181
$state->close();
182