backup
5 years ago
database
7 years ago
exception
9 years ago
extension
8 years ago
log
9 years ago
notice
5 years ago
restore
8 years ago
schedule
6 years ago
storage
5 years ago
widget
8 years ago
SGBoot.php
5 years ago
SGConfig.php
10 years ago
SGPing.php
5 years ago
functions.php
5 years ago
functions.php
796 lines
| 1 | <?php |
| 2 | |
| 3 | function backupGuardGetSiteUrl() |
| 4 | { |
| 5 | if (SG_ENV_ADAPTER == SG_ENV_WORDPRESS) { |
| 6 | return get_site_url(); |
| 7 | } |
| 8 | else { |
| 9 | return sprintf( |
| 10 | "%s://%s%s", |
| 11 | isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http', |
| 12 | $_SERVER['SERVER_NAME'], |
| 13 | $_SERVER['REQUEST_URI'] |
| 14 | ); |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | function backupGuardGetCapabilities() |
| 19 | { |
| 20 | switch (SG_PRODUCT_IDENTIFIER) { |
| 21 | case 'backup-guard-en': |
| 22 | case 'backup-guard-wp-platinum': |
| 23 | case 'backup-guard-en-regular': |
| 24 | case 'backup-guard-en-extended': |
| 25 | return BACKUP_GUARD_CAPABILITIES_PLATINUM; |
| 26 | case 'backup-guard-wp-gold': |
| 27 | return BACKUP_GUARD_CAPABILITIES_GOLD; |
| 28 | case 'backup-guard-wp-silver': |
| 29 | return BACKUP_GUARD_CAPABILITIES_SILVER; |
| 30 | case 'backup-guard-wp-free': |
| 31 | return BACKUP_GUARD_CAPABILITIES_FREE; |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | function convertToReadableSize($size) |
| 36 | { |
| 37 | if (!$size) { |
| 38 | return '0'; |
| 39 | } |
| 40 | |
| 41 | $base = log($size) / log(1000); |
| 42 | $suffix = array("", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"); |
| 43 | $f_base = floor($base); |
| 44 | |
| 45 | return round(pow(1000, $base - floor($base)), 1) . $suffix[$f_base]; |
| 46 | } |
| 47 | |
| 48 | function backupGuardgetSealPopup() |
| 49 | { |
| 50 | $currentDate = time(); |
| 51 | $sgShouldShowPopup = SGConfig::get('SG_SHOULD_SHOW_POPUP') == null ? true : SGConfig::get('SG_SHOULD_SHOW_POPUP'); |
| 52 | $sgPluginInstallUpdateDate = SGConfig::get('SG_PLUGIN_INSTALL_UPDATE_DATE') == null ? time() : SGConfig::get('SG_PLUGIN_INSTALL_UPDATE_DATE'); |
| 53 | |
| 54 | // check ig plugin is active for free days show poup |
| 55 | if (($currentDate - $sgPluginInstallUpdateDate >= SG_PLUGIN_ACTIVE_INTERVAL) && $sgShouldShowPopup) { |
| 56 | ?> |
| 57 | <script> |
| 58 | window.SGPMPopupLoader=window.SGPMPopupLoader||{ids:[],popups:{},call:function(w,d,s,l,id){ |
| 59 | w['sgp']=w['sgp']||function(){(w['sgp'].q=w['sgp'].q||[]).push(arguments[0]);}; |
| 60 | var sg1=d.createElement(s),sg0=d.getElementsByTagName(s)[0]; |
| 61 | if(SGPMPopupLoader && SGPMPopupLoader.ids && SGPMPopupLoader.ids.length > 0){SGPMPopupLoader.ids.push(id); return;} |
| 62 | SGPMPopupLoader.ids.push(id); |
| 63 | sg1.onload = function(){SGPMPopup.openSGPMPopup();}; sg1.async=true; sg1.src=l; |
| 64 | sg0.parentNode.insertBefore(sg1,sg0); |
| 65 | return {}; |
| 66 | }}; |
| 67 | SGPMPopupLoader.call(window,document,'script','https://popupmaker.com/assets/lib/SGPMPopup.min.js','7c685e17'); |
| 68 | </script> |
| 69 | <?php |
| 70 | SGConfig::set('SG_SHOULD_SHOW_POPUP', 0); |
| 71 | } |
| 72 | |
| 73 | return; |
| 74 | } |
| 75 | |
| 76 | function backupGuardConvertDateTimezone($date, $dateFormat = "Y-m-d H:i:s", $timezone = "UTC") |
| 77 | { |
| 78 | if (in_array($timezone, timezone_identifiers_list())) { |
| 79 | $date = date_create($date); |
| 80 | $timezone = timezone_open($timezone); |
| 81 | date_timezone_set($date, $timezone); |
| 82 | |
| 83 | if (!$dateFormat) { |
| 84 | $dateFormat = "Y-m-d H:i:s"; |
| 85 | } |
| 86 | |
| 87 | return date_format($date, $dateFormat); |
| 88 | } |
| 89 | |
| 90 | return $date; |
| 91 | } |
| 92 | |
| 93 | function backupGuardRemoveSlashes($value) |
| 94 | { |
| 95 | if (SG_ENV_ADAPTER == SG_ENV_WORDPRESS) { |
| 96 | return wp_unslash($value); |
| 97 | } |
| 98 | else { |
| 99 | if (is_array($value)) { |
| 100 | return array_map('stripslashes', $value); |
| 101 | } |
| 102 | |
| 103 | return stripslashes($value); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | function backupGuardSanitizeTextField($value) |
| 108 | { |
| 109 | if (SG_ENV_ADAPTER == SG_ENV_WORDPRESS) { |
| 110 | if (is_array($value)) { |
| 111 | return array_map('sanitize_text_field', $value); |
| 112 | } |
| 113 | |
| 114 | return sanitize_text_field($value); |
| 115 | } |
| 116 | else { |
| 117 | if (is_array($value)) { |
| 118 | return array_map('strip_tags', $value); |
| 119 | } |
| 120 | |
| 121 | return strip_tags($value); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | function backupGuardIsMultisite() |
| 126 | { |
| 127 | if (SG_ENV_ADAPTER == SG_ENV_WORDPRESS) { |
| 128 | return defined('BG_IS_MULTISITE')?BG_IS_MULTISITE:is_multisite(); |
| 129 | } |
| 130 | else { |
| 131 | return false; |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | function backupGuardGetBanner($env, $type="plugin", $userType = null) |
| 136 | { |
| 137 | require_once(SG_LIB_PATH.'BackupGuard/Client.php'); |
| 138 | $client = new BackupGuard\Client(); |
| 139 | return $client->getBanner(strtolower($env), $type, $userType); |
| 140 | } |
| 141 | |
| 142 | function backupGuardGetFilenameOptions($options) |
| 143 | { |
| 144 | $selectedPaths = explode(',', $options['SG_BACKUP_FILE_PATHS']); |
| 145 | $pathsToExclude = explode(',', $options['SG_BACKUP_FILE_PATHS_EXCLUDE']); |
| 146 | |
| 147 | $opt = ''; |
| 148 | |
| 149 | if (SG_ENV_ADAPTER == SG_ENV_WORDPRESS) { |
| 150 | $opt .= 'opt('; |
| 151 | |
| 152 | if ($options['SG_BACKUP_TYPE'] == SG_BACKUP_TYPE_CUSTOM) { |
| 153 | if ($options['SG_ACTION_BACKUP_DATABASE_AVAILABLE']) { |
| 154 | $opt .= 'db_'; |
| 155 | } |
| 156 | |
| 157 | if ($options['SG_ACTION_BACKUP_FILES_AVAILABLE']) { |
| 158 | if (in_array('wp-content', $selectedPaths)) { |
| 159 | $opt .= 'wpc_'; |
| 160 | } |
| 161 | if (!in_array('wp-content/plugins', $pathsToExclude)) { |
| 162 | $opt .= 'plg_'; |
| 163 | } |
| 164 | if (!in_array('wp-content/themes', $pathsToExclude)) { |
| 165 | $opt .= 'thm_'; |
| 166 | } |
| 167 | if (!in_array('wp-content/uploads', $pathsToExclude)) { |
| 168 | $opt .= 'upl_'; |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | |
| 173 | } |
| 174 | else { |
| 175 | $opt .= 'full'; |
| 176 | } |
| 177 | |
| 178 | $opt = trim($opt, "_"); |
| 179 | $opt .= ')_'; |
| 180 | } |
| 181 | |
| 182 | return $opt; |
| 183 | } |
| 184 | |
| 185 | function backupGuardGenerateToken() |
| 186 | { |
| 187 | return md5(time()); |
| 188 | } |
| 189 | |
| 190 | // Parse a URL and return its components |
| 191 | function backupGuardParseUrl($url) |
| 192 | { |
| 193 | $urlComponents = parse_url($url); |
| 194 | $domain = $urlComponents['host']; |
| 195 | $port = ''; |
| 196 | |
| 197 | if (isset($urlComponents['port']) && strlen($urlComponents['port'])) { |
| 198 | $port = ":".$urlComponents['port']; |
| 199 | } |
| 200 | |
| 201 | $domain = preg_replace("/(www|\dww|w\dw|ww\d)\./", "", $domain); |
| 202 | |
| 203 | $path = ""; |
| 204 | if (isset($urlComponents['path'])) { |
| 205 | $path = $urlComponents['path']; |
| 206 | } |
| 207 | |
| 208 | return $domain.$port.$path; |
| 209 | } |
| 210 | |
| 211 | function backupGuardIsReloadEnabled() |
| 212 | { |
| 213 | // Check if reloads option is turned on |
| 214 | return SGConfig::get('SG_BACKUP_WITH_RELOADINGS')?true:false; |
| 215 | } |
| 216 | |
| 217 | function backupGuardGetBackupOptions($options) |
| 218 | { |
| 219 | $backupOptions = array( |
| 220 | 'SG_BACKUP_UPLOAD_TO_STORAGES' => '', |
| 221 | 'SG_BACKUP_FILE_PATHS_EXCLUDE' => '', |
| 222 | 'SG_BACKUP_FILE_PATHS' => '' |
| 223 | ); |
| 224 | |
| 225 | if (isset($options['sg-custom-backup-name']) && $options['sg-custom-backup-name']) { |
| 226 | SGConfig::set("SG_CUSTOM_BACKUP_NAME", $options['sg-custom-backup-name']); |
| 227 | } |
| 228 | else { |
| 229 | SGConfig::set("SG_CUSTOM_BACKUP_NAME", ''); |
| 230 | } |
| 231 | |
| 232 | //If background mode |
| 233 | $isBackgroundMode = !empty($options['backgroundMode']) ? 1 : 0; |
| 234 | |
| 235 | if ($isBackgroundMode) { |
| 236 | $backupOptions['SG_BACKUP_IN_BACKGROUND_MODE'] = $isBackgroundMode; |
| 237 | } |
| 238 | |
| 239 | //If cloud backup |
| 240 | if (!empty($options['backupCloud']) && count($options['backupStorages'])) { |
| 241 | $clouds = $options['backupStorages']; |
| 242 | $backupOptions['SG_BACKUP_UPLOAD_TO_STORAGES'] = implode(',', $clouds); |
| 243 | } |
| 244 | |
| 245 | $backupOptions['SG_BACKUP_TYPE'] = $options['backupType']; |
| 246 | |
| 247 | if ($options['backupType'] == SG_BACKUP_TYPE_FULL) { |
| 248 | $backupOptions['SG_ACTION_BACKUP_DATABASE_AVAILABLE']= 1; |
| 249 | $backupOptions['SG_ACTION_BACKUP_FILES_AVAILABLE'] = 1; |
| 250 | $backupOptions['SG_BACKUP_FILE_PATHS_EXCLUDE'] = SG_BACKUP_FILE_PATHS_EXCLUDE; |
| 251 | $backupOptions['SG_BACKUP_FILE_PATHS'] = 'wp-content'; |
| 252 | } |
| 253 | else if ($options['backupType'] == SG_BACKUP_TYPE_CUSTOM) { |
| 254 | //If database backup |
| 255 | $isDatabaseBackup = !empty($options['backupDatabase']) ? 1 : 0; |
| 256 | $backupOptions['SG_ACTION_BACKUP_DATABASE_AVAILABLE'] = $isDatabaseBackup; |
| 257 | |
| 258 | //If db backup |
| 259 | if($options['backupDBType']){ |
| 260 | $tablesToBackup = implode(',', $options['table']); |
| 261 | $backupOptions['SG_BACKUP_TABLES_TO_BACKUP'] = $tablesToBackup; |
| 262 | } |
| 263 | |
| 264 | //If files backup |
| 265 | if (!empty($options['backupFiles']) && count($options['directory'])) { |
| 266 | $backupFiles = explode(',', SG_BACKUP_FILE_PATHS); |
| 267 | $filesToExclude = @array_diff($backupFiles, $options['directory']); |
| 268 | |
| 269 | if (in_array('wp-content', $options['directory'])) { |
| 270 | $options['directory'] = array('wp-content'); |
| 271 | } |
| 272 | else { |
| 273 | $filesToExclude = array_diff($filesToExclude, array('wp-content')); |
| 274 | } |
| 275 | |
| 276 | $filesToExclude = implode(',', $filesToExclude); |
| 277 | if (strlen($filesToExclude)) { |
| 278 | $filesToExclude = ','.$filesToExclude; |
| 279 | } |
| 280 | |
| 281 | $backupOptions['SG_BACKUP_FILE_PATHS_EXCLUDE'] = SG_BACKUP_FILE_PATHS_EXCLUDE.$filesToExclude; |
| 282 | $options['directory'] = backupGuardSanitizeTextField($options['directory']); |
| 283 | $backupOptions['SG_BACKUP_FILE_PATHS'] = implode(',', $options['directory']); |
| 284 | $backupOptions['SG_ACTION_BACKUP_FILES_AVAILABLE'] = 1; |
| 285 | } |
| 286 | else { |
| 287 | $backupOptions['SG_ACTION_BACKUP_FILES_AVAILABLE'] = 0; |
| 288 | $backupOptions['SG_BACKUP_FILE_PATHS'] = 0; |
| 289 | } |
| 290 | } |
| 291 | return $backupOptions; |
| 292 | } |
| 293 | |
| 294 | function backupGuardLoadStateData() |
| 295 | { |
| 296 | if (file_exists(SG_BACKUP_DIRECTORY.SG_STATE_FILE_NAME)) { |
| 297 | $sgState = new SGState(); |
| 298 | $stateFile = file_get_contents(SG_BACKUP_DIRECTORY.SG_STATE_FILE_NAME); |
| 299 | $sgState = $sgState->factory($stateFile); |
| 300 | return $sgState; |
| 301 | } |
| 302 | |
| 303 | return false; |
| 304 | } |
| 305 | |
| 306 | function backupGuardValidateApiCall($token) |
| 307 | { |
| 308 | if (!strlen($token)) { |
| 309 | exit(); |
| 310 | } |
| 311 | |
| 312 | $statePath = SG_BACKUP_DIRECTORY.SG_STATE_FILE_NAME; |
| 313 | |
| 314 | if (!file_exists($statePath)) { |
| 315 | exit(); |
| 316 | } |
| 317 | |
| 318 | $state = file_get_contents($statePath); |
| 319 | $state = json_decode($state, true); |
| 320 | $stateToken = $state['token']; |
| 321 | |
| 322 | if ($stateToken != $token) { |
| 323 | exit(); |
| 324 | } |
| 325 | |
| 326 | return true; |
| 327 | } |
| 328 | |
| 329 | function backupGuardScanBackupsDirectory($path) |
| 330 | { |
| 331 | $backups = scandir($path); |
| 332 | $backupFolders = array(); |
| 333 | foreach ($backups as $key => $backup) { |
| 334 | if ($backup == "." || $backup == "..") { |
| 335 | continue; |
| 336 | } |
| 337 | |
| 338 | if (is_dir($path.$backup)) { |
| 339 | $backupFolders[$backup] = filemtime($path.$backup); |
| 340 | } |
| 341 | } |
| 342 | // Sort(from low to high) backups by creation date |
| 343 | asort($backupFolders); |
| 344 | return $backupFolders; |
| 345 | } |
| 346 | |
| 347 | function backupGuardSymlinksCleanup($dir) |
| 348 | { |
| 349 | if (is_dir($dir)) { |
| 350 | $objects = scandir($dir); |
| 351 | foreach ($objects as $object) { |
| 352 | if ($object == "." || $object == "..") { |
| 353 | continue; |
| 354 | } |
| 355 | |
| 356 | if (filetype($dir.$object) != "dir") { |
| 357 | @unlink($dir.$object); |
| 358 | } |
| 359 | else { |
| 360 | backupGuardSymlinksCleanup($dir.$object.'/'); |
| 361 | @rmdir($dir.$object); |
| 362 | } |
| 363 | } |
| 364 | } |
| 365 | else if (file_exists($dir)) { |
| 366 | @unlink($dir); |
| 367 | } |
| 368 | return; |
| 369 | } |
| 370 | |
| 371 | function backupGuardRealFilesize($filename) |
| 372 | { |
| 373 | $fp = fopen($filename, 'r'); |
| 374 | $return = false; |
| 375 | if (is_resource($fp)) |
| 376 | { |
| 377 | if (PHP_INT_SIZE < 8) // 32 bit |
| 378 | { |
| 379 | if (0 === fseek($fp, 0, SEEK_END)) |
| 380 | { |
| 381 | $return = 0.0; |
| 382 | $step = 0x7FFFFFFF; |
| 383 | while ($step > 0) |
| 384 | { |
| 385 | if (0 === fseek($fp, - $step, SEEK_CUR)) |
| 386 | { |
| 387 | $return += floatval($step); |
| 388 | } |
| 389 | else |
| 390 | { |
| 391 | $step >>= 1; |
| 392 | } |
| 393 | } |
| 394 | } |
| 395 | } |
| 396 | else if (0 === fseek($fp, 0, SEEK_END)) // 64 bit |
| 397 | { |
| 398 | $return = ftell($fp); |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | return $return; |
| 403 | } |
| 404 | |
| 405 | function backupGuardFormattedDuration($startTs, $endTs) |
| 406 | { |
| 407 | $unit = 'seconds'; |
| 408 | $duration = $endTs-$startTs; |
| 409 | if ($duration>=60 && $duration<3600) |
| 410 | { |
| 411 | $duration /= 60.0; |
| 412 | $unit = 'minutes'; |
| 413 | } |
| 414 | else if ($duration>=3600) |
| 415 | { |
| 416 | $duration /= 3600.0; |
| 417 | $unit = 'hours'; |
| 418 | } |
| 419 | $duration = number_format($duration, 2, '.', ''); |
| 420 | |
| 421 | return $duration.' '.$unit; |
| 422 | } |
| 423 | |
| 424 | function backupGuardDeleteDirectory($dirName) |
| 425 | { |
| 426 | $dirHandle = null; |
| 427 | if (is_dir($dirName)) |
| 428 | { |
| 429 | $dirHandle = opendir($dirName); |
| 430 | } |
| 431 | |
| 432 | if (!$dirHandle) |
| 433 | { |
| 434 | return false; |
| 435 | } |
| 436 | |
| 437 | while ($file = readdir($dirHandle)) |
| 438 | { |
| 439 | if ($file != "." && $file != "..") |
| 440 | { |
| 441 | if (!is_dir($dirName."/".$file)) |
| 442 | { |
| 443 | @unlink($dirName."/".$file); |
| 444 | } |
| 445 | else |
| 446 | { |
| 447 | backupGuardDeleteDirectory($dirName.'/'.$file); |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | closedir($dirHandle); |
| 453 | return @rmdir($dirName); |
| 454 | } |
| 455 | |
| 456 | function backupGuardDownloadFile($file, $type = 'application/octet-stream') |
| 457 | { |
| 458 | $file = backupGuardRemoveSlashes($file); |
| 459 | if (file_exists($file)) { |
| 460 | header('Content-Description: File Transfer'); |
| 461 | header('Content-Type: '.$type); |
| 462 | header('Content-Disposition: attachment; filename="'.basename($file).'";'); |
| 463 | header('Expires: 0'); |
| 464 | header('Cache-Control: must-revalidate'); |
| 465 | header('Pragma: public'); |
| 466 | header('Content-Length: ' . filesize($file)); |
| 467 | readfile($file); |
| 468 | } |
| 469 | |
| 470 | exit; |
| 471 | } |
| 472 | |
| 473 | function backupGuardDownloadViaPhp($backupName, $fileName) |
| 474 | { |
| 475 | $str = backupGuardMakeSymlinkFolder($fileName); |
| 476 | @copy(SG_BACKUP_DIRECTORY.$backupName.'/'.$fileName, SG_SYMLINK_PATH.$str.'/'.$fileName); |
| 477 | |
| 478 | if (file_exists(SG_SYMLINK_PATH.$str.'/'.$fileName)) { |
| 479 | $remoteGet = wp_remote_get(SG_SYMLINK_URL.$str.'/'.$fileName); |
| 480 | if (!is_wp_error($remoteGet)) { |
| 481 | $content = wp_remote_retrieve_body($remoteGet); |
| 482 | header('Pragma: public'); |
| 483 | header('Expires: 0'); |
| 484 | header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
| 485 | header('Cache-Control: private', false); |
| 486 | header('Content-Type: application/octet-stream'); |
| 487 | header('Content-Disposition: attachment; filename='.$fileName.';'); |
| 488 | header('Content-Transfer-Encoding: binary'); |
| 489 | echo $content; |
| 490 | exit; |
| 491 | } |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | function backupGuardMakeSymlinkFolder($filename) |
| 496 | { |
| 497 | $filename = backupGuardRemoveSlashes($filename); |
| 498 | |
| 499 | $downloaddir = SG_SYMLINK_PATH; |
| 500 | $downloadURL = SG_SYMLINK_URL; |
| 501 | |
| 502 | if (!file_exists($downloaddir)) { |
| 503 | mkdir($downloaddir, 0777); |
| 504 | } |
| 505 | |
| 506 | $letters = 'abcdefghijklmnopqrstuvwxyz'; |
| 507 | srand((double) microtime() * 1000000); |
| 508 | $string = ''; |
| 509 | |
| 510 | for ($i = 1; $i <= rand(4,12); $i++) { |
| 511 | $q = rand(1,24); |
| 512 | $string = $string.$letters[$q]; |
| 513 | } |
| 514 | |
| 515 | $handle = opendir($downloaddir); |
| 516 | while ($dir = readdir($handle)) { |
| 517 | if ($dir == "." || $dir == "..") { |
| 518 | continue; |
| 519 | } |
| 520 | |
| 521 | if (is_dir($downloaddir.$dir)) { |
| 522 | @unlink($downloaddir . $dir . "/" . $filename); |
| 523 | @rmdir($downloaddir . $dir); |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | closedir($handle); |
| 528 | mkdir($downloaddir . $string, 0777); |
| 529 | |
| 530 | return $string; |
| 531 | } |
| 532 | |
| 533 | function backupGuardDownloadFileSymlink($safedir, $filename) |
| 534 | { |
| 535 | $downloaddir = SG_SYMLINK_PATH; |
| 536 | $downloadURL = SG_SYMLINK_URL; |
| 537 | |
| 538 | $safedir = backupGuardRemoveSlashes($safedir); |
| 539 | $string = backupGuardMakeSymlinkFolder($filename); |
| 540 | |
| 541 | $res = @symlink($safedir . $filename, $downloaddir . $string . "/" . $filename); |
| 542 | if ($res) { |
| 543 | header('Content-Description: File Transfer'); |
| 544 | header('Content-Type: application/octet-stream'); |
| 545 | header('Content-Disposition: attachment;filename="'.$filename.'"'); |
| 546 | header('Content-Transfer-Encoding: binary'); |
| 547 | header("Location: " . $downloadURL . $string . "/" . $filename); |
| 548 | } |
| 549 | else{ |
| 550 | wp_die(_backupGuardT("Symlink / shortcut creation failed! Seems your server configurations don't allow symlink creation, so we're unable to provide you the direct download url. You can download your backup using any FTP client. All backups and related stuff we locate '/wp-content/uploads/backup-guard' directory. If you need this functionality, you should check out your server configurations and make sure you don't have any limitation related to symlink creation.", true)); |
| 551 | } |
| 552 | exit; |
| 553 | } |
| 554 | |
| 555 | function backupGuardGetCurrentUrlScheme() |
| 556 | { |
| 557 | return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off')?'https':'http'; |
| 558 | } |
| 559 | |
| 560 | function backupGuardValidateLicense() |
| 561 | { |
| 562 | $pluginCapabilities = backupGuardGetCapabilities(); |
| 563 | if ($pluginCapabilities == BACKUP_GUARD_CAPABILITIES_FREE) { |
| 564 | return true; |
| 565 | } |
| 566 | |
| 567 | //only check once per day |
| 568 | $ts = (int)SGConfig::get('SG_LICENSE_CHECK_TS'); |
| 569 | if (time() - $ts < SG_LICENSE_CHECK_TIMEOUT) { |
| 570 | return true; |
| 571 | } |
| 572 | |
| 573 | require_once(SG_LIB_PATH.'SGAuthClient.php'); |
| 574 | |
| 575 | $url = site_url(); |
| 576 | |
| 577 | $auth = SGAuthClient::getInstance(); |
| 578 | $res = $auth->validateUrl($url); |
| 579 | |
| 580 | if ($res === -1) { //login is required |
| 581 | backup_guard_login_page(); |
| 582 | return false; |
| 583 | } |
| 584 | else if ($res === false) { //invalid license |
| 585 | backup_guard_link_license_page(); |
| 586 | return false; |
| 587 | } |
| 588 | else { |
| 589 | SGConfig::set('SG_LICENSE_CHECK_TS', time(), true); |
| 590 | SGConfig::set('SG_LICENSE_KEY', $res, true); |
| 591 | } |
| 592 | |
| 593 | return true; |
| 594 | } |
| 595 | |
| 596 | //returns true if string $haystack ends with string $needle or $needle is an empty string |
| 597 | function backupGuardStringEndsWith($haystack, $needle) |
| 598 | { |
| 599 | $length = strlen($needle); |
| 600 | |
| 601 | return $length === 0 || |
| 602 | (substr($haystack, -$length) === $needle); |
| 603 | } |
| 604 | //returns true if string $haystack starts with string $needle |
| 605 | function backupGuardStringStartsWith($haystack, $needle) |
| 606 | { |
| 607 | $length = strlen($needle); |
| 608 | return (substr($haystack, 0, $length) === $needle); |
| 609 | } |
| 610 | |
| 611 | function backupGuardGetDbTables(){ |
| 612 | $sgdb = SGDatabase::getInstance(); |
| 613 | $tables = $sgdb->query("SHOW TABLES"); |
| 614 | $tablesKey = 'Tables_in_'.SG_DB_NAME; |
| 615 | $tableNames = array(); |
| 616 | $customTablesToExclude = str_replace(' ', '', SGConfig::get('SG_TABLES_TO_EXCLUDE')); |
| 617 | $tablesToExclude = explode(',', $customTablesToExclude); |
| 618 | foreach ($tables as $table): |
| 619 | $tableName = $table[$tablesKey]; |
| 620 | if($tableName != SG_ACTION_TABLE_NAME && $tableName != SG_CONFIG_TABLE_NAME && $tableName != SG_SCHEDULE_TABLE_NAME){ |
| 621 | array_push($tableNames, array('name'=>$tableName, |
| 622 | 'current'=> backupGuardStringStartsWith($tableName, SG_ENV_DB_PREFIX)? 'true':'false', |
| 623 | 'disabled'=>in_array($tableName,$tablesToExclude)? 'disabled':'' |
| 624 | )); |
| 625 | } |
| 626 | endforeach; |
| 627 | usort($tableNames, function ($name1, $name2){ |
| 628 | if(backupGuardStringStartsWith($name1['name'], SG_ENV_DB_PREFIX)){ |
| 629 | if(backupGuardStringStartsWith($name2['name'], SG_ENV_DB_PREFIX)){ |
| 630 | return 0; |
| 631 | } |
| 632 | return -1; |
| 633 | } |
| 634 | return 1; |
| 635 | }); |
| 636 | return $tableNames; |
| 637 | } |
| 638 | |
| 639 | function backupGuardGetBackupTablesHTML($defaultChecked = false){ |
| 640 | $tables = backupGuardGetDbTables(); |
| 641 | ?> |
| 642 | |
| 643 | <div class="checkbox"> |
| 644 | <label for="custom-backupdb-chbx"> |
| 645 | <input type="checkbox" class="sg-custom-option" name="backupDatabase" id="custom-backupdb-chbx" <?php echo $defaultChecked?'checked':'' ?>> |
| 646 | <span class="sg-checkbox-label-text"><?php _backupGuardT('Backup database'); ?></span> |
| 647 | </label> |
| 648 | <div class="col-md-12 sg-checkbox sg-backup-db-options"> |
| 649 | <div class="checkbox"> |
| 650 | <label for="custombackupdbfull-radio" class="sg-backup-db-mode" title="<?php _backupGuardT('Backup all tables found in the database')?>"> |
| 651 | <input type="radio" name="backupDBType" id="custombackupdbfull-radio" value="0" checked> |
| 652 | <?php _backupGuardT('Full'); ?> |
| 653 | </label> |
| 654 | <label for="custombackupdbcurent-radio" class="sg-backup-db-mode" title="<?php echo _backupGuardT('Backup tables related to the current WordPress installation. Only tables with', true).' '.SG_ENV_DB_PREFIX.' '._backupGuardT('will be backed up', true)?>"> |
| 655 | <input type="radio" name="backupDBType" id="custombackupdbcurent-radio" value="1"> |
| 656 | <?php _backupGuardT('Only WordPress'); ?> |
| 657 | </label> |
| 658 | <label for="custombackupdbcustom-radio" class="sg-backup-db-mode" title="<?php _backupGuardT('Select tables you want to include in your backup') ?>"> |
| 659 | <input type="radio" name="backupDBType" id="custombackupdbcustom-radio" value="2"> |
| 660 | <?php _backupGuardT('Custom'); ?> |
| 661 | </label> |
| 662 | <!--Tables--> |
| 663 | <div class="col-md-12 sg-custom-backup-tables"> |
| 664 | <?php foreach ($tables as $table): ?> |
| 665 | <div class="checkbox"> |
| 666 | <label for="<?php echo $table['name']?>"> |
| 667 | <input type="checkbox" name="table[]" current="<?php echo $table['current'] ?>" <?php echo $table['disabled'] ?> id="<?php echo $table['name']?>" value="<?php echo $table['name'];?>"> |
| 668 | <span class="sg-checkbox-label-text"><?php echo basename($table['name']);?></span> |
| 669 | <?php if($table['disabled']) {?> |
| 670 | <span class="sg-disableText"><?php _backupGuardT('(excluded from settings)') ?></span> |
| 671 | <?php } ?> |
| 672 | </label> |
| 673 | </div> |
| 674 | <?php endforeach;?> |
| 675 | </div> |
| 676 | </div> |
| 677 | </div> |
| 678 | |
| 679 | </div> |
| 680 | |
| 681 | <?php |
| 682 | |
| 683 | } |
| 684 | |
| 685 | function backupGuardIsAccountGold() |
| 686 | { |
| 687 | return strpos("gold", SG_PRODUCT_IDENTIFIER)!== false; |
| 688 | } |
| 689 | |
| 690 | function backupGuardGetProductName() |
| 691 | { |
| 692 | $name = ''; |
| 693 | switch (SG_PRODUCT_IDENTIFIER) { |
| 694 | case 'backup-guard-wp-silver': |
| 695 | $name = 'Silver'; |
| 696 | break; |
| 697 | case 'backup-guard-wp-platinum': |
| 698 | $name = 'Platinum'; |
| 699 | break; |
| 700 | case 'backup-guard-en': |
| 701 | case 'backup-guard-en-regular': |
| 702 | $name = 'Regular'; |
| 703 | break; |
| 704 | case 'backup-guard-en-extended': |
| 705 | $name = 'Extended'; |
| 706 | break; |
| 707 | case 'backup-guard-wp-gold': |
| 708 | $name = 'Gold'; |
| 709 | break; |
| 710 | case 'backup-guard-wp-free': |
| 711 | $name = 'Free'; |
| 712 | break; |
| 713 | } |
| 714 | |
| 715 | return $name; |
| 716 | } |
| 717 | |
| 718 | function backupGuardGetFileSelectiveRestore() |
| 719 | { |
| 720 | ?> |
| 721 | <div class="col-md-12 sg-checkbox sg-restore-files-options"> |
| 722 | <div class="checkbox"> |
| 723 | <label for="restorefilesfull-radio" class="sg-restore-files-mode" > |
| 724 | <input type="radio" name="restoreFilesType" checked id="restorefilesfull-radio" value="0"> |
| 725 | <?php _backupGuardT('Full'); ?> |
| 726 | </label> |
| 727 | |
| 728 | <label for="restorefilescustom-radio" class="sg-restore-files-mode"> |
| 729 | <input type="radio" name="restoreFilesType" id="restorefilescustom-radio" value="1"> |
| 730 | <?php _backupGuardT('Custom'); ?> |
| 731 | </label> |
| 732 | <!--Files--> |
| 733 | <div class="col-md-12 sg-file-selective-restore"> |
| 734 | <div id="fileSystemTreeContainer"></div> |
| 735 | </div> |
| 736 | </div> |
| 737 | </div> |
| 738 | <?php |
| 739 | } |
| 740 | |
| 741 | function checkAllMissedTables() |
| 742 | { |
| 743 | $sgdb = SGDatabase::getInstance(); |
| 744 | $allTables = array(SG_CONFIG_TABLE_NAME, SG_SCHEDULE_TABLE_NAME, SG_ACTION_TABLE_NAME); |
| 745 | $missedTables = array(); |
| 746 | $status = true; |
| 747 | |
| 748 | foreach ($allTables as $table) { |
| 749 | $query = $sgdb->query("SELECT count(*) as isExists |
| 750 | FROM information_schema.TABLES |
| 751 | WHERE (TABLE_SCHEMA = '".DB_NAME."') AND (TABLE_NAME = '$table')" |
| 752 | ); |
| 753 | |
| 754 | if (empty($query[0]['isExists'])) { |
| 755 | $status = false; |
| 756 | } |
| 757 | } |
| 758 | |
| 759 | return $status; |
| 760 | } |
| 761 | |
| 762 | function backupGuardIncludeFile($filePath) |
| 763 | { |
| 764 | if (file_exists($filePath)) { |
| 765 | include_once($filePath); |
| 766 | } |
| 767 | } |
| 768 | |
| 769 | function getCloudUploadDefaultMaxChunkSize() |
| 770 | { |
| 771 | $memory = (int)SGBoot::$memoryLimit; |
| 772 | $uploadSize = 1; |
| 773 | |
| 774 | if ($memory <= 128) { |
| 775 | $uploadSize = 4; |
| 776 | } |
| 777 | else if ($memory > 128 && $memory <= 256) { |
| 778 | $uploadSize = 8; |
| 779 | } |
| 780 | else if ($memory > 256 && $memory <= 512) { |
| 781 | $uploadSize = 16; |
| 782 | } |
| 783 | else if ($memory > 512) { |
| 784 | $uploadSize = 32; |
| 785 | } |
| 786 | |
| 787 | return $uploadSize; |
| 788 | } |
| 789 | |
| 790 | function getCloudUploadChunkSize() |
| 791 | { |
| 792 | $cloudUploadDefaultChunkSize = (int)getCloudUploadDefaultMaxChunkSize(); |
| 793 | $savedCloudUploadChunkSize = (int)SGConfig::get('SG_BACKUP_CLOUD_UPLOAD_CHUNK_SIZE'); |
| 794 | |
| 795 | return ($savedCloudUploadChunkSize ? $savedCloudUploadChunkSize:$cloudUploadDefaultChunkSize); |
| 796 | } |