index.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. if (cfr('BACKUP')) {
  3. set_time_limit(0);
  4. $alterConf = $ubillingConfig->getAlter();
  5. if (!ubRouting::checkGet('restore')) {
  6. //new database backup creation
  7. if (ubRouting::post('createbackup')) {
  8. if (ubRouting::post('imready')) {
  9. if (!empty($alterConf['MYSQLDUMP_PATH'])) {
  10. //run system mysqldump command
  11. zb_BackupDatabase();
  12. } else {
  13. show_error(__('You missed an important option') . ': MYSQLDUMP_PATH');
  14. }
  15. } else {
  16. show_error(__('You are not mentally prepared for this'));
  17. }
  18. }
  19. //downloading mysql dump or another configs backup
  20. if (ubRouting::checkGet('download')) {
  21. if (cfr('BACKUPDL')) {
  22. $filePath = base64_decode(ubRouting::get('download'));
  23. zb_DownloadFile($filePath);
  24. } else {
  25. show_error(__('Access denied'));
  26. }
  27. }
  28. //deleting database dump
  29. if (ubRouting::checkGet('deletedump')) {
  30. //thats require root rights by security reasons
  31. if (cfr('ROOT')) {
  32. $deletePath = base64_decode(ubRouting::get('deletedump'));
  33. if (file_exists($deletePath)) {
  34. rcms_delete_files($deletePath);
  35. log_register('BACKUP DELETE `' . $deletePath . '`');
  36. ubRouting::nav('?module=backups');
  37. } else {
  38. show_error(__('Not existing item'));
  39. }
  40. } else {
  41. show_error(__('Access denied'));
  42. }
  43. }
  44. //tables cleanup
  45. if (ubRouting::checkGet('tableclean')) {
  46. if (cfr('ROOT')) {
  47. zb_DBTableCleanup(ubRouting::get('tableclean'));
  48. ubRouting::nav('?module=backups');
  49. } else {
  50. show_error(__('Access denied'));
  51. }
  52. }
  53. show_window(__('Create backup'), web_BackupForm());
  54. show_window(__('Available database backups'), web_AvailableDBBackupsList());
  55. show_window(__('Important Ubilling configs'), web_ConfigsUbillingList());
  56. show_window(__('Database cleanup'), web_DBCleanupForm());
  57. } else {
  58. //database restoration functionality here
  59. if (cfr('ROOT')) {
  60. if (!empty($alterConf['MYSQL_PATH'])) {
  61. if (ubRouting::checkGet('restoredump')) {
  62. $mysqlConf = rcms_parse_ini_file(CONFIG_PATH . 'mysql.ini');
  63. $billingConf = $ubillingConfig->getBilling();
  64. $restoreFilename = base64_decode(ubRouting::get('restoredump'));
  65. if (file_exists($restoreFilename)) {
  66. if (($billingConf['NOSTGCHECKPID']) AND ( !file_exists($billingConf['STGPID']))) {
  67. if (!ubRouting::checkPost('lastchanceok')) {
  68. $lastChanceInputs = __('Restoring a database from a dump, completely and permanently destroy your current database. Think again if you really want it.');
  69. $lastChanceInputs .= wf_tag('br');
  70. $lastChanceInputs .= __('Filename') . ': ' . $restoreFilename;
  71. $lastChanceInputs .= wf_tag('br');
  72. $lastChanceInputs .= wf_CheckInput('lastchanceok', __('I`m ready'), true, false);
  73. $lastChanceInputs .= wf_Submit(__('Restore DB'));
  74. $lastChanceForm = wf_Form('', 'POST', $lastChanceInputs, 'glamour');
  75. show_window(__('Warning'), $lastChanceForm);
  76. show_window('', wf_BackLink('?module=backups', __('Back'), true, 'ubButton'));
  77. } else {
  78. $restoreCommand = $alterConf['MYSQL_PATH'] . ' --host ' . $mysqlConf['server'] . ' -u ' . $mysqlConf['username'] . ' -p' . $mysqlConf['password'] . ' ' . $mysqlConf['db'] . ' --default-character-set=utf8 < ' . $restoreFilename . ' 2>&1';
  79. $restoreResult = shell_exec($restoreCommand);
  80. if (ispos($restoreResult, 'command line interface')) {
  81. $restoreResult = '';
  82. }
  83. if (empty($restoreResult)) {
  84. show_success(__('Success') . '! ' . __('Database') . ' ' . $mysqlConf['db'] . ' ' . __('is restored to server') . ' ' . $mysqlConf['server']);
  85. } else {
  86. show_error(__('Something went wrong'));
  87. show_window(__('Result'), $restoreResult);
  88. }
  89. show_window('', wf_BackLink('?module=backups'));
  90. }
  91. } else {
  92. log_register("BACKUP RESTORE TRY WITH RUNNING STARGAZER");
  93. show_error(__('You can restore database only with enabled NOSTGCHECKPID option and stopped Stargazer'));
  94. show_window('', wf_BackLink('?module=backups', __('Back'), true, 'ubButton'));
  95. }
  96. } else {
  97. show_error(__('Strange exeption') . ': NOT_EXISTING_DUMP_FILE');
  98. }
  99. } else {
  100. show_error(__('Strange exeption') . ': GET_NO_DUMP_FILENAME');
  101. }
  102. } else {
  103. show_error(__('You missed an important option') . ': MYSQL_PATH');
  104. }
  105. } else {
  106. show_error(__('You cant control this module'));
  107. }
  108. }
  109. } else {
  110. show_error(__('You cant control this module'));
  111. }