2009-09-28 01:22:00 +02:00
< ? php
2016-10-25 02:33:40 +02:00
/* Copyright ( C ) 2004 - 2016 Laurent Destailleur < eldy @ users . sourceforge . net >
2011-09-06 11:25:32 +02:00
* Copyright ( C ) 2011 Juanjo Menent < jmenent @ 2 byte . es >
2009-09-28 01:22:00 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2009-09-28 01:22:00 +02:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2011-08-01 01:45:11 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2009-09-28 01:22:00 +02:00
*/
/**
2010-07-21 14:35:56 +02:00
* \file htdocs / ftp / admin / ftpclient . php
2009-09-28 01:22:00 +02:00
* \ingroup ftp
* \brief Admin page to setup FTP client module
*/
2012-08-22 23:24:21 +02:00
require '../../main.inc.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php' ;
2009-09-28 01:22:00 +02:00
$langs -> load ( " admin " );
2010-07-10 01:49:41 +02:00
$langs -> load ( " ftp " );
2009-09-28 01:22:00 +02:00
2009-09-30 18:11:54 +02:00
// Security check
2009-09-28 01:22:00 +02:00
if ( ! $user -> admin ) accessforbidden ();
$def = array ();
$lastftpentry = 0 ;
2012-04-04 16:53:59 +02:00
$action = GETPOST ( 'action' , 'alpha' );
$entry = GETPOST ( 'numero_entry' , 'alpha' );
2011-09-06 11:25:32 +02:00
2016-10-25 02:33:40 +02:00
/*
* Action
*/
// Get value for $lastftpentry
2010-03-24 14:06:29 +01:00
$sql = " select MAX(name) as name from " . MAIN_DB_PREFIX . " const " ;
2009-09-28 01:22:00 +02:00
$sql .= " WHERE name like 'FTP_SERVER_%' " ;
$result = $db -> query ( $sql );
if ( $result )
{
$obj = $db -> fetch_object ( $result );
2009-10-22 13:13:31 +02:00
preg_match ( '/([0-9]+)$/i' , $obj -> name , $reg );
2009-09-28 01:22:00 +02:00
if ( $reg [ 1 ]) $lastftpentry = $reg [ 1 ];
}
else
{
dol_print_error ( $db );
}
2012-04-04 16:53:59 +02:00
if ( $action == 'add' || GETPOST ( 'modify' , 'alpha' ))
2009-09-28 01:22:00 +02:00
{
2011-09-06 11:25:32 +02:00
$ftp_name = " FTP_NAME_ " . $entry ; // $_POST["numero_entry"];
$ftp_server = " FTP_SERVER_ " . $entry ; //$_POST["numero_entry"];
2009-09-28 01:22:00 +02:00
2009-09-30 18:11:54 +02:00
$error = 0 ;
2010-03-24 14:06:29 +01:00
2012-04-04 16:53:59 +02:00
if ( ! GETPOST ( " $ftp_name " , 'alpha' ))
2009-09-30 18:11:54 +02:00
{
$error = 1 ;
2015-10-17 17:09:34 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Label " )), null , 'errors' );
2009-09-30 18:11:54 +02:00
}
2010-03-24 14:06:29 +01:00
2012-04-04 16:53:59 +02:00
if ( ! GETPOST ( " $ftp_server " , 'alpha' ))
2009-09-30 18:11:54 +02:00
{
$error = 1 ;
2015-10-17 17:09:34 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Server " )), null , 'errors' );
2009-09-30 18:11:54 +02:00
}
2010-03-24 14:06:29 +01:00
2009-09-30 18:11:54 +02:00
if ( ! $error )
2009-09-28 01:22:00 +02:00
{
2011-09-06 11:25:32 +02:00
$ftp_port = " FTP_PORT_ " . $entry ;
$ftp_user = " FTP_USER_ " . $entry ;
$ftp_password = " FTP_PASSWORD_ " . $entry ;
2012-12-31 05:54:38 +01:00
$ftp_passive = " FTP_PASSIVE_ " . $entry ;
2009-09-28 01:22:00 +02:00
$db -> begin ();
2012-04-04 16:53:59 +02:00
$result1 = dolibarr_set_const ( $db , " FTP_PORT_ " . $entry , GETPOST ( $ftp_port , 'alpha' ), 'chaine' , 0 , '' , $conf -> entity );
if ( $result1 ) $result2 = dolibarr_set_const ( $db , " FTP_SERVER_ " . $entry , GETPOST ( $ftp_server , '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 ( $result4 ) $result5 = dolibarr_set_const ( $db , " FTP_NAME_ " . $entry , GETPOST ( $ftp_name , 'alpha' ), 'chaine' , 0 , '' , $conf -> entity );
2012-12-31 05:54:38 +01:00
if ( $result5 ) $result6 = dolibarr_set_const ( $db , " FTP_PASSIVE_ " . $entry , GETPOST ( $ftp_passive , 'alpha' ), 'chaine' , 0 , '' , $conf -> entity );
2009-09-28 01:22:00 +02:00
2012-12-18 18:17:07 +01:00
if ( $result1 && $result2 && $result3 && $result4 && $result5 && $result6 )
2009-09-28 01:22:00 +02:00
{
$db -> commit ();
header ( " Location: " . $_SERVER [ " PHP_SELF " ]);
exit ;
}
else
{
$db -> rollback ();
dol_print_error ( $db );
}
}
}
2012-04-04 16:53:59 +02:00
if ( GETPOST ( 'delete' , 'alpha' ))
2009-09-28 01:22:00 +02:00
{
2011-09-06 11:25:32 +02:00
if ( $entry )
2009-09-28 01:22:00 +02:00
{
$db -> begin ();
2012-12-18 18:17:07 +01:00
$result1 = dolibarr_del_const ( $db , " FTP_PORT_ " . $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 ( $result3 ) $result4 = dolibarr_del_const ( $db , " FTP_PASSWORD_ " . $entry , $conf -> entity );
if ( $result4 ) $result5 = dolibarr_del_const ( $db , " FTP_NAME_ " . $entry , $conf -> entity );
2012-12-31 05:54:38 +01:00
if ( $result4 ) $result6 = dolibarr_del_const ( $db , " FTP_PASSIVE_ " . $entry , $conf -> entity );
2012-12-18 18:17:07 +01:00
if ( $result1 && $result2 && $result3 && $result4 && $result5 && $result6 )
2009-09-28 01:22:00 +02:00
{
$db -> commit ();
2012-12-18 18:17:07 +01:00
header ( " Location: " . $_SERVER [ " PHP_SELF " ]);
2009-09-28 01:22:00 +02:00
exit ;
}
else
{
$db -> rollback ();
dol_print_error ( $db );
}
}
}
/*
* View
*/
2012-12-18 18:17:07 +01:00
$form = new Form ( $db );
2009-09-28 01:22:00 +02:00
llxHeader ();
2018-02-26 09:20:05 +01:00
$linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php?restore_lastsearch_values=1">' . $langs -> trans ( " BackToModuleList " ) . '</a>' ;
2015-09-24 18:33:48 +02:00
print load_fiche_titre ( $langs -> trans ( " FTPClientSetup " ), $linkback , 'title_setup' );
2009-09-28 01:22:00 +02:00
print '<br>' ;
if ( ! function_exists ( 'ftp_connect' ))
{
print $langs -> trans ( " FTPFeatureNotSupportedByYourPHP " );
}
else
{
2010-03-24 14:06:29 +01:00
2009-09-28 01:22:00 +02:00
// Formulaire ajout
print '<form name="ftpconfig" action="ftpclient.php" method="post">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2014-03-11 12:02:44 +01:00
print '<table class="noborder" width="100%">' ;
2009-09-28 01:22:00 +02:00
print '<tr class="liste_titre">' ;
print '<td colspan="2">' . $langs -> trans ( " NewFTPClient " ) . '</td>' ;
print '<td>' . $langs -> trans ( " Example " ) . '</td>' ;
print '</tr>' ;
2009-09-28 02:49:21 +02:00
print '<tr class="pair">' ;
print '<td>' . $langs -> trans ( " Label " ) . '</td>' ;
2012-12-18 18:17:07 +01:00
print '<td><input type="text" name="FTP_NAME_' . ( $lastftpentry + 1 ) . '" value="' . GETPOST ( " FTP_NAME_ " . ( $lastftpentry + 1 )) . '" size="64"></td>' ;
2009-09-28 02:49:21 +02:00
print '<td>My FTP access</td>' ;
print '</tr>' ;
2009-09-28 01:22:00 +02:00
print '<tr class="impair">' ;
print '<td>' . $langs -> trans ( " Server " ) . '</td>' ;
2012-12-18 18:17:07 +01:00
print '<td><input type="text" name="FTP_SERVER_' . ( $lastftpentry + 1 ) . '" value="' . GETPOST ( " FTP_SERVER_ " . ( $lastftpentry + 1 )) . '" size="64"></td>' ;
2009-09-28 01:22:00 +02:00
print '<td>localhost</td>' ;
print '</tr>' ;
print '<tr class="pair">' ;
print '<td width="100">' . $langs -> trans ( " Port " ) . '</td>' ;
2012-12-18 18:17:07 +01:00
print '<td><input type="text" name="FTP_PORT_' . ( $lastftpentry + 1 ) . '" value="' . GETPOST ( " FTP_PORT_ " . ( $lastftpentry + 1 )) . '" size="64"></td>' ;
2016-10-15 02:11:49 +02:00
print '<td>21 for pure non crypted FTP or if option FTP_CONNECT_WITH_SSL (See Home-Setup-Other) is on (FTPS)<br>22 if option FTP_CONNECT_WITH_SFTP (See Home-Setup-Other) is on (SFTP)</td>' ;
2009-09-28 01:22:00 +02:00
print '</tr>' ;
print '<tr class="impair">' ;
print '<td>' . $langs -> trans ( " User " ) . '</td>' ;
2012-12-18 18:17:07 +01:00
print '<td><input type="text" name="FTP_USER_' . ( $lastftpentry + 1 ) . '" value="' . GETPOST ( " FTP_USER_ " . ( $lastftpentry + 1 )) . '" size="24"></td>' ;
2009-09-28 01:22:00 +02:00
print '<td>myftplogin</td>' ;
print '</tr>' ;
print '<tr class="pair">' ;
print '<td>' . $langs -> trans ( " Password " ) . '</td>' ;
2012-12-18 18:17:07 +01:00
print '<td><input type="password" name="FTP_PASSWORD_' . ( $lastftpentry + 1 ) . '" value="' . GETPOST ( " FTP_PASSWORD_ " . ( $lastftpentry + 1 )) . '" size="24"></td>' ;
2009-09-28 01:22:00 +02:00
print '<td>myftppassword</td>' ;
print '</tr>' ;
2012-12-18 18:17:07 +01:00
print '<tr class="impair">' ;
2012-12-31 05:54:38 +01:00
print '<td>' . $langs -> trans ( " FTPPassiveMode " ) . '</td>' ;
2012-12-18 18:17:07 +01:00
$defaultpassive = GETPOST ( " FTP_PASSIVE_ " . ( $lastftpentry + 1 ));
if ( ! isset ( $_POST [ " FTP_PASSIVE_ " . ( $lastftpentry + 1 )])) $defaultpassive = empty ( $conf -> global -> FTP_SUGGEST_PASSIVE_BYDEFAULT ) ? 0 : 1 ;
2016-03-25 15:53:44 +01:00
print '<td>' . $form -> selectyesno ( 'FTP_PASSIVE_' . ( $lastftpentry + 1 ), $defaultpassive , 2 ) . '</td>' ;
2012-12-18 18:17:07 +01:00
print '<td>' . $langs -> trans ( " No " ) . '</td>' ;
print '</tr>' ;
2014-03-11 12:02:44 +01:00
print '</table>' ;
2014-11-25 20:40:00 +01:00
?>
< br >< div class = " center " >< input type = " submit " class = " button " value = " <?php echo $langs->trans ( " Add " ) ?> " ></ div >
2009-09-28 01:22:00 +02:00
< input type = " hidden " name = " action " value = " add " >
< input type = " hidden " name = " numero_entry " value = " <?php echo ( $lastftpentry +1) ?> " >
< ? php
print '</form>' ;
?>
< br >
< ? php
$sql = " select name, value, note from " . MAIN_DB_PREFIX . " const " ;
$sql .= " WHERE name like 'FTP_SERVER_%' " ;
$sql .= " ORDER BY name " ;
2014-06-12 11:31:53 +02:00
dol_syslog ( " ftpclient select ftp setup " , LOG_DEBUG );
2009-09-28 01:22:00 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
{
$num = $db -> num_rows ( $resql );
$i = 0 ;
while ( $i < $num )
{
$obj = $db -> fetch_object ( $resql );
2009-10-22 13:13:31 +02:00
preg_match ( '/([0-9]+)$/i' , $obj -> name , $reg );
2009-09-28 02:49:21 +02:00
$idrss = $reg [ 0 ];
//print "x".join(',',$reg)."=".$obj->name."=".$idrss;
2009-09-28 01:22:00 +02:00
print " <form name= \" externalrssconfig \" action= \" " . $_SERVER [ " PHP_SELF " ] . " \" method= \" post \" > " ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2016-10-25 02:33:40 +02:00
print '<input type="hidden" name="numero_entry" value="' . $idrss . '">' ;
print '<table class="noborder" width="100%">' . " \n " ;
2009-09-28 01:22:00 +02:00
2016-10-25 02:33:40 +02:00
print '<tr class="liste_titre">' ;
print '<td class="fieldtitle">' . $langs -> trans ( " FTP " ) . " " . ( $idrss ) . " </td> " ;
print '<td></td>' ;
2009-09-28 02:49:21 +02:00
print " </tr> " ;
2017-04-29 18:30:36 +02:00
$keyforname = " FTP_NAME_ " . $idrss ;
$keyforserver = " FTP_SERVER_ " . $idrss ;
$keyforport = " FTP_PORT_ " . $idrss ;
$keyforuser = " FTP_USER_ " . $idrss ;
$keyforpassword = " FTP_PASSWORD_ " . $idrss ;
$keyforpassive = " FTP_PASSIVE_ " . $idrss ;
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2009-09-28 02:49:21 +02:00
print " <td> " . $langs -> trans ( " Name " ) . " </td> " ;
2017-04-29 18:30:36 +02:00
print " <td><input type= \" text \" class= \" flat \" name= \" FTP_NAME_ " . $idrss . " \" value= \" " . $conf -> global -> $keyforname . " \" size= \" 64 \" ></td> " ;
2009-09-28 01:22:00 +02:00
print " </tr> " ;
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2009-09-28 01:22:00 +02:00
print " <td> " . $langs -> trans ( " Server " ) . " </td> " ;
2017-04-29 18:30:36 +02:00
print " <td><input type= \" text \" class= \" flat \" name= \" FTP_SERVER_ " . $idrss . " \" value= \" " . $conf -> global -> $keyforserver . " \" size= \" 64 \" ></td> " ;
2009-09-28 01:22:00 +02:00
print " </tr> " ;
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2009-09-28 01:22:00 +02:00
print " <td width= \" 100 \" > " . $langs -> trans ( " Port " ) . " </td> " ;
2017-04-29 18:30:36 +02:00
print " <td><input type= \" text \" class= \" flat \" name= \" FTP_PORT_ " . $idrss . " \" value= \" " . $conf -> global -> $keyforport . " \" size= \" 64 \" ></td> " ;
2009-09-28 01:22:00 +02:00
print " </tr> " ;
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2009-09-28 01:22:00 +02:00
print " <td width= \" 100 \" > " . $langs -> trans ( " User " ) . " </td> " ;
2017-04-29 18:30:36 +02:00
print " <td><input type= \" text \" class= \" flat \" name= \" FTP_USER_ " . $idrss . " \" value= \" " . $conf -> global -> $keyforuser . " \" size= \" 24 \" ></td> " ;
2009-09-28 01:22:00 +02:00
print " </tr> " ;
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2009-09-28 01:22:00 +02:00
print " <td width= \" 100 \" > " . $langs -> trans ( " Password " ) . " </td> " ;
2017-04-29 18:30:36 +02:00
print " <td><input type= \" password \" class= \" flat \" name= \" FTP_PASSWORD_ " . $idrss . " \" value= \" " . $conf -> global -> $keyforpassword . " \" size= \" 24 \" ></td> " ;
2009-09-28 01:22:00 +02:00
print " </tr> " ;
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2014-03-11 12:02:44 +01:00
print " <td width= \" 100 \" > " . $langs -> trans ( " FTPPassiveMode " ) . " </td> " ;
2017-04-29 18:30:36 +02:00
print '<td>' . $form -> selectyesno ( 'FTP_PASSIVE_' . $idrss , $conf -> global -> $keyforpassive , 1 ) . '</td>' ;
2012-12-18 18:17:07 +01:00
print " </tr> " ;
2009-09-28 01:22:00 +02:00
print " <tr> " ;
print " <td colspan= \" 2 \" align= \" center \" > " ;
print " <input type= \" submit \" class= \" button \" name= \" modify \" value= \" " . $langs -> trans ( " Modify " ) . " \" > " ;
print " " ;
print " <input type= \" submit \" class= \" button \" name= \" delete \" value= \" " . $langs -> trans ( " Delete " ) . " \" > " ;
print " </td> " ;
print " </tr> " ;
2016-10-25 02:33:40 +02:00
print '</table>' ;
2009-09-28 01:22:00 +02:00
print " </form> " ;
2016-10-25 02:33:40 +02:00
print '<br>' ;
2009-09-28 01:22:00 +02:00
$i ++ ;
}
}
else
{
dol_print_error ( $db );
}
}
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-12-18 18:17:07 +01:00
$db -> close ();