index.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. if (cfr('BACKUP')) {
  3. set_time_limit(0);
  4. $alterConf = $ubillingConfig->getAlter();
  5. $binPathsConf = $ubillingConfig->getBinpaths();
  6. if (!ubRouting::checkGet(array('restore'))) {
  7. if (ubRouting::post('createbackup')) {
  8. if (ubRouting::post('imready')) {
  9. if (!empty($binPathsConf['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
  20. if (ubRouting::checkGet('download')) {
  21. if (cfr('ROOT')) {
  22. $filePath = base64_decode(ubRouting::get('download'));
  23. zb_DownloadFile($filePath);
  24. } else {
  25. show_error(__('Access denied'));
  26. }
  27. }
  28. //deleting dump
  29. if (ubRouting::checkGet('deletedump')) {
  30. if (cfr('ROOT')) {
  31. $deletePath = base64_decode(ubRouting::get('deletedump'));
  32. if (file_exists($deletePath)) {
  33. rcms_delete_files($deletePath);
  34. log_register('BACKUP DELETE `' . $deletePath . '`');
  35. ubRouting::nav('?module=backups');
  36. } else {
  37. show_error(__('Not existing item'));
  38. }
  39. } else {
  40. show_error(__('Access denied'));
  41. }
  42. }
  43. function web_AvailableDBBackupsList() {
  44. $backupsPath = DATA_PATH . 'backups/sql/';
  45. $availbacks = rcms_scandir($backupsPath);
  46. $messages = new UbillingMessageHelper();
  47. $result = $messages->getStyledMessage(__('No existing DB backups here'), 'warning');
  48. if (!empty($availbacks)) {
  49. $cells = wf_TableCell(__('File modification date'));
  50. $cells .= wf_TableCell(__('Size'));
  51. $cells .= wf_TableCell(__('Filename'));
  52. $cells .= wf_TableCell(__('Actions'));
  53. $rows = wf_TableRow($cells, 'row1');
  54. foreach ($availbacks as $eachDump) {
  55. if (is_file($backupsPath . $eachDump)) {
  56. $fileDate = filectime($backupsPath . $eachDump);
  57. $fileDate = date("Y-m-d H:i:s", $fileDate);
  58. $fileSize = filesize($backupsPath . $eachDump);
  59. $fileSize = wr_convertSize($fileSize);
  60. $encodedDumpPath = base64_encode($backupsPath . $eachDump);
  61. $downloadLink = wf_Link('?module=backups&download=' . $encodedDumpPath, $eachDump, false, '');
  62. $actLinks = wf_JSAlert('?module=backups&deletedump=' . $encodedDumpPath, web_delete_icon(), __('Removing this may lead to irreparable results')) . ' ';
  63. $actLinks .= wf_Link('?module=backups&download=' . $encodedDumpPath, wf_img('skins/icon_download.png', __('Download')), false, '');
  64. $actLinks .= wf_JSAlert('?module=backups&restore=true&restoredump=' . $encodedDumpPath, wf_img('skins/icon_restoredb.png', __('Restore DB')), __('Are you serious'));
  65. $cells = wf_TableCell($fileDate);
  66. $cells .= wf_TableCell($fileSize);
  67. $cells .= wf_TableCell($downloadLink);
  68. $cells .= wf_TableCell($actLinks);
  69. $rows .= wf_TableRow($cells, 'row5');
  70. }
  71. }
  72. $result = wf_TableBody($rows, '100%', '0', 'sortable resp-table');
  73. }
  74. return ($result);
  75. }
  76. show_window(__('Create backup'), web_BackupForm());
  77. show_window(__('Available database backups'), web_AvailableDBBackupsList());
  78. } else {
  79. //database restoration functionality
  80. if (cfr('ROOT')) {
  81. if (!empty($binPathsConf['MYSQL_PATH'])) {
  82. if (ubRouting::checkGet(array('restoredump'))) {
  83. $mysqlConf = rcms_parse_ini_file(CONFIG_PATH . 'mysql.ini');
  84. $restoreFilename = base64_decode(ubRouting::get('restoredump'));
  85. if (file_exists($restoreFilename)) {
  86. if (!ubRouting::post('lastchanceok')) {
  87. $lastChanceInputs = __('Restoring a database from a dump, completely and permanently destroy your current database. Think again if you really want it.');
  88. $lastChanceInputs .= wf_tag('br');
  89. $lastChanceInputs .= __('Filename') . ': ' . $restoreFilename;
  90. $lastChanceInputs .= wf_tag('br');
  91. $lastChanceInputs .= wf_CheckInput('lastchanceok', __('I`m ready'), true, false);
  92. $lastChanceInputs .= wf_Submit(__('Restore DB'));
  93. $lastChanceForm = wf_Form('', 'POST', $lastChanceInputs, 'glamour');
  94. show_window(__('Warning'), $lastChanceForm);
  95. show_window('', wf_BackLink('?module=backups', __('Back'), true, 'ubButton'));
  96. } else {
  97. $restoreCommand = $binPathsConf['MYSQL_PATH'] . ' --host ' . $mysqlConf['server'] . ' -u ' . $mysqlConf['username'] . ' -p' . $mysqlConf['password'] . ' ' . $mysqlConf['db'] . ' --default-character-set=utf8 < ' . $restoreFilename . ' 2>&1';
  98. $restoreResult = shell_exec($restoreCommand);
  99. if ($restoreResult) {
  100. if (ispos($restoreResult, 'command line interface')) {
  101. $restoreResult = '';
  102. }
  103. }
  104. if (empty($restoreResult)) {
  105. show_success(__('Success') . '! ' . __('Database') . ' ' . $mysqlConf['db'] . ' ' . __('is restored to server') . ' ' . $mysqlConf['server']);
  106. } else {
  107. show_error(__('Something went wrong'));
  108. show_window(__('Result'), $restoreResult);
  109. }
  110. show_window('', wf_BackLink('?module=backups'));
  111. }
  112. } else {
  113. show_error(__('Strange exeption') . ': NOT_EXISTING_DUMP_FILE');
  114. }
  115. } else {
  116. show_error(__('Strange exeption') . ': GET_NO_DUMP_FILENAME');
  117. }
  118. } else {
  119. show_error(__('You missed an important option') . ': MYSQL_PATH');
  120. }
  121. } else {
  122. show_error(__('You cant control this module'));
  123. }
  124. //////////////////////////////////////////////////////
  125. }
  126. } else {
  127. show_error(__('You cant control this module'));
  128. }