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 <https://www.gnu.org/licenses/>. 17 */ 18 19/** 20 * \file htdocs/ftp/admin/ftpclient.php 21 * \ingroup ftp 22 * \brief Admin page to setup FTP client module 23 */ 24 25require '../../main.inc.php'; 26require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; 27 28$langs->loadLangs(array("admin", "ftp")); 29 30// Security check 31if (!$user->admin) accessforbidden(); 32 33$def = array(); 34$lastftpentry = 0; 35 36$action = GETPOST('action', 'aZ09'); 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); 48if ($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} else { 54 dol_print_error($db); 55} 56 57if ($action == 'add' || GETPOST('modify', 'alpha')) 58{ 59 $ftp_name = "FTP_NAME_".$entry; // $_POST["numero_entry"]; 60 $ftp_server = "FTP_SERVER_".$entry; //$_POST["numero_entry"]; 61 62 $error = 0; 63 64 if (!GETPOST("$ftp_name", 'alpha')) 65 { 66 $error = 1; 67 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); 68 } 69 70 if (!GETPOST("$ftp_server", 'alpha')) 71 { 72 $error = 1; 73 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Server")), null, 'errors'); 74 } 75 76 if (!$error) 77 { 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) $result2 = dolibarr_set_const($db, "FTP_SERVER_".$entry, GETPOST($ftp_server, 'alpha'), 'chaine', 0, '', $conf->entity); 87 if ($result2) $result3 = dolibarr_set_const($db, "FTP_USER_".$entry, GETPOST($ftp_user, 'alpha'), 'chaine', 0, '', $conf->entity); 88 if ($result3) $result4 = dolibarr_set_const($db, "FTP_PASSWORD_".$entry, GETPOST($ftp_password, 'alpha'), 'chaine', 0, '', $conf->entity); 89 if ($result4) $result5 = dolibarr_set_const($db, "FTP_NAME_".$entry, GETPOST($ftp_name, 'alpha'), 'chaine', 0, '', $conf->entity); 90 if ($result5) $result6 = dolibarr_set_const($db, "FTP_PASSIVE_".$entry, GETPOST($ftp_passive, 'alpha'), 'chaine', 0, '', $conf->entity); 91 92 if ($result1 && $result2 && $result3 && $result4 && $result5 && $result6) 93 { 94 $db->commit(); 95 header("Location: ".$_SERVER["PHP_SELF"]); 96 exit; 97 } else { 98 $db->rollback(); 99 dol_print_error($db); 100 } 101 } 102} 103 104if (GETPOST('delete', 'alpha')) 105{ 106 if ($entry) 107 { 108 $db->begin(); 109 110 $result1 = dolibarr_del_const($db, "FTP_PORT_".$entry, $conf->entity); 111 if ($result1) $result2 = dolibarr_del_const($db, "FTP_SERVER_".$entry, $conf->entity); 112 if ($result2) $result3 = dolibarr_del_const($db, "FTP_USER_".$entry, $conf->entity); 113 if ($result3) $result4 = dolibarr_del_const($db, "FTP_PASSWORD_".$entry, $conf->entity); 114 if ($result4) $result5 = dolibarr_del_const($db, "FTP_NAME_".$entry, $conf->entity); 115 if ($result4) $result6 = dolibarr_del_const($db, "FTP_PASSIVE_".$entry, $conf->entity); 116 117 if ($result1 && $result2 && $result3 && $result4 && $result5 && $result6) 118 { 119 $db->commit(); 120 header("Location: ".$_SERVER["PHP_SELF"]); 121 exit; 122 } else { 123 $db->rollback(); 124 dol_print_error($db); 125 } 126 } 127} 128 129 130/* 131 * View 132 */ 133 134$form = new Form($db); 135 136llxHeader(); 137 138$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>'; 139print load_fiche_titre($langs->trans("FTPClientSetup"), $linkback, 'title_setup'); 140print '<br>'; 141 142if (!function_exists('ftp_connect')) 143{ 144 print $langs->trans("FTPFeatureNotSupportedByYourPHP"); 145} else { 146 // Formulaire ajout 147 print '<form name="ftpconfig" action="ftpclient.php" method="post">'; 148 print '<input type="hidden" name="token" value="'.newToken().'">'; 149 150 print '<table class="noborder centpercent">'; 151 print '<tr class="liste_titre">'; 152 print '<td colspan="2">'.$langs->trans("NewFTPClient").'</td>'; 153 print '<td>'.$langs->trans("Example").'</td>'; 154 print '</tr>'; 155 156 print '<tr class="pair">'; 157 print '<td>'.$langs->trans("Label").'</td>'; 158 print '<td><input type="text" name="FTP_NAME_'.($lastftpentry + 1).'" value="'.GETPOST("FTP_NAME_".($lastftpentry + 1)).'" size="64"></td>'; 159 print '<td>My FTP access</td>'; 160 print '</tr>'; 161 162 print '<tr class="impair">'; 163 print '<td>'.$langs->trans("Server").'</td>'; 164 print '<td><input type="text" name="FTP_SERVER_'.($lastftpentry + 1).'" value="'.GETPOST("FTP_SERVER_".($lastftpentry + 1)).'" size="64"></td>'; 165 print '<td>localhost</td>'; 166 print '</tr>'; 167 168 print '<tr class="pair">'; 169 print '<td width="100">'.$langs->trans("Port").'</td>'; 170 print '<td><input type="text" name="FTP_PORT_'.($lastftpentry + 1).'" value="'.GETPOST("FTP_PORT_".($lastftpentry + 1)).'" size="64"></td>'; 171 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>'; 172 print '</tr>'; 173 174 print '<tr class="impair">'; 175 print '<td>'.$langs->trans("User").'</td>'; 176 print '<td><input type="text" name="FTP_USER_'.($lastftpentry + 1).'" value="'.GETPOST("FTP_USER_".($lastftpentry + 1)).'" size="24"></td>'; 177 print '<td>myftplogin</td>'; 178 print '</tr>'; 179 180 print '<tr class="pair">'; 181 print '<td>'.$langs->trans("Password").'</td>'; 182 print '<td><input type="password" name="FTP_PASSWORD_'.($lastftpentry + 1).'" value="'.GETPOST("FTP_PASSWORD_".($lastftpentry + 1)).'" size="24"></td>'; 183 print '<td>myftppassword</td>'; 184 print '</tr>'; 185 186 print '<tr class="impair">'; 187 print '<td>'.$langs->trans("FTPPassiveMode").'</td>'; 188 $defaultpassive = GETPOST("FTP_PASSIVE_".($lastftpentry + 1)); 189 if (!isset($_POST["FTP_PASSIVE_".($lastftpentry + 1)])) $defaultpassive = empty($conf->global->FTP_SUGGEST_PASSIVE_BYDEFAULT) ? 0 : 1; 190 print '<td>'.$form->selectyesno('FTP_PASSIVE_'.($lastftpentry + 1), $defaultpassive, 2).'</td>'; 191 print '<td>'.$langs->trans("No").'</td>'; 192 print '</tr>'; 193 194 print '</table>'; 195 196 ?> 197 <br><div class="center"><input type="submit" class="button" value="<?php echo $langs->trans("Add") ?>"></div> 198 <input type="hidden" name="action" value="add"> 199 <input type="hidden" name="numero_entry" value="<?php echo ($lastftpentry + 1) ?>"> 200 <?php 201 print '</form>'; 202 ?> 203 204 <br> 205 206 <?php 207 208 $sql = "select name, value, note from ".MAIN_DB_PREFIX."const"; 209 $sql .= " WHERE name like 'FTP_SERVER_%'"; 210 $sql .= " ORDER BY name"; 211 212 dol_syslog("ftpclient select ftp setup", LOG_DEBUG); 213 $resql = $db->query($sql); 214 if ($resql) 215 { 216 $num = $db->num_rows($resql); 217 $i = 0; 218 219 while ($i < $num) 220 { 221 $obj = $db->fetch_object($resql); 222 223 preg_match('/([0-9]+)$/i', $obj->name, $reg); 224 $idrss = $reg[0]; 225 //print "x".join(',',$reg)."=".$obj->name."=".$idrss; 226 227 print "<form name=\"externalrssconfig\" action=\"".$_SERVER["PHP_SELF"]."\" method=\"post\">"; 228 print '<input type="hidden" name="token" value="'.newToken().'">'; 229 print '<input type="hidden" name="numero_entry" value="'.$idrss.'">'; 230 231 print '<table class="noborder centpercent">'."\n"; 232 233 print '<tr class="liste_titre">'; 234 print '<td class="fieldtitle">'.$langs->trans("FTP")." ".($idrss)."</td>"; 235 print '<td></td>'; 236 print "</tr>"; 237 238 $keyforname = "FTP_NAME_".$idrss; 239 $keyforserver = "FTP_SERVER_".$idrss; 240 $keyforport = "FTP_PORT_".$idrss; 241 $keyforuser = "FTP_USER_".$idrss; 242 $keyforpassword = "FTP_PASSWORD_".$idrss; 243 $keyforpassive = "FTP_PASSIVE_".$idrss; 244 245 print '<tr class="oddeven">'; 246 print "<td>".$langs->trans("Name")."</td>"; 247 print "<td><input type=\"text\" class=\"flat\" name=\"FTP_NAME_".$idrss."\" value=\"".$conf->global->$keyforname."\" size=\"64\"></td>"; 248 print "</tr>"; 249 250 251 print '<tr class="oddeven">'; 252 print "<td>".$langs->trans("Server")."</td>"; 253 print "<td><input type=\"text\" class=\"flat\" name=\"FTP_SERVER_".$idrss."\" value=\"".$conf->global->$keyforserver."\" size=\"64\"></td>"; 254 print "</tr>"; 255 256 257 print '<tr class="oddeven">'; 258 print "<td width=\"100\">".$langs->trans("Port")."</td>"; 259 print "<td><input type=\"text\" class=\"flat\" name=\"FTP_PORT_".$idrss."\" value=\"".$conf->global->$keyforport."\" size=\"64\"></td>"; 260 print "</tr>"; 261 262 263 print '<tr class="oddeven">'; 264 print "<td width=\"100\">".$langs->trans("User")."</td>"; 265 print "<td><input type=\"text\" class=\"flat\" name=\"FTP_USER_".$idrss."\" value=\"".$conf->global->$keyforuser."\" size=\"24\"></td>"; 266 print "</tr>"; 267 268 269 print '<tr class="oddeven">'; 270 print "<td width=\"100\">".$langs->trans("Password")."</td>"; 271 print "<td><input type=\"password\" class=\"flat\" name=\"FTP_PASSWORD_".$idrss."\" value=\"".$conf->global->$keyforpassword."\" size=\"24\"></td>"; 272 print "</tr>"; 273 274 275 print '<tr class="oddeven">'; 276 print "<td width=\"100\">".$langs->trans("FTPPassiveMode")."</td>"; 277 print '<td>'.$form->selectyesno('FTP_PASSIVE_'.$idrss, $conf->global->$keyforpassive, 1).'</td>'; 278 print "</tr>"; 279 280 print "<tr>"; 281 print "<td colspan=\"2\" class=\"center\">"; 282 print "<input type=\"submit\" class=\"button\" name=\"modify\" value=\"".$langs->trans("Modify")."\">"; 283 print " "; 284 print "<input type=\"submit\" class=\"button\" name=\"delete\" value=\"".$langs->trans("Delete")."\">"; 285 print "</td>"; 286 print "</tr>"; 287 288 print '</table>'; 289 290 print "</form>"; 291 print '<br>'; 292 293 $i++; 294 } 295 } else { 296 dol_print_error($db); 297 } 298} 299 300// End of page 301llxFooter(); 302$db->close(); 303