27 require
'../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/treeview.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ftp.lib.php';
34 $langs->loadLangs(array(
'companies',
'other'));
38 $socid = $user->socid;
43 $action =
GETPOST(
'action',
'aZ09');
45 $newfolder =
GETPOST(
'newfolder');
49 $numero_ftp =
GETPOST(
"numero_ftp");
54 $upload_dir = $conf->ftp->dir_temp;
55 $download_dir = $conf->ftp->dir_temp;
57 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
58 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
59 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
61 if (empty($page) || $page == -1) {
64 $offset = $limit * $page;
65 $pageprev = $page - 1;
66 $pagenext = $page + 1;
74 $s_ftp_name =
'FTP_NAME_'.$numero_ftp;
75 $s_ftp_server =
'FTP_SERVER_'.$numero_ftp;
76 $s_ftp_port =
'FTP_PORT_'.$numero_ftp;
77 $s_ftp_user =
'FTP_USER_'.$numero_ftp;
78 $s_ftp_password =
'FTP_PASSWORD_'.$numero_ftp;
79 $s_ftp_passive =
'FTP_PASSIVE_'.$numero_ftp;
83 if (empty($ftp_port)) {
101 if ($action ==
'uploadfile') {
104 $newsectioniso = utf8_decode($section);
105 $resultarray =
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
106 $conn_id = $resultarray[
'conn_id'];
107 $ok = $resultarray[
'ok'];
108 $mesg = $resultarray[
'mesg'];
110 if ($conn_id && $ok && !$mesg) {
111 $nbfile = count($_FILES[
'userfile'][
'name']);
112 for ($i = 0; $i < $nbfile; $i++) {
113 $newsection = $newsectioniso;
114 $fileupload = $_FILES[
'userfile'][
'name'][$i];
115 $fileuploadpath = $_FILES[
'userfile'][
'tmp_name'][$i];
116 $result =
dol_ftp_put($conn_id, $fileupload, $fileuploadpath, $newsection);
119 setEventMessages($langs->trans(
"FileWasUpload", $fileupload),
null,
'mesgs');
121 dol_syslog(
"ftp/index.php ftp_delete", LOG_ERR);
122 setEventMessages($langs->trans(
"FTPFailedToUploadFile", $fileupload),
null,
'errors');
131 if ($action ==
'addfolder') {
134 $newsectioniso = utf8_decode($section);
135 $resultarray =
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
136 $conn_id = $resultarray[
'conn_id'];
137 $ok = $resultarray[
'ok'];
138 $mesg = $resultarray[
'mesg'];
140 if ($conn_id && $ok && !$mesg) {
141 $result =
dol_ftp_mkdir($conn_id, $newfolder, $newsectioniso);
144 setEventMessages($langs->trans(
"FileWasCreateFolder", $newfolder),
null,
'mesgs');
146 dol_syslog(
"ftp/index.php ftp_delete", LOG_ERR);
147 setEventMessages($langs->trans(
"FTPFailedToCreateFolder", $newfolder),
null,
'errors');
156 if ($action ==
'add' && $user->rights->ftp->setup) {
158 $ecmdir->label =
GETPOST(
"label");
159 $ecmdir->description =
GETPOST(
"desc");
161 $id = $ecmdir->create($user);
163 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
172 if ($action ==
'confirm_deletefile' &&
GETPOST(
'confirm') ==
'yes') {
175 $newsectioniso = utf8_decode($section);
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');
200 if (
GETPOST(
"const",
'array') &&
GETPOST(
"delete") &&
GETPOST(
"delete") == $langs->trans(
"Delete")) {
203 $newsectioniso = utf8_decode($section);
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');
239 if ($action ==
'confirm_deletesection' && $confirm ==
'yes') {
242 $newsectioniso = utf8_decode($section);
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');
269 if ($action ==
'download') {
272 $newsectioniso = utf8_decode($section);
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);
289 if (!empty($conf->global->MAIN_UMASK)) {
290 @chmod($localfile, octdec($conf->global->MAIN_UMASK));
294 $type =
'application/octet-stream';
306 header(
'Content-Type: '.$type);
309 header(
'Content-Disposition: attachment; filename="'.$file.
'"');
311 header(
'Content-Disposition: inline; filename="'.$file.
'"');
315 header(
'Cache-Control: Public, must-revalidate');
316 header(
'Pragma: public');
318 readfile($localfile);
322 setEventMessages($langs->transnoentitiesnoconv(
'FailedToGetFile', $file),
null,
'errors');
341 if ($conf->use_javascript_ajax) {
343 <script
type=
"text/javascript">
344 jQuery(document).ready(
function() {
345 jQuery(
"#delconst").hide();
347 jQuery(
".checkboxfordelete").click(
function() {
348 jQuery(
"#delconst").show();
351 $(
"#checkall").click(
function() {
352 $(
".checkboxfordelete").prop(
'checked',
true);
353 jQuery(
"#delconst").show();
355 $(
"#checknone").click(
function() {
356 $(
".checkboxfordelete").prop(
'checked',
false);
357 jQuery(
"#delconst").hide();
369 $userstatic =
new User($db);
375 print $langs->trans(
"FTPAreaDesc").
"<br>";
377 if (!function_exists(
'ftp_connect')) {
378 print $langs->trans(
"FTPFeatureNotSupportedByYourPHP");
380 if (!empty($ftp_server)) {
382 if ($action ==
'delete') {
383 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);
387 if ($action ==
'delete_section') {
388 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);
391 print $langs->trans(
"Server").
': <b>'.$ftp_server.
'</b><br>';
392 print $langs->trans(
"Port").
': <b>'.$ftp_port.
'</b> '.($ftp_passive ?
"(Passive)" :
"(Active)").
'<br>';
393 print $langs->trans(
"User").
': <b>'.$ftp_user.
'</b><br>';
394 print $langs->trans(
"FTPs (FTP over SSH)").
': <b>'.
yn($conf->global->FTP_CONNECT_WITH_SSL).
'</b><br>';
395 print $langs->trans(
"SFTP (FTP as a subsytem of SSH)").
': <b>'.
yn($conf->global->FTP_CONNECT_WITH_SFTP).
'</b><br>';
396 print $langs->trans(
"Directory").
': ';
397 $sectionarray = preg_split(
'|[\/]|', $section);
400 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=refreshmanual&numero_ftp='.$numero_ftp.($newsection ?
'§ion='.urlencode($newsection) :
'').
'">';
405 foreach ($sectionarray as $val) {
414 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=refreshmanual&numero_ftp='.$numero_ftp.($newsection ?
'§ion='.urlencode($newsection) :
'').
'">';
422 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
423 print
'<input type="hidden" name="numero_ftp" value="'.$numero_ftp.
'">';
424 print
'<input type="hidden" name="token" value="'.newToken().
'">';
428 print
'<table width="100%" class="noborder">'.
"\n";
430 print
'<tr class="liste_titre">'.
"\n";
431 print
'<td class="liste_titre left">'.$langs->trans(
"Content").
'</td>'.
"\n";
432 print
'<td class="liste_titre center">'.$langs->trans(
"Size").
'</td>'.
"\n";
433 print
'<td class="liste_titre center">'.$langs->trans(
"Date").
'</td>'.
"\n";
434 print
'<td class="liste_titre center">'.$langs->trans(
"Owner").
'</td>'.
"\n";
435 print
'<td class="liste_titre center">'.$langs->trans(
"Group").
'</td>'.
"\n";
436 print
'<td class="liste_titre center">'.$langs->trans(
"Permissions").
'</td>'.
"\n";
437 print
'<td class="liste_titre nowrap right">';
438 if ($conf->use_javascript_ajax) {
439 print
'<a href="#" id="checkall">'.$langs->trans(
"All").
'</a> / <a href="#" id="checknone">'.$langs->trans(
"None").
'</a> ';
441 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=refreshmanual&numero_ftp='.$numero_ftp.($section ?
'§ion='.urlencode($section) :
'').
'">'.
img_picto($langs->trans(
"Refresh"),
'refresh').
'</a> ';
446 if (empty($conn_id)) {
447 $resultarray =
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive);
449 $conn_id = $resultarray[
'conn_id'];
450 $ok = $resultarray[
'ok'];
451 $mesg = $resultarray[
'mesg'];
457 $newsection = $section;
458 $newsectioniso = utf8_decode($section);
462 if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
463 if ($newsection ==
'/') {
465 $newsection = ssh2_sftp_realpath($conn_id,
".").
'/./';
472 $contents = scandir(
'ssh2.sftp://'.intval($conn_id).$newsection);
474 foreach ($contents as $i => $key) {
475 $buff[$i] =
"---------- - root root 1234 Aug 01 2000 ".$key;
492 $buff = ftp_rawlist($conn_id, $newsectioniso);
493 $contents = ftp_nlist($conn_id, $newsectioniso);
496 $nboflines = count($contents);
497 $rawlisthasfailed =
false;
500 while ($i < $nboflines && $i < 1000) {
501 $vals = preg_split(
'@ +@', utf8_encode($buff[$i]), 9);
505 $rawlisthasfailed =
true;
506 $file = utf8_encode($contents[$i]);
509 if ($file ==
'.' || ($file ==
'..' && $section ==
'/')) {
519 } elseif (!$rawlisthasfailed) {
520 if (preg_match(
'/^d/', $vals[0])) {
523 if (preg_match(
'/^l/', $vals[0])) {
532 $remotefile = $section.(preg_match(
'@[\\\/]$@', $section) ?
'' :
'/').preg_replace(
'@^[\\\/]@',
'', $file);
534 $newremotefileiso = utf8_decode($remotefile);
536 $is_directory =
ftp_isdir($conn_id, $newremotefileiso);
540 print
'<tr class="oddeven" height="18">';
543 $newsection = $section.(preg_match(
'@[\\\/]$@', $section) ?
'' :
'/').$file;
544 $newsection = preg_replace(
'@[\\\/][^\\\/]+[\\\/]\.\.$@',
'/', $newsection);
546 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?section='.urlencode($newsection).
'&numero_ftp='.$numero_ftp.
'">';
554 print
'<td class="center nowrap">';
555 if (!$is_directory && !$is_link) {
562 print
'<td class="center nowrap">';
563 print $vals[5].
' '.$vals[6].
' '.$vals[7];
566 print
'<td class="center nowrap">';
570 print
'<td class="center nowrap">';
574 print
'<td class="center nowrap">';
578 print
'<td class="right nowrap" width="64">';
581 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=delete_section&token='.
newToken().
'&numero_ftp='.$numero_ftp.
'§ion='.urlencode($section).
'&file='.urlencode($file).
'">'.
img_delete().
'</a>';
585 } elseif ($is_link) {
587 $newfile = preg_replace(
'/ ->.*/',
'', $newfile);
588 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=delete&token='.
newToken().
'&numero_ftp='.$numero_ftp.
'§ion='.urlencode($section).
'&file='.urlencode($newfile).
'">'.
img_delete().
'</a>';
590 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=download&token='.
newToken().
'&numero_ftp='.$numero_ftp.
'§ion='.urlencode($section).
'&file='.urlencode($file).
'">'.
img_picto(
'',
'file').
'</a>';
592 print
'<input type="checkbox" class="flat checkboxfordelete" id="check_'.$i.
'" name="const['.$i.
'][check]" value="1">';
594 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=delete&token='.
newToken().
'&numero_ftp='.$numero_ftp.
'§ion='.urlencode($section).
'&file='.urlencode($file).
'">'.
img_delete().
'</a>';
595 print
'<input type="hidden" name="const['.$i.
'][section]" value="'.$section.
'">';
596 print
'<input type="hidden" name="const['.$i.
'][file]" value="'.$file.
'">';
609 print $mesg.
'<br>'.
"\n";
624 print
'<div id="delconst" class="right">';
625 print
'<input type="submit" name="delete" class="button" value="'.$langs->trans(
"Delete").
'">';
630 if ($user->hasRight(
'ftp',
'write')) {
632 print
'<form enctype="multipart/form-data" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
633 print
'<input type="hidden" name="token" value="'.newToken().
'">';
634 print
'<input type="hidden" name="numero_ftp" value="'.$numero_ftp.
'">';
635 print
'<input type="hidden" name="section" value="'.$section.
'">';
636 print
'<input type="hidden" name="action" value="uploadfile">';
637 print
'<td><input type="file" class="flat" name="userfile[]" multiple></td>';
639 print
'<td align="center"><button type="submit" class="butAction" name="uploadfile" value="'.$langs->trans(
"Save").
'">'.$langs->trans(
"Upload").
'</button></td>';
645 print
'<form enctype="multipart/form-data" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
646 print
'<input type="hidden" name="token" value="'.newToken().
'">';
647 print
'<input type="hidden" name="numero_ftp" value="'.$numero_ftp.
'">';
648 print
'<input type="hidden" name="section" value="'.$section.
'">';
649 print
'<input type="hidden" name="action" value="addfolder">';
650 print
'<td><input type="text" class="flat" name="newfolder" multiple></td>';
652 print
'<td align="center"><button type="submit" class="butAction" name="addfolder" value="'.$langs->trans(
"Save").
'">'.$langs->trans(
"AddFolder").
'</button></td>';
659 while ($i <= $MAXFTP) {
660 $paramkey =
'FTP_NAME_'.$i;
662 if (!empty($conf->global->$paramkey)) {
669 print $langs->trans(
"SetupOfFTPClientModuleNotComplete");
671 print $langs->trans(
"ChooseAFTPEntryIntoMenu");
678 if (!empty($conn_id)) {
Class to manage Dolibarr users.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
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($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
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.