2015-04-01 15:35:27 +00:00
|
|
|
<?php
|
|
|
|
/*
|
2015-05-24 22:06:53 +00:00
|
|
|
* Sakura Community Management System
|
2016-02-02 21:04:15 +00:00
|
|
|
* (c) 2013-2016 Julian van de Groep <http://flash.moe>
|
2015-04-01 15:35:27 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
// Declare namespace
|
|
|
|
namespace Sakura;
|
|
|
|
|
|
|
|
// Define Sakura version
|
2016-02-05 11:20:33 +00:00
|
|
|
define('SAKURA_VERSION', '20160205');
|
2016-01-14 20:43:33 +00:00
|
|
|
define('SAKURA_VLABEL', 'Amethyst');
|
|
|
|
define('SAKURA_COLOUR', '#9966CC');
|
2015-04-01 15:35:27 +00:00
|
|
|
|
|
|
|
// Define Sakura Path
|
2015-12-03 19:40:01 +00:00
|
|
|
define('ROOT', __DIR__ . '/');
|
2015-04-01 15:35:27 +00:00
|
|
|
|
2015-12-04 14:19:10 +00:00
|
|
|
// Turn error reporting on for the initial startup sequence
|
|
|
|
error_reporting(-1);
|
2015-04-01 15:35:27 +00:00
|
|
|
|
2016-01-26 18:09:18 +00:00
|
|
|
// Override expiration variables
|
|
|
|
ignore_user_abort(true);
|
|
|
|
set_time_limit(0);
|
|
|
|
|
2015-07-05 00:03:15 +00:00
|
|
|
// Set internal encoding method
|
|
|
|
mb_internal_encoding('utf-8');
|
|
|
|
|
2015-08-23 22:08:36 +00:00
|
|
|
// Stop the execution if the PHP Version is older than 5.4.0
|
2016-02-05 11:20:33 +00:00
|
|
|
if (version_compare(phpversion(), '5.5.0', '<')) {
|
|
|
|
die('Sakura requires at least PHP 5.5.0, please upgrade to a newer PHP version.');
|
2015-08-23 22:08:36 +00:00
|
|
|
}
|
|
|
|
|
2015-11-13 23:11:55 +00:00
|
|
|
// Include third-party libraries
|
2015-12-04 13:52:57 +00:00
|
|
|
if (!@include_once ROOT . 'vendor/autoload.php') {
|
2015-12-10 20:55:51 +00:00
|
|
|
die('Autoloader not found, did you run composer?');
|
2015-12-03 19:40:01 +00:00
|
|
|
}
|
2015-11-13 23:11:55 +00:00
|
|
|
|
2015-12-29 01:27:49 +00:00
|
|
|
// Include core libraries
|
2015-12-09 20:21:08 +00:00
|
|
|
require_once ROOT . 'libraries/ActionCode.php';
|
2015-12-03 19:40:01 +00:00
|
|
|
require_once ROOT . 'libraries/Bans.php';
|
|
|
|
require_once ROOT . 'libraries/BBcode.php';
|
|
|
|
require_once ROOT . 'libraries/Comments.php';
|
|
|
|
require_once ROOT . 'libraries/Config.php';
|
2016-01-02 17:55:31 +00:00
|
|
|
require_once ROOT . 'libraries/CSRF.php';
|
2015-12-03 19:40:01 +00:00
|
|
|
require_once ROOT . 'libraries/Database.php';
|
|
|
|
require_once ROOT . 'libraries/File.php';
|
|
|
|
require_once ROOT . 'libraries/Hashing.php';
|
|
|
|
require_once ROOT . 'libraries/News.php';
|
|
|
|
require_once ROOT . 'libraries/Payments.php';
|
2015-12-29 01:27:49 +00:00
|
|
|
require_once ROOT . 'libraries/Perms.php';
|
2015-12-03 19:40:01 +00:00
|
|
|
require_once ROOT . 'libraries/Rank.php';
|
2016-01-30 00:18:23 +00:00
|
|
|
require_once ROOT . 'libraries/Router.php';
|
2015-12-03 19:40:01 +00:00
|
|
|
require_once ROOT . 'libraries/Session.php';
|
|
|
|
require_once ROOT . 'libraries/Template.php';
|
|
|
|
require_once ROOT . 'libraries/Trick.php';
|
|
|
|
require_once ROOT . 'libraries/Urls.php';
|
|
|
|
require_once ROOT . 'libraries/User.php';
|
|
|
|
require_once ROOT . 'libraries/Users.php';
|
2016-01-17 01:58:31 +00:00
|
|
|
require_once ROOT . 'libraries/Utils.php';
|
2015-12-03 19:40:01 +00:00
|
|
|
require_once ROOT . 'libraries/Whois.php';
|
2016-01-22 20:07:44 +00:00
|
|
|
require_once ROOT . 'libraries/Console/Application.php';
|
2016-02-05 12:26:31 +00:00
|
|
|
require_once ROOT . 'libraries/Controllers/Auth.php';
|
2016-02-04 20:56:40 +00:00
|
|
|
require_once ROOT . 'libraries/Controllers/Forums.php';
|
2016-01-30 00:18:23 +00:00
|
|
|
require_once ROOT . 'libraries/Controllers/Meta.php';
|
2016-02-04 20:56:40 +00:00
|
|
|
require_once ROOT . 'libraries/Controllers/User.php';
|
2015-12-03 19:40:01 +00:00
|
|
|
require_once ROOT . 'libraries/Forum/Forum.php';
|
|
|
|
require_once ROOT . 'libraries/Forum/Post.php';
|
|
|
|
require_once ROOT . 'libraries/Forum/Thread.php';
|
2015-12-29 01:27:49 +00:00
|
|
|
require_once ROOT . 'libraries/Perms/Forum.php';
|
2015-12-29 21:52:19 +00:00
|
|
|
require_once ROOT . 'libraries/Perms/Manage.php';
|
2015-12-29 01:27:49 +00:00
|
|
|
require_once ROOT . 'libraries/Perms/Site.php';
|
2015-04-01 15:35:27 +00:00
|
|
|
|
2015-05-29 19:27:45 +00:00
|
|
|
// Include database extensions
|
2015-12-03 19:40:01 +00:00
|
|
|
foreach (glob(ROOT . 'libraries/DBWrapper/*.php') as $driver) {
|
2015-07-30 01:12:53 +00:00
|
|
|
require_once $driver;
|
|
|
|
}
|
2015-04-01 15:35:27 +00:00
|
|
|
|
|
|
|
// Set Error handler
|
2016-01-17 01:58:31 +00:00
|
|
|
set_error_handler(['Sakura\Utils', 'errorHandler']);
|
2015-04-01 15:35:27 +00:00
|
|
|
|
2015-12-10 20:55:51 +00:00
|
|
|
// Load the local configuration
|
|
|
|
Config::init(ROOT . 'config/config.ini');
|
2015-05-29 19:27:45 +00:00
|
|
|
|
2015-12-04 14:19:10 +00:00
|
|
|
// Change error reporting according to the dev configuration
|
2015-12-27 04:37:57 +00:00
|
|
|
error_reporting(Config::local('dev', 'show_errors') ? -1 : 0);
|
2015-12-04 14:19:10 +00:00
|
|
|
|
2015-12-10 20:55:51 +00:00
|
|
|
// Make the database connection
|
|
|
|
Database::init(Config::local('database', 'driver'));
|
|
|
|
|
|
|
|
// Load the configuration stored in the database
|
|
|
|
Config::initDB();
|
|
|
|
|
2015-08-23 22:08:36 +00:00
|
|
|
// Assign servers file to whois class
|
2015-12-04 14:19:10 +00:00
|
|
|
Whois::setServers(ROOT . Config::local('data', 'whoisservers'));
|
2015-08-23 22:08:36 +00:00
|
|
|
|
2016-01-22 20:07:44 +00:00
|
|
|
// Check if we're using console
|
2016-01-26 18:09:18 +00:00
|
|
|
if (php_sapi_name() === 'cli' && !defined('SAKURA_CRON')) {
|
2016-01-22 20:07:44 +00:00
|
|
|
$console = new Console\Application;
|
|
|
|
$console->run($argv);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2015-09-12 19:57:44 +00:00
|
|
|
// Check if we the system has a cron service
|
2015-12-04 14:19:10 +00:00
|
|
|
if (Config::get('no_cron_service')) {
|
2015-09-12 19:57:44 +00:00
|
|
|
// If not do an "asynchronous" call to the cron.php script
|
2015-12-04 14:19:10 +00:00
|
|
|
if (Config::get('no_cron_last') < (time() - Config::get('no_cron_interval'))) {
|
2015-09-12 19:57:44 +00:00
|
|
|
// Check OS
|
2015-09-14 20:51:23 +00:00
|
|
|
if (substr(strtolower(PHP_OS), 0, 3) == 'win') {
|
2015-12-03 19:40:01 +00:00
|
|
|
pclose(popen('start /B ' . PHP_BINDIR . '\php.exe ' . addslashes(ROOT . 'cron.php'), 'r'));
|
2015-09-12 19:57:44 +00:00
|
|
|
} else {
|
2015-12-03 19:40:01 +00:00
|
|
|
pclose(popen(PHP_BINDIR . '/php ' . ROOT . 'cron.php > /dev/null 2>/dev/null &', 'r'));
|
2015-09-12 19:57:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update last execution time
|
2015-12-10 20:55:51 +00:00
|
|
|
Database::update('config', [['config_value' => time()], ['config_name' => ['no_cron_last', '=']]]);
|
2015-09-12 19:57:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-29 19:27:45 +00:00
|
|
|
// Start output buffering
|
2015-12-04 14:19:10 +00:00
|
|
|
ob_start(Config::get('use_gzip') ? 'ob_gzhandler' : null);
|
2015-04-01 15:35:27 +00:00
|
|
|
|
2016-01-30 00:18:23 +00:00
|
|
|
// Initialise the router
|
|
|
|
Router::init();
|
|
|
|
|
|
|
|
// Include routes file
|
|
|
|
include_once ROOT . 'routes.php';
|
|
|
|
|
2015-10-18 01:50:50 +00:00
|
|
|
// Auth check
|
|
|
|
$authCheck = Users::checkLogin();
|
|
|
|
|
2015-08-21 22:07:45 +00:00
|
|
|
// Create a user object for the current logged in user
|
2015-12-29 01:27:49 +00:00
|
|
|
$currentUser = User::construct($authCheck[0]);
|
2015-08-21 22:07:45 +00:00
|
|
|
|
2015-09-04 23:49:53 +00:00
|
|
|
// Create the Urls object
|
|
|
|
$urls = new Urls();
|
|
|
|
|
2015-08-29 13:25:57 +00:00
|
|
|
// Prepare the name of the template to load (outside of SAKURA_NO_TPL because it's used in imageserve.php)
|
2015-09-14 20:51:23 +00:00
|
|
|
$templateName =
|
2015-12-12 17:57:34 +00:00
|
|
|
!defined('SAKURA_MANAGE')
|
|
|
|
&& isset($currentUser->optionFields()['useMisaki'])
|
|
|
|
&& $currentUser->optionFields()['useMisaki'] ?
|
|
|
|
'misaki' : Config::get('site_style');
|
2015-07-30 01:12:53 +00:00
|
|
|
|
2015-09-14 20:51:23 +00:00
|
|
|
if (!defined('SAKURA_NO_TPL')) {
|
2016-02-04 20:56:40 +00:00
|
|
|
// Start templating engine
|
|
|
|
Template::set($templateName);
|
|
|
|
|
2015-07-30 01:12:53 +00:00
|
|
|
// Set base page rendering data
|
|
|
|
$renderData = [
|
|
|
|
'sakura' => [
|
2015-08-20 23:17:27 +00:00
|
|
|
'versionInfo' => [
|
2015-09-14 20:51:23 +00:00
|
|
|
'version' => SAKURA_VERSION,
|
2015-12-04 14:19:10 +00:00
|
|
|
],
|
|
|
|
|
|
|
|
'dev' => [
|
2015-12-27 04:37:57 +00:00
|
|
|
'showChangelog' => Config::local('dev', 'show_changelog'),
|
2015-08-20 23:17:27 +00:00
|
|
|
],
|
|
|
|
|
|
|
|
'cookie' => [
|
2015-12-04 14:19:10 +00:00
|
|
|
'prefix' => Config::get('cookie_prefix'),
|
|
|
|
'domain' => Config::get('cookie_domain'),
|
|
|
|
'path' => Config::get('cookie_path'),
|
2015-08-20 23:17:27 +00:00
|
|
|
],
|
|
|
|
|
2015-12-04 14:19:10 +00:00
|
|
|
'contentPath' => Config::get('content_path'),
|
|
|
|
'resources' => Config::get('content_path') . '/data/' . $templateName,
|
2015-08-20 23:17:27 +00:00
|
|
|
|
2015-12-04 14:19:10 +00:00
|
|
|
'charset' => Config::get('charset'),
|
|
|
|
'siteName' => Config::get('sitename'),
|
|
|
|
'siteLogo' => Config::get('sitelogo'),
|
|
|
|
'siteDesc' => Config::get('sitedesc'),
|
2016-01-02 17:55:31 +00:00
|
|
|
'siteTags' => json_decode(Config::get('sitetags'), true),
|
2015-12-04 14:19:10 +00:00
|
|
|
'dateFormat' => Config::get('date_format'),
|
2016-01-14 20:43:33 +00:00
|
|
|
'currentPage' => (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : null),
|
2015-10-22 14:24:18 +00:00
|
|
|
'referrer' => (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null),
|
2015-12-04 14:19:10 +00:00
|
|
|
'onlineTimeout' => Config::get('max_online_time'),
|
2015-12-11 20:49:40 +00:00
|
|
|
'announcementImage' => Config::get('header_announcement_image'),
|
|
|
|
'announcementLink' => Config::get('header_announcement_link'),
|
2016-01-10 18:24:47 +00:00
|
|
|
'trashForumId' => Config::get('forum_trash_id'),
|
2015-12-04 14:19:10 +00:00
|
|
|
|
|
|
|
'recaptchaPublic' => Config::get('recaptcha_public'),
|
|
|
|
'recaptchaEnabled' => Config::get('recaptcha'),
|
|
|
|
|
|
|
|
'disableRegistration' => Config::get('disable_registration'),
|
|
|
|
'lockAuth' => Config::get('lock_authentication'),
|
|
|
|
'requireActivation' => Config::get('require_activation'),
|
|
|
|
'minPwdEntropy' => Config::get('min_entropy'),
|
|
|
|
'minUsernameLength' => Config::get('username_min_length'),
|
|
|
|
'maxUsernameLength' => Config::get('username_max_length'),
|
2015-07-30 01:12:53 +00:00
|
|
|
],
|
|
|
|
'php' => [
|
|
|
|
'sessionid' => \session_id(),
|
2015-09-14 20:51:23 +00:00
|
|
|
'time' => \time(),
|
|
|
|
'self' => $_SERVER['PHP_SELF'],
|
2015-07-30 01:12:53 +00:00
|
|
|
],
|
|
|
|
|
2015-08-19 19:44:01 +00:00
|
|
|
'session' => [
|
2015-10-18 01:50:50 +00:00
|
|
|
'checkLogin' => $authCheck,
|
|
|
|
'sessionId' => $authCheck[1],
|
|
|
|
'userId' => $authCheck[0],
|
2015-08-19 19:44:01 +00:00
|
|
|
],
|
|
|
|
|
2015-09-04 23:49:53 +00:00
|
|
|
'user' => $currentUser,
|
2015-09-14 20:51:23 +00:00
|
|
|
'urls' => $urls,
|
2015-11-15 14:29:26 +00:00
|
|
|
|
|
|
|
'get' => $_GET,
|
|
|
|
'post' => $_POST,
|
2015-07-30 01:12:53 +00:00
|
|
|
];
|
|
|
|
|
2016-02-04 20:56:40 +00:00
|
|
|
// Add the default render data
|
|
|
|
Template::vars($renderData);
|
|
|
|
|
2015-09-16 20:34:36 +00:00
|
|
|
// Site closing
|
2015-12-04 14:19:10 +00:00
|
|
|
if (Config::get('site_closed')) {
|
2016-02-04 20:56:40 +00:00
|
|
|
// Set parse variables
|
|
|
|
Template::vars([
|
2015-09-16 20:34:36 +00:00
|
|
|
'page' => [
|
2015-12-04 14:19:10 +00:00
|
|
|
'message' => Config::get('site_closed_reason'),
|
2015-09-16 20:34:36 +00:00
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
2015-11-06 22:30:37 +00:00
|
|
|
// Print page contents
|
2016-02-04 20:56:40 +00:00
|
|
|
echo Template::render('global/information');
|
2015-09-16 20:34:36 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2015-07-30 01:12:53 +00:00
|
|
|
// Ban checking
|
2016-01-17 01:58:31 +00:00
|
|
|
if ($authCheck && !in_array($_SERVER['PHP_SELF'], [$urls->format('AUTH_ACTION', [], false)]) && $ban = Bans::checkBan($currentUser->id)) {
|
2015-07-30 01:12:53 +00:00
|
|
|
// Additional render data
|
2016-02-04 20:56:40 +00:00
|
|
|
Template::vars([
|
2015-07-30 01:12:53 +00:00
|
|
|
'ban' => [
|
2015-09-14 20:51:23 +00:00
|
|
|
'reason' => $ban['reason'],
|
|
|
|
'issued' => $ban['issued'],
|
|
|
|
'expires' => $ban['expires'],
|
2015-12-29 01:27:49 +00:00
|
|
|
'issuer' => (User::construct($ban['issuer'])),
|
2015-09-14 20:51:23 +00:00
|
|
|
],
|
2015-07-30 01:12:53 +00:00
|
|
|
]);
|
|
|
|
|
2015-11-06 22:30:37 +00:00
|
|
|
// Print page contents
|
2016-02-04 20:56:40 +00:00
|
|
|
echo Template::render('main/banned');
|
2015-07-30 01:12:53 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|