cron.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * BackupMODX cron connector
  4. *
  5. * @package backupmodx
  6. * @subpackage connector
  7. *
  8. * @var modX $modx
  9. */
  10. use BackupMODX\Backup\Backup;
  11. require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/config.core.php';
  12. require_once MODX_CORE_PATH . 'config/' . MODX_CONFIG_KEY . '.inc.php';
  13. require_once MODX_CONNECTORS_PATH . 'index.php';
  14. $corePath = $modx->getOption('backupmodx.core_path', null, $modx->getOption('core_path') . 'components/backupmodx/');
  15. /** @var BackupMODX $backupmodx */
  16. $backupmodx = $modx->getService('backupmodx', 'BackupMODX', $corePath . 'model/backupmodx/', array(
  17. 'core_path' => $corePath
  18. ));
  19. // Check if Cron is enabled
  20. if ($backupmodx->getOption('cronEnable') != true) {
  21. $msg = 'Access Denied. Cron is disabled in MODX system-settings.';
  22. if (php_sapi_name() == 'cli') {
  23. fwrite(STDERR, $msg . "\n");
  24. exit(1);
  25. } else {
  26. exit($msg);
  27. }
  28. }
  29. // Check Key for permission
  30. if (php_sapi_name() == 'cli') {
  31. if (!isset($_SERVER['argv'][1]) || $_SERVER['argv'][1] != $backupmodx->getOption('cronKey')) {
  32. fwrite(STDERR,
  33. 'Access Denied. Cron-Security-Key is not correct.' . "\n" .
  34. 'Usage: ' . basename($argv[0]) . ' <key>' . "\n");
  35. exit(1);
  36. }
  37. } else {
  38. if (!isset($_REQUEST['key']) || $_REQUEST['key'] != $backupmodx->getOption('cronKey')) {
  39. exit ('Access Denied. Cron-Security-Key is not correct.');
  40. }
  41. }
  42. // System Settings
  43. $files = $backupmodx->getOption('cronFiles');
  44. $database = $backupmodx->getOption('cronDatabase');
  45. $note = $backupmodx->getOption('cronNote');
  46. $maxDatabase = $backupmodx->getOption('cronMaxDatabase', array(), 10);
  47. $maxFiles = $backupmodx->getOption('cronMaxFiles', array(), 5);
  48. // Backup
  49. $backup = new Backup($modx);
  50. $result = $backup->backup($files, $database, $note);
  51. // Clean old Backups
  52. $backupmodx->cleanCronBackups($maxDatabase, $maxFiles);
  53. if (is_array($result)) {
  54. if (php_sapi_name() == 'cli') {
  55. exit(0);
  56. } else {
  57. exit;
  58. }
  59. } else {
  60. if (php_sapi_name() == 'cli') {
  61. fwrite(STDERR, $result . "\n");
  62. exit(1);
  63. } else {
  64. exit ($result);
  65. }
  66. }
  67. // @TODO - Optional Call to Backup-Center to send Files - Send optional E-mail