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