dolibarr  9.0.0
ftpclient.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004-2016 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 <http://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", "ftp"));
29 
30 // Security check
31 if (!$user->admin) accessforbidden();
32 
33 $def = array();
34 $lastftpentry=0;
35 
36 $action = GETPOST('action','alpha');
37 $entry = GETPOST('numero_entry','alpha');
38 
39 
40 /*
41  * Action
42  */
43 
44 // Get value for $lastftpentry
45 $sql ="select MAX(name) as name from ".MAIN_DB_PREFIX."const";
46 $sql.=" WHERE name like 'FTP_SERVER_%'";
47 $result=$db->query($sql);
48 if ($result)
49 {
50  $obj = $db->fetch_object($result);
51  preg_match('/([0-9]+)$/i',$obj->name,$reg);
52  if ($reg[1]) $lastftpentry = $reg[1];
53 }
54 else
55 {
56  dol_print_error($db);
57 }
58 
59 if ($action == 'add' || GETPOST('modify','alpha'))
60 {
61  $ftp_name = "FTP_NAME_" . $entry;// $_POST["numero_entry"];
62  $ftp_server = "FTP_SERVER_" . $entry; //$_POST["numero_entry"];
63 
64  $error=0;
65 
66  if (! GETPOST("$ftp_name",'alpha'))
67  {
68  $error=1;
69  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
70  }
71 
72  if (! GETPOST("$ftp_server",'alpha'))
73  {
74  $error=1;
75  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Server")), null, 'errors');
76  }
77 
78  if (! $error)
79  {
80  $ftp_port = "FTP_PORT_" . $entry;
81  $ftp_user = "FTP_USER_" . $entry;
82  $ftp_password = "FTP_PASSWORD_" . $entry;
83  $ftp_passive = "FTP_PASSIVE_" . $entry;
84 
85  $db->begin();
86 
87  $result1=dolibarr_set_const($db, "FTP_PORT_" . $entry,GETPOST($ftp_port,'alpha'),'chaine',0,'',$conf->entity);
88  if ($result1) $result2=dolibarr_set_const($db, "FTP_SERVER_" . $entry, GETPOST($ftp_server,'alpha'),'chaine',0,'',$conf->entity);
89  if ($result2) $result3=dolibarr_set_const($db, "FTP_USER_" . $entry,GETPOST($ftp_user,'alpha'),'chaine',0,'',$conf->entity);
90  if ($result3) $result4=dolibarr_set_const($db, "FTP_PASSWORD_" . $entry,GETPOST($ftp_password,'alpha'),'chaine',0,'',$conf->entity);
91  if ($result4) $result5=dolibarr_set_const($db, "FTP_NAME_" . $entry,GETPOST($ftp_name,'alpha'),'chaine',0,'',$conf->entity);
92  if ($result5) $result6=dolibarr_set_const($db, "FTP_PASSIVE_" . $entry,GETPOST($ftp_passive,'alpha'),'chaine',0,'',$conf->entity);
93 
94  if ($result1 && $result2 && $result3 && $result4 && $result5 && $result6)
95  {
96  $db->commit();
97  header("Location: ".$_SERVER["PHP_SELF"]);
98  exit;
99  }
100  else
101  {
102  $db->rollback();
103  dol_print_error($db);
104  }
105  }
106 }
107 
108 if (GETPOST('delete','alpha'))
109 {
110  if($entry)
111  {
112  $db->begin();
113 
114  $result1=dolibarr_del_const($db,"FTP_PORT_" . $entry,$conf->entity);
115  if ($result1) $result2=dolibarr_del_const($db,"FTP_SERVER_" . $entry,$conf->entity);
116  if ($result2) $result3=dolibarr_del_const($db,"FTP_USER_" . $entry,$conf->entity);
117  if ($result3) $result4=dolibarr_del_const($db,"FTP_PASSWORD_" . $entry,$conf->entity);
118  if ($result4) $result5=dolibarr_del_const($db,"FTP_NAME_" . $entry,$conf->entity);
119  if ($result4) $result6=dolibarr_del_const($db,"FTP_PASSIVE_" . $entry,$conf->entity);
120 
121  if ($result1 && $result2 && $result3 && $result4 && $result5 && $result6)
122  {
123  $db->commit();
124  header("Location: ".$_SERVER["PHP_SELF"]);
125  exit;
126  }
127  else
128  {
129  $db->rollback();
130  dol_print_error($db);
131  }
132  }
133 }
134 
135 
136 /*
137  * View
138  */
139 
140 $form=new Form($db);
141 
142 llxHeader();
143 
144 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
145 print load_fiche_titre($langs->trans("FTPClientSetup"), $linkback, 'title_setup');
146 print '<br>';
147 
148 if (! function_exists('ftp_connect'))
149 {
150  print $langs->trans("FTPFeatureNotSupportedByYourPHP");
151 }
152 else
153 {
154 
155  // Formulaire ajout
156  print '<form name="ftpconfig" action="ftpclient.php" method="post">';
157  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
158 
159  print '<table class="noborder" width="100%">';
160  print '<tr class="liste_titre">';
161  print '<td colspan="2">'.$langs->trans("NewFTPClient").'</td>';
162  print '<td>'.$langs->trans("Example").'</td>';
163  print '</tr>';
164 
165  print '<tr class="pair">';
166  print '<td>'.$langs->trans("Label").'</td>';
167  print '<td><input type="text" name="FTP_NAME_'.($lastftpentry+1).'" value="'.GETPOST("FTP_NAME_" . ($lastftpentry+1)).'" size="64"></td>';
168  print '<td>My FTP access</td>';
169  print '</tr>';
170 
171  print '<tr class="impair">';
172  print '<td>'.$langs->trans("Server").'</td>';
173  print '<td><input type="text" name="FTP_SERVER_'.($lastftpentry+1).'" value="'.GETPOST("FTP_SERVER_" . ($lastftpentry+1)).'" size="64"></td>';
174  print '<td>localhost</td>';
175  print '</tr>';
176 
177  print '<tr class="pair">';
178  print '<td width="100">'.$langs->trans("Port").'</td>';
179  print '<td><input type="text" name="FTP_PORT_'.($lastftpentry+1).'" value="'.GETPOST("FTP_PORT_" . ($lastftpentry+1)).'" size="64"></td>';
180  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>';
181  print '</tr>';
182 
183  print '<tr class="impair">';
184  print '<td>'.$langs->trans("User").'</td>';
185  print '<td><input type="text" name="FTP_USER_'.($lastftpentry+1).'" value="'.GETPOST("FTP_USER_" . ($lastftpentry+1)).'" size="24"></td>';
186  print '<td>myftplogin</td>';
187  print '</tr>';
188 
189  print '<tr class="pair">';
190  print '<td>'.$langs->trans("Password").'</td>';
191  print '<td><input type="password" name="FTP_PASSWORD_'.($lastftpentry+1).'" value="'.GETPOST("FTP_PASSWORD_" . ($lastftpentry+1)).'" size="24"></td>';
192  print '<td>myftppassword</td>';
193  print '</tr>';
194 
195  print '<tr class="impair">';
196  print '<td>'.$langs->trans("FTPPassiveMode").'</td>';
197  $defaultpassive=GETPOST("FTP_PASSIVE_" . ($lastftpentry+1));
198  if (! isset($_POST["FTP_PASSIVE_" . ($lastftpentry+1)])) $defaultpassive=empty($conf->global->FTP_SUGGEST_PASSIVE_BYDEFAULT)?0:1;
199  print '<td>'.$form->selectyesno('FTP_PASSIVE_'.($lastftpentry+1), $defaultpassive, 2).'</td>';
200  print '<td>'.$langs->trans("No").'</td>';
201  print '</tr>';
202 
203  print '</table>';
204 
205  ?>
206  <br><div class="center"><input type="submit" class="button" value="<?php echo $langs->trans("Add") ?>"></div>
207  <input type="hidden" name="action" value="add">
208  <input type="hidden" name="numero_entry" value="<?php echo ($lastftpentry+1) ?>">
209  <?php
210  print '</form>';
211  ?>
212 
213  <br>
214 
215  <?php
216 
217  $sql ="select name, value, note from ".MAIN_DB_PREFIX."const";
218  $sql.=" WHERE name like 'FTP_SERVER_%'";
219  $sql.=" ORDER BY name";
220 
221  dol_syslog("ftpclient select ftp setup", LOG_DEBUG);
222  $resql=$db->query($sql);
223  if ($resql)
224  {
225  $num =$db->num_rows($resql);
226  $i=0;
227 
228  while ($i < $num)
229  {
230  $obj = $db->fetch_object($resql);
231 
232  preg_match('/([0-9]+)$/i',$obj->name,$reg);
233  $idrss = $reg[0];
234  //print "x".join(',',$reg)."=".$obj->name."=".$idrss;
235 
236  print "<form name=\"externalrssconfig\" action=\"".$_SERVER["PHP_SELF"]."\" method=\"post\">";
237  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
238  print '<input type="hidden" name="numero_entry" value="'.$idrss.'">';
239 
240  print '<table class="noborder" width="100%">'."\n";
241 
242  print '<tr class="liste_titre">';
243  print '<td class="fieldtitle">'.$langs->trans("FTP")." ".($idrss)."</td>";
244  print '<td></td>';
245  print "</tr>";
246 
247  $keyforname="FTP_NAME_" . $idrss;
248  $keyforserver="FTP_SERVER_" . $idrss;
249  $keyforport="FTP_PORT_" . $idrss;
250  $keyforuser="FTP_USER_" . $idrss;
251  $keyforpassword="FTP_PASSWORD_" . $idrss;
252  $keyforpassive="FTP_PASSIVE_" . $idrss;
253 
254  print '<tr class="oddeven">';
255  print "<td>".$langs->trans("Name")."</td>";
256  print "<td><input type=\"text\" class=\"flat\" name=\"FTP_NAME_" . $idrss . "\" value=\"" . $conf->global->$keyforname . "\" size=\"64\"></td>";
257  print "</tr>";
258 
259 
260  print '<tr class="oddeven">';
261  print "<td>".$langs->trans("Server")."</td>";
262  print "<td><input type=\"text\" class=\"flat\" name=\"FTP_SERVER_" . $idrss . "\" value=\"" . $conf->global->$keyforserver . "\" size=\"64\"></td>";
263  print "</tr>";
264 
265 
266  print '<tr class="oddeven">';
267  print "<td width=\"100\">".$langs->trans("Port")."</td>";
268  print "<td><input type=\"text\" class=\"flat\" name=\"FTP_PORT_" . $idrss . "\" value=\"" . $conf->global->$keyforport . "\" size=\"64\"></td>";
269  print "</tr>";
270 
271 
272  print '<tr class="oddeven">';
273  print "<td width=\"100\">".$langs->trans("User")."</td>";
274  print "<td><input type=\"text\" class=\"flat\" name=\"FTP_USER_" . $idrss . "\" value=\"" . $conf->global->$keyforuser . "\" size=\"24\"></td>";
275  print "</tr>";
276 
277 
278  print '<tr class="oddeven">';
279  print "<td width=\"100\">".$langs->trans("Password")."</td>";
280  print "<td><input type=\"password\" class=\"flat\" name=\"FTP_PASSWORD_" . $idrss . "\" value=\"" . $conf->global->$keyforpassword . "\" size=\"24\"></td>";
281  print "</tr>";
282 
283 
284  print '<tr class="oddeven">';
285  print "<td width=\"100\">".$langs->trans("FTPPassiveMode")."</td>";
286  print '<td>'.$form->selectyesno('FTP_PASSIVE_'.$idrss, $conf->global->$keyforpassive, 1).'</td>';
287  print "</tr>";
288 
289  print "<tr>";
290  print "<td colspan=\"2\" align=\"center\">";
291  print "<input type=\"submit\" class=\"button\" name=\"modify\" value=\"".$langs->trans("Modify")."\">";
292  print " &nbsp; ";
293  print "<input type=\"submit\" class=\"button\" name=\"delete\" value=\"".$langs->trans("Delete")."\">";
294  print "</td>";
295  print "</tr>";
296 
297  print '</table>';
298 
299  print "</form>";
300  print '<br>';
301 
302  $i++;
303  }
304  }
305  else
306  {
307  dol_print_error($db);
308  }
309 }
310 
311 // End of page
312 llxFooter();
313 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
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:510
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:103
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
type
Definition: viewcat.php:284
dolibarr_del_const($db, $name, $entity=1)
Effacement d&#39;une constante dans la base de donnees.
Definition: admin.lib.php:435
llxHeader()
Empty header.
Definition: wrapper.php:44