27if (! defined(
'CSRFCHECK_WITH_TOKEN')) {
28 define(
'CSRFCHECK_WITH_TOKEN',
'1');
32require
'../../main.inc.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
42require_once DOL_DOCUMENT_ROOT.
'/core/class/utils.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
47$action =
GETPOST(
'action',
'aZ09');
48$what =
GETPOST(
'what',
'alpha');
49$export_type =
GETPOST(
'export_type',
'alpha');
50$file = trim(
GETPOST(
'zipfilename_template',
'alpha'));
51$compression =
GETPOST(
'compression',
'aZ09');
54$file = preg_replace(
'/(\.zip|\.tar|\.tgz|\.gz|\.tar\.gz|\.bz2|\.zst)$/i',
'', $file);
56$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
57$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
67} elseif (empty($page)) {
71$offset = $limit * $page;
84if ($action ==
'delete') {
86 $filepath =
$conf->admin->dir_output.
'/'.$filerelative;
89 setEventMessages($langs->trans(
"FileWasRemoved", $filerelative),
null,
'mesgs');
91 setEventMessages($langs->trans(
"ErrorFailToDeleteFile", $filerelative),
null,
'errors');
102$ExecTimeLimit =
getDolGlobalInt(
'MAIN_ADMIN_TOOLS_EXPORT_FILES_EXEC_TIME_LIMIT', 1800);;
103if (!empty($ExecTimeLimit)) {
104 $err = error_reporting();
107 @set_time_limit($ExecTimeLimit);
108 error_reporting($err);
113if (!empty($MemoryLimit)) {
114 @ini_set(
'memory_limit', $MemoryLimit);
134$outputdir =
$conf->admin->dir_output.
'/documents';
139if ($export_type ==
'externalmodule' && !empty($what)) {
142 $fulldirtocompress = DOL_DATA_ROOT;
144$dirtoswitch = dirname($fulldirtocompress);
145$dirtocompress = basename($fulldirtocompress);
147if ($compression ==
'zip') {
150 $excludefiles =
'/(\.back|\.old|\.log|\.pdf_preview-.*\.png|[\/\\\]temp[\/\\\]|[\/\\\]admin[\/\\\]documents[\/\\\])/i';
156 if ($export_type ==
'externalmodule' && !empty($what)) {
157 $rootdirinzip = $what;
159 global $dolibarr_allow_download_external_modules;
160 if (empty($dolibarr_allow_download_external_modules)) {
161 print
'Download of external modules is not allowed by $dolibarr_allow_download_external_modules in conf.php file';
168 $ret = dol_compress_dir($fulldirtocompress, $outputdir.
"/".$file, $compression, $excludefiles, $rootdirinzip);
171 $langs->load(
"errors");
172 $errormsg = $langs->trans(
"ErrNoZipEngine");
174 $langs->load(
"errors");
176 $errormsg = $langs->trans(
"ErrorFailedToWriteInDir", $outputdir).($errormsg ?
"\n" . $errormsg :
"");
179} elseif (in_array($compression, array(
'gz',
'bz',
'zstd'))) {
180 $userlogin = ($user->login ? $user->login :
'unknown');
196 $cmd =
"tar -cf '".escapeshellcmd($tmpfile).
"' --exclude-vcs --exclude-caches-all --exclude='temp' --exclude='*.log' --exclude='*.pdf_preview-*.png' --exclude='documents/admin/documents' -C '".escapeshellcmd(
dol_sanitizePathName($dirtoswitch)).
"' '".escapeshellcmd(
dol_sanitizeFileName($dirtocompress)).
"'";
198 $result = $utils->executeCLI($cmd, $outputfile, 0,
null, 1);
200 $retval = $result[
'error'];
201 if ($result[
'result'] || !empty($retval)) {
202 $langs->load(
"errors");
203 dol_syslog(
"Documents tar retval after exec=".$retval, LOG_ERR);
204 $errormsg =
'Error tar generation return '.$retval;
205 if (file_exists($tmpfile)) {
209 $compressedtmpfile = $tmpfile;
210 if ($compression ==
'gz') {
211 $cmd =
"gzip -f ".$tmpfile;
212 $compressedtmpfile = $tmpfile.
'.gz';
213 } elseif ($compression ==
'bz') {
214 $cmd =
"bzip2 -f ".$tmpfile;
215 $compressedtmpfile = $tmpfile.
'.bz2';
216 } elseif ($compression ==
'zstd') {
217 $cmd =
"zstd -z -9 -q --rm ".$tmpfile;
218 $compressedtmpfile = $tmpfile.
'.zst';
221 $result = $utils->executeCLI($cmd, $outputfile);
223 $retval = $result[
'error'];
224 if ($result[
'result'] || !empty($retval)) {
225 $errormsg =
'Error '.$compression.
' generation return '.$retval;
226 if (file_exists($tmpfile)) {
229 if (file_exists($compressedtmpfile)) {
230 unlink($compressedtmpfile);
234 $finalfile = $outputdir.
'/'.basename($compressedtmpfile);
235 if (!@rename($compressedtmpfile, $finalfile)) {
236 $errormsg =
'Error moving generated archive to '.$outputdir;
237 if (file_exists($compressedtmpfile)) {
238 unlink($compressedtmpfile);
241 $file = basename($compressedtmpfile);
246 $errormsg =
'Bad value for compression method';
253if ($export_type !=
'externalmodule' || empty($what)) {
259 setEventMessages($langs->trans(
"BackupFileSuccessfullyCreated").
'.<br>'.$langs->trans(
"YouCanDownloadBackupFile"),
null,
'mesgs');
265 $returnto =
'dolibarr_export.php';
267 header(
"Location: ".$returnto);
273 $zipname = $outputdir.
"/".$file;
277 header(
'Content-disposition: attachment; filename='.basename($zipname));
278 header(
'Content-Length: '.filesize($zipname));
Class to manage utility methods.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
dol_sanitizePathName($str, $newstr='_', $unaccent=0, $allowdash=0)
Clean a string to use it as a path name.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.