| 1 |
<?php |
| 2 |
/** |
| 3 |
* This class handles the MainWP Post Backups. |
| 4 |
* |
| 5 |
* @package MainWP/Dashboard |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace MainWP\Dashboard; |
| 9 |
|
| 10 |
/** |
| 11 |
* Class MainWP_Post_Backup_Handler |
| 12 |
* |
| 13 |
* Handle Backup Post. |
| 14 |
* |
| 15 |
* @package MainWP\Dashboard |
| 16 |
* |
| 17 |
* @uses \MainWP\Dashboard\MainWP_Post_Base_Handler |
| 18 |
*/ |
| 19 |
class MainWP_Post_Backup_Handler extends MainWP_Post_Base_Handler { |
| 20 |
|
| 21 |
/** @var $instance Singleton MainWP_Post_Backup_Handler. */ |
| 22 |
private static $instance = null; |
| 23 |
|
| 24 |
/** |
| 25 |
* Create public static instance. |
| 26 |
* |
| 27 |
* @static |
| 28 |
* @return self $instance MainWP_Post_Backup_Handler. |
| 29 |
*/ |
| 30 |
public static function instance() { |
| 31 |
if ( null == self::$instance ) { |
| 32 |
self::$instance = new self(); |
| 33 |
} |
| 34 |
return self::$instance; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Init backups actions |
| 39 |
*/ |
| 40 |
public function init() { |
| 41 |
// Page: ManageBackups. |
| 42 |
$this->add_action( 'mainwp_addbackup', array( &$this, 'mainwp_addbackup' ) ); |
| 43 |
if ( mainwp_current_user_have_right( 'dashboard', 'edit_backup_tasks' ) ) { |
| 44 |
$this->add_action( 'mainwp_updatebackup', array( &$this, 'mainwp_updatebackup' ) ); |
| 45 |
} |
| 46 |
if ( mainwp_current_user_have_right( 'dashboard', 'delete_backup_tasks' ) ) { |
| 47 |
$this->add_action( 'mainwp_removebackup', array( &$this, 'mainwp_removebackup' ) ); |
| 48 |
} |
| 49 |
$this->add_action( 'mainwp_pausebackup', array( &$this, 'mainwp_pausebackup' ) ); |
| 50 |
$this->add_action( 'mainwp_resumebackup', array( &$this, 'mainwp_resumebackup' ) ); |
| 51 |
|
| 52 |
$this->add_action( 'mainwp_backuptask_get_sites', array( &$this, 'mainwp_backuptask_get_sites' ) ); |
| 53 |
|
| 54 |
if ( mainwp_current_user_have_right( 'dashboard', 'run_backup_tasks' ) ) { |
| 55 |
$this->add_action( 'mainwp_backuptask_run_site', array( &$this, 'mainwp_backuptask_run_site' ) ); |
| 56 |
} |
| 57 |
$this->add_action( 'mainwp_backup_upload_file', array( &$this, 'mainwp_backup_upload_file' ) ); |
| 58 |
|
| 59 |
// Page: backup. |
| 60 |
if ( mainwp_current_user_have_right( 'dashboard', 'run_backup_tasks' ) ) { |
| 61 |
$this->add_action( 'mainwp_backup_run_site', array( &$this, 'mainwp_backup_run_site' ) ); |
| 62 |
} |
| 63 |
if ( mainwp_current_user_have_right( 'dashboard', 'execute_backups' ) ) { |
| 64 |
$this->add_action( 'mainwp_backup', array( &$this, 'mainwp_backup' ) ); |
| 65 |
} |
| 66 |
$this->add_action( 'mainwp_checkbackups', array( &$this, 'mainwp_checkbackups' ) ); |
| 67 |
$this->add_action( 'mainwp_backup_checkpid', array( &$this, 'mainwp_backup_checkpid' ) ); |
| 68 |
$this->add_action( 'mainwp_createbackup_getfilesize', array( &$this, 'mainwp_createbackup_getfilesize' ) ); |
| 69 |
$this->add_action( 'mainwp_backup_download_file', array( &$this, 'mainwp_backup_download_file' ) ); |
| 70 |
$this->add_action( 'mainwp_backup_delete_file', array( &$this, 'mainwp_backup_delete_file' ) ); |
| 71 |
$this->add_action( 'mainwp_backup_getfilesize', array( &$this, 'mainwp_backup_getfilesize' ) ); |
| 72 |
$this->add_action( 'mainwp_backup_upload_getprogress', array( &$this, 'mainwp_backup_upload_getprogress' ) ); |
| 73 |
$this->add_action( 'mainwp_backup_upload_checkstatus', array( &$this, 'mainwp_backup_upload_checkstatus' ) ); |
| 74 |
} |
| 75 |
|
| 76 |
/* |
| 77 |
* Page: Backup |
| 78 |
*/ |
| 79 |
|
| 80 |
/** |
| 81 |
* Method mainwp_backup_run_site() |
| 82 |
* |
| 83 |
* Run backup task of site |
| 84 |
* |
| 85 |
* @throws MainWP_Exception on errors. |
| 86 |
* |
| 87 |
* @uses \MainWP\Dashboard\MainWP_Backup_Handler::backup() |
| 88 |
* @uses \MainWP\Dashboard\MainWP_Exception |
| 89 |
*/ |
| 90 |
public function mainwp_backup_run_site() { |
| 91 |
$this->secure_request( 'mainwp_backup_run_site' ); |
| 92 |
$site_id = isset( $_POST['site_id'] ) ? intval( $_POST['site_id'] ) : false; |
| 93 |
try { |
| 94 |
if ( ! $site_id ) { |
| 95 |
throw new MainWP_Exception( 'Site ID not found. Please reload the page and try again.', 'mainwp' ); |
| 96 |
} |
| 97 |
|
| 98 |
$ret = array( 'result' => MainWP_Backup_Handler::backup( $site_id, 'full', '', '', 1, 1, 1, 1 ) ); |
| 99 |
wp_send_json( $ret ); |
| 100 |
} catch ( MainWP_Exception $e ) { |
| 101 |
die( |
| 102 |
wp_json_encode( |
| 103 |
array( |
| 104 |
'error' => array( |
| 105 |
'message' => $e->getMessage(), |
| 106 |
'extra' => $e->get_message_extra(), |
| 107 |
), |
| 108 |
) |
| 109 |
) |
| 110 |
); |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* Method mainwp_backup() |
| 116 |
* |
| 117 |
* Run backup task |
| 118 |
* |
| 119 |
* @throws MainWP_Exception on errors. |
| 120 |
* |
| 121 |
* @uses \MainWP\Dashboard\MainWP_Backup_Handler::backup() |
| 122 |
* @uses \MainWP\Dashboard\MainWP_Exception |
| 123 |
*/ |
| 124 |
public function mainwp_backup() { |
| 125 |
$this->secure_request( 'mainwp_backup' ); |
| 126 |
$site_id = isset( $_POST['site_id'] ) ? intval( $_POST['site_id'] ) : false; |
| 127 |
try { |
| 128 |
if ( ! $site_id ) { |
| 129 |
throw new MainWP_Exception( 'Site ID not found. Please reload the page and try again.', 'mainwp' ); |
| 130 |
} |
| 131 |
|
| 132 |
$excludedFolder = isset( $_POST['exclude'] ) ? trim( $_POST['exclude'], "\n" ) : ''; |
| 133 |
$excludedFolder = explode( "\n", $excludedFolder ); |
| 134 |
$excludedFolder = array_map( array( MainWP_Utility::get_class_name(), 'trim_slashes' ), $excludedFolder ); |
| 135 |
$excludedFolder = array_map( 'htmlentities', $excludedFolder ); |
| 136 |
$excludedFolder = implode( ',', $excludedFolder ); |
| 137 |
|
| 138 |
$type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; |
| 139 |
$subfolder = isset( $_POST['subfolder'] ) ? sanitize_text_field( wp_unslash( $_POST['subfolder'] ) ) : ''; |
| 140 |
$excludebackup = isset( $_POST['excludebackup'] ) ? sanitize_text_field( wp_unslash( $_POST['excludebackup'] ) ) : ''; |
| 141 |
$excludecache = isset( $_POST['excludecache'] ) ? sanitize_text_field( wp_unslash( $_POST['excludecache'] ) ) : ''; |
| 142 |
$excludenonwp = isset( $_POST['excludenonwp'] ) ? sanitize_text_field( wp_unslash( $_POST['excludenonwp'] ) ) : ''; |
| 143 |
$excludezip = isset( $_POST['excludezip'] ) ? sanitize_text_field( wp_unslash( $_POST['excludezip'] ) ) : ''; |
| 144 |
$filename = isset( $_POST['filename'] ) ? sanitize_text_field( wp_unslash( $_POST['filename'] ) ) : ''; |
| 145 |
$fileNameUID = isset( $_POST['fileNameUID'] ) ? sanitize_text_field( wp_unslash( $_POST['fileNameUID'] ) ) : ''; |
| 146 |
$archiveFormat = isset( $_POST['archiveFormat'] ) ? sanitize_text_field( wp_unslash( $_POST['archiveFormat'] ) ) : ''; |
| 147 |
$maximumFileDescriptorsOverride = isset( $_POST['maximumFileDescriptorsOverride'] ) ? intval( $_POST['maximumFileDescriptorsOverride'] ) : false; |
| 148 |
$maximumFileDescriptorsAuto = isset( $_POST['maximumFileDescriptorsAuto'] ) ? intval( $_POST['maximumFileDescriptorsAuto'] ) : false; |
| 149 |
$maximumFileDescriptors = isset( $_POST['maximumFileDescriptors'] ) ? sanitize_text_field( wp_unslash( $_POST['maximumFileDescriptors'] ) ) : ''; |
| 150 |
$loadFilesBeforeZip = isset( $_POST['loadFilesBeforeZip'] ) ? sanitize_text_field( wp_unslash( $_POST['loadFilesBeforeZip'] ) ) : false; |
| 151 |
$pid = isset( $_POST['pid'] ) ? intval( $_POST['pid'] ) : false; |
| 152 |
$append = isset( $_POST['append'] ) ? intval( $_POST['append'] ) : false; |
| 153 |
|
| 154 |
$result = MainWP_Backup_Handler::backup( $site_id, $type, $subfolder, $excludedFolder, $excludebackup, $excludecache, $excludenonwp, $excludezip, $filename, $fileNameUID, $archiveFormat, $maximumFileDescriptorsOverride, $maximumFileDescriptorsAuto, $maximumFileDescriptors, $loadFilesBeforeZip, $pid, $append ); |
| 155 |
wp_send_json( array( 'result' => $result ) ); |
| 156 |
} catch ( MainWP_Exception $e ) { |
| 157 |
die( |
| 158 |
wp_json_encode( |
| 159 |
array( |
| 160 |
'error' => array( |
| 161 |
'message' => $e->getMessage(), |
| 162 |
'extra' => $e->get_message_extra(), |
| 163 |
), |
| 164 |
) |
| 165 |
) |
| 166 |
); |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
/** |
| 171 |
* Method mainwp_backup_checkpid() |
| 172 |
* |
| 173 |
* Check backup task |
| 174 |
* |
| 175 |
* @throws MainWP_Exception on errors. |
| 176 |
* |
| 177 |
* @uses \MainWP\Dashboard\MainWP_Backup_Handler::backup_check_pid() |
| 178 |
* @uses \MainWP\Dashboard\MainWP_Exception |
| 179 |
*/ |
| 180 |
public function mainwp_backup_checkpid() { |
| 181 |
$this->secure_request( 'mainwp_backup_checkpid' ); |
| 182 |
$site_id = isset( $_POST['site_id'] ) ? intval( $_POST['site_id'] ) : false; |
| 183 |
try { |
| 184 |
if ( ! $site_id ) { |
| 185 |
throw new MainWP_Exception( 'Site ID not found. Please reload the page and try again.', 'mainwp' ); |
| 186 |
} |
| 187 |
$pid = isset( $_POST['pid'] ) ? intval( $_POST['pid'] ) : false; |
| 188 |
$type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; |
| 189 |
$subfolder = isset( $_POST['subfolder'] ) ? sanitize_text_field( wp_unslash( $_POST['subfolder'] ) ) : ''; |
| 190 |
$filename = isset( $_POST['filename'] ) ? sanitize_text_field( wp_unslash( $_POST['filename'] ) ) : ''; |
| 191 |
wp_send_json( MainWP_Backup_Handler::backup_check_pid( $site_id, $pid, $type, $subfolder, $filename ) ); |
| 192 |
} catch ( MainWP_Exception $e ) { |
| 193 |
die( |
| 194 |
wp_json_encode( |
| 195 |
array( |
| 196 |
'error' => array( |
| 197 |
'message' => $e->getMessage(), |
| 198 |
'extra' => $e->get_message_extra(), |
| 199 |
), |
| 200 |
) |
| 201 |
) |
| 202 |
); |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
/** |
| 207 |
* Method mainwp_backup_download_file() |
| 208 |
* |
| 209 |
* Download backup file |
| 210 |
* |
| 211 |
* @throws MainWP_Exception on errors. |
| 212 |
* |
| 213 |
* @uses \MainWP\Dashboard\MainWP_Backup_Handler::backup_download_file() |
| 214 |
* @uses \MainWP\Dashboard\MainWP_Exception |
| 215 |
*/ |
| 216 |
public function mainwp_backup_download_file() { |
| 217 |
$this->secure_request( 'mainwp_backup_download_file' ); |
| 218 |
$site_id = isset( $_POST['site_id'] ) ? intval( $_POST['site_id'] ) : false; |
| 219 |
try { |
| 220 |
if ( ! $site_id ) { |
| 221 |
throw new MainWP_Exception( 'Site ID not found. Please reload the page and try again.', 'mainwp' ); |
| 222 |
} |
| 223 |
$type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; |
| 224 |
$url = isset( $_POST['url'] ) ? sanitize_text_field( wp_unslash( $_POST['url'] ) ) : ''; |
| 225 |
$local = isset( $_POST['local'] ) ? sanitize_text_field( wp_unslash( $_POST['local'] ) ) : ''; |
| 226 |
die( wp_json_encode( array( 'result' => MainWP_Backup_Handler::backup_download_file( $site_id, $type, $url, $local ) ) ) ); |
| 227 |
} catch ( MainWP_Exception $e ) { |
| 228 |
die( |
| 229 |
wp_json_encode( |
| 230 |
array( |
| 231 |
'error' => array( |
| 232 |
'message' => $e->getMessage(), |
| 233 |
'extra' => $e->get_message_extra(), |
| 234 |
), |
| 235 |
) |
| 236 |
) |
| 237 |
); |
| 238 |
} |
| 239 |
} |
| 240 |
|
| 241 |
/** |
| 242 |
* Method mainwp_backup_delete_file() |
| 243 |
* |
| 244 |
* Delete backup file |
| 245 |
* |
| 246 |
* @throws MainWP_Exception on errors. |
| 247 |
* |
| 248 |
* @uses \MainWP\Dashboard\MainWP_Backup_Handler::backup_delete_file() |
| 249 |
* @uses \MainWP\Dashboard\MainWP_Exception |
| 250 |
*/ |
| 251 |
public function mainwp_backup_delete_file() { |
| 252 |
$this->secure_request( 'mainwp_backup_delete_file' ); |
| 253 |
$site_id = isset( $_POST['site_id'] ) ? intval( $_POST['site_id'] ) : false; |
| 254 |
try { |
| 255 |
if ( ! $site_id ) { |
| 256 |
throw new MainWP_Exception( esc_html__( 'Site ID not found. Please reload the page and try again.', 'mainwp' ) ); |
| 257 |
} |
| 258 |
|
| 259 |
$site_id = isset( $_POST['site_id'] ) ? intval( $_POST['site_id'] ) : 0; |
| 260 |
$file = isset( $_POST['file'] ) ? sanitize_text_field( wp_unslash( $_POST['file'] ) ) : ''; |
| 261 |
|
| 262 |
die( wp_json_encode( array( 'result' => MainWP_Backup_Handler::backup_delete_file( $site_id, $file ) ) ) ); |
| 263 |
} catch ( MainWP_Exception $e ) { |
| 264 |
die( |
| 265 |
wp_json_encode( |
| 266 |
array( |
| 267 |
'error' => array( |
| 268 |
'message' => $e->getMessage(), |
| 269 |
'extra' => $e->get_message_extra(), |
| 270 |
), |
| 271 |
) |
| 272 |
) |
| 273 |
); |
| 274 |
} |
| 275 |
} |
| 276 |
|
| 277 |
/** |
| 278 |
* Method mainwp_createbackup_getfilesize() |
| 279 |
* |
| 280 |
* Get create backup file size. |
| 281 |
* |
| 282 |
* @throws \Exception on errors. |
| 283 |
* |
| 284 |
* @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed() |
| 285 |
* @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() |
| 286 |
* @uses \MainWP\Dashboard\MainWP_Utility::end_session() |
| 287 |
* @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit() |
| 288 |
*/ |
| 289 |
public function mainwp_createbackup_getfilesize() { |
| 290 |
$this->secure_request( 'mainwp_createbackup_getfilesize' ); |
| 291 |
|
| 292 |
try { |
| 293 |
if ( ! isset( $_POST['siteId'] ) ) { |
| 294 |
throw new \Exception( esc_html__( 'No site selected!', 'mainwp' ) ); |
| 295 |
} |
| 296 |
$siteId = isset( $_POST['siteId'] ) ? intval( $_POST['siteId'] ) : ''; |
| 297 |
$fileName = isset( $_POST['fileName'] ) ? sanitize_text_field( wp_unslash( $_POST['fileName'] ) ) : ''; |
| 298 |
$fileNameUID = isset( $_POST['fileNameUID'] ) ? sanitize_text_field( wp_unslash( $_POST['fileNameUID'] ) ) : ''; |
| 299 |
$type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; |
| 300 |
|
| 301 |
$website = MainWP_DB::instance()->get_website_by_id( $siteId ); |
| 302 |
if ( ! $website ) { |
| 303 |
throw new \Exception( esc_html__( 'No site selected!', 'mainwp' ) ); |
| 304 |
} |
| 305 |
|
| 306 |
MainWP_Utility::end_session(); |
| 307 |
// Send request to the childsite! |
| 308 |
$result = MainWP_Connect::fetch_url_authed( |
| 309 |
$website, |
| 310 |
'createBackupPoll', |
| 311 |
array( |
| 312 |
'fileName' => $fileName, |
| 313 |
'fileNameUID' => $fileNameUID, |
| 314 |
'type' => $type, |
| 315 |
) |
| 316 |
); |
| 317 |
|
| 318 |
if ( ! isset( $result['size'] ) ) { |
| 319 |
throw new \Exception( esc_html__( 'Invalid response!', 'mainwp' ) ); |
| 320 |
} |
| 321 |
|
| 322 |
if ( MainWP_Utility::ctype_digit( $result['size'] ) ) { |
| 323 |
$output = array( 'size' => $result['size'] ); |
| 324 |
} else { |
| 325 |
$output = array(); |
| 326 |
} |
| 327 |
} catch ( \Exception $e ) { |
| 328 |
$output = array( 'error' => $e->getMessage() ); |
| 329 |
} |
| 330 |
|
| 331 |
die( wp_json_encode( $output ) ); |
| 332 |
} |
| 333 |
|
| 334 |
/** |
| 335 |
* Method mainwp_backup_getfilesize() |
| 336 |
* |
| 337 |
* Get backup file size |
| 338 |
* |
| 339 |
* @uses \MainWP\Dashboard\MainWP_Exception |
| 340 |
* @uses \MainWP\Dashboard\MainWP_Manage_Sites::backup_get_file_size() |
| 341 |
*/ |
| 342 |
public function mainwp_backup_getfilesize() { |
| 343 |
$this->secure_request( 'mainwp_backup_getfilesize' ); |
| 344 |
|
| 345 |
try { |
| 346 |
$local = isset( $_POST['local'] ) ? sanitize_text_field( wp_unslash( $_POST['local'] ) ) : ''; |
| 347 |
die( wp_json_encode( array( 'result' => MainWP_Backup_Handler::backup_get_file_size( $local ) ) ) ); |
| 348 |
} catch ( MainWP_Exception $e ) { |
| 349 |
die( |
| 350 |
wp_json_encode( |
| 351 |
array( |
| 352 |
'error' => array( |
| 353 |
'message' => $e->getMessage(), |
| 354 |
'extra' => $e->get_message_extra(), |
| 355 |
), |
| 356 |
) |
| 357 |
) |
| 358 |
); |
| 359 |
} |
| 360 |
} |
| 361 |
|
| 362 |
/** |
| 363 |
* Method mainwp_backup_upload_checkstatus() |
| 364 |
* |
| 365 |
* Check upload status |
| 366 |
* |
| 367 |
* @throws MainWP_Exception on errors. |
| 368 |
* |
| 369 |
* @uses \MainWP\Dashboard\MainWP_Exception |
| 370 |
*/ |
| 371 |
public function mainwp_backup_upload_checkstatus() { |
| 372 |
$this->secure_request( 'mainwp_backup_upload_checkstatus' ); |
| 373 |
|
| 374 |
try { |
| 375 |
$unique = isset( $_POST['unique'] ) ? sanitize_text_field( wp_unslash( $_POST['unique'] ) ) : false; |
| 376 |
$array = get_option( 'mainwp_upload_progress' ); |
| 377 |
$info = apply_filters( 'mainwp_remote_destination_info', array(), ( isset( $_POST['remote_destination'] ) ? sanitize_text_field( wp_unslash( $_POST['remote_destination'] ) ) : '' ) ); |
| 378 |
|
| 379 |
if ( ! is_array( $array ) || empty( $unique ) || empty( $array[ $unique ] ) || empty( $array[ $unique ]['dts'] ) ) { |
| 380 |
die( |
| 381 |
wp_json_encode( |
| 382 |
array( |
| 383 |
'status' => 'stalled', |
| 384 |
'info' => $info, |
| 385 |
) |
| 386 |
) |
| 387 |
); |
| 388 |
} elseif ( isset( $array[ $unique ]['finished'] ) ) { |
| 389 |
die( |
| 390 |
wp_json_encode( |
| 391 |
array( |
| 392 |
'status' => 'done', |
| 393 |
'info' => $info, |
| 394 |
) |
| 395 |
) |
| 396 |
); |
| 397 |
} else { |
| 398 |
|
| 399 |
if ( isset( $array[ $unique ]['dts'] ) && intval( $array[ $unique ]['dts'] ) < ( time() - ( 2 * 60 ) ) ) { // 2minutes. |
| 400 |
die( |
| 401 |
wp_json_encode( |
| 402 |
array( |
| 403 |
'status' => 'stalled', |
| 404 |
'info' => $info, |
| 405 |
) |
| 406 |
) |
| 407 |
); |
| 408 |
} else { |
| 409 |
die( |
| 410 |
wp_json_encode( |
| 411 |
array( |
| 412 |
'status' => 'busy', |
| 413 |
'info' => $info, |
| 414 |
) |
| 415 |
) |
| 416 |
); |
| 417 |
} |
| 418 |
} |
| 419 |
} catch ( MainWP_Exception $e ) { |
| 420 |
die( |
| 421 |
wp_json_encode( |
| 422 |
array( |
| 423 |
'error' => array( |
| 424 |
'message' => $e->getMessage(), |
| 425 |
'extra' => $e->get_message_extra(), |
| 426 |
), |
| 427 |
) |
| 428 |
) |
| 429 |
); |
| 430 |
} |
| 431 |
} |
| 432 |
|
| 433 |
/** |
| 434 |
* Method mainwp_backup_upload_getprogress() |
| 435 |
* |
| 436 |
* Get progress status |
| 437 |
* |
| 438 |
* @throws MainWP_Exception on finished or errors. |
| 439 |
* |
| 440 |
* @uses \MainWP\Dashboard\MainWP_Exception |
| 441 |
*/ |
| 442 |
public function mainwp_backup_upload_getprogress() { |
| 443 |
$this->secure_request( 'mainwp_backup_upload_getprogress' ); |
| 444 |
|
| 445 |
try { |
| 446 |
$array = get_option( 'mainwp_upload_progress' ); |
| 447 |
$unique = isset( $_POST['unique'] ) ? sanitize_text_field( wp_unslash( $_POST['unique'] ) ) : false; |
| 448 |
|
| 449 |
if ( ! is_array( $array ) || ! isset( $array[ $unique ] ) ) { |
| 450 |
die( wp_json_encode( array( 'result' => 0 ) ) ); |
| 451 |
} elseif ( isset( $array[ $unique ]['finished'] ) ) { |
| 452 |
throw new MainWP_Exception( esc_html__( 'finished...', 'maiwnp' ) ); |
| 453 |
} else { |
| 454 |
wp_send_json( array( 'result' => ( isset( $array[ $unique ]['offset'] ) ? $array[ $unique ]['offset'] : $array[ $unique ] ) ) ); |
| 455 |
} |
| 456 |
} catch ( MainWP_Exception $e ) { |
| 457 |
die( |
| 458 |
wp_json_encode( |
| 459 |
array( |
| 460 |
'error' => array( |
| 461 |
'message' => $e->getMessage(), |
| 462 |
'extra' => $e->get_message_extra(), |
| 463 |
), |
| 464 |
) |
| 465 |
) |
| 466 |
); |
| 467 |
} |
| 468 |
} |
| 469 |
|
| 470 |
/* |
| 471 |
* Page: ManageBackups |
| 472 |
*/ |
| 473 |
|
| 474 |
/** |
| 475 |
* Method mainwp_addbackup() |
| 476 |
* |
| 477 |
* Add task to the database. |
| 478 |
* |
| 479 |
* @uses \MainWP\Dashboard\MainWP_Manage_Backups_Handler::add_backup() |
| 480 |
*/ |
| 481 |
public function mainwp_addbackup() { |
| 482 |
$this->secure_request( 'mainwp_addbackup' ); |
| 483 |
|
| 484 |
MainWP_Manage_Backups_Handler::add_backup(); |
| 485 |
} |
| 486 |
|
| 487 |
/** |
| 488 |
* Method mainwp_updatebackup() |
| 489 |
* |
| 490 |
* Update task. |
| 491 |
* |
| 492 |
* @uses \MainWP\Dashboard\MainWP_Manage_Backups_Handler::update_backup() |
| 493 |
*/ |
| 494 |
public function mainwp_updatebackup() { |
| 495 |
$this->secure_request( 'mainwp_updatebackup' ); |
| 496 |
|
| 497 |
MainWP_Manage_Backups_Handler::update_backup(); |
| 498 |
} |
| 499 |
|
| 500 |
/** |
| 501 |
* Method mainwp_removebackup() |
| 502 |
* |
| 503 |
* Remove a task from MainWP. |
| 504 |
* |
| 505 |
* @uses \MainWP\Dashboard\MainWP_Manage_Backups_Handler::remove_backup() |
| 506 |
*/ |
| 507 |
public function mainwp_removebackup() { |
| 508 |
$this->secure_request( 'mainwp_removebackup' ); |
| 509 |
|
| 510 |
MainWP_Manage_Backups_Handler::remove_backup(); |
| 511 |
} |
| 512 |
|
| 513 |
/** |
| 514 |
* Method mainwp_resumebackup() |
| 515 |
* |
| 516 |
* Resume backup task. |
| 517 |
* |
| 518 |
* @uses \MainWP\Dashboard\MainWP_Manage_Backups_Handler::resume_backup() |
| 519 |
*/ |
| 520 |
public function mainwp_resumebackup() { |
| 521 |
$this->secure_request( 'mainwp_resumebackup' ); |
| 522 |
|
| 523 |
MainWP_Manage_Backups_Handler::resume_backup(); |
| 524 |
} |
| 525 |
|
| 526 |
/** |
| 527 |
* Method mainwp_pausebackup() |
| 528 |
* |
| 529 |
* Pause backup task. |
| 530 |
* |
| 531 |
* @uses \MainWP\Dashboard\MainWP_Manage_Backups_Handler::pause_backup() |
| 532 |
*/ |
| 533 |
public function mainwp_pausebackup() { |
| 534 |
$this->secure_request( 'mainwp_pausebackup' ); |
| 535 |
|
| 536 |
MainWP_Manage_Backups_Handler::pause_backup(); |
| 537 |
} |
| 538 |
|
| 539 |
/** |
| 540 |
* Method mainwp_backuptask_get_sites() |
| 541 |
* |
| 542 |
* Get sites of backup task. |
| 543 |
* |
| 544 |
* @uses \MainWP\Dashboard\MainWP_Manage_Backups_Handler::get_backup_task_sites() |
| 545 |
*/ |
| 546 |
public function mainwp_backuptask_get_sites() { |
| 547 |
$this->secure_request( 'mainwp_backuptask_get_sites' ); |
| 548 |
|
| 549 |
$taskID = isset( $_POST['task_id'] ) ? intval( $_POST['task_id'] ) : 0; |
| 550 |
|
| 551 |
wp_send_json( array( 'result' => MainWP_Manage_Backups_Handler::get_backup_task_sites( $taskID ) ) ); |
| 552 |
} |
| 553 |
|
| 554 |
/** |
| 555 |
* Method mainwp_backuptask_run_site() |
| 556 |
* |
| 557 |
* Run backup task of site. |
| 558 |
* |
| 559 |
* @throws MainWP_Exception on errors. |
| 560 |
* |
| 561 |
* @uses \MainWP\Dashboard\MainWP_Exception |
| 562 |
* @uses \MainWP\Dashboard\MainWP_Manage_Backups_Handler::backup() |
| 563 |
*/ |
| 564 |
public function mainwp_backuptask_run_site() { |
| 565 |
try { |
| 566 |
$this->secure_request( 'mainwp_backuptask_run_site' ); |
| 567 |
$site_id = isset( $_POST['site_id'] ) ? intval( $_POST['site_id'] ) : false; |
| 568 |
$task_id = isset( $_POST['task_id'] ) ? intval( $_POST['task_id'] ) : false; |
| 569 |
if ( ! $site_id || ! $task_id ) { |
| 570 |
throw new MainWP_Exception( esc_html__( 'Site ID or backup task ID not found. Please reload the page and try again.', 'mainwp' ) ); |
| 571 |
} |
| 572 |
|
| 573 |
$fileNameUID = isset( $_POST['fileNameUID'] ) ? sanitize_text_field( wp_unslash( $_POST['fileNameUID'] ) ) : false; |
| 574 |
wp_send_json( array( 'result' => MainWP_Manage_Backups_Handler::backup( $task_id, $site_id, $fileNameUID ) ) ); |
| 575 |
} catch ( MainWP_Exception $e ) { |
| 576 |
die( |
| 577 |
wp_json_encode( |
| 578 |
array( |
| 579 |
'error' => array( |
| 580 |
'message' => $e->getMessage(), |
| 581 |
'extra' => $e->get_message_extra(), |
| 582 |
), |
| 583 |
) |
| 584 |
) |
| 585 |
); |
| 586 |
} |
| 587 |
} |
| 588 |
|
| 589 |
/** |
| 590 |
* Method mainwp_checkbackups() |
| 591 |
* |
| 592 |
* Check backup status. |
| 593 |
* |
| 594 |
* @throws \Exception on errors. |
| 595 |
* |
| 596 |
* @uses \MainWP\Dashboard\MainWP_Updates_Overview::check_backups() |
| 597 |
*/ |
| 598 |
public function mainwp_checkbackups() { |
| 599 |
$this->secure_request( 'mainwp_checkbackups' ); |
| 600 |
|
| 601 |
try { |
| 602 |
wp_send_json( array( 'result' => MainWP_Updates_Overview::check_backups() ) ); |
| 603 |
} catch ( \Exception $e ) { |
| 604 |
die( wp_json_encode( array( 'error' => $e->getMessage() ) ) ); |
| 605 |
} |
| 606 |
} |
| 607 |
} |
| 608 |
|