From 87c590b8231691bfa7382878eb979d21b5b9a6e3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur <eldy@users.sourceforge.net> Date: Mon, 28 Sep 2009 00:03:43 +0000 Subject: [PATCH] New: Add module FTP client --- htdocs/ftp/index.php | 76 ++++++++++++++++++++++-------------- htdocs/ftp/pre.inc.php | 14 +++++++ htdocs/lib/functions.lib.php | 1 + 3 files changed, 61 insertions(+), 30 deletions(-) diff --git a/htdocs/ftp/index.php b/htdocs/ftp/index.php index 455ff696a11..d38c7ee0c69 100644 --- a/htdocs/ftp/index.php +++ b/htdocs/ftp/index.php @@ -62,10 +62,12 @@ $offset = $limit * $page ; if (! $sortorder) $sortorder="ASC"; if (! $sortfield) $sortfield="label"; +$s_ftp_name='FTP_NAME_'.$numero_ftp; $s_ftp_server='FTP_SERVER_'.$numero_ftp; $s_ftp_port='FTP_PORT_'.$numero_ftp; $s_ftp_user='FTP_USER_'.$numero_ftp; $s_ftp_password='FTP_PASSWORD_'.$numero_ftp; +$ftp_name=$conf->global->$s_ftp_name; $ftp_server=$conf->global->$s_ftp_server; $ftp_port=$conf->global->$s_ftp_port; $ftp_user=$conf->global->$s_ftp_user; @@ -319,7 +321,6 @@ $userstatic = new User($db); print_fiche_titre($langs->trans("FTPArea")); print $langs->trans("FTPAreaDesc")."<br>"; -print "<br>\n"; if (! function_exists('ftp_connect')) { @@ -333,7 +334,7 @@ else // Confirm remove file if ($_GET['action'] == 'delete') { - $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?section='.urlencode($_REQUEST["section"]).'&file='.urlencode($_GET["file"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile','','',1); + $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?numero_ftp='.$numero_ftp.'§ion='.urlencode($_REQUEST["section"]).'&file='.urlencode($_GET["file"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile','','',1); if ($ret == 'html') print '<br>'; } @@ -343,7 +344,7 @@ else // Confirmation de la suppression d'une ligne categorie if ($_GET['action'] == 'delete_section') { - $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?section='.urlencode($_REQUEST["section"]).'&file='.urlencode($_GET["file"]), $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection',$ecmdir->label), 'confirm_deletesection','','',1); + $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?numero_ftp='.$numero_ftp.'§ion='.urlencode($_REQUEST["section"]).'&file='.urlencode($_GET["file"]), $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection',$ecmdir->label), 'confirm_deletesection','','',1); if ($ret == 'html') print '<br>'; } @@ -365,7 +366,7 @@ else print '<td class="liste_titre" align="center">'.$langs->trans("Group").'</td>'."\n"; print '<td class="liste_titre" align="center">'.$langs->trans("Permissions").'</td>'."\n"; print '<td class="liste_titre" align="right">'; - print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual'.($section?'&section='.urlencode($section):'').'">'.img_picto($langs->trans("Refresh"),'refresh').'</a> '; + print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual&numero_ftp='.$numero_ftp.($section?'§ion='.urlencode($section):'').'">'.img_picto($langs->trans("Refresh"),'refresh').'</a> '; print '</td>'."\n"; print '</tr>'."\n"; @@ -460,7 +461,7 @@ else print '<td align="right" width="64" nowrap="nowrap">'; if ($is_directory) { - if ($file != '..') print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete_section§ion='.urlencode($section).'&file='.urlencode($file).'">'.img_delete().'</a>'; + if ($file != '..') print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete_section&numero_ftp='.$numero_ftp.'§ion='.urlencode($section).'&file='.urlencode($file).'">'.img_delete().'</a>'; else print ' '; } else if ($is_link) @@ -469,9 +470,9 @@ else } else { - print '<a href="'.$_SERVER["PHP_SELF"].'?action=download§ion='.urlencode($section).'&file='.urlencode($file).'">'.img_file().'</a>'; + print '<a href="'.$_SERVER["PHP_SELF"].'?action=download&numero_ftp='.$numero_ftp.'§ion='.urlencode($section).'&file='.urlencode($file).'">'.img_file().'</a>'; print ' '; - print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete§ion='.urlencode($section).'&file='.urlencode($file).'">'.img_delete().'</a>'; + print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete&numero_ftp='.$numero_ftp.'§ion='.urlencode($section).'&file='.urlencode($file).'">'.img_delete().'</a>'; } print '</td>'; print '</tr>'."\n"; @@ -524,43 +525,58 @@ llxFooter('$Date$ - $Revision$'); */ function dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section) { + global $langs; + $ok=1; - $conn_id = ftp_connect($ftp_server, $ftp_port, 20); - if ($conn_id) + if (! is_numeric($ftp_port)) { - // turn on passive mode transfers - //ftp_pasv ($conn_id, true) ; + $mesg=$langs->trans("FailedToConnectToFTPServer",$ftp_server,$ftp_port); + $ok=0; + } - if ($ftp_user) + if ($ok) + { + $conn_id = ftp_connect($ftp_server, $ftp_port, 20); + if ($conn_id) { - if (ftp_login($conn_id, $ftp_user, $ftp_password)) - { - // Change the dir - $newsectioniso=utf8_decode($section); - ftp_chdir($conn_id, $newsectioniso); - } - else - { - $mesg=$langs->trans("FailedToConnectToFTPServerWithCredentials"); - $ok=0; - } + // turn on passive mode transfers + //ftp_pasv ($conn_id, true) ; + + if ($ftp_user) + { + if (ftp_login($conn_id, $ftp_user, $ftp_password)) + { + // Change the dir + $newsectioniso=utf8_decode($section); + ftp_chdir($conn_id, $newsectioniso); + } + else + { + $mesg=$langs->trans("FailedToConnectToFTPServerWithCredentials"); + $ok=0; + } + } + } + else + { + $mesg=$langs->trans("FailedToConnectToFTPServer",$ftp_server,$ftp_port); + $ok=0; } - } - else - { - $mesg=$langs->trans("FailedToConnectToFTPServer",$ftp_server,$ftp_port); - $ok=0; } $arrayresult=array('conn_id'=>$conn_id, 'ok'=>$ok, 'mesg'=>$mesg); - return $arrayresult; } /** -*/ + * Tell if an entry is a FTP directory + * + * @param unknown_type $connect_id + * @param unknown_type $dir + * @return unknown + */ function ftp_isdir($connect_id,$dir) { if(ftp_chdir($connect_id,$dir)) diff --git a/htdocs/ftp/pre.inc.php b/htdocs/ftp/pre.inc.php index f96932bd3f3..32d78d5acce 100644 --- a/htdocs/ftp/pre.inc.php +++ b/htdocs/ftp/pre.inc.php @@ -36,6 +36,20 @@ function llxHeader($head = '', $title='', $help_url='', $morehtml='') $menu = new Menu(); + $MAXFTP=20; + $i=1; + while ($i <= $MAXFTP) + { + $paramkey='FTP_NAME_'.$i; + //print $paramkey; + if (! empty($conf->global->$paramkey)) + { + $link=DOL_URL_ROOT."/ftp/index.php?idmenu=".$_SESSION["idmenu"]."&numero_ftp=".$i; + + $menu->add($link, dol_trunc($conf->global->$paramkey,24)); + } + $i++; + } left_menu($menu->liste, $help_url, $morehtml); diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index ee24b4f4112..7d42fa1c942 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -927,6 +927,7 @@ function dolibarr_trunc($string,$size=40,$trunc='right',$stringencoding='') * \param string String to truncate * \param size Max string size. 0 for no limit. * \param trunc Where to trunc: right, left, middle + * \param stringencoding Tell what is source string encoding * \return string Truncated string * \remarks USE_SHORT_TITLE=0 can disable all truncings */ -- GitLab