update.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/admin/tools/update.php
  21. * \brief Page to make a Dolibarr online upgrade
  22. */
  23. if (! defined('CSRFCHECK_WITH_TOKEN')) {
  24. define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
  25. }
  26. // Load Dolibarr environment
  27. require '../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
  31. // Load translation files required by the page
  32. $langs->loadLangs(array("admin", "other"));
  33. $action = GETPOST('action', 'aZ09');
  34. if (!$user->admin) {
  35. accessforbidden();
  36. }
  37. if (GETPOST('msg', 'alpha')) {
  38. setEventMessages(GETPOST('msg', 'alpha'), null, 'errors');
  39. }
  40. $urldolibarr = 'https://www.dolibarr.org/downloads/';
  41. $dolibarrroot = preg_replace('/([\\/]+)$/i', '', DOL_DOCUMENT_ROOT);
  42. $dolibarrroot = preg_replace('/([^\\/]+)$/i', '', $dolibarrroot);
  43. $dolibarrdataroot = preg_replace('/([\\/]+)$/i', '', DOL_DATA_ROOT);
  44. $sfurl = '';
  45. $version = '0.0';
  46. /*
  47. * Actions
  48. */
  49. if ($action == 'getlastversion') {
  50. $result = getURLContent('https://sourceforge.net/projects/dolibarr/rss');
  51. //var_dump($result['content']);
  52. if (function_exists('simplexml_load_string')) {
  53. $sfurl = simplexml_load_string($result['content'], 'SimpleXMLElement', LIBXML_NOCDATA|LIBXML_NONET);
  54. } else {
  55. $sfurl = 'xml_not_available';
  56. }
  57. }
  58. /*
  59. * View
  60. */
  61. $wikihelp = 'EN:Installation_-_Upgrade|FR:Installation_-_Mise_à_jour|ES:Instalación_-_Actualización';
  62. llxHeader('', $langs->trans("Upgrade"), $wikihelp);
  63. print load_fiche_titre($langs->trans("Upgrade"), '', 'title_setup');
  64. print '<br>';
  65. print $langs->trans("CurrentVersion").' : <strong>'.DOL_VERSION.'</strong><br>';
  66. if (function_exists('curl_init')) {
  67. $conf->global->MAIN_USE_RESPONSE_TIMEOUT = 10;
  68. if ($action == 'getlastversion') {
  69. if ($sfurl == 'xml_not_available') {
  70. $langs->load("errors");
  71. print $langs->trans("LastStableVersion").' : <b class="error">'.$langs->trans("ErrorFunctionNotAvailableInPHP", 'simplexml_load_string').'</b><br>';
  72. } elseif ($sfurl) {
  73. $i = 0;
  74. while (!empty($sfurl->channel[0]->item[$i]->title) && $i < 10000) {
  75. $title = $sfurl->channel[0]->item[$i]->title;
  76. if (preg_match('/([0-9]+\.([0-9\.]+))/', $title, $reg)) {
  77. $newversion = $reg[1];
  78. $newversionarray = explode('.', $newversion);
  79. $versionarray = explode('.', $version);
  80. //var_dump($newversionarray);var_dump($versionarray);
  81. if (versioncompare($newversionarray, $versionarray) > 0) {
  82. $version = $newversion;
  83. }
  84. }
  85. $i++;
  86. }
  87. // Show version
  88. print $langs->trans("LastStableVersion").' : <b>'.(($version != '0.0') ? $version : $langs->trans("Unknown")).'</b><br>';
  89. } else {
  90. print $langs->trans("LastStableVersion").' : <b>'.$langs->trans("UpdateServerOffline").'</b><br>';
  91. }
  92. } else {
  93. print $langs->trans("LastStableVersion").' : <a href="'.$_SERVER["PHP_SELF"].'?action=getlastversion&token='.newToken().'" class="button smallpaddingimp">'.$langs->trans("Check").'</a><br>';
  94. }
  95. }
  96. print '<br>';
  97. print '<br>';
  98. // Upgrade
  99. print $langs->trans("Upgrade").'<br>';
  100. print '<hr>';
  101. print $langs->trans("ThisIsProcessToFollow").'<br>';
  102. print '<b>'.$langs->trans("StepNb", 1).'</b>: ';
  103. $fullurl = '<a href="'.$urldolibarr.'" target="_blank" rel="noopener noreferrer">'.$urldolibarr.'</a>';
  104. print str_replace('{s}', $fullurl, $langs->trans("DownloadPackageFromWebSite", '{s}')).'<br>';
  105. print '<b>'.$langs->trans("StepNb", 2).'</b>: ';
  106. print str_replace('{s}', $dolibarrroot, $langs->trans("UnpackPackageInDolibarrRoot", '{s}')).'<br>';
  107. print '<b>'.$langs->trans("StepNb", 3).'</b>: ';
  108. print $langs->trans("RemoveLock", $dolibarrdataroot.'/install.lock').'<br>';
  109. print '<b>'.$langs->trans("StepNb", 4).'</b>: ';
  110. $fullurl = '<a href="'.DOL_URL_ROOT.'/install/" target="_blank" rel="noopener noreferrer">'.DOL_URL_ROOT.'/install/</a>';
  111. print str_replace('{s}', $fullurl, $langs->trans("CallUpdatePage", '{s}')).'<br>';
  112. print '<b>'.$langs->trans("StepNb", 5).'</b>: ';
  113. print $langs->trans("RestoreLock", $dolibarrdataroot.'/install.lock').'<br>';
  114. print '<br>';
  115. print '<br>';
  116. print $langs->trans("AddExtensionThemeModuleOrOther").'<br>';
  117. print '<hr>';
  118. $texttoshow = $langs->trans("GoModuleSetupArea", DOL_URL_ROOT.'/admin/modules.php?mode=deploy', '{s2}');
  119. $texttoshow = str_replace('{s2}', img_picto('', 'tools', 'class="pictofixedwidth"').$langs->transnoentities("Home").' - '.$langs->transnoentities("Setup").' - '.$langs->transnoentities("Modules"), $texttoshow);
  120. print $texttoshow;
  121. // End of page
  122. llxFooter();
  123. $db->close();