2009-09-28 01:22:00 +02:00
< ? php
2022-07-25 13:12:08 +02:00
/* Copyright ( C ) 2004 - 2022 Laurent Destailleur < eldy @ users . sourceforge . net >
2019-03-10 09:39:31 +01:00
* Copyright ( C ) 2011 Juanjo Menent < jmenent @ 2 byte . es >
2024-11-04 23:53:20 +01:00
* Copyright ( C ) 2024 Frédéric France < frederic . france @ free . fr >
2025-02-02 22:19:18 +01:00
* Copyright ( C ) 2025 MDW < mdeweerd @ users . noreply . github . com >
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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// 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
*/
2022-09-07 20:08:59 +02:00
// Load Dolibarr environment
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
2024-11-04 23:53:20 +01:00
/**
* @ var Conf $conf
* @ var DoliDB $db
* @ var HookManager $hookmanager
* @ var Translate $langs
* @ var User $user
*/
2022-07-03 11:47:40 +02:00
$langs -> loadLangs ( array ( " admin " , " other " ));
2009-09-28 01:22:00 +02:00
$def = array ();
2020-04-10 10:59:32 +02:00
$lastftpentry = 0 ;
2009-09-28 01:22:00 +02:00
2020-09-16 19:39:50 +02:00
$action = GETPOST ( 'action' , 'aZ09' );
2019-01-27 11:55:16 +01:00
$entry = GETPOST ( 'numero_entry' , 'alpha' );
2011-09-06 11:25:32 +02:00
2022-07-25 13:12:08 +02:00
// Security check
if ( ! $user -> admin ) {
accessforbidden ();
}
2025-02-02 22:19:18 +01:00
// Initialise variables
$result1 = 0 ;
$result2 = 0 ;
$result3 = 0 ;
$result4 = 0 ;
$result5 = 0 ;
$result6 = 0 ;
2016-10-25 02:33:40 +02:00
/*
* Action
*/
// Get value for $lastftpentry
2020-04-10 10:59:32 +02:00
$sql = " select MAX(name) as name from " . MAIN_DB_PREFIX . " const " ;
$sql .= " WHERE name like 'FTP_SERVER_%' " ;
$result = $db -> query ( $sql );
2021-02-26 17:59:31 +01:00
if ( $result ) {
2020-03-23 15:54:02 +01:00
$obj = $db -> fetch_object ( $result );
2022-07-25 13:12:08 +02:00
$reg = array ();
2020-03-23 15:54:02 +01:00
preg_match ( '/([0-9]+)$/i' , $obj -> name , $reg );
2022-07-25 13:12:08 +02:00
if ( ! empty ( $reg [ 1 ])) {
2021-02-26 17:59:31 +01:00
$lastftpentry = $reg [ 1 ];
}
2020-05-21 15:05:19 +02:00
} else {
2020-03-23 15:54:02 +01:00
dol_print_error ( $db );
2009-09-28 01:22:00 +02:00
}
2021-02-26 17:59:31 +01:00
if ( $action == 'add' || GETPOST ( 'modify' , 'alpha' )) {
2021-03-24 19:53:31 +01:00
$ftp_name = " FTP_NAME_ " . $entry ;
$ftp_server = " FTP_SERVER_ " . $entry ;
2009-09-28 01:22:00 +02:00
2020-04-10 10:59:32 +02:00
$error = 0 ;
2010-03-24 14:06:29 +01:00
2022-07-25 13:12:08 +02:00
if ( ! GETPOST ( $ftp_name , 'alpha' )) {
2020-04-10 10:59:32 +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
2022-07-25 13:12:08 +02:00
if ( ! GETPOST ( $ftp_server , 'alpha' )) {
2020-04-10 10:59:32 +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
2021-02-26 17:59:31 +01:00
if ( ! $error ) {
2020-04-10 10:59:32 +02:00
$ftp_port = " FTP_PORT_ " . $entry ;
$ftp_user = " FTP_USER_ " . $entry ;
$ftp_password = " FTP_PASSWORD_ " . $entry ;
$ftp_passive = " FTP_PASSIVE_ " . $entry ;
2009-09-28 01:22:00 +02:00
2020-03-23 15:54:02 +01:00
$db -> begin ();
2009-09-28 01:22:00 +02:00
2020-04-10 10:59:32 +02:00
$result1 = dolibarr_set_const ( $db , " FTP_PORT_ " . $entry , GETPOST ( $ftp_port , 'alpha' ), 'chaine' , 0 , '' , $conf -> entity );
2021-02-26 17:59:31 +01:00
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 );
}
if ( $result5 ) {
$result6 = dolibarr_set_const ( $db , " FTP_PASSIVE_ " . $entry , GETPOST ( $ftp_passive , 'alpha' ), 'chaine' , 0 , '' , $conf -> entity );
}
if ( $result1 && $result2 && $result3 && $result4 && $result5 && $result6 ) {
2020-03-23 15:54:02 +01:00
$db -> commit ();
header ( " Location: " . $_SERVER [ " PHP_SELF " ]);
exit ;
2020-05-21 15:05:19 +02:00
} else {
2020-03-23 15:54:02 +01:00
$db -> rollback ();
dol_print_error ( $db );
}
}
2009-09-28 01:22:00 +02:00
}
2021-02-26 17:59:31 +01:00
if ( GETPOST ( 'delete' , 'alpha' )) {
if ( $entry ) {
2020-03-23 15:54:02 +01:00
$db -> begin ();
2009-09-28 01:22:00 +02:00
2020-04-10 10:59:32 +02:00
$result1 = dolibarr_del_const ( $db , " FTP_PORT_ " . $entry , $conf -> entity );
2021-02-26 17:59:31 +01:00
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 );
}
if ( $result4 ) {
$result6 = dolibarr_del_const ( $db , " FTP_PASSIVE_ " . $entry , $conf -> entity );
}
if ( $result1 && $result2 && $result3 && $result4 && $result5 && $result6 ) {
2020-10-31 14:32:18 +01:00
$db -> commit ();
header ( " Location: " . $_SERVER [ " PHP_SELF " ]);
exit ;
} else {
$db -> rollback ();
dol_print_error ( $db );
}
}
2009-09-28 01:22:00 +02:00
}
/*
* View
*/
2020-04-10 10:59:32 +02:00
$form = new Form ( $db );
2012-12-18 18:17:07 +01:00
2021-03-17 17:57:07 +01:00
$help_url = 'EN:Module_FTP_En|FR:Module_FTP|ES:Módulo_FTP' ;
llxHeader ( '' , 'FTP' , $help_url );
2009-09-28 01:22:00 +02:00
2020-04-10 10:59:32 +02: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>' ;
2021-02-26 17:59:31 +01:00
if ( ! function_exists ( 'ftp_connect' )) {
2009-09-28 01:22:00 +02:00
print $langs -> trans ( " FTPFeatureNotSupportedByYourPHP " );
2020-05-21 15:05:19 +02:00
} else {
2009-09-28 01:22:00 +02:00
// Formulaire ajout
print '<form name="ftpconfig" action="ftpclient.php" method="post">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2009-09-28 01:22:00 +02:00
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
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>' ;
2022-07-25 13:12:08 +02:00
print '<tr class="oddeven">' ;
2009-09-28 02:49:21 +02:00
print '<td>' . $langs -> trans ( " Label " ) . '</td>' ;
2020-04-10 10:59:32 +02: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>' ;
2022-07-25 13:12:08 +02:00
print '<tr class="oddeven">' ;
2009-09-28 01:22:00 +02:00
print '<td>' . $langs -> trans ( " Server " ) . '</td>' ;
2020-04-10 10:59:32 +02: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>' ;
2022-07-25 13:12:08 +02:00
print '<tr class="oddeven">' ;
2009-09-28 01:22:00 +02:00
print '<td width="100">' . $langs -> trans ( " Port " ) . '</td>' ;
2020-04-10 10:59:32 +02:00
print '<td><input type="text" name="FTP_PORT_' . ( $lastftpentry + 1 ) . '" value="' . GETPOST ( " FTP_PORT_ " . ( $lastftpentry + 1 )) . '" size="64"></td>' ;
2024-01-11 10:07:06 +01:00
print '<td>21 for pure non encrypted 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>' ;
2022-07-25 13:12:08 +02:00
print '<tr class="oddeven">' ;
2009-09-28 01:22:00 +02:00
print '<td>' . $langs -> trans ( " User " ) . '</td>' ;
2021-06-13 01:27:04 +02:00
print '<td><input type="text" name="FTP_USER_' . ( $lastftpentry + 1 ) . '" value="' . GETPOST ( " FTP_USER_ " . ( $lastftpentry + 1 )) . '" class="minwidth175"></td>' ;
2009-09-28 01:22:00 +02:00
print '<td>myftplogin</td>' ;
print '</tr>' ;
2022-07-25 13:12:08 +02:00
print '<tr class="oddeven">' ;
2009-09-28 01:22:00 +02:00
print '<td>' . $langs -> trans ( " Password " ) . '</td>' ;
2021-06-13 01:27:04 +02:00
print '<td><input type="password" name="FTP_PASSWORD_' . ( $lastftpentry + 1 ) . '" value="' . GETPOST ( " FTP_PASSWORD_ " . ( $lastftpentry + 1 )) . '" class="minwidth175"></td>' ;
2009-09-28 01:22:00 +02:00
print '<td>myftppassword</td>' ;
print '</tr>' ;
2022-07-25 13:12:08 +02:00
print '<tr class="oddeven">' ;
2012-12-31 05:54:38 +01:00
print '<td>' . $langs -> trans ( " FTPPassiveMode " ) . '</td>' ;
2020-04-10 10:59:32 +02:00
$defaultpassive = GETPOST ( " FTP_PASSIVE_ " . ( $lastftpentry + 1 ));
2021-03-24 19:53:31 +01:00
if ( ! GETPOSTISSET ( " FTP_PASSIVE_ " . ( $lastftpentry + 1 ))) {
2023-11-27 11:41:05 +01:00
$defaultpassive = ! getDolGlobalString ( 'FTP_SUGGEST_PASSIVE_BYDEFAULT' ) ? 0 : 1 ;
2021-02-26 17:59:31 +01:00
}
2020-04-10 10:59:32 +02: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>' ;
2019-03-10 09:39:31 +01:00
2023-12-04 12:12:12 +01:00
print '</table>' ; ?>
2022-07-25 13:12:08 +02:00
< 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 " >
2023-12-04 12:12:12 +01:00
< input type = " hidden " name = " numero_entry " value = " <?php echo( $lastftpentry + 1) ?> " >
2009-09-28 01:22:00 +02:00
< ? php
print '</form>' ;
2023-12-04 12:12:12 +01:00
print '<br>' ; ?>
2009-09-28 01:22:00 +02:00
< br >
< ? php
2020-04-10 10:59:32 +02:00
$sql = " select name, value, note from " . MAIN_DB_PREFIX . " const " ;
$sql .= " WHERE name like 'FTP_SERVER_%' " ;
$sql .= " ORDER BY name " ;
2009-09-28 01:22:00 +02:00
2014-06-12 11:31:53 +02:00
dol_syslog ( " ftpclient select ftp setup " , LOG_DEBUG );
2020-04-10 10:59:32 +02:00
$resql = $db -> query ( $sql );
2021-02-26 17:59:31 +01:00
if ( $resql ) {
2020-04-10 10:59:32 +02:00
$num = $db -> num_rows ( $resql );
$i = 0 ;
2009-09-28 01:22:00 +02:00
2021-02-26 17:59:31 +01:00
while ( $i < $num ) {
2009-09-28 01:22:00 +02:00
$obj = $db -> fetch_object ( $resql );
2021-04-25 15:55:36 +02:00
$reg = array ();
2020-03-23 15:54:02 +01: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
2022-07-25 13:12:08 +02:00
print '<br>' ;
print '<form name="externalrssconfig" action="' . $_SERVER [ " PHP_SELF " ] . '" method="post">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2016-10-25 02:33:40 +02:00
print '<input type="hidden" name="numero_entry" value="' . $idrss . '">' ;
2019-03-10 09:39:31 +01:00
2022-07-25 13:12:08 +02:00
print '<div class="div-table-responsive-no-min">' ;
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' . " \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> " ;
2020-04-10 10:59:32 +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 ;
2019-03-10 09:39:31 +01:00
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> " ;
2022-07-25 13:12:08 +02:00
print " <td><input type= \" text \" class= \" flat \" name= \" FTP_NAME_ " . $idrss . " \" value= \" " . getDolGlobalString ( $keyforname ) . " \" size= \" 64 \" ></td> " ;
2009-09-28 01:22:00 +02:00
print " </tr> " ;
2019-03-10 09:39:31 +01:00
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> " ;
2022-07-25 13:12:08 +02:00
print " <td><input type= \" text \" class= \" flat \" name= \" FTP_SERVER_ " . $idrss . " \" value= \" " . getDolGlobalString ( $keyforserver ) . " \" size= \" 64 \" ></td> " ;
2009-09-28 01:22:00 +02:00
print " </tr> " ;
2019-03-10 09:39:31 +01:00
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> " ;
2022-07-25 13:12:08 +02:00
print " <td><input type= \" text \" class= \" flat \" name= \" FTP_PORT_ " . $idrss . " \" value= \" " . getDolGlobalString ( $keyforport ) . " \" size= \" 64 \" ></td> " ;
2009-09-28 01:22:00 +02:00
print " </tr> " ;
2019-03-10 09:39:31 +01:00
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> " ;
2022-07-25 13:12:08 +02:00
print " <td><input type= \" text \" class= \" flat \" name= \" FTP_USER_ " . $idrss . " \" value= \" " . getDolGlobalString ( $keyforuser ) . " \" size= \" 24 \" ></td> " ;
2009-09-28 01:22:00 +02:00
print " </tr> " ;
2019-03-10 09:39:31 +01:00
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> " ;
2022-07-25 13:12:08 +02:00
print " <td><input type= \" password \" class= \" flat \" name= \" FTP_PASSWORD_ " . $idrss . " \" value= \" " . getDolGlobalString ( $keyforpassword ) . " \" size= \" 24 \" ></td> " ;
2009-09-28 01:22:00 +02:00
print " </tr> " ;
2019-03-10 09:39:31 +01:00
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> " ;
2022-07-25 13:12:08 +02:00
print '<td>' . $form -> selectyesno ( 'FTP_PASSIVE_' . $idrss , getDolGlobalString ( $keyforpassive ), 1 ) . '</td>' ;
2009-09-28 01:22:00 +02:00
print " </tr> " ;
2016-10-25 02:33:40 +02:00
print '</table>' ;
2022-07-25 13:12:08 +02:00
print '</div>' ;
print '<div class="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 '</center>' ;
2019-03-10 09:39:31 +01:00
2009-09-28 01:22:00 +02:00
print " </form> " ;
2022-07-25 13:12:08 +02:00
print '<br><br>' ;
2019-03-10 09:39:31 +01:00
2009-09-28 01:22:00 +02:00
$i ++ ;
}
2020-05-21 15:05:19 +02:00
} else {
2009-09-28 01:22:00 +02:00
dol_print_error ( $db );
}
}
2018-08-13 10:20:21 +02:00
// End of page
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-12-18 18:17:07 +01:00
$db -> close ();