dolibarr  7.0.0-beta
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@capnetworks.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
25 require('../main.inc.php');
26 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php';
29 
30 // Load traductions files
31 $langs->load("ftp");
32 $langs->load("companies");
33 $langs->load("other");
34 
35 // Security check
36 if ($user->societe_id) $socid=$user->societe_id;
37 $result = restrictedArea($user, 'ftp','');
38 
39 // Get parameters
40 $action=GETPOST('action','aZ09');
41 $section=GETPOST('section');
42 if (! $section) $section='/';
43 $numero_ftp = GETPOST("numero_ftp");
44 /* if (! $numero_ftp) $numero_ftp=1; */
45 $file=GETPOST("file");
46 $confirm=GETPOST('confirm');
47 
48 $upload_dir = $conf->ftp->dir_temp;
49 $download_dir = $conf->ftp->dir_temp;
50 
51 $sortfield = GETPOST("sortfield",'alpha');
52 $sortorder = GETPOST("sortorder",'alpha');
53 $page = GETPOST("page",'int');
54 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
55 $offset = $conf->liste_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($_REQUEST["section"]);
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  }
106  else {
107  $langs->load("errors");
108  if ($resupload < 0) // Unknown error
109  {
110  setEventMessages($langs->trans("ErrorFileNotUploaded"), null, 'errors');
111  }
112  else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
113  {
114  setEventMessages($langs->trans("ErrorFileIsInfectedWithAVirus"), null, 'errors');
115  }
116  else // Known error
117  {
118  setEventMessages($langs->trans($resupload), null, 'errors');
119  }
120  }
121  }
122  else
123  {
124  // Echec transfert (fichier depassant la limite ?)
125  $langs->load("errors");
126  setEventMessages($langs->trans("ErrorFailToCreateDir",$upload_dir), null, 'errors');
127  }
128 }
129 
130 // Action ajout d'un rep
131 if ($action == 'add' && $user->rights->ftp->setup)
132 {
133  $ecmdir->ref = $_POST["ref"];
134  $ecmdir->label = $_POST["label"];
135  $ecmdir->description = $_POST["desc"];
136 
137  $id = $ecmdir->create($user);
138  if ($id > 0)
139  {
140  header("Location: ".$_SERVER["PHP_SELF"]);
141  exit;
142  }
143  else
144  {
145  setEventMessages($langs->trans("ErrorFailToCreateDir"), null, 'errors');
146  $action = "create";
147  }
148 }
149 
150 // Remove file
151 if ($action == 'confirm_deletefile' && $_REQUEST['confirm'] == 'yes')
152 {
153  // set up a connection or die
154  if (! $conn_id)
155  {
156  $newsectioniso=utf8_decode($section);
157  $resultarray=dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
158  $conn_id=$resultarray['conn_id'];
159  $ok=$resultarray['ok'];
160  $mesg=$resultarray['mesg'];
161  }
162 
163  if ($conn_id && $ok && ! $mesg)
164  {
165  $langs->load("other");
166 
167  // Remote file
168  $filename=$file;
169  $remotefile=$section.(preg_match('@[\\\/]$@',$section)?'':'/').$file;
170  $newremotefileiso=utf8_decode($remotefile);
171 
172  //print "x".$newremotefileiso;
173  dol_syslog("ftp/index.php ftp_delete ".$newremotefileiso);
174  $result=@ftp_delete($conn_id, $newremotefileiso);
175  if ($result)
176  {
177  setEventMessages($langs->trans("FileWasRemoved",$file), null, 'mesgs');
178  }
179  else
180  {
181  dol_syslog("ftp/index.php ftp_delete", LOG_ERR);
182  setEventMessages($langs->trans("FTPFailedToRemoveFile",$file), null, 'errors');
183  }
184 
185  //ftp_close($conn_id); Close later
186 
187  $action='';
188  }
189  else
190  {
191  dol_print_error('',$mesg);
192  }
193 }
194 
195 // Delete several lines at once
196 if ($_POST["const"] && $_POST["delete"] && $_POST["delete"] == $langs->trans("Delete"))
197 {
198  // set up a connection or die
199  if (! $conn_id)
200  {
201  $newsectioniso=utf8_decode($section);
202  $resultarray=dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
203  $conn_id=$resultarray['conn_id'];
204  $ok=$resultarray['ok'];
205  $mesg=$resultarray['mesg'];
206  }
207 
208  if ($conn_id && $ok && ! $mesg)
209  {
210  foreach($_POST["const"] as $const)
211  {
212  if ($const["check"]) // Is checkbox checked
213  {
214  $langs->load("other");
215 
216  // Remote file
217  $file=$const["file"];
218  $section=$const["section"];
219  $remotefile=$section.(preg_match('@[\\\/]$@',$section)?'':'/').$file;
220  $newremotefileiso=utf8_decode($remotefile);
221 
222  //print "x".$newremotefileiso;
223  dol_syslog("ftp/index.php ftp_delete ".$newremotefileiso);
224  $result=@ftp_delete($conn_id, $newremotefileiso);
225  if ($result)
226  {
227  setEventMessages($langs->trans("FileWasRemoved",$file), null, 'mesgs');
228  }
229  else
230  {
231  dol_syslog("ftp/index.php ftp_delete", 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 
241  }
242  else
243  {
244  dol_print_error('',$mesg);
245  }
246 }
247 
248 // Remove directory
249 if ($action == 'confirm_deletesection' && $confirm == 'yes')
250 {
251  // set up a connection or die
252  if (! $conn_id)
253  {
254  $newsectioniso=utf8_decode($section);
255  $resultarray=dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
256  $conn_id=$resultarray['conn_id'];
257  $ok=$resultarray['ok'];
258  $mesg=$resultarray['mesg'];
259  }
260 
261  if ($conn_id && $ok && ! $mesg)
262  {
263  // Remote file
264  $filename=$file;
265  $remotefile=$section.(preg_match('@[\\\/]$@',$section)?'':'/').$file;
266  $newremotefileiso=utf8_decode($remotefile);
267 
268  $result=@ftp_rmdir($conn_id, $newremotefileiso);
269  if ($result)
270  {
271  setEventMessages($langs->trans("DirWasRemoved",$file), null, 'mesgs');
272  }
273  else
274  {
275  setEventMessages($langs->trans("FTPFailedToRemoveDir",$file), null, 'errors');
276  }
277 
278  //ftp_close($conn_id); Close later
279 
280  $action='';
281  }
282  else
283  {
284  dol_print_error('',$mesg);
285  }
286 }
287 
288 // Download directory
289 if ($action == 'download')
290 {
291  // set up a connection or die
292  if (! $conn_id)
293  {
294  $newsectioniso=utf8_decode($section);
295  $resultarray=dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
296  $conn_id=$resultarray['conn_id'];
297  $ok=$resultarray['ok'];
298  $mesg=$resultarray['mesg'];
299  }
300 
301  if ($conn_id && $ok && ! $mesg)
302  {
303  // Local file
304  $localfile=tempnam($download_dir,'dol_');
305 
306  // Remote file
307  $filename=$file;
308  $remotefile=$section.(preg_match('@[\\\/]$@',$section)?'':'/').$file;
309  $newremotefileiso=utf8_decode($remotefile);
310 
311  $result=ftp_get($conn_id,$localfile,$newremotefileiso,FTP_BINARY);
312  if ($result)
313  {
314  if (! empty($conf->global->MAIN_UMASK))
315  @chmod($localfile, octdec($conf->global->MAIN_UMASK));
316 
317  // Define mime type
318  $type = 'application/octet-stream';
319  if (! empty($_GET["type"])) $type=$_GET["type"];
320  else $type=dol_mimetype($original_file);
321 
322  // Define attachment (attachment=true to force choice popup 'open'/'save as')
323  $attachment = true;
324 
325  if ($encoding) header('Content-Encoding: '.$encoding);
326  if ($type) header('Content-Type: '.$type);
327  if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"');
328  else header('Content-Disposition: inline; filename="'.$filename.'"');
329 
330  // Ajout directives pour resoudre bug IE
331  header('Cache-Control: Public, must-revalidate');
332  header('Pragma: public');
333 
334  readfile($localfile);
335 
336  ftp_close($conn_id);
337 
338  exit;
339  }
340  else
341  {
342  setEventMessages($langs->transnoentitiesnoconv('FailedToGetFile',$remotefile), null, 'errors');
343  }
344 
345  }
346  else
347  {
348  dol_print_error('',$mesg);
349  }
350 
351  //ftp_close($conn_id); Close later
352 }
353 
354 
355 
356 
357 /*
358  * View
359  */
360 
361 llxHeader();
362 
363 // Add logic to shoow/hide buttons
364 if ($conf->use_javascript_ajax)
365 {
366 ?>
367 <script type="text/javascript">
368 jQuery(document).ready(function() {
369  jQuery("#delconst").hide();
370 
371  jQuery(".checkboxfordelete").click(function() {
372  jQuery("#delconst").show();
373  });
374 
375  $("#checkall").click(function() {
376  $(".checkboxfordelete").prop('checked', true);
377  jQuery("#delconst").show();
378  });
379  $("#checknone").click(function() {
380  $(".checkboxfordelete").prop('checked', false);
381  jQuery("#delconst").hide();
382  });
383 
384 });
385 
386 </script>
387 
388 <?php
389 }
390 
391 $form=new Form($db);
392 $formfile=new FormFile($db);
393 $userstatic = new User($db);
394 
395 
396 // List
397 print load_fiche_titre($langs->trans("FTPArea"));
398 
399 print $langs->trans("FTPAreaDesc")."<br>";
400 
401 if (! function_exists('ftp_connect'))
402 {
403  print $langs->trans("FTPFeatureNotSupportedByYourPHP");
404 }
405 else
406 {
407  if (! empty($ftp_server))
408  {
409  // Confirm remove file
410  if ($action == 'delete')
411  {
412  print $form->formconfirm($_SERVER["PHP_SELF"].'?numero_ftp='.$numero_ftp.'&section='.urlencode($_REQUEST["section"]).'&file='.urlencode($_GET["file"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile','','',1);
413 
414  }
415 
416  // Confirmation de la suppression d'une ligne categorie
417  if ($action == 'delete_section')
418  {
419  print $form->formconfirm($_SERVER["PHP_SELF"].'?numero_ftp='.$numero_ftp.'&section='.urlencode($_REQUEST["section"]).'&file='.urlencode($_GET["file"]), $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection',$ecmdir->label), 'confirm_deletesection','','',1);
420  }
421 
422  print $langs->trans("Server").': <b>'.$ftp_server.'</b><br>';
423  print $langs->trans("Port").': <b>'.$ftp_port.'</b> '.($ftp_passive?"(Passive)":"(Active)").'<br>';
424  print $langs->trans("User").': <b>'.$ftp_user.'</b><br>';
425  print $langs->trans("FTPs (FTP over SSH)").': <b>'.yn($conf->global->FTP_CONNECT_WITH_SSL).'</b><br>';
426  print $langs->trans("SFTP (FTP as a subsytem of SSH)").': <b>'.yn($conf->global->FTP_CONNECT_WITH_SFTP).'</b><br>';
427  print $langs->trans("Directory").': ';
428  $sectionarray=preg_split('|[\/]|',$section);
429  // For /
430  $newsection='/';
431  print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual&numero_ftp='.$numero_ftp.($newsection?'&section='.urlencode($newsection):'').'">';
432  print '/';
433  print '</a> ';
434  // For other directories
435  $i=0;
436  foreach($sectionarray as $val)
437  {
438  if (empty($val)) continue; // Discard first and last entry that should be empty as section start/end with /
439  if ($i > 0)
440  {
441  print ' / ';
442  $newsection.='/';
443  }
444  $newsection.=$val;
445  print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual&numero_ftp='.$numero_ftp.($newsection?'&section='.urlencode($newsection):'').'">';
446  print $val;
447  print '</a>';
448  $i++;
449  }
450  print '<br>';
451  print "<br>\n";
452 
453  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
454  print '<input type="hidden" name="numero_ftp" value="'.$numero_ftp.'">';
455  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
456 
457 
458  // Construit liste des repertoires
459  print '<table width="100%" class="noborder">'."\n";
460 
461  print '<tr class="liste_titre">'."\n";
462  print '<td class="liste_titre" align="left">'.$langs->trans("Content").'</td>'."\n";
463  print '<td class="liste_titre" align="center">'.$langs->trans("Size").'</td>'."\n";
464  print '<td class="liste_titre" align="center">'.$langs->trans("Date").'</td>'."\n";
465  print '<td class="liste_titre" align="center">'.$langs->trans("Owner").'</td>'."\n";
466  print '<td class="liste_titre" align="center">'.$langs->trans("Group").'</td>'."\n";
467  print '<td class="liste_titre" align="center">'.$langs->trans("Permissions").'</td>'."\n";
468  print '<td class="liste_titre nowrap" align="right">';
469  if ($conf->use_javascript_ajax) print '<a href="#" id="checkall">'.$langs->trans("All").'</a> / <a href="#" id="checknone">'.$langs->trans("None").'</a> ';
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  {
477  $resultarray=dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive);
478 
479  $conn_id=$resultarray['conn_id'];
480  $ok=$resultarray['ok'];
481  $mesg=$resultarray['mesg'];
482  }
483 
484  if ($ok)
485  {
486  //$type = ftp_systype($conn_id);
487 
488  $newsection=$section;
489  $newsectioniso=utf8_decode($section);
490  //$newsection='/home';
491 
492  // List content of directory ($newsection = '/', '/home', ...)
493  if (! empty($conf->global->FTP_CONNECT_WITH_SFTP))
494  {
495  if ($newsection == '/') $newsection='/./'; // workaround for bug https://bugs.php.net/bug.php?id=64169
496  //$dirHandle = opendir("ssh2.sftp://$conn_id".$newsection);
497  //var_dump($dirHandle);
498  $contents = scandir('ssh2.sftp://' . $conn_id . $newsection);
499  $buff=array();
500  foreach($contents as $i => $key)
501  {
502  $buff[$i]="---------- - root root 1234 Aug 01 2000 ".$key;
503  }
504  }
505  else
506  {
507  $buff = ftp_rawlist($conn_id, $newsectioniso);
508  $contents = ftp_nlist($conn_id, $newsectioniso); // Sometimes rawlist fails but never nlist
509  //var_dump($contents);
510  //var_dump($buff);
511  }
512 
513  $nboflines=count($contents);
514  $var=true;
515  $rawlisthasfailed=false;
516  $i=0;
517  while ($i < $nboflines && $i < 1000)
518  {
519  $vals=preg_split('@ +@',utf8_encode($buff[$i]),9);
520  //$vals=preg_split('@ +@','drwxr-xr-x 2 root root 4096 Aug 30 2008 backup_apollon1',9);
521  //var_dump($vals);
522  $file=$vals[8];
523  if (empty($file))
524  {
525  $rawlisthasfailed=true;
526  $file=utf8_encode($contents[$i]);
527  }
528 
529  if ($file == '.' || ($file == '..' && $section == '/'))
530  {
531  $i++;
532  continue;
533  }
534 
535  // Is it a directory ?
536  $is_directory=0;
537  if ($file == '..') $is_directory=1;
538  else if (! $rawlisthasfailed)
539  {
540  if (preg_match('/^d/',$vals[0])) $is_directory=1;
541  if (preg_match('/^l/',$vals[0])) $is_link=1;
542  }
543  else
544  {
545  // Remote file
546  $filename=$file;
547  //print "section=".$section.' file='.$file.'X';
548  //print preg_match('@[\/]$@','aaa/').'Y';
549  //print preg_match('@[\\\/]$@',"aaa\\").'Y';
550  $remotefile=$section.(preg_match('@[\\\/]$@',$section)?'':'/').preg_replace('@^[\\\/]@','',$file);
551  //print 'A'.$remotefile.'A';
552  $newremotefileiso=utf8_decode($remotefile);
553  //print 'Z'.$newremotefileiso.'Z';
554  $is_directory=ftp_isdir($conn_id, $newremotefileiso);
555  }
556 
557 
558  print '<tr '.$bc[$var].' height="18">';
559  // Name
560  print '<td>';
561  $newsection=$section.(preg_match('@[\\\/]$@',$section)?'':'/').$file;
562  $newsection=preg_replace('@[\\\/][^\\\/]+[\\\/]\.\.$@','/',$newsection); // Change aaa/xxx/.. to new aaa
563  if ($is_directory) print '<a href="'.$_SERVER["PHP_SELF"].'?section='.urlencode($newsection).'&numero_ftp='.$numero_ftp.'">';
564  print $file;
565  if ($is_directory) print '</a>';
566  print '</td>';
567  // Size
568  print '<td align="center" class="nowrap">';
569  if (! $is_directory && ! $is_link) print $vals[4];
570  else print '&nbsp;';
571  print '</td>';
572  // Date
573  print '<td align="center" class="nowrap">';
574  print $vals[5].' '.$vals[6].' '.$vals[7];
575  print '</td>';
576  // User
577  print '<td align="center" class="nowrap">';
578  print $vals[2];
579  print '</td>';
580  // Group
581  print '<td align="center" class="nowrap">';
582  print $vals[3];
583  print '</td>';
584  // Permissions
585  print '<td align="center" class="nowrap">';
586  print $vals[0];
587  print '</td>';
588  // Action
589  print '<td align="right" width="64" class="nowrap">';
590  if ($is_directory)
591  {
592  if ($file != '..') print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete_section&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($file).'">'.img_delete().'</a>';
593  else print '&nbsp;';
594  }
595  else if ($is_link)
596  {
597  $newfile=$file;
598  $newfile=preg_replace('/ ->.*/','',$newfile);
599  print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($newfile).'">'.img_delete().'</a>';
600  }
601  else
602  {
603  print '<a href="'.$_SERVER["PHP_SELF"].'?action=download&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($file).'">'.img_picto('','file').'</a>';
604  print ' &nbsp; ';
605  print '<input type="checkbox" class="flat checkboxfordelete" id="check_'.$i.'" name="const['.$i.'][check]" value="1">';
606  print ' &nbsp; ';
607  print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($file).'">'.img_delete().'</a>';
608  print '<input type="hidden" name="const['.$i.'][section]" value="'.$section.'">';
609  print '<input type="hidden" name="const['.$i.'][file]" value="'.$file.'">';
610  }
611  print '</td>';
612  print '</tr>'."\n";
613  $i++;
614  $nbofentries++;
615  }
616 
617  }
618 
619  print "</table>";
620 
621 
622  if (! $ok)
623  {
624  print $mesg.'<br>'."\n";
625  setEventMessages($mesg, null, 'errors');
626  }
627 
628 
629  // Actions
630  /*
631  if ($user->rights->ftp->write && ! empty($section))
632  {
633  $formfile->form_attach_new_file(DOL_URL_ROOT.'/ftp/index.php','',0,$section,1);
634  }
635  else print '&nbsp;';
636  */
637 
638  print '<br>';
639  print '<div id="delconst" align="right">';
640  print '<input type="submit" name="delete" class="button" value="'.$langs->trans("Delete").'">';
641  print '</div>';
642 
643  print "</form>";
644  }
645  else
646  {
647  $foundsetup=false;
648  $MAXFTP=20;
649  $i=1;
650  while ($i <= $MAXFTP)
651  {
652  $paramkey='FTP_NAME_'.$i;
653  //print $paramkey;
654  if (! empty($conf->global->$paramkey))
655  {
656  $foundsetup=true;
657  break;
658  }
659  $i++;
660  }
661  if (! $foundsetup)
662  {
663  print $langs->trans("SetupOfFTPClientModuleNotComplete");
664  }
665  else
666  {
667  print $langs->trans("ChooseAFTPEntryIntoMenu");
668  }
669  }
670 }
671 
672 print '<br>';
673 
674 // Close FTP connection
675 if ($conn_id)
676 {
677  if (! empty($conf->global->FTP_CONNECT_WITH_SFTP))
678  {
679 
680  }
681  else if (! empty($conf->global->FTP_CONNECT_WITH_SSL))
682  {
683  ftp_close($conn_id);
684  }
685  else
686  {
687  ftp_close($conn_id);
688  }
689 }
690 
691 
692 llxFooter();
693 
694 $db->close();
695 
696 
697 
709 function dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive=0)
710 {
711  global $langs, $conf;
712 
713  $ok=1;
714  $conn_id=null;
715 
716  if (! is_numeric($ftp_port))
717  {
718  $mesg=$langs->transnoentitiesnoconv("FailedToConnectToFTPServer",$ftp_server,$ftp_port);
719  $ok=0;
720  }
721 
722  if ($ok)
723  {
724  $connecttimeout=(empty($conf->global->FTP_CONNECT_TIMEOUT)?40:$conf->global->FTP_CONNECT_TIMEOUT);
725  if (! empty($conf->global->FTP_CONNECT_WITH_SFTP))
726  {
727  dol_syslog('Try to connect with ssh2_ftp');
728  $tmp_conn_id = ssh2_connect($ftp_server, $ftp_port);
729  }
730  else if (! empty($conf->global->FTP_CONNECT_WITH_SSL))
731  {
732  dol_syslog('Try to connect with ftp_ssl_connect');
733  $conn_id = ftp_ssl_connect($ftp_server, $ftp_port, $connecttimeout);
734  }
735  else
736  {
737  dol_syslog('Try to connect with ftp_connect');
738  $conn_id = ftp_connect($ftp_server, $ftp_port, $connecttimeout);
739  }
740  if ($conn_id || $tmp_conn_id)
741  {
742  if ($ftp_user)
743  {
744  if (! empty($conf->global->FTP_CONNECT_WITH_SFTP))
745  {
746  if (ssh2_auth_password($tmp_conn_id, $ftp_user, $ftp_password))
747  {
748  // Turn on passive mode transfers (must be after a successful login
749  //if ($ftp_passive) ftp_pasv($conn_id, true);
750 
751  // Change the dir
752  $newsectioniso=utf8_decode($section);
753  //ftp_chdir($conn_id, $newsectioniso);
754  $conn_id = ssh2_sftp($tmp_conn_id);
755  if (! $conn_id)
756  {
757  $mesg=$langs->transnoentitiesnoconv("FailedToConnectToSFTPAfterSSHAuthentication");
758  $ok=0;
759  $error++;
760  }
761  }
762  else
763  {
764  $mesg=$langs->transnoentitiesnoconv("FailedToConnectToFTPServerWithCredentials");
765  $ok=0;
766  $error++;
767  }
768  }
769  else
770  {
771  if (ftp_login($conn_id, $ftp_user, $ftp_password))
772  {
773  // Turn on passive mode transfers (must be after a successful login
774  if ($ftp_passive) ftp_pasv($conn_id, true);
775 
776  // Change the dir
777  $newsectioniso=utf8_decode($section);
778  ftp_chdir($conn_id, $newsectioniso);
779  }
780  else
781  {
782  $mesg=$langs->transnoentitiesnoconv("FailedToConnectToFTPServerWithCredentials");
783  $ok=0;
784  $error++;
785  }
786  }
787  }
788  }
789  else
790  {
791  dol_syslog('FailedToConnectToFTPServer '.$ftp_server.' '.$ftp_port, LOG_ERR);
792  $mesg=$langs->transnoentitiesnoconv("FailedToConnectToFTPServer",$ftp_server,$ftp_port);
793  $ok=0;
794  }
795  }
796 
797  $arrayresult=array('conn_id'=>$conn_id, 'ok'=>$ok, 'mesg'=>$mesg, 'curdir'=>$section, 'curdiriso'=>$newsectioniso);
798  return $arrayresult;
799 }
800 
801 
809 function ftp_isdir($connect_id,$dir)
810 {
811  if (@ftp_chdir($connect_id,$dir))
812  {
813  ftp_cdup($connect_id);
814  return 1;
815 
816  }
817  else
818  {
819  return 0;
820  }
821 }
822 
llxFooter()
Footer empty.
Definition: index.php:43
dol_unescapefile($filename)
Unescape a file submitted by upload.
Definition: files.lib.php:908
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it's its name (generic function)
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $varfiles='addedfile')
Make control on an uploaded file from an GUI page and move it to final destination.
Definition: files.lib.php:962
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return mime type of a file.
Class to manage Dolibarr users.
Definition: user.class.php:39
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
ftp_isdir($connect_id, $dir)
Tell if an entry is a FTP directory.
Definition: index.php:809
Class to manage generation of HTML components Only common components must be here.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
llxHeader()
Header empty.
Definition: index.php:37
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive=0)
Connect to FTP server.
Definition: index.php:709
img_delete($titlealt= 'default', $other= 'class="pictodelete"')
Show delete logo.
Class to offer components to list and upload files.
print
Draft customers invoices.
Definition: index.php:91
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
type
Definition: viewcat.php:283
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.