cron.php
43 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 | $isWeb = isset($_SERVER['HTTP_TE']) || isset($_SERVER['HTTP_COOKIE']) || isset($_SERVER['HTTP_ACCEPT']) ?? null; |
| 16 | $location = ($_SERVER['SCRIPT_FILENAME'] ?? __FILE__); |
| 17 | // /home/user/public_html/wp-content/plugins/backup/public/cron/cron.php |
| 18 | |
| 19 | define ('WP_ROOT', dirname($location, 6)); |
| 20 | |
| 21 | if (!file_exists(WP_ROOT . DIRECTORY_SEPARATOR . 'wp-load.php')) { |
| 22 | die('Error: Cannot locate wp-load.php. Ensure WP_ROOT is correct.'); |
| 23 | } |
| 24 | |
| 25 | // Get into WordPress ecosystem |
| 26 | require_once(WP_ROOT . DIRECTORY_SEPARATOR . 'wp-load.php'); |
| 27 | |
| 28 | $_active_plugins = is_multisite() ? array_keys(get_site_option('active_sitewide_plugins')) : Wordpress::getOption('active_plugins'); |
| 29 | $_plugin_name = 'backup/backup.php'; // Cannot use DIRECTORY_SEPARATOR, will cause false positives with IIS |
| 30 | if (!in_array($_plugin_name, $_active_plugins)) die('JetBackup Plugin is inactive'); |
| 31 | |
| 32 | if ($isWeb) { |
| 33 | $key = Factory::getConfig()->getCronToken(); |
| 34 | $token = filter_input(INPUT_GET, 'token', FILTER_SANITIZE_FULL_SPECIAL_CHARS); |
| 35 | if (!$key || !$token || $key != $token) die(1); |
| 36 | } |
| 37 | |
| 38 | try { |
| 39 | Cron::main(); |
| 40 | } catch(Exception $e) { |
| 41 | die($e->getMessage() . PHP_EOL); |
| 42 | } |
| 43 |