28 if (!defined(
'NOTOKENRENEWAL')) {
29 define(
'NOTOKENRENEWAL',
'1');
31 if (!defined(
'NOREQUIREMENU')) {
32 define(
'NOREQUIREMENU',
'1');
34 if (!defined(
'NOREQUIREHTML')) {
35 define(
'NOREQUIREHTML',
'1');
37 if (!defined(
'NOREQUIREAJAX')) {
38 define(
'NOREQUIREAJAX',
'1');
40 if (!defined(
'NOLOGIN')) {
43 if (!defined(
'NOCSRFCHECK')) {
44 define(
"NOCSRFCHECK", 1);
47 require
"../main.inc.php";
48 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
49 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
50 require_once DOL_DOCUMENT_ROOT.
'/dav/dav.class.php';
51 require_once DOL_DOCUMENT_ROOT.
'/dav/dav.lib.php';
52 require_once DOL_DOCUMENT_ROOT.
'/includes/sabre/autoload.php';
55 $user =
new User($db);
56 if (isset($_SERVER[
'PHP_AUTH_USER']) && $_SERVER[
'PHP_AUTH_USER'] !=
'') {
57 $user->fetch(
'', $_SERVER[
'PHP_AUTH_USER']);
62 $langs->loadLangs(array(
"main",
"other"));
65 if (empty($conf->dav->enabled)) {
70 if (!empty($conf->global->DAV_RESTRICT_ON_IP)) {
71 $allowedip = explode(
' ', $conf->global->DAV_RESTRICT_ON_IP);
73 if (!in_array($ipremote, $allowedip)) {
74 dol_syslog(
'Remote ip is '.$ipremote.
', not into list '.$conf->global->DAV_RESTRICT_ON_IP);
75 print
'DAV not allowed from the IP '.$ipremote;
76 header(
'HTTP/1.1 503 DAV not allowed from your IP '.$ipremote);
83 $entity = (
GETPOST(
'entity',
'int') ?
GETPOST(
'entity',
'int') : (!empty($conf->entity) ? $conf->entity : 1));
86 $publicDir = $conf->dav->multidir_output[$entity].
'/public';
87 $privateDir = $conf->dav->multidir_output[$entity].
'/private';
88 $ecmDir = $conf->ecm->multidir_output[$entity];
89 $tmpDir = $conf->dav->multidir_output[$entity];
94 $authBackend = new \Sabre\DAV\Auth\Backend\BasicCallBack(
function ($username, $password) {
97 global $dolibarr_main_authentication, $dolibarr_auto_user;
99 if (empty($user->login)) {
100 dol_syslog(
"Failed to authenticate to DAV, login is not provided", LOG_WARNING);
103 if ($user->socid > 0) {
104 dol_syslog(
"Failed to authenticate to DAV, use is an external user", LOG_WARNING);
107 if ($user->login != $username) {
108 dol_syslog(
"Failed to authenticate to DAV, login does not match the login of loaded user", LOG_WARNING);
113 if (empty($dolibarr_main_authentication)) {
114 $dolibarr_main_authentication =
'dolibarr';
118 if ($dolibarr_main_authentication ==
'forceuser') {
119 if (empty($dolibarr_auto_user)) {
120 $dolibarr_auto_user =
'auto';
122 if ($dolibarr_auto_user != $username) {
123 dol_syslog(
"Warning: your instance is set to use the automatic forced login '".$dolibarr_auto_user.
"' that is not the requested login. DAV usage is forbidden in this mode.");
128 $authmode = explode(
',', $dolibarr_main_authentication);
129 $entity = (
GETPOST(
'entity',
'int') ?
GETPOST(
'entity',
'int') : (!empty($conf->entity) ? $conf->entity : 1));
138 $authBackend->setRealm(constant(
'DOL_APPLICATION_TITLE').
' - WebDAV');
154 if (!empty($conf->global->DAV_ALLOW_PUBLIC_DIR)) {
155 $nodes[] = new \Sabre\DAV\FS\Directory($publicDir);
158 $nodes[] = new \Sabre\DAV\FS\Directory($privateDir);
160 if (
isModEnabled(
'ecm') && !empty($conf->global->DAV_ALLOW_ECM_DIR)) {
161 $nodes[] = new \Sabre\DAV\FS\Directory($ecmDir);
180 $server = new \Sabre\DAV\Server($nodes);
184 $baseUri = DOL_URL_ROOT.
'/dav/fileserver.php/';
185 if (isset($baseUri)) {
186 $server->setBaseUri($baseUri);
190 if ((empty($conf->global->DAV_ALLOW_PUBLIC_DIR)
191 || !preg_match(
'/'.preg_quote(DOL_URL_ROOT.
'/dav/fileserver.php/public',
'/').
'/', $_SERVER[
"PHP_SELF"]))
192 && !preg_match(
'/^sabreAction=asset&assetName=[a-zA-Z0-9%\-\/]+\.(png|css|woff|ico|ttf)$/', $_SERVER[
"QUERY_STRING"])
195 $server->addPlugin(
new \Sabre\DAV\Auth\Plugin($authBackend));
198 $lockBackend = new \Sabre\DAV\Locks\Backend\File($tmpDir.
'/.locksdb');
199 $lockPlugin = new \Sabre\DAV\Locks\Plugin($lockBackend);
200 $server->addPlugin($lockPlugin);
203 if (empty($conf->global->DAV_DISABLE_BROWSER)) {
204 $browser = new \Sabre\DAV\Browser\Plugin();
205 $server->addPlugin($browser);
223 if (is_object($db)) {
Class to manage Dolibarr users.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getUserRemoteIP()
Return the IP of remote user.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
checkLoginPassEntity($usertotest, $passwordtotest, $entitytotest, $authmode, $context='')
Return a login if login/pass was successfull.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.