awake.php
6 years ago
cancelBackup.php
6 years ago
cancelDownload.php
6 years ago
checkBackupCreation.php
6 years ago
checkPHPVersionCompatibility.php
6 years ago
checkRestoreCreation.php
6 years ago
cloudDropbox.php
6 years ago
curlChecker.php
6 years ago
deleteBackup.php
6 years ago
dismissDiscountNotice.php
6 years ago
downloadBackup.php
6 years ago
getAction.php
6 years ago
getBackupContent.php
6 years ago
getRunningActions.php
6 years ago
hideNotice.php
6 years ago
importBackup.php
6 years ago
isFeatureAvailable.php
6 years ago
manualBackup.php
6 years ago
modalImport.php
6 years ago
modalManualBackup.php
6 years ago
modalManualRestore.php
6 years ago
modalPrivacy.php
6 years ago
modalReview.php
6 years ago
modalTerms.php
6 years ago
resetStatus.php
6 years ago
restore.php
6 years ago
reviewBannerActions.php
6 years ago
schedule.php
6 years ago
setReviewPopupState.php
6 years ago
setUserInfoVerificationPopupState.php
6 years ago
settings.php
6 years ago
storeSubscriberInfo.php
6 years ago
storeSurveyResult.php
6 years ago
schedule.php
144 lines
| 1 | <?php |
| 2 | require_once(dirname(__FILE__).'/../boot.php'); |
| 3 | require_once(SG_BACKUP_PATH.'SGBackupSchedule.php'); |
| 4 | |
| 5 | $error = array(); |
| 6 | $success = array('success'=>1); |
| 7 | |
| 8 | if(backupGuardIsAjax() && count($_POST)) { |
| 9 | $_POST = backupGuardRemoveSlashes($_POST); |
| 10 | |
| 11 | if (isset($_POST['remove'])) { |
| 12 | if(isset($_POST['id'])) { |
| 13 | SGBackupSchedule::remove((int)$_POST['id']); |
| 14 | } |
| 15 | else { |
| 16 | SGBackupSchedule::remove(); |
| 17 | } |
| 18 | |
| 19 | die(json_encode($success)); |
| 20 | } |
| 21 | |
| 22 | //Check if cron available |
| 23 | if(!SGSchedule::isCronAvailable()) { |
| 24 | array_push($error, _backupGuardT('Cron is not available on your hosting.',true)); |
| 25 | die(json_encode($error)); |
| 26 | } |
| 27 | |
| 28 | $options = $_POST; |
| 29 | $cronOptions = array( |
| 30 | 'SG_BACKUP_IN_BACKGROUND_MODE' => 0, |
| 31 | 'SG_BACKUP_UPLOAD_TO_STORAGES' => '', |
| 32 | 'SG_ACTION_BACKUP_DATABASE_AVAILABLE' => 0, |
| 33 | 'SG_ACTION_BACKUP_FILES_AVAILABLE' => '', |
| 34 | 'SG_BACKUP_FILE_PATHS_EXCLUDE' => '', |
| 35 | 'SG_BACKUP_FILE_PATHS' => '', |
| 36 | ); |
| 37 | |
| 38 | $cronLabel = ''; |
| 39 | //Check if schedule name is not empaty |
| 40 | if (isset($options['sg-schedule-label'])) { |
| 41 | $label = trim($options['sg-schedule-label']); |
| 42 | $label = backupGuardSanitizeTextField($label); |
| 43 | if (empty($label)) { |
| 44 | array_push($error, _backupGuardT('Label field is required.',true)); |
| 45 | die(json_encode($error)); |
| 46 | } |
| 47 | else { |
| 48 | $cronLabel = $label; |
| 49 | } |
| 50 | } |
| 51 | else { |
| 52 | array_push($error, _backupGuardT('Label field is required.',true)); |
| 53 | die(json_encode($error)); |
| 54 | } |
| 55 | |
| 56 | //If background mode |
| 57 | $isBackgroundMode = isset($options['backgroundMode'])?1:0; |
| 58 | $cronOptions['SG_BACKUP_IN_BACKGROUND_MODE'] = $isBackgroundMode; |
| 59 | |
| 60 | //If cloud backup |
| 61 | if(isset($options['backupCloud']) && count($options['backupStorages'])) { |
| 62 | $clouds = backupGuardSanitizeTextField($options['backupStorages']); |
| 63 | $cronOptions['SG_BACKUP_UPLOAD_TO_STORAGES'] = implode(',', $clouds); |
| 64 | } |
| 65 | |
| 66 | $cronOptions['SG_BACKUP_TYPE'] = $options['backupType']; |
| 67 | |
| 68 | if ($options['backupType'] == SG_BACKUP_TYPE_FULL) { |
| 69 | $cronOptions['SG_BACKUP_FILE_PATHS_EXCLUDE'] = SG_BACKUP_FILE_PATHS_EXCLUDE; |
| 70 | $cronOptions['SG_BACKUP_FILE_PATHS'] = 'wp-content'; |
| 71 | $cronOptions['SG_ACTION_BACKUP_DATABASE_AVAILABLE'] = 1; |
| 72 | $cronOptions['SG_ACTION_BACKUP_FILES_AVAILABLE'] = 1; |
| 73 | } |
| 74 | else if ($options['backupType'] == SG_BACKUP_TYPE_CUSTOM) { |
| 75 | //If database backup |
| 76 | $isDatabaseBackup = isset($options['backupDatabase'])?1:0; |
| 77 | $cronOptions['SG_ACTION_BACKUP_DATABASE_AVAILABLE'] = $isDatabaseBackup; |
| 78 | |
| 79 | //If db backup |
| 80 | if($options['backupDBType']){ |
| 81 | $tablesToBackup = implode(',', $options['table']); |
| 82 | $backupOptions['SG_BACKUP_TABLES_TO_BACKUP'] = $tablesToBackup; |
| 83 | } |
| 84 | //If files backup |
| 85 | if(isset($options['backupFiles']) && count($options['directory'])) { |
| 86 | $backupFiles = explode(',', SG_BACKUP_FILE_PATHS); |
| 87 | $options['directory'] = backupGuardSanitizeTextField($options['directory']); |
| 88 | $filesToExclude = @array_diff($backupFiles, $options['directory']); |
| 89 | |
| 90 | if (in_array('wp-content', $options['directory'])) { |
| 91 | $options['directory'] = array('wp-content'); |
| 92 | } |
| 93 | else { |
| 94 | $filesToExclude = array_diff($filesToExclude, array('wp-content')); |
| 95 | } |
| 96 | |
| 97 | $filesToExclude = implode(',', $filesToExclude); |
| 98 | if (strlen($filesToExclude)) { |
| 99 | $filesToExclude = ','.$filesToExclude; |
| 100 | } |
| 101 | |
| 102 | $cronOptions['SG_BACKUP_FILE_PATHS_EXCLUDE'] = SG_BACKUP_FILE_PATHS_EXCLUDE.$filesToExclude; |
| 103 | $cronOptions['SG_ACTION_BACKUP_FILES_AVAILABLE'] = 1; |
| 104 | $cronOptions['SG_BACKUP_FILE_PATHS'] = implode(',', $options['directory']); |
| 105 | } |
| 106 | else { |
| 107 | $cronOptions['SG_ACTION_BACKUP_FILES_AVAILABLE'] = 0; |
| 108 | $cronOptions['SG_BACKUP_FILE_PATHS'] = 0; |
| 109 | } |
| 110 | } |
| 111 | else { |
| 112 | array_push($error, _backupGuardT('Invalid backup type', true)); |
| 113 | die(json_encode($error)); |
| 114 | } |
| 115 | |
| 116 | $scheduleIntervalDay = ''; |
| 117 | if ($options['scheduleInterval'] == BG_SCHEDULE_INTERVAL_WEEKLY && isset($options['sg-schedule-day-of-week'])) { |
| 118 | $scheduleIntervalDay = (int)$options['sg-schedule-day-of-week']; |
| 119 | } |
| 120 | else if($options['scheduleInterval'] == BG_SCHEDULE_INTERVAL_MONTHLY && isset($options['sg-schedule-day-of-month'])) { |
| 121 | $scheduleIntervalDay = (int)$options['sg-schedule-day-of-month']; |
| 122 | } |
| 123 | |
| 124 | try { |
| 125 | $cronTab = array( |
| 126 | 'dayOfInterval' => $scheduleIntervalDay, |
| 127 | 'intervalHour' => $options['scheduleHour'], |
| 128 | 'interval' => $options['scheduleInterval'] |
| 129 | ); |
| 130 | |
| 131 | if (isset($options['sg-schedule-id'])) { |
| 132 | SGBackupSchedule::remove($options['sg-schedule-id']); |
| 133 | } |
| 134 | |
| 135 | SGBackupSchedule::create($cronTab, $cronOptions, $cronLabel); |
| 136 | |
| 137 | die(json_encode($success)); |
| 138 | } |
| 139 | catch(SGException $exception) { |
| 140 | array_push($error, $exception->getMessage()); |
| 141 | die(json_encode($error)); |
| 142 | } |
| 143 | } |
| 144 |