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";
50require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
51require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
52require_once DOL_DOCUMENT_ROOT.
'/dav/dav.class.php';
53require_once DOL_DOCUMENT_ROOT.
'/dav/dav.lib.php';
55require_once DOL_DOCUMENT_ROOT.
'/includes/sabre/autoload.php';
67if (isset($_SERVER[
'PHP_AUTH_USER']) && $_SERVER[
'PHP_AUTH_USER'] !=
'') {
68 $user->fetch(0, $_SERVER[
'PHP_AUTH_USER']);
73$langs->loadLangs(array(
"main",
"other"));
76if (empty(
$conf->dav->enabled)) {
84 if (!in_array($ipremote, $allowedip)) {
86 print
'DAV not allowed from the IP '.$ipremote;
87 header(
'HTTP/1.1 503 DAV not allowed from your IP '.$ipremote);
96$publicDir = DOL_DATA_ROOT.
'/dav/public';
97$privateDir = DOL_DATA_ROOT.
'/dav/private';
98$ecmDir = DOL_DATA_ROOT.
'/ecm';
99$tmpDir = DOL_DATA_ROOT.
'/ecm/temp';
100if (isModEnabled(
'dav')) {
101 $publicDir =
$conf->dav->multidir_output[$entity].
'/public';
102 $privateDir =
$conf->dav->multidir_output[$entity].
'/private';
104if (isModEnabled(
'ecm')) {
105 $ecmDir =
$conf->ecm->multidir_output[$entity];
106 $tmpDir =
$conf->ecm->multidir_output[$entity];
112$authBackend = new \Sabre\DAV\Auth\Backend\BasicCallBack(
118 static function ($username, $password) {
120 global $dolibarr_main_authentication, $dolibarr_auto_user;
122 if (empty($user->login)) {
123 dol_syslog(
"Failed to authenticate to DAV, login is not provided", LOG_WARNING);
126 if ($user->socid > 0) {
127 dol_syslog(
"Failed to authenticate to DAV, user is an external user", LOG_WARNING);
130 if ($user->login != $username) {
131 dol_syslog(
"Failed to authenticate to DAV, login does not match the login of loaded user", LOG_WARNING);
136 if (empty($dolibarr_main_authentication) || $dolibarr_main_authentication ==
'openid_connect') {
137 $dolibarr_main_authentication =
'dolibarr';
141 if ($dolibarr_main_authentication ==
'forceuser') {
142 if (empty($dolibarr_auto_user)) {
143 $dolibarr_auto_user =
'auto';
145 if ($dolibarr_auto_user != $username) {
146 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.");
151 $authmode = explode(
',', $dolibarr_main_authentication);
159 if ($user->statut != $user::STATUS_ENABLED) {
166 if (($user->flagdelsessionsbefore && !empty($_SESSION[
"dol_logindate"]) && $user->flagdelsessionsbefore > $_SESSION[
"dol_logindate"])) {
168 dol_syslog(
"The user has a date for session invalidation = ".$user->flagdelsessionsbefore.
" and a session date = ".$_SESSION[
"dol_logindate"].
". We must invalidate its sessions.");
173 if ($user->isNotIntoValidityDateRange()) {
175 dol_syslog(
"The user login has a validity between [".$user->datestartvalidity.
" and ".$user->dateendvalidity.
"], current date is ".
dol_now());
183$authBackend->setRealm(constant(
'DOL_APPLICATION_TITLE').
' - WebDAV');
200 $nodes[] = new \Sabre\DAV\FS\Directory($publicDir);
203$nodes[] = new \Sabre\DAV\FS\Directory($privateDir);
206 $nodes[] = new \Sabre\DAV\FS\Directory($ecmDir);
225$server = new \Sabre\DAV\Server($nodes);
229$baseUri = DOL_URL_ROOT.
'/dav/fileserver.php/';
230if (isset($baseUri)) {
231 $server->setBaseUri($baseUri);
236 || !preg_match(
'/'.preg_quote(DOL_URL_ROOT.
'/dav/fileserver.php/public',
'/').
'/', $_SERVER[
"PHP_SELF"]))
237 && !preg_match(
'/^sabreAction=asset&assetName=[a-zA-Z0-9%\-\/]+\.(png|css|woff|ico|ttf)$/', $_SERVER[
"QUERY_STRING"])
240 $server->addPlugin(
new \Sabre\DAV\Auth\Plugin($authBackend));
243$lockBackend = new \Sabre\DAV\Locks\Backend\File($tmpDir.
'/.locksdb');
244$lockPlugin = new \Sabre\DAV\Locks\Plugin($lockBackend);
245$server->addPlugin($lockPlugin);
249 $browser = new \Sabre\DAV\Browser\Plugin();
250 $server->addPlugin($browser);
Class to manage Dolibarr users.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_now($mode='auto')
Return date for now.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
getUserRemoteIP()
Return the IP of remote user.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.