Core  3.2
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  * @package FDL
5 */
6 /**
7  * @author Anakeen
8  * @package FDL
9  */
10 
11 $d1 = microtime();
12 include_once ("../WHAT/Lib.Common.php");
13 chdir(DEFAULT_PUBDIR);
14 include_once ("DAV/Class.FdlDav.php");
15 //error_log("dav: path_info=(".$_SERVER["PATH_INFO"].")");
16 
17 $_SERVER['PATH_INFO'] = "/" . (empty($_GET['filename']) ? "" : $_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->dbaccess);
38 $s->setFolderMaxItem($action->getParam('WEBDAV_FOLDERMAXITEM'));
39 $path = $_SERVER['PATH_INFO'];
40 $login = "";
41 if ($type == "freedav") {
42  if (preg_match("|/vid-([0-9]+)-([0-9]+)-([^/]+)|", $path, $reg)) {
43  $docid = $reg[1];
44  $vid = $reg[2];
45  $sid = $reg[3];
46  //error_log("dav: -> $docid $vid $sid");
47  $login = $s->getLogin($docid, $vid, $sid);
48  //error_log("dav LOGIN: -> $login");
49 
50  }
51 } else {
52  $login = $_SERVER['PHP_AUTH_USER'];
53 }
54 if (!$login) {
55  if (((($path == "/") || (strtolower($path) == "/freedav")) && ($_SERVER['REQUEST_METHOD'] == "OPTIONS")) || ((($path == "/") || (strtolower($path) == "/freedav")) && ($_SERVER['REQUEST_METHOD'] == "PROPFIND"))) {
56  // keep without authenticate
57 
58  } else {
59  // header('HTTP/1.0 401 Unauthorized');
60  header('HTTP/1.0 403 Forbidden');
61  exit;
62  }
63 } else {
65 }
66 
67 $d2 = microtime();
68 
69 $dt = sprintf("%.02f", microtime_diff($d1, $d2));
70 
71 $s->http_auth_realm = "Dynacase Platform connection";
72 $s->db_freedom = $action->dbaccess;
73 $s->type = $type;
74 $s->racine = $action->getParam("WEBDAV_ROOTID", 9);
75 $s->ServeRequest();
76 $d2 = microtime();
77 $d = sprintf("%.02f", microtime_diff($d1, $d2));
78 
79 error_log("================ $d $dt=====" . $login . "===================");
80 
81 function whatInit()
82 {
83  global $action;
84  include_once ('Class.User.php');
85  include_once ('Class.Session.php');
86 
87  $CoreNull = "";
88  $core = new Application();
89  $core->Set("CORE", $CoreNull);
90  $core->session = new Session();
91  $action = new Action();
92  $action->Set("", $core);
93  // i18n
94  $lang = $action->Getparam("CORE_LANG");
95  setLanguage($action->Getparam("CORE_LANG"));
96 }
97 
98 function whatLogin($login)
99 {
100  global $action;
101  include_once ('Class.User.php');
102  include_once ('Class.Session.php');
103 
104  if ($login != "") {
105  $action->user = new Account(); //create user
106  $action->user->setLoginName($login);
107  $action->parent->user = $action->user;
108  }
109 }
110 
111 function webdav_auth()
112 {
113  include_once ('WHAT/Lib.Main.php');
114  include_once ('WHAT/Class.AuthenticatorManager.php');
115 
116  global $_SERVER;
117 
118  $status = AuthenticatorManager::checkAccess('basic');
119 
120  switch ($status) {
121  case 0: // it'good, user is authentified
122  break;
123 
124  default:
125  sleep(1); // for robots
126  // Redirect to authentication
127  AuthenticatorManager::$auth->askAuthentication(array());
128  exit(0);
129  }
130 
131  $_SERVER['PHP_AUTH_USER'] = AuthenticatorManager::$auth->getAuthUser();
132 }
$status
Definition: index.php:30
webdav_auth()
Definition: dav.php:111
$dt
Definition: dav.php:69
whatInit()
Definition: dav.php:81
$type
Definition: dav.php:18
$lang
Definition: lang.php:18
$d
Definition: dav.php:77
const DEFAULT_PUBDIR
Definition: Lib.Prefix.php:28
$d1
Definition: dav.php:11
$docid
Definition: cleanFamily.php:13
$d2
Definition: dav.php:67
$path
Definition: dav.php:39
global $_GET
Definition: wsh.php:37
microtime_diff($a, $b)
Definition: Lib.Common.php:302
$login
Definition: dav.php:40
setLanguage($lang)
Definition: Lib.Common.php:886
whatLogin($login)
Definition: dav.php:98
$_SERVER['PATH_INFO']
Definition: dav.php:17
switch($command) exit
Definition: checkVault.php:46
global $action
Definition: dav.php:28
$s
Definition: dav.php:37
$CoreNull
Definition: chgpasswd.php:32
$core
Definition: chgpasswd.php:33
← centre documentaire © anakeen