27require
'../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/lib/treeview.lib.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/lib/ftp.lib.php';
34$langs->loadLangs(array(
'companies',
'other'));
37$action =
GETPOST(
'action',
'aZ09');
39$newfolder =
GETPOST(
'newfolder');
43$numero_ftp =
GETPOST(
"numero_ftp");
48$upload_dir = $conf->ftp->dir_temp;
49$download_dir = $conf->ftp->dir_temp;
52$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
53$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
55if (empty($page) || $page == -1) {
58$offset = $limit * $page;
68$s_ftp_name =
'FTP_NAME_'.$numero_ftp;
69$s_ftp_server =
'FTP_SERVER_'.$numero_ftp;
70$s_ftp_port =
'FTP_PORT_'.$numero_ftp;
71$s_ftp_user =
'FTP_USER_'.$numero_ftp;
72$s_ftp_password =
'FTP_PASSWORD_'.$numero_ftp;
73$s_ftp_passive =
'FTP_PASSIVE_'.$numero_ftp;
77if (empty($ftp_port)) {
91 $socid = $user->socid;
100if ($action ==
'uploadfile' && $user->hasRight(
'ftp',
'write')) {
103 $newsectioniso = mb_convert_encoding($section,
'ISO-8859-1');
104 $resultarray =
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
105 $conn_id = $resultarray[
'conn_id'];
106 $ok = $resultarray[
'ok'];
107 $mesg = $resultarray[
'mesg'];
109 if ($conn_id && $ok && !$mesg) {
110 $nbfile = count($_FILES[
'userfile'][
'name']);
111 for ($i = 0; $i < $nbfile; $i++) {
112 $newsection = $newsectioniso;
115 $result =
dol_ftp_put($conn_id, $fileupload, $fileuploadpath, $newsection);
118 setEventMessages($langs->trans(
"FileWasUpload", $fileupload),
null,
'mesgs');
120 dol_syslog(
"ftp/index.php ftp_delete", LOG_ERR);
121 setEventMessages($langs->trans(
"FTPFailedToUploadFile", $fileupload),
null,
'errors');
130if ($action ==
'addfolder' && $user->hasRight(
'ftp',
'write')) {
133 $newsectioniso = mb_convert_encoding($section,
'ISO-8859-1');
134 $resultarray =
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
135 $conn_id = $resultarray[
'conn_id'];
136 $ok = $resultarray[
'ok'];
137 $mesg = $resultarray[
'mesg'];
139 if ($conn_id && $ok && !$mesg) {
140 $result =
dol_ftp_mkdir($conn_id, $newfolder, $newsectioniso);
143 setEventMessages($langs->trans(
"FileWasCreateFolder", $newfolder),
null,
'mesgs');
145 dol_syslog(
"ftp/index.php ftp_delete", LOG_ERR);
146 setEventMessages($langs->trans(
"FTPFailedToCreateFolder", $newfolder),
null,
'errors');
155if ($action ==
'add' && $user->hasRight(
'ftp',
'write')) {
158 $ecmdir->label =
GETPOST(
"label");
159 $ecmdir->description =
GETPOST(
"desc");
161 $id = $ecmdir->create($user);
163 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
172if ($action ==
'confirm_deletefile' &&
GETPOST(
'confirm') ==
'yes' && $user->hasRight(
'ftp',
'write')) {
175 $newsectioniso = mb_convert_encoding($section,
'ISO-8859-1');
176 $resultarray =
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
177 $conn_id = $resultarray[
'conn_id'];
178 $ok = $resultarray[
'ok'];
179 $mesg = $resultarray[
'mesg'];
182 if ($conn_id && $ok && !$mesg) {
183 $newsection = $section;
189 dol_syslog(
"ftp/index.php ftp_delete", LOG_ERR);
190 setEventMessages($langs->trans(
"FTPFailedToRemoveFile", $file),
null,
'errors');
200if (
GETPOST(
"const",
'array') &&
GETPOST(
"delete") &&
GETPOST(
"delete") == $langs->trans(
"Delete") && $user->hasRight(
'ftp',
'write')) {
203 $newsectioniso = mb_convert_encoding($section,
'ISO-8859-1');
204 $resultarray =
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
205 $conn_id = $resultarray[
'conn_id'];
206 $ok = $resultarray[
'ok'];
207 $mesg = $resultarray[
'mesg'];
210 if ($conn_id && $ok && !$mesg) {
211 foreach (
GETPOST(
'const',
'array') as $const) {
212 if (isset($const[
"check"])) {
213 $langs->load(
"other");
216 $file = $const[
"file"];
217 $newsection = $const[
"section"];
224 dol_syslog(
"ftp/index.php ftp_delete n files", LOG_ERR);
225 setEventMessages($langs->trans(
"FTPFailedToRemoveFile", $file),
null,
'errors');
239if ($action ==
'confirm_deletesection' && $confirm ==
'yes' && $user->hasRight(
'ftp',
'write')) {
242 $newsectioniso = mb_convert_encoding($section,
'ISO-8859-1');
243 $resultarray =
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
244 $conn_id = $resultarray[
'conn_id'];
245 $ok = $resultarray[
'ok'];
246 $mesg = $resultarray[
'mesg'];
249 if ($conn_id && $ok && !$mesg) {
250 $newsection = $section;
257 setEventMessages($langs->trans(
"FTPFailedToRemoveDir", $file),
null,
'errors');
269if ($action ==
'download' && $user->hasRight(
'ftp',
'read')) {
272 $newsectioniso = mb_convert_encoding($section,
'ISO-8859-1');
273 $resultarray =
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
274 $conn_id = $resultarray[
'conn_id'];
275 $ok = $resultarray[
'ok'];
276 $mesg = $resultarray[
'mesg'];
279 if ($conn_id && $ok && !$mesg) {
281 $localfile = tempnam($download_dir,
'dol_');
283 $newsection = $section;
285 $result =
dol_ftp_get($conn_id, $localfile, $file, $newsection);
292 $type =
'application/octet-stream';
293 if (GETPOSTISSET(
"type")) {
304 header(
'Content-Type: '.$type);
307 header(
'Content-Disposition: attachment; filename="'.$file.
'"');
309 header(
'Content-Disposition: inline; filename="'.$file.
'"');
313 header(
'Cache-Control: Public, must-revalidate');
314 header(
'Pragma: public');
316 readfile($localfile);
320 setEventMessages($langs->transnoentitiesnoconv(
'FailedToGetFile', $file),
null,
'errors');
337if ($conf->use_javascript_ajax) {
339<script
type=
"text/javascript">
340jQuery(document).ready(
function() {
341 jQuery(
"#delconst").hide();
343 jQuery(
".checkboxfordelete").click(
function() {
344 jQuery(
"#delconst").show();
347 $(
"#checkall").click(
function() {
348 $(
".checkboxfordelete").prop(
'checked',
true);
349 jQuery(
"#delconst").show();
351 $(
"#checknone").click(
function() {
352 $(
".checkboxfordelete").prop(
'checked',
false);
353 jQuery(
"#delconst").hide();
363$form =
new Form($db);
365$userstatic =
new User($db);
371print $langs->trans(
"FTPAreaDesc").
"<br>";
373if (!function_exists(
'ftp_connect')) {
374 print $langs->trans(
"FTPFeatureNotSupportedByYourPHP");
376 if (!empty($ftp_server)) {
378 if ($action ==
'delete') {
379 print $form->formconfirm($_SERVER[
"PHP_SELF"].
'?numero_ftp='.$numero_ftp.
'§ion='.urlencode(
GETPOST(
'section')).
'&file='.urlencode(
GETPOST(
'file')), $langs->trans(
'DeleteFile'), $langs->trans(
'ConfirmDeleteFile',
GETPOST(
'file')),
'confirm_deletefile',
'',
'', 1);
383 if ($action ==
'delete_section') {
384 print $form->formconfirm($_SERVER[
"PHP_SELF"].
'?numero_ftp='.$numero_ftp.
'§ion='.urlencode(
GETPOST(
'section')).
'&file='.urlencode(
GETPOST(
'file')), $langs->trans(
'DeleteSection'), $langs->trans(
'ConfirmDeleteSection',
GETPOST(
'file')),
'confirm_deletesection',
'',
'', 1);
387 print $langs->trans(
"Server").
': <b>'.$ftp_server.
'</b><br>';
388 print $langs->trans(
"Port").
': <b>'.$ftp_port.
'</b> '.($ftp_passive ?
"(Passive)" :
"(Active)").
'<br>';
389 print $langs->trans(
"User").
': <b>'.$ftp_user.
'</b><br>';
390 print $langs->trans(
"FTPs (FTP over SSH)").
': <b>'.
yn(
getDolGlobalString(
'FTP_CONNECT_WITH_SSL')).
'</b><br>';
391 print $langs->trans(
"SFTP (FTP as a subsystem of SSH)").
': <b>'.
yn(
getDolGlobalString(
'FTP_CONNECT_WITH_SFTP')).
'</b><br>';
392 print $langs->trans(
"Directory").
': ';
393 $sectionarray = preg_split(
'|[\/]|', $section);
396 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=refreshmanual&numero_ftp='.$numero_ftp.($newsection ?
'§ion='.urlencode($newsection) :
'').
'">';
401 foreach ($sectionarray as $val) {
410 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=refreshmanual&numero_ftp='.$numero_ftp.($newsection ?
'§ion='.urlencode($newsection) :
'').
'">';
418 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
419 print
'<input type="hidden" name="numero_ftp" value="'.$numero_ftp.
'">';
420 print
'<input type="hidden" name="token" value="'.newToken().
'">';
424 print
'<table width="100%" class="noborder">'.
"\n";
426 print
'<tr class="liste_titre">'.
"\n";
427 print
'<td class="liste_titre left">'.$langs->trans(
"Content").
'</td>'.
"\n";
428 print
'<td class="liste_titre center">'.$langs->trans(
"Size").
'</td>'.
"\n";
429 print
'<td class="liste_titre center">'.$langs->trans(
"Date").
'</td>'.
"\n";
430 print
'<td class="liste_titre center">'.$langs->trans(
"Owner").
'</td>'.
"\n";
431 print
'<td class="liste_titre center">'.$langs->trans(
"Group").
'</td>'.
"\n";
432 print
'<td class="liste_titre center">'.$langs->trans(
"Permissions").
'</td>'.
"\n";
433 print
'<td class="liste_titre nowrap right">';
434 if ($conf->use_javascript_ajax) {
435 print
'<a href="#" id="checkall">'.$langs->trans(
"All").
'</a> / <a href="#" id="checknone">'.$langs->trans(
"None").
'</a> ';
437 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=refreshmanual&numero_ftp='.$numero_ftp.($section ?
'§ion='.urlencode($section) :
'').
'">'.
img_picto($langs->trans(
"Refresh"),
'refresh').
'</a> ';
442 if (empty($conn_id)) {
443 $resultarray =
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive);
445 $conn_id = $resultarray[
'conn_id'];
446 $ok = $resultarray[
'ok'];
447 $mesg = $resultarray[
'mesg'];
453 $newsection = $section;
454 $newsectioniso = mb_convert_encoding($section,
'ISO-8859-1');
459 if ($newsection ==
'/') {
461 $newsection = ssh2_sftp_realpath($conn_id,
".").
'/./';
468 $contents = scandir(
'ssh2.sftp://'.intval($conn_id).$newsection);
470 foreach ($contents as $i => $key) {
471 $buff[$i] =
"---------- - root root 1234 Aug 01 2000 ".$key;
488 $buff = ftp_rawlist($conn_id, $newsectioniso);
489 $contents = ftp_nlist($conn_id, $newsectioniso);
492 $nboflines = count($contents);
493 $rawlisthasfailed =
false;
496 while ($i < $nboflines && $i < 1000) {
497 $vals = preg_split(
'@ +@', mb_convert_encoding($buff[$i],
'UTF-8',
'ISO-8859-1'), 9);
501 $rawlisthasfailed =
true;
502 $file = mb_convert_encoding($contents[$i],
'UTF-8',
'ISO-8859-1');
505 if ($file ==
'.' || ($file ==
'..' && $section ==
'/')) {
515 } elseif (!$rawlisthasfailed) {
516 if (preg_match(
'/^d/', $vals[0])) {
519 if (preg_match(
'/^l/', $vals[0])) {
528 $remotefile = $section.(preg_match(
'@[\\\/]$@', $section) ?
'' :
'/').preg_replace(
'@^[\\\/]@',
'', $file);
530 $newremotefileiso = mb_convert_encoding($remotefile,
'ISO-8859-1');
532 $is_directory =
ftp_isdir($conn_id, $newremotefileiso);
536 print
'<tr class="oddeven" height="18">';
539 $newsection = $section.(preg_match(
'@[\\\/]$@', $section) ?
'' :
'/').$file;
540 $newsection = preg_replace(
'@[\\\/][^\\\/]+[\\\/]\.\.$@',
'/', $newsection);
542 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?section='.urlencode($newsection).
'&numero_ftp='.$numero_ftp.
'">';
550 print
'<td class="center nowrap">';
551 if (!$is_directory && !$is_link) {
558 print
'<td class="center nowrap">';
559 print $vals[5].
' '.$vals[6].
' '.$vals[7];
562 print
'<td class="center nowrap">';
566 print
'<td class="center nowrap">';
570 print
'<td class="center nowrap">';
574 print
'<td class="right nowrap" width="64">';
577 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=delete_section&token='.
newToken().
'&numero_ftp='.$numero_ftp.
'§ion='.urlencode($section).
'&file='.urlencode($file).
'">'.
img_delete().
'</a>';
581 } elseif ($is_link) {
583 $newfile = preg_replace(
'/ ->.*/',
'', $newfile);
584 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=delete&token='.
newToken().
'&numero_ftp='.$numero_ftp.
'§ion='.urlencode($section).
'&file='.urlencode($newfile).
'">'.
img_delete().
'</a>';
586 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=download&token='.
newToken().
'&numero_ftp='.$numero_ftp.
'§ion='.urlencode($section).
'&file='.urlencode($file).
'">'.
img_picto(
'',
'file').
'</a>';
588 print
'<input type="checkbox" class="flat checkboxfordelete" id="check_'.$i.
'" name="const['.$i.
'][check]" value="1">';
590 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=delete&token='.
newToken().
'&numero_ftp='.$numero_ftp.
'§ion='.urlencode($section).
'&file='.urlencode($file).
'">'.
img_delete().
'</a>';
591 print
'<input type="hidden" name="const['.$i.
'][section]" value="'.$section.
'">';
592 print
'<input type="hidden" name="const['.$i.
'][file]" value="'.$file.
'">';
605 print $mesg.
'<br>'.
"\n";
613 print
'<div id="delconst" class="right">';
614 print
'<input type="submit" name="delete" class="button" value="'.$langs->trans(
"Delete").
'">';
619 if ($user->hasRight(
'ftp',
'write')) {
621 print
'<form enctype="multipart/form-data" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
622 print
'<input type="hidden" name="token" value="'.newToken().
'">';
623 print
'<input type="hidden" name="numero_ftp" value="'.$numero_ftp.
'">';
624 print
'<input type="hidden" name="section" value="'.$section.
'">';
625 print
'<input type="hidden" name="action" value="uploadfile">';
626 print
'<td><input type="file" class="flat" name="userfile[]" multiple></td>';
628 print
'<td align="center"><button type="submit" class="butAction" name="uploadfile" value="'.$langs->trans(
"Save").
'">'.$langs->trans(
"Upload").
'</button></td>';
634 print
'<form enctype="multipart/form-data" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
635 print
'<input type="hidden" name="token" value="'.newToken().
'">';
636 print
'<input type="hidden" name="numero_ftp" value="'.$numero_ftp.
'">';
637 print
'<input type="hidden" name="section" value="'.$section.
'">';
638 print
'<input type="hidden" name="action" value="addfolder">';
639 print
'<td><input type="text" class="flat" name="newfolder" multiple></td>';
641 print
'<td align="center"><button type="submit" class="butAction" name="addfolder" value="'.$langs->trans(
"Save").
'">'.$langs->trans(
"AddFolder").
'</button></td>';
648 while ($i <= $MAXFTP) {
649 $paramkey =
'FTP_NAME_'.$i;
658 print $langs->trans(
"SetupOfFTPClientModuleNotComplete");
660 print $langs->trans(
"ChooseAFTPEntryIntoMenu");
667if (!empty($conn_id)) {
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage ECM directories.
Class to manage Dolibarr users.
dol_ftp_mkdir($connect_id, $newdir, $newsection)
Remove FTP directory.
ftp_isdir($connect_id, $dir)
Tell if an entry is a FTP directory.
dol_ftp_close($connect_id)
Tell if an entry is a FTP directory.
dol_ftp_delete($connect_id, $file, $newsection)
Delete a FTP file.
dol_ftp_rmdir($connect_id, $file, $newsection)
Remove FTP directory.
dol_ftp_put($connect_id, $file, $localfile, $newsection)
Upload a FTP file.
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive=0)
Connect to FTP server.
dol_ftp_get($connect_id, $localfile, $file, $newsection)
Download a FTP file.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_sanitizePathName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a path name.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.