26 require
'../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/treeview.lib.php';
32 $langs->loadLangs(array(
'ftp',
'companies',
'other'));
35 if ($user->socid) $socid = $user->socid;
39 $action =
GETPOST(
'action',
'aZ09');
41 if (!$section) $section =
'/';
42 $numero_ftp =
GETPOST(
"numero_ftp");
47 $upload_dir = $conf->ftp->dir_temp;
48 $download_dir = $conf->ftp->dir_temp;
50 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
51 $sortfield =
GETPOST(
"sortfield",
'alpha');
52 $sortorder =
GETPOST(
"sortorder",
'alpha');
54 if (empty($page) || $page == -1) { $page = 0; }
55 $offset = $limit * $page;
56 $pageprev = $page - 1;
57 $pagenext = $page + 1;
58 if (!$sortorder) $sortorder =
"ASC";
59 if (!$sortfield) $sortfield =
"label";
61 $s_ftp_name =
'FTP_NAME_'.$numero_ftp;
62 $s_ftp_server =
'FTP_SERVER_'.$numero_ftp;
63 $s_ftp_port =
'FTP_PORT_'.$numero_ftp;
64 $s_ftp_user =
'FTP_USER_'.$numero_ftp;
65 $s_ftp_password =
'FTP_PASSWORD_'.$numero_ftp;
66 $s_ftp_passive =
'FTP_PASSIVE_'.$numero_ftp;
67 $ftp_name = $conf->global->$s_ftp_name;
68 $ftp_server = $conf->global->$s_ftp_server;
69 $ftp_port = $conf->global->$s_ftp_port;
if (empty($ftp_port)) $ftp_port = 21;
70 $ftp_user = $conf->global->$s_ftp_user;
71 $ftp_password = $conf->global->$s_ftp_password;
72 $ftp_passive = $conf->global->$s_ftp_passive;
86 if (
GETPOST(
"sendit") && !empty($conf->global->MAIN_UPLOAD_DOC))
88 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
90 $result = $ecmdir->fetch(
GETPOST(
"section",
'int'));
96 $relativepath = $ecmdir->getRelativePath();
97 $upload_dir = $conf->ecm->dir_output.
'/'.$relativepath;
102 if (is_numeric($resupload) && $resupload > 0)
104 $result = $ecmdir->changeNbOfFiles(
'+');
106 $langs->load(
"errors");
110 } elseif (preg_match(
'/ErrorFileIsInfectedWithAVirus/', $resupload)) {
112 setEventMessages($langs->trans(
"ErrorFileIsInfectedWithAVirus"), null,
'errors');
120 $langs->load(
"errors");
121 setEventMessages($langs->trans(
"ErrorFailToCreateDir", $upload_dir), null,
'errors');
126 if ($action ==
'add' && $user->rights->ftp->setup)
129 $ecmdir->label =
GETPOST(
"label");
130 $ecmdir->description =
GETPOST(
"desc");
132 $id = $ecmdir->create($user);
135 header(
"Location: ".
$_SERVER[
"PHP_SELF"]);
144 if ($action ==
'confirm_deletefile' &&
GETPOST(
'confirm') ==
'yes')
149 $newsectioniso = utf8_decode($section);
150 $resultarray =
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
151 $conn_id = $resultarray[
'conn_id'];
152 $ok = $resultarray[
'ok'];
153 $mesg = $resultarray[
'mesg'];
156 if ($conn_id && $ok && !$mesg)
158 $newsection = $section;
159 if (!empty($conf->global->FTP_CONNECT_WITH_SFTP))
161 $newsection = ssh2_sftp_realpath($conn_id,
".").
'/./';
164 $langs->load(
"other");
168 $remotefile = $newsection.(preg_match(
'@[\\\/]$@', $newsection) ?
'' :
'/').$file;
169 $newremotefileiso = utf8_decode($remotefile);
172 dol_syslog(
"ftp/index.php ftp_delete ".$newremotefileiso);
173 if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
174 $result = ssh2_sftp_unlink($conn_id, $newremotefileiso);
176 $result = @ftp_delete($conn_id, $newremotefileiso);
182 dol_syslog(
"ftp/index.php ftp_delete", LOG_ERR);
183 setEventMessages($langs->trans(
"FTPFailedToRemoveFile", $file), null,
'errors');
200 $newsectioniso = utf8_decode($section);
201 $resultarray =
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
202 $conn_id = $resultarray[
'conn_id'];
203 $ok = $resultarray[
'ok'];
204 $mesg = $resultarray[
'mesg'];
207 if ($conn_id && $ok && !$mesg)
209 foreach (
GETPOST(
'const',
'array') as $const)
213 $langs->load(
"other");
216 $file = $const[
"file"];
217 $newsection = $const[
"section"];
218 if (!empty($conf->global->FTP_CONNECT_WITH_SFTP))
220 $newsection = ssh2_sftp_realpath($conn_id,
".").
'/./';
222 $remotefile = $newsection.(preg_match(
'@[\\\/]$@', $newsection) ?
'' :
'/').$file;
223 $newremotefileiso = utf8_decode($remotefile);
226 dol_syslog(
"ftp/index.php ftp_delete n files for ".$newremotefileiso);
227 if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
228 $result = ssh2_sftp_unlink($conn_id, $newremotefileiso);
230 $result = @ftp_delete($conn_id, $newremotefileiso);
236 dol_syslog(
"ftp/index.php ftp_delete n files", LOG_ERR);
237 setEventMessages($langs->trans(
"FTPFailedToRemoveFile", $file), null,
'errors');
251 if ($action ==
'confirm_deletesection' && $confirm ==
'yes')
256 $newsectioniso = utf8_decode($section);
257 $resultarray =
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
258 $conn_id = $resultarray[
'conn_id'];
259 $ok = $resultarray[
'ok'];
260 $mesg = $resultarray[
'mesg'];
263 if ($conn_id && $ok && !$mesg)
265 $newsection = $section;
266 if (!empty($conf->global->FTP_CONNECT_WITH_SFTP))
268 $newsection = ssh2_sftp_realpath($conn_id,
".").
'/./';
273 $remotefile = $newsection.(preg_match(
'@[\\\/]$@', $newsection) ?
'' :
'/').$file;
274 $newremotefileiso = utf8_decode($remotefile);
276 if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
277 $result = ssh2_sftp_rmdir($conn_id, $newremotefileiso);
279 $result = @ftp_rmdir($conn_id, $newremotefileiso);
285 setEventMessages($langs->trans(
"FTPFailedToRemoveDir", $file), null,
'errors');
297 if ($action ==
'download')
302 $newsectioniso = utf8_decode($section);
303 $resultarray =
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
304 $conn_id = $resultarray[
'conn_id'];
305 $ok = $resultarray[
'ok'];
306 $mesg = $resultarray[
'mesg'];
309 if ($conn_id && $ok && !$mesg)
312 $localfile = tempnam($download_dir,
'dol_');
314 $newsection = $section;
315 if (!empty($conf->global->FTP_CONNECT_WITH_SFTP))
317 $newsection = ssh2_sftp_realpath($conn_id,
".").
'/./';
322 $remotefile = $newsection.(preg_match(
'@[\\\/]$@', $newsection) ?
'' :
'/').$file;
323 $newremotefileiso = utf8_decode($remotefile);
325 if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
326 $result = fopen(
'ssh2.sftp://'.intval($conn_id).$newremotefileiso,
'r');
328 $result = ftp_get($conn_id, $localfile, $newremotefileiso, FTP_BINARY);
332 if (!empty($conf->global->MAIN_UMASK))
333 @chmod($localfile, octdec($conf->global->MAIN_UMASK));
336 $type =
'application/octet-stream';
344 if ($type) header(
'Content-Type: '.$type);
345 if ($attachment) header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
346 else header(
'Content-Disposition: inline; filename="'.$filename.
'"');
349 header(
'Cache-Control: Public, must-revalidate');
350 header(
'Pragma: public');
352 readfile($localfile);
358 setEventMessages($langs->transnoentitiesnoconv(
'FailedToGetFile', $remotefile), null,
'errors');
377 if ($conf->use_javascript_ajax)
380 <script
type=
"text/javascript">
381 jQuery(document).ready(
function() {
382 jQuery(
"#delconst").hide();
384 jQuery(
".checkboxfordelete").click(
function() {
385 jQuery(
"#delconst").show();
388 $(
"#checkall").click(
function() {
389 $(
".checkboxfordelete").prop(
'checked',
true);
390 jQuery(
"#delconst").show();
392 $(
"#checknone").click(
function() {
393 $(
".checkboxfordelete").prop(
'checked',
false);
394 jQuery(
"#delconst").hide();
404 $form =
new Form($db);
406 $userstatic =
new User($db);
412 print $langs->trans(
"FTPAreaDesc").
"<br>";
414 if (!function_exists(
'ftp_connect'))
416 print $langs->trans(
"FTPFeatureNotSupportedByYourPHP");
418 if (!empty($ftp_server))
421 if ($action ==
'delete')
423 print $form->formconfirm(
$_SERVER[
"PHP_SELF"].
'?numero_ftp='.$numero_ftp.
'§ion='.urlencode(
GETPOST(
'section')).
'&file='.urlencode(
GETPOST(
'file')), $langs->trans(
'DeleteFile'), $langs->trans(
'ConfirmDeleteFile'),
'confirm_deletefile',
'',
'', 1);
427 if ($action ==
'delete_section')
429 print $form->formconfirm(
$_SERVER[
"PHP_SELF"].
'?numero_ftp='.$numero_ftp.
'§ion='.urlencode(
GETPOST(
'section')).
'&file='.urlencode(
GETPOST(
'file')), $langs->trans(
'DeleteSection'), $langs->trans(
'ConfirmDeleteSection', $ecmdir->label),
'confirm_deletesection',
'',
'', 1);
432 print $langs->trans(
"Server").
': <b>'.$ftp_server.
'</b><br>';
433 print $langs->trans(
"Port").
': <b>'.$ftp_port.
'</b> '.($ftp_passive ?
"(Passive)" :
"(Active)").
'<br>';
434 print $langs->trans(
"User").
': <b>'.$ftp_user.
'</b><br>';
435 print $langs->trans(
"FTPs (FTP over SSH)").
': <b>'.
yn($conf->global->FTP_CONNECT_WITH_SSL).
'</b><br>';
436 print $langs->trans(
"SFTP (FTP as a subsytem of SSH)").
': <b>'.
yn($conf->global->FTP_CONNECT_WITH_SFTP).
'</b><br>';
437 print $langs->trans(
"Directory").
': ';
438 $sectionarray = preg_split(
'|[\/]|', $section);
441 print '<a href="'.$_SERVER[
"PHP_SELF"].
'?action=refreshmanual&numero_ftp='.$numero_ftp.($newsection ?
'§ion='.urlencode($newsection) :
'').
'">';
446 foreach ($sectionarray as $val)
448 if (empty($val))
continue;
455 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=refreshmanual&numero_ftp='.$numero_ftp.($newsection ?
'§ion='.urlencode($newsection) :
'').
'">';
463 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
464 print
'<input type="hidden" name="numero_ftp" value="'.$numero_ftp.
'">';
465 print
'<input type="hidden" name="token" value="'.newToken().
'">';
469 print
'<table width="100%" class="noborder">'.
"\n";
471 print
'<tr class="liste_titre">'.
"\n";
472 print
'<td class="liste_titre left">'.$langs->trans(
"Content").
'</td>'.
"\n";
473 print
'<td class="liste_titre center">'.$langs->trans(
"Size").
'</td>'.
"\n";
474 print
'<td class="liste_titre center">'.$langs->trans(
"Date").
'</td>'.
"\n";
475 print
'<td class="liste_titre center">'.$langs->trans(
"Owner").
'</td>'.
"\n";
476 print
'<td class="liste_titre center">'.$langs->trans(
"Group").
'</td>'.
"\n";
477 print
'<td class="liste_titre center">'.$langs->trans(
"Permissions").
'</td>'.
"\n";
478 print
'<td class="liste_titre nowrap right">';
479 if ($conf->use_javascript_ajax) print
'<a href="#" id="checkall">'.$langs->trans(
"All").
'</a> / <a href="#" id="checknone">'.$langs->trans(
"None").
'</a> ';
480 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=refreshmanual&numero_ftp='.$numero_ftp.($section ?
'§ion='.urlencode($section) :
'').
'">'.
img_picto($langs->trans(
"Refresh"),
'refresh').
'</a> ';
487 $resultarray =
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive);
489 $conn_id = $resultarray[
'conn_id'];
490 $ok = $resultarray[
'ok'];
491 $mesg = $resultarray[
'mesg'];
498 $newsection = $section;
499 $newsectioniso = utf8_decode($section);
503 if (!empty($conf->global->FTP_CONNECT_WITH_SFTP))
505 if ($newsection ==
'/') {
507 $newsection = ssh2_sftp_realpath($conn_id,
".").
'/./';
512 $contents = scandir(
'ssh2.sftp://'.intval($conn_id).$newsection);
514 foreach ($contents as $i => $key)
516 $buff[$i] =
"---------- - root root 1234 Aug 01 2000 ".$key;
519 $buff = ftp_rawlist($conn_id, $newsectioniso);
520 $contents = ftp_nlist($conn_id, $newsectioniso);
525 $nboflines = count($contents);
526 $rawlisthasfailed =
false;
528 while ($i < $nboflines && $i < 1000)
530 $vals = preg_split(
'@ +@', utf8_encode($buff[$i]), 9);
536 $rawlisthasfailed =
true;
537 $file = utf8_encode($contents[$i]);
540 if ($file ==
'.' || ($file ==
'..' && $section ==
'/'))
548 if ($file ==
'..') $is_directory = 1;
549 elseif (!$rawlisthasfailed)
551 if (preg_match(
'/^d/', $vals[0])) $is_directory = 1;
552 if (preg_match(
'/^l/', $vals[0])) $is_link = 1;
559 $remotefile = $section.(preg_match(
'@[\\\/]$@', $section) ?
'' :
'/').preg_replace(
'@^[\\\/]@',
'', $file);
561 $newremotefileiso = utf8_decode($remotefile);
563 $is_directory =
ftp_isdir($conn_id, $newremotefileiso);
567 print
'<tr class="oddeven" height="18">';
570 $newsection = $section.(preg_match(
'@[\\\/]$@', $section) ?
'' :
'/').$file;
571 $newsection = preg_replace(
'@[\\\/][^\\\/]+[\\\/]\.\.$@',
'/', $newsection);
572 if ($is_directory) print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?section='.urlencode($newsection).
'&numero_ftp='.$numero_ftp.
'">';
574 if ($is_directory) print
'</a>';
577 print
'<td class="center nowrap">';
578 if (!$is_directory && !$is_link) print $vals[4];
582 print
'<td class="center nowrap">';
583 print $vals[5].
' '.$vals[6].
' '.$vals[7];
586 print
'<td class="center nowrap">';
590 print
'<td class="center nowrap">';
594 print
'<td class="center nowrap">';
598 print
'<td class="right nowrap" width="64">';
601 if ($file !=
'..') print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=delete_section&token='.
newToken().
'&numero_ftp='.$numero_ftp.
'§ion='.urlencode($section).
'&file='.urlencode($file).
'">'.
img_delete().
'</a>';
606 $newfile = preg_replace(
'/ ->.*/',
'', $newfile);
607 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=delete&token='.
newToken().
'&numero_ftp='.$numero_ftp.
'§ion='.urlencode($section).
'&file='.urlencode($newfile).
'">'.
img_delete().
'</a>';
609 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=download&token='.
newToken().
'&numero_ftp='.$numero_ftp.
'§ion='.urlencode($section).
'&file='.urlencode($file).
'">'.
img_picto(
'',
'file').
'</a>';
611 print
'<input type="checkbox" class="flat checkboxfordelete" id="check_'.$i.
'" name="const['.$i.
'][check]" value="1">';
613 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=delete&token='.
newToken().
'&numero_ftp='.$numero_ftp.
'§ion='.urlencode($section).
'&file='.urlencode($file).
'">'.
img_delete().
'</a>';
614 print
'<input type="hidden" name="const['.$i.
'][section]" value="'.$section.
'">';
615 print
'<input type="hidden" name="const['.$i.
'][file]" value="'.$file.
'">';
629 print $mesg.
'<br>'.
"\n";
644 print
'<div id="delconst" class="right">';
645 print
'<input type="submit" name="delete" class="button" value="'.$langs->trans(
"Delete").
'">';
653 while ($i <= $MAXFTP)
655 $paramkey =
'FTP_NAME_'.$i;
657 if (!empty($conf->global->$paramkey))
666 print $langs->trans(
"SetupOfFTPClientModuleNotComplete");
668 print $langs->trans(
"ChooseAFTPEntryIntoMenu");
678 if (!empty($conf->global->FTP_CONNECT_WITH_SFTP))
680 } elseif (!empty($conf->global->FTP_CONNECT_WITH_SSL))
705 function dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive = 0)
707 global $langs, $conf;
712 if (!is_numeric($ftp_port))
714 $mesg = $langs->transnoentitiesnoconv(
"FailedToConnectToFTPServer", $ftp_server, $ftp_port);
720 $connecttimeout = (empty($conf->global->FTP_CONNECT_TIMEOUT) ? 40 : $conf->global->FTP_CONNECT_TIMEOUT);
721 if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
723 $tmp_conn_id = ssh2_connect($ftp_server, $ftp_port);
724 } elseif (!empty($conf->global->FTP_CONNECT_WITH_SSL)) {
725 dol_syslog(
'Try to connect with ftp_ssl_connect');
726 $conn_id = ftp_ssl_connect($ftp_server, $ftp_port, $connecttimeout);
728 dol_syslog(
'Try to connect with ftp_connect');
729 $conn_id = ftp_connect($ftp_server, $ftp_port, $connecttimeout);
731 if ($conn_id || $tmp_conn_id)
735 if (!empty($conf->global->FTP_CONNECT_WITH_SFTP))
737 dol_syslog(
'Try to authenticate with ssh2_auth_password');
738 if (ssh2_auth_password($tmp_conn_id, $ftp_user, $ftp_password))
744 $newsectioniso = utf8_decode($section);
746 $conn_id = ssh2_sftp($tmp_conn_id);
749 dol_syslog(
'Failed to connect to SFTP after sssh authentication', LOG_DEBUG);
750 $mesg = $langs->transnoentitiesnoconv(
"FailedToConnectToSFTPAfterSSHAuthentication");
755 dol_syslog(
'Failed to connect to FTP with login '.$ftp_user, LOG_DEBUG);
756 $mesg = $langs->transnoentitiesnoconv(
"FailedToConnectToFTPServerWithCredentials");
761 if (ftp_login($conn_id, $ftp_user, $ftp_password))
764 if ($ftp_passive) ftp_pasv($conn_id,
true);
767 $newsectioniso = utf8_decode($section);
768 ftp_chdir($conn_id, $newsectioniso);
770 $mesg = $langs->transnoentitiesnoconv(
"FailedToConnectToFTPServerWithCredentials");
777 dol_syslog(
'FailedToConnectToFTPServer '.$ftp_server.
' '.$ftp_port, LOG_ERR);
778 $mesg = $langs->transnoentitiesnoconv(
"FailedToConnectToFTPServer", $ftp_server, $ftp_port);
783 $arrayresult = array(
'conn_id'=>$conn_id,
'ok'=>$ok,
'mesg'=>$mesg,
'curdir'=>$section,
'curdiriso'=>$newsectioniso);
797 if (@ftp_chdir($connect_id, $dir))
799 ftp_cdup($connect_id);
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_unescapefile($filename)
Unescape a file submitted by upload.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
Class to manage Dolibarr users.
ftp_isdir($connect_id, $dir)
Tell if an entry is a FTP directory.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
dol_mimetype($file, $default= 'application/octet-stream', $mode=0)
Return mime type of a file.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive=0)
Connect to FTP server.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $varfiles= 'addedfile', $upload_dir= '')
Make control on an uploaded file from an GUI page and move it to final destination.
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...