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