26if (! defined(
'CSRFCHECK_WITH_TOKEN')) {
27 define(
'CSRFCHECK_WITH_TOKEN',
'1');
31require
'../../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/class/utils.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
39$action =
GETPOST(
'action',
'aZ09');
40$what =
GETPOST(
'what',
'alpha');
41$export_type =
GETPOST(
'export_type',
'alpha');
42$file = trim(
GETPOST(
'zipfilename_template',
'alpha'));
43$compression =
GETPOST(
'compression',
'aZ09');
46$file = preg_replace(
'/(\.zip|\.tar|\.tgz|\.gz|\.tar\.gz|\.bz2|\.zst)$/i',
'', $file);
48$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
49$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
59} elseif (empty($page)) {
63$offset = $limit * $page;
76if ($action ==
'delete') {
78 $filepath = $conf->admin->dir_output.
'/'.$filerelative;
81 setEventMessages($langs->trans(
"FileWasRemoved", $filerelative),
null,
'mesgs');
83 setEventMessages($langs->trans(
"ErrorFailToDeleteFile", $filerelative),
null,
'errors');
95if (!empty($ExecTimeLimit)) {
96 $err = error_reporting();
99 @set_time_limit($ExecTimeLimit);
100 error_reporting($err);
105if (!empty($MemoryLimit)) {
106 @ini_set(
'memory_limit', $MemoryLimit);
109$form =
new Form($db);
126$outputdir = $conf->admin->dir_output.
'/documents';
129$utils =
new Utils($db);
131if ($export_type ==
'externalmodule' && !empty($what)) {
134 $fulldirtocompress = DOL_DATA_ROOT;
136$dirtoswitch = dirname($fulldirtocompress);
137$dirtocompress = basename($fulldirtocompress);
139if ($compression ==
'zip') {
142 $excludefiles =
'/(\.back|\.old|\.log|\.pdf_preview-.*\.png|[\/\\\]temp[\/\\\]|[\/\\\]admin[\/\\\]documents[\/\\\])/i';
148 if ($export_type ==
'externalmodule' && !empty($what)) {
149 $rootdirinzip = $what;
151 global $dolibarr_allow_download_external_modules;
152 if (empty($dolibarr_allow_download_external_modules)) {
153 print
'Download of external modules is not allowed by $dolibarr_allow_download_external_modules in conf.php file';
159 $ret = dol_compress_dir($fulldirtocompress, $outputdir.
"/".$file, $compression, $excludefiles, $rootdirinzip);
162 $langs->load(
"errors");
163 $errormsg = $langs->trans(
"ErrNoZipEngine");
165 $langs->load(
"errors");
166 $errormsg = $langs->trans(
"ErrorFailedToWriteInDir", $outputdir);
169} elseif (in_array($compression, array(
'gz',
'bz',
'zstd'))) {
170 $userlogin = ($user->login ? $user->login :
'unknown');
172 $outputfile = $conf->admin->dir_temp.
'/export_files.'.$userlogin.
'.out';
178 $cmd =
"tar -cf '".escapeshellcmd($outputdir.
"/".$file).
"' --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)).
"'";
180 $result = $utils->executeCLI($cmd, $outputfile, 0,
null, 1);
182 $retval = $result[
'error'];
183 if ($result[
'result'] || !empty($retval)) {
184 $langs->load(
"errors");
185 dol_syslog(
"Documents tar retval after exec=".$retval, LOG_ERR);
186 $errormsg =
'Error tar generation return '.$retval;
188 if ($compression ==
'gz') {
189 $cmd =
"gzip -f ".$outputdir.
"/".$file;
190 } elseif ($compression ==
'bz') {
191 $cmd =
"bzip2 -f ".$outputdir.
"/".$file;
192 } elseif ($compression ==
'zstd') {
193 $cmd =
"zstd -z -9 -q --rm ".$outputdir.
"/".$file;
196 $result = $utils->executeCLI($cmd, $outputfile);
198 $retval = $result[
'error'];
199 if ($result[
'result'] || !empty($retval)) {
200 $errormsg =
'Error '.$compression.
' generation return '.$retval;
201 unlink($outputdir.
"/".$file);
205 $errormsg =
'Bad value for compression method';
212if ($export_type !=
'externalmodule' || empty($what)) {
218 setEventMessages($langs->trans(
"BackupFileSuccessfullyCreated").
'.<br>'.$langs->trans(
"YouCanDownloadBackupFile"),
null,
'mesgs');
224 $returnto =
'dolibarr_export.php';
226 header(
"Location: ".$returnto);
232 $zipname = $outputdir.
"/".$file;
236 header(
'Content-disposition: attachment; filename='.basename($zipname));
237 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.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_sanitizePathName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a path name.
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.