purge.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /* Copyright (C) 2006-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2006-2012 Regis Houssin <regis.houssin@inodbox.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/admin/tools/purge.php
  20. * \brief Page to purge files (temporary or not)
  21. */
  22. if (! defined('CSRFCHECK_WITH_TOKEN')) {
  23. define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
  24. }
  25. // Load Dolibarr environment
  26. require '../../main.inc.php';
  27. include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  28. $langs->load("admin");
  29. $action = GETPOST('action', 'aZ09');
  30. $confirm = GETPOST('confirm', 'alpha');
  31. $choice = GETPOST('choice', 'aZ09');
  32. $nbsecondsold = GETPOSTINT('nbsecondsold');
  33. // Define filelog to discard it from purge
  34. $filelog = '';
  35. if (!empty($conf->syslog->enabled)) {
  36. $filelog = $conf->global->SYSLOG_FILE;
  37. $filelog = preg_replace('/DOL_DATA_ROOT/i', DOL_DATA_ROOT, $filelog);
  38. }
  39. // Security
  40. if (!$user->admin) {
  41. accessforbidden();
  42. }
  43. /*
  44. * Actions
  45. */
  46. if ($action == 'purge' && !preg_match('/^confirm/i', $choice) && ($choice != 'allfiles' || $confirm == 'yes')) {
  47. // Increase limit of time. Works only if we are not in safe mode
  48. $ExecTimeLimit = 600;
  49. if (!empty($ExecTimeLimit)) {
  50. $err = error_reporting();
  51. error_reporting(0); // Disable all errors
  52. //error_reporting(E_ALL);
  53. @set_time_limit($ExecTimeLimit); // Need more than 240 on Windows 7/64
  54. error_reporting($err);
  55. }
  56. require_once DOL_DOCUMENT_ROOT.'/core/class/utils.class.php';
  57. $utils = new Utils($db);
  58. $result = $utils->purgeFiles($choice, $nbsecondsold);
  59. $mesg = $utils->output;
  60. setEventMessages($mesg, null, 'mesgs');
  61. }
  62. /*
  63. * View
  64. */
  65. llxHeader();
  66. $form = new Form($db);
  67. print load_fiche_titre($langs->trans("Purge"), '', 'title_setup');
  68. print '<span class="opacitymedium">'.$langs->trans("PurgeAreaDesc", $dolibarr_main_data_root).'</span><br>';
  69. print '<br>';
  70. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  71. print '<input type="hidden" name="token" value="'.newToken().'" />';
  72. print '<input type="hidden" name="action" value="purge" />';
  73. print '<table class="border centpercent">';
  74. print '<tr class="border"><td style="padding: 4px">';
  75. if (!empty($conf->syslog->enabled)) {
  76. print '<input type="radio" name="choice" id="choicelogfile" value="logfile"';
  77. print ($choice && $choice == 'logfile') ? ' checked' : '';
  78. $filelogparam = $filelog;
  79. if ($user->admin && preg_match('/^dolibarr.*\.log$/', basename($filelog))) {
  80. $filelogparam = '<a class="wordbreak" href="'.DOL_URL_ROOT.'/document.php?modulepart=logs&file=';
  81. $filelogparam .= basename($filelog);
  82. $filelogparam .= '">'.$filelog.'</a>';
  83. }
  84. $desc = $langs->trans("PurgeDeleteLogFile", '{filelogparam}');
  85. $desc = str_replace('{filelogparam}', $filelogparam, $desc);
  86. print '> <label for="choicelogfile">'.$desc.'</label>';
  87. print '<br><br>';
  88. }
  89. print '<input type="radio" name="choice" id="choicetempfiles" value="tempfiles"';
  90. print (!$choice || $choice == 'tempfiles' || $choice == 'allfiles') ? ' checked' : '';
  91. print '> <label for="choicetempfiles">'.$langs->trans("PurgeDeleteTemporaryFilesShort").'</label><br><br>';
  92. print '<input type="radio" name="choice" id="choiceallfiles" value="confirm_allfiles"';
  93. print ($choice && $choice == 'confirm_allfiles') ? ' checked' : '';
  94. print '> <label for="choiceallfiles">'.$langs->trans("PurgeDeleteAllFilesInDocumentsDir", $dolibarr_main_data_root).'</label>';
  95. print '<br>';
  96. if (getDolGlobalInt('MAIN_PURGE_ACCEPT_NBSECONDSOLD')) {
  97. print 'NbSecondsOld = <input class="width50 right" type="text" name="nbsecondsold" value="'.$nbsecondsold.'">';
  98. }
  99. print '</td></tr></table>';
  100. //if ($choice != 'confirm_allfiles')
  101. //{
  102. print '<br>';
  103. print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("PurgeRunNow").'"></div>';
  104. //}
  105. print '</form>';
  106. if (preg_match('/^confirm/i', $choice)) {
  107. print '<br>';
  108. $formquestion = array();
  109. print $form->formconfirm($_SERVER["PHP_SELF"].'?choice=allfiles&nbsecondsold='.$nbsecondsold, $langs->trans('Purge'), $langs->trans('ConfirmPurge').img_warning().' ', 'purge', $formquestion, 'no', 2);
  110. }
  111. // End of page
  112. llxFooter();
  113. $db->close();