dolibarr  16.0.5
ftpclient.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004-2022 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
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 <https://www.gnu.org/licenses/>.
17  */
18 
25 require '../../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
27 
28 $langs->loadLangs(array("admin", "other"));
29 
30 $def = array();
31 $lastftpentry = 0;
32 
33 $action = GETPOST('action', 'aZ09');
34 $entry = GETPOST('numero_entry', 'alpha');
35 
36 // Security check
37 if (!$user->admin) {
39 }
40 
41 
42 /*
43  * Action
44  */
45 
46 // Get value for $lastftpentry
47 $sql = "select MAX(name) as name from ".MAIN_DB_PREFIX."const";
48 $sql .= " WHERE name like 'FTP_SERVER_%'";
49 $result = $db->query($sql);
50 if ($result) {
51  $obj = $db->fetch_object($result);
52  $reg = array();
53  preg_match('/([0-9]+)$/i', $obj->name, $reg);
54  if (!empty($reg[1])) {
55  $lastftpentry = $reg[1];
56  }
57 } else {
58  dol_print_error($db);
59 }
60 
61 if ($action == 'add' || GETPOST('modify', 'alpha')) {
62  $ftp_name = "FTP_NAME_".$entry;
63  $ftp_server = "FTP_SERVER_".$entry;
64 
65  $error = 0;
66 
67  if (!GETPOST($ftp_name, 'alpha')) {
68  $error = 1;
69  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
70  }
71 
72  if (!GETPOST($ftp_server, 'alpha')) {
73  $error = 1;
74  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Server")), null, 'errors');
75  }
76 
77  if (!$error) {
78  $ftp_port = "FTP_PORT_".$entry;
79  $ftp_user = "FTP_USER_".$entry;
80  $ftp_password = "FTP_PASSWORD_".$entry;
81  $ftp_passive = "FTP_PASSIVE_".$entry;
82 
83  $db->begin();
84 
85  $result1 = dolibarr_set_const($db, "FTP_PORT_".$entry, GETPOST($ftp_port, 'alpha'), 'chaine', 0, '', $conf->entity);
86  if ($result1) {
87  $result2 = dolibarr_set_const($db, "FTP_SERVER_".$entry, GETPOST($ftp_server, 'alpha'), 'chaine', 0, '', $conf->entity);
88  }
89  if ($result2) {
90  $result3 = dolibarr_set_const($db, "FTP_USER_".$entry, GETPOST($ftp_user, 'alpha'), 'chaine', 0, '', $conf->entity);
91  }
92  if ($result3) {
93  $result4 = dolibarr_set_const($db, "FTP_PASSWORD_".$entry, GETPOST($ftp_password, 'alpha'), 'chaine', 0, '', $conf->entity);
94  }
95  if ($result4) {
96  $result5 = dolibarr_set_const($db, "FTP_NAME_".$entry, GETPOST($ftp_name, 'alpha'), 'chaine', 0, '', $conf->entity);
97  }
98  if ($result5) {
99  $result6 = dolibarr_set_const($db, "FTP_PASSIVE_".$entry, GETPOST($ftp_passive, 'alpha'), 'chaine', 0, '', $conf->entity);
100  }
101 
102  if ($result1 && $result2 && $result3 && $result4 && $result5 && $result6) {
103  $db->commit();
104  header("Location: ".$_SERVER["PHP_SELF"]);
105  exit;
106  } else {
107  $db->rollback();
108  dol_print_error($db);
109  }
110  }
111 }
112 
113 if (GETPOST('delete', 'alpha')) {
114  if ($entry) {
115  $db->begin();
116 
117  $result1 = dolibarr_del_const($db, "FTP_PORT_".$entry, $conf->entity);
118  if ($result1) {
119  $result2 = dolibarr_del_const($db, "FTP_SERVER_".$entry, $conf->entity);
120  }
121  if ($result2) {
122  $result3 = dolibarr_del_const($db, "FTP_USER_".$entry, $conf->entity);
123  }
124  if ($result3) {
125  $result4 = dolibarr_del_const($db, "FTP_PASSWORD_".$entry, $conf->entity);
126  }
127  if ($result4) {
128  $result5 = dolibarr_del_const($db, "FTP_NAME_".$entry, $conf->entity);
129  }
130  if ($result4) {
131  $result6 = dolibarr_del_const($db, "FTP_PASSIVE_".$entry, $conf->entity);
132  }
133 
134  if ($result1 && $result2 && $result3 && $result4 && $result5 && $result6) {
135  $db->commit();
136  header("Location: ".$_SERVER["PHP_SELF"]);
137  exit;
138  } else {
139  $db->rollback();
140  dol_print_error($db);
141  }
142  }
143 }
144 
145 
146 /*
147  * View
148  */
149 
150 $form = new Form($db);
151 
152 
153 $help_url = 'EN:Module_FTP_En|FR:Module_FTP|ES:Módulo_FTP';
154 
155 llxHeader('', 'FTP', $help_url);
156 
157 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
158 print load_fiche_titre($langs->trans("FTPClientSetup"), $linkback, 'title_setup');
159 print '<br>';
160 
161 if (!function_exists('ftp_connect')) {
162  print $langs->trans("FTPFeatureNotSupportedByYourPHP");
163 } else {
164  // Formulaire ajout
165  print '<form name="ftpconfig" action="ftpclient.php" method="post">';
166  print '<input type="hidden" name="token" value="'.newToken().'">';
167 
168  print '<table class="noborder centpercent">';
169  print '<tr class="liste_titre">';
170  print '<td colspan="2">'.$langs->trans("NewFTPClient").'</td>';
171  print '<td>'.$langs->trans("Example").'</td>';
172  print '</tr>';
173 
174  print '<tr class="oddeven">';
175  print '<td>'.$langs->trans("Label").'</td>';
176  print '<td><input type="text" name="FTP_NAME_'.($lastftpentry + 1).'" value="'.GETPOST("FTP_NAME_".($lastftpentry + 1)).'" size="64"></td>';
177  print '<td>My FTP access</td>';
178  print '</tr>';
179 
180  print '<tr class="oddeven">';
181  print '<td>'.$langs->trans("Server").'</td>';
182  print '<td><input type="text" name="FTP_SERVER_'.($lastftpentry + 1).'" value="'.GETPOST("FTP_SERVER_".($lastftpentry + 1)).'" size="64"></td>';
183  print '<td>localhost</td>';
184  print '</tr>';
185 
186  print '<tr class="oddeven">';
187  print '<td width="100">'.$langs->trans("Port").'</td>';
188  print '<td><input type="text" name="FTP_PORT_'.($lastftpentry + 1).'" value="'.GETPOST("FTP_PORT_".($lastftpentry + 1)).'" size="64"></td>';
189  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>';
190  print '</tr>';
191 
192  print '<tr class="oddeven">';
193  print '<td>'.$langs->trans("User").'</td>';
194  print '<td><input type="text" name="FTP_USER_'.($lastftpentry + 1).'" value="'.GETPOST("FTP_USER_".($lastftpentry + 1)).'" class="minwidth175"></td>';
195  print '<td>myftplogin</td>';
196  print '</tr>';
197 
198  print '<tr class="oddeven">';
199  print '<td>'.$langs->trans("Password").'</td>';
200  print '<td><input type="password" name="FTP_PASSWORD_'.($lastftpentry + 1).'" value="'.GETPOST("FTP_PASSWORD_".($lastftpentry + 1)).'" class="minwidth175"></td>';
201  print '<td>myftppassword</td>';
202  print '</tr>';
203 
204  print '<tr class="oddeven">';
205  print '<td>'.$langs->trans("FTPPassiveMode").'</td>';
206  $defaultpassive = GETPOST("FTP_PASSIVE_".($lastftpentry + 1));
207  if (!GETPOSTISSET("FTP_PASSIVE_".($lastftpentry + 1))) {
208  $defaultpassive = empty($conf->global->FTP_SUGGEST_PASSIVE_BYDEFAULT) ? 0 : 1;
209  }
210  print '<td>'.$form->selectyesno('FTP_PASSIVE_'.($lastftpentry + 1), $defaultpassive, 2).'</td>';
211  print '<td>'.$langs->trans("No").'</td>';
212  print '</tr>';
213 
214  print '</table>';
215 
216  ?>
217  <div class="center">
218  <input type="submit" class="button" value="<?php echo $langs->trans("Add") ?>"></div>
219  <input type="hidden" name="action" value="add">
220  <input type="hidden" name="numero_entry" value="<?php echo ($lastftpentry + 1) ?>">
221  <?php
222  print '</form>';
223  print '<br>';
224  ?>
225 
226  <br>
227 
228  <?php
229 
230  $sql = "select name, value, note from ".MAIN_DB_PREFIX."const";
231  $sql .= " WHERE name like 'FTP_SERVER_%'";
232  $sql .= " ORDER BY name";
233 
234  dol_syslog("ftpclient select ftp setup", LOG_DEBUG);
235  $resql = $db->query($sql);
236  if ($resql) {
237  $num = $db->num_rows($resql);
238  $i = 0;
239 
240  while ($i < $num) {
241  $obj = $db->fetch_object($resql);
242 
243  $reg = array();
244  preg_match('/([0-9]+)$/i', $obj->name, $reg);
245  $idrss = $reg[0];
246  //print "x".join(',',$reg)."=".$obj->name."=".$idrss;
247 
248  print '<br>';
249  print '<form name="externalrssconfig" action="'.$_SERVER["PHP_SELF"].'" method="post">';
250  print '<input type="hidden" name="token" value="'.newToken().'">';
251  print '<input type="hidden" name="numero_entry" value="'.$idrss.'">';
252 
253  print '<div class="div-table-responsive-no-min">';
254  print '<table class="noborder centpercent">'."\n";
255 
256  print '<tr class="liste_titre">';
257  print '<td class="fieldtitle">'.$langs->trans("FTP")." ".($idrss)."</td>";
258  print '<td></td>';
259  print "</tr>";
260 
261  $keyforname = "FTP_NAME_".$idrss;
262  $keyforserver = "FTP_SERVER_".$idrss;
263  $keyforport = "FTP_PORT_".$idrss;
264  $keyforuser = "FTP_USER_".$idrss;
265  $keyforpassword = "FTP_PASSWORD_".$idrss;
266  $keyforpassive = "FTP_PASSIVE_".$idrss;
267 
268  print '<tr class="oddeven">';
269  print "<td>".$langs->trans("Name")."</td>";
270  print "<td><input type=\"text\" class=\"flat\" name=\"FTP_NAME_".$idrss."\" value=\"".getDolGlobalString($keyforname)."\" size=\"64\"></td>";
271  print "</tr>";
272 
273 
274  print '<tr class="oddeven">';
275  print "<td>".$langs->trans("Server")."</td>";
276  print "<td><input type=\"text\" class=\"flat\" name=\"FTP_SERVER_".$idrss."\" value=\"".getDolGlobalString($keyforserver)."\" size=\"64\"></td>";
277  print "</tr>";
278 
279 
280  print '<tr class="oddeven">';
281  print "<td width=\"100\">".$langs->trans("Port")."</td>";
282  print "<td><input type=\"text\" class=\"flat\" name=\"FTP_PORT_".$idrss."\" value=\"".getDolGlobalString($keyforport)."\" size=\"64\"></td>";
283  print "</tr>";
284 
285 
286  print '<tr class="oddeven">';
287  print "<td width=\"100\">".$langs->trans("User")."</td>";
288  print "<td><input type=\"text\" class=\"flat\" name=\"FTP_USER_".$idrss."\" value=\"".getDolGlobalString($keyforuser)."\" size=\"24\"></td>";
289  print "</tr>";
290 
291 
292  print '<tr class="oddeven">';
293  print "<td width=\"100\">".$langs->trans("Password")."</td>";
294  print "<td><input type=\"password\" class=\"flat\" name=\"FTP_PASSWORD_".$idrss."\" value=\"".getDolGlobalString($keyforpassword)."\" size=\"24\"></td>";
295  print "</tr>";
296 
297 
298  print '<tr class="oddeven">';
299  print "<td width=\"100\">".$langs->trans("FTPPassiveMode")."</td>";
300  print '<td>'.$form->selectyesno('FTP_PASSIVE_'.$idrss, getDolGlobalString($keyforpassive), 1).'</td>';
301  print "</tr>";
302 
303  print '</table>';
304  print '</div>';
305 
306  print '<div class="center">';
307  print '<input type="submit" class="button" name="modify" value="'.$langs->trans("Modify").'">';
308  print " &nbsp; ";
309  print '<input type="submit" class="button" name="delete" value="'.$langs->trans("Delete").'">';
310  print '</center>';
311 
312  print "</form>";
313  print '<br><br>';
314 
315  $i++;
316  }
317  } else {
318  dol_print_error($db);
319  }
320 }
321 
322 // End of page
323 llxFooter();
324 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
dolibarr_del_const
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
Definition: admin.lib.php:552
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
name
$conf db name
Definition: repair.php:122
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:80
dolibarr_set_const
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
Definition: admin.lib.php:627
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59