30if (!defined(
'NOTOKENRENEWAL')) {
31 define(
'NOTOKENRENEWAL',
'1');
33if (!defined(
'NOREQUIREMENU')) {
34 define(
'NOREQUIREMENU',
'1');
36if (!defined(
'NOREQUIREHTML')) {
37 define(
'NOREQUIREHTML',
'1');
39if (!defined(
'NOREQUIREAJAX')) {
40 define(
'NOREQUIREAJAX',
'1');
42if (!defined(
'NOLOGIN')) {
45if (!defined(
'NOCSRFCHECK')) {
46 define(
"NOCSRFCHECK", 1);
49require
"../main.inc.php";
57require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
58require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
59require_once DOL_DOCUMENT_ROOT.
'/dav/dav.class.php';
60require_once DOL_DOCUMENT_ROOT.
'/dav/dav.lib.php';
62require_once DOL_DOCUMENT_ROOT.
'/includes/sabre/autoload.php';
66if (isset($_SERVER[
'PHP_AUTH_USER']) && $_SERVER[
'PHP_AUTH_USER'] !=
'') {
67 $user->fetch(0, $_SERVER[
'PHP_AUTH_USER']);
72$langs->loadLangs(array(
"main",
"other"));
75if (empty(
$conf->dav->enabled)) {
83 if (!in_array($ipremote, $allowedip)) {
85 print
'DAV not allowed from the IP '.$ipremote;
86 header(
'HTTP/1.1 503 DAV not allowed from your IP '.$ipremote);
95$publicDir = DOL_DATA_ROOT.
'/dav/public';
96$privateDir = DOL_DATA_ROOT.
'/dav/private';
97$ecmDir = DOL_DATA_ROOT.
'/ecm';
98$tmpDir = DOL_DATA_ROOT.
'/ecm/temp';
100 $publicDir =
$conf->dav->multidir_output[$entity].
'/public';
101 $privateDir =
$conf->dav->multidir_output[$entity].
'/private';
104 $ecmDir =
$conf->ecm->multidir_output[$entity];
105 $tmpDir =
$conf->ecm->multidir_output[$entity];
111$authBackend = new \Sabre\DAV\Auth\Backend\BasicCallBack(
117 static function ($username, $password) {
119 global $dolibarr_main_authentication, $dolibarr_auto_user;
121 if (empty($user->login)) {
122 dol_syslog(
"Failed to authenticate to DAV, login is not provided", LOG_WARNING);
125 if ($user->socid > 0) {
126 dol_syslog(
"Failed to authenticate to DAV, user is an external user", LOG_WARNING);
129 if ($user->login != $username) {
130 dol_syslog(
"Failed to authenticate to DAV, login does not match the login of loaded user", LOG_WARNING);
135 if (empty($dolibarr_main_authentication) || $dolibarr_main_authentication ==
'openid_connect') {
136 $dolibarr_main_authentication =
'dolibarr';
140 if ($dolibarr_main_authentication ==
'forceuser') {
141 if (empty($dolibarr_auto_user)) {
142 $dolibarr_auto_user =
'auto';
144 if ($dolibarr_auto_user != $username) {
145 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.");
150 $authmode = explode(
',', $dolibarr_main_authentication);
158 if ($user->status != $user::STATUS_ENABLED) {
165 if (($user->flagdelsessionsbefore && !empty($_SESSION[
"dol_logindate"]) && $user->flagdelsessionsbefore > $_SESSION[
"dol_logindate"])) {
167 dol_syslog(
"The user has a date for session invalidation = ".$user->flagdelsessionsbefore.
" and a session date = ".$_SESSION[
"dol_logindate"].
". We must invalidate its sessions.");
172 if ($user->isNotIntoValidityDateRange()) {
174 dol_syslog(
"The user login has a validity between [".$user->datestartvalidity.
" and ".$user->dateendvalidity.
"], current date is ".
dol_now());
182$authBackend->setRealm(constant(
'DOL_APPLICATION_TITLE').
' - WebDAV');
199 $nodes[] = new \Sabre\DAV\FS\Directory($publicDir);
202$nodes[] = new \Sabre\DAV\FS\Directory($privateDir);
205 $nodes[] = new \Sabre\DAV\FS\Directory($ecmDir);
224$server = new \Sabre\DAV\Server($nodes);
228$baseUri = DOL_URL_ROOT.
'/dav/fileserver.php/';
229if (isset($baseUri)) {
230 $server->setBaseUri($baseUri);
235 || !preg_match(
'/'.preg_quote(DOL_URL_ROOT.
'/dav/fileserver.php/public',
'/').
'/', Sabre\Uri\normalize($_SERVER[
"PHP_SELF"])))
236 && !preg_match(
'/^sabreAction=asset&assetName=[a-zA-Z0-9%\-\/]+\.(png|css|woff|ico|ttf)$/', $_SERVER[
"QUERY_STRING"])
239 $server->addPlugin(
new \Sabre\DAV\Auth\Plugin($authBackend));
242$lockBackend = new \Sabre\DAV\Locks\Backend\File($tmpDir.
'/.locksdb');
243$lockPlugin = new \Sabre\DAV\Locks\Plugin($lockBackend);
244$server->addPlugin($lockPlugin);
248 $browser = new \Sabre\DAV\Browser\Plugin();
249 $server->addPlugin($browser);
Class to manage Dolibarr users.
dol_now($mode='gmt')
Return date for now.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getUserRemoteIP($trusted=0)
Return the real IP of remote user.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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 successful.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.