* Copyright (C) 2011 Juanjo Menent * * 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 * the Free Software Foundation; either version 3 of the License, or * (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 * along with this program. If not, see . */ /** * \file htdocs/ftp/admin/ftpclient.php * \ingroup ftp * \brief Admin page to setup FTP client module */ // Load Dolibarr environment require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; $langs->loadLangs(array("admin", "other")); $def = array(); $lastftpentry = 0; $action = GETPOST('action', 'aZ09'); $entry = GETPOST('numero_entry', 'alpha'); // Security check if (!$user->admin) { accessforbidden(); } /* * Action */ // Get value for $lastftpentry $sql = "select MAX(name) as name from ".MAIN_DB_PREFIX."const"; $sql .= " WHERE name like 'FTP_SERVER_%'"; $result = $db->query($sql); if ($result) { $obj = $db->fetch_object($result); $reg = array(); preg_match('/([0-9]+)$/i', $obj->name, $reg); if (!empty($reg[1])) { $lastftpentry = $reg[1]; } } else { dol_print_error($db); } if ($action == 'add' || GETPOST('modify', 'alpha')) { $ftp_name = "FTP_NAME_".$entry; $ftp_server = "FTP_SERVER_".$entry; $error = 0; if (!GETPOST($ftp_name, 'alpha')) { $error = 1; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); } if (!GETPOST($ftp_server, 'alpha')) { $error = 1; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Server")), null, 'errors'); } if (!$error) { $ftp_port = "FTP_PORT_".$entry; $ftp_user = "FTP_USER_".$entry; $ftp_password = "FTP_PASSWORD_".$entry; $ftp_passive = "FTP_PASSIVE_".$entry; $db->begin(); $result1 = dolibarr_set_const($db, "FTP_PORT_".$entry, GETPOST($ftp_port, 'alpha'), 'chaine', 0, '', $conf->entity); 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) { $db->commit(); header("Location: ".$_SERVER["PHP_SELF"]); exit; } else { $db->rollback(); dol_print_error($db); } } } if (GETPOST('delete', 'alpha')) { if ($entry) { $db->begin(); $result1 = dolibarr_del_const($db, "FTP_PORT_".$entry, $conf->entity); 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) { $db->commit(); header("Location: ".$_SERVER["PHP_SELF"]); exit; } else { $db->rollback(); dol_print_error($db); } } } /* * View */ $form = new Form($db); $help_url = 'EN:Module_FTP_En|FR:Module_FTP|ES:Módulo_FTP'; llxHeader('', 'FTP', $help_url); $linkback = ''.$langs->trans("BackToModuleList").''; print load_fiche_titre($langs->trans("FTPClientSetup"), $linkback, 'title_setup'); print '
'; if (!function_exists('ftp_connect')) { print $langs->trans("FTPFeatureNotSupportedByYourPHP"); } else { // Formulaire ajout print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; $defaultpassive = GETPOST("FTP_PASSIVE_".($lastftpentry + 1)); if (!GETPOSTISSET("FTP_PASSIVE_".($lastftpentry + 1))) { $defaultpassive = !getDolGlobalString('FTP_SUGGEST_PASSIVE_BYDEFAULT') ? 0 : 1; } print ''; print ''; print ''; print '
'.$langs->trans("NewFTPClient").''.$langs->trans("Example").'
'.$langs->trans("Label").'My FTP access
'.$langs->trans("Server").'localhost
'.$langs->trans("Port").'21 for pure non encrypted FTP or if option FTP_CONNECT_WITH_SSL (See Home-Setup-Other) is on (FTPS)
22 if option FTP_CONNECT_WITH_SFTP (See Home-Setup-Other) is on (SFTP)
'.$langs->trans("User").'myftplogin
'.$langs->trans("Password").'myftppassword
'.$langs->trans("FTPPassiveMode").''.$form->selectyesno('FTP_PASSIVE_'.($lastftpentry + 1), $defaultpassive, 2).''.$langs->trans("No").'
'; ?>
">
'; print '
'; ?>
query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; while ($i < $num) { $obj = $db->fetch_object($resql); $reg = array(); preg_match('/([0-9]+)$/i', $obj->name, $reg); $idrss = $reg[0]; //print "x".join(',',$reg)."=".$obj->name."=".$idrss; print '
'; print ''; print ''; print ''; print '
'; print ''."\n"; print ''; print '"; print ''; print ""; $keyforname = "FTP_NAME_".$idrss; $keyforserver = "FTP_SERVER_".$idrss; $keyforport = "FTP_PORT_".$idrss; $keyforuser = "FTP_USER_".$idrss; $keyforpassword = "FTP_PASSWORD_".$idrss; $keyforpassive = "FTP_PASSIVE_".$idrss; print ''; print ""; print ""; print ""; print ''; print ""; print ""; print ""; print ''; print ""; print ""; print ""; print ''; print ""; print ""; print ""; print ''; print ""; print ""; print ""; print ''; print ""; print ''; print ""; print '
'.$langs->trans("FTP")." ".($idrss)."
".$langs->trans("Name")."
".$langs->trans("Server")."
".$langs->trans("Port")."
".$langs->trans("User")."
".$langs->trans("Password")."
".$langs->trans("FTPPassiveMode")."'.$form->selectyesno('FTP_PASSIVE_'.$idrss, getDolGlobalString($keyforpassive), 1).'
'; print '
'; print '
'; print ''; print "   "; print ''; print ''; print ""; print '

'; $i++; } } else { dol_print_error($db); } } // End of page llxFooter(); $db->close();