Fix: FTP modules fails with servers than need passive connection
This commit is contained in:
parent
6952a5f465
commit
dff532159d
@ -74,10 +74,10 @@ if ($action == 'add' || GETPOST('modify','alpha'))
|
|||||||
|
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
|
|
||||||
$ftp_port = "FTP_PORT_" . $entry;
|
$ftp_port = "FTP_PORT_" . $entry;
|
||||||
$ftp_user = "FTP_USER_" . $entry;
|
$ftp_user = "FTP_USER_" . $entry;
|
||||||
$ftp_password = "FTP_PASSWORD_" . $entry;
|
$ftp_password = "FTP_PASSWORD_" . $entry;
|
||||||
|
$ftp_passive = "FTP_PASSIVE_" . $entry;
|
||||||
|
|
||||||
$db->begin();
|
$db->begin();
|
||||||
|
|
||||||
@ -86,8 +86,9 @@ if ($action == 'add' || GETPOST('modify','alpha'))
|
|||||||
if ($result2) $result3=dolibarr_set_const($db, "FTP_USER_" . $entry,GETPOST($ftp_user,'alpha'),'chaine',0,'',$conf->entity);
|
if ($result2) $result3=dolibarr_set_const($db, "FTP_USER_" . $entry,GETPOST($ftp_user,'alpha'),'chaine',0,'',$conf->entity);
|
||||||
if ($result3) $result4=dolibarr_set_const($db, "FTP_PASSWORD_" . $entry,GETPOST($ftp_password,'alpha'),'chaine',0,'',$conf->entity);
|
if ($result3) $result4=dolibarr_set_const($db, "FTP_PASSWORD_" . $entry,GETPOST($ftp_password,'alpha'),'chaine',0,'',$conf->entity);
|
||||||
if ($result4) $result5=dolibarr_set_const($db, "FTP_NAME_" . $entry,GETPOST($ftp_name,'alpha'),'chaine',0,'',$conf->entity);
|
if ($result4) $result5=dolibarr_set_const($db, "FTP_NAME_" . $entry,GETPOST($ftp_name,'alpha'),'chaine',0,'',$conf->entity);
|
||||||
|
if ($result5) $result6=dolibarr_set_const($db, "FTP_PASSIVE_" . $entry,GETPOST($ftp_passive,'alpha'),'chaine',0,'',$conf->entity);
|
||||||
|
|
||||||
if ($result1 && $result2 && $result3 && $result4 && $result5)
|
if ($result1 && $result2 && $result3 && $result4 && $result5 && $result6)
|
||||||
{
|
{
|
||||||
$db->commit();
|
$db->commit();
|
||||||
//$mesg='<div class="ok">'.$langs->trans("Success").'</div>';
|
//$mesg='<div class="ok">'.$langs->trans("Success").'</div>';
|
||||||
@ -108,17 +109,18 @@ if (GETPOST('delete','alpha'))
|
|||||||
{
|
{
|
||||||
$db->begin();
|
$db->begin();
|
||||||
|
|
||||||
$result1=dolibarr_del_const($db,"ftp_port_" . $entry,$conf->entity);
|
$result1=dolibarr_del_const($db,"FTP_PORT_" . $entry,$conf->entity);
|
||||||
if ($result1) $result2=dolibarr_del_const($db,"ftp_server_" . $entry,$conf->entity);
|
if ($result1) $result2=dolibarr_del_const($db,"FTP_SERVER_" . $entry,$conf->entity);
|
||||||
if ($result2) $result3=dolibarr_del_const($db,"ftp_user_" . $entry,$conf->entity);
|
if ($result2) $result3=dolibarr_del_const($db,"FTP_USER_" . $entry,$conf->entity);
|
||||||
if ($result3) $result4=dolibarr_del_const($db,"ftp_password_" . $entry,$conf->entity);
|
if ($result3) $result4=dolibarr_del_const($db,"FTP_PASSWORD_" . $entry,$conf->entity);
|
||||||
if ($result4) $result5=dolibarr_del_const($db,"ftp_name_" . $entry,$conf->entity);
|
if ($result4) $result5=dolibarr_del_const($db,"FTP_NAME_" . $entry,$conf->entity);
|
||||||
|
if ($result4) $result5=dolibarr_del_const($db,"FTP_PASSIVE_" . $entry,$conf->entity);
|
||||||
|
|
||||||
if ($result1 && $result2 && $result3 && $result4 && $result5)
|
if ($result1 && $result2 && $result3 && $result4 && $result5 && $result6)
|
||||||
{
|
{
|
||||||
$db->commit();
|
$db->commit();
|
||||||
//$mesg='<div class="ok">'.$langs->trans("Success").'</div>';
|
//$mesg='<div class="ok">'.$langs->trans("Success").'</div>';
|
||||||
header("Location: ftpclient.php");
|
header("Location: ".$_SERVER["PHP_SELF"]);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -134,6 +136,8 @@ if (GETPOST('delete','alpha'))
|
|||||||
* View
|
* View
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
$form=new Form($db);
|
||||||
|
|
||||||
llxHeader();
|
llxHeader();
|
||||||
|
|
||||||
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
|
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
|
||||||
@ -159,34 +163,42 @@ else
|
|||||||
|
|
||||||
print '<tr class="pair">';
|
print '<tr class="pair">';
|
||||||
print '<td>'.$langs->trans("Label").'</td>';
|
print '<td>'.$langs->trans("Label").'</td>';
|
||||||
print '<td><input type="text" name="FTP_NAME_'.($lastftpentry+1).'" value="'.@constant("FTP_NAME_" . ($lastftpentry+1)).'" size="64"></td>';
|
print '<td><input type="text" name="FTP_NAME_'.($lastftpentry+1).'" value="'.GETPOST("FTP_NAME_" . ($lastftpentry+1)).'" size="64"></td>';
|
||||||
print '<td>My FTP access</td>';
|
print '<td>My FTP access</td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
|
|
||||||
print '<tr class="impair">';
|
print '<tr class="impair">';
|
||||||
print '<td>'.$langs->trans("Server").'</td>';
|
print '<td>'.$langs->trans("Server").'</td>';
|
||||||
print '<td><input type="text" name="FTP_SERVER_'.($lastftpentry+1).'" value="'.@constant("FTP_SERVER_" . ($lastftpentry+1)).'" size="64"></td>';
|
print '<td><input type="text" name="FTP_SERVER_'.($lastftpentry+1).'" value="'.GETPOST("FTP_SERVER_" . ($lastftpentry+1)).'" size="64"></td>';
|
||||||
print '<td>localhost</td>';
|
print '<td>localhost</td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
|
|
||||||
print '<tr class="pair">';
|
print '<tr class="pair">';
|
||||||
print '<td width="100">'.$langs->trans("Port").'</td>';
|
print '<td width="100">'.$langs->trans("Port").'</td>';
|
||||||
print '<td><input type="text" name="FTP_PORT_'.($lastftpentry+1).'" value="'.@constant("FTP_PORT_" . ($lastftpentry+1)).'" size="64"></td>';
|
print '<td><input type="text" name="FTP_PORT_'.($lastftpentry+1).'" value="'.GETPOST("FTP_PORT_" . ($lastftpentry+1)).'" size="64"></td>';
|
||||||
print '<td>21</td>';
|
print '<td>21</td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
|
|
||||||
print '<tr class="impair">';
|
print '<tr class="impair">';
|
||||||
print '<td>'.$langs->trans("User").'</td>';
|
print '<td>'.$langs->trans("User").'</td>';
|
||||||
print '<td><input type="text" name="FTP_USER_'.($lastftpentry+1).'" value="'.@constant("FTP_USER_" . ($lastftpentry+1)).'" size="24"></td>';
|
print '<td><input type="text" name="FTP_USER_'.($lastftpentry+1).'" value="'.GETPOST("FTP_USER_" . ($lastftpentry+1)).'" size="24"></td>';
|
||||||
print '<td>myftplogin</td>';
|
print '<td>myftplogin</td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
|
|
||||||
print '<tr class="pair">';
|
print '<tr class="pair">';
|
||||||
print '<td>'.$langs->trans("Password").'</td>';
|
print '<td>'.$langs->trans("Password").'</td>';
|
||||||
print '<td><input type="password" name="FTP_PASSWORD_'.($lastftpentry+1).'" value="'.@constant("FTP_PASSWORD_" . ($lastftpentry+1)).'" size="24"></td>';
|
print '<td><input type="password" name="FTP_PASSWORD_'.($lastftpentry+1).'" value="'.GETPOST("FTP_PASSWORD_" . ($lastftpentry+1)).'" size="24"></td>';
|
||||||
print '<td>myftppassword</td>';
|
print '<td>myftppassword</td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
|
|
||||||
|
print '<tr class="impair">';
|
||||||
|
print '<td>'.$langs->trans("Passive").'</td>';
|
||||||
|
$defaultpassive=GETPOST("FTP_PASSIVE_" . ($lastftpentry+1));
|
||||||
|
if (! isset($_POST["FTP_PASSIVE_" . ($lastftpentry+1)])) $defaultpassive=empty($conf->global->FTP_SUGGEST_PASSIVE_BYDEFAULT)?0:1;
|
||||||
|
print '<td>'.$form->selectyesno('FTP_PASSIVE_'.($lastftpentry+1), $defaultpassive, 2).'</td>';
|
||||||
|
print '<td>'.$langs->trans("No").'</td>';
|
||||||
|
print '</tr>';
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<tr><td colspan="3" align="center">
|
<tr><td colspan="3" align="center">
|
||||||
<input type="submit" class="button" value="<?php echo $langs->trans("Add") ?>">
|
<input type="submit" class="button" value="<?php echo $langs->trans("Add") ?>">
|
||||||
@ -263,6 +275,12 @@ else
|
|||||||
print "<td><input type=\"password\" class=\"flat\" name=\"FTP_PASSWORD_" . $idrss . "\" value=\"" . @constant("FTP_PASSWORD_" . $idrss) . "\" size=\"24\"></td>";
|
print "<td><input type=\"password\" class=\"flat\" name=\"FTP_PASSWORD_" . $idrss . "\" value=\"" . @constant("FTP_PASSWORD_" . $idrss) . "\" size=\"24\"></td>";
|
||||||
print "</tr>";
|
print "</tr>";
|
||||||
|
|
||||||
|
$var=!$var;
|
||||||
|
print "<tr ".$bc[$var].">";
|
||||||
|
print "<td width=\"100\">".$langs->trans("Passive")."</td>";
|
||||||
|
print '<td>'.$form->selectyesno('FTP_PASSIVE_'.$idrss, @constant("FTP_PASSIVE_" . $idrss), 1).'</td>';
|
||||||
|
print "</tr>";
|
||||||
|
|
||||||
print "<tr>";
|
print "<tr>";
|
||||||
print "<td colspan=\"2\" align=\"center\">";
|
print "<td colspan=\"2\" align=\"center\">";
|
||||||
print "<input type=\"submit\" class=\"button\" name=\"modify\" value=\"".$langs->trans("Modify")."\">";
|
print "<input type=\"submit\" class=\"button\" name=\"modify\" value=\"".$langs->trans("Modify")."\">";
|
||||||
@ -288,7 +306,8 @@ else
|
|||||||
|
|
||||||
dol_htmloutput_mesg($mesg);
|
dol_htmloutput_mesg($mesg);
|
||||||
|
|
||||||
$db->close();
|
|
||||||
|
|
||||||
llxFooter();
|
llxFooter();
|
||||||
|
|
||||||
|
$db->close();
|
||||||
?>
|
?>
|
||||||
|
|||||||
@ -63,11 +63,13 @@ $s_ftp_server='FTP_SERVER_'.$numero_ftp;
|
|||||||
$s_ftp_port='FTP_PORT_'.$numero_ftp;
|
$s_ftp_port='FTP_PORT_'.$numero_ftp;
|
||||||
$s_ftp_user='FTP_USER_'.$numero_ftp;
|
$s_ftp_user='FTP_USER_'.$numero_ftp;
|
||||||
$s_ftp_password='FTP_PASSWORD_'.$numero_ftp;
|
$s_ftp_password='FTP_PASSWORD_'.$numero_ftp;
|
||||||
|
$s_ftp_passive='FTP_PASSIVE_'.$numero_ftp;
|
||||||
$ftp_name=$conf->global->$s_ftp_name;
|
$ftp_name=$conf->global->$s_ftp_name;
|
||||||
$ftp_server=$conf->global->$s_ftp_server;
|
$ftp_server=$conf->global->$s_ftp_server;
|
||||||
$ftp_port=$conf->global->$s_ftp_port; if (empty($ftp_port)) $ftp_port=21;
|
$ftp_port=$conf->global->$s_ftp_port; if (empty($ftp_port)) $ftp_port=21;
|
||||||
$ftp_user=$conf->global->$s_ftp_user;
|
$ftp_user=$conf->global->$s_ftp_user;
|
||||||
$ftp_password=$conf->global->$s_ftp_password;
|
$ftp_password=$conf->global->$s_ftp_password;
|
||||||
|
$ftp_passive=$conf->global->$s_ftp_passive;
|
||||||
|
|
||||||
$conn_id=0; // FTP connection ID
|
$conn_id=0; // FTP connection ID
|
||||||
|
|
||||||
@ -413,7 +415,7 @@ else
|
|||||||
}
|
}
|
||||||
|
|
||||||
print $langs->trans("Server").': <b>'.$ftp_server.'</b><br>';
|
print $langs->trans("Server").': <b>'.$ftp_server.'</b><br>';
|
||||||
print $langs->trans("Port").': <b>'.$ftp_port.'</b><br>';
|
print $langs->trans("Port").': <b>'.$ftp_port.'</b> '.($ftp_passive?"(Passive)":"(Active)").'<br>';
|
||||||
print $langs->trans("User").': <b>'.$ftp_user.'</b><br>';
|
print $langs->trans("User").': <b>'.$ftp_user.'</b><br>';
|
||||||
|
|
||||||
print $langs->trans("Directory").': ';
|
print $langs->trans("Directory").': ';
|
||||||
@ -638,9 +640,10 @@ llxFooter();
|
|||||||
* @param string $ftp_user FTP user
|
* @param string $ftp_user FTP user
|
||||||
* @param string $ftp_password FTP password
|
* @param string $ftp_password FTP password
|
||||||
* @param string $section Directory
|
* @param string $section Directory
|
||||||
|
* @param string $ftp_passive Use a passive mode
|
||||||
* @return int <0 if OK, >0 if KO
|
* @return int <0 if OK, >0 if KO
|
||||||
*/
|
*/
|
||||||
function dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section)
|
function dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive=0)
|
||||||
{
|
{
|
||||||
global $langs;
|
global $langs;
|
||||||
|
|
||||||
@ -657,13 +660,13 @@ function dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $sect
|
|||||||
$conn_id = ftp_connect($ftp_server, $ftp_port, 20);
|
$conn_id = ftp_connect($ftp_server, $ftp_port, 20);
|
||||||
if ($conn_id)
|
if ($conn_id)
|
||||||
{
|
{
|
||||||
// turn on passive mode transfers
|
|
||||||
//ftp_pasv ($conn_id, true);
|
|
||||||
|
|
||||||
if ($ftp_user)
|
if ($ftp_user)
|
||||||
{
|
{
|
||||||
if (ftp_login($conn_id, $ftp_user, $ftp_password))
|
if (ftp_login($conn_id, $ftp_user, $ftp_password))
|
||||||
{
|
{
|
||||||
|
// Turn on passive mode transfers (must be after a successful login
|
||||||
|
if ($ftp_passive) ftp_pasv($conn_id, true);
|
||||||
|
|
||||||
// Change the dir
|
// Change the dir
|
||||||
$newsectioniso=utf8_decode($section);
|
$newsectioniso=utf8_decode($section);
|
||||||
ftp_chdir($conn_id, $newsectioniso);
|
ftp_chdir($conn_id, $newsectioniso);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user