update.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <?php
  2. /* Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2009-2012 Regis Houssin <regis.houssin@capnetworks.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 <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/admin/tools/update.php
  21. * \brief Page to make a Dolibarr online upgrade
  22. */
  23. require '../../main.inc.php';
  24. include_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
  25. include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
  26. include_once DOL_DOCUMENT_ROOT . '/core/lib/geturl.lib.php';
  27. $langs->load("admin");
  28. $langs->load("other");
  29. $action=GETPOST('action','alpha');
  30. if (! $user->admin) accessforbidden();
  31. if (GETPOST('msg','alpha')) {
  32. setEventMessages(GETPOST('msg','alpha'), null, 'errors');
  33. }
  34. $urldolibarr='http://www.dolibarr.org/downloads/';
  35. $urldolibarrmodules='https://www.dolistore.com/';
  36. $urldolibarrthemes='https://www.dolistore.com/';
  37. $dolibarrroot=preg_replace('/([\\/]+)$/i','',DOL_DOCUMENT_ROOT);
  38. $dolibarrroot=preg_replace('/([^\\/]+)$/i','',$dolibarrroot);
  39. $dolibarrdataroot=preg_replace('/([\\/]+)$/i','',DOL_DATA_ROOT);
  40. $dirins=DOL_DOCUMENT_ROOT.'/custom';
  41. /*
  42. * Actions
  43. */
  44. if ($action=='install')
  45. {
  46. $error=0;
  47. // $original_file should match format module_modulename-x.y[.z].zip
  48. $original_file=basename($_FILES["fileinstall"]["name"]);
  49. $newfile=$conf->admin->dir_temp.'/'.$original_file.'/'.$original_file;
  50. if (! $original_file)
  51. {
  52. $langs->load("Error");
  53. setEventMessages($langs->trans("ErrorFileRequired"), null, 'warnings');
  54. $error++;
  55. }
  56. else
  57. {
  58. if (! preg_match('/\.zip/i',$original_file))
  59. {
  60. $langs->load("errors");
  61. setEventMessages($langs->trans("ErrorFileMustBeADolibarrPackage",$original_file), null, 'errors');
  62. $error++;
  63. }
  64. }
  65. if (! $error)
  66. {
  67. if ($original_file)
  68. {
  69. @dol_delete_dir_recursive($conf->admin->dir_temp.'/'.$original_file);
  70. dol_mkdir($conf->admin->dir_temp.'/'.$original_file);
  71. }
  72. $tmpdir=preg_replace('/\.zip$/','',$original_file).'.dir';
  73. if ($tmpdir)
  74. {
  75. @dol_delete_dir_recursive($conf->admin->dir_temp.'/'.$tmpdir);
  76. dol_mkdir($conf->admin->dir_temp.'/'.$tmpdir);
  77. }
  78. $result=dol_move_uploaded_file($_FILES['fileinstall']['tmp_name'],$newfile,1,0,$_FILES['fileinstall']['error']);
  79. if ($result > 0)
  80. {
  81. $result=dol_uncompress($newfile,$conf->admin->dir_temp.'/'.$tmpdir);
  82. if (! empty($result['error']))
  83. {
  84. $langs->load("errors");
  85. setEventMessages($langs->trans($result['error'],$original_file), null, 'errors');
  86. $error++;
  87. }
  88. else
  89. {
  90. // Now we move the dir of the module
  91. $modulename=preg_replace('/module_/', '', $original_file);
  92. $modulename=preg_replace('/\-[\d]+\.[\d]+.*$/', '', $modulename);
  93. // Search dir $modulename
  94. $modulenamedir=$conf->admin->dir_temp.'/'.$tmpdir.'/'.$modulename;
  95. //var_dump($modulenamedir);
  96. if (! dol_is_dir($modulenamedir))
  97. {
  98. $modulenamedir=$conf->admin->dir_temp.'/'.$tmpdir.'/htdocs/'.$modulename;
  99. //var_dump($modulenamedir);
  100. if (! dol_is_dir($modulenamedir))
  101. {
  102. setEventMessages($langs->trans("ErrorModuleFileSeemsToHaveAWrongFormat"), null, 'errors');
  103. $error++;
  104. }
  105. }
  106. if (! $error)
  107. {
  108. //var_dump($dirins);
  109. @dol_delete_dir_recursive($dirins.'/'.$modulename);
  110. $result=dolCopyDir($modulenamedir, $dirins.'/'.$modulename, '0444', 1);
  111. if ($result <= 0)
  112. {
  113. setEventMessages($langs->trans("ErrorFailedToCopy"), null, 'errors');
  114. $error++;
  115. }
  116. }
  117. }
  118. }
  119. else
  120. {
  121. $error++;
  122. }
  123. }
  124. if (! $error)
  125. {
  126. setEventMessages($langs->trans("SetupIsReadyForUse"), null, 'mesgs');
  127. }
  128. }
  129. /*
  130. * View
  131. */
  132. // Set dir where external modules are installed
  133. if (! dol_is_dir($dirins))
  134. {
  135. dol_mkdir($dirins);
  136. }
  137. $dirins_ok=(dol_is_dir($dirins));
  138. $wikihelp='EN:Installation_-_Upgrade|FR:Installation_-_Mise_à_jour|ES:Instalación_-_Actualización';
  139. llxHeader('',$langs->trans("Upgrade"),$wikihelp);
  140. print load_fiche_titre($langs->trans("Upgrade"),'','title_setup');
  141. print $langs->trans("CurrentVersion").' : <b>'.DOL_VERSION.'</b><br>';
  142. if (function_exists('curl_init'))
  143. {
  144. $result = getURLContent('http://sourceforge.net/projects/dolibarr/rss');
  145. //var_dump($result['content']);
  146. $sfurl = simplexml_load_string($result['content']);
  147. if ($sfurl)
  148. {
  149. $i=0;
  150. $version='0.0';
  151. while (! empty($sfurl->channel[0]->item[$i]->title) && $i < 10000)
  152. {
  153. $title=$sfurl->channel[0]->item[$i]->title;
  154. if (preg_match('/([0-9]+\.([0-9\.]+))/', $title, $reg))
  155. {
  156. $newversion=$reg[1];
  157. $newversionarray=explode('.',$newversion);
  158. $versionarray=explode('.',$version);
  159. //var_dump($newversionarray);var_dump($versionarray);
  160. if (versioncompare($newversionarray, $versionarray) > 0) $version=$newversion;
  161. }
  162. $i++;
  163. }
  164. // Show version
  165. print $langs->trans("LastStableVersion").' : <b>'. (($version != '0.0')?$version:$langs->trans("Unknown")) .'</b><br>';
  166. }
  167. else
  168. {
  169. print $langs->trans("LastStableVersion").' : <b>' .$langs->trans("UpdateServerOffline").'</b><br>';
  170. }
  171. }
  172. print '<br>';
  173. // Upgrade
  174. print $langs->trans("Upgrade").'<br>';
  175. print '<hr>';
  176. print $langs->trans("ThisIsProcessToFollow").'<br>';
  177. print '<b>'.$langs->trans("StepNb",1).'</b>: ';
  178. $fullurl='<a href="'.$urldolibarr.'" target="_blank">'.$urldolibarr.'</a>';
  179. print $langs->trans("DownloadPackageFromWebSite",$fullurl).'<br>';
  180. print '<b>'.$langs->trans("StepNb",2).'</b>: ';
  181. print $langs->trans("UnpackPackageInDolibarrRoot",$dolibarrroot).'<br>';
  182. print '<b>'.$langs->trans("StepNb",3).'</b>: ';
  183. print $langs->trans("RemoveLock",$dolibarrdataroot.'/install.lock').'<br>';
  184. print '<b>'.$langs->trans("StepNb",4).'</b>: ';
  185. $fullurl='<a href="'.DOL_URL_ROOT.'/install/" target="_blank">'.DOL_URL_ROOT.'/install/</a>';
  186. print $langs->trans("CallUpdatePage",$fullurl).'<br>';
  187. print '<b>'.$langs->trans("StepNb",5).'</b>: ';
  188. print $langs->trans("RestoreLock",$dolibarrdataroot.'/install.lock').'<br>';
  189. print '<br>';
  190. print '<br>';
  191. // Install external module
  192. $allowonlineinstall=true;
  193. $allowfromweb=1;
  194. if (dol_is_file($dolibarrdataroot.'/installmodules.lock')) $allowonlineinstall=false;
  195. $fullurl='<a href="'.$urldolibarrmodules.'" target="_blank">'.$urldolibarrmodules.'</a>';
  196. $message='';
  197. if (! empty($allowonlineinstall))
  198. {
  199. if (! in_array('/custom',explode(',',$dolibarr_main_url_root_alt)))
  200. {
  201. $message=info_admin($langs->trans("ConfFileMuseContainCustom", DOL_DOCUMENT_ROOT.'/custom', DOL_DOCUMENT_ROOT));
  202. $allowfromweb=-1;
  203. }
  204. else
  205. {
  206. if ($dirins_ok)
  207. {
  208. if (! is_writable(dol_osencode($dirins)))
  209. {
  210. $langs->load("errors");
  211. $message=info_admin($langs->trans("ErrorFailedToWriteInDir",$dirins));
  212. $allowfromweb=0;
  213. }
  214. }
  215. else
  216. {
  217. $message=info_admin($langs->trans("NotExistsDirect",$dirins).$langs->trans("InfDirAlt").$langs->trans("InfDirExample"));
  218. $allowfromweb=0;
  219. }
  220. }
  221. }
  222. else
  223. {
  224. $message=info_admin($langs->trans("InstallModuleFromWebHasBeenDisabledByFile",$dolibarrdataroot.'/installmodules.lock'));
  225. $allowfromweb=0;
  226. }
  227. print $langs->trans("AddExtensionThemeModuleOrOther").'<br>';
  228. print '<hr>';
  229. if ($allowfromweb < 1)
  230. {
  231. print $langs->trans("SomethingMakeInstallFromWebNotPossible");
  232. print $message;
  233. //print $langs->trans("SomethingMakeInstallFromWebNotPossible2");
  234. print '<br>';
  235. }
  236. if ($allowfromweb >= 0)
  237. {
  238. if ($allowfromweb == 1) print $langs->trans("ThisIsProcessToFollow").'<br>';
  239. else print $langs->trans("ThisIsAlternativeProcessToFollow").'<br>';
  240. print '<b>'.$langs->trans("StepNb",1).'</b>: ';
  241. print $langs->trans("FindPackageFromWebSite",$fullurl).'<br>';
  242. print '<b>'.$langs->trans("StepNb",2).'</b>: ';
  243. print $langs->trans("DownloadPackageFromWebSite",$fullurl).'<br>';
  244. print '<b>'.$langs->trans("StepNb",3).'</b>: ';
  245. if ($allowfromweb == 1)
  246. {
  247. print $langs->trans("UnpackPackageInDolibarrRoot",$dirins).'<br>';
  248. print '<form enctype="multipart/form-data" method="POST" class="noborder" action="'.$_SERVER["PHP_SELF"].'" name="forminstall">';
  249. print '<input type="hidden" name="action" value="install">';
  250. print $langs->trans("YouCanSubmitFile").' <input type="file" name="fileinstall"> ';
  251. print '<input type="submit" name="'.dol_escape_htmltag($langs->trans("Send")).'" class="button">';
  252. print '</form>';
  253. }
  254. else
  255. {
  256. print $langs->trans("UnpackPackageInDolibarrRoot",$dirins).'<br>';
  257. print '<b>'.$langs->trans("StepNb",4).'</b>: ';
  258. print $langs->trans("SetupIsReadyForUse").'<br>';
  259. }
  260. }
  261. if (! empty($result['return']))
  262. {
  263. print '<br>';
  264. foreach($result['return'] as $value)
  265. {
  266. echo $value.'<br>';
  267. }
  268. }
  269. llxFooter();
  270. $db->close();