1 | <?php |
||||
2 | /* Copyright (C) 2006-2014 Laurent Destailleur <[email protected]> |
||||
3 | * Copyright (C) 2011 Juanjo Menent <[email protected]> |
||||
4 | * Copyright (C) 2015 Raphaël Doursenaud <[email protected]> |
||||
5 | * |
||||
6 | * This program is free software; you can redistribute it and/or modify |
||||
7 | * it under the terms of the GNU General Public License as published by |
||||
8 | * the Free Software Foundation; either version 3 of the License, or |
||||
9 | * (at your option) any later version. |
||||
10 | * |
||||
11 | * This program is distributed in the hope that it will be useful, |
||||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
14 | * GNU General Public License for more details. |
||||
15 | * |
||||
16 | * You should have received a copy of the GNU General Public License |
||||
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
18 | */ |
||||
19 | |||||
20 | /** |
||||
21 | * \file htdocs/admin/tools/export.php |
||||
22 | * \brief Page to export a database into a dump file |
||||
23 | */ |
||||
24 | |||||
25 | |||||
26 | // Copyright (C) 2018 Alxarafe/Alixar <[email protected]> |
||||
27 | defined('BASE_PATH') or die('Single entry point through the index.php of the main folder'); |
||||
28 | require DOL_BASE_PATH . '/main.inc.php'; |
||||
29 | require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; |
||||
30 | require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
||||
31 | require_once DOL_DOCUMENT_ROOT.'/core/class/utils.class.php'; |
||||
32 | require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; |
||||
33 | |||||
34 | $langs->load("admin"); |
||||
35 | |||||
36 | $action=GETPOST('action','alpha'); |
||||
37 | $what=GETPOST('what','alpha'); |
||||
38 | $export_type=GETPOST('export_type','alpha'); |
||||
39 | $file=GETPOST('zipfilename_template','alpha'); |
||||
40 | $compression = GETPOST('compression'); |
||||
41 | |||||
42 | $sortfield = GETPOST('sortfield','alpha'); |
||||
43 | $sortorder = GETPOST('sortorder','alpha'); |
||||
44 | $page = GETPOST("page",'int'); |
||||
45 | if (! $sortorder) $sortorder="DESC"; |
||||
46 | if (! $sortfield) $sortfield="date"; |
||||
47 | if ($page < 0) { $page = 0; } |
||||
48 | elseif (empty($page)) $page = 0; |
||||
49 | $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; |
||||
50 | $offset = $limit * $page; |
||||
51 | |||||
52 | if (! $user->admin) accessforbidden(); |
||||
53 | |||||
54 | $errormsg=''; |
||||
55 | |||||
56 | |||||
57 | /* |
||||
58 | * Actions |
||||
59 | */ |
||||
60 | |||||
61 | if ($action == 'delete') |
||||
62 | { |
||||
63 | $file=$conf->admin->dir_output.'/'.GETPOST('urlfile'); |
||||
64 | $ret=dol_delete_file($file, 1); |
||||
65 | if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs'); |
||||
66 | else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors'); |
||||
67 | $action=''; |
||||
68 | } |
||||
69 | |||||
70 | |||||
71 | /* |
||||
72 | * View |
||||
73 | */ |
||||
74 | |||||
75 | // Increase limit of time. Works only if we are not in safe mode |
||||
76 | $ExecTimeLimit=600; |
||||
77 | if (!empty($ExecTimeLimit)) |
||||
78 | { |
||||
79 | $err=error_reporting(); |
||||
80 | error_reporting(0); // Disable all errors |
||||
81 | //error_reporting(E_ALL); |
||||
82 | @set_time_limit($ExecTimeLimit); // Need more than 240 on Windows 7/64 |
||||
0 ignored issues
–
show
|
|||||
83 | error_reporting($err); |
||||
84 | } |
||||
85 | $MemoryLimit=0; |
||||
86 | if (!empty($MemoryLimit)) |
||||
87 | { |
||||
88 | @ini_set('memory_limit', $MemoryLimit); |
||||
0 ignored issues
–
show
It seems like you do not handle an error condition for
ini_set() . This can introduce security issues, and is generally not recommended.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
|
|||||
89 | } |
||||
90 | |||||
91 | $form=new Form($db); |
||||
92 | $formfile = new FormFile($db); |
||||
93 | |||||
94 | //$help_url='EN:Backups|FR:Sauvegardes|ES:Copias_de_seguridad'; |
||||
95 | //llxHeader('','',$help_url); |
||||
96 | |||||
97 | //print load_fiche_titre($langs->trans("Backup"),'','title_setup'); |
||||
98 | |||||
99 | |||||
100 | // Start with empty buffer |
||||
101 | $dump_buffer = ''; |
||||
102 | $dump_buffer_len = 0; |
||||
103 | |||||
104 | // We will send fake headers to avoid browser timeout when buffering |
||||
105 | $time_start = time(); |
||||
106 | |||||
107 | |||||
108 | $outputdir = $conf->admin->dir_output.'/documents'; |
||||
109 | $result=dol_mkdir($outputdir); |
||||
110 | |||||
111 | $utils = new Utils($db); |
||||
112 | |||||
113 | if ($compression == 'zip') |
||||
114 | { |
||||
115 | $ret = dol_compress_dir(DOL_DATA_ROOT, $outputdir."/".$file, $compression); |
||||
116 | if ($ret < 0) |
||||
117 | { |
||||
118 | $errormsg = $langs->trans("ErrorFailedToWriteInDir",$outputfile); |
||||
119 | } |
||||
120 | } |
||||
121 | elseif (in_array($compression, array('gz', 'bz'))) |
||||
122 | { |
||||
123 | $file = substr($file, 0, strrpos($file, '.')); |
||||
124 | $file .= '.tar'; |
||||
125 | $cmd = 'tar -cf '.$outputdir."/".$file." --exclude=documents/admin/documents -C ".DOL_DATA_ROOT." ".DOL_DATA_ROOT."/../documents/"; |
||||
126 | exec($cmd, $out, $retval); |
||||
127 | //var_dump($cmd, DOL_DATA_ROOT);exit; |
||||
128 | |||||
129 | if ($retval != 0) |
||||
130 | { |
||||
131 | $langs->load("errors"); |
||||
132 | dol_syslog("Documents tar retval after exec=".$retval, LOG_ERR); |
||||
133 | $errormsg = 'Error tar generation return '.$retval; |
||||
134 | } |
||||
135 | else |
||||
136 | { |
||||
137 | if ($compression == 'gz') |
||||
138 | { |
||||
139 | $cmd = "gzip " . $outputdir."/".$file; |
||||
140 | } |
||||
141 | if ($compression == 'bz') |
||||
142 | { |
||||
143 | $cmd = "bzip2 " . $outputdir."/".$file; |
||||
144 | } |
||||
145 | |||||
146 | exec($cmd, $out, $retval); |
||||
147 | if ($retval != 0) |
||||
148 | { |
||||
149 | $errormsg = 'Error '.$compression.' generation return '.$retval; |
||||
150 | unlink($outputdir."/".$file); |
||||
151 | } |
||||
152 | } |
||||
153 | } |
||||
154 | |||||
155 | if ($errormsg) |
||||
156 | { |
||||
157 | setEventMessages($langs->trans("Error")." : ".$errormsg, null, 'errors'); |
||||
158 | } |
||||
159 | |||||
160 | print '<br>'; |
||||
161 | |||||
162 | |||||
163 | // Redirect t backup page |
||||
164 | header("Location: dolibarr_export.php"); |
||||
165 | |||||
166 | $time_end = time(); |
||||
167 | |||||
168 | $db->close(); |
||||
169 | |||||
170 |
If you suppress an error, we recommend checking for the error condition explicitly: