Issues (1697)

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 is 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 dev
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
obExit(null, null, true);
75
76
/**
77
 * The main dispatcher.
78
 * This delegates to each area.
79
 */
80
function elk_main()
81
{
82
	global $modSettings, $context;
83
84
	// What shall we do?
85
	$dispatcher = new SiteDispatcher( HttpReq::instance());
86
87
	if ($dispatcher->needSecurity())
88
	{
89
		// We should set our security headers now.
90
		frameOptionsHeader();
91
		securityOptionsHeader();
92
93
		// Load the user's cookie (or set as guest) and load their settings.
94
		User::load(true);
95
		$dispatcher->setUser(User::$info);
96
97
		// Load the current board's information.
98
		loadBoard();
99
100
		// Load the current user's permissions.
101
		loadPermissions();
102
103
		// Load the current theme.  (note that ?theme=1 will also work, may be used for guest theming.)
104
		if ($dispatcher->needTheme())
105
		{
106
			// Do our BadBehavior checking before we go any further
107
			if (runBadBehavior())
108
			{
109
				// Not much to say, 403 and gone
110
				sleep(10);
111
				\ElkArte\Errors\Errors::instance()->display_403_error(true);
112
			}
113
114
			new ThemeLoader();
115
116
			// The parser is not an object just yet
117
			loadBBCParsers();
118
		}
119
120
		// Check if the user should be disallowed access.
121
		is_not_banned();
122
123
		// Do some logging, unless this is an attachment, avatar, toggle of editor buttons, theme option, XML feed etc.
124
		if ($dispatcher->trackStats())
125
		{
126
			// I see you!
127
			writeLog();
128
129
			// Track forum statistics and hits...?
130
			if (!empty($modSettings['hitStats']))
131
			{
132
				trackStats(['hits' => '+']);
133
			}
134
		}
135
136
		// Show where we came from, and go
137
		$context['site_action'] = $dispatcher->site_action();
138
	}
139
140
	$dispatcher->dispatch();
141
}
142