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