dolibarr  16.0.5
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2008-2016 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2008-2009 Regis Houssin <regis.houssin@inodbox.com>
4  * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
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 <https://www.gnu.org/licenses/>.
18  */
19 
26 require '../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php';
30 
31 // Load translation files required by the page
32 $langs->loadLangs(array('companies', 'other'));
33 
34 // Security check
35 if ($user->socid) {
36  $socid = $user->socid;
37 }
38 $result = restrictedArea($user, 'ftp', '');
39 
40 // Get parameters
41 $action = GETPOST('action', 'aZ09');
42 $section = GETPOST('section');
43 if (!$section) {
44  $section = '/';
45 }
46 $numero_ftp = GETPOST("numero_ftp");
47 /* if (! $numero_ftp) $numero_ftp=1; */
48 $file = GETPOST("file");
49 $confirm = GETPOST('confirm');
50 
51 $upload_dir = $conf->ftp->dir_temp;
52 $download_dir = $conf->ftp->dir_temp;
53 
54 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
55 $sortfield = GETPOST('sortfield', 'aZ09comma');
56 $sortorder = GETPOST('sortorder', 'aZ09comma');
57 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
58 if (empty($page) || $page == -1) {
59  $page = 0;
60 } // If $page is not defined, or '' or -1
61 $offset = $limit * $page;
62 $pageprev = $page - 1;
63 $pagenext = $page + 1;
64 if (!$sortorder) {
65  $sortorder = "ASC";
66 }
67 if (!$sortfield) {
68  $sortfield = "label";
69 }
70 
71 $s_ftp_name = 'FTP_NAME_'.$numero_ftp;
72 $s_ftp_server = 'FTP_SERVER_'.$numero_ftp;
73 $s_ftp_port = 'FTP_PORT_'.$numero_ftp;
74 $s_ftp_user = 'FTP_USER_'.$numero_ftp;
75 $s_ftp_password = 'FTP_PASSWORD_'.$numero_ftp;
76 $s_ftp_passive = 'FTP_PASSIVE_'.$numero_ftp;
77 $ftp_name = getDolGlobalString($s_ftp_name);
78 $ftp_server = getDolGlobalString($s_ftp_server);
79 $ftp_port = getDolGlobalString($s_ftp_port);
80 if (empty($ftp_port)) {
81  $ftp_port = 21;
82 }
83 $ftp_user = getDolGlobalString($s_ftp_user);
84 $ftp_password = getDolGlobalString($s_ftp_password);
85 $ftp_passive = getDolGlobalString($s_ftp_passive);
86 
87 // For result on connection
88 $ok = 0;
89 $conn_id = null; // FTP connection ID
90 $mesg = '';
91 
92 
93 
94 /*
95  * ACTIONS
96  */
97 
98 // Submit file
99 if (GETPOST("sendit") && !empty($conf->global->MAIN_UPLOAD_DOC)) {
100  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
101 
102  $result = $ecmdir->fetch(GETPOST("section", 'int'));
103  if (!($result > 0)) {
104  dol_print_error($db, $ecmdir->error);
105  exit;
106  }
107  $relativepath = $ecmdir->getRelativePath();
108  $upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
109 
110  if (dol_mkdir($upload_dir) >= 0) {
111  $resupload = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir."/".dol_unescapefile($_FILES['userfile']['name']), 0);
112  if (is_numeric($resupload) && $resupload > 0) {
113  $result = $ecmdir->changeNbOfFiles('+');
114  } else {
115  $langs->load("errors");
116  if ($resupload < 0) { // Unknown error
117  setEventMessages($langs->trans("ErrorFileNotUploaded"), null, 'errors');
118  } elseif (preg_match('/ErrorFileIsInfectedWithAVirus/', $resupload)) {
119  // Files infected by a virus
120  setEventMessages($langs->trans("ErrorFileIsInfectedWithAVirus"), null, 'errors');
121  } else // Known error
122  {
123  setEventMessages($langs->trans($resupload), null, 'errors');
124  }
125  }
126  } else {
127  // Transfer failure (file exceeding the limit ?)
128  $langs->load("errors");
129  setEventMessages($langs->trans("ErrorFailToCreateDir", $upload_dir), null, 'errors');
130  }
131 }
132 
133 // Action ajout d'un rep
134 if ($action == 'add' && $user->rights->ftp->setup) {
135  $ecmdir->ref = GETPOST("ref");
136  $ecmdir->label = GETPOST("label");
137  $ecmdir->description = GETPOST("desc");
138 
139  $id = $ecmdir->create($user);
140  if ($id > 0) {
141  header("Location: ".$_SERVER["PHP_SELF"]);
142  exit;
143  } else {
144  setEventMessages($langs->trans("ErrorFailToCreateDir"), null, 'errors');
145  $action = "create";
146  }
147 }
148 
149 // Remove 1 file
150 if ($action == 'confirm_deletefile' && GETPOST('confirm') == 'yes') {
151  // set up a connection or die
152  if (!$conn_id) {
153  $newsectioniso = utf8_decode($section);
154  $resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
155  $conn_id = $resultarray['conn_id'];
156  $ok = $resultarray['ok'];
157  $mesg = $resultarray['mesg'];
158  }
159 
160  if ($conn_id && $ok && !$mesg) {
161  $newsection = $section;
162  if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
163  $newsection = ssh2_sftp_realpath($conn_id, ".").'/./'; // workaround for bug https://bugs.php.net/bug.php?id=64169
164  }
165 
166  $langs->load("other");
167 
168  // Remote file
169  $filename = $file;
170  $remotefile = $newsection.(preg_match('@[\\\/]$@', $newsection) ? '' : '/').$file;
171  $newremotefileiso = utf8_decode($remotefile);
172 
173  //print "x".$newremotefileiso;
174  dol_syslog("ftp/index.php ftp_delete ".$newremotefileiso);
175  if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
176  $result = ssh2_sftp_unlink($conn_id, $newremotefileiso);
177  } else {
178  $result = @ftp_delete($conn_id, $newremotefileiso);
179  }
180  if ($result) {
181  setEventMessages($langs->trans("FileWasRemoved", $file), null, 'mesgs');
182  } else {
183  dol_syslog("ftp/index.php ftp_delete", LOG_ERR);
184  setEventMessages($langs->trans("FTPFailedToRemoveFile", $file), null, 'errors');
185  }
186 
187  //ftp_close($conn_id); Close later
188 
189  $action = '';
190  } else {
191  dol_print_error('', $mesg);
192  }
193 }
194 
195 // Delete several lines at once
196 if (GETPOST("const", 'array') && GETPOST("delete") && GETPOST("delete") == $langs->trans("Delete")) {
197  // set up a connection or die
198  if (!$conn_id) {
199  $newsectioniso = utf8_decode($section);
200  $resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
201  $conn_id = $resultarray['conn_id'];
202  $ok = $resultarray['ok'];
203  $mesg = $resultarray['mesg'];
204  }
205 
206  if ($conn_id && $ok && !$mesg) {
207  foreach (GETPOST('const', 'array') as $const) {
208  if ($const["check"]) { // Is checkbox checked
209  $langs->load("other");
210 
211  // Remote file
212  $file = $const["file"];
213  $newsection = $const["section"];
214  if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
215  $newsection = ssh2_sftp_realpath($conn_id, ".").'/./'; // workaround for bug https://bugs.php.net/bug.php?id=64169
216  }
217  $remotefile = $newsection.(preg_match('@[\\\/]$@', $newsection) ? '' : '/').$file;
218  $newremotefileiso = utf8_decode($remotefile);
219 
220  //print "x".$newremotefileiso;
221  dol_syslog("ftp/index.php ftp_delete n files for ".$newremotefileiso);
222  if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
223  $result = ssh2_sftp_unlink($conn_id, $newremotefileiso);
224  } else {
225  $result = @ftp_delete($conn_id, $newremotefileiso);
226  }
227  if ($result) {
228  setEventMessages($langs->trans("FileWasRemoved", $file), null, 'mesgs');
229  } else {
230  dol_syslog("ftp/index.php ftp_delete n files", LOG_ERR);
231  setEventMessages($langs->trans("FTPFailedToRemoveFile", $file), null, 'errors');
232  }
233 
234  //ftp_close($conn_id); Close later
235 
236  $action = '';
237  }
238  }
239  } else {
240  dol_print_error('', $mesg);
241  }
242 }
243 
244 // Remove directory
245 if ($action == 'confirm_deletesection' && $confirm == 'yes') {
246  // set up a connection or die
247  if (!$conn_id) {
248  $newsectioniso = utf8_decode($section);
249  $resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
250  $conn_id = $resultarray['conn_id'];
251  $ok = $resultarray['ok'];
252  $mesg = $resultarray['mesg'];
253  }
254 
255  if ($conn_id && $ok && !$mesg) {
256  $newsection = $section;
257  if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
258  $newsection = ssh2_sftp_realpath($conn_id, ".").'/./'; // workaround for bug https://bugs.php.net/bug.php?id=64169
259  }
260 
261  // Remote file
262  $filename = $file;
263  $remotefile = $newsection.(preg_match('@[\\\/]$@', $newsection) ? '' : '/').$file;
264  $newremotefileiso = utf8_decode($remotefile);
265 
266  if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
267  $result = ssh2_sftp_rmdir($conn_id, $newremotefileiso);
268  } else {
269  $result = @ftp_rmdir($conn_id, $newremotefileiso);
270  }
271  if ($result) {
272  setEventMessages($langs->trans("DirWasRemoved", $file), null, 'mesgs');
273  } else {
274  setEventMessages($langs->trans("FTPFailedToRemoveDir", $file), null, 'errors');
275  }
276 
277  //ftp_close($conn_id); Close later
278 
279  $action = '';
280  } else {
281  dol_print_error('', $mesg);
282  }
283 }
284 
285 // Download directory
286 if ($action == 'download') {
287  // set up a connection or die
288  if (!$conn_id) {
289  $newsectioniso = utf8_decode($section);
290  $resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
291  $conn_id = $resultarray['conn_id'];
292  $ok = $resultarray['ok'];
293  $mesg = $resultarray['mesg'];
294  }
295 
296  if ($conn_id && $ok && !$mesg) {
297  // Local file
298  $localfile = tempnam($download_dir, 'dol_');
299 
300  $newsection = $section;
301  if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
302  $newsection = ssh2_sftp_realpath($conn_id, ".").'/./'; // workaround for bug https://bugs.php.net/bug.php?id=64169
303  }
304 
305  // Remote file
306  $filename = $file;
307  $remotefile = $newsection.(preg_match('@[\\\/]$@', $newsection) ? '' : '/').$file;
308  $newremotefileiso = utf8_decode($remotefile);
309 
310  if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
311  $result = fopen('ssh2.sftp://'.intval($conn_id).$newremotefileiso, 'r');
312  } else {
313  $result = ftp_get($conn_id, $localfile, $newremotefileiso, FTP_BINARY);
314  }
315  if ($result) {
316  if (!empty($conf->global->MAIN_UMASK)) {
317  @chmod($localfile, octdec($conf->global->MAIN_UMASK));
318  }
319 
320  // Define mime type
321  $type = 'application/octet-stream';
322  if (GETPOSTISSET("type")) {
323  $type = GETPOST("type");
324  } else {
325  $type = dol_mimetype($file);
326  }
327 
328  // Define attachment (attachment=true to force choice popup 'open'/'save as')
329  $attachment = true;
330 
331  //if ($encoding) header('Content-Encoding: '.$encoding);
332  if ($type) {
333  header('Content-Type: '.$type);
334  }
335  if ($attachment) {
336  header('Content-Disposition: attachment; filename="'.$filename.'"');
337  } else {
338  header('Content-Disposition: inline; filename="'.$filename.'"');
339  }
340 
341  // Ajout directives pour resoudre bug IE
342  header('Cache-Control: Public, must-revalidate');
343  header('Pragma: public');
344 
345  readfile($localfile);
346 
347  ftp_close($conn_id);
348 
349  exit;
350  } else {
351  setEventMessages($langs->transnoentitiesnoconv('FailedToGetFile', $remotefile), null, 'errors');
352  }
353  } else {
354  dol_print_error('', $mesg);
355  }
356 
357  //ftp_close($conn_id); Close later
358 }
359 
360 
361 
362 
363 /*
364  * View
365  */
366 
367 llxHeader();
368 
369 // Add logic to shoow/hide buttons
370 if ($conf->use_javascript_ajax) {
371  ?>
372 <script type="text/javascript">
373 jQuery(document).ready(function() {
374  jQuery("#delconst").hide();
375 
376  jQuery(".checkboxfordelete").click(function() {
377  jQuery("#delconst").show();
378  });
379 
380  $("#checkall").click(function() {
381  $(".checkboxfordelete").prop('checked', true);
382  jQuery("#delconst").show();
383  });
384  $("#checknone").click(function() {
385  $(".checkboxfordelete").prop('checked', false);
386  jQuery("#delconst").hide();
387  });
388 
389 });
390 
391 </script>
392 
393  <?php
394 }
395 
396 $form = new Form($db);
397 $formfile = new FormFile($db);
398 $userstatic = new User($db);
399 
400 
401 // List
402 print load_fiche_titre($langs->trans("FTPArea"));
403 
404 print $langs->trans("FTPAreaDesc")."<br>";
405 
406 if (!function_exists('ftp_connect')) {
407  print $langs->trans("FTPFeatureNotSupportedByYourPHP");
408 } else {
409  if (!empty($ftp_server)) {
410  // Confirm remove file
411  if ($action == 'delete') {
412  print $form->formconfirm($_SERVER["PHP_SELF"].'?numero_ftp='.$numero_ftp.'&section='.urlencode(GETPOST('section')).'&file='.urlencode(GETPOST('file')), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', '', 1);
413  }
414 
415  // Confirmation de la suppression d'une ligne categorie
416  if ($action == 'delete_section') {
417  print $form->formconfirm($_SERVER["PHP_SELF"].'?numero_ftp='.$numero_ftp.'&section='.urlencode(GETPOST('section')).'&file='.urlencode(GETPOST('file')), $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection', $ecmdir->label), 'confirm_deletesection', '', '', 1);
418  }
419 
420  print $langs->trans("Server").': <b>'.$ftp_server.'</b><br>';
421  print $langs->trans("Port").': <b>'.$ftp_port.'</b> '.($ftp_passive ? "(Passive)" : "(Active)").'<br>';
422  print $langs->trans("User").': <b>'.$ftp_user.'</b><br>';
423  print $langs->trans("FTPs (FTP over SSH)").': <b>'.yn($conf->global->FTP_CONNECT_WITH_SSL).'</b><br>';
424  print $langs->trans("SFTP (FTP as a subsytem of SSH)").': <b>'.yn($conf->global->FTP_CONNECT_WITH_SFTP).'</b><br>';
425  print $langs->trans("Directory").': ';
426  $sectionarray = preg_split('|[\/]|', $section);
427  // For /
428  $newsection = '/';
429  print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual&numero_ftp='.$numero_ftp.($newsection ? '&section='.urlencode($newsection) : '').'">';
430  print '/';
431  print '</a> ';
432  // For other directories
433  $i = 0;
434  foreach ($sectionarray as $val) {
435  if (empty($val)) {
436  continue; // Discard first and last entry that should be empty as section start/end with /
437  }
438  if ($i > 0) {
439  print ' / ';
440  $newsection .= '/';
441  }
442  $newsection .= $val;
443  print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual&numero_ftp='.$numero_ftp.($newsection ? '&section='.urlencode($newsection) : '').'">';
444  print $val;
445  print '</a>';
446  $i++;
447  }
448  print '<br>';
449  print "<br>\n";
450 
451  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
452  print '<input type="hidden" name="numero_ftp" value="'.$numero_ftp.'">';
453  print '<input type="hidden" name="token" value="'.newToken().'">';
454 
455 
456  // Construit liste des repertoires
457  print '<table width="100%" class="noborder">'."\n";
458 
459  print '<tr class="liste_titre">'."\n";
460  print '<td class="liste_titre left">'.$langs->trans("Content").'</td>'."\n";
461  print '<td class="liste_titre center">'.$langs->trans("Size").'</td>'."\n";
462  print '<td class="liste_titre center">'.$langs->trans("Date").'</td>'."\n";
463  print '<td class="liste_titre center">'.$langs->trans("Owner").'</td>'."\n";
464  print '<td class="liste_titre center">'.$langs->trans("Group").'</td>'."\n";
465  print '<td class="liste_titre center">'.$langs->trans("Permissions").'</td>'."\n";
466  print '<td class="liste_titre nowrap right">';
467  if ($conf->use_javascript_ajax) {
468  print '<a href="#" id="checkall">'.$langs->trans("All").'</a> / <a href="#" id="checknone">'.$langs->trans("None").'</a> ';
469  }
470  print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual&numero_ftp='.$numero_ftp.($section ? '&section='.urlencode($section) : '').'">'.img_picto($langs->trans("Refresh"), 'refresh').'</a>&nbsp;';
471  print '</td>'."\n";
472  print '</tr>'."\n";
473 
474  // set up a connection or die
475  if (empty($conn_id)) {
476  $resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive);
477 
478  $conn_id = $resultarray['conn_id'];
479  $ok = $resultarray['ok'];
480  $mesg = $resultarray['mesg'];
481  }
482 
483  if ($ok) {
484  //$type = ftp_systype($conn_id);
485 
486  $newsection = $section;
487  $newsectioniso = utf8_decode($section);
488  //$newsection='/home';
489 
490  // List content of directory ($newsection = '/', '/home', ...)
491  if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
492  if ($newsection == '/') {
493  //$newsection = '/./';
494  $newsection = ssh2_sftp_realpath($conn_id, ".").'/./'; // workaround for bug https://bugs.php.net/bug.php?id=64169
495  }
496 
497  //$newsection='/';
498  //$dirHandle = opendir("ssh2.sftp://$conn_id".$newsection);
499  //$dirHandle = opendir("ssh2.sftp://".intval($conn_id).ssh2_sftp_realpath($conn_id, ".").'/./');
500 
501  $contents = scandir('ssh2.sftp://'.intval($conn_id).$newsection);
502  $buff = array();
503  foreach ($contents as $i => $key) {
504  $buff[$i] = "---------- - root root 1234 Aug 01 2000 ".$key;
505  }
506 
507  //$i = 0;
508  //$handle = opendir('ssh2.sftp://'.intval($conn_id).$newsection);
509  //$buff=array();
510  //while (false !== ($file = readdir($handle))) {
511  // if (substr("$file", 0, 1) != "."){
512  // if (is_dir($file)) {
513  // $buff[$i]="d--------- - root root 1234 Aug 01 2000 ".$file;
514  // } else {
515  // $buff[$i]="---------- - root root 1234 Aug 01 2000 ".$file;
516  // }
517  // }
518  // $i++;
519  //}
520  } else {
521  $buff = ftp_rawlist($conn_id, $newsectioniso);
522  $contents = ftp_nlist($conn_id, $newsectioniso); // Sometimes rawlist fails but never nlist
523  //var_dump($contents);
524  //var_dump($buff);
525  }
526 
527  $nboflines = count($contents);
528  $rawlisthasfailed = false;
529  $i = 0;
530  $nbofentries = 0;
531  while ($i < $nboflines && $i < 1000) {
532  $vals = preg_split('@ +@', utf8_encode($buff[$i]), 9);
533  //$vals=preg_split('@ +@','drwxr-xr-x 2 root root 4096 Aug 30 2008 backup_apollon1',9);
534  //var_dump($vals);
535  $file = $vals[8];
536  if (empty($file)) {
537  $rawlisthasfailed = true;
538  $file = utf8_encode($contents[$i]);
539  }
540 
541  if ($file == '.' || ($file == '..' && $section == '/')) {
542  $i++;
543  continue;
544  }
545 
546  // Is it a directory ?
547  $is_directory = 0;
548  $is_link = 0;
549  if ($file == '..') {
550  $is_directory = 1;
551  } elseif (!$rawlisthasfailed) {
552  if (preg_match('/^d/', $vals[0])) {
553  $is_directory = 1;
554  }
555  if (preg_match('/^l/', $vals[0])) {
556  $is_link = 1;
557  }
558  } else {
559  // Remote file
560  $filename = $file;
561  //print "section=".$section.' file='.$file.'X';
562  //print preg_match('@[\/]$@','aaa/').'Y';
563  //print preg_match('@[\\\/]$@',"aaa\\").'Y';
564  $remotefile = $section.(preg_match('@[\\\/]$@', $section) ? '' : '/').preg_replace('@^[\\\/]@', '', $file);
565  //print 'A'.$remotefile.'A';
566  $newremotefileiso = utf8_decode($remotefile);
567  //print 'Z'.$newremotefileiso.'Z';
568  $is_directory = ftp_isdir($conn_id, $newremotefileiso);
569  }
570 
571 
572  print '<tr class="oddeven" height="18">';
573  // Name
574  print '<td>';
575  $newsection = $section.(preg_match('@[\\\/]$@', $section) ? '' : '/').$file;
576  $newsection = preg_replace('@[\\\/][^\\\/]+[\\\/]\.\.$@', '/', $newsection); // Change aaa/xxx/.. to new aaa
577  if ($is_directory) {
578  print '<a href="'.$_SERVER["PHP_SELF"].'?section='.urlencode($newsection).'&numero_ftp='.$numero_ftp.'">';
579  }
580  print dol_escape_htmltag($file);
581  if ($is_directory) {
582  print '</a>';
583  }
584  print '</td>';
585  // Size
586  print '<td class="center nowrap">';
587  if (!$is_directory && !$is_link) {
588  print $vals[4];
589  } else {
590  print '&nbsp;';
591  }
592  print '</td>';
593  // Date
594  print '<td class="center nowrap">';
595  print $vals[5].' '.$vals[6].' '.$vals[7];
596  print '</td>';
597  // User
598  print '<td class="center nowrap">';
599  print $vals[2];
600  print '</td>';
601  // Group
602  print '<td class="center nowrap">';
603  print $vals[3];
604  print '</td>';
605  // Permissions
606  print '<td class="center nowrap">';
607  print $vals[0];
608  print '</td>';
609  // Action
610  print '<td class="right nowrap" width="64">';
611  if ($is_directory) {
612  if ($file != '..') {
613  print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete_section&token='.newToken().'&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($file).'">'.img_delete().'</a>';
614  } else {
615  print '&nbsp;';
616  }
617  } elseif ($is_link) {
618  $newfile = $file;
619  $newfile = preg_replace('/ ->.*/', '', $newfile);
620  print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($newfile).'">'.img_delete().'</a>';
621  } else {
622  print '<a href="'.$_SERVER["PHP_SELF"].'?action=download&token='.newToken().'&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($file).'">'.img_picto('', 'file').'</a>';
623  print ' &nbsp; ';
624  print '<input type="checkbox" class="flat checkboxfordelete" id="check_'.$i.'" name="const['.$i.'][check]" value="1">';
625  print ' &nbsp; ';
626  print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($file).'">'.img_delete().'</a>';
627  print '<input type="hidden" name="const['.$i.'][section]" value="'.$section.'">';
628  print '<input type="hidden" name="const['.$i.'][file]" value="'.$file.'">';
629  }
630  print '</td>';
631  print '</tr>'."\n";
632  $i++;
633  $nbofentries++;
634  }
635  }
636 
637  print "</table>";
638 
639 
640  if (!$ok) {
641  print $mesg.'<br>'."\n";
642  setEventMessages($mesg, null, 'errors');
643  }
644 
645 
646  // Actions
647  /*
648  if ($user->rights->ftp->write && ! empty($section))
649  {
650  $formfile->form_attach_new_file(DOL_URL_ROOT.'/ftp/index.php','',0,$section,1);
651  }
652  else print '&nbsp;';
653  */
654 
655  print '<br>';
656  print '<div id="delconst" class="right">';
657  print '<input type="submit" name="delete" class="button" value="'.$langs->trans("Delete").'">';
658  print '</div>';
659 
660  print "</form>";
661  } else {
662  $foundsetup = false;
663  $MAXFTP = 20;
664  $i = 1;
665  while ($i <= $MAXFTP) {
666  $paramkey = 'FTP_NAME_'.$i;
667  //print $paramkey;
668  if (!empty($conf->global->$paramkey)) {
669  $foundsetup = true;
670  break;
671  }
672  $i++;
673  }
674  if (!$foundsetup) {
675  print $langs->trans("SetupOfFTPClientModuleNotComplete");
676  } else {
677  print $langs->trans("ChooseAFTPEntryIntoMenu");
678  }
679  }
680 }
681 
682 print '<br>';
683 
684 // Close FTP connection
685 if ($conn_id) {
686  if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
687  } elseif (!empty($conf->global->FTP_CONNECT_WITH_SSL)) {
688  ftp_close($conn_id);
689  } else {
690  ftp_close($conn_id);
691  }
692 }
693 
694 // End of page
695 llxFooter();
696 $db->close();
697 
698 
699 
711 function dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive = 0)
712 {
713  global $langs, $conf;
714 
715  $ok = 1;
716  $error = 0;
717  $conn_id = null;
718  $newsectioniso = '';
719  $mesg="";
720 
721  if (!is_numeric($ftp_port)) {
722  $mesg = $langs->transnoentitiesnoconv("FailedToConnectToFTPServer", $ftp_server, $ftp_port);
723  $ok = 0;
724  }
725 
726  if ($ok) {
727  $connecttimeout = (empty($conf->global->FTP_CONNECT_TIMEOUT) ? 40 : $conf->global->FTP_CONNECT_TIMEOUT);
728  if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
729  dol_syslog('Try to connect with ssh2_connect');
730  $tmp_conn_id = ssh2_connect($ftp_server, $ftp_port);
731  } elseif (!empty($conf->global->FTP_CONNECT_WITH_SSL)) {
732  dol_syslog('Try to connect with ftp_ssl_connect');
733  $conn_id = ftp_ssl_connect($ftp_server, $ftp_port, $connecttimeout);
734  } else {
735  dol_syslog('Try to connect with ftp_connect');
736  $conn_id = ftp_connect($ftp_server, $ftp_port, $connecttimeout);
737  }
738  if (!empty($conn_id) || !empty($tmp_conn_id)) {
739  if ($ftp_user) {
740  if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
741  dol_syslog('Try to authenticate with ssh2_auth_password');
742  if (ssh2_auth_password($tmp_conn_id, $ftp_user, $ftp_password)) {
743  // Turn on passive mode transfers (must be after a successful login
744  //if ($ftp_passive) ftp_pasv($conn_id, true);
745 
746  // Change the dir
747  $newsectioniso = utf8_decode($section);
748  //ftp_chdir($conn_id, $newsectioniso);
749  $conn_id = ssh2_sftp($tmp_conn_id);
750  if (!$conn_id) {
751  dol_syslog('Failed to connect to SFTP after sssh authentication', LOG_DEBUG);
752  $mesg = $langs->transnoentitiesnoconv("FailedToConnectToSFTPAfterSSHAuthentication");
753  $ok = 0;
754  $error++;
755  }
756  } else {
757  dol_syslog('Failed to connect to FTP with login '.$ftp_user, LOG_DEBUG);
758  $mesg = $langs->transnoentitiesnoconv("FailedToConnectToFTPServerWithCredentials");
759  $ok = 0;
760  $error++;
761  }
762  } else {
763  if (ftp_login($conn_id, $ftp_user, $ftp_password)) {
764  // Turn on passive mode transfers (must be after a successful login
765  if ($ftp_passive) {
766  ftp_pasv($conn_id, true);
767  }
768 
769  // Change the dir
770  $newsectioniso = utf8_decode($section);
771  ftp_chdir($conn_id, $newsectioniso);
772  } else {
773  $mesg = $langs->transnoentitiesnoconv("FailedToConnectToFTPServerWithCredentials");
774  $ok = 0;
775  $error++;
776  }
777  }
778  }
779  } else {
780  dol_syslog('FailedToConnectToFTPServer '.$ftp_server.' '.$ftp_port, LOG_ERR);
781  $mesg = $langs->transnoentitiesnoconv("FailedToConnectToFTPServer", $ftp_server, $ftp_port);
782  $ok = 0;
783  }
784  }
785 
786  $arrayresult = array('conn_id'=>$conn_id, 'ok'=>$ok, 'mesg'=>$mesg, 'curdir'=>$section, 'curdiriso'=>$newsectioniso);
787  return $arrayresult;
788 }
789 
790 
798 function ftp_isdir($connect_id, $dir)
799 {
800  if (@ftp_chdir($connect_id, $dir)) {
801  ftp_cdup($connect_id);
802  return 1;
803  } else {
804  return 0;
805  }
806 }
807 
yn
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
Definition: functions.lib.php:6491
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
ftp_isdir
ftp_isdir($connect_id, $dir)
Tell if an entry is a FTP directory.
Definition: index.php:798
dol_mimetype
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
Definition: functions.lib.php:9741
dol_ftp_connect
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive=0)
Connect to FTP server.
Definition: index.php:711
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
dol_unescapefile
dol_unescapefile($filename)
Unescape a file submitted by upload.
Definition: files.lib.php:1038
llxFooter
llxFooter()
Footer empty.
Definition: index.php:71
img_delete
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
Definition: functions.lib.php:4429
dol_move_uploaded_file
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $varfiles='addedfile', $upload_dir='')
Make control on an uploaded file from an GUI page and move it to final destination.
Definition: files.lib.php:1092
FormFile
Class to offer components to list and upload files.
Definition: html.formfile.class.php:36
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
llxHeader
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
Definition: index.php:63
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:80
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
User
Class to manage Dolibarr users.
Definition: user.class.php:44
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6603
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119