28 if (!defined(
'NOTOKENRENEWAL')) define(
'NOTOKENRENEWAL',
'1');
29 if (!defined(
'NOREQUIREMENU')) define(
'NOREQUIREMENU',
'1');
30 if (!defined(
'NOREQUIREHTML')) define(
'NOREQUIREHTML',
'1');
31 if (!defined(
'NOREQUIREAJAX')) define(
'NOREQUIREAJAX',
'1');
32 if (!defined(
'NOLOGIN')) define(
"NOLOGIN", 1);
33 if (!defined(
'NOCSRFCHECK')) define(
"NOCSRFCHECK", 1);
35 require
"../main.inc.php";
36 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
38 require_once DOL_DOCUMENT_ROOT.
'/dav/dav.class.php';
39 require_once DOL_DOCUMENT_ROOT.
'/dav/dav.lib.php';
40 require_once DOL_DOCUMENT_ROOT.
'/includes/sabre/autoload.php';
43 $user =
new User($db);
46 $user->fetch(
'',
$_SERVER[
'PHP_AUTH_USER']);
51 $langs->loadLangs(array(
"main",
"other"));
54 if (empty($conf->dav->enabled))
59 if (!empty($conf->global->DAV_RESTRICT_ON_IP))
61 $allowedip = explode(
' ', $conf->global->DAV_RESTRICT_ON_IP);
63 if (!in_array($ipremote, $allowedip))
65 dol_syslog(
'Remote ip is '.$ipremote.
', not into list '.$conf->global->DAV_RESTRICT_ON_IP);
66 print 'DAV not allowed from the IP '.$ipremote;
67 header(
'HTTP/1.1 503 DAV not allowed from your IP '.$ipremote);
74 $entity = (
GETPOST(
'entity',
'int') ?
GETPOST(
'entity',
'int') : (!empty($conf->entity) ? $conf->entity : 1));
77 $publicDir = $conf->dav->multidir_output[$entity].
'/public';
78 $privateDir = $conf->dav->multidir_output[$entity].
'/private';
79 $ecmDir = $conf->ecm->multidir_output[$entity];
80 $tmpDir = $conf->dav->multidir_output[$entity];
85 $authBackend = new \Sabre\DAV\Auth\Backend\BasicCallBack(
function ($username, $password) {
88 global $dolibarr_main_authentication, $dolibarr_auto_user;
90 if (empty($user->login))
92 dol_syslog(
"Failed to authenticate to DAV, login is not provided", LOG_WARNING);
97 dol_syslog(
"Failed to authenticate to DAV, use is an external user", LOG_WARNING);
100 if ($user->login != $username)
102 dol_syslog(
"Failed to authenticate to DAV, login does not match the login of loaded user", LOG_WARNING);
107 if (empty($dolibarr_main_authentication)) $dolibarr_main_authentication =
'dolibarr';
110 if ($dolibarr_main_authentication ==
'forceuser')
112 if (empty($dolibarr_auto_user)) $dolibarr_auto_user =
'auto';
113 if ($dolibarr_auto_user != $username)
115 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.");
120 $authmode = explode(
',', $dolibarr_main_authentication);
121 $entity = (
GETPOST(
'entity',
'int') ?
GETPOST(
'entity',
'int') : (!empty($conf->entity) ? $conf->entity : 1));
129 $authBackend->setRealm(constant(
'DOL_APPLICATION_TITLE'));
145 if (!empty($conf->global->DAV_ALLOW_PUBLIC_DIR))
147 $nodes[] = new \Sabre\DAV\FS\Directory($publicDir);
150 $nodes[] = new \Sabre\DAV\FS\Directory($privateDir);
152 if (!empty($conf->ecm->enabled) && !empty($conf->global->DAV_ALLOW_ECM_DIR))
154 $nodes[] = new \Sabre\DAV\FS\Directory($ecmDir);
173 $server = new \Sabre\DAV\Server($nodes);
177 $baseUri = DOL_URL_ROOT.
'/dav/fileserver.php/';
178 if (isset($baseUri)) $server->setBaseUri($baseUri);
181 if ((empty($conf->global->DAV_ALLOW_PUBLIC_DIR)
182 || !preg_match(
'/'.preg_quote(DOL_URL_ROOT.
'/dav/fileserver.php/public',
'/').
'/',
$_SERVER[
"PHP_SELF"]))
183 && !preg_match(
'/^sabreAction=asset&assetName=[a-zA-Z0-9%\-\/]+\.(png|css|woff|ico|ttf)$/',
$_SERVER[
"QUERY_STRING"])
187 $server->addPlugin(
new \Sabre\DAV\
Auth\Plugin($authBackend));
190 $lockBackend = new \Sabre\DAV\Locks\Backend\File($tmpDir.
'/.locksdb');
191 $lockPlugin = new \Sabre\DAV\Locks\Plugin($lockBackend);
192 $server->addPlugin($lockPlugin);
195 if (empty($conf->global->DAV_DISABLE_BROWSER))
197 $browser = new \Sabre\DAV\Browser\Plugin();
198 $server->addPlugin($browser);
216 if (is_object($db)) $db->close();
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.
Class ot manage authentication for pos module (cashdesk)
Class to manage Dolibarr users.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
checkLoginPassEntity($usertotest, $passwordtotest, $entitytotest, $authmode, $context= '')
Return a login if login/pass was successfull.