banner
2 years ago
check
2 years ago
cli
2 years ago
cron
2 years ago
dashboard
2 years ago
database
2 years ago
extracter
2 years ago
htaccess
2 years ago
progress
2 years ago
scanner
2 years ago
staging
2 years ago
uploader
2 years ago
zipper
2 years ago
activation.php
2 years ago
ajax.php
2 years ago
analyst.php
2 years ago
backup-cli.php
2 years ago
backup-heart.php
2 years ago
bypasser.php
2 years ago
cli-handler.php
2 years ago
compatibility.php
2 years ago
config.php
2 years ago
constants.php
2 years ago
initializer.php
2 years ago
logger.php
2 years ago
restore-batching.php
2 years ago
backup-cli.php
114 lines
| 1 | <?php |
| 2 | |
| 3 | // Namespace |
| 4 | namespace BMI\Plugin\Heart; |
| 5 | |
| 6 | // Allow this script to run only via CLI |
| 7 | $cli = (php_sapi_name() === 'cli' || defined('STDIN')) ? true : false; |
| 8 | if (!$cli) { |
| 9 | echo '010011010101'; |
| 10 | exit; |
| 11 | } |
| 12 | |
| 13 | // Get fields |
| 14 | $file = __DIR__ . '/htaccess/bmi_cli_data.json'; |
| 15 | if (!file_exists($file)) { |
| 16 | echo '010011010111'; |
| 17 | exit; |
| 18 | } |
| 19 | $fields = json_decode(file_get_contents($file)); |
| 20 | // @unlink($file); |
| 21 | |
| 22 | function isFunctionEnabled($func) { |
| 23 | $disabled = explode(',', ini_get('disable_functions')); |
| 24 | $isDisabled = in_array($func, $disabled); |
| 25 | if (!$isDisabled && function_exists($func)) return true; |
| 26 | else return false; |
| 27 | } |
| 28 | |
| 29 | // Let other files know that it's CLI request |
| 30 | define('BMI_CURL_REQUEST', false); |
| 31 | define('BMI_CLI_REQUEST', true); |
| 32 | |
| 33 | // Load some constants |
| 34 | define('ABSPATH', $fields->abs_dir); |
| 35 | if (substr($fields->content_dir, -1) == '/') { |
| 36 | $fields->content_dir = $fields->content_dir . '/'; |
| 37 | } |
| 38 | define('WP_CONTENT_DIR', $fields->content_dir); |
| 39 | define('BMI_CONFIG_DIR', $fields->config_dir); |
| 40 | define('BMI_BACKUPS', $fields->backup_dir); |
| 41 | define('BMI_ROOT_DIR', $fields->root_dir); |
| 42 | define('BMI_INCLUDES', BMI_ROOT_DIR . 'includes'); |
| 43 | define('BMI_SAFELIMIT', intval($fields->safelimit)); |
| 44 | |
| 45 | // Replace error-log file |
| 46 | if (isFunctionEnabled('ini_set')) { |
| 47 | @ini_set('log_errors', 1); |
| 48 | @ini_set('error_log', BMI_CONFIG_DIR . '/background-errors.log'); |
| 49 | } |
| 50 | |
| 51 | // Increase max execution time |
| 52 | if (isFunctionEnabled('set_time_limit')) @set_time_limit(259200); |
| 53 | if (isFunctionEnabled('ini_set')) { |
| 54 | @ini_set('memory_limit', (BMI_SAFELIMIT * 4 + 16) . 'M'); |
| 55 | @ini_set('max_input_time', '259200'); |
| 56 | @ini_set('max_execution_time', '259200'); |
| 57 | @ini_set('session.gc_maxlifetime', '1200'); |
| 58 | } |
| 59 | |
| 60 | // Let the server know it's server-side script |
| 61 | if (isFunctionEnabled('ignore_user_abort')) { |
| 62 | @ignore_user_abort(true); |
| 63 | } |
| 64 | |
| 65 | if (isFunctionEnabled('session_write_close')) { |
| 66 | @session_write_close(); |
| 67 | } |
| 68 | |
| 69 | // Catch anything if possible |
| 70 | try { |
| 71 | |
| 72 | // Load bypasser |
| 73 | require_once BMI_INCLUDES . '/bypasser.php'; |
| 74 | $request = new BMI_Backup_Heart(true, |
| 75 | $fields->config_dir, |
| 76 | $fields->content_dir, |
| 77 | $fields->backup_dir, |
| 78 | $fields->abs_dir, |
| 79 | $fields->root_dir, |
| 80 | $fields->url, |
| 81 | [ |
| 82 | 'identy' => $fields->identy, |
| 83 | 'manifest' => $fields->manifest, |
| 84 | 'safelimit' => $fields->safelimit, |
| 85 | 'rev' => $fields->rev, |
| 86 | 'backupname' => $fields->backupname, |
| 87 | 'start' => $fields->start, |
| 88 | 'filessofar' => $fields->filessofar, |
| 89 | 'total_files' => $fields->total_files, |
| 90 | 'browser' => 'cli' |
| 91 | ], |
| 92 | 0, |
| 93 | 0, |
| 94 | 0 |
| 95 | ); |
| 96 | |
| 97 | // Handle request |
| 98 | $request->handle_batch(); |
| 99 | |
| 100 | } catch (\Exception $e) { |
| 101 | |
| 102 | error_log('There was an error with Backup Migration plugin: ' . $e->getMessage()); |
| 103 | error_log(strval($e)); |
| 104 | |
| 105 | } catch (\Throwable $e) { |
| 106 | |
| 107 | error_log('There was an error with Backup Migration plugin: ' . $e->getMessage()); |
| 108 | error_log(strval($e)); |
| 109 | |
| 110 | } |
| 111 | |
| 112 | // End the server task |
| 113 | exit; |
| 114 |