cron.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.org>
  4. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  5. * Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file cron/admin/cron.php
  23. * \ingroup cron
  24. */
  25. // Dolibarr environment
  26. require '../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/cron.lib.php';
  29. // Load translation files required by the page
  30. $langs->loadLangs(array('admin', 'cron'));
  31. if (!$user->admin) {
  32. accessforbidden();
  33. }
  34. $actionsave = GETPOST("save", 'alphanohtml');
  35. // Save parameters
  36. if (!empty($actionsave)) {
  37. $i = 0;
  38. $db->begin();
  39. $i += dolibarr_set_const($db, 'CRON_KEY', GETPOST("CRON_KEY"), 'chaine', 0, '', 0);
  40. if ($i >= 1) {
  41. $db->commit();
  42. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  43. } else {
  44. $db->rollback();
  45. setEventMessages($langs->trans("Error"), null, 'errors');
  46. }
  47. }
  48. /*
  49. * View
  50. */
  51. $help_url = '';
  52. llxHeader('', '', $help_url);
  53. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  54. print load_fiche_titre($langs->trans("CronSetup"), $linkback, 'title_setup');
  55. // Configuration header
  56. $head = cronadmin_prepare_head();
  57. print '<form name="agendasetupform" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  58. print '<input type="hidden" name="token" value="'.newToken().'">';
  59. print dol_get_fiche_head($head, 'setup', $langs->trans("Module2300Name"), -1, 'cron');
  60. print '<span class="opacitymedium">'.$langs->trans('CronInfo').'</span><br>';
  61. print "<br>\n";
  62. print '<table class="noborder centpercent">';
  63. print '<tr class="liste_titre">';
  64. print "<td>".$langs->trans("Parameter")."</td>";
  65. print "<td>".$langs->trans("Value")."</td>";
  66. print "<td></td>";
  67. print "</tr>";
  68. print '<tr class="oddeven">';
  69. print '<td class="fieldrequired">'.$langs->trans("KeyForCronAccess").'</td>';
  70. $disabled = '';
  71. if (!empty($conf->global->CRON_DISABLE_KEY_CHANGE)) {
  72. $disabled = ' disabled="disabled"';
  73. }
  74. print '<td>';
  75. if (empty($conf->global->CRON_DISABLE_KEY_CHANGE)) {
  76. print '<input type="text" class="flat minwidth300"'.$disabled.' id="CRON_KEY" name="CRON_KEY" value="'.(GETPOST('CRON_KEY') ?GETPOST('CRON_KEY') : (!empty($conf->global->CRON_KEY) ? $conf->global->CRON_KEY : '')).'">';
  77. if (!empty($conf->use_javascript_ajax)) {
  78. print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
  79. }
  80. } else {
  81. print (!empty($conf->global->CRON_KEY) ? $conf->global->CRON_KEY : '');
  82. print '<input type="hidden" id="CRON_KEY" name="CRON_KEY" value="'.(GETPOST('CRON_KEY') ?GETPOST('CRON_KEY') : (!empty($conf->global->CRON_KEY) ? $conf->global->CRON_KEY : '')).'">';
  83. }
  84. print '</td>';
  85. print '<td>&nbsp;</td>';
  86. print '</tr>';
  87. print '</table>';
  88. print dol_get_fiche_end();
  89. print '<div class="center">';
  90. print '<input type="submit" name="save" class="button button-save" value="'.$langs->trans("Save").'">';
  91. print '</div>';
  92. print '</form>';
  93. print '<br><br><br>';
  94. //print $langs->trans("UseMenuModuleToolsToAddCronJobs", dol_buildpath('/cron/list.php?leftmenu=admintools', 1)).'<br>';
  95. if (!empty($conf->global->CRON_WARNING_DELAY_HOURS)) {
  96. print info_admin($langs->trans("WarningCronDelayed", $conf->global->CRON_WARNING_DELAY_HOURS)).'<br>';
  97. }
  98. print '<br>';
  99. dol_print_cron_urls();
  100. print '<br>';
  101. if (!empty($conf->use_javascript_ajax)) {
  102. print "\n".'<script type="text/javascript">';
  103. print '$(document).ready(function () {
  104. $("#generate_token").click(function() {
  105. $.get( "'.DOL_URL_ROOT.'/core/ajax/security.php", {
  106. action: \'getrandompassword\',
  107. generic: true
  108. },
  109. function(token) {
  110. $("#CRON_KEY").val(token);
  111. });
  112. });
  113. });';
  114. print '</script>';
  115. }
  116. llxFooter();
  117. $db->close();