2007-03-24 18:05:16 +01:00
< ? php
2012-04-16 11:07:09 +02:00
/* Copyright ( C ) 2007 - 2012 Laurent Destailleur < eldy @ users . sourceforge . net >
2012-12-30 15:13:49 +01:00
* Copyright ( C ) 2009 - 2012 Regis Houssin < regis . houssin @ capnetworks . com >
2012-04-25 12:41:00 +02:00
* Copyright ( C ) 2012 Juanjo Menent < jmenent @ 2 byte . es >
2007-03-24 18:05:16 +01:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2007-03-24 18:05:16 +01:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2011-08-03 02:45:22 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2007-03-24 18:05:16 +01:00
*/
/**
2009-05-18 01:54:07 +02:00
* \file htdocs / admin / tools / update . php
* \brief Page to make a Dolibarr online upgrade
*/
2007-04-27 11:19:42 +02:00
2012-08-22 23:24:21 +02:00
require '../../main.inc.php' ;
2015-12-03 14:46:34 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php' ;
2014-08-13 12:42:55 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2015-03-14 13:23:36 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/geturl.lib.php' ;
2007-03-24 18:05:16 +01:00
$langs -> load ( " admin " );
2007-04-27 11:19:42 +02:00
$langs -> load ( " other " );
2007-03-24 18:05:16 +01:00
2015-04-04 00:19:03 +02:00
$action = GETPOST ( 'action' , 'alpha' );
2011-12-28 12:53:46 +01:00
if ( ! $user -> admin ) accessforbidden ();
2007-04-27 11:19:42 +02:00
2014-07-20 01:09:43 +02:00
if ( GETPOST ( 'msg' , 'alpha' )) {
2015-10-23 12:58:30 +02:00
setEventMessages ( GETPOST ( 'msg' , 'alpha' ), null , 'errors' );
2014-07-20 01:09:43 +02:00
}
2007-04-27 11:19:42 +02:00
2017-01-07 14:56:15 +01:00
$urldolibarr = 'https://www.dolibarr.org/downloads/' ;
2016-03-29 21:14:12 +02:00
$urldolibarrmodules = 'https://www.dolistore.com/' ;
$urldolibarrthemes = 'https://www.dolistore.com/' ;
2009-10-20 17:57:45 +02:00
$dolibarrroot = preg_replace ( '/([\\/]+)$/i' , '' , DOL_DOCUMENT_ROOT );
$dolibarrroot = preg_replace ( '/([^\\/]+)$/i' , '' , $dolibarrroot );
2012-04-16 11:07:09 +02:00
$dolibarrdataroot = preg_replace ( '/([\\/]+)$/i' , '' , DOL_DATA_ROOT );
2007-04-27 11:19:42 +02:00
2015-04-04 00:19:03 +02:00
$dirins = DOL_DOCUMENT_ROOT . '/custom' ;
2007-04-27 11:19:42 +02:00
/*
2010-06-06 19:36:35 +02:00
* Actions
*/
2007-04-27 11:19:42 +02:00
2015-04-04 00:19:03 +02:00
if ( $action == 'install' )
2010-06-06 19:36:35 +02:00
{
$error = 0 ;
2015-04-04 00:19:03 +02:00
// $original_file should match format module_modulename-x.y[.z].zip
2010-06-06 19:36:35 +02:00
$original_file = basename ( $_FILES [ " fileinstall " ][ " name " ]);
$newfile = $conf -> admin -> dir_temp . '/' . $original_file . '/' . $original_file ;
if ( ! $original_file )
{
2012-04-27 09:11:03 +02:00
$langs -> load ( " Error " );
2015-10-23 12:58:30 +02:00
setEventMessages ( $langs -> trans ( " ErrorFileRequired " ), null , 'warnings' );
2010-06-06 19:36:35 +02:00
$error ++ ;
}
else
{
2017-02-13 01:13:41 +01:00
if ( ! preg_match ( '/\.zip$/i' , $original_file ))
2010-06-06 19:36:35 +02:00
{
2012-04-27 09:11:03 +02:00
$langs -> load ( " errors " );
2015-10-23 12:58:30 +02:00
setEventMessages ( $langs -> trans ( " ErrorFileMustBeADolibarrPackage " , $original_file ), null , 'errors' );
2010-06-06 19:36:35 +02:00
$error ++ ;
}
2017-02-13 01:13:41 +01:00
if ( ! preg_match ( '/module_.*\-[\d]+\.[\d]+.*$/i' , $original_file ))
{
$langs -> load ( " errors " );
setEventMessages ( $langs -> trans ( " ErrorFilenameDosNotMatchDolibarrPackageRules " , $original_file , 'module_*-x.y*.zip' ), null , 'errors' );
$error ++ ;
}
2010-06-06 19:36:35 +02:00
}
if ( ! $error )
{
2015-04-04 00:19:03 +02:00
if ( $original_file )
{
@ dol_delete_dir_recursive ( $conf -> admin -> dir_temp . '/' . $original_file );
dol_mkdir ( $conf -> admin -> dir_temp . '/' . $original_file );
}
$tmpdir = preg_replace ( '/\.zip$/' , '' , $original_file ) . '.dir' ;
if ( $tmpdir )
{
@ dol_delete_dir_recursive ( $conf -> admin -> dir_temp . '/' . $tmpdir );
dol_mkdir ( $conf -> admin -> dir_temp . '/' . $tmpdir );
}
2010-06-06 19:36:35 +02:00
2012-04-25 12:41:00 +02:00
$result = dol_move_uploaded_file ( $_FILES [ 'fileinstall' ][ 'tmp_name' ], $newfile , 1 , 0 , $_FILES [ 'fileinstall' ][ 'error' ]);
2010-06-06 19:36:35 +02:00
if ( $result > 0 )
{
2015-04-04 00:19:03 +02:00
$result = dol_uncompress ( $newfile , $conf -> admin -> dir_temp . '/' . $tmpdir );
2012-04-26 15:02:29 +02:00
if ( ! empty ( $result [ 'error' ]))
2012-04-25 12:41:00 +02:00
{
2012-07-02 19:30:37 +02:00
$langs -> load ( " errors " );
2015-10-23 12:58:30 +02:00
setEventMessages ( $langs -> trans ( $result [ 'error' ], $original_file ), null , 'errors' );
2015-04-04 00:19:03 +02:00
$error ++ ;
2012-04-25 12:41:00 +02:00
}
2012-04-26 15:02:29 +02:00
else
2012-04-25 12:41:00 +02:00
{
2015-04-04 00:19:03 +02:00
// Now we move the dir of the module
$modulename = preg_replace ( '/module_/' , '' , $original_file );
$modulename = preg_replace ( '/\-[\d]+\.[\d]+.*$/' , '' , $modulename );
// Search dir $modulename
$modulenamedir = $conf -> admin -> dir_temp . '/' . $tmpdir . '/' . $modulename ;
//var_dump($modulenamedir);
if ( ! dol_is_dir ( $modulenamedir ))
{
$modulenamedir = $conf -> admin -> dir_temp . '/' . $tmpdir . '/htdocs/' . $modulename ;
//var_dump($modulenamedir);
if ( ! dol_is_dir ( $modulenamedir ))
{
2017-02-13 01:13:41 +01:00
setEventMessages ( $langs -> trans ( " ErrorModuleFileSeemsToHaveAWrongFormat " ) . '<br>Dir not found: ' . $conf -> admin -> dir_temp . '/' . $tmpdir . '/' . $modulename . '<br>' . $conf -> admin -> dir_temp . '/' . $tmpdir . '/htdocs/' . $modulename , null , 'errors' );
2015-04-04 00:19:03 +02:00
$error ++ ;
}
}
if ( ! $error )
{
//var_dump($dirins);
@ dol_delete_dir_recursive ( $dirins . '/' . $modulename );
$result = dolCopyDir ( $modulenamedir , $dirins . '/' . $modulename , '0444' , 1 );
if ( $result <= 0 )
{
2015-10-23 12:58:30 +02:00
setEventMessages ( $langs -> trans ( " ErrorFailedToCopy " ), null , 'errors' );
2015-04-04 00:19:03 +02:00
$error ++ ;
}
}
2012-04-25 12:41:00 +02:00
}
2010-06-06 19:36:35 +02:00
}
2015-04-04 00:19:03 +02:00
else
{
$error ++ ;
}
}
if ( ! $error )
{
2017-02-10 18:42:59 +01:00
setEventMessages ( $langs -> trans ( " SetupIsReadyForUse " , DOL_URL_ROOT . '/admin/modules.php?mainmenu=home' , $langs -> transnoentitiesnoconv ( " Home " ) . ' - ' . $langs -> transnoentitiesnoconv ( " Setup " ) . ' - ' . $langs -> transnoentitiesnoconv ( " Modules " )), null , 'warnings' );
2010-06-06 19:36:35 +02:00
}
2007-04-27 11:19:42 +02:00
}
2015-04-04 00:19:03 +02:00
2007-04-27 11:19:42 +02:00
/*
2010-06-06 19:36:35 +02:00
* View
*/
2007-03-24 18:05:16 +01:00
2015-04-04 00:19:03 +02:00
// Set dir where external modules are installed
if ( ! dol_is_dir ( $dirins ))
{
dol_mkdir ( $dirins );
}
$dirins_ok = ( dol_is_dir ( $dirins ));
2012-04-25 12:41:00 +02:00
2012-04-30 16:23:43 +02:00
$wikihelp = 'EN:Installation_-_Upgrade|FR:Installation_-_Mise_à _jour|ES:Instalación_-_Actualización' ;
2010-05-26 13:42:29 +02:00
llxHeader ( '' , $langs -> trans ( " Upgrade " ), $wikihelp );
2007-03-24 18:05:16 +01:00
2015-09-24 18:33:48 +02:00
print load_fiche_titre ( $langs -> trans ( " Upgrade " ), '' , 'title_setup' );
2007-03-24 18:05:16 +01:00
2008-02-11 17:34:55 +01:00
print $langs -> trans ( " CurrentVersion " ) . ' : <b>' . DOL_VERSION . '</b><br>' ;
2015-03-14 13:23:36 +01:00
2017-02-13 01:37:12 +01:00
if ( function_exists ( 'curl_init' ))
2015-03-14 13:23:36 +01:00
{
2017-02-10 18:42:59 +01:00
$conf -> global -> MAIN_USE_RESPONSE_TIMEOUT = 10 ;
2016-07-27 16:45:13 +02:00
$result = getURLContent ( 'http://sourceforge.net/projects/dolibarr/rss' );
//var_dump($result['content']);
$sfurl = simplexml_load_string ( $result [ 'content' ]);
if ( $sfurl )
2015-12-03 14:46:34 +01:00
{
2016-07-27 16:45:13 +02:00
$i = 0 ;
$version = '0.0' ;
while ( ! empty ( $sfurl -> channel [ 0 ] -> item [ $i ] -> title ) && $i < 10000 )
2015-12-03 14:46:34 +01:00
{
2016-07-27 16:45:13 +02:00
$title = $sfurl -> channel [ 0 ] -> item [ $i ] -> title ;
if ( preg_match ( '/([0-9]+\.([0-9\.]+))/' , $title , $reg ))
{
$newversion = $reg [ 1 ];
$newversionarray = explode ( '.' , $newversion );
$versionarray = explode ( '.' , $version );
//var_dump($newversionarray);var_dump($versionarray);
if ( versioncompare ( $newversionarray , $versionarray ) > 0 ) $version = $newversion ;
}
$i ++ ;
2015-12-03 14:46:34 +01:00
}
2016-07-27 16:45:13 +02:00
// Show version
print $langs -> trans ( " LastStableVersion " ) . ' : <b>' . (( $version != '0.0' ) ? $version : $langs -> trans ( " Unknown " )) . '</b><br>' ;
}
else
{
print $langs -> trans ( " LastStableVersion " ) . ' : <b>' . $langs -> trans ( " UpdateServerOffline " ) . '</b><br>' ;
2015-12-03 14:46:34 +01:00
}
2015-01-26 16:05:47 +01:00
}
2007-03-24 18:05:16 +01:00
2016-07-27 16:45:13 +02:00
print '<br>' ;
2015-04-04 00:19:03 +02:00
// Upgrade
2007-03-24 18:05:16 +01:00
print $langs -> trans ( " Upgrade " ) . '<br>' ;
2008-02-11 17:34:55 +01:00
print '<hr>' ;
print $langs -> trans ( " ThisIsProcessToFollow " ) . '<br>' ;
print '<b>' . $langs -> trans ( " StepNb " , 1 ) . '</b>: ' ;
$fullurl = '<a href="' . $urldolibarr . '" target="_blank">' . $urldolibarr . '</a>' ;
print $langs -> trans ( " DownloadPackageFromWebSite " , $fullurl ) . '<br>' ;
print '<b>' . $langs -> trans ( " StepNb " , 2 ) . '</b>: ' ;
print $langs -> trans ( " UnpackPackageInDolibarrRoot " , $dolibarrroot ) . '<br>' ;
print '<b>' . $langs -> trans ( " StepNb " , 3 ) . '</b>: ' ;
2012-04-16 11:07:09 +02:00
print $langs -> trans ( " RemoveLock " , $dolibarrdataroot . '/install.lock' ) . '<br>' ;
2009-03-13 01:57:36 +01:00
print '<b>' . $langs -> trans ( " StepNb " , 4 ) . '</b>: ' ;
2011-09-14 23:50:18 +02:00
$fullurl = '<a href="' . DOL_URL_ROOT . '/install/" target="_blank">' . DOL_URL_ROOT . '/install/</a>' ;
2008-02-11 17:34:55 +01:00
print $langs -> trans ( " CallUpdatePage " , $fullurl ) . '<br>' ;
2009-03-13 01:57:36 +01:00
print '<b>' . $langs -> trans ( " StepNb " , 5 ) . '</b>: ' ;
2012-04-16 11:07:09 +02:00
print $langs -> trans ( " RestoreLock " , $dolibarrdataroot . '/install.lock' ) . '<br>' ;
2007-03-24 18:05:16 +01:00
print '<br>' ;
print '<br>' ;
2015-04-04 00:19:03 +02:00
// Install external module
$allowonlineinstall = true ;
$allowfromweb = 1 ;
if ( dol_is_file ( $dolibarrdataroot . '/installmodules.lock' )) $allowonlineinstall = false ;
2010-06-05 01:00:57 +02:00
$fullurl = '<a href="' . $urldolibarrmodules . '" target="_blank">' . $urldolibarrmodules . '</a>' ;
2015-04-04 00:19:03 +02:00
$message = '' ;
if ( ! empty ( $allowonlineinstall ))
{
if ( ! in_array ( '/custom' , explode ( ',' , $dolibarr_main_url_root_alt )))
{
$message = info_admin ( $langs -> trans ( " ConfFileMuseContainCustom " , DOL_DOCUMENT_ROOT . '/custom' , DOL_DOCUMENT_ROOT ));
$allowfromweb =- 1 ;
}
else
{
if ( $dirins_ok )
{
if ( ! is_writable ( dol_osencode ( $dirins )))
{
$langs -> load ( " errors " );
$message = info_admin ( $langs -> trans ( " ErrorFailedToWriteInDir " , $dirins ));
$allowfromweb = 0 ;
}
}
else
{
$message = info_admin ( $langs -> trans ( " NotExistsDirect " , $dirins ) . $langs -> trans ( " InfDirAlt " ) . $langs -> trans ( " InfDirExample " ));
$allowfromweb = 0 ;
}
}
}
else
{
$message = info_admin ( $langs -> trans ( " InstallModuleFromWebHasBeenDisabledByFile " , $dolibarrdataroot . '/installmodules.lock' ));
$allowfromweb = 0 ;
}
2007-03-24 18:05:16 +01:00
print $langs -> trans ( " AddExtensionThemeModuleOrOther " ) . '<br>' ;
2008-02-11 17:34:55 +01:00
print '<hr>' ;
2015-04-04 00:19:03 +02:00
if ( $allowfromweb < 1 )
{
print $langs -> trans ( " SomethingMakeInstallFromWebNotPossible " );
print $message ;
//print $langs->trans("SomethingMakeInstallFromWebNotPossible2");
print '<br>' ;
}
if ( $allowfromweb >= 0 )
2010-06-06 19:36:35 +02:00
{
2017-02-10 18:42:59 +01:00
if ( $allowfromweb == 1 )
{
//print $langs->trans("ThisIsProcessToFollow").'<br>';
}
else
{
print $langs -> trans ( " ThisIsAlternativeProcessToFollow " ) . '<br>' ;
print '<b>' . $langs -> trans ( " StepNb " , 1 ) . '</b>: ' ;
print $langs -> trans ( " FindPackageFromWebSite " , $fullurl ) . '<br>' ;
print '<b>' . $langs -> trans ( " StepNb " , 2 ) . '</b>: ' ;
print $langs -> trans ( " DownloadPackageFromWebSite " , $fullurl ) . '<br>' ;
print '<b>' . $langs -> trans ( " StepNb " , 3 ) . '</b>: ' ;
}
2015-04-04 00:19:03 +02:00
if ( $allowfromweb == 1 )
2012-04-25 12:41:00 +02:00
{
2017-02-10 18:42:59 +01:00
print $langs -> trans ( " UnpackPackageInModulesRoot " , $dirins ) . '<br>' ;
2012-04-25 12:41:00 +02:00
print '<form enctype="multipart/form-data" method="POST" class="noborder" action="' . $_SERVER [ " PHP_SELF " ] . '" name="forminstall">' ;
print '<input type="hidden" name="action" value="install">' ;
print $langs -> trans ( " YouCanSubmitFile " ) . ' <input type="file" name="fileinstall"> ' ;
2017-02-10 18:42:59 +01:00
print '<input type="submit" name="send" value="' . dol_escape_htmltag ( $langs -> trans ( " Send " )) . '" class="button">' ;
2012-04-25 12:41:00 +02:00
print '</form>' ;
}
2012-04-28 18:21:51 +02:00
else
2012-07-02 19:30:37 +02:00
{
2017-02-10 18:42:59 +01:00
print $langs -> trans ( " UnpackPackageInModulesRoot " , $dirins ) . '<br>' ;
2015-04-04 00:19:03 +02:00
print '<b>' . $langs -> trans ( " StepNb " , 4 ) . '</b>: ' ;
print $langs -> trans ( " SetupIsReadyForUse " ) . '<br>' ;
2012-04-28 18:21:51 +02:00
}
2012-04-25 12:41:00 +02:00
}
2015-04-04 00:19:03 +02:00
2007-04-27 11:19:42 +02:00
2012-04-26 15:02:29 +02:00
if ( ! empty ( $result [ 'return' ]))
{
print '<br>' ;
2012-04-28 18:21:51 +02:00
2012-04-26 15:02:29 +02:00
foreach ( $result [ 'return' ] as $value )
{
echo $value . '<br>' ;
}
}
2011-08-27 16:24:16 +02:00
llxFooter ();
2014-07-08 01:02:30 +02:00
2012-04-16 11:07:09 +02:00
$db -> close ();