PageRenderTime 61ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/ftp/index.php

https://bitbucket.org/speedealing/speedealing
PHP | 711 lines | 489 code | 101 blank | 121 comment | 115 complexity | f92452667ec8c822f377919d5cdc6e98 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2008-2009 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. /**
  19. * \file htdocs/ftp/index.php
  20. * \ingroup ftp
  21. * \brief Main page for FTP section area
  22. * \author Laurent Destailleur
  23. */
  24. require 'pre.inc.php'; // We use pre.inc.php to have a dynamic menu
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php';
  28. // Load traductions files
  29. $langs->load("ftp");
  30. $langs->load("companies");
  31. $langs->load("other");
  32. // Security check
  33. if ($user->societe_id) $socid=$user->societe_id;
  34. $result = restrictedArea($user, 'ftp','');
  35. // Get parameters
  36. $action = isset($_GET["action"])?$_GET["action"]:$_POST['action'];
  37. $section=isset($_GET["section"])?$_GET["section"]:$_POST['section'];
  38. if (! $section) $section='/';
  39. $numero_ftp = GETPOST("numero_ftp");
  40. if (! $numero_ftp) $numero_ftp=1;
  41. $file=isset($_GET["file"])?$_GET["file"]:$_POST['file'];
  42. $upload_dir = $conf->ftp->dir_temp;
  43. $download_dir = $conf->ftp->dir_temp;
  44. $sortfield = GETPOST("sortfield",'alpha');
  45. $sortorder = GETPOST("sortorder",'alpha');
  46. $page = GETPOST("page",'int');
  47. if ($page == -1) { $page = 0; }
  48. $offset = $conf->liste_limit * $page;
  49. $pageprev = $page - 1;
  50. $pagenext = $page + 1;
  51. if (! $sortorder) $sortorder="ASC";
  52. if (! $sortfield) $sortfield="label";
  53. $s_ftp_name='FTP_NAME_'.$numero_ftp;
  54. $s_ftp_server='FTP_SERVER_'.$numero_ftp;
  55. $s_ftp_port='FTP_PORT_'.$numero_ftp;
  56. $s_ftp_user='FTP_USER_'.$numero_ftp;
  57. $s_ftp_password='FTP_PASSWORD_'.$numero_ftp;
  58. $ftp_name=$conf->global->$s_ftp_name;
  59. $ftp_server=$conf->global->$s_ftp_server;
  60. $ftp_port=$conf->global->$s_ftp_port; if (empty($ftp_port)) $ftp_port=21;
  61. $ftp_user=$conf->global->$s_ftp_user;
  62. $ftp_password=$conf->global->$s_ftp_password;
  63. $conn_id=0; // FTP connection ID
  64. /*******************************************************************
  65. * ACTIONS
  66. *
  67. * Put here all code to do according to value of "action" parameter
  68. ********************************************************************/
  69. // Envoie fichier
  70. if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
  71. {
  72. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  73. $result=$ecmdir->fetch($_REQUEST["section"]);
  74. if (! $result > 0)
  75. {
  76. dol_print_error($db,$ecmdir->error);
  77. exit;
  78. }
  79. $relativepath=$ecmdir->getRelativePath();
  80. $upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
  81. if (dol_mkdir($upload_dir) >= 0)
  82. {
  83. $resupload = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . dol_unescapefile($_FILES['userfile']['name']),0);
  84. if (is_numeric($resupload) && $resupload > 0)
  85. {
  86. //$mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
  87. //print_r($_FILES);
  88. $result=$ecmdir->changeNbOfFiles('+');
  89. }
  90. else {
  91. $langs->load("errors");
  92. if ($resupload < 0) // Unknown error
  93. {
  94. setEventMessage($langs->trans("ErrorFileNotUploaded"), 'errors');
  95. }
  96. else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
  97. {
  98. setEventMessage($langs->trans("ErrorFileIsInfectedWithAVirus"), 'errors');
  99. }
  100. else // Known error
  101. {
  102. setEventMessage($langs->trans($resupload), 'errors');
  103. }
  104. }
  105. }
  106. else
  107. {
  108. // Echec transfert (fichier depassant la limite ?)
  109. $langs->load("errors");
  110. $mesg = '<div class="error">'.$langs->trans("ErrorFailToCreateDir",$upload_dir).'</div>';
  111. }
  112. }
  113. // Action ajout d'un rep
  114. if ($_POST["action"] == 'add' && $user->rights->ftp->setup)
  115. {
  116. $ecmdir->ref = $_POST["ref"];
  117. $ecmdir->label = $_POST["label"];
  118. $ecmdir->description = $_POST["desc"];
  119. $id = $ecmdir->create($user);
  120. if ($id > 0)
  121. {
  122. header("Location: ".$_SERVER["PHP_SELF"]);
  123. exit;
  124. }
  125. else
  126. {
  127. $mesg='<div class="error">Error '.$langs->trans($ecmdir->error).'</div>';
  128. $_GET["action"] = "create";
  129. }
  130. }
  131. // Remove file
  132. if ($_REQUEST['action'] == 'confirm_deletefile' && $_REQUEST['confirm'] == 'yes')
  133. {
  134. // set up a connection or die
  135. if (! $conn_id)
  136. {
  137. $newsectioniso=utf8_decode($section);
  138. $resultarray=dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso);
  139. $conn_id=$resultarray['conn_id'];
  140. $ok=$resultarray['ok'];
  141. $mesg=$resultarray['mesg'];
  142. }
  143. if ($conn_id && $ok && ! $mesg)
  144. {
  145. $langs->load("other");
  146. // Remote file
  147. $filename=$file;
  148. $remotefile=$section.(preg_match('@[\\\/]$@',$section)?'':'/').$file;
  149. $newremotefileiso=utf8_decode($remotefile);
  150. //print "x".$newremotefileiso;
  151. dol_syslog("ftp/index.php ftp_delete ".$newremotefileiso);
  152. $result=@ftp_delete($conn_id, $newremotefileiso);
  153. if ($result)
  154. {
  155. $mesg = '<div class="ok">'.$langs->trans("FileWasRemoved",$file).'</div>';
  156. }
  157. else
  158. {
  159. dol_syslog("ftp/index.php ftp_delete", LOG_ERR);
  160. $mesg = '<div class="error">'.$langs->trans("FTPFailedToRemoveFile",$file).'</div>';
  161. }
  162. //ftp_close($conn_id); Close later
  163. $action='';
  164. }
  165. else
  166. {
  167. dol_print_error('',$mesg);
  168. }
  169. }
  170. // Delete several lines at once
  171. if ($_POST["const"] && $_POST["delete"] && $_POST["delete"] == $langs->trans("Delete"))
  172. {
  173. // set up a connection or die
  174. if (! $conn_id)
  175. {
  176. $newsectioniso=utf8_decode($section);
  177. $resultarray=dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso);
  178. $conn_id=$resultarray['conn_id'];
  179. $ok=$resultarray['ok'];
  180. $mesg=$resultarray['mesg'];
  181. }
  182. if ($conn_id && $ok && ! $mesg)
  183. {
  184. foreach($_POST["const"] as $const)
  185. {
  186. if ($const["check"]) // Is checkbox checked
  187. {
  188. $langs->load("other");
  189. // Remote file
  190. $file=$const["file"];
  191. $section=$const["section"];
  192. $remotefile=$section.(preg_match('@[\\\/]$@',$section)?'':'/').$file;
  193. $newremotefileiso=utf8_decode($remotefile);
  194. //print "x".$newremotefileiso;
  195. dol_syslog("ftp/index.php ftp_delete ".$newremotefileiso);
  196. $result=@ftp_delete($conn_id, $newremotefileiso);
  197. if ($result)
  198. {
  199. $mesg .= '<div class="ok">'.$langs->trans("FileWasRemoved",$file).'</div>';
  200. }
  201. else
  202. {
  203. dol_syslog("ftp/index.php ftp_delete", LOG_ERR);
  204. $mesg .= '<div class="error">'.$langs->trans("FTPFailedToRemoveFile",$file).'</div>';
  205. }
  206. //ftp_close($conn_id); Close later
  207. $action='';
  208. }
  209. }
  210. }
  211. else
  212. {
  213. dol_print_error('',$mesg);
  214. }
  215. }
  216. // Remove directory
  217. if ($_REQUEST['action'] == 'confirm_deletesection' && $_REQUEST['confirm'] == 'yes')
  218. {
  219. // set up a connection or die
  220. if (! $conn_id)
  221. {
  222. $newsectioniso=utf8_decode($section);
  223. $resultarray=dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso);
  224. $conn_id=$resultarray['conn_id'];
  225. $ok=$resultarray['ok'];
  226. $mesg=$resultarray['mesg'];
  227. }
  228. if ($conn_id && $ok && ! $mesg)
  229. {
  230. // Remote file
  231. $filename=$file;
  232. $remotefile=$section.(preg_match('@[\\\/]$@',$section)?'':'/').$file;
  233. $newremotefileiso=utf8_decode($remotefile);
  234. $result=@ftp_rmdir($conn_id, $newremotefileiso);
  235. if ($result)
  236. {
  237. $mesg = '<div class="ok">'.$langs->trans("DirWasRemoved",$file).'</div>';
  238. }
  239. else
  240. {
  241. $mesg = '<div class="error">'.$langs->trans("FTPFailedToRemoveDir",$file).'</div>';
  242. }
  243. //ftp_close($conn_id); Close later
  244. $action='';
  245. }
  246. else
  247. {
  248. dol_print_error('',$mesg);
  249. }
  250. }
  251. // Download directory
  252. if ($_REQUEST['action'] == 'download')
  253. {
  254. // set up a connection or die
  255. if (! $conn_id)
  256. {
  257. $newsectioniso=utf8_decode($section);
  258. $resultarray=dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso);
  259. $conn_id=$resultarray['conn_id'];
  260. $ok=$resultarray['ok'];
  261. $mesg=$resultarray['mesg'];
  262. }
  263. if ($conn_id && $ok && ! $mesg)
  264. {
  265. // Local file
  266. $localfile=tempnam($download_dir,'dol_');
  267. // Remote file
  268. $filename=$file;
  269. $remotefile=$section.(preg_match('@[\\\/]$@',$section)?'':'/').$file;
  270. $newremotefileiso=utf8_decode($remotefile);
  271. $result=ftp_get($conn_id,$localfile,$newremotefileiso,FTP_BINARY);
  272. if ($result)
  273. {
  274. if (! empty($conf->global->MAIN_UMASK))
  275. @chmod($localfile, octdec($conf->global->MAIN_UMASK));
  276. // Define mime type
  277. $type = 'application/octet-stream';
  278. if (! empty($_GET["type"])) $type=$_GET["type"];
  279. else $type=dol_mimetype($original_file);
  280. // Define attachment (attachment=true to force choice popup 'open'/'save as')
  281. $attachment = true;
  282. if ($encoding) header('Content-Encoding: '.$encoding);
  283. if ($type) header('Content-Type: '.$type);
  284. if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"');
  285. else header('Content-Disposition: inline; filename="'.$filename.'"');
  286. // Ajout directives pour resoudre bug IE
  287. header('Cache-Control: Public, must-revalidate');
  288. header('Pragma: public');
  289. readfile($localfile);
  290. ftp_close($conn_id);
  291. exit;
  292. }
  293. else
  294. {
  295. $mesg='<div class="error">Failed to get file '.$remotefile.'</div>';
  296. }
  297. }
  298. else
  299. {
  300. dol_print_error('',$mesg);
  301. }
  302. //ftp_close($conn_id); Close later
  303. }
  304. /*******************************************************************
  305. * PAGE
  306. *
  307. * Put here all code to do according to value of "action" parameter
  308. ********************************************************************/
  309. llxHeader();
  310. // Add logic to shoow/hide buttons
  311. if ($conf->use_javascript_ajax)
  312. {
  313. ?>
  314. <script type="text/javascript">
  315. jQuery(document).ready(function() {
  316. jQuery("#delconst").hide();
  317. jQuery(".checkboxfordelete").click(function() {
  318. jQuery("#delconst").show();
  319. });
  320. });
  321. </script>
  322. <?php
  323. }
  324. $form=new Form($db);
  325. $formfile=new FormFile($db);
  326. $userstatic = new User($db);
  327. //***********************
  328. // List
  329. //***********************
  330. print_fiche_titre($langs->trans("FTPArea"));
  331. print $langs->trans("FTPAreaDesc")."<br>";
  332. if (! function_exists('ftp_connect'))
  333. {
  334. print $langs->trans("FTPFeatureNotSupportedByYourPHP");
  335. }
  336. else
  337. {
  338. if (! empty($ftp_server))
  339. {
  340. // Confirm remove file
  341. if ($_GET['action'] == 'delete')
  342. {
  343. $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?numero_ftp='.$numero_ftp.'&section='.urlencode($_REQUEST["section"]).'&file='.urlencode($_GET["file"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile','','',1);
  344. if ($ret == 'html') print '<br>';
  345. }
  346. // Confirmation de la suppression d'une ligne categorie
  347. if ($_GET['action'] == 'delete_section')
  348. {
  349. $ret=$form->form_confirm($_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);
  350. if ($ret == 'html') print '<br>';
  351. }
  352. print $langs->trans("Server").': <b>'.$ftp_server.'</b><br>';
  353. print $langs->trans("Port").': <b>'.$ftp_port.'</b><br>';
  354. print $langs->trans("User").': <b>'.$ftp_user.'</b><br>';
  355. print $langs->trans("Directory").': ';
  356. $sectionarray=preg_split('|[\/]|',$section);
  357. // For /
  358. $newsection='/';
  359. print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual&numero_ftp='.$numero_ftp.($newsection?'&section='.urlencode($newsection):'').'">';
  360. print '/';
  361. print '</a> ';
  362. // For other directories
  363. $i=0;
  364. foreach($sectionarray as $val)
  365. {
  366. if (empty($val)) continue; // Discard first and last entry that should be empty as section start/end with /
  367. if ($i > 0)
  368. {
  369. print ' / ';
  370. $newsection.='/';
  371. }
  372. $newsection.=$val;
  373. print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual&numero_ftp='.$numero_ftp.($newsection?'&section='.urlencode($newsection):'').'">';
  374. print $val;
  375. print '</a>';
  376. $i++;
  377. }
  378. print '<br>';
  379. print "<br>\n";
  380. if ($mesg) { print $mesg."<br>"; }
  381. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  382. print '<input type="hidden" name="numero_ftp" value="'.$numero_ftp.'">';
  383. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  384. // Construit liste des repertoires
  385. print '<table width="100%" class="nobordernopadding">'."\n";
  386. print '<tr class="liste_titre">'."\n";
  387. print '<td class="liste_titre" align="left">'.$langs->trans("Content").'</td>'."\n";
  388. print '<td class="liste_titre" align="center">'.$langs->trans("Size").'</td>'."\n";
  389. print '<td class="liste_titre" align="center">'.$langs->trans("Date").'</td>'."\n";
  390. print '<td class="liste_titre" align="center">'.$langs->trans("Owner").'</td>'."\n";
  391. print '<td class="liste_titre" align="center">'.$langs->trans("Group").'</td>'."\n";
  392. print '<td class="liste_titre" align="center">'.$langs->trans("Permissions").'</td>'."\n";
  393. print '<td class="liste_titre" align="right">';
  394. print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual&numero_ftp='.$numero_ftp.($section?'&section='.urlencode($section):'').'">'.img_picto($langs->trans("Refresh"),'refresh').'</a>&nbsp;';
  395. print '</td>'."\n";
  396. print '</tr>'."\n";
  397. // set up a connection or die
  398. if (! $conn_id)
  399. {
  400. $resultarray=dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section);
  401. $conn_id=$resultarray['conn_id'];
  402. $ok=$resultarray['ok'];
  403. $mesg=$resultarray['mesg'];
  404. }
  405. if ($ok)
  406. {
  407. //$type = ftp_systype($conn_id);
  408. $newsectioniso=utf8_decode($section);
  409. $buff = ftp_rawlist($conn_id, $newsectioniso);
  410. $contents = ftp_nlist($conn_id, $newsectioniso); // Sometimes rawlist fails but never nlist
  411. //var_dump($contents);
  412. //var_dump($buff);
  413. $nboflines=count($contents);
  414. $var=true;
  415. $rawlisthasfailed=false;
  416. $i=0;
  417. while ($i < $nboflines && $i < 1000)
  418. {
  419. $vals=preg_split('@ +@',utf8_encode($buff[$i]),9);
  420. //$vals=preg_split('@ +@','drwxr-xr-x 2 root root 4096 Aug 30 2008 backup_apollon1',9);
  421. //var_dump($vals);
  422. $file=$vals[8];
  423. if (empty($file))
  424. {
  425. $rawlisthasfailed=true;
  426. $file=utf8_encode($contents[$i]);
  427. }
  428. if ($file == '.' || ($file == '..' && $section == '/'))
  429. {
  430. $i++;
  431. continue;
  432. }
  433. // Is it a directory ?
  434. $is_directory=0;
  435. if ($file == '..') $is_directory=1;
  436. else if (! $rawlisthasfailed)
  437. {
  438. if (preg_match('/^d/',$vals[0])) $is_directory=1;
  439. if (preg_match('/^l/',$vals[0])) $is_link=1;
  440. }
  441. else
  442. {
  443. // Remote file
  444. $filename=$file;
  445. //print "section=".$section.' file='.$file.'X';
  446. //print preg_match('@[\/]$@','aaa/').'Y';
  447. //print preg_match('@[\\\/]$@',"aaa\\").'Y';
  448. $remotefile=$section.(preg_match('@[\\\/]$@',$section)?'':'/').preg_replace('@^[\\\/]@','',$file);
  449. //print 'A'.$remotefile.'A';
  450. $newremotefileiso=utf8_decode($remotefile);
  451. //print 'Z'.$newremotefileiso.'Z';
  452. $is_directory=ftp_isdir($conn_id, $newremotefileiso);
  453. }
  454. $var=!$var;
  455. print '<tr '.$bc[$var].' height="18">';
  456. // Name
  457. print '<td>';
  458. $newsection=$section.(preg_match('@[\\\/]$@',$section)?'':'/').$file;
  459. $newsection=preg_replace('@[\\\/][^\\\/]+[\\\/]\.\.$@','/',$newsection); // Change aaa/xxx/.. to new aaa
  460. if ($is_directory) print '<a href="'.$_SERVER["PHP_SELF"].'?section='.urlencode($newsection).'&numero_ftp='.$numero_ftp.'">';
  461. print $file;
  462. if ($is_directory) print '</a>';
  463. print '</td>';
  464. // Size
  465. print '<td align="center" nowrap="nowrap">';
  466. if (! $is_directory && ! $is_link) print $vals[4];
  467. else print '&nbsp;';
  468. print '</td>';
  469. // Date
  470. print '<td align="center" nowrap="nowrap">';
  471. print $vals[5].' '.$vals[6].' '.$vals[7];
  472. print '</td>';
  473. // User
  474. print '<td align="center" nowrap="nowrap">';
  475. print $vals[2];
  476. print '</td>';
  477. // Group
  478. print '<td align="center" nowrap="nowrap">';
  479. print $vals[3];
  480. print '</td>';
  481. // Permissions
  482. print '<td align="center" nowrap="nowrap">';
  483. print $vals[0];
  484. print '</td>';
  485. // Action
  486. print '<td align="right" width="64" nowrap="nowrap">';
  487. if ($is_directory)
  488. {
  489. if ($file != '..') print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete_section&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($file).'">'.img_delete().'</a>';
  490. else print '&nbsp;';
  491. }
  492. else if ($is_link)
  493. {
  494. $newfile=$file;
  495. $newfile=preg_replace('/ ->.*/','',$newfile);
  496. print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($newfile).'">'.img_delete().'</a>';
  497. }
  498. else
  499. {
  500. print '<a href="'.$_SERVER["PHP_SELF"].'?action=download&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($file).'">'.img_picto('','file').'</a>';
  501. print ' &nbsp; ';
  502. print '<input type="checkbox" class="flat checkboxfordelete" id="check_'.$i.'" name="const['.$i.'][check]" value="1">';
  503. print ' &nbsp; ';
  504. print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($file).'">'.img_delete().'</a>';
  505. print '<input type="hidden" name="const['.$i.'][section]" value="'.$section.'">';
  506. print '<input type="hidden" name="const['.$i.'][file]" value="'.$file.'">';
  507. }
  508. print '</td>';
  509. print '</tr>'."\n";
  510. $i++;
  511. $nbofentries++;
  512. }
  513. }
  514. print "</table>";
  515. if (! $ok && $mesg) print $mesg;
  516. // Actions
  517. /*
  518. if ($user->rights->ftp->write && ! empty($section))
  519. {
  520. $formfile->form_attach_new_file(DOL_URL_ROOT.'/ftp/index.php','',0,$section,1);
  521. }
  522. else print '&nbsp;';
  523. */
  524. print '<br>';
  525. print '<div id="delconst" align="right">';
  526. print '<input type="submit" name="delete" class="button" value="'.$langs->trans("Delete").'">';
  527. print '</div>';
  528. print "</form>";
  529. }
  530. else
  531. {
  532. print $langs->trans("SetupOfFTPClientModuleNotComplete");
  533. }
  534. }
  535. print '<br>';
  536. // Close FTP connection
  537. if ($conn_id) ftp_close($conn_id);
  538. // End of page
  539. $db->close();
  540. llxFooter();
  541. /**
  542. * Connect to FTP server
  543. *
  544. * @param string $ftp_server Server name
  545. * @param string $ftp_port Server port
  546. * @param string $ftp_user FTP user
  547. * @param string $ftp_password FTP password
  548. * @param string $section Directory
  549. * @return int <0 if OK, >0 if KO
  550. */
  551. function dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section)
  552. {
  553. global $langs;
  554. $ok=1;
  555. if (! is_numeric($ftp_port))
  556. {
  557. $mesg=$langs->trans("FailedToConnectToFTPServer",$ftp_server,$ftp_port);
  558. $ok=0;
  559. }
  560. if ($ok)
  561. {
  562. $conn_id = ftp_connect($ftp_server, $ftp_port, 20);
  563. if ($conn_id)
  564. {
  565. // turn on passive mode transfers
  566. //ftp_pasv ($conn_id, true);
  567. if ($ftp_user)
  568. {
  569. if (ftp_login($conn_id, $ftp_user, $ftp_password))
  570. {
  571. // Change the dir
  572. $newsectioniso=utf8_decode($section);
  573. ftp_chdir($conn_id, $newsectioniso);
  574. }
  575. else
  576. {
  577. $mesg=$langs->trans("FailedToConnectToFTPServerWithCredentials");
  578. $ok=0;
  579. }
  580. }
  581. }
  582. else
  583. {
  584. $mesg=$langs->trans("FailedToConnectToFTPServer",$ftp_server,$ftp_port);
  585. $ok=0;
  586. }
  587. }
  588. $arrayresult=array('conn_id'=>$conn_id, 'ok'=>$ok, 'mesg'=>$mesg);
  589. return $arrayresult;
  590. }
  591. /**
  592. * Tell if an entry is a FTP directory
  593. *
  594. * @param resource $connect_id Connection handler
  595. * @param string $dir Directory
  596. * @return int 1=directory, 0=not a directory
  597. */
  598. function ftp_isdir($connect_id,$dir)
  599. {
  600. if (@ftp_chdir($connect_id,$dir))
  601. {
  602. ftp_cdup($connect_id);
  603. return 1;
  604. }
  605. else
  606. {
  607. return 0;
  608. }
  609. }
  610. ?>