cron.php
48 lines
| 1 | <?php |
| 2 | if (function_exists('opcache_get_status')) ini_set('opcache.enable', 0); |
| 3 | ini_set('display_errors', 1); |
| 4 | ini_set('display_startup_errors', 1); |
| 5 | error_reporting(E_ALL); |
| 6 | |
| 7 | header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0'); |
| 8 | header('Pragma: no-cache'); |
| 9 | header('Expires: 0'); |
| 10 | |
| 11 | use JetBackup\Cron\Cron; |
| 12 | use JetBackup\Factory; |
| 13 | use JetBackup\Wordpress\Wordpress; |
| 14 | |
| 15 | //Use PHP_SAPI instead of HTTP headers to reliably distinguish CLI from web requests.. |
| 16 | $isWeb = PHP_SAPI !== 'cli'; |
| 17 | $location = ($_SERVER['SCRIPT_FILENAME'] ?? __FILE__); |
| 18 | // /home/user/public_html/wp-content/plugins/backup/public/cron/cron.php |
| 19 | |
| 20 | define ('WP_ROOT', dirname($location, 6)); |
| 21 | |
| 22 | if (!file_exists(WP_ROOT . DIRECTORY_SEPARATOR . 'wp-load.php')) { |
| 23 | die('Error: Cannot locate wp-load.php. Ensure WP_ROOT is correct.'); |
| 24 | } |
| 25 | |
| 26 | // Get into WordPress ecosystem |
| 27 | require_once(WP_ROOT . DIRECTORY_SEPARATOR . 'wp-load.php'); |
| 28 | |
| 29 | $_active_plugins = is_multisite() ? array_keys(get_site_option('active_sitewide_plugins')) : Wordpress::getOption('active_plugins'); |
| 30 | $_plugin_name = 'backup/backup.php'; // Cannot use DIRECTORY_SEPARATOR, will cause false positives with IIS |
| 31 | if (!in_array($_plugin_name, $_active_plugins)) die('JetBackup Plugin is inactive'); |
| 32 | |
| 33 | if ($isWeb) { |
| 34 | $key = Factory::getConfig()->getCronToken(); |
| 35 | $token = filter_input(INPUT_GET, 'token', FILTER_SANITIZE_FULL_SPECIAL_CHARS); |
| 36 | // hash_equals() for a timing-safe comparison (avoids leaking the token via response timing). |
| 37 | if (!$key || !$token || !hash_equals($key, $token)) { |
| 38 | http_response_code(403); |
| 39 | die('Forbidden'); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | try { |
| 44 | Cron::main(); |
| 45 | } catch(Exception $e) { |
| 46 | die($e->getMessage() . PHP_EOL); |
| 47 | } |
| 48 |