27if (! defined(
'CSRFCHECK_WITH_TOKEN')) {
28 define(
'CSRFCHECK_WITH_TOKEN',
'1');
32require
'../../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/class/utils.class.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
48$action =
GETPOST(
'action',
'aZ09');
49$what =
GETPOST(
'what',
'alpha');
50$export_type =
GETPOST(
'export_type',
'alpha');
51$file = trim(
GETPOST(
'zipfilename_template',
'alpha'));
52$compression =
GETPOST(
'compression',
'aZ09');
55$file = preg_replace(
'/(\.zip|\.tar|\.tgz|\.gz|\.tar\.gz|\.bz2|\.zst)$/i',
'', $file);
57$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
58$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
68} elseif (empty($page)) {
72$offset = $limit * $page;
85if ($action ==
'delete') {
87 $filepath =
$conf->admin->dir_output.
'/'.$filerelative;
90 setEventMessages($langs->trans(
"FileWasRemoved", $filerelative),
null,
'mesgs');
92 setEventMessages($langs->trans(
"ErrorFailToDeleteFile", $filerelative),
null,
'errors');
103$ExecTimeLimit = 1800;
104if (!empty($ExecTimeLimit)) {
105 $err = error_reporting();
108 @set_time_limit($ExecTimeLimit);
109 error_reporting($err);
114if (!empty($MemoryLimit)) {
115 @ini_set(
'memory_limit', $MemoryLimit);
118$form =
new Form($db);
135$outputdir =
$conf->admin->dir_output.
'/documents';
138$utils =
new Utils($db);
140if ($export_type ==
'externalmodule' && !empty($what)) {
143 $fulldirtocompress = DOL_DATA_ROOT;
145$dirtoswitch = dirname($fulldirtocompress);
146$dirtocompress = basename($fulldirtocompress);
148if ($compression ==
'zip') {
151 $excludefiles =
'/(\.back|\.old|\.log|\.pdf_preview-.*\.png|[\/\\\]temp[\/\\\]|[\/\\\]admin[\/\\\]documents[\/\\\])/i';
157 if ($export_type ==
'externalmodule' && !empty($what)) {
158 $rootdirinzip = $what;
160 global $dolibarr_allow_download_external_modules;
161 if (empty($dolibarr_allow_download_external_modules)) {
162 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");
175 $errormsg = $langs->trans(
"ErrorFailedToWriteInDir", $outputdir);
178} elseif (in_array($compression, array(
'gz',
'bz',
'zstd'))) {
179 $userlogin = ($user->login ? $user->login :
'unknown');
181 $outputfile =
$conf->admin->dir_temp.
'/export_files.'.$userlogin.
'.out';
187 $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)).
"'";
189 $result = $utils->executeCLI($cmd, $outputfile, 0,
null, 1);
191 $retval = $result[
'error'];
192 if ($result[
'result'] || !empty($retval)) {
193 $langs->load(
"errors");
194 dol_syslog(
"Documents tar retval after exec=".$retval, LOG_ERR);
195 $errormsg =
'Error tar generation return '.$retval;
197 if ($compression ==
'gz') {
198 $cmd =
"gzip -f ".$outputdir.
"/".$file;
199 } elseif ($compression ==
'bz') {
200 $cmd =
"bzip2 -f ".$outputdir.
"/".$file;
201 } elseif ($compression ==
'zstd') {
202 $cmd =
"zstd -z -9 -q --rm ".$outputdir.
"/".$file;
205 $result = $utils->executeCLI($cmd, $outputfile);
207 $retval = $result[
'error'];
208 if ($result[
'result'] || !empty($retval)) {
209 $errormsg =
'Error '.$compression.
' generation return '.$retval;
210 unlink($outputdir.
"/".$file);
214 $errormsg =
'Bad value for compression method';
221if ($export_type !=
'externalmodule' || empty($what)) {
227 setEventMessages($langs->trans(
"BackupFileSuccessfullyCreated").
'.<br>'.$langs->trans(
"YouCanDownloadBackupFile"),
null,
'mesgs');
233 $returnto =
'dolibarr_export.php';
235 header(
"Location: ".$returnto);
241 $zipname = $outputdir.
"/".$file;
245 header(
'Content-disposition: attachment; filename='.basename($zipname));
246 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.
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.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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_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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.