Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
dav.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * @author Anakeen
9  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
10  * @package FDL
11  */
12 
13 $d1 = microtime();
14 include_once ("../WHAT/Lib.Common.php");
15 include_once ("DAV/Class.FdlDav.php");
16 //error_log("dav: path_info=(".$_SERVER["PATH_INFO"].")");
17 $_SERVER['PATH_INFO'] = "/" . $_GET['filename'];
18 $type = isset($_GET['type']) ? $_GET['type'] : 'freedav';
19 
20 if ($type != 'webdav' && $type != 'freedav') {
21  error_log(sprintf("Error: Invalid DAV type '%s'", $type));
22  header('HTTP/1.1 500 Invalid DAV type');
23  exit;
24 }
25 
26 $_SERVER['SCRIPT_NAME'] = preg_replace('/index\.php$/', '', $_SERVER['SCRIPT_NAME']);
27 
28 global $action;
29 global $_SERVER;
30 
31 if ($type == 'webdav') {
32  webdav_auth();
33 }
34 
35 error_log(" [ " . $_SERVER['REQUEST_METHOD'] . " ]=[ " . $_SERVER['PATH_INFO'] . " ]=======");
36 whatInit();
37 $s = new HTTP_WebDAV_Server_Freedom($action->getParam("WEBDAV_DB"));
38 $s->setFolderMaxItem($action->getParam('WEBDAV_FOLDERMAXITEM'));
39 $path = $_SERVER['PATH_INFO'];
40 if ($type == "freedav") {
41  if (preg_match("|/vid-([0-9]+)-([0-9]+)-([^/]+)|", $path, $reg)) {
42  $docid = $reg[1];
43  $vid = $reg[2];
44  $sid = $reg[3];
45  //error_log("dav: -> $docid $vid $sid");
46  $login = $s->getLogin($docid, $vid, $sid);
47  //error_log("dav LOGIN: -> $login");
48 
49  }
50 } else {
51  $login = $_SERVER['PHP_AUTH_USER'];
52 }
53 if (!$login) {
54  if (((($path == "/") || (strtolower($path) == "/freedav")) && ($_SERVER['REQUEST_METHOD'] == "OPTIONS")) || ((($path == "/") || (strtolower($path) == "/freedav")) && ($_SERVER['REQUEST_METHOD'] == "PROPFIND"))) {
55  // keep without authenticate
56 
57  } else {
58  // header('HTTP/1.0 401 Unauthorized');
59  header('HTTP/1.0 403 Forbidden');
60  exit;
61  }
62 } else {
63  whatLogin($login);
64 }
65 
66 $d2 = microtime();
67 
68 $dt = sprintf("%.02f", microtime_diff($d1, $d2));
69 
70 $s->http_auth_realm = "Dynacase Platform connection";
71 $s->db_freedom = $action->getParam("FREEDOM_DB");
72 $s->type = $type;
73 $s->racine = $action->getParam("WEBDAV_ROOTID", 9);
74 $s->ServeRequest();
75 $d2 = microtime();
76 $d = sprintf("%.02f", microtime_diff($d1, $d2));
77 
78 error_log("================ $d $dt=====" . $login . "===================");
79 
80 function whatInit()
81 {
82  global $action;
83  include_once ('Class.User.php');
84  include_once ('Class.Session.php');
85 
86  $CoreNull = "";
87  $core = new Application();
88  $core->Set("CORE", $CoreNull);
89  $core->session = new Session();
90  $action = new Action();
91  $action->Set("", $core);
92  // i18n
93  $lang = $action->Getparam("CORE_LANG");
94  setLanguage($action->Getparam("CORE_LANG"));
95 }
96 
97 function whatLogin($login)
98 {
99  global $action;
100  include_once ('Class.User.php');
101  include_once ('Class.Session.php');
102 
103  if ($login != "") {
104  $action->user = new User(); //create user
105  $action->user->setLoginName($login);
106  }
107 }
108 
109 function webdav_auth()
110 {
111  include_once ('WHAT/Lib.Main.php');
112  include_once ('WHAT/Class.AuthenticatorManager.php');
113 
114  global $_SERVER;
115 
116  $status = AuthenticatorManager::checkAccess('basic');
117 
118  switch ($status) {
119  case 0: // it'good, user is authentified
120  break;
121 
122  default:
123  sleep(1); // for robots
124  // Redirect to authentication
125  AuthenticatorManager::$auth->askAuthentication();
126  exit(0);
127  }
128 
129  $_SERVER['PHP_AUTH_USER'] = AuthenticatorManager::$auth->getAuthUser();
130 }
131 ?>
← centre documentaire © anakeen - published under CC License - Dynacase