2006-08-20 21:15:47 +02:00
|
|
|
<?php
|
2015-12-17 21:10:14 +01:00
|
|
|
/* Copyright (C) 2006-2014 Laurent Destailleur <eldy@users.sourceforge.net>
|
|
|
|
|
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
|
|
|
|
|
* Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
|
2006-08-20 21:15:47 +02:00
|
|
|
*
|
2011-10-15 20:45:16 +02: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
|
2011-10-15 20:45:16 +02: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
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
2006-08-20 21:15:47 +02:00
|
|
|
|
|
|
|
|
/**
|
2009-03-09 13:38:22 +01:00
|
|
|
* \file htdocs/admin/tools/export.php
|
2009-09-29 19:14:52 +02:00
|
|
|
* \brief Page to export a database into a dump file
|
2009-03-09 13:38:22 +01:00
|
|
|
*/
|
2006-08-20 21:15:47 +02:00
|
|
|
|
2012-08-22 23:24:21 +02:00
|
|
|
require '../../main.inc.php';
|
2012-08-22 23:11:24 +02:00
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
|
|
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
2016-03-29 14:52:27 +02:00
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/class/utils.class.php';
|
2012-08-22 23:11:24 +02:00
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
|
2006-08-20 21:15:47 +02:00
|
|
|
|
|
|
|
|
$langs->load("admin");
|
|
|
|
|
|
2012-04-10 08:44:43 +02:00
|
|
|
$action=GETPOST('action','alpha');
|
|
|
|
|
$what=GETPOST('what','alpha');
|
|
|
|
|
$export_type=GETPOST('export_type','alpha');
|
|
|
|
|
$file=GETPOST('filename_template','alpha');
|
2006-08-20 21:15:47 +02:00
|
|
|
|
2012-04-10 08:44:43 +02:00
|
|
|
$sortfield = GETPOST('sortfield','alpha');
|
|
|
|
|
$sortorder = GETPOST('sortorder','alpha');
|
2012-10-13 14:47:46 +02:00
|
|
|
$page = GETPOST("page",'int');
|
2012-02-10 10:53:11 +01:00
|
|
|
if (! $sortorder) $sortorder="DESC";
|
|
|
|
|
if (! $sortfield) $sortfield="date";
|
|
|
|
|
if ($page < 0) { $page = 0; }
|
2018-04-21 12:16:12 +02:00
|
|
|
$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
|
2012-02-10 10:53:11 +01:00
|
|
|
$offset = $limit * $page;
|
|
|
|
|
|
|
|
|
|
if (! $user->admin) accessforbidden();
|
2006-08-20 21:15:47 +02:00
|
|
|
|
2009-03-09 13:38:22 +01:00
|
|
|
if ($file && ! $what)
|
2006-08-20 21:15:47 +02:00
|
|
|
{
|
2011-10-14 16:02:18 +02:00
|
|
|
//print DOL_URL_ROOT.'/dolibarr_export.php';
|
|
|
|
|
header("Location: ".DOL_URL_ROOT.'/admin/tools/dolibarr_export.php?msg='.urlencode($langs->trans("ErrorFieldRequired",$langs->transnoentities("ExportMethod"))));
|
|
|
|
|
exit;
|
2006-08-20 21:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
2016-06-25 15:16:32 +02:00
|
|
|
$errormsg='';
|
|
|
|
|
|
2006-08-20 21:15:47 +02:00
|
|
|
|
2008-08-03 13:34:47 +02:00
|
|
|
/*
|
2012-02-10 10:53:11 +01:00
|
|
|
* Actions
|
|
|
|
|
*/
|
2008-08-03 13:34:47 +02:00
|
|
|
|
2012-02-10 11:09:34 +01:00
|
|
|
if ($action == 'delete')
|
|
|
|
|
{
|
2014-03-31 00:19:31 +02:00
|
|
|
$file=$conf->admin->dir_output.'/'.GETPOST('urlfile');
|
2012-07-29 16:11:52 +02:00
|
|
|
$ret=dol_delete_file($file, 1);
|
2015-10-23 12:58:30 +02:00
|
|
|
if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs');
|
|
|
|
|
else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors');
|
2012-07-29 15:47:24 +02:00
|
|
|
$action='';
|
2012-02-10 11:09:34 +01:00
|
|
|
}
|
2006-08-24 20:51:59 +02:00
|
|
|
|
|
|
|
|
|
2012-02-10 10:53:11 +01:00
|
|
|
/*
|
|
|
|
|
* View
|
|
|
|
|
*/
|
2006-08-24 20:51:59 +02:00
|
|
|
|
2015-05-18 20:33:02 +02:00
|
|
|
$_SESSION["commandbackuplastdone"]='';
|
|
|
|
|
$_SESSION["commandbackuptorun"]='';
|
|
|
|
|
$_SESSION["commandbackupresult"]='';
|
|
|
|
|
|
2012-02-10 10:53:11 +01:00
|
|
|
// Increase limit of time. Works only if we are not in safe mode
|
2011-03-05 02:53:20 +01:00
|
|
|
$ExecTimeLimit=600;
|
2012-02-10 10:53:11 +01:00
|
|
|
if (!empty($ExecTimeLimit))
|
|
|
|
|
{
|
2011-03-05 02:53:20 +01:00
|
|
|
$err=error_reporting();
|
|
|
|
|
error_reporting(0); // Disable all errors
|
|
|
|
|
//error_reporting(E_ALL);
|
|
|
|
|
@set_time_limit($ExecTimeLimit); // Need more than 240 on Windows 7/64
|
|
|
|
|
error_reporting($err);
|
2010-08-21 22:16:52 +02:00
|
|
|
}
|
2017-06-26 09:20:16 +02:00
|
|
|
$MemoryLimit=0;
|
2012-02-10 10:53:11 +01:00
|
|
|
if (!empty($MemoryLimit))
|
|
|
|
|
{
|
2011-03-05 02:53:20 +01:00
|
|
|
@ini_set('memory_limit', $MemoryLimit);
|
2006-08-20 21:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
2012-02-10 10:53:11 +01:00
|
|
|
$form=new Form($db);
|
|
|
|
|
$formfile = new FormFile($db);
|
|
|
|
|
|
2015-04-03 17:17:02 +02:00
|
|
|
//$help_url='EN:Backups|FR:Sauvegardes|ES:Copias_de_seguridad';
|
|
|
|
|
//llxHeader('','',$help_url);
|
2012-02-10 10:53:11 +01:00
|
|
|
|
2015-09-24 18:33:48 +02:00
|
|
|
//print load_fiche_titre($langs->trans("Backup"),'','title_setup');
|
2012-02-10 10:53:11 +01:00
|
|
|
|
|
|
|
|
|
2006-08-20 21:15:47 +02:00
|
|
|
// Start with empty buffer
|
|
|
|
|
$dump_buffer = '';
|
|
|
|
|
$dump_buffer_len = 0;
|
|
|
|
|
|
2012-02-10 10:53:11 +01:00
|
|
|
// We will send fake headers to avoid browser timeout when buffering
|
2006-08-20 21:15:47 +02:00
|
|
|
$time_start = time();
|
|
|
|
|
|
|
|
|
|
|
2016-01-31 14:58:04 +01:00
|
|
|
$outputdir = $conf->admin->dir_output.'/backup';
|
|
|
|
|
$result=dol_mkdir($outputdir);
|
|
|
|
|
|
|
|
|
|
|
2016-03-29 14:52:27 +02:00
|
|
|
$utils = new Utils($db);
|
|
|
|
|
|
|
|
|
|
|
2009-10-26 04:10:12 +01:00
|
|
|
// MYSQL
|
2006-08-20 21:15:47 +02:00
|
|
|
if ($what == 'mysql')
|
|
|
|
|
{
|
2017-06-26 09:20:16 +02:00
|
|
|
|
2016-09-08 11:05:47 +02:00
|
|
|
$cmddump=GETPOST("mysqldump"); // Do not sanitize here with 'alpha', will be sanitize later by dol_sanitizePathName and escapeshellarg
|
|
|
|
|
$cmddump=dol_sanitizePathName($cmddump);
|
2017-06-26 09:20:16 +02:00
|
|
|
|
2016-06-25 15:16:32 +02:00
|
|
|
if (! empty($dolibarr_main_restrict_os_commands))
|
|
|
|
|
{
|
|
|
|
|
$arrayofallowedcommand=explode(',', $dolibarr_main_restrict_os_commands);
|
|
|
|
|
$ok=0;
|
2018-10-07 21:45:20 +02:00
|
|
|
dol_syslog("Command are restricted to ".$dolibarr_main_restrict_os_commands.". We check that one of this command is inside ".$cmddump);
|
2016-06-25 15:16:32 +02:00
|
|
|
foreach($arrayofallowedcommand as $allowedcommand)
|
|
|
|
|
{
|
|
|
|
|
if (preg_match('/'.preg_quote($allowedcommand,'/').'/', $cmddump))
|
|
|
|
|
{
|
|
|
|
|
$ok=1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (! $ok)
|
|
|
|
|
{
|
|
|
|
|
$errormsg=$langs->trans('CommandIsNotInsideAllowedCommands');
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-26 09:20:16 +02:00
|
|
|
|
2016-06-25 15:16:32 +02:00
|
|
|
if (! $errormsg && $cmddump)
|
2011-10-14 16:02:18 +02:00
|
|
|
{
|
|
|
|
|
dolibarr_set_const($db, 'SYSTEMTOOLS_MYSQLDUMP', $cmddump,'chaine',0,'',$conf->entity);
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-26 09:20:16 +02:00
|
|
|
if (! $errormsg)
|
2016-06-25 15:16:32 +02:00
|
|
|
{
|
|
|
|
|
$utils->dumpDatabase(GETPOST('compression','alpha'), $what, 0, $file);
|
|
|
|
|
$errormsg=$utils->error;
|
|
|
|
|
$_SESSION["commandbackuplastdone"]=$utils->result['commandbackuplastdone'];
|
|
|
|
|
$_SESSION["commandbackuptorun"]=$utils->result['commandbackuptorun'];
|
|
|
|
|
}
|
2011-10-14 16:02:18 +02:00
|
|
|
}
|
|
|
|
|
|
2016-03-29 14:52:27 +02:00
|
|
|
// MYSQL NO BIN
|
2011-10-14 16:02:18 +02:00
|
|
|
if ($what == 'mysqlnobin')
|
|
|
|
|
{
|
2016-03-29 14:52:27 +02:00
|
|
|
$utils->dumpDatabase(GETPOST('compression','alpha'), $what, 0, $file);
|
2015-04-03 17:17:02 +02:00
|
|
|
|
2016-03-29 14:52:27 +02:00
|
|
|
$errormsg=$utils->error;
|
|
|
|
|
$_SESSION["commandbackuplastdone"]=$utils->result['commandbackuplastdone'];
|
|
|
|
|
$_SESSION["commandbackuptorun"]=$utils->result['commandbackuptorun'];
|
2009-10-26 04:10:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POSTGRESQL
|
|
|
|
|
if ($what == 'postgresql')
|
|
|
|
|
{
|
2016-09-08 11:05:47 +02:00
|
|
|
$cmddump=GETPOST("postgresqldump"); // Do not sanitize here with 'alpha', will be sanitize later by dol_sanitizePathName and escapeshellarg
|
|
|
|
|
$cmddump=dol_sanitizePathName($cmddump);
|
2017-06-26 09:20:16 +02:00
|
|
|
|
2016-06-25 15:16:32 +02:00
|
|
|
if (! $errormsg && $cmddump)
|
2011-10-14 16:02:18 +02:00
|
|
|
{
|
|
|
|
|
dolibarr_set_const($db, 'SYSTEMTOOLS_POSTGRESQLDUMP', $cmddump,'chaine',0,'',$conf->entity);
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-26 09:20:16 +02:00
|
|
|
if (! $errormsg)
|
2016-06-25 15:16:32 +02:00
|
|
|
{
|
|
|
|
|
$utils->dumpDatabase(GETPOST('compression','alpha'), $what, 0, $file);
|
|
|
|
|
$errormsg=$utils->error;
|
|
|
|
|
$_SESSION["commandbackuplastdone"]=$utils->result['commandbackuplastdone'];
|
|
|
|
|
$_SESSION["commandbackuptorun"]=$utils->result['commandbackuptorun'];
|
|
|
|
|
}
|
2016-03-29 14:52:27 +02:00
|
|
|
|
|
|
|
|
$what=''; // Clear to show message to run command
|
2006-08-20 21:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
2009-10-26 04:10:12 +01:00
|
|
|
|
|
|
|
|
|
2016-01-31 14:58:04 +01:00
|
|
|
if ($errormsg)
|
|
|
|
|
{
|
|
|
|
|
setEventMessages($langs->trans("Error")." : ".$errormsg, null, 'errors');
|
2009-10-26 04:10:12 +01:00
|
|
|
|
2016-01-31 14:58:04 +01:00
|
|
|
$resultstring='';
|
|
|
|
|
$resultstring.='<div class="error">'.$langs->trans("Error")." : ".$errormsg.'</div>';
|
2015-05-18 20:33:02 +02:00
|
|
|
|
2016-01-31 14:58:04 +01:00
|
|
|
$_SESSION["commandbackupresult"]=$resultstring;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if ($what)
|
|
|
|
|
{
|
|
|
|
|
setEventMessages($langs->trans("BackupFileSuccessfullyCreated").'.<br>'.$langs->trans("YouCanDownloadBackupFile"), null, 'mesgs');
|
|
|
|
|
|
|
|
|
|
$resultstring='<div class="ok">';
|
|
|
|
|
$resultstring.=$langs->trans("BackupFileSuccessfullyCreated").'.<br>';
|
|
|
|
|
$resultstring.=$langs->trans("YouCanDownloadBackupFile");
|
|
|
|
|
$resultstring.='<div>';
|
2015-05-18 20:33:02 +02:00
|
|
|
|
|
|
|
|
$_SESSION["commandbackupresult"]=$resultstring;
|
2016-01-31 14:58:04 +01:00
|
|
|
}
|
2017-11-25 01:58:11 +01:00
|
|
|
/*else
|
2015-04-03 17:17:02 +02:00
|
|
|
{
|
2017-11-25 01:58:11 +01:00
|
|
|
setEventMessages($langs->trans("YouMustRunCommandFromCommandLineAfterLoginToUser",$dolibarr_main_db_user,$dolibarr_main_db_user), null, 'warnings');
|
|
|
|
|
}*/
|
2016-01-31 14:58:04 +01:00
|
|
|
}
|
|
|
|
|
|
2006-08-20 21:15:47 +02:00
|
|
|
|
2015-04-03 17:17:02 +02:00
|
|
|
/*
|
2012-02-10 10:53:11 +01:00
|
|
|
$filearray=dol_dir_list($conf->admin->dir_output.'/backup','files',0,'','',$sortfield,(strtolower($sortorder)=='asc'?SORT_ASC:SORT_DESC),1);
|
2012-02-10 11:09:34 +01:00
|
|
|
$result=$formfile->list_of_documents($filearray,null,'systemtools','',1,'backup/',1,0,($langs->trans("NoBackupFileAvailable").'<br>'.$langs->trans("ToBuildBackupFileClickHere",DOL_URL_ROOT.'/admin/tools/dolibarr_export.php')),0,$langs->trans("PreviousDumpFiles"));
|
2009-03-09 13:38:22 +01:00
|
|
|
|
2006-08-20 21:15:47 +02:00
|
|
|
print '<br>';
|
2015-04-03 17:17:02 +02:00
|
|
|
*/
|
2006-08-20 21:15:47 +02:00
|
|
|
|
2015-04-03 17:17:02 +02:00
|
|
|
// Redirect t backup page
|
|
|
|
|
header("Location: dolibarr_export.php");
|
2006-08-20 21:15:47 +02:00
|
|
|
|
2015-04-03 17:17:02 +02:00
|
|
|
$time_end = time();
|
2011-10-14 16:02:18 +02:00
|
|
|
|
|
|
|
|
$db->close();
|
|
|
|
|
|