diff --git a/htdocs/core/ajax/ajaxdirpreview.php b/htdocs/core/ajax/ajaxdirpreview.php
index 74d9db0ec6d..203bd71e645 100644
--- a/htdocs/core/ajax/ajaxdirpreview.php
+++ b/htdocs/core/ajax/ajaxdirpreview.php
@@ -39,11 +39,11 @@ if (! isset($mode) || $mode != 'noajax') // For ajax call
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php';
- $action=GETPOST('action','aZ09');
- $file=urldecode(GETPOST('file'));
- $section=GETPOST("section");
- $module=GETPOST("module");
- $urlsource=GETPOST("urlsource");
+ $action=GETPOST('action','aZ09');
+ $file=urldecode(GETPOST('file','alpha'));
+ $section=GETPOST("section",'alpha');
+ $module=GETPOST("module",'alpha');
+ $urlsource=GETPOST("urlsource",'alpha');
$search_doc_ref=GETPOST('search_doc_ref','alpha');
$sortfield = GETPOST("sortfield",'alpha');
@@ -56,7 +56,9 @@ if (! isset($mode) || $mode != 'noajax') // For ajax call
if (! $sortorder) $sortorder="ASC";
if (! $sortfield) $sortfield="name";
- $upload_dir = dirname(str_replace("../","/", $conf->ecm->dir_output.'/'.$file));
+ $rootdirfordoc = $conf->ecm->dir_output;
+
+ $upload_dir = dirname(str_replace("../", "/", $rootdirfordoc.'/'.$file));
$ecmdir = new EcmDirectory($db);
$result=$ecmdir->fetch($section);
@@ -68,7 +70,9 @@ if (! isset($mode) || $mode != 'noajax') // For ajax call
}
else // For no ajax call
{
- $ecmdir = new EcmDirectory($db);
+ $rootdirfordoc = $conf->ecm->dir_output;
+
+ $ecmdir = new EcmDirectory($db);
$relativepath='';
if ($section > 0)
{
@@ -80,7 +84,7 @@ else // For no ajax call
}
}
$relativepath=$ecmdir->getRelativePath();
- $upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
+ $upload_dir = $rootdirfordoc.'/'.$relativepath;
}
if (empty($url)) $url=DOL_URL_ROOT.'/ecm/index.php';
@@ -95,8 +99,7 @@ if ($user->societe_id > 0) $socid = $user->societe_id;
//print 'xxx'.$upload_dir;
// Security:
-// On interdit les remontees de repertoire ainsi que les pipe dans
-// les noms de fichiers.
+// On interdit les remontees de repertoire ainsi que les pipe dans les noms de fichiers.
if (preg_match('/\.\./',$upload_dir) || preg_match('/[<>|]/',$upload_dir))
{
dol_syslog("Refused to deliver file ".$upload_dir);
@@ -105,6 +108,16 @@ if (preg_match('/\.\./',$upload_dir) || preg_match('/[<>|]/',$upload_dir))
exit;
}
+// Check permissions
+if ($modulepart == 'ecm')
+{
+ if (! $user->rights->ecm->read) accessforbidden();
+}
+if ($modulepart == 'medias')
+{
+ // Always allowed
+}
+
/*
* Action
@@ -153,7 +166,7 @@ if ($type == 'directory')
$excludefiles = array('^SPECIMEN\.pdf$','^\.','(\.meta|_preview.*\.png)$','^temp$','^payments$','^CVS$','^thumbs$');
$sorting = (strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC);
- // Right area. If module is defined, we are in automatic ecm.
+ // Right area. If module is defined here, we are in automatic ecm.
$automodules = array('company', 'invoice', 'invoice_supplier', 'propal', 'order', 'order_supplier', 'contract', 'product', 'tax', 'project', 'fichinter', 'user', 'expensereport');
// TODO change for multicompany sharing
@@ -197,20 +210,33 @@ if ($type == 'directory')
$filter=preg_quote($search_doc_ref, '/');
$filearray=dol_dir_list($upload_dir, "files", 1, $filter, $excludefiles, $sortfield, $sorting,1);
- $formfile->list_of_autoecmfiles($upload_dir,$filearray,$module,$param,1,'',$user->rights->ecm->upload,1,$textifempty,$maxlengthname,$url,1);
+ $perm=$user->rights->ecm->upload;
+
+ $formfile->list_of_autoecmfiles($upload_dir,$filearray,$module,$param,1,'',$perm,1,$textifempty,$maxlengthname,$url,1);
}
// Manual list
else
{
- $relativepath=$ecmdir->getRelativePath();
- $upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
+ if ($module == 'medias')
+ {
+ $relativepath=GETPOST('file','alpha');
+ $upload_dir = $dolibarr_main_data_root.'/medias/'.$relativepath;
+ }
+ else
+ {
+ $relativepath=$ecmdir->getRelativePath();
+ $upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
+ }
// If $section defined with value 0
- if ($section === '0' || empty($section))
+ if (($section === '0' || empty($section)) && ($module != 'medias'))
{
$filearray=array();
}
- else $filearray=dol_dir_list($upload_dir,"files",0,'',array('^\.','(\.meta|_preview.*\.png)$','^temp$','^CVS$'),$sortfield, $sorting,1);
+ else
+ {
+ $filearray=dol_dir_list($upload_dir,"files",0,'',array('^\.','(\.meta|_preview.*\.png)$','^temp$','^CVS$'),$sortfield, $sorting,1);
+ }
if ($section)
{
@@ -222,7 +248,18 @@ if ($type == 'directory')
else if ($section === '0') $textifempty='