-
-
Notifications
You must be signed in to change notification settings - Fork 409
/
class_core.php
626 lines (569 loc) · 13.7 KB
/
class_core.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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
<?php
/**
* MyBB 1.8
* Copyright 2014 MyBB Group, All Rights Reserved
*
* Website: http://www.mybb.com
* License: http://www.mybb.com/about/license
*
*/
class MyBB {
/**
* The friendly version number of MyBB we're running.
*
* @var string
*/
public $version = "1.8.22";
/**
* The version code of MyBB we're running.
*
* @var integer
*/
public $version_code = 1822;
/**
* The current working directory.
*
* @var string
*/
public $cwd = ".";
/**
* Input variables received from the outer world.
*
* @var array
*/
public $input = array();
/**
* Cookie variables received from the outer world.
*
* @var array
*/
public $cookies = array();
/**
* Information about the current user.
*
* @var array
*/
public $user = array();
/**
* Information about the current usergroup.
*
* @var array
*/
public $usergroup = array();
/**
* MyBB settings.
*
* @var array
*/
public $settings = array();
/**
* Whether or not magic quotes are enabled.
*
* @var int
*/
public $magicquotes = 0;
/**
* Whether or not MyBB supports SEO URLs
*
* @var boolean
*/
public $seo_support = false;
/**
* MyBB configuration.
*
* @var array
*/
public $config = array();
/**
* The request method that called this page.
*
* @var string
*/
public $request_method = "";
/**
* Whether or not PHP's safe_mode is enabled
*
* @var boolean
*/
public $safemode = false;
/**
* Loads templates directly from the master theme and disables the installer locked error
*
* @var boolean
*/
public $dev_mode = false;
/**
* Variables that need to be clean.
*
* @var array
*/
public $clean_variables = array(
"int" => array(
"tid", "pid", "uid",
"eid", "pmid", "fid",
"aid", "rid", "sid",
"vid", "cid", "bid",
"hid", "gid", "mid",
"wid", "lid", "iid",
"did", "qid", "id"
),
"pos" => array(
"page", "perpage"
),
"a-z" => array(
"sortby", "order"
)
);
/**
* Variables that are to be ignored from cleansing process
*
* @var array
*/
public $ignore_clean_variables = array();
/**
* Using built in shutdown functionality provided by register_shutdown_function for < PHP 5?
*
* @var bool
*/
public $use_shutdown = true;
/**
* Debug mode?
*
* @var bool
*/
public $debug_mode = false;
/**
* Binary database fields need to be handled differently
*
* @var array
*/
public $binary_fields = array(
'adminlog' => array('ipaddress' => true),
'adminsessions' => array('ip' => true),
'maillogs' => array('ipaddress' => true),
'moderatorlog' => array('ipaddress' => true),
'pollvotes' => array('ipaddress' => true),
'posts' => array('ipaddress' => true),
'privatemessages' => array('ipaddress' => true),
'searchlog' => array('ipaddress' => true),
'sessions' => array('ip' => true),
'threadratings' => array('ipaddress' => true),
'users' => array('regip' => true, 'lastip' => true),
'spamlog' => array('ipaddress' => true),
);
/**
* The cache instance to use.
*
* @var datacache
*/
public $cache;
/**
* The base URL to assets.
*
* @var string
*/
public $asset_url = null;
/**
* String input constant for use with get_input().
*
* @see get_input
*/
const INPUT_STRING = 0;
/**
* Integer input constant for use with get_input().
*
* @see get_input
*/
const INPUT_INT = 1;
/**
* Array input constant for use with get_input().
*
* @see get_input
*/
const INPUT_ARRAY = 2;
/**
* Float input constant for use with get_input().
*
* @see get_input
*/
const INPUT_FLOAT = 3;
/**
* Boolean input constant for use with get_input().
*
* @see get_input
*/
const INPUT_BOOL = 4;
/**
* Constructor of class.
*/
function __construct()
{
// Set up MyBB
$protected = array("_GET", "_POST", "_SERVER", "_COOKIE", "_FILES", "_ENV", "GLOBALS");
foreach($protected as $var)
{
if(isset($_POST[$var]) || isset($_GET[$var]) || isset($_COOKIE[$var]) || isset($_FILES[$var]))
{
die("Hacking attempt");
}
}
if(defined("IGNORE_CLEAN_VARS"))
{
if(!is_array(IGNORE_CLEAN_VARS))
{
$this->ignore_clean_variables = array(IGNORE_CLEAN_VARS);
}
else
{
$this->ignore_clean_variables = IGNORE_CLEAN_VARS;
}
}
// Determine Magic Quotes Status (< PHP 6.0)
if(version_compare(PHP_VERSION, '6.0', '<'))
{
if(@get_magic_quotes_gpc())
{
$this->magicquotes = 1;
$this->strip_slashes_array($_POST);
$this->strip_slashes_array($_GET);
$this->strip_slashes_array($_COOKIE);
}
@set_magic_quotes_runtime(0);
@ini_set("magic_quotes_gpc", 0);
@ini_set("magic_quotes_runtime", 0);
}
// Determine input
$this->parse_incoming($_GET);
$this->parse_incoming($_POST);
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$this->request_method = "post";
}
else if($_SERVER['REQUEST_METHOD'] == "GET")
{
$this->request_method = "get";
}
// If we've got register globals on, then kill them too
if(@ini_get("register_globals") == 1)
{
$this->unset_globals($_POST);
$this->unset_globals($_GET);
$this->unset_globals($_FILES);
$this->unset_globals($_COOKIE);
}
$this->clean_input();
$safe_mode_status = @ini_get("safe_mode");
if($safe_mode_status == 1 || strtolower($safe_mode_status) == 'on')
{
$this->safemode = true;
}
// Are we running on a development server?
if(isset($_SERVER['MYBB_DEV_MODE']) && $_SERVER['MYBB_DEV_MODE'] == 1)
{
$this->dev_mode = 1;
}
// Are we running in debug mode?
if(isset($this->input['debug']) && $this->input['debug'] == 1)
{
$this->debug_mode = true;
}
if(isset($this->input['action']) && $this->input['action'] == "mybb_logo")
{
require_once dirname(__FILE__)."/mybb_group.php";
output_logo();
}
if(isset($this->input['intcheck']) && $this->input['intcheck'] == 1)
{
die("MYBB");
}
}
/**
* Parses the incoming variables.
*
* @param array $array The array of incoming variables.
*/
function parse_incoming($array)
{
if(!is_array($array))
{
return;
}
foreach($array as $key => $val)
{
$this->input[$key] = $val;
}
}
/**
* Parses the incoming cookies
*
*/
function parse_cookies()
{
if(!is_array($_COOKIE))
{
return;
}
$prefix_length = strlen($this->settings['cookieprefix']);
foreach($_COOKIE as $key => $val)
{
if($prefix_length && substr($key, 0, $prefix_length) == $this->settings['cookieprefix'])
{
$key = substr($key, $prefix_length);
// Fixes conflicts with one board having a prefix and another that doesn't on the same domain
// Gives priority to our cookies over others (overwrites them)
if($this->cookies[$key])
{
unset($this->cookies[$key]);
}
}
if(empty($this->cookies[$key]))
{
$this->cookies[$key] = $val;
}
}
}
/**
* Strips slashes out of a given array.
*
* @param array $array The array to strip.
*/
function strip_slashes_array(&$array)
{
foreach($array as $key => $val)
{
if(is_array($array[$key]))
{
$this->strip_slashes_array($array[$key]);
}
else
{
$array[$key] = stripslashes($array[$key]);
}
}
}
/**
* Unsets globals from a specific array.
*
* @param array $array The array to unset from.
*/
function unset_globals($array)
{
if(!is_array($array))
{
return;
}
foreach(array_keys($array) as $key)
{
unset($GLOBALS[$key]);
unset($GLOBALS[$key]); // Double unset to circumvent the zend_hash_del_key_or_index hole in PHP <4.4.3 and <5.1.4
}
}
/**
* Cleans predefined input variables.
*
*/
function clean_input()
{
foreach($this->clean_variables as $type => $variables)
{
foreach($variables as $var)
{
// If this variable is in the ignored array, skip and move to next.
if(in_array($var, $this->ignore_clean_variables))
{
continue;
}
if(isset($this->input[$var]))
{
switch($type)
{
case "int":
$this->input[$var] = $this->get_input($var, MyBB::INPUT_INT);
break;
case "a-z":
$this->input[$var] = preg_replace("#[^a-z\.\-_]#i", "", $this->get_input($var));
break;
case "pos":
if(($this->input[$var] < 0 && $var != "page") || ($var == "page" && $this->input[$var] != "last" && $this->input[$var] < 0))
$this->input[$var] = 0;
break;
}
}
}
}
}
/**
* Checks the input data type before usage.
*
* @param string $name Variable name ($mybb->input)
* @param int $type The type of the variable to get. Should be one of MyBB::INPUT_INT, MyBB::INPUT_ARRAY or MyBB::INPUT_STRING.
*
* @return int|float|array|string Checked data. Type depending on $type
*/
function get_input($name, $type = MyBB::INPUT_STRING)
{
switch($type)
{
case MyBB::INPUT_ARRAY:
if(!isset($this->input[$name]) || !is_array($this->input[$name]))
{
return array();
}
return $this->input[$name];
case MyBB::INPUT_INT:
if(!isset($this->input[$name]) || !is_numeric($this->input[$name]))
{
return 0;
}
return (int)$this->input[$name];
case MyBB::INPUT_FLOAT:
if(!isset($this->input[$name]) || !is_numeric($this->input[$name]))
{
return 0.0;
}
return (float)$this->input[$name];
case MyBB::INPUT_BOOL:
if(!isset($this->input[$name]) || !is_scalar($this->input[$name]))
{
return false;
}
return (bool)$this->input[$name];
default:
if(!isset($this->input[$name]) || !is_scalar($this->input[$name]))
{
return '';
}
return $this->input[$name];
}
}
/**
* Get the path to an asset using the CDN URL if configured.
*
* @param string $path The path to the file.
* @param bool $use_cdn Whether to use the configured CDN options.
*
* @return string The complete URL to the asset.
*/
public function get_asset_url($path = '', $use_cdn = true)
{
$path = (string) $path;
$path = ltrim($path, '/');
if(substr($path, 0, 4) != 'http')
{
if(substr($path, 0, 2) == './')
{
$path = substr($path, 2);
}
if($use_cdn && $this->settings['usecdn'] && !empty($this->settings['cdnurl']))
{
$base_path = rtrim($this->settings['cdnurl'], '/');
}
else
{
$base_path = rtrim($this->settings['bburl'], '/');
}
$url = $base_path;
if(!empty($path))
{
$url = $base_path . '/' . $path;
}
}
else
{
$url = $path;
}
return $url;
}
/**
* Triggers a generic error.
*
* @param string $code The error code.
*/
function trigger_generic_error($code)
{
global $error_handler;
switch($code)
{
case "cache_no_write":
$message = "The data cache directory (cache/) needs to exist and be writable by the web server. Change its permissions so that it is writable (777 on Unix based servers).";
$error_code = MYBB_CACHE_NO_WRITE;
break;
case "install_directory":
$message = "The install directory (install/) still exists on your server and is not locked. To access MyBB please either remove this directory or create an empty file in it called 'lock'.";
$error_code = MYBB_INSTALL_DIR_EXISTS;
break;
case "board_not_installed":
$message = "Your board has not yet been installed and configured. Please do so before attempting to browse it.";
$error_code = MYBB_NOT_INSTALLED;
break;
case "board_not_upgraded":
$message = "Your board has not yet been upgraded. Please do so before attempting to browse it.";
$error_code = MYBB_NOT_UPGRADED;
break;
case "sql_load_error":
$message = "MyBB was unable to load the SQL extension. Please contact the MyBB Group for support. <a href=\"https://mybb.com\">MyBB Website</a>";
$error_code = MYBB_SQL_LOAD_ERROR;
break;
case "apc_load_error":
$message = "APC needs to be configured with PHP to use the APC cache support.";
$error_code = MYBB_CACHEHANDLER_LOAD_ERROR;
break;
case "eaccelerator_load_error":
$message = "eAccelerator needs to be configured with PHP to use the eAccelerator cache support.";
$error_code = MYBB_CACHEHANDLER_LOAD_ERROR;
break;
case "memcache_load_error":
$message = "Your server does not have memcache support enabled.";
$error_code = MYBB_CACHEHANDLER_LOAD_ERROR;
break;
case "memcached_load_error":
$message = "Your server does not have memcached support enabled.";
$error_code = MYBB_CACHEHANDLER_LOAD_ERROR;
break;
case "xcache_load_error":
$message = "Xcache needs to be configured with PHP to use the Xcache cache support.";
$error_code = MYBB_CACHEHANDLER_LOAD_ERROR;
break;
default:
$message = "MyBB has experienced an internal error. Please contact the MyBB Group for support. <a href=\"https://mybb.com\">MyBB Website</a>";
$error_code = MYBB_GENERAL;
}
$error_handler->trigger($message, $error_code);
}
function __destruct()
{
// Run shutdown function
if(function_exists("run_shutdown"))
{
run_shutdown();
}
}
}
/**
* Do this here because the core is used on every MyBB page
*/
$grouppermignore = array("gid", "type", "title", "description", "namestyle", "usertitle", "stars", "starimage", "image");
$groupzerogreater = array("pmquota", "maxpmrecipients", "maxreputationsday", "attachquota", "maxemails", "maxposts", "edittimelimit", "maxreputationsperuser", "maxreputationsperthread", "emailfloodtime");
$displaygroupfields = array("title", "description", "namestyle", "usertitle", "stars", "starimage", "image");
// These are fields in the usergroups table that are also forum permission specific.
$fpermfields = array(
'canview',
'canviewthreads',
'candlattachments',
'canpostthreads',
'canpostreplys',
'canpostattachments',
'canratethreads',
'caneditposts',
'candeleteposts',
'candeletethreads',
'caneditattachments',
'canviewdeletionnotice',
'modposts',
'modthreads',
'modattachments',
'mod_edit_posts',
'canpostpolls',
'canvotepolls',
'cansearch'
);