Issues (1697)

index.php (2 issues)

1
<?php
2
3
/**
4
 * This, as you have probably guessed, is the crux for all functions.
5
 * Everything should start here, so all the setup and security are done
6
 * properly.
7
 *
8
 * @package   ElkArte Forum
9
 * @copyright ElkArte Forum contributors
10
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file)
11
 *
12
 * This file contains code covered by:
13
 * copyright: 2011 Simple Machines (http://www.simplemachines.org)
14
 *
15
 * @version 2.0 Beta 1
16
 *
17
 */
18
19
use ElkArte\Controller\ScheduledTasks;
20
use ElkArte\EventManager;
21
use ElkArte\Helper\HttpReq;
22
use ElkArte\SiteDispatcher;
23
use ElkArte\Themes\ThemeLoader;
24
use ElkArte\User;
25
26
// Bootstrap the system
27
require_once(__DIR__ . '/bootstrap.php');
28
new Bootstrap(false);
29
30
// Turn on output buffering if it isn't already on (via php.ini, for example)
31
if (!ob_get_level())
32
{
33
	ob_start();
34
}
35
36
// Before we get carried away, are we doing a scheduled task? If so, save CPU cycles by jumping out!
37
if (isset($_GET['scheduled']))
38
{
39
	// Don't make people wait on us if we can help it.
40
	if (function_exists('fastcgi_finish_request'))
41
	{
42
		fastcgi_finish_request();
43
	}
44
45
	$controller = new ScheduledTasks(new EventManager());
46
	$controller->action_autotask();
47
}
48
49
// Check if compressed output is enabled, supported, and not already being done.
50
if (!empty($modSettings['enableCompressedOutput']) && !headers_sent())
51
{
52
	// If zlib is being used, turn off output compression.
53
	if (detectServer()->outPutCompressionEnabled())
54
	{
55
		$modSettings['enableCompressedOutput'] = 0;
56
	}
57
	else
58
	{
59
		@ob_end_clean();
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for ob_end_clean(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

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

59
		/** @scrutinizer ignore-unhandled */ @ob_end_clean();

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
60
		ob_start('ob_gzhandler');
61
	}
62
}
63
64
// Register error & exception handlers.
65
new ElkArte\Errors\ErrorHandler();
66
67
// Start the session. (assuming it hasn't already been.)
68
loadSession();
69
70
// Pre-dispatch
71
elk_main();
72
73
// Call obExit specially; we're coming from the main area ;).
74
// @todo why is this still needed, its going to return and end here anyway?
75
// obExit(null, null, false);
76
obExit();
77
78
/**
79
 * The main dispatcher.
80
 * This delegates to each area.
81
 */
82
function elk_main()
83
{
84
	global $modSettings, $context;
85
86
	// What shall we do?
87
	$dispatcher = new SiteDispatcher( HttpReq::instance());
88
89
	if ($dispatcher->needSecurity())
90
	{
91
		// We should set our security headers now.
92
		frameOptionsHeader();
93
		securityOptionsHeader();
94
95
		// Load the user's cookie (or set as guest) and load their settings.
96
		User::load(true);
97
		$dispatcher->setUser(User::$info);
98
99
		// Load the current board's information.
100
		loadBoard();
101
102
		// Load the current user's permissions.
103
		loadPermissions();
104
105
		// Load the current theme.  (note that ?theme=1 will also work, may be used for guest theming.)
106
		if ($dispatcher->needTheme())
107
		{
108
			// Do our BadBehavior checking before we go any further
109
			$badActor = runBadBehavior();
110
			if ($badActor !== false)
111
			{
112
				// Not much to say, waste some time and 403 and gone
113
				sleep(10);
114
				\ElkArte\Errors\Errors::instance()->display_403_error(true, $badActor);
0 ignored issues
show
The type ElkArte\Errors\Errors was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
115
			}
116
117
			new ThemeLoader();
118
119
			// The parser is not an object just yet
120
			loadBBCParsers();
121
		}
122
123
		// Check if the user should be disallowed access.
124
		is_not_banned();
125
126
		// Do some logging, unless this is an attachment, avatar, toggle of editor buttons, theme option, XML feed etc.
127
		if ($dispatcher->trackStats())
128
		{
129
			// I see you!
130
			writeLog();
131
132
			// Track forum statistics and hits...?
133
			if (!empty($modSettings['hitStats']))
134
			{
135
				trackStats(['hits' => '+']);
136
			}
137
		}
138
139
		// Show where we came from and then go
140
		$context['site_action'] = $dispatcher->site_action();
141
	}
142
143
	$dispatcher->dispatch();
144
}
145