1 | <?php |
||
2 | |||
3 | /* Copyright (C) 2008-2016 Laurent Destailleur <[email protected]> |
||
4 | * Copyright (C) 2008-2009 Regis Houssin <[email protected]> |
||
5 | * Copyright (C) 2019 Frédéric France <[email protected]> |
||
6 | * Copyright (C) 2024 Rafael San José <[email protected]> |
||
7 | * |
||
8 | * This program is free software; you can redistribute it and/or modify |
||
9 | * it under the terms of the GNU General Public License as published by |
||
10 | * the Free Software Foundation; either version 3 of the License, or |
||
11 | * (at your option) any later version. |
||
12 | * |
||
13 | * This program is distributed in the hope that it will be useful, |
||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
16 | * GNU General Public License for more details. |
||
17 | * |
||
18 | * You should have received a copy of the GNU General Public License |
||
19 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
||
20 | */ |
||
21 | |||
22 | use Dolibarr\Code\Core\Classes\Form; |
||
23 | use Dolibarr\Code\Core\Classes\FormFile; |
||
24 | use Dolibarr\Code\Ecm\Classes\EcmDirectory; |
||
25 | use Dolibarr\Code\User\Classes\User; |
||
26 | use Dolibarr\Lib\ViewMain; |
||
27 | |||
28 | /** |
||
29 | * \file htdocs/ftp/index.php |
||
30 | * \ingroup ftp |
||
31 | * \brief Main page for FTP section area |
||
32 | */ |
||
33 | |||
34 | // Load Dolibarr environment |
||
35 | require constant('DOL_DOCUMENT_ROOT') . '/main.inc.php'; |
||
36 | require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/files.lib.php'; |
||
37 | require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/treeview.lib.php'; |
||
38 | require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/ftp.lib.php'; |
||
39 | |||
40 | // Load translation files required by the page |
||
41 | $langs->loadLangs(array('companies', 'other')); |
||
42 | |||
43 | // Security check |
||
44 | if ($user->socid) { |
||
45 | $socid = $user->socid; |
||
46 | } |
||
47 | $result = restrictedArea($user, 'ftp', ''); |
||
48 | |||
49 | // Get parameters |
||
50 | $action = GETPOST('action', 'aZ09'); |
||
51 | $section = GETPOST('section'); |
||
52 | $newfolder = GETPOST('newfolder'); |
||
53 | if (!$section) { |
||
54 | $section = '/'; |
||
55 | } |
||
56 | $numero_ftp = GETPOST("numero_ftp"); |
||
57 | /* if (! $numero_ftp) $numero_ftp=1; */ |
||
58 | $file = GETPOST("file"); |
||
59 | $confirm = GETPOST('confirm'); |
||
60 | |||
61 | $upload_dir = $conf->ftp->dir_temp; |
||
62 | $download_dir = $conf->ftp->dir_temp; |
||
63 | |||
64 | $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit; |
||
65 | $sortfield = GETPOST('sortfield', 'aZ09comma'); |
||
66 | $sortorder = GETPOST('sortorder', 'aZ09comma'); |
||
67 | $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page"); |
||
68 | if (empty($page) || $page == -1) { |
||
69 | $page = 0; |
||
70 | } // If $page is not defined, or '' or -1 |
||
71 | $offset = $limit * $page; |
||
72 | $pageprev = $page - 1; |
||
73 | $pagenext = $page + 1; |
||
74 | if (!$sortorder) { |
||
75 | $sortorder = "ASC"; |
||
76 | } |
||
77 | if (!$sortfield) { |
||
78 | $sortfield = "label"; |
||
79 | } |
||
80 | |||
81 | $s_ftp_name = 'FTP_NAME_' . $numero_ftp; |
||
82 | $s_ftp_server = 'FTP_SERVER_' . $numero_ftp; |
||
83 | $s_ftp_port = 'FTP_PORT_' . $numero_ftp; |
||
84 | $s_ftp_user = 'FTP_USER_' . $numero_ftp; |
||
85 | $s_ftp_password = 'FTP_PASSWORD_' . $numero_ftp; |
||
86 | $s_ftp_passive = 'FTP_PASSIVE_' . $numero_ftp; |
||
87 | $ftp_name = getDolGlobalString($s_ftp_name); |
||
88 | $ftp_server = getDolGlobalString($s_ftp_server); |
||
89 | $ftp_port = getDolGlobalString($s_ftp_port); |
||
90 | if (empty($ftp_port)) { |
||
91 | $ftp_port = 21; |
||
92 | } |
||
93 | $ftp_user = getDolGlobalString($s_ftp_user); |
||
94 | $ftp_password = getDolGlobalString($s_ftp_password); |
||
95 | $ftp_passive = getDolGlobalString($s_ftp_passive); |
||
96 | |||
97 | // For result on connection |
||
98 | $ok = 0; |
||
99 | $conn_id = null; // FTP connection ID |
||
100 | $mesg = ''; |
||
101 | |||
102 | |||
103 | /* |
||
104 | * ACTIONS |
||
105 | */ |
||
106 | |||
107 | if ($action == 'uploadfile') { |
||
108 | // set up a connection or die |
||
109 | if (!$conn_id) { |
||
110 | $newsectioniso = mb_convert_encoding($section, 'ISO-8859-1'); |
||
111 | $resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive); |
||
112 | $conn_id = $resultarray['conn_id']; |
||
113 | $ok = $resultarray['ok']; |
||
114 | $mesg = $resultarray['mesg']; |
||
115 | } |
||
116 | if ($conn_id && $ok && !$mesg) { |
||
117 | $nbfile = count($_FILES['userfile']['name']); |
||
118 | for ($i = 0; $i < $nbfile; $i++) { |
||
119 | $newsection = $newsectioniso; |
||
120 | $fileupload = dol_sanitizeFileName($_FILES['userfile']['name'][$i]); |
||
121 | $fileuploadpath = dol_sanitizePathName($_FILES['userfile']['tmp_name'][$i]); |
||
122 | $result = dol_ftp_put($conn_id, $fileupload, $fileuploadpath, $newsection); |
||
123 | |||
124 | if ($result) { |
||
125 | setEventMessages($langs->trans("FileWasUpload", $fileupload), null, 'mesgs'); |
||
126 | } else { |
||
127 | dol_syslog("ftp/index.php ftp_delete", LOG_ERR); |
||
128 | setEventMessages($langs->trans("FTPFailedToUploadFile", $fileupload), null, 'errors'); |
||
129 | } |
||
130 | } |
||
131 | $action = ''; |
||
132 | } else { |
||
133 | dol_print_error(null, $mesg); |
||
134 | } |
||
135 | } |
||
136 | |||
137 | if ($action == 'addfolder') { |
||
138 | // set up a connection or die |
||
139 | if (!$conn_id) { |
||
140 | $newsectioniso = mb_convert_encoding($section, 'ISO-8859-1'); |
||
141 | $resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive); |
||
142 | $conn_id = $resultarray['conn_id']; |
||
143 | $ok = $resultarray['ok']; |
||
144 | $mesg = $resultarray['mesg']; |
||
145 | } |
||
146 | if ($conn_id && $ok && !$mesg) { |
||
147 | $result = dol_ftp_mkdir($conn_id, $newfolder, $newsectioniso); |
||
148 | |||
149 | if ($result) { |
||
150 | setEventMessages($langs->trans("FileWasCreateFolder", $newfolder), null, 'mesgs'); |
||
151 | } else { |
||
152 | dol_syslog("ftp/index.php ftp_delete", LOG_ERR); |
||
153 | setEventMessages($langs->trans("FTPFailedToCreateFolder", $newfolder), null, 'errors'); |
||
154 | } |
||
155 | $action = ''; |
||
156 | } else { |
||
157 | dol_print_error(null, $mesg); |
||
158 | } |
||
159 | } |
||
160 | |||
161 | // Action ajout d'un rep |
||
162 | if ($action == 'add' && $user->hasRight('ftp', 'setup')) { |
||
163 | $ecmdir = new EcmDirectory($db); |
||
164 | $ecmdir->ref = GETPOST("ref"); |
||
0 ignored issues
–
show
|
|||
165 | $ecmdir->label = GETPOST("label"); |
||
0 ignored issues
–
show
It seems like
GETPOST('label') can also be of type array or array or array . However, the property $label is declared as type string . Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
![]() |
|||
166 | $ecmdir->description = GETPOST("desc"); |
||
0 ignored issues
–
show
It seems like
GETPOST('desc') can also be of type array or array or array . However, the property $description is declared as type string . Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
![]() |
|||
167 | |||
168 | $id = $ecmdir->create($user); |
||
169 | if ($id > 0) { |
||
170 | header("Location: " . $_SERVER["PHP_SELF"]); |
||
171 | exit; |
||
172 | } else { |
||
173 | setEventMessages($langs->trans("ErrorFailToCreateDir"), null, 'errors'); |
||
174 | $action = "create"; |
||
175 | } |
||
176 | } |
||
177 | |||
178 | // Remove 1 file |
||
179 | if ($action == 'confirm_deletefile' && GETPOST('confirm') == 'yes') { |
||
180 | // set up a connection or die |
||
181 | if (!$conn_id) { |
||
182 | $newsectioniso = mb_convert_encoding($section, 'ISO-8859-1'); |
||
183 | $resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive); |
||
184 | $conn_id = $resultarray['conn_id']; |
||
185 | $ok = $resultarray['ok']; |
||
186 | $mesg = $resultarray['mesg']; |
||
187 | } |
||
188 | |||
189 | if ($conn_id && $ok && !$mesg) { |
||
190 | $newsection = $section; |
||
191 | $result = dol_ftp_delete($conn_id, $file, $newsection); |
||
192 | |||
193 | if ($result) { |
||
194 | setEventMessages($langs->trans("FileWasRemoved", $file), null, 'mesgs'); |
||
195 | } else { |
||
196 | dol_syslog("ftp/index.php ftp_delete", LOG_ERR); |
||
197 | setEventMessages($langs->trans("FTPFailedToRemoveFile", $file), null, 'errors'); |
||
198 | } |
||
199 | |||
200 | $action = ''; |
||
201 | } else { |
||
202 | dol_print_error(null, $mesg); |
||
203 | } |
||
204 | } |
||
205 | |||
206 | // Delete several lines at once |
||
207 | if (GETPOST("const", 'array') && GETPOST("delete") && GETPOST("delete") == $langs->trans("Delete")) { |
||
208 | // set up a connection or die |
||
209 | if (!$conn_id) { |
||
210 | $newsectioniso = mb_convert_encoding($section, 'ISO-8859-1'); |
||
211 | $resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive); |
||
212 | $conn_id = $resultarray['conn_id']; |
||
213 | $ok = $resultarray['ok']; |
||
214 | $mesg = $resultarray['mesg']; |
||
215 | } |
||
216 | |||
217 | if ($conn_id && $ok && !$mesg) { |
||
218 | foreach (GETPOST('const', 'array') as $const) { |
||
219 | if (isset($const["check"])) { // Is checkbox checked |
||
220 | $langs->load("other"); |
||
221 | |||
222 | // Remote file |
||
223 | $file = $const["file"]; |
||
224 | $newsection = $const["section"]; |
||
225 | |||
226 | $result = dol_ftp_delete($conn_id, $file, $newsection); |
||
227 | |||
228 | if ($result) { |
||
229 | setEventMessages($langs->trans("FileWasRemoved", $file), null, 'mesgs'); |
||
230 | } else { |
||
231 | dol_syslog("ftp/index.php ftp_delete n files", LOG_ERR); |
||
232 | setEventMessages($langs->trans("FTPFailedToRemoveFile", $file), null, 'errors'); |
||
233 | } |
||
234 | |||
235 | //ftp_close($conn_id); Close later |
||
236 | |||
237 | $action = ''; |
||
238 | } |
||
239 | } |
||
240 | } else { |
||
241 | dol_print_error(null, $mesg); |
||
242 | } |
||
243 | } |
||
244 | |||
245 | // Remove directory |
||
246 | if ($action == 'confirm_deletesection' && $confirm == 'yes') { |
||
247 | // set up a connection or die |
||
248 | if (!$conn_id) { |
||
249 | $newsectioniso = mb_convert_encoding($section, 'ISO-8859-1'); |
||
250 | $resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive); |
||
251 | $conn_id = $resultarray['conn_id']; |
||
252 | $ok = $resultarray['ok']; |
||
253 | $mesg = $resultarray['mesg']; |
||
254 | } |
||
255 | |||
256 | if ($conn_id && $ok && !$mesg) { |
||
257 | $newsection = $section; |
||
258 | |||
259 | $result = dol_ftp_rmdir($conn_id, $file, $newsection); |
||
260 | |||
261 | if ($result) { |
||
262 | setEventMessages($langs->trans("DirWasRemoved", $file), null, 'mesgs'); |
||
263 | } else { |
||
264 | setEventMessages($langs->trans("FTPFailedToRemoveDir", $file), null, 'errors'); |
||
265 | } |
||
266 | |||
267 | //ftp_close($conn_id); Close later |
||
268 | |||
269 | $action = ''; |
||
270 | } else { |
||
271 | dol_print_error(null, $mesg); |
||
272 | } |
||
273 | } |
||
274 | |||
275 | // Download directory |
||
276 | if ($action == 'download') { |
||
277 | // set up a connection or die |
||
278 | if (!$conn_id) { |
||
279 | $newsectioniso = mb_convert_encoding($section, 'ISO-8859-1'); |
||
280 | $resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive); |
||
281 | $conn_id = $resultarray['conn_id']; |
||
282 | $ok = $resultarray['ok']; |
||
283 | $mesg = $resultarray['mesg']; |
||
284 | } |
||
285 | |||
286 | if ($conn_id && $ok && !$mesg) { |
||
287 | // Local file |
||
288 | $localfile = tempnam($download_dir, 'dol_'); |
||
289 | |||
290 | $newsection = $section; |
||
291 | |||
292 | $result = dol_ftp_get($conn_id, $localfile, $file, $newsection); |
||
293 | |||
294 | |||
295 | if ($result) { |
||
296 | dolChmod($localfile); |
||
297 | |||
298 | // Define mime type |
||
299 | $type = 'application/octet-stream'; |
||
300 | if (GETPOSTISSET("type")) { |
||
301 | $type = GETPOST("type"); |
||
302 | } else { |
||
303 | $type = dol_mimetype($file); |
||
304 | } |
||
305 | |||
306 | // Define attachment (attachment=true to force choice popup 'open'/'save as') |
||
307 | $attachment = true; |
||
308 | |||
309 | //if ($encoding) header('Content-Encoding: '.$encoding); |
||
310 | if ($type) { |
||
311 | header('Content-Type: ' . $type); |
||
312 | } |
||
313 | if ($attachment) { |
||
314 | header('Content-Disposition: attachment; filename="' . $file . '"'); |
||
315 | } else { |
||
316 | header('Content-Disposition: inline; filename="' . $file . '"'); |
||
317 | } |
||
318 | |||
319 | // Ajout directives pour resoudre bug IE |
||
320 | header('Cache-Control: Public, must-revalidate'); |
||
321 | header('Pragma: public'); |
||
322 | |||
323 | readfile($localfile); |
||
324 | |||
325 | exit; |
||
326 | } else { |
||
327 | setEventMessages($langs->transnoentitiesnoconv('FailedToGetFile', $file), null, 'errors'); |
||
328 | } |
||
329 | } else { |
||
330 | dol_print_error(null, $mesg); |
||
331 | } |
||
332 | |||
333 | //ftp_close($conn_id); Close later |
||
334 | } |
||
335 | |||
336 | |||
337 | /* |
||
338 | * View |
||
339 | */ |
||
340 | |||
341 | ViewMain::llxHeader(); |
||
342 | |||
343 | // Add logic to shoow/hide buttons |
||
344 | if ($conf->use_javascript_ajax) { |
||
345 | ?> |
||
346 | <script type="text/javascript"> |
||
347 | jQuery(document).ready(function () { |
||
348 | jQuery("#delconst").hide(); |
||
349 | |||
350 | jQuery(".checkboxfordelete").click(function () { |
||
351 | jQuery("#delconst").show(); |
||
352 | }); |
||
353 | |||
354 | $("#checkall").click(function () { |
||
355 | $(".checkboxfordelete").prop('checked', true); |
||
356 | jQuery("#delconst").show(); |
||
357 | }); |
||
358 | $("#checknone").click(function () { |
||
359 | $(".checkboxfordelete").prop('checked', false); |
||
360 | jQuery("#delconst").hide(); |
||
361 | }); |
||
362 | |||
363 | }); |
||
364 | |||
365 | </script> |
||
366 | |||
367 | <?php |
||
368 | } |
||
369 | |||
370 | $form = new Form($db); |
||
371 | $formfile = new FormFile($db); |
||
372 | $userstatic = new User($db); |
||
373 | |||
374 | |||
375 | // List |
||
376 | print load_fiche_titre($langs->trans("FTPArea")); |
||
377 | |||
378 | print $langs->trans("FTPAreaDesc") . "<br>"; |
||
379 | |||
380 | if (!function_exists('ftp_connect')) { |
||
381 | print $langs->trans("FTPFeatureNotSupportedByYourPHP"); |
||
382 | } else { |
||
383 | if (!empty($ftp_server)) { |
||
384 | // Confirm remove file |
||
385 | if ($action == 'delete') { |
||
386 | print $form->formconfirm($_SERVER["PHP_SELF"] . '?numero_ftp=' . $numero_ftp . '§ion=' . urlencode(GETPOST('section')) . '&file=' . urlencode(GETPOST('file')), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile', GETPOST('file')), 'confirm_deletefile', '', '', 1); |
||
387 | } |
||
388 | |||
389 | // Confirmation de la suppression d'une ligne categorie |
||
390 | if ($action == 'delete_section') { |
||
391 | print $form->formconfirm($_SERVER["PHP_SELF"] . '?numero_ftp=' . $numero_ftp . '§ion=' . urlencode(GETPOST('section')) . '&file=' . urlencode(GETPOST('file')), $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection', GETPOST('file')), 'confirm_deletesection', '', '', 1); |
||
392 | } |
||
393 | |||
394 | print $langs->trans("Server") . ': <b>' . $ftp_server . '</b><br>'; |
||
395 | print $langs->trans("Port") . ': <b>' . $ftp_port . '</b> ' . ($ftp_passive ? "(Passive)" : "(Active)") . '<br>'; |
||
396 | print $langs->trans("User") . ': <b>' . $ftp_user . '</b><br>'; |
||
397 | print $langs->trans("FTPs (FTP over SSH)") . ': <b>' . yn(getDolGlobalString('FTP_CONNECT_WITH_SSL')) . '</b><br>'; |
||
398 | print $langs->trans("SFTP (FTP as a subsystem of SSH)") . ': <b>' . yn(getDolGlobalString('FTP_CONNECT_WITH_SFTP')) . '</b><br>'; |
||
399 | print $langs->trans("Directory") . ': '; |
||
400 | $sectionarray = preg_split('|[\/]|', $section); |
||
401 | // For / |
||
402 | $newsection = '/'; |
||
403 | print '<a href="' . $_SERVER["PHP_SELF"] . '?action=refreshmanual&numero_ftp=' . $numero_ftp . ($newsection ? '§ion=' . urlencode($newsection) : '') . '">'; |
||
404 | print '/'; |
||
405 | print '</a> '; |
||
406 | // For other directories |
||
407 | $i = 0; |
||
408 | foreach ($sectionarray as $val) { |
||
409 | if (empty($val)) { |
||
410 | continue; // Discard first and last entry that should be empty as section start/end with / |
||
411 | } |
||
412 | if ($i > 0) { |
||
413 | print ' / '; |
||
414 | $newsection .= '/'; |
||
415 | } |
||
416 | $newsection .= $val; |
||
417 | print '<a href="' . $_SERVER["PHP_SELF"] . '?action=refreshmanual&numero_ftp=' . $numero_ftp . ($newsection ? '§ion=' . urlencode($newsection) : '') . '">'; |
||
418 | print $val; |
||
419 | print '</a>'; |
||
420 | $i++; |
||
421 | } |
||
422 | print '<br>'; |
||
423 | print "<br>\n"; |
||
424 | |||
425 | print '<form action="' . $_SERVER["PHP_SELF"] . '" method="POST">'; |
||
426 | print '<input type="hidden" name="numero_ftp" value="' . $numero_ftp . '">'; |
||
427 | print '<input type="hidden" name="token" value="' . newToken() . '">'; |
||
428 | |||
429 | |||
430 | // Construit liste des repertoires |
||
431 | print '<table width="100%" class="noborder">' . "\n"; |
||
432 | |||
433 | print '<tr class="liste_titre">' . "\n"; |
||
434 | print '<td class="liste_titre left">' . $langs->trans("Content") . '</td>' . "\n"; |
||
435 | print '<td class="liste_titre center">' . $langs->trans("Size") . '</td>' . "\n"; |
||
436 | print '<td class="liste_titre center">' . $langs->trans("Date") . '</td>' . "\n"; |
||
437 | print '<td class="liste_titre center">' . $langs->trans("Owner") . '</td>' . "\n"; |
||
438 | print '<td class="liste_titre center">' . $langs->trans("Group") . '</td>' . "\n"; |
||
439 | print '<td class="liste_titre center">' . $langs->trans("Permissions") . '</td>' . "\n"; |
||
440 | print '<td class="liste_titre nowrap right">'; |
||
441 | if ($conf->use_javascript_ajax) { |
||
442 | print '<a href="#" id="checkall">' . $langs->trans("All") . '</a> / <a href="#" id="checknone">' . $langs->trans("None") . '</a> '; |
||
443 | } |
||
444 | print '<a href="' . $_SERVER["PHP_SELF"] . '?action=refreshmanual&numero_ftp=' . $numero_ftp . ($section ? '§ion=' . urlencode($section) : '') . '">' . img_picto($langs->trans("Refresh"), 'refresh') . '</a> '; |
||
445 | print '</td>' . "\n"; |
||
446 | print '</tr>' . "\n"; |
||
447 | |||
448 | // set up a connection or die |
||
449 | if (empty($conn_id)) { |
||
450 | $resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive); |
||
451 | |||
452 | $conn_id = $resultarray['conn_id']; |
||
453 | $ok = $resultarray['ok']; |
||
454 | $mesg = $resultarray['mesg']; |
||
455 | } |
||
456 | |||
457 | if ($ok) { |
||
458 | //$type = ftp_systype($conn_id); |
||
459 | |||
460 | $newsection = $section; |
||
461 | $newsectioniso = mb_convert_encoding($section, 'ISO-8859-1'); |
||
462 | //$newsection='/home'; |
||
463 | |||
464 | // List content of directory ($newsection = '/', '/home', ...) |
||
465 | if (getDolGlobalString('FTP_CONNECT_WITH_SFTP')) { |
||
466 | if ($newsection == '/') { |
||
467 | //$newsection = '/./'; |
||
468 | $newsection = ssh2_sftp_realpath($conn_id, ".") . '/./'; // workaround for bug https://bugs.php.net/bug.php?id=64169 |
||
469 | } |
||
470 | |||
471 | //$newsection='/'; |
||
472 | //$dirHandle = opendir("ssh2.sftp://$conn_id".$newsection); |
||
473 | //$dirHandle = opendir("ssh2.sftp://".intval($conn_id).ssh2_sftp_realpath($conn_id, ".").'/./'); |
||
474 | |||
475 | $contents = scandir('ssh2.sftp://' . intval($conn_id) . $newsection); |
||
476 | $buff = array(); |
||
477 | foreach ($contents as $i => $key) { |
||
478 | $buff[$i] = "---------- - root root 1234 Aug 01 2000 " . $key; |
||
479 | } |
||
480 | |||
481 | //$i = 0; |
||
482 | //$handle = opendir('ssh2.sftp://'.intval($conn_id).$newsection); |
||
483 | //$buff=array(); |
||
484 | //while (false !== ($file = readdir($handle))) { |
||
485 | // if (substr("$file", 0, 1) != "."){ |
||
486 | // if (is_dir($file)) { |
||
487 | // $buff[$i]="d--------- - root root 1234 Aug 01 2000 ".$file; |
||
488 | // } else { |
||
489 | // $buff[$i]="---------- - root root 1234 Aug 01 2000 ".$file; |
||
490 | // } |
||
491 | // } |
||
492 | // $i++; |
||
493 | //} |
||
494 | } else { |
||
495 | $buff = ftp_rawlist($conn_id, $newsectioniso); |
||
496 | $contents = ftp_nlist($conn_id, $newsectioniso); // Sometimes rawlist fails but never nlist |
||
497 | } |
||
498 | |||
499 | $nboflines = count($contents); |
||
500 | $rawlisthasfailed = false; |
||
501 | $i = 0; |
||
502 | $nbofentries = 0; |
||
503 | while ($i < $nboflines && $i < 1000) { |
||
504 | $vals = preg_split('@ +@', mb_convert_encoding($buff[$i], 'UTF-8', 'ISO-8859-1'), 9); |
||
505 | //$vals=preg_split('@ +@','drwxr-xr-x 2 root root 4096 Aug 30 2008 backup_apollon1',9); |
||
506 | $file = $vals[8]; |
||
507 | if (empty($file)) { |
||
508 | $rawlisthasfailed = true; |
||
509 | $file = mb_convert_encoding($contents[$i], 'UTF-8', 'ISO-8859-1'); |
||
510 | } |
||
511 | |||
512 | if ($file == '.' || ($file == '..' && $section == '/')) { |
||
513 | $i++; |
||
514 | continue; |
||
515 | } |
||
516 | |||
517 | // Is it a directory ? |
||
518 | $is_directory = 0; |
||
519 | $is_link = 0; |
||
520 | if ($file == '..') { |
||
521 | $is_directory = 1; |
||
522 | } elseif (!$rawlisthasfailed) { |
||
523 | if (preg_match('/^d/', $vals[0])) { |
||
524 | $is_directory = 1; |
||
525 | } |
||
526 | if (preg_match('/^l/', $vals[0])) { |
||
527 | $is_link = 1; |
||
528 | } |
||
529 | } else { |
||
530 | // Remote file |
||
531 | $filename = $file; |
||
532 | //print "section=".$section.' file='.$file.'X'; |
||
533 | //print preg_match('@[\/]$@','aaa/').'Y'; |
||
534 | //print preg_match('@[\\\/]$@',"aaa\\").'Y'; |
||
535 | $remotefile = $section . (preg_match('@[\\\/]$@', $section) ? '' : '/') . preg_replace('@^[\\\/]@', '', $file); |
||
536 | //print 'A'.$remotefile.'A'; |
||
537 | $newremotefileiso = mb_convert_encoding($remotefile, 'ISO-8859-1'); |
||
538 | //print 'Z'.$newremotefileiso.'Z'; |
||
539 | $is_directory = ftp_isdir($conn_id, $newremotefileiso); |
||
540 | } |
||
541 | |||
542 | |||
543 | print '<tr class="oddeven" height="18">'; |
||
544 | // Name |
||
545 | print '<td>'; |
||
546 | $newsection = $section . (preg_match('@[\\\/]$@', $section) ? '' : '/') . $file; |
||
547 | $newsection = preg_replace('@[\\\/][^\\\/]+[\\\/]\.\.$@', '/', $newsection); // Change aaa/xxx/.. to new aaa |
||
548 | if ($is_directory) { |
||
549 | print '<a href="' . $_SERVER["PHP_SELF"] . '?section=' . urlencode($newsection) . '&numero_ftp=' . $numero_ftp . '">'; |
||
550 | } |
||
551 | print dol_escape_htmltag($file); |
||
552 | if ($is_directory) { |
||
553 | print '</a>'; |
||
554 | } |
||
555 | print '</td>'; |
||
556 | // Size |
||
557 | print '<td class="center nowrap">'; |
||
558 | if (!$is_directory && !$is_link) { |
||
559 | print $vals[4]; |
||
560 | } else { |
||
561 | print ' '; |
||
562 | } |
||
563 | print '</td>'; |
||
564 | // Date |
||
565 | print '<td class="center nowrap">'; |
||
566 | print $vals[5] . ' ' . $vals[6] . ' ' . $vals[7]; |
||
567 | print '</td>'; |
||
568 | // User |
||
569 | print '<td class="center nowrap">'; |
||
570 | print $vals[2]; |
||
571 | print '</td>'; |
||
572 | // Group |
||
573 | print '<td class="center nowrap">'; |
||
574 | print $vals[3]; |
||
575 | print '</td>'; |
||
576 | // Permissions |
||
577 | print '<td class="center nowrap">'; |
||
578 | print $vals[0]; |
||
579 | print '</td>'; |
||
580 | // Action |
||
581 | print '<td class="right nowrap" width="64">'; |
||
582 | if ($is_directory) { |
||
583 | if ($file != '..') { |
||
584 | print '<a href="' . $_SERVER["PHP_SELF"] . '?action=delete_section&token=' . newToken() . '&numero_ftp=' . $numero_ftp . '§ion=' . urlencode($section) . '&file=' . urlencode($file) . '">' . img_delete() . '</a>'; |
||
585 | } else { |
||
586 | print ' '; |
||
587 | } |
||
588 | } elseif ($is_link) { |
||
589 | $newfile = $file; |
||
590 | $newfile = preg_replace('/ ->.*/', '', $newfile); |
||
591 | print '<a href="' . $_SERVER["PHP_SELF"] . '?action=delete&token=' . newToken() . '&numero_ftp=' . $numero_ftp . '§ion=' . urlencode($section) . '&file=' . urlencode($newfile) . '">' . img_delete() . '</a>'; |
||
592 | } else { |
||
593 | print '<a href="' . $_SERVER["PHP_SELF"] . '?action=download&token=' . newToken() . '&numero_ftp=' . $numero_ftp . '§ion=' . urlencode($section) . '&file=' . urlencode($file) . '">' . img_picto('', 'file') . '</a>'; |
||
594 | print ' '; |
||
595 | print '<input type="checkbox" class="flat checkboxfordelete" id="check_' . $i . '" name="const[' . $i . '][check]" value="1">'; |
||
596 | print ' '; |
||
597 | print '<a href="' . $_SERVER["PHP_SELF"] . '?action=delete&token=' . newToken() . '&numero_ftp=' . $numero_ftp . '§ion=' . urlencode($section) . '&file=' . urlencode($file) . '">' . img_delete() . '</a>'; |
||
598 | print '<input type="hidden" name="const[' . $i . '][section]" value="' . $section . '">'; |
||
599 | print '<input type="hidden" name="const[' . $i . '][file]" value="' . $file . '">'; |
||
600 | } |
||
601 | print '</td>'; |
||
602 | print '</tr>' . "\n"; |
||
603 | $i++; |
||
604 | $nbofentries++; |
||
605 | } |
||
606 | } |
||
607 | |||
608 | print "</table>"; |
||
609 | |||
610 | |||
611 | if (!$ok) { |
||
612 | print $mesg . '<br>' . "\n"; |
||
613 | setEventMessages($mesg, null, 'errors'); |
||
614 | } |
||
615 | |||
616 | |||
617 | // Actions |
||
618 | |||
619 | print '<br>'; |
||
620 | print '<div id="delconst" class="right">'; |
||
621 | print '<input type="submit" name="delete" class="button" value="' . $langs->trans("Delete") . '">'; |
||
622 | print '</div>'; |
||
623 | |||
624 | print "</form>"; |
||
625 | |||
626 | if ($user->hasRight('ftp', 'write')) { |
||
627 | print load_fiche_titre($langs->trans("AttachANewFile"), null, null); |
||
628 | print '<form enctype="multipart/form-data" action="' . $_SERVER["PHP_SELF"] . '" method="post">'; |
||
629 | print '<input type="hidden" name="token" value="' . newToken() . '">'; |
||
630 | print '<input type="hidden" name="numero_ftp" value="' . $numero_ftp . '">'; |
||
631 | print '<input type="hidden" name="section" value="' . $section . '">'; |
||
632 | print '<input type="hidden" name="action" value="uploadfile">'; |
||
633 | print '<td><input type="file" class="flat" name="userfile[]" multiple></td>'; |
||
634 | print '<td></td>'; |
||
635 | print '<td align="center"><button type="submit" class="butAction" name="uploadfile" value="' . $langs->trans("Save") . '">' . $langs->trans("Upload") . '</button></td>'; |
||
636 | print '</form>'; |
||
637 | |||
638 | print '<br><br>'; |
||
639 | |||
640 | print load_fiche_titre($langs->trans("AddFolder"), null, null); |
||
641 | print '<form enctype="multipart/form-data" action="' . $_SERVER["PHP_SELF"] . '" method="post">'; |
||
642 | print '<input type="hidden" name="token" value="' . newToken() . '">'; |
||
643 | print '<input type="hidden" name="numero_ftp" value="' . $numero_ftp . '">'; |
||
644 | print '<input type="hidden" name="section" value="' . $section . '">'; |
||
645 | print '<input type="hidden" name="action" value="addfolder">'; |
||
646 | print '<td><input type="text" class="flat" name="newfolder" multiple></td>'; |
||
647 | print '<td></td>'; |
||
648 | print '<td align="center"><button type="submit" class="butAction" name="addfolder" value="' . $langs->trans("Save") . '">' . $langs->trans("AddFolder") . '</button></td>'; |
||
649 | print '</form>'; |
||
650 | } |
||
651 | } else { |
||
652 | $foundsetup = false; |
||
653 | $MAXFTP = 20; |
||
654 | $i = 1; |
||
655 | while ($i <= $MAXFTP) { |
||
656 | $paramkey = 'FTP_NAME_' . $i; |
||
657 | //print $paramkey; |
||
658 | if (getDolGlobalString($paramkey)) { |
||
659 | $foundsetup = true; |
||
660 | break; |
||
661 | } |
||
662 | $i++; |
||
663 | } |
||
664 | if (!$foundsetup) { |
||
665 | print $langs->trans("SetupOfFTPClientModuleNotComplete"); |
||
666 | } else { |
||
667 | print $langs->trans("ChooseAFTPEntryIntoMenu"); |
||
668 | } |
||
669 | } |
||
670 | } |
||
671 | |||
672 | print '<br>'; |
||
673 | |||
674 | if (!empty($conn_id)) { |
||
675 | $disconnect = dol_ftp_close($conn_id); |
||
676 | |||
677 | if (!$disconnect) { |
||
678 | setEventMessages($langs->trans("ErrorFTPNodisconnect"), null, 'errors'); |
||
679 | } |
||
680 | } |
||
681 | |||
682 | // End of page |
||
683 | ViewMain::llxFooter(); |
||
684 | $db->close(); |
||
685 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.