0) { ob_clean(); } echo $data; exit; } ob_start(); register_shutdown_function('handleFatalError'); set_error_handler('handleError', E_ALL | E_STRICT); $publicDir = str_replace('\\', '/', __DIR__) . '/'; $bearCMSDir = str_replace('\\', '/', dirname(__DIR__)) . '/bearcms/'; $isInstalled = function() use ($bearCMSDir) { return is_file($bearCMSDir . 'core/config.php'); }; if (isset($_POST['install'])) { if ($isInstalled()) { renderError('A configuration file (' . $bearCMSDir . 'core/config.php) from a previous Bear CMS installation is found! Please remove it before running the installer again.'); } if (version_compare(PHP_VERSION, '7.1.0', '<')) { renderError('The Bear CMS client requires PHP version 7.1.0 or newer! Current version is ' . PHP_VERSION . '. (1002)'); } $secretKey = isset($_POST['secretKey']) ? trim((string) $_POST['secretKey']) : ''; if (!isset($secretKey[0])) { renderError('The secret key is required!'); } if (!function_exists('curl_init')) { renderError('The PHP library cURL is required for installing the Bear CMS client! (1006)'); } if (isset($_SERVER['SCRIPT_NAME']) && pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_BASENAME) === 'index.php') { renderError('The installer file cannot be named index.php! (1003)'); } $makeDir = function($dir) { if (is_dir($dir)) { if (!is_writable($dir)) { renderError('The directory ' . $dir . ' is not writable! (1004)'); } } else { if (!mkdir($dir, 0777, true)) { renderError('Cannot create directory ' . $dir . '! (1005)'); } } }; $makeFile = function($filename, $content, $ignoreIfExists = false) use ($makeDir) { if ($ignoreIfExists && is_file($filename)) { return; } $makeDir(pathinfo($filename, PATHINFO_DIRNAME)); file_put_contents($filename, $content); if (pathinfo($filename, PATHINFO_EXTENSION) === 'php') { clearstatcache(true, $filename); if (function_exists('opcache_invalidate')) { opcache_invalidate($filename); } } }; $makeFile($publicDir . 'index.php', base64_decode('PD9waHAKCi8qCiAqIFRoaXMgZmlsZSBpcyBnZW5lcmF0ZWQgYnkgdGhlIEJlYXIgQ01TIFN0YW5kYWxvbmUgSW5zdGFsbGVyLgogKiBEbyBub3QgZWRpdCB0aGlzIGZpbGUsIGJlY2F1c2UgYWxsIHRoZSBjaGFuZ2VzIHdpbGwgYmUgbG9zdCBhZnRlciBydW5uaW5nIHRoZSB1cGRhdGUgbWFuYWdlci4KICovCgokY29yZUluZGV4ID0gX19ESVJfXyAuICcvLi4vYmVhcmNtcy9jb3JlL2luZGV4LnBocCc7CmlmIChpc19maWxlKCRjb3JlSW5kZXgpKSB7CiAgICByZXF1aXJlICRjb3JlSW5kZXg7Cn0gZWxzZSB7CiAgICBlY2hvICdDYW5ub3QgZmluZCB0aGUgY29yZSBpbmRleCBmaWxlISBZb3UgY2FuIGZpeCB0aGlzIGJ5IHJ1bm5pbmcgdGhlIGluc3RhbGxlciBhZ2Fpbi4nOwogICAgZXhpdDsKfQ==')); $makeFile($publicDir . '.htaccess', base64_decode('PElmTW9kdWxlIG1vZF9yZXdyaXRlLmM+CgpSZXdyaXRlRW5naW5lIE9uCgpSZXdyaXRlQ29uZCAle1JFUVVFU1RfRklMRU5BTUV9ICEtZApSZXdyaXRlQ29uZCAle1JFUVVFU1RfRklMRU5BTUV9ICEtZgpSZXdyaXRlUnVsZSBeIGluZGV4LnBocCBbTF0KCjwvSWZNb2R1bGU+'), true); $makeDir($bearCMSDir . '/data'); $makeDir($bearCMSDir . '/logs'); $makeFile($bearCMSDir . 'core/config.php', ' \'' . addslashes($secretKey) . '\' ]; '); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://bearcms.com/api/client/manager'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 30); $response = curl_exec($ch); $error = curl_error($ch); if (isset($error[0])) { throw new \Exception('Request curl error: ' . $error . '! (1027)'); } if ((int) curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200) { throw new \Exception(''); } $makeFile($bearCMSDir . 'core/manager.php', $response); $manager = require $bearCMSDir . 'core/manager.php'; try { $statusLog = []; if (!$manager->update($statusLog)) { unlink($bearCMSDir . 'core/config.php'); $statusLog = implode("\n", $statusLog); if (strpos($statusLog, 'Invalid appSecretKey!') !== false) { renderError('The secret key provided is not valid! You can generate a new one from your bearcms.com account!'); } else { renderError('Cannot download and install requirements! Please check the bearcms/core/update.log file!'); } } } catch (\Exception $e) { renderError($e->getMessage()); } echo '1'; exit; } ?>