28require
'../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/lib/treeview.lib.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/lib/ftp.lib.php';
43$langs->loadLangs(array(
'companies',
'other'));
46$action =
GETPOST(
'action',
'aZ09');
48$newfolder =
GETPOST(
'newfolder');
52$numero_ftp =
GETPOST(
"numero_ftp");
57$upload_dir =
$conf->ftp->dir_temp;
58$download_dir =
$conf->ftp->dir_temp;
61$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
62$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
64if (empty($page) || $page == -1) {
67$offset = $limit * $page;
77$s_ftp_name =
'FTP_NAME_'.$numero_ftp;
78$s_ftp_server =
'FTP_SERVER_'.$numero_ftp;
79$s_ftp_port =
'FTP_PORT_'.$numero_ftp;
80$s_ftp_user =
'FTP_USER_'.$numero_ftp;
81$s_ftp_password =
'FTP_PASSWORD_'.$numero_ftp;
82$s_ftp_passive =
'FTP_PASSIVE_'.$numero_ftp;
86if (empty($ftp_port)) {
100 $socid = $user->socid;
109if ($action ==
'uploadfile' && $user->hasRight(
'ftp',
'write')) {
112 $newsectioniso = mb_convert_encoding($section,
'ISO-8859-1');
113 $resultarray =
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
114 $conn_id = $resultarray[
'conn_id'];
115 $ok = $resultarray[
'ok'];
116 $mesg = $resultarray[
'mesg'];
118 if ($conn_id && $ok && !$mesg) {
119 $nbfile = count($_FILES[
'userfile'][
'name']);
120 for ($i = 0; $i < $nbfile; $i++) {
121 $newsection = $newsectioniso;
124 $result =
dol_ftp_put($conn_id, $fileupload, $fileuploadpath, $newsection);
127 setEventMessages($langs->trans(
"FileWasUpload", $fileupload),
null,
'mesgs');
129 dol_syslog(
"ftp/index.php ftp_delete", LOG_ERR);
130 setEventMessages($langs->trans(
"FTPFailedToUploadFile", $fileupload),
null,
'errors');
139if ($action ==
'addfolder' && $user->hasRight(
'ftp',
'write')) {
142 $newsectioniso = mb_convert_encoding($section,
'ISO-8859-1');
143 $resultarray =
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
144 $conn_id = $resultarray[
'conn_id'];
145 $ok = $resultarray[
'ok'];
146 $mesg = $resultarray[
'mesg'];
148 if ($conn_id && $ok && !$mesg) {
149 $result =
dol_ftp_mkdir($conn_id, $newfolder, $newsectioniso);
152 setEventMessages($langs->trans(
"FileWasCreateFolder", $newfolder),
null,
'mesgs');
154 dol_syslog(
"ftp/index.php ftp_delete", LOG_ERR);
155 setEventMessages($langs->trans(
"FTPFailedToCreateFolder", $newfolder),
null,
'errors');
164if ($action ==
'add' && $user->hasRight(
'ftp',
'write')) {
167 $ecmdir->label =
GETPOST(
"label");
168 $ecmdir->description =
GETPOST(
"desc");
170 $id = $ecmdir->create($user);
172 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
181if ($action ==
'confirm_deletefile' &&
GETPOST(
'confirm') ==
'yes' && $user->hasRight(
'ftp',
'write')) {
184 $newsectioniso = mb_convert_encoding($section,
'ISO-8859-1');
185 $resultarray =
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
186 $conn_id = $resultarray[
'conn_id'];
187 $ok = $resultarray[
'ok'];
188 $mesg = $resultarray[
'mesg'];
191 if ($conn_id && $ok && !$mesg) {
192 $newsection = $section;
198 dol_syslog(
"ftp/index.php ftp_delete", LOG_ERR);
199 setEventMessages($langs->trans(
"FTPFailedToRemoveFile", $file),
null,
'errors');
209if (
GETPOST(
"const",
'array') &&
GETPOST(
"delete") &&
GETPOST(
"delete") == $langs->trans(
"Delete") && $user->hasRight(
'ftp',
'write')) {
212 $newsectioniso = mb_convert_encoding($section,
'ISO-8859-1');
213 $resultarray =
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
214 $conn_id = $resultarray[
'conn_id'];
215 $ok = $resultarray[
'ok'];
216 $mesg = $resultarray[
'mesg'];
219 if ($conn_id && $ok && !$mesg) {
220 foreach (
GETPOST(
'const',
'array') as $const) {
221 if (isset($const[
"check"])) {
222 $langs->load(
"other");
225 $file = $const[
"file"];
226 $newsection = $const[
"section"];
233 dol_syslog(
"ftp/index.php ftp_delete n files", LOG_ERR);
234 setEventMessages($langs->trans(
"FTPFailedToRemoveFile", $file),
null,
'errors');
248if ($action ==
'confirm_deletesection' && $confirm ==
'yes' && $user->hasRight(
'ftp',
'write')) {
251 $newsectioniso = mb_convert_encoding($section,
'ISO-8859-1');
252 $resultarray =
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
253 $conn_id = $resultarray[
'conn_id'];
254 $ok = $resultarray[
'ok'];
255 $mesg = $resultarray[
'mesg'];
258 if ($conn_id && $ok && !$mesg) {
259 $newsection = $section;
266 setEventMessages($langs->trans(
"FTPFailedToRemoveDir", $file),
null,
'errors');
278if ($action ==
'download' && $user->hasRight(
'ftp',
'read')) {
281 $newsectioniso = mb_convert_encoding($section,
'ISO-8859-1');
282 $resultarray =
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
283 $conn_id = $resultarray[
'conn_id'];
284 $ok = $resultarray[
'ok'];
285 $mesg = $resultarray[
'mesg'];
288 if ($conn_id && $ok && !$mesg) {
290 $localfile = tempnam($download_dir,
'dol_');
292 $newsection = $section;
294 $result =
dol_ftp_get($conn_id, $localfile, $file, $newsection);
301 $type =
'application/octet-stream';
302 if (GETPOSTISSET(
"type")) {
313 header(
'Content-Type: '.$type);
316 header(
'Content-Disposition: attachment; filename="'.$file.
'"');
318 header(
'Content-Disposition: inline; filename="'.$file.
'"');
322 header(
'Cache-Control: Public, must-revalidate');
323 header(
'Pragma: public');
325 readfile($localfile);
329 setEventMessages($langs->transnoentitiesnoconv(
'FailedToGetFile', $file),
null,
'errors');
346if (
$conf->use_javascript_ajax) {
348<script
type=
"text/javascript">
349jQuery(document).ready(
function() {
350 jQuery(
"#delconst").hide();
352 jQuery(
".checkboxfordelete").click(
function() {
353 jQuery(
"#delconst").show();
356 $(
"#checkall").click(
function() {
357 $(
".checkboxfordelete").prop(
'checked',
true);
358 jQuery(
"#delconst").show();
360 $(
"#checknone").click(
function() {
361 $(
".checkboxfordelete").prop(
'checked',
false);
362 jQuery(
"#delconst").hide();
372$form =
new Form($db);
374$userstatic =
new User($db);
380print $langs->trans(
"FTPAreaDesc").
"<br>";
382if (!function_exists(
'ftp_connect')) {
383 print $langs->trans(
"FTPFeatureNotSupportedByYourPHP");
385 if (!empty($ftp_server)) {
387 if ($action ==
'delete') {
388 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);
392 if ($action ==
'delete_section') {
393 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);
396 print $langs->trans(
"Server").
': <b>'.$ftp_server.
'</b><br>';
397 print $langs->trans(
"Port").
': <b>'.$ftp_port.
'</b> '.($ftp_passive ?
"(Passive)" :
"(Active)").
'<br>';
398 print $langs->trans(
"User").
': <b>'.$ftp_user.
'</b><br>';
399 print $langs->trans(
"FTPs (FTP over SSH)").
': <b>'.
yn(
getDolGlobalString(
'FTP_CONNECT_WITH_SSL')).
'</b><br>';
400 print $langs->trans(
"SFTP (FTP as a subsystem of SSH)").
': <b>'.
yn(
getDolGlobalString(
'FTP_CONNECT_WITH_SFTP')).
'</b><br>';
401 print $langs->trans(
"Directory").
': ';
402 $sectionarray = preg_split(
'|[\/]|', $section);
405 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=refreshmanual&numero_ftp='.$numero_ftp.($newsection ?
'§ion='.urlencode($newsection) :
'').
'">';
410 foreach ($sectionarray as $val) {
419 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=refreshmanual&numero_ftp='.$numero_ftp.($newsection ?
'§ion='.urlencode($newsection) :
'').
'">';
427 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
428 print
'<input type="hidden" name="numero_ftp" value="'.$numero_ftp.
'">';
429 print
'<input type="hidden" name="token" value="'.newToken().
'">';
433 print
'<table width="100%" class="noborder">'.
"\n";
435 print
'<tr class="liste_titre">'.
"\n";
436 print
'<td class="liste_titre left">'.$langs->trans(
"Content").
'</td>'.
"\n";
437 print
'<td class="liste_titre center">'.$langs->trans(
"Size").
'</td>'.
"\n";
438 print
'<td class="liste_titre center">'.$langs->trans(
"Date").
'</td>'.
"\n";
439 print
'<td class="liste_titre center">'.$langs->trans(
"Owner").
'</td>'.
"\n";
440 print
'<td class="liste_titre center">'.$langs->trans(
"Group").
'</td>'.
"\n";
441 print
'<td class="liste_titre center">'.$langs->trans(
"Permissions").
'</td>'.
"\n";
442 print
'<td class="liste_titre nowrap right">';
443 if (
$conf->use_javascript_ajax) {
444 print
'<a href="#" id="checkall">'.$langs->trans(
"All").
'</a> / <a href="#" id="checknone">'.$langs->trans(
"None").
'</a> ';
446 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=refreshmanual&numero_ftp='.$numero_ftp.($section ?
'§ion='.urlencode($section) :
'').
'">'.
img_picto($langs->trans(
"Refresh"),
'refresh').
'</a> ';
451 if (empty($conn_id)) {
452 $resultarray =
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive);
454 $conn_id = $resultarray[
'conn_id'];
455 $ok = $resultarray[
'ok'];
456 $mesg = $resultarray[
'mesg'];
462 $newsection = $section;
463 $newsectioniso = mb_convert_encoding($section,
'ISO-8859-1');
468 if ($newsection ==
'/') {
470 $newsection = ssh2_sftp_realpath($conn_id,
".").
'/./';
477 $contents = scandir(
'ssh2.sftp://'.intval($conn_id).$newsection);
479 foreach ($contents as $i => $key) {
480 $buff[$i] =
"---------- - root root 1234 Aug 01 2000 ".$key;
496 } elseif (!empty($conn_id)) {
497 $buff = ftp_rawlist($conn_id, $newsectioniso);
498 $contents = ftp_nlist($conn_id, $newsectioniso);
500 dol_syslog(__FILE__ .
": Unexpected state for ftp connection", LOG_ERR);
505 $nboflines = count($contents);
506 $rawlisthasfailed =
false;
509 while ($i < $nboflines && $i < 1000) {
510 $vals = preg_split(
'@ +@', mb_convert_encoding($buff[$i],
'UTF-8',
'ISO-8859-1'), 9);
514 $rawlisthasfailed =
true;
515 $file = mb_convert_encoding($contents[$i],
'UTF-8',
'ISO-8859-1');
518 if ($file ==
'.' || ($file ==
'..' && $section ==
'/')) {
528 } elseif (!$rawlisthasfailed) {
529 if (preg_match(
'/^d/', $vals[0])) {
532 if (preg_match(
'/^l/', $vals[0])) {
541 $remotefile = $section.(preg_match(
'@[\\\/]$@', $section) ?
'' :
'/').preg_replace(
'@^[\\\/]@',
'', $file);
543 $newremotefileiso = mb_convert_encoding($remotefile,
'ISO-8859-1');
545 $is_directory =
ftp_isdir($conn_id, $newremotefileiso);
549 print
'<tr class="oddeven" height="18">';
552 $newsection = $section.(preg_match(
'@[\\\/]$@', $section) ?
'' :
'/').$file;
553 $newsection = preg_replace(
'@[\\\/][^\\\/]+[\\\/]\.\.$@',
'/', $newsection);
555 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?section='.urlencode($newsection).
'&numero_ftp='.$numero_ftp.
'">';
563 print
'<td class="center nowrap">';
564 if (!$is_directory && !$is_link) {
571 print
'<td class="center nowrap">';
572 print $vals[5].
' '.$vals[6].
' '.$vals[7];
575 print
'<td class="center nowrap">';
579 print
'<td class="center nowrap">';
583 print
'<td class="center nowrap">';
587 print
'<td class="right nowrap" width="64">';
590 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=delete_section&token='.
newToken().
'&numero_ftp='.$numero_ftp.
'§ion='.urlencode($section).
'&file='.urlencode($file).
'">'.
img_delete().
'</a>';
594 } elseif ($is_link) {
596 $newfile = preg_replace(
'/ ->.*/',
'', $newfile);
597 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=delete&token='.
newToken().
'&numero_ftp='.$numero_ftp.
'§ion='.urlencode($section).
'&file='.urlencode($newfile).
'">'.
img_delete().
'</a>';
599 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=download&token='.
newToken().
'&numero_ftp='.$numero_ftp.
'§ion='.urlencode($section).
'&file='.urlencode($file).
'">'.
img_picto(
'',
'file').
'</a>';
601 print
'<input type="checkbox" class="flat checkboxfordelete" id="check_'.$i.
'" name="const['.$i.
'][check]" value="1">';
603 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=delete&token='.
newToken().
'&numero_ftp='.$numero_ftp.
'§ion='.urlencode($section).
'&file='.urlencode($file).
'">'.
img_delete().
'</a>';
604 print
'<input type="hidden" name="const['.$i.
'][section]" value="'.$section.
'">';
605 print
'<input type="hidden" name="const['.$i.
'][file]" value="'.$file.
'">';
618 print $mesg.
'<br>'.
"\n";
626 print
'<div id="delconst" class="right">';
627 print
'<input type="submit" name="delete" class="button" value="'.$langs->trans(
"Delete").
'">';
632 if ($user->hasRight(
'ftp',
'write')) {
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="uploadfile">';
639 print
'<td><input type="file" class="flat" name="userfile[]" multiple></td>';
641 print
'<td align="center"><button type="submit" class="butAction" name="uploadfile" value="'.$langs->trans(
"Save").
'">'.$langs->trans(
"Upload").
'</button></td>';
647 print
'<form enctype="multipart/form-data" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
648 print
'<input type="hidden" name="token" value="'.newToken().
'">';
649 print
'<input type="hidden" name="numero_ftp" value="'.$numero_ftp.
'">';
650 print
'<input type="hidden" name="section" value="'.$section.
'">';
651 print
'<input type="hidden" name="action" value="addfolder">';
652 print
'<td><input type="text" class="flat" name="newfolder" multiple></td>';
654 print
'<td align="center"><button type="submit" class="butAction" name="addfolder" value="'.$langs->trans(
"Save").
'">'.$langs->trans(
"AddFolder").
'</button></td>';
661 while ($i <= $MAXFTP) {
662 $paramkey =
'FTP_NAME_'.$i;
671 print $langs->trans(
"SetupOfFTPClientModuleNotComplete");
673 print $langs->trans(
"ChooseAFTPEntryIntoMenu");
680if (!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.
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'.
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.