@@ -6730,14 +6730,14 @@ |
||
6730 | 6730 | { |
6731 | 6731 | if ($this->folderExists($_folder,true)) |
6732 | 6732 | { |
6733 | - if($this->isSentFolder($_folder)) |
|
6733 | + if($this->isSentFolder($_folder)) |
|
6734 | 6734 | { |
6735 | - $flags = '\\Seen'; |
|
6736 | - } elseif($this->isDraftFolder($_folder)) { |
|
6737 | - $flags = '\\Draft'; |
|
6738 | - } else { |
|
6739 | - $flags = ''; |
|
6740 | - } |
|
6735 | + $flags = '\\Seen'; |
|
6736 | + } elseif($this->isDraftFolder($_folder)) { |
|
6737 | + $flags = '\\Draft'; |
|
6738 | + } else { |
|
6739 | + $flags = ''; |
|
6740 | + } |
|
6741 | 6741 | $savefailed = false; |
6742 | 6742 | try |
6743 | 6743 | { |
@@ -43,209 +43,209 @@ |
||
43 | 43 | */ |
44 | 44 | class _parse_lockinfo |
45 | 45 | { |
46 | - /** |
|
47 | - * success state flag |
|
48 | - * |
|
49 | - * @var bool |
|
50 | - * @access public |
|
51 | - */ |
|
52 | - var $success = false; |
|
53 | - |
|
54 | - /** |
|
55 | - * lock type, currently only "write" |
|
56 | - * |
|
57 | - * @var string |
|
58 | - * @access public |
|
59 | - */ |
|
60 | - var $locktype = ""; |
|
61 | - |
|
62 | - /** |
|
63 | - * lock scope, "shared" or "exclusive" |
|
64 | - * |
|
65 | - * @var string |
|
66 | - * @access public |
|
67 | - */ |
|
68 | - var $lockscope = ""; |
|
69 | - |
|
70 | - /** |
|
71 | - * lock owner information |
|
72 | - * |
|
73 | - * @var string |
|
74 | - * @access public |
|
75 | - */ |
|
76 | - var $owner = ""; |
|
77 | - |
|
78 | - /** |
|
79 | - * flag that is set during lock owner read |
|
80 | - * |
|
81 | - * @var bool |
|
82 | - * @access private |
|
83 | - */ |
|
84 | - var $collect_owner = false; |
|
85 | - |
|
86 | - /** |
|
87 | - * constructor |
|
88 | - * |
|
89 | - * @param string path of stream to read |
|
90 | - * @access public |
|
91 | - */ |
|
92 | - function __construct($path) |
|
93 | - { |
|
94 | - // we assume success unless problems occur |
|
95 | - $this->success = true; |
|
96 | - |
|
97 | - // remember if any input was parsed |
|
98 | - $had_input = false; |
|
99 | - |
|
100 | - // open stream |
|
101 | - $f_in = fopen($path, "r"); |
|
102 | - if (!$f_in) { |
|
103 | - $this->success = false; |
|
104 | - return; |
|
105 | - } |
|
106 | - |
|
107 | - // create namespace aware parser |
|
108 | - $xml_parser = xml_parser_create_ns("UTF-8", " "); |
|
109 | - |
|
110 | - // set tag and data handlers |
|
111 | - xml_set_element_handler($xml_parser, |
|
112 | - array(&$this, "_startElement"), |
|
113 | - array(&$this, "_endElement")); |
|
114 | - xml_set_character_data_handler($xml_parser, |
|
115 | - array(&$this, "_data")); |
|
116 | - |
|
117 | - // we want a case sensitive parser |
|
118 | - xml_parser_set_option($xml_parser, |
|
119 | - XML_OPTION_CASE_FOLDING, false); |
|
120 | - |
|
121 | - // parse input |
|
122 | - while ($this->success && !feof($f_in)) { |
|
123 | - $line = fgets($f_in); |
|
124 | - if (is_string($line)) { |
|
125 | - $had_input = true; |
|
126 | - $this->success &= xml_parse($xml_parser, $line, false); |
|
127 | - } |
|
128 | - } |
|
129 | - |
|
130 | - // finish parsing |
|
131 | - if ($had_input) { |
|
132 | - $this->success &= xml_parse($xml_parser, "", true); |
|
133 | - } |
|
134 | - |
|
135 | - // check if required tags where found |
|
136 | - $this->success &= !empty($this->locktype); |
|
137 | - $this->success &= !empty($this->lockscope); |
|
138 | - |
|
139 | - // free parser resource |
|
140 | - xml_parser_free($xml_parser); |
|
141 | - |
|
142 | - // close input stream |
|
143 | - fclose($f_in); |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * tag start handler |
|
149 | - * |
|
150 | - * @param resource parser |
|
151 | - * @param string tag name |
|
152 | - * @param array tag attributes |
|
153 | - * @return void |
|
154 | - * @access private |
|
155 | - */ |
|
156 | - function _startElement($parser, $name, $attrs) |
|
157 | - { |
|
158 | - // namespace handling |
|
159 | - if (strstr($name, " ")) { |
|
160 | - list($ns, $tag) = explode(" ", $name); |
|
161 | - } else { |
|
162 | - $ns = ""; |
|
163 | - $tag = $name; |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - if ($this->collect_owner) { |
|
168 | - // everything within the <owner> tag needs to be collected |
|
169 | - $ns_short = ""; |
|
170 | - $ns_attr = ""; |
|
171 | - if ($ns) { |
|
172 | - if ($ns == "DAV:") { |
|
173 | - $ns_short = "D:"; |
|
174 | - } else { |
|
175 | - $ns_attr = " xmlns='$ns'"; |
|
176 | - } |
|
177 | - } |
|
178 | - $this->owner .= "<$ns_short$tag$ns_attr>"; |
|
179 | - } else if ($ns == "DAV:") { |
|
180 | - // parse only the essential tags |
|
181 | - switch ($tag) { |
|
182 | - case "write": |
|
183 | - $this->locktype = $tag; |
|
184 | - break; |
|
185 | - case "exclusive": |
|
186 | - case "shared": |
|
187 | - $this->lockscope = $tag; |
|
188 | - break; |
|
189 | - case "owner": |
|
190 | - $this->collect_owner = true; |
|
191 | - break; |
|
192 | - } |
|
193 | - } |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * data handler |
|
198 | - * |
|
199 | - * @param resource parser |
|
200 | - * @param string data |
|
201 | - * @return void |
|
202 | - * @access private |
|
203 | - */ |
|
204 | - function _data($parser, $data) |
|
205 | - { |
|
206 | - // only the <owner> tag has data content |
|
207 | - if ($this->collect_owner) { |
|
208 | - $this->owner .= $data; |
|
209 | - } |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * tag end handler |
|
214 | - * |
|
215 | - * @param resource parser |
|
216 | - * @param string tag name |
|
217 | - * @return void |
|
218 | - * @access private |
|
219 | - */ |
|
220 | - function _endElement($parser, $name) |
|
221 | - { |
|
222 | - // namespace handling |
|
223 | - if (strstr($name, " ")) { |
|
224 | - list($ns, $tag) = explode(" ", $name); |
|
225 | - } else { |
|
226 | - $ns = ""; |
|
227 | - $tag = $name; |
|
228 | - } |
|
229 | - |
|
230 | - // <owner> finished? |
|
231 | - if (($ns == "DAV:") && ($tag == "owner")) { |
|
232 | - $this->collect_owner = false; |
|
233 | - } |
|
234 | - |
|
235 | - // within <owner> we have to collect everything |
|
236 | - if ($this->collect_owner) { |
|
237 | - $ns_short = ""; |
|
238 | - $ns_attr = ""; |
|
239 | - if ($ns) { |
|
240 | - if ($ns == "DAV:") { |
|
241 | - $ns_short = "D:"; |
|
242 | - } else { |
|
243 | - $ns_attr = " xmlns='$ns'"; |
|
244 | - } |
|
245 | - } |
|
246 | - $this->owner .= "</$ns_short$tag$ns_attr>"; |
|
247 | - } |
|
248 | - } |
|
46 | + /** |
|
47 | + * success state flag |
|
48 | + * |
|
49 | + * @var bool |
|
50 | + * @access public |
|
51 | + */ |
|
52 | + var $success = false; |
|
53 | + |
|
54 | + /** |
|
55 | + * lock type, currently only "write" |
|
56 | + * |
|
57 | + * @var string |
|
58 | + * @access public |
|
59 | + */ |
|
60 | + var $locktype = ""; |
|
61 | + |
|
62 | + /** |
|
63 | + * lock scope, "shared" or "exclusive" |
|
64 | + * |
|
65 | + * @var string |
|
66 | + * @access public |
|
67 | + */ |
|
68 | + var $lockscope = ""; |
|
69 | + |
|
70 | + /** |
|
71 | + * lock owner information |
|
72 | + * |
|
73 | + * @var string |
|
74 | + * @access public |
|
75 | + */ |
|
76 | + var $owner = ""; |
|
77 | + |
|
78 | + /** |
|
79 | + * flag that is set during lock owner read |
|
80 | + * |
|
81 | + * @var bool |
|
82 | + * @access private |
|
83 | + */ |
|
84 | + var $collect_owner = false; |
|
85 | + |
|
86 | + /** |
|
87 | + * constructor |
|
88 | + * |
|
89 | + * @param string path of stream to read |
|
90 | + * @access public |
|
91 | + */ |
|
92 | + function __construct($path) |
|
93 | + { |
|
94 | + // we assume success unless problems occur |
|
95 | + $this->success = true; |
|
96 | + |
|
97 | + // remember if any input was parsed |
|
98 | + $had_input = false; |
|
99 | + |
|
100 | + // open stream |
|
101 | + $f_in = fopen($path, "r"); |
|
102 | + if (!$f_in) { |
|
103 | + $this->success = false; |
|
104 | + return; |
|
105 | + } |
|
106 | + |
|
107 | + // create namespace aware parser |
|
108 | + $xml_parser = xml_parser_create_ns("UTF-8", " "); |
|
109 | + |
|
110 | + // set tag and data handlers |
|
111 | + xml_set_element_handler($xml_parser, |
|
112 | + array(&$this, "_startElement"), |
|
113 | + array(&$this, "_endElement")); |
|
114 | + xml_set_character_data_handler($xml_parser, |
|
115 | + array(&$this, "_data")); |
|
116 | + |
|
117 | + // we want a case sensitive parser |
|
118 | + xml_parser_set_option($xml_parser, |
|
119 | + XML_OPTION_CASE_FOLDING, false); |
|
120 | + |
|
121 | + // parse input |
|
122 | + while ($this->success && !feof($f_in)) { |
|
123 | + $line = fgets($f_in); |
|
124 | + if (is_string($line)) { |
|
125 | + $had_input = true; |
|
126 | + $this->success &= xml_parse($xml_parser, $line, false); |
|
127 | + } |
|
128 | + } |
|
129 | + |
|
130 | + // finish parsing |
|
131 | + if ($had_input) { |
|
132 | + $this->success &= xml_parse($xml_parser, "", true); |
|
133 | + } |
|
134 | + |
|
135 | + // check if required tags where found |
|
136 | + $this->success &= !empty($this->locktype); |
|
137 | + $this->success &= !empty($this->lockscope); |
|
138 | + |
|
139 | + // free parser resource |
|
140 | + xml_parser_free($xml_parser); |
|
141 | + |
|
142 | + // close input stream |
|
143 | + fclose($f_in); |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * tag start handler |
|
149 | + * |
|
150 | + * @param resource parser |
|
151 | + * @param string tag name |
|
152 | + * @param array tag attributes |
|
153 | + * @return void |
|
154 | + * @access private |
|
155 | + */ |
|
156 | + function _startElement($parser, $name, $attrs) |
|
157 | + { |
|
158 | + // namespace handling |
|
159 | + if (strstr($name, " ")) { |
|
160 | + list($ns, $tag) = explode(" ", $name); |
|
161 | + } else { |
|
162 | + $ns = ""; |
|
163 | + $tag = $name; |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + if ($this->collect_owner) { |
|
168 | + // everything within the <owner> tag needs to be collected |
|
169 | + $ns_short = ""; |
|
170 | + $ns_attr = ""; |
|
171 | + if ($ns) { |
|
172 | + if ($ns == "DAV:") { |
|
173 | + $ns_short = "D:"; |
|
174 | + } else { |
|
175 | + $ns_attr = " xmlns='$ns'"; |
|
176 | + } |
|
177 | + } |
|
178 | + $this->owner .= "<$ns_short$tag$ns_attr>"; |
|
179 | + } else if ($ns == "DAV:") { |
|
180 | + // parse only the essential tags |
|
181 | + switch ($tag) { |
|
182 | + case "write": |
|
183 | + $this->locktype = $tag; |
|
184 | + break; |
|
185 | + case "exclusive": |
|
186 | + case "shared": |
|
187 | + $this->lockscope = $tag; |
|
188 | + break; |
|
189 | + case "owner": |
|
190 | + $this->collect_owner = true; |
|
191 | + break; |
|
192 | + } |
|
193 | + } |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * data handler |
|
198 | + * |
|
199 | + * @param resource parser |
|
200 | + * @param string data |
|
201 | + * @return void |
|
202 | + * @access private |
|
203 | + */ |
|
204 | + function _data($parser, $data) |
|
205 | + { |
|
206 | + // only the <owner> tag has data content |
|
207 | + if ($this->collect_owner) { |
|
208 | + $this->owner .= $data; |
|
209 | + } |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * tag end handler |
|
214 | + * |
|
215 | + * @param resource parser |
|
216 | + * @param string tag name |
|
217 | + * @return void |
|
218 | + * @access private |
|
219 | + */ |
|
220 | + function _endElement($parser, $name) |
|
221 | + { |
|
222 | + // namespace handling |
|
223 | + if (strstr($name, " ")) { |
|
224 | + list($ns, $tag) = explode(" ", $name); |
|
225 | + } else { |
|
226 | + $ns = ""; |
|
227 | + $tag = $name; |
|
228 | + } |
|
229 | + |
|
230 | + // <owner> finished? |
|
231 | + if (($ns == "DAV:") && ($tag == "owner")) { |
|
232 | + $this->collect_owner = false; |
|
233 | + } |
|
234 | + |
|
235 | + // within <owner> we have to collect everything |
|
236 | + if ($this->collect_owner) { |
|
237 | + $ns_short = ""; |
|
238 | + $ns_attr = ""; |
|
239 | + if ($ns) { |
|
240 | + if ($ns == "DAV:") { |
|
241 | + $ns_short = "D:"; |
|
242 | + } else { |
|
243 | + $ns_attr = " xmlns='$ns'"; |
|
244 | + } |
|
245 | + } |
|
246 | + $this->owner .= "</$ns_short$tag$ns_attr>"; |
|
247 | + } |
|
248 | + } |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | ?> |
@@ -43,198 +43,198 @@ |
||
43 | 43 | */ |
44 | 44 | class _parse_proppatch |
45 | 45 | { |
46 | - /** |
|
47 | - * |
|
48 | - * |
|
49 | - * @var |
|
50 | - * @access |
|
51 | - */ |
|
52 | - var $success; |
|
53 | - |
|
54 | - /** |
|
55 | - * |
|
56 | - * |
|
57 | - * @var |
|
58 | - * @access |
|
59 | - */ |
|
60 | - var $props; |
|
61 | - |
|
62 | - /** |
|
63 | - * |
|
64 | - * |
|
65 | - * @var |
|
66 | - * @access |
|
67 | - */ |
|
68 | - var $depth; |
|
69 | - |
|
70 | - /** |
|
71 | - * |
|
72 | - * |
|
73 | - * @var |
|
74 | - * @access |
|
75 | - */ |
|
76 | - var $mode; |
|
77 | - |
|
78 | - /** |
|
79 | - * |
|
80 | - * |
|
81 | - * @var |
|
82 | - * @access |
|
83 | - */ |
|
84 | - var $current; |
|
85 | - |
|
86 | - /** |
|
87 | - * On return whole request, if $store_request == true was specified in constructor |
|
88 | - * |
|
89 | - * @var string |
|
90 | - */ |
|
91 | - var $request; |
|
92 | - |
|
93 | - /** |
|
94 | - * constructor |
|
95 | - * |
|
96 | - * @param string path of input stream |
|
97 | - * @param boolean $store_request =false if true whole request data will be made available in $this->request |
|
98 | - * @access public |
|
99 | - */ |
|
100 | - function __construct($path, $store_request=false) |
|
101 | - { |
|
102 | - $this->success = true; |
|
103 | - |
|
104 | - $this->depth = 0; |
|
105 | - $this->props = array(); |
|
106 | - $had_input = false; |
|
107 | - |
|
108 | - $f_in = fopen($path, "r"); |
|
109 | - if (!$f_in) { |
|
110 | - $this->success = false; |
|
111 | - return; |
|
112 | - } |
|
113 | - |
|
114 | - $xml_parser = xml_parser_create_ns("UTF-8", " "); |
|
115 | - |
|
116 | - xml_set_element_handler($xml_parser, |
|
117 | - array(&$this, "_startElement"), |
|
118 | - array(&$this, "_endElement")); |
|
119 | - |
|
120 | - xml_set_character_data_handler($xml_parser, |
|
121 | - array(&$this, "_data")); |
|
122 | - |
|
123 | - xml_parser_set_option($xml_parser, |
|
124 | - XML_OPTION_CASE_FOLDING, false); |
|
125 | - |
|
126 | - while($this->success && !feof($f_in)) { |
|
127 | - $line = fgets($f_in); |
|
128 | - if ($store_request) $this->request .= $line; |
|
129 | - if (is_string($line)) { |
|
130 | - $had_input = true; |
|
131 | - $this->success &= xml_parse($xml_parser, $line, false); |
|
132 | - } |
|
133 | - } |
|
134 | - |
|
135 | - if($had_input) { |
|
136 | - $this->success &= xml_parse($xml_parser, "", true); |
|
137 | - } |
|
138 | - |
|
139 | - xml_parser_free($xml_parser); |
|
140 | - |
|
141 | - fclose($f_in); |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * tag start handler |
|
146 | - * |
|
147 | - * @param resource parser |
|
148 | - * @param string tag name |
|
149 | - * @param array tag attributes |
|
150 | - * @return void |
|
151 | - * @access private |
|
152 | - */ |
|
153 | - function _startElement($parser, $name, $attrs) |
|
154 | - { |
|
155 | - if (strstr($name, " ")) { |
|
156 | - list($ns, $tag) = explode(" ", $name); |
|
157 | - if ($ns == "") |
|
158 | - $this->success = false; |
|
159 | - } else { |
|
160 | - $ns = ""; |
|
161 | - $tag = $name; |
|
162 | - } |
|
163 | - |
|
164 | - if ($this->depth == 1) { |
|
165 | - $this->mode = $tag; |
|
166 | - } |
|
167 | - |
|
168 | - if ($this->depth == 3) { |
|
169 | - $prop = array("name" => $tag); |
|
170 | - $this->current = array("name" => $tag, "ns" => $ns, "status"=> 200); |
|
171 | - if ($this->mode == "set") { |
|
172 | - $this->current["val"] = ""; // default set val |
|
173 | - } |
|
174 | - } |
|
175 | - |
|
176 | - if ($this->depth >= 4) { |
|
177 | - $this->current["val"] .= "<$tag"; |
|
178 | - if (isset($attr)) { |
|
179 | - foreach ($attr as $key => $val) { |
|
180 | - $this->current["val"] .= ' '.$key.'="'.str_replace('"','"', $val).'"'; |
|
181 | - } |
|
182 | - } |
|
183 | - $this->current["val"] .= ">"; |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - |
|
188 | - $this->depth++; |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * tag end handler |
|
193 | - * |
|
194 | - * @param resource parser |
|
195 | - * @param string tag name |
|
196 | - * @return void |
|
197 | - * @access private |
|
198 | - */ |
|
199 | - function _endElement($parser, $name) |
|
200 | - { |
|
201 | - if (strstr($name, " ")) { |
|
202 | - list($ns, $tag) = explode(" ", $name); |
|
203 | - if ($ns == "") |
|
204 | - $this->success = false; |
|
205 | - } else { |
|
206 | - $ns = ""; |
|
207 | - $tag = $name; |
|
208 | - } |
|
209 | - |
|
210 | - $this->depth--; |
|
211 | - |
|
212 | - if ($this->depth >= 4) { |
|
213 | - $this->current["val"] .= "</$tag>"; |
|
214 | - } |
|
215 | - |
|
216 | - if ($this->depth == 3) { |
|
217 | - if (isset($this->current)) { |
|
218 | - $this->props[] = $this->current; |
|
219 | - unset($this->current); |
|
220 | - } |
|
221 | - } |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * input data handler |
|
226 | - * |
|
227 | - * @param resource parser |
|
228 | - * @param string data |
|
229 | - * @return void |
|
230 | - * @access private |
|
231 | - */ |
|
232 | - function _data($parser, $data) |
|
233 | - { |
|
234 | - if (isset($this->current)) { |
|
235 | - $this->current["val"] .= $data; |
|
236 | - } |
|
237 | - } |
|
46 | + /** |
|
47 | + * |
|
48 | + * |
|
49 | + * @var |
|
50 | + * @access |
|
51 | + */ |
|
52 | + var $success; |
|
53 | + |
|
54 | + /** |
|
55 | + * |
|
56 | + * |
|
57 | + * @var |
|
58 | + * @access |
|
59 | + */ |
|
60 | + var $props; |
|
61 | + |
|
62 | + /** |
|
63 | + * |
|
64 | + * |
|
65 | + * @var |
|
66 | + * @access |
|
67 | + */ |
|
68 | + var $depth; |
|
69 | + |
|
70 | + /** |
|
71 | + * |
|
72 | + * |
|
73 | + * @var |
|
74 | + * @access |
|
75 | + */ |
|
76 | + var $mode; |
|
77 | + |
|
78 | + /** |
|
79 | + * |
|
80 | + * |
|
81 | + * @var |
|
82 | + * @access |
|
83 | + */ |
|
84 | + var $current; |
|
85 | + |
|
86 | + /** |
|
87 | + * On return whole request, if $store_request == true was specified in constructor |
|
88 | + * |
|
89 | + * @var string |
|
90 | + */ |
|
91 | + var $request; |
|
92 | + |
|
93 | + /** |
|
94 | + * constructor |
|
95 | + * |
|
96 | + * @param string path of input stream |
|
97 | + * @param boolean $store_request =false if true whole request data will be made available in $this->request |
|
98 | + * @access public |
|
99 | + */ |
|
100 | + function __construct($path, $store_request=false) |
|
101 | + { |
|
102 | + $this->success = true; |
|
103 | + |
|
104 | + $this->depth = 0; |
|
105 | + $this->props = array(); |
|
106 | + $had_input = false; |
|
107 | + |
|
108 | + $f_in = fopen($path, "r"); |
|
109 | + if (!$f_in) { |
|
110 | + $this->success = false; |
|
111 | + return; |
|
112 | + } |
|
113 | + |
|
114 | + $xml_parser = xml_parser_create_ns("UTF-8", " "); |
|
115 | + |
|
116 | + xml_set_element_handler($xml_parser, |
|
117 | + array(&$this, "_startElement"), |
|
118 | + array(&$this, "_endElement")); |
|
119 | + |
|
120 | + xml_set_character_data_handler($xml_parser, |
|
121 | + array(&$this, "_data")); |
|
122 | + |
|
123 | + xml_parser_set_option($xml_parser, |
|
124 | + XML_OPTION_CASE_FOLDING, false); |
|
125 | + |
|
126 | + while($this->success && !feof($f_in)) { |
|
127 | + $line = fgets($f_in); |
|
128 | + if ($store_request) $this->request .= $line; |
|
129 | + if (is_string($line)) { |
|
130 | + $had_input = true; |
|
131 | + $this->success &= xml_parse($xml_parser, $line, false); |
|
132 | + } |
|
133 | + } |
|
134 | + |
|
135 | + if($had_input) { |
|
136 | + $this->success &= xml_parse($xml_parser, "", true); |
|
137 | + } |
|
138 | + |
|
139 | + xml_parser_free($xml_parser); |
|
140 | + |
|
141 | + fclose($f_in); |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * tag start handler |
|
146 | + * |
|
147 | + * @param resource parser |
|
148 | + * @param string tag name |
|
149 | + * @param array tag attributes |
|
150 | + * @return void |
|
151 | + * @access private |
|
152 | + */ |
|
153 | + function _startElement($parser, $name, $attrs) |
|
154 | + { |
|
155 | + if (strstr($name, " ")) { |
|
156 | + list($ns, $tag) = explode(" ", $name); |
|
157 | + if ($ns == "") |
|
158 | + $this->success = false; |
|
159 | + } else { |
|
160 | + $ns = ""; |
|
161 | + $tag = $name; |
|
162 | + } |
|
163 | + |
|
164 | + if ($this->depth == 1) { |
|
165 | + $this->mode = $tag; |
|
166 | + } |
|
167 | + |
|
168 | + if ($this->depth == 3) { |
|
169 | + $prop = array("name" => $tag); |
|
170 | + $this->current = array("name" => $tag, "ns" => $ns, "status"=> 200); |
|
171 | + if ($this->mode == "set") { |
|
172 | + $this->current["val"] = ""; // default set val |
|
173 | + } |
|
174 | + } |
|
175 | + |
|
176 | + if ($this->depth >= 4) { |
|
177 | + $this->current["val"] .= "<$tag"; |
|
178 | + if (isset($attr)) { |
|
179 | + foreach ($attr as $key => $val) { |
|
180 | + $this->current["val"] .= ' '.$key.'="'.str_replace('"','"', $val).'"'; |
|
181 | + } |
|
182 | + } |
|
183 | + $this->current["val"] .= ">"; |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + |
|
188 | + $this->depth++; |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * tag end handler |
|
193 | + * |
|
194 | + * @param resource parser |
|
195 | + * @param string tag name |
|
196 | + * @return void |
|
197 | + * @access private |
|
198 | + */ |
|
199 | + function _endElement($parser, $name) |
|
200 | + { |
|
201 | + if (strstr($name, " ")) { |
|
202 | + list($ns, $tag) = explode(" ", $name); |
|
203 | + if ($ns == "") |
|
204 | + $this->success = false; |
|
205 | + } else { |
|
206 | + $ns = ""; |
|
207 | + $tag = $name; |
|
208 | + } |
|
209 | + |
|
210 | + $this->depth--; |
|
211 | + |
|
212 | + if ($this->depth >= 4) { |
|
213 | + $this->current["val"] .= "</$tag>"; |
|
214 | + } |
|
215 | + |
|
216 | + if ($this->depth == 3) { |
|
217 | + if (isset($this->current)) { |
|
218 | + $this->props[] = $this->current; |
|
219 | + unset($this->current); |
|
220 | + } |
|
221 | + } |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * input data handler |
|
226 | + * |
|
227 | + * @param resource parser |
|
228 | + * @param string data |
|
229 | + * @return void |
|
230 | + * @access private |
|
231 | + */ |
|
232 | + function _data($parser, $data) |
|
233 | + { |
|
234 | + if (isset($this->current)) { |
|
235 | + $this->current["val"] .= $data; |
|
236 | + } |
|
237 | + } |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /* |
@@ -42,244 +42,244 @@ |
||
42 | 42 | */ |
43 | 43 | class _parse_propfind |
44 | 44 | { |
45 | - /** |
|
46 | - * success state flag |
|
47 | - * |
|
48 | - * @var bool |
|
49 | - * @access public |
|
50 | - */ |
|
51 | - var $success = false; |
|
45 | + /** |
|
46 | + * success state flag |
|
47 | + * |
|
48 | + * @var bool |
|
49 | + * @access public |
|
50 | + */ |
|
51 | + var $success = false; |
|
52 | 52 | |
53 | - /** |
|
54 | - * found properties are collected here |
|
55 | - * |
|
56 | - * @var array |
|
57 | - * @access public |
|
58 | - */ |
|
59 | - var $props = false; |
|
53 | + /** |
|
54 | + * found properties are collected here |
|
55 | + * |
|
56 | + * @var array |
|
57 | + * @access public |
|
58 | + */ |
|
59 | + var $props = false; |
|
60 | 60 | |
61 | - /** |
|
62 | - * found (CalDAV) filters are collected here |
|
63 | - * |
|
64 | - * @var array |
|
65 | - * @access public |
|
66 | - */ |
|
67 | - var $filters = false; |
|
61 | + /** |
|
62 | + * found (CalDAV) filters are collected here |
|
63 | + * |
|
64 | + * @var array |
|
65 | + * @access public |
|
66 | + */ |
|
67 | + var $filters = false; |
|
68 | 68 | |
69 | - /** |
|
70 | - * found other tags, eg. CalDAV calendar-multiget href's |
|
71 | - * |
|
72 | - * @var array |
|
73 | - * @access public |
|
74 | - */ |
|
75 | - var $other = false; |
|
69 | + /** |
|
70 | + * found other tags, eg. CalDAV calendar-multiget href's |
|
71 | + * |
|
72 | + * @var array |
|
73 | + * @access public |
|
74 | + */ |
|
75 | + var $other = false; |
|
76 | 76 | |
77 | - /** |
|
78 | - * what we are currently parsing: props or filters |
|
79 | - * |
|
80 | - * @var array |
|
81 | - * @access private |
|
82 | - */ |
|
83 | - var $use = 'props'; |
|
77 | + /** |
|
78 | + * what we are currently parsing: props or filters |
|
79 | + * |
|
80 | + * @var array |
|
81 | + * @access private |
|
82 | + */ |
|
83 | + var $use = 'props'; |
|
84 | 84 | |
85 | - /** |
|
86 | - * Root tag, usually 'propfind' for PROPFIND, but can be eg. 'calendar-query' or 'calendar-multiget' for CalDAV REPORT |
|
87 | - * |
|
88 | - * @var array with keys 'name' and 'ns' |
|
89 | - */ |
|
90 | - var $root; |
|
85 | + /** |
|
86 | + * Root tag, usually 'propfind' for PROPFIND, but can be eg. 'calendar-query' or 'calendar-multiget' for CalDAV REPORT |
|
87 | + * |
|
88 | + * @var array with keys 'name' and 'ns' |
|
89 | + */ |
|
90 | + var $root; |
|
91 | 91 | |
92 | - /** |
|
93 | - * internal tag nesting depth counter |
|
94 | - * |
|
95 | - * @var int |
|
96 | - * @access private |
|
97 | - */ |
|
98 | - var $depth = 0; |
|
92 | + /** |
|
93 | + * internal tag nesting depth counter |
|
94 | + * |
|
95 | + * @var int |
|
96 | + * @access private |
|
97 | + */ |
|
98 | + var $depth = 0; |
|
99 | 99 | |
100 | - /** |
|
101 | - * On return whole request, if $store_request == true was specified in constructor |
|
102 | - * |
|
103 | - * @var string |
|
104 | - */ |
|
105 | - var $request; |
|
100 | + /** |
|
101 | + * On return whole request, if $store_request == true was specified in constructor |
|
102 | + * |
|
103 | + * @var string |
|
104 | + */ |
|
105 | + var $request; |
|
106 | 106 | |
107 | - /** |
|
108 | - * constructor |
|
109 | - * |
|
110 | - * @access public |
|
111 | - * @param string $path |
|
112 | - * @param boolean $store_request =false if true whole request data will be made available in $this->request |
|
113 | - */ |
|
114 | - function __construct($path, $store_request=false) |
|
115 | - { |
|
116 | - // success state flag |
|
117 | - $this->success = true; |
|
107 | + /** |
|
108 | + * constructor |
|
109 | + * |
|
110 | + * @access public |
|
111 | + * @param string $path |
|
112 | + * @param boolean $store_request =false if true whole request data will be made available in $this->request |
|
113 | + */ |
|
114 | + function __construct($path, $store_request=false) |
|
115 | + { |
|
116 | + // success state flag |
|
117 | + $this->success = true; |
|
118 | 118 | |
119 | - // property storage array |
|
120 | - $this->props = array(); |
|
119 | + // property storage array |
|
120 | + $this->props = array(); |
|
121 | 121 | |
122 | - // internal tag depth counter |
|
123 | - $this->depth = 0; |
|
122 | + // internal tag depth counter |
|
123 | + $this->depth = 0; |
|
124 | 124 | |
125 | - // remember if any input was parsed |
|
126 | - $had_input = false; |
|
125 | + // remember if any input was parsed |
|
126 | + $had_input = false; |
|
127 | 127 | |
128 | - // open input stream |
|
129 | - $f_in = fopen($path, "r"); |
|
130 | - if (!$f_in) { |
|
131 | - $this->success = false; |
|
132 | - return; |
|
133 | - } |
|
128 | + // open input stream |
|
129 | + $f_in = fopen($path, "r"); |
|
130 | + if (!$f_in) { |
|
131 | + $this->success = false; |
|
132 | + return; |
|
133 | + } |
|
134 | 134 | |
135 | - // create XML parser |
|
136 | - $xml_parser = xml_parser_create_ns("UTF-8", " "); |
|
135 | + // create XML parser |
|
136 | + $xml_parser = xml_parser_create_ns("UTF-8", " "); |
|
137 | 137 | |
138 | - // set tag and data handlers |
|
139 | - xml_set_element_handler($xml_parser, |
|
140 | - array(&$this, "_startElement"), |
|
141 | - array(&$this, "_endElement")); |
|
138 | + // set tag and data handlers |
|
139 | + xml_set_element_handler($xml_parser, |
|
140 | + array(&$this, "_startElement"), |
|
141 | + array(&$this, "_endElement")); |
|
142 | 142 | |
143 | 143 | xml_set_character_data_handler($xml_parser, |
144 | - array(&$this,'_charData') |
|
145 | - ); |
|
144 | + array(&$this,'_charData') |
|
145 | + ); |
|
146 | 146 | |
147 | - // we want a case sensitive parser |
|
148 | - xml_parser_set_option($xml_parser, |
|
149 | - XML_OPTION_CASE_FOLDING, false); |
|
147 | + // we want a case sensitive parser |
|
148 | + xml_parser_set_option($xml_parser, |
|
149 | + XML_OPTION_CASE_FOLDING, false); |
|
150 | 150 | |
151 | - // parse input |
|
152 | - while ($this->success && !feof($f_in)) { |
|
153 | - $line = fgets($f_in); |
|
154 | - if ($store_request) $this->request .= $line; |
|
155 | - if (is_string($line)) { |
|
156 | - $had_input = true; |
|
157 | - $this->success &= xml_parse($xml_parser, $line, false); |
|
158 | - } |
|
159 | - } |
|
151 | + // parse input |
|
152 | + while ($this->success && !feof($f_in)) { |
|
153 | + $line = fgets($f_in); |
|
154 | + if ($store_request) $this->request .= $line; |
|
155 | + if (is_string($line)) { |
|
156 | + $had_input = true; |
|
157 | + $this->success &= xml_parse($xml_parser, $line, false); |
|
158 | + } |
|
159 | + } |
|
160 | 160 | |
161 | - // finish parsing |
|
162 | - if ($had_input) { |
|
163 | - $this->success &= xml_parse($xml_parser, "", true); |
|
164 | - } |
|
161 | + // finish parsing |
|
162 | + if ($had_input) { |
|
163 | + $this->success &= xml_parse($xml_parser, "", true); |
|
164 | + } |
|
165 | 165 | |
166 | - // free parser |
|
167 | - xml_parser_free($xml_parser); |
|
166 | + // free parser |
|
167 | + xml_parser_free($xml_parser); |
|
168 | 168 | |
169 | - // close input stream |
|
170 | - fclose($f_in); |
|
169 | + // close input stream |
|
170 | + fclose($f_in); |
|
171 | 171 | |
172 | - // if no input was parsed it was a request |
|
173 | - if(!count($this->props)) $this->props = "all"; // default |
|
174 | - } |
|
172 | + // if no input was parsed it was a request |
|
173 | + if(!count($this->props)) $this->props = "all"; // default |
|
174 | + } |
|
175 | 175 | |
176 | 176 | |
177 | - /** |
|
178 | - * start tag handler |
|
179 | - * |
|
180 | - * @access private |
|
181 | - * @param resource parser |
|
182 | - * @param string tag name |
|
183 | - * @param array tag attributes |
|
184 | - */ |
|
185 | - function _startElement($parser, $name, $attrs) |
|
186 | - { |
|
187 | - // name space handling |
|
188 | - if (strstr($name, " ")) { |
|
189 | - list($ns, $tag) = explode(" ", $name); |
|
190 | - if ($ns == "") |
|
191 | - $this->success = false; |
|
192 | - } else { |
|
193 | - $ns = ""; |
|
194 | - $tag = $name; |
|
195 | - } |
|
177 | + /** |
|
178 | + * start tag handler |
|
179 | + * |
|
180 | + * @access private |
|
181 | + * @param resource parser |
|
182 | + * @param string tag name |
|
183 | + * @param array tag attributes |
|
184 | + */ |
|
185 | + function _startElement($parser, $name, $attrs) |
|
186 | + { |
|
187 | + // name space handling |
|
188 | + if (strstr($name, " ")) { |
|
189 | + list($ns, $tag) = explode(" ", $name); |
|
190 | + if ($ns == "") |
|
191 | + $this->success = false; |
|
192 | + } else { |
|
193 | + $ns = ""; |
|
194 | + $tag = $name; |
|
195 | + } |
|
196 | 196 | |
197 | - // record root tag |
|
198 | - if ($this->depth == 0) { |
|
199 | - $this->root = array('name' => $tag, 'xmlns' => $ns, 'attrs' => $attrs); |
|
200 | - } |
|
201 | - // special tags at level 1: <allprop> and <propname> |
|
202 | - if ($this->depth == 1) { |
|
203 | - $this->use = 'props'; |
|
204 | - switch ($tag) |
|
205 | - { |
|
206 | - case "allprop": |
|
207 | - $this->props = "all"; |
|
197 | + // record root tag |
|
198 | + if ($this->depth == 0) { |
|
199 | + $this->root = array('name' => $tag, 'xmlns' => $ns, 'attrs' => $attrs); |
|
200 | + } |
|
201 | + // special tags at level 1: <allprop> and <propname> |
|
202 | + if ($this->depth == 1) { |
|
203 | + $this->use = 'props'; |
|
204 | + switch ($tag) |
|
205 | + { |
|
206 | + case "allprop": |
|
207 | + $this->props = "all"; |
|
208 | 208 | break; |
209 | - case "propname": |
|
210 | - $this->props = "names"; |
|
211 | - break; |
|
212 | - case 'prop': |
|
213 | - break; |
|
214 | - case 'filter': |
|
215 | - $this->use = 'filters'; |
|
216 | - $this->filters['attrs'] = $attrs; // need attrs eg. <filters test="(anyof|alloff)"> |
|
217 | - break; |
|
218 | - default: |
|
219 | - $this->use = 'other'; |
|
220 | - break; |
|
221 | - } |
|
222 | - } |
|
209 | + case "propname": |
|
210 | + $this->props = "names"; |
|
211 | + break; |
|
212 | + case 'prop': |
|
213 | + break; |
|
214 | + case 'filter': |
|
215 | + $this->use = 'filters'; |
|
216 | + $this->filters['attrs'] = $attrs; // need attrs eg. <filters test="(anyof|alloff)"> |
|
217 | + break; |
|
218 | + default: |
|
219 | + $this->use = 'other'; |
|
220 | + break; |
|
221 | + } |
|
222 | + } |
|
223 | 223 | //echo "$this->depth: use=$this->use $ns:$tag attrs=".array2string($attrs)."\n"; |
224 | 224 | |
225 | - // requested properties are found at level 2 |
|
226 | - // CalDAV filters can be at deeper levels too and we need the attrs, same for other tags (eg. multiget href's) |
|
227 | - if ($this->depth == 2 || $this->use == 'filters' && $this->depth >= 2 || $this->use == 'other' || |
|
228 | - $this->use == 'props' && $this->depth >= 2) { |
|
229 | - $prop = array("name" => $tag); |
|
230 | - if ($ns) |
|
231 | - $prop["xmlns"] = $ns; |
|
232 | - if ($this->use != 'props' || $this->depth > 2) { |
|
233 | - $prop['attrs'] = $attrs; |
|
234 | - $prop['depth'] = $this->depth; |
|
235 | - } |
|
236 | - // collect sub-elements of props in the original props children attribute |
|
237 | - // eg. required for CalDAV <calendar-data><expand start="..." end="..."/></calendar-data> |
|
238 | - if ($this->use == 'props' && $this->depth > 2) |
|
239 | - { |
|
240 | - $this->last_prop['children'][$tag] = $prop; |
|
241 | - } |
|
242 | - else |
|
243 | - { |
|
244 | - // this can happen if we have allprop and prop in one propfind: |
|
245 | - // <allprop /><prop><blah /></prop>, eg. blah is not automatic returned by allprop |
|
246 | - if (!is_array($this->{$this->use}) && $this->{$this->use}) $this->{$this->use} = array($this->{$this->use}); |
|
247 | - $this->{$this->use}[] =& $prop; |
|
248 | - $this->last_prop =& $prop; |
|
249 | - unset($prop); |
|
250 | - } |
|
251 | - } |
|
225 | + // requested properties are found at level 2 |
|
226 | + // CalDAV filters can be at deeper levels too and we need the attrs, same for other tags (eg. multiget href's) |
|
227 | + if ($this->depth == 2 || $this->use == 'filters' && $this->depth >= 2 || $this->use == 'other' || |
|
228 | + $this->use == 'props' && $this->depth >= 2) { |
|
229 | + $prop = array("name" => $tag); |
|
230 | + if ($ns) |
|
231 | + $prop["xmlns"] = $ns; |
|
232 | + if ($this->use != 'props' || $this->depth > 2) { |
|
233 | + $prop['attrs'] = $attrs; |
|
234 | + $prop['depth'] = $this->depth; |
|
235 | + } |
|
236 | + // collect sub-elements of props in the original props children attribute |
|
237 | + // eg. required for CalDAV <calendar-data><expand start="..." end="..."/></calendar-data> |
|
238 | + if ($this->use == 'props' && $this->depth > 2) |
|
239 | + { |
|
240 | + $this->last_prop['children'][$tag] = $prop; |
|
241 | + } |
|
242 | + else |
|
243 | + { |
|
244 | + // this can happen if we have allprop and prop in one propfind: |
|
245 | + // <allprop /><prop><blah /></prop>, eg. blah is not automatic returned by allprop |
|
246 | + if (!is_array($this->{$this->use}) && $this->{$this->use}) $this->{$this->use} = array($this->{$this->use}); |
|
247 | + $this->{$this->use}[] =& $prop; |
|
248 | + $this->last_prop =& $prop; |
|
249 | + unset($prop); |
|
250 | + } |
|
251 | + } |
|
252 | 252 | |
253 | - // increment depth count |
|
254 | - $this->depth++; |
|
255 | - } |
|
253 | + // increment depth count |
|
254 | + $this->depth++; |
|
255 | + } |
|
256 | 256 | |
257 | 257 | |
258 | - /** |
|
259 | - * end tag handler |
|
260 | - * |
|
261 | - * @access private |
|
262 | - * @param resource parser |
|
263 | - * @param string tag name |
|
264 | - */ |
|
265 | - function _endElement($parser, $name) |
|
266 | - { |
|
267 | - // here we only need to decrement the depth count |
|
268 | - $this->depth--; |
|
269 | - } |
|
258 | + /** |
|
259 | + * end tag handler |
|
260 | + * |
|
261 | + * @access private |
|
262 | + * @param resource parser |
|
263 | + * @param string tag name |
|
264 | + */ |
|
265 | + function _endElement($parser, $name) |
|
266 | + { |
|
267 | + // here we only need to decrement the depth count |
|
268 | + $this->depth--; |
|
269 | + } |
|
270 | 270 | |
271 | 271 | |
272 | - /** |
|
273 | - * char data handler for non prop tags, eg. href's in CalDAV multiget, or filter contents |
|
274 | - * |
|
275 | - * @access private |
|
276 | - * @param resource parser |
|
277 | - * @param string character data |
|
278 | - */ |
|
279 | - function _charData($parser, $data) |
|
280 | - { |
|
281 | - if ($this->use != 'props' && ($n = count($this->{$this->use})) && ($data = trim($data))) { |
|
282 | - $this->{$this->use}[$n-1]['data'] = $data; |
|
283 | - } |
|
284 | - } |
|
272 | + /** |
|
273 | + * char data handler for non prop tags, eg. href's in CalDAV multiget, or filter contents |
|
274 | + * |
|
275 | + * @access private |
|
276 | + * @param resource parser |
|
277 | + * @param string character data |
|
278 | + */ |
|
279 | + function _charData($parser, $data) |
|
280 | + { |
|
281 | + if ($this->use != 'props' && ($n = count($this->{$this->use})) && ($data = trim($data))) { |
|
282 | + $this->{$this->use}[$n-1]['data'] = $data; |
|
283 | + } |
|
284 | + } |
|
285 | 285 | } |
@@ -44,793 +44,793 @@ discard block |
||
44 | 44 | */ |
45 | 45 | class HTTP_WebDAV_Server_Filesystem extends HTTP_WebDAV_Server |
46 | 46 | { |
47 | - /** |
|
48 | - * Root directory for WebDAV access |
|
49 | - * |
|
50 | - * Defaults to webserver document root (set by ServeRequest) |
|
51 | - * |
|
52 | - * @access private |
|
53 | - * @var string |
|
54 | - */ |
|
55 | - var $base = ""; |
|
56 | - |
|
57 | - /** |
|
58 | - * MySQL Host where property and locking information is stored |
|
59 | - * |
|
60 | - * @access private |
|
61 | - * @var string |
|
62 | - */ |
|
63 | - var $db_host = "localhost"; |
|
64 | - |
|
65 | - /** |
|
66 | - * MySQL database for property/locking information storage |
|
67 | - * |
|
68 | - * @access private |
|
69 | - * @var string |
|
70 | - */ |
|
71 | - var $db_name = "webdav"; |
|
72 | - |
|
73 | - /** |
|
74 | - * MySQL table name prefix |
|
75 | - * |
|
76 | - * @access private |
|
77 | - * @var string |
|
78 | - */ |
|
79 | - var $db_prefix = ""; |
|
80 | - |
|
81 | - /** |
|
82 | - * MySQL user for property/locking db access |
|
83 | - * |
|
84 | - * @access private |
|
85 | - * @var string |
|
86 | - */ |
|
87 | - var $db_user = "root"; |
|
88 | - |
|
89 | - /** |
|
90 | - * MySQL password for property/locking db access |
|
91 | - * |
|
92 | - * @access private |
|
93 | - * @var string |
|
94 | - */ |
|
95 | - var $db_passwd = ""; |
|
96 | - |
|
97 | - /** |
|
98 | - * Serve a webdav request |
|
99 | - * |
|
100 | - * @access public |
|
101 | - * @param string |
|
102 | - */ |
|
103 | - function ServeRequest($base = false) |
|
104 | - { |
|
105 | - // special treatment for litmus compliance test |
|
106 | - // reply on its identifier header |
|
107 | - // not needed for the test itself but eases debugging |
|
108 | - if (isset($this->_SERVER['HTTP_X_LITMUS'])) { |
|
109 | - error_log("Litmus test ".$this->_SERVER['HTTP_X_LITMUS']); |
|
110 | - header("X-Litmus-reply: ".$this->_SERVER['HTTP_X_LITMUS']); |
|
111 | - } |
|
112 | - |
|
113 | - // set root directory, defaults to webserver document root if not set |
|
114 | - if ($base) { |
|
115 | - $this->base = realpath($base); // TODO throw if not a directory |
|
116 | - } else if (!$this->base) { |
|
117 | - $this->base = $this->_SERVER['DOCUMENT_ROOT']; |
|
118 | - } |
|
119 | - |
|
120 | - // establish connection to property/locking db |
|
121 | - mysql_connect($this->db_host, $this->db_user, $this->db_passwd) or die(mysql_error()); |
|
122 | - mysql_select_db($this->db_name) or die(mysql_error()); |
|
123 | - // TODO throw on connection problems |
|
124 | - |
|
125 | - // let the base class do all the work |
|
126 | - parent::ServeRequest(); |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * No authentication is needed here |
|
131 | - * |
|
132 | - * @access private |
|
133 | - * @param string HTTP Authentication type (Basic, Digest, ...) |
|
134 | - * @param string Username |
|
135 | - * @param string Password |
|
136 | - * @return bool true on successful authentication |
|
137 | - */ |
|
138 | - function check_auth($type, $user, $pass) |
|
139 | - { |
|
140 | - return true; |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * PROPFIND method handler |
|
146 | - * |
|
147 | - * @param array general parameter passing array |
|
148 | - * @param array return array for file properties |
|
149 | - * @return bool true on success |
|
150 | - */ |
|
151 | - function PROPFIND(&$options, &$files) |
|
152 | - { |
|
153 | - // get absolute fs path to requested resource |
|
154 | - $fspath = $this->base . $options["path"]; |
|
155 | - |
|
156 | - // sanity check |
|
157 | - if (!file_exists($fspath)) { |
|
158 | - return false; |
|
159 | - } |
|
160 | - |
|
161 | - // prepare property array |
|
162 | - $files["files"] = array(); |
|
163 | - |
|
164 | - // store information for the requested path itself |
|
165 | - $files["files"][] = $this->fileinfo($options["path"]); |
|
166 | - |
|
167 | - // information for contained resources requested? |
|
168 | - if (!empty($options["depth"]) && is_dir($fspath) && $this->_is_readable($fspath)) { |
|
169 | - |
|
170 | - // make sure path ends with '/' |
|
171 | - $options["path"] = $this->_slashify($options["path"]); |
|
172 | - |
|
173 | - // try to open directory |
|
174 | - $handle = opendir($fspath); |
|
175 | - |
|
176 | - if ($handle) { |
|
177 | - // ok, now get all its contents |
|
178 | - while ($filename = readdir($handle)) { |
|
179 | - if ($filename != "." && $filename != "..") { |
|
180 | - $files["files"][] = $this->fileinfo($options["path"].$filename); |
|
181 | - } |
|
182 | - } |
|
183 | - // TODO recursion needed if "Depth: infinite" |
|
184 | - closedir($handle); |
|
185 | - } |
|
186 | - } |
|
187 | - |
|
188 | - // ok, all done |
|
189 | - return true; |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * Get properties for a single file/resource |
|
194 | - * |
|
195 | - * @param string resource path |
|
196 | - * @return array resource properties |
|
197 | - */ |
|
198 | - function fileinfo($path) |
|
199 | - { |
|
200 | - // map URI path to filesystem path |
|
201 | - $fspath = $this->base . $path; |
|
202 | - |
|
203 | - // create result array |
|
204 | - $info = array(); |
|
205 | - // TODO remove slash append code when base clase is able to do it itself |
|
206 | - $info["path"] = is_dir($fspath) ? $this->_slashify($path) : $path; |
|
207 | - $info["props"] = array(); |
|
208 | - |
|
209 | - // no special beautified displayname here ... |
|
210 | - $info["props"][] = $this->mkprop("displayname", strtoupper($path)); |
|
211 | - |
|
212 | - // creation and modification time |
|
213 | - $info["props"][] = $this->mkprop("creationdate", filectime($fspath)); |
|
214 | - $info["props"][] = $this->mkprop("getlastmodified", filemtime($fspath)); |
|
215 | - |
|
216 | - // Microsoft extensions: last access time and 'hidden' status |
|
217 | - $info["props"][] = $this->mkprop("lastaccessed", fileatime($fspath)); |
|
218 | - $info["props"][] = $this->mkprop("ishidden", ('.' === substr(basename($fspath), 0, 1))); |
|
219 | - |
|
220 | - // type and size (caller already made sure that path exists) |
|
221 | - if (is_dir($fspath)) { |
|
222 | - // directory (WebDAV collection) |
|
223 | - $info["props"][] = $this->mkprop("resourcetype", "collection"); |
|
224 | - $info["props"][] = $this->mkprop("getcontenttype", "httpd/unix-directory"); |
|
225 | - } else { |
|
226 | - // plain file (WebDAV resource) |
|
227 | - $info["props"][] = $this->mkprop("resourcetype", ""); |
|
228 | - if ($this->_is_readable($fspath)) { |
|
229 | - $info["props"][] = $this->mkprop("getcontenttype", $this->_mimetype($fspath)); |
|
230 | - } else { |
|
231 | - $info["props"][] = $this->mkprop("getcontenttype", "application/x-non-readable"); |
|
232 | - } |
|
233 | - $info["props"][] = $this->mkprop("getcontentlength", filesize($fspath)); |
|
234 | - } |
|
235 | - |
|
236 | - // get additional properties from database |
|
237 | - $query = "SELECT ns, name, value |
|
47 | + /** |
|
48 | + * Root directory for WebDAV access |
|
49 | + * |
|
50 | + * Defaults to webserver document root (set by ServeRequest) |
|
51 | + * |
|
52 | + * @access private |
|
53 | + * @var string |
|
54 | + */ |
|
55 | + var $base = ""; |
|
56 | + |
|
57 | + /** |
|
58 | + * MySQL Host where property and locking information is stored |
|
59 | + * |
|
60 | + * @access private |
|
61 | + * @var string |
|
62 | + */ |
|
63 | + var $db_host = "localhost"; |
|
64 | + |
|
65 | + /** |
|
66 | + * MySQL database for property/locking information storage |
|
67 | + * |
|
68 | + * @access private |
|
69 | + * @var string |
|
70 | + */ |
|
71 | + var $db_name = "webdav"; |
|
72 | + |
|
73 | + /** |
|
74 | + * MySQL table name prefix |
|
75 | + * |
|
76 | + * @access private |
|
77 | + * @var string |
|
78 | + */ |
|
79 | + var $db_prefix = ""; |
|
80 | + |
|
81 | + /** |
|
82 | + * MySQL user for property/locking db access |
|
83 | + * |
|
84 | + * @access private |
|
85 | + * @var string |
|
86 | + */ |
|
87 | + var $db_user = "root"; |
|
88 | + |
|
89 | + /** |
|
90 | + * MySQL password for property/locking db access |
|
91 | + * |
|
92 | + * @access private |
|
93 | + * @var string |
|
94 | + */ |
|
95 | + var $db_passwd = ""; |
|
96 | + |
|
97 | + /** |
|
98 | + * Serve a webdav request |
|
99 | + * |
|
100 | + * @access public |
|
101 | + * @param string |
|
102 | + */ |
|
103 | + function ServeRequest($base = false) |
|
104 | + { |
|
105 | + // special treatment for litmus compliance test |
|
106 | + // reply on its identifier header |
|
107 | + // not needed for the test itself but eases debugging |
|
108 | + if (isset($this->_SERVER['HTTP_X_LITMUS'])) { |
|
109 | + error_log("Litmus test ".$this->_SERVER['HTTP_X_LITMUS']); |
|
110 | + header("X-Litmus-reply: ".$this->_SERVER['HTTP_X_LITMUS']); |
|
111 | + } |
|
112 | + |
|
113 | + // set root directory, defaults to webserver document root if not set |
|
114 | + if ($base) { |
|
115 | + $this->base = realpath($base); // TODO throw if not a directory |
|
116 | + } else if (!$this->base) { |
|
117 | + $this->base = $this->_SERVER['DOCUMENT_ROOT']; |
|
118 | + } |
|
119 | + |
|
120 | + // establish connection to property/locking db |
|
121 | + mysql_connect($this->db_host, $this->db_user, $this->db_passwd) or die(mysql_error()); |
|
122 | + mysql_select_db($this->db_name) or die(mysql_error()); |
|
123 | + // TODO throw on connection problems |
|
124 | + |
|
125 | + // let the base class do all the work |
|
126 | + parent::ServeRequest(); |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * No authentication is needed here |
|
131 | + * |
|
132 | + * @access private |
|
133 | + * @param string HTTP Authentication type (Basic, Digest, ...) |
|
134 | + * @param string Username |
|
135 | + * @param string Password |
|
136 | + * @return bool true on successful authentication |
|
137 | + */ |
|
138 | + function check_auth($type, $user, $pass) |
|
139 | + { |
|
140 | + return true; |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * PROPFIND method handler |
|
146 | + * |
|
147 | + * @param array general parameter passing array |
|
148 | + * @param array return array for file properties |
|
149 | + * @return bool true on success |
|
150 | + */ |
|
151 | + function PROPFIND(&$options, &$files) |
|
152 | + { |
|
153 | + // get absolute fs path to requested resource |
|
154 | + $fspath = $this->base . $options["path"]; |
|
155 | + |
|
156 | + // sanity check |
|
157 | + if (!file_exists($fspath)) { |
|
158 | + return false; |
|
159 | + } |
|
160 | + |
|
161 | + // prepare property array |
|
162 | + $files["files"] = array(); |
|
163 | + |
|
164 | + // store information for the requested path itself |
|
165 | + $files["files"][] = $this->fileinfo($options["path"]); |
|
166 | + |
|
167 | + // information for contained resources requested? |
|
168 | + if (!empty($options["depth"]) && is_dir($fspath) && $this->_is_readable($fspath)) { |
|
169 | + |
|
170 | + // make sure path ends with '/' |
|
171 | + $options["path"] = $this->_slashify($options["path"]); |
|
172 | + |
|
173 | + // try to open directory |
|
174 | + $handle = opendir($fspath); |
|
175 | + |
|
176 | + if ($handle) { |
|
177 | + // ok, now get all its contents |
|
178 | + while ($filename = readdir($handle)) { |
|
179 | + if ($filename != "." && $filename != "..") { |
|
180 | + $files["files"][] = $this->fileinfo($options["path"].$filename); |
|
181 | + } |
|
182 | + } |
|
183 | + // TODO recursion needed if "Depth: infinite" |
|
184 | + closedir($handle); |
|
185 | + } |
|
186 | + } |
|
187 | + |
|
188 | + // ok, all done |
|
189 | + return true; |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * Get properties for a single file/resource |
|
194 | + * |
|
195 | + * @param string resource path |
|
196 | + * @return array resource properties |
|
197 | + */ |
|
198 | + function fileinfo($path) |
|
199 | + { |
|
200 | + // map URI path to filesystem path |
|
201 | + $fspath = $this->base . $path; |
|
202 | + |
|
203 | + // create result array |
|
204 | + $info = array(); |
|
205 | + // TODO remove slash append code when base clase is able to do it itself |
|
206 | + $info["path"] = is_dir($fspath) ? $this->_slashify($path) : $path; |
|
207 | + $info["props"] = array(); |
|
208 | + |
|
209 | + // no special beautified displayname here ... |
|
210 | + $info["props"][] = $this->mkprop("displayname", strtoupper($path)); |
|
211 | + |
|
212 | + // creation and modification time |
|
213 | + $info["props"][] = $this->mkprop("creationdate", filectime($fspath)); |
|
214 | + $info["props"][] = $this->mkprop("getlastmodified", filemtime($fspath)); |
|
215 | + |
|
216 | + // Microsoft extensions: last access time and 'hidden' status |
|
217 | + $info["props"][] = $this->mkprop("lastaccessed", fileatime($fspath)); |
|
218 | + $info["props"][] = $this->mkprop("ishidden", ('.' === substr(basename($fspath), 0, 1))); |
|
219 | + |
|
220 | + // type and size (caller already made sure that path exists) |
|
221 | + if (is_dir($fspath)) { |
|
222 | + // directory (WebDAV collection) |
|
223 | + $info["props"][] = $this->mkprop("resourcetype", "collection"); |
|
224 | + $info["props"][] = $this->mkprop("getcontenttype", "httpd/unix-directory"); |
|
225 | + } else { |
|
226 | + // plain file (WebDAV resource) |
|
227 | + $info["props"][] = $this->mkprop("resourcetype", ""); |
|
228 | + if ($this->_is_readable($fspath)) { |
|
229 | + $info["props"][] = $this->mkprop("getcontenttype", $this->_mimetype($fspath)); |
|
230 | + } else { |
|
231 | + $info["props"][] = $this->mkprop("getcontenttype", "application/x-non-readable"); |
|
232 | + } |
|
233 | + $info["props"][] = $this->mkprop("getcontentlength", filesize($fspath)); |
|
234 | + } |
|
235 | + |
|
236 | + // get additional properties from database |
|
237 | + $query = "SELECT ns, name, value |
|
238 | 238 | FROM {$this->db_prefix}properties |
239 | 239 | WHERE path = '$path'"; |
240 | - $res = mysql_query($query); |
|
241 | - while ($row = mysql_fetch_assoc($res)) { |
|
242 | - $info["props"][] = $this->mkprop($row["ns"], $row["name"], $row["value"]); |
|
243 | - } |
|
244 | - mysql_free_result($res); |
|
245 | - |
|
246 | - return $info; |
|
247 | - } |
|
248 | - |
|
249 | - /** |
|
250 | - * detect if a given program is found in the search PATH |
|
251 | - * |
|
252 | - * helper function used by _mimetype() to detect if the |
|
253 | - * external 'file' utility is available |
|
254 | - * |
|
255 | - * @param string program name |
|
256 | - * @param string optional search path, defaults to $PATH |
|
257 | - * @return bool true if executable program found in path |
|
258 | - */ |
|
259 | - function _can_execute($name, $path = false) |
|
260 | - { |
|
261 | - // path defaults to PATH from environment if not set |
|
262 | - if ($path === false) { |
|
263 | - $path = getenv("PATH"); |
|
264 | - } |
|
265 | - |
|
266 | - // check method depends on operating system |
|
267 | - if (!strncmp(PHP_OS, "WIN", 3)) { |
|
268 | - // on Windows an appropriate COM or EXE file needs to exist |
|
269 | - $exts = array(".exe", ".com"); |
|
270 | - $check_fn = "file_exists"; |
|
271 | - } else { |
|
272 | - // anywhere else we look for an executable file of that name |
|
273 | - $exts = array(""); |
|
274 | - $check_fn = "is_executable"; |
|
275 | - } |
|
276 | - |
|
277 | - // now check the directories in the path for the program |
|
278 | - foreach (explode(PATH_SEPARATOR, $path) as $dir) { |
|
279 | - // skip invalid path entries |
|
280 | - if (!file_exists($dir)) continue; |
|
281 | - if (!is_dir($dir)) continue; |
|
282 | - |
|
283 | - // and now look for the file |
|
284 | - foreach ($exts as $ext) { |
|
285 | - if ($check_fn("$dir/$name".$ext)) return true; |
|
286 | - } |
|
287 | - } |
|
288 | - |
|
289 | - return false; |
|
290 | - } |
|
291 | - |
|
292 | - /** |
|
293 | - * Check if path is readable by current user |
|
294 | - * |
|
295 | - * Allow extending classes to overwrite it |
|
296 | - * |
|
297 | - * @param string $fspath |
|
298 | - * @return boolean |
|
299 | - */ |
|
300 | - function _is_readable($fspath) |
|
301 | - { |
|
302 | - return is_readable($fspath); |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * Check if path is writable by current user |
|
307 | - * |
|
308 | - * Allow extending classes to overwrite it |
|
309 | - * |
|
310 | - * @param string $fspath |
|
311 | - * @return boolean |
|
312 | - */ |
|
313 | - function _is_writable($fspath) |
|
314 | - { |
|
315 | - return is_writable($fspath); |
|
316 | - } |
|
317 | - |
|
318 | - /** |
|
319 | - * try to detect the mime type of a file |
|
320 | - * |
|
321 | - * @param string file path |
|
322 | - * @return string guessed mime type |
|
323 | - */ |
|
324 | - function _mimetype($fspath) |
|
325 | - { |
|
326 | - if (is_dir($fspath)) { |
|
327 | - // directories are easy |
|
328 | - return "httpd/unix-directory"; |
|
329 | - } else if (function_exists("mime_content_type")) { |
|
330 | - // use mime magic extension if available |
|
331 | - $mime_type = mime_content_type($fspath); |
|
332 | - } else if ($this->_can_execute("file")) { |
|
333 | - // it looks like we have a 'file' command, |
|
334 | - // lets see it it does have mime support |
|
335 | - $fp = popen("file -i '$fspath' 2>/dev/null", "r"); |
|
336 | - $reply = fgets($fp); |
|
337 | - pclose($fp); |
|
338 | - |
|
339 | - // popen will not return an error if the binary was not found |
|
340 | - // and find may not have mime support using "-i" |
|
341 | - // so we test the format of the returned string |
|
342 | - |
|
343 | - // the reply begins with the requested filename |
|
344 | - if (!strncmp($reply, "$fspath: ", strlen($fspath)+2)) { |
|
345 | - $reply = substr($reply, strlen($fspath)+2); |
|
346 | - // followed by the mime type (maybe including options) |
|
347 | - if (preg_match('|^[[:alnum:]_-]+/[[:alnum:]_-]+;?.*|', $reply, $matches)) { |
|
348 | - $mime_type = $matches[0]; |
|
349 | - } |
|
350 | - } |
|
351 | - } |
|
352 | - |
|
353 | - if (empty($mime_type)) { |
|
354 | - // Fallback solution: try to guess the type by the file extension |
|
355 | - // TODO: add more ... |
|
356 | - // TODO: it has been suggested to delegate mimetype detection |
|
357 | - // to apache but this has at least three issues: |
|
358 | - // - works only with apache |
|
359 | - // - needs file to be within the document tree |
|
360 | - // - requires apache mod_magic |
|
361 | - // TODO: can we use the registry for this on Windows? |
|
362 | - // OTOH if the server is Windos the clients are likely to |
|
363 | - // be Windows, too, and tend do ignore the Content-Type |
|
364 | - // anyway (overriding it with information taken from |
|
365 | - // the registry) |
|
366 | - // TODO: have a seperate PEAR class for mimetype detection? |
|
367 | - switch (strtolower(strrchr(basename($fspath), "."))) { |
|
368 | - case ".html": |
|
369 | - $mime_type = "text/html"; |
|
370 | - break; |
|
371 | - case ".gif": |
|
372 | - $mime_type = "image/gif"; |
|
373 | - break; |
|
374 | - case ".jpg": |
|
375 | - $mime_type = "image/jpeg"; |
|
376 | - break; |
|
377 | - default: |
|
378 | - $mime_type = "application/octet-stream"; |
|
379 | - break; |
|
380 | - } |
|
381 | - } |
|
382 | - |
|
383 | - return $mime_type; |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * HEAD method handler |
|
388 | - * |
|
389 | - * @param array parameter passing array |
|
390 | - * @return bool true on success |
|
391 | - */ |
|
392 | - function HEAD(&$options) |
|
393 | - { |
|
394 | - // get absolute fs path to requested resource |
|
395 | - $fspath = $this->base . $options["path"]; |
|
396 | - |
|
397 | - // sanity check |
|
398 | - if (!file_exists($fspath)) return false; |
|
399 | - |
|
400 | - // detect resource type |
|
401 | - $options['mimetype'] = $this->_mimetype($fspath); |
|
402 | - |
|
403 | - // detect modification time |
|
404 | - // see rfc2518, section 13.7 |
|
405 | - // some clients seem to treat this as a reverse rule |
|
406 | - // requiering a Last-Modified header if the getlastmodified header was set |
|
407 | - $options['mtime'] = filemtime($fspath); |
|
408 | - |
|
409 | - // detect resource size |
|
410 | - $options['size'] = filesize($fspath); |
|
411 | - |
|
412 | - return true; |
|
413 | - } |
|
414 | - |
|
415 | - /** |
|
416 | - * GET method handler |
|
417 | - * |
|
418 | - * @param array parameter passing array |
|
419 | - * @return bool true on success |
|
420 | - */ |
|
421 | - function GET(&$options) |
|
422 | - { |
|
423 | - // get absolute fs path to requested resource |
|
424 | - $fspath = $this->base . $options["path"]; |
|
425 | - |
|
426 | - // is this a collection? |
|
427 | - if (is_dir($fspath)) { |
|
428 | - return $this->GetDir($fspath, $options); |
|
429 | - } |
|
430 | - |
|
431 | - // the header output is the same as for HEAD |
|
432 | - if (!$this->HEAD($options)) { |
|
433 | - return false; |
|
434 | - } |
|
435 | - |
|
436 | - // no need to check result here, it is handled by the base class |
|
437 | - $options['stream'] = fopen($fspath, "r"); |
|
438 | - |
|
439 | - return true; |
|
440 | - } |
|
441 | - |
|
442 | - /** |
|
443 | - * GET method handler for directories |
|
444 | - * |
|
445 | - * This is a very simple mod_index lookalike. |
|
446 | - * See RFC 2518, Section 8.4 on GET/HEAD for collections |
|
447 | - * |
|
448 | - * @param string directory path |
|
449 | - * @return void function has to handle HTTP response itself |
|
450 | - */ |
|
451 | - function GetDir($fspath, &$options) |
|
452 | - { |
|
453 | - $path = $this->_slashify($options["path"]); |
|
454 | - if ($path != $options["path"]) { |
|
455 | - header("Location: ".$this->base_uri.$path); |
|
456 | - exit; |
|
457 | - } |
|
458 | - |
|
459 | - // fixed width directory column format |
|
460 | - $format = "%15s %-19s %-s\n"; |
|
461 | - |
|
462 | - if (!$this->_is_readable($fspath)) { |
|
463 | - return false; |
|
464 | - } |
|
465 | - |
|
466 | - $handle = opendir($fspath); |
|
467 | - if (!$handle) { |
|
468 | - return false; |
|
469 | - } |
|
470 | - |
|
471 | - echo "<html><head><title>Index of ".htmlspecialchars(urldecode($options['path']))."</title></head>\n"; |
|
472 | - |
|
473 | - echo "<h1>Index of ".htmlspecialchars($options['path'])."</h1>\n"; |
|
474 | - |
|
475 | - echo "<pre>"; |
|
476 | - printf($format, "Size", "Last modified", "Filename"); |
|
477 | - echo "<hr>"; |
|
478 | - |
|
479 | - while ($filename = readdir($handle)) { |
|
480 | - if ($filename != "." && $filename != "..") { |
|
481 | - $fullpath = $fspath.$filename; |
|
482 | - $name = htmlspecialchars($filename); |
|
483 | - printf($format, |
|
484 | - number_format(filesize($fullpath)), |
|
485 | - strftime("%Y-%m-%d %H:%M:%S", filemtime($fullpath)), |
|
486 | - '<a href="'.$name.'">'.urldecode($name).'</a>'); |
|
487 | - } |
|
488 | - } |
|
489 | - |
|
490 | - echo "</pre>"; |
|
491 | - |
|
492 | - closedir($handle); |
|
493 | - |
|
494 | - echo "</html>\n"; |
|
495 | - |
|
496 | - exit; |
|
497 | - } |
|
498 | - |
|
499 | - /** |
|
500 | - * PUT method handler |
|
501 | - * |
|
502 | - * @param array parameter passing array |
|
503 | - * @return bool true on success |
|
504 | - */ |
|
505 | - function PUT(&$options) |
|
506 | - { |
|
507 | - $fspath = $this->base . $options["path"]; |
|
508 | - |
|
509 | - $dir = dirname($fspath); |
|
510 | - if (!file_exists($dir) || !is_dir($dir)) { |
|
511 | - return "409 Conflict"; // TODO right status code for both? |
|
512 | - } |
|
513 | - |
|
514 | - $options["new"] = ! file_exists($fspath); |
|
515 | - |
|
516 | - if ($options["new"] && !$this->_is_writable($dir)) { |
|
517 | - return "403 Forbidden"; |
|
518 | - } |
|
519 | - if (!$options["new"] && !$this->_is_writable($fspath)) { |
|
520 | - return "403 Forbidden"; |
|
521 | - } |
|
522 | - if (!$options["new"] && is_dir($fspath)) { |
|
523 | - return "403 Forbidden"; |
|
524 | - } |
|
525 | - |
|
526 | - $fp = fopen($fspath, "w"); |
|
527 | - |
|
528 | - return $fp; |
|
529 | - } |
|
530 | - |
|
531 | - |
|
532 | - /** |
|
533 | - * MKCOL method handler |
|
534 | - * |
|
535 | - * @param array general parameter passing array |
|
536 | - * @return bool true on success |
|
537 | - */ |
|
538 | - function MKCOL($options) |
|
539 | - { |
|
540 | - $path = $this->base .$options["path"]; |
|
541 | - $parent = dirname($path); |
|
542 | - $name = basename($path); |
|
543 | - |
|
544 | - if (!file_exists($parent)) { |
|
545 | - return "409 Conflict"; |
|
546 | - } |
|
547 | - |
|
548 | - if (!is_dir($parent)) { |
|
549 | - return "403 Forbidden"; |
|
550 | - } |
|
551 | - |
|
552 | - if ( file_exists($parent."/".$name) ) { |
|
553 | - return "405 Method not allowed"; |
|
554 | - } |
|
555 | - |
|
556 | - if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet |
|
557 | - return "415 Unsupported media type"; |
|
558 | - } |
|
559 | - |
|
560 | - $stat = mkdir($parent."/".$name, 0777); |
|
561 | - if (!$stat) { |
|
562 | - return "403 Forbidden"; |
|
563 | - } |
|
564 | - |
|
565 | - return ("201 Created"); |
|
566 | - } |
|
567 | - |
|
568 | - |
|
569 | - /** |
|
570 | - * DELETE method handler |
|
571 | - * |
|
572 | - * @param array general parameter passing array |
|
573 | - * @return bool true on success |
|
574 | - */ |
|
575 | - function DELETE($options) |
|
576 | - { |
|
577 | - $path = $this->base . "/" .$options["path"]; |
|
578 | - |
|
579 | - if (!file_exists($path)) { |
|
580 | - return "404 Not found"; |
|
581 | - } |
|
582 | - |
|
583 | - if (is_dir($path)) { |
|
584 | - $query = "DELETE FROM {$this->db_prefix}properties |
|
240 | + $res = mysql_query($query); |
|
241 | + while ($row = mysql_fetch_assoc($res)) { |
|
242 | + $info["props"][] = $this->mkprop($row["ns"], $row["name"], $row["value"]); |
|
243 | + } |
|
244 | + mysql_free_result($res); |
|
245 | + |
|
246 | + return $info; |
|
247 | + } |
|
248 | + |
|
249 | + /** |
|
250 | + * detect if a given program is found in the search PATH |
|
251 | + * |
|
252 | + * helper function used by _mimetype() to detect if the |
|
253 | + * external 'file' utility is available |
|
254 | + * |
|
255 | + * @param string program name |
|
256 | + * @param string optional search path, defaults to $PATH |
|
257 | + * @return bool true if executable program found in path |
|
258 | + */ |
|
259 | + function _can_execute($name, $path = false) |
|
260 | + { |
|
261 | + // path defaults to PATH from environment if not set |
|
262 | + if ($path === false) { |
|
263 | + $path = getenv("PATH"); |
|
264 | + } |
|
265 | + |
|
266 | + // check method depends on operating system |
|
267 | + if (!strncmp(PHP_OS, "WIN", 3)) { |
|
268 | + // on Windows an appropriate COM or EXE file needs to exist |
|
269 | + $exts = array(".exe", ".com"); |
|
270 | + $check_fn = "file_exists"; |
|
271 | + } else { |
|
272 | + // anywhere else we look for an executable file of that name |
|
273 | + $exts = array(""); |
|
274 | + $check_fn = "is_executable"; |
|
275 | + } |
|
276 | + |
|
277 | + // now check the directories in the path for the program |
|
278 | + foreach (explode(PATH_SEPARATOR, $path) as $dir) { |
|
279 | + // skip invalid path entries |
|
280 | + if (!file_exists($dir)) continue; |
|
281 | + if (!is_dir($dir)) continue; |
|
282 | + |
|
283 | + // and now look for the file |
|
284 | + foreach ($exts as $ext) { |
|
285 | + if ($check_fn("$dir/$name".$ext)) return true; |
|
286 | + } |
|
287 | + } |
|
288 | + |
|
289 | + return false; |
|
290 | + } |
|
291 | + |
|
292 | + /** |
|
293 | + * Check if path is readable by current user |
|
294 | + * |
|
295 | + * Allow extending classes to overwrite it |
|
296 | + * |
|
297 | + * @param string $fspath |
|
298 | + * @return boolean |
|
299 | + */ |
|
300 | + function _is_readable($fspath) |
|
301 | + { |
|
302 | + return is_readable($fspath); |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * Check if path is writable by current user |
|
307 | + * |
|
308 | + * Allow extending classes to overwrite it |
|
309 | + * |
|
310 | + * @param string $fspath |
|
311 | + * @return boolean |
|
312 | + */ |
|
313 | + function _is_writable($fspath) |
|
314 | + { |
|
315 | + return is_writable($fspath); |
|
316 | + } |
|
317 | + |
|
318 | + /** |
|
319 | + * try to detect the mime type of a file |
|
320 | + * |
|
321 | + * @param string file path |
|
322 | + * @return string guessed mime type |
|
323 | + */ |
|
324 | + function _mimetype($fspath) |
|
325 | + { |
|
326 | + if (is_dir($fspath)) { |
|
327 | + // directories are easy |
|
328 | + return "httpd/unix-directory"; |
|
329 | + } else if (function_exists("mime_content_type")) { |
|
330 | + // use mime magic extension if available |
|
331 | + $mime_type = mime_content_type($fspath); |
|
332 | + } else if ($this->_can_execute("file")) { |
|
333 | + // it looks like we have a 'file' command, |
|
334 | + // lets see it it does have mime support |
|
335 | + $fp = popen("file -i '$fspath' 2>/dev/null", "r"); |
|
336 | + $reply = fgets($fp); |
|
337 | + pclose($fp); |
|
338 | + |
|
339 | + // popen will not return an error if the binary was not found |
|
340 | + // and find may not have mime support using "-i" |
|
341 | + // so we test the format of the returned string |
|
342 | + |
|
343 | + // the reply begins with the requested filename |
|
344 | + if (!strncmp($reply, "$fspath: ", strlen($fspath)+2)) { |
|
345 | + $reply = substr($reply, strlen($fspath)+2); |
|
346 | + // followed by the mime type (maybe including options) |
|
347 | + if (preg_match('|^[[:alnum:]_-]+/[[:alnum:]_-]+;?.*|', $reply, $matches)) { |
|
348 | + $mime_type = $matches[0]; |
|
349 | + } |
|
350 | + } |
|
351 | + } |
|
352 | + |
|
353 | + if (empty($mime_type)) { |
|
354 | + // Fallback solution: try to guess the type by the file extension |
|
355 | + // TODO: add more ... |
|
356 | + // TODO: it has been suggested to delegate mimetype detection |
|
357 | + // to apache but this has at least three issues: |
|
358 | + // - works only with apache |
|
359 | + // - needs file to be within the document tree |
|
360 | + // - requires apache mod_magic |
|
361 | + // TODO: can we use the registry for this on Windows? |
|
362 | + // OTOH if the server is Windos the clients are likely to |
|
363 | + // be Windows, too, and tend do ignore the Content-Type |
|
364 | + // anyway (overriding it with information taken from |
|
365 | + // the registry) |
|
366 | + // TODO: have a seperate PEAR class for mimetype detection? |
|
367 | + switch (strtolower(strrchr(basename($fspath), "."))) { |
|
368 | + case ".html": |
|
369 | + $mime_type = "text/html"; |
|
370 | + break; |
|
371 | + case ".gif": |
|
372 | + $mime_type = "image/gif"; |
|
373 | + break; |
|
374 | + case ".jpg": |
|
375 | + $mime_type = "image/jpeg"; |
|
376 | + break; |
|
377 | + default: |
|
378 | + $mime_type = "application/octet-stream"; |
|
379 | + break; |
|
380 | + } |
|
381 | + } |
|
382 | + |
|
383 | + return $mime_type; |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | + * HEAD method handler |
|
388 | + * |
|
389 | + * @param array parameter passing array |
|
390 | + * @return bool true on success |
|
391 | + */ |
|
392 | + function HEAD(&$options) |
|
393 | + { |
|
394 | + // get absolute fs path to requested resource |
|
395 | + $fspath = $this->base . $options["path"]; |
|
396 | + |
|
397 | + // sanity check |
|
398 | + if (!file_exists($fspath)) return false; |
|
399 | + |
|
400 | + // detect resource type |
|
401 | + $options['mimetype'] = $this->_mimetype($fspath); |
|
402 | + |
|
403 | + // detect modification time |
|
404 | + // see rfc2518, section 13.7 |
|
405 | + // some clients seem to treat this as a reverse rule |
|
406 | + // requiering a Last-Modified header if the getlastmodified header was set |
|
407 | + $options['mtime'] = filemtime($fspath); |
|
408 | + |
|
409 | + // detect resource size |
|
410 | + $options['size'] = filesize($fspath); |
|
411 | + |
|
412 | + return true; |
|
413 | + } |
|
414 | + |
|
415 | + /** |
|
416 | + * GET method handler |
|
417 | + * |
|
418 | + * @param array parameter passing array |
|
419 | + * @return bool true on success |
|
420 | + */ |
|
421 | + function GET(&$options) |
|
422 | + { |
|
423 | + // get absolute fs path to requested resource |
|
424 | + $fspath = $this->base . $options["path"]; |
|
425 | + |
|
426 | + // is this a collection? |
|
427 | + if (is_dir($fspath)) { |
|
428 | + return $this->GetDir($fspath, $options); |
|
429 | + } |
|
430 | + |
|
431 | + // the header output is the same as for HEAD |
|
432 | + if (!$this->HEAD($options)) { |
|
433 | + return false; |
|
434 | + } |
|
435 | + |
|
436 | + // no need to check result here, it is handled by the base class |
|
437 | + $options['stream'] = fopen($fspath, "r"); |
|
438 | + |
|
439 | + return true; |
|
440 | + } |
|
441 | + |
|
442 | + /** |
|
443 | + * GET method handler for directories |
|
444 | + * |
|
445 | + * This is a very simple mod_index lookalike. |
|
446 | + * See RFC 2518, Section 8.4 on GET/HEAD for collections |
|
447 | + * |
|
448 | + * @param string directory path |
|
449 | + * @return void function has to handle HTTP response itself |
|
450 | + */ |
|
451 | + function GetDir($fspath, &$options) |
|
452 | + { |
|
453 | + $path = $this->_slashify($options["path"]); |
|
454 | + if ($path != $options["path"]) { |
|
455 | + header("Location: ".$this->base_uri.$path); |
|
456 | + exit; |
|
457 | + } |
|
458 | + |
|
459 | + // fixed width directory column format |
|
460 | + $format = "%15s %-19s %-s\n"; |
|
461 | + |
|
462 | + if (!$this->_is_readable($fspath)) { |
|
463 | + return false; |
|
464 | + } |
|
465 | + |
|
466 | + $handle = opendir($fspath); |
|
467 | + if (!$handle) { |
|
468 | + return false; |
|
469 | + } |
|
470 | + |
|
471 | + echo "<html><head><title>Index of ".htmlspecialchars(urldecode($options['path']))."</title></head>\n"; |
|
472 | + |
|
473 | + echo "<h1>Index of ".htmlspecialchars($options['path'])."</h1>\n"; |
|
474 | + |
|
475 | + echo "<pre>"; |
|
476 | + printf($format, "Size", "Last modified", "Filename"); |
|
477 | + echo "<hr>"; |
|
478 | + |
|
479 | + while ($filename = readdir($handle)) { |
|
480 | + if ($filename != "." && $filename != "..") { |
|
481 | + $fullpath = $fspath.$filename; |
|
482 | + $name = htmlspecialchars($filename); |
|
483 | + printf($format, |
|
484 | + number_format(filesize($fullpath)), |
|
485 | + strftime("%Y-%m-%d %H:%M:%S", filemtime($fullpath)), |
|
486 | + '<a href="'.$name.'">'.urldecode($name).'</a>'); |
|
487 | + } |
|
488 | + } |
|
489 | + |
|
490 | + echo "</pre>"; |
|
491 | + |
|
492 | + closedir($handle); |
|
493 | + |
|
494 | + echo "</html>\n"; |
|
495 | + |
|
496 | + exit; |
|
497 | + } |
|
498 | + |
|
499 | + /** |
|
500 | + * PUT method handler |
|
501 | + * |
|
502 | + * @param array parameter passing array |
|
503 | + * @return bool true on success |
|
504 | + */ |
|
505 | + function PUT(&$options) |
|
506 | + { |
|
507 | + $fspath = $this->base . $options["path"]; |
|
508 | + |
|
509 | + $dir = dirname($fspath); |
|
510 | + if (!file_exists($dir) || !is_dir($dir)) { |
|
511 | + return "409 Conflict"; // TODO right status code for both? |
|
512 | + } |
|
513 | + |
|
514 | + $options["new"] = ! file_exists($fspath); |
|
515 | + |
|
516 | + if ($options["new"] && !$this->_is_writable($dir)) { |
|
517 | + return "403 Forbidden"; |
|
518 | + } |
|
519 | + if (!$options["new"] && !$this->_is_writable($fspath)) { |
|
520 | + return "403 Forbidden"; |
|
521 | + } |
|
522 | + if (!$options["new"] && is_dir($fspath)) { |
|
523 | + return "403 Forbidden"; |
|
524 | + } |
|
525 | + |
|
526 | + $fp = fopen($fspath, "w"); |
|
527 | + |
|
528 | + return $fp; |
|
529 | + } |
|
530 | + |
|
531 | + |
|
532 | + /** |
|
533 | + * MKCOL method handler |
|
534 | + * |
|
535 | + * @param array general parameter passing array |
|
536 | + * @return bool true on success |
|
537 | + */ |
|
538 | + function MKCOL($options) |
|
539 | + { |
|
540 | + $path = $this->base .$options["path"]; |
|
541 | + $parent = dirname($path); |
|
542 | + $name = basename($path); |
|
543 | + |
|
544 | + if (!file_exists($parent)) { |
|
545 | + return "409 Conflict"; |
|
546 | + } |
|
547 | + |
|
548 | + if (!is_dir($parent)) { |
|
549 | + return "403 Forbidden"; |
|
550 | + } |
|
551 | + |
|
552 | + if ( file_exists($parent."/".$name) ) { |
|
553 | + return "405 Method not allowed"; |
|
554 | + } |
|
555 | + |
|
556 | + if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet |
|
557 | + return "415 Unsupported media type"; |
|
558 | + } |
|
559 | + |
|
560 | + $stat = mkdir($parent."/".$name, 0777); |
|
561 | + if (!$stat) { |
|
562 | + return "403 Forbidden"; |
|
563 | + } |
|
564 | + |
|
565 | + return ("201 Created"); |
|
566 | + } |
|
567 | + |
|
568 | + |
|
569 | + /** |
|
570 | + * DELETE method handler |
|
571 | + * |
|
572 | + * @param array general parameter passing array |
|
573 | + * @return bool true on success |
|
574 | + */ |
|
575 | + function DELETE($options) |
|
576 | + { |
|
577 | + $path = $this->base . "/" .$options["path"]; |
|
578 | + |
|
579 | + if (!file_exists($path)) { |
|
580 | + return "404 Not found"; |
|
581 | + } |
|
582 | + |
|
583 | + if (is_dir($path)) { |
|
584 | + $query = "DELETE FROM {$this->db_prefix}properties |
|
585 | 585 | WHERE path LIKE '".$this->_slashify($options["path"])."%'"; |
586 | - mysql_query($query); |
|
587 | - System::rm(array("-rf", $path)); |
|
588 | - } else { |
|
589 | - unlink($path); |
|
590 | - } |
|
591 | - $query = "DELETE FROM {$this->db_prefix}properties |
|
586 | + mysql_query($query); |
|
587 | + System::rm(array("-rf", $path)); |
|
588 | + } else { |
|
589 | + unlink($path); |
|
590 | + } |
|
591 | + $query = "DELETE FROM {$this->db_prefix}properties |
|
592 | 592 | WHERE path = '$options[path]'"; |
593 | - mysql_query($query); |
|
594 | - |
|
595 | - return "204 No Content"; |
|
596 | - } |
|
597 | - |
|
598 | - |
|
599 | - /** |
|
600 | - * MOVE method handler |
|
601 | - * |
|
602 | - * @param array general parameter passing array |
|
603 | - * @return bool true on success |
|
604 | - */ |
|
605 | - function MOVE($options) |
|
606 | - { |
|
607 | - return $this->COPY($options, true); |
|
608 | - } |
|
609 | - |
|
610 | - /** |
|
611 | - * COPY method handler |
|
612 | - * |
|
613 | - * @param array general parameter passing array |
|
614 | - * @return bool true on success |
|
615 | - */ |
|
616 | - function COPY($options, $del=false) |
|
617 | - { |
|
618 | - // TODO Property updates still broken (Litmus should detect this?) |
|
619 | - |
|
620 | - if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet |
|
621 | - return "415 Unsupported media type"; |
|
622 | - } |
|
623 | - |
|
624 | - // no copying to different WebDAV Servers yet |
|
625 | - if (isset($options["dest_url"])) { |
|
626 | - return "502 bad gateway"; |
|
627 | - } |
|
628 | - |
|
629 | - $source = $this->base . $options["path"]; |
|
630 | - if (!file_exists($source)) { |
|
631 | - return "404 Not found"; |
|
632 | - } |
|
633 | - |
|
634 | - if (is_dir($source)) { // resource is a collection |
|
635 | - switch ($options["depth"]) { |
|
636 | - case "infinity": // valid |
|
637 | - break; |
|
638 | - case "0": // valid for COPY only |
|
639 | - if ($del) { // MOVE? |
|
640 | - return "400 Bad request"; |
|
641 | - } |
|
642 | - break; |
|
643 | - case "1": // invalid for both COPY and MOVE |
|
644 | - default: |
|
645 | - return "400 Bad request"; |
|
646 | - } |
|
647 | - } |
|
648 | - |
|
649 | - $dest = $this->base . $options["dest"]; |
|
650 | - $destdir = dirname($dest); |
|
651 | - |
|
652 | - if (!file_exists($destdir) || !is_dir($destdir)) { |
|
653 | - return "409 Conflict"; |
|
654 | - } |
|
655 | - |
|
656 | - |
|
657 | - $new = !file_exists($dest); |
|
658 | - $existing_col = false; |
|
659 | - |
|
660 | - if (!$new) { |
|
661 | - if ($del && is_dir($dest)) { |
|
662 | - if (!$options["overwrite"]) { |
|
663 | - return "412 precondition failed"; |
|
664 | - } |
|
665 | - $dest .= basename($source); |
|
666 | - if (file_exists($dest)) { |
|
667 | - $options["dest"] .= basename($source); |
|
668 | - } else { |
|
669 | - $new = true; |
|
670 | - $existing_col = true; |
|
671 | - } |
|
672 | - } |
|
673 | - } |
|
674 | - |
|
675 | - if (!$new) { |
|
676 | - if ($options["overwrite"]) { |
|
677 | - $stat = $this->DELETE(array("path" => $options["dest"])); |
|
678 | - if (($stat{0} != "2") && (substr($stat, 0, 3) != "404")) { |
|
679 | - return $stat; |
|
680 | - } |
|
681 | - } else { |
|
682 | - return "412 precondition failed"; |
|
683 | - } |
|
684 | - } |
|
685 | - |
|
686 | - if ($del) { |
|
687 | - if (!rename($source, $dest)) { |
|
688 | - return "500 Internal server error"; |
|
689 | - } |
|
690 | - $destpath = $this->_unslashify($options["dest"]); |
|
691 | - if (is_dir($source)) { |
|
692 | - $query = "UPDATE {$this->db_prefix}properties |
|
593 | + mysql_query($query); |
|
594 | + |
|
595 | + return "204 No Content"; |
|
596 | + } |
|
597 | + |
|
598 | + |
|
599 | + /** |
|
600 | + * MOVE method handler |
|
601 | + * |
|
602 | + * @param array general parameter passing array |
|
603 | + * @return bool true on success |
|
604 | + */ |
|
605 | + function MOVE($options) |
|
606 | + { |
|
607 | + return $this->COPY($options, true); |
|
608 | + } |
|
609 | + |
|
610 | + /** |
|
611 | + * COPY method handler |
|
612 | + * |
|
613 | + * @param array general parameter passing array |
|
614 | + * @return bool true on success |
|
615 | + */ |
|
616 | + function COPY($options, $del=false) |
|
617 | + { |
|
618 | + // TODO Property updates still broken (Litmus should detect this?) |
|
619 | + |
|
620 | + if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet |
|
621 | + return "415 Unsupported media type"; |
|
622 | + } |
|
623 | + |
|
624 | + // no copying to different WebDAV Servers yet |
|
625 | + if (isset($options["dest_url"])) { |
|
626 | + return "502 bad gateway"; |
|
627 | + } |
|
628 | + |
|
629 | + $source = $this->base . $options["path"]; |
|
630 | + if (!file_exists($source)) { |
|
631 | + return "404 Not found"; |
|
632 | + } |
|
633 | + |
|
634 | + if (is_dir($source)) { // resource is a collection |
|
635 | + switch ($options["depth"]) { |
|
636 | + case "infinity": // valid |
|
637 | + break; |
|
638 | + case "0": // valid for COPY only |
|
639 | + if ($del) { // MOVE? |
|
640 | + return "400 Bad request"; |
|
641 | + } |
|
642 | + break; |
|
643 | + case "1": // invalid for both COPY and MOVE |
|
644 | + default: |
|
645 | + return "400 Bad request"; |
|
646 | + } |
|
647 | + } |
|
648 | + |
|
649 | + $dest = $this->base . $options["dest"]; |
|
650 | + $destdir = dirname($dest); |
|
651 | + |
|
652 | + if (!file_exists($destdir) || !is_dir($destdir)) { |
|
653 | + return "409 Conflict"; |
|
654 | + } |
|
655 | + |
|
656 | + |
|
657 | + $new = !file_exists($dest); |
|
658 | + $existing_col = false; |
|
659 | + |
|
660 | + if (!$new) { |
|
661 | + if ($del && is_dir($dest)) { |
|
662 | + if (!$options["overwrite"]) { |
|
663 | + return "412 precondition failed"; |
|
664 | + } |
|
665 | + $dest .= basename($source); |
|
666 | + if (file_exists($dest)) { |
|
667 | + $options["dest"] .= basename($source); |
|
668 | + } else { |
|
669 | + $new = true; |
|
670 | + $existing_col = true; |
|
671 | + } |
|
672 | + } |
|
673 | + } |
|
674 | + |
|
675 | + if (!$new) { |
|
676 | + if ($options["overwrite"]) { |
|
677 | + $stat = $this->DELETE(array("path" => $options["dest"])); |
|
678 | + if (($stat{0} != "2") && (substr($stat, 0, 3) != "404")) { |
|
679 | + return $stat; |
|
680 | + } |
|
681 | + } else { |
|
682 | + return "412 precondition failed"; |
|
683 | + } |
|
684 | + } |
|
685 | + |
|
686 | + if ($del) { |
|
687 | + if (!rename($source, $dest)) { |
|
688 | + return "500 Internal server error"; |
|
689 | + } |
|
690 | + $destpath = $this->_unslashify($options["dest"]); |
|
691 | + if (is_dir($source)) { |
|
692 | + $query = "UPDATE {$this->db_prefix}properties |
|
693 | 693 | SET path = REPLACE(path, '".$options["path"]."', '".$destpath."') |
694 | 694 | WHERE path LIKE '".$this->_slashify($options["path"])."%'"; |
695 | - mysql_query($query); |
|
696 | - } |
|
695 | + mysql_query($query); |
|
696 | + } |
|
697 | 697 | |
698 | - $query = "UPDATE {$this->db_prefix}properties |
|
698 | + $query = "UPDATE {$this->db_prefix}properties |
|
699 | 699 | SET path = '".$destpath."' |
700 | 700 | WHERE path = '".$options["path"]."'"; |
701 | - mysql_query($query); |
|
702 | - } else { |
|
703 | - if (is_dir($source) && $options["depth"] == "infinity") { // no find for depth="0" |
|
704 | - $files = System::find($source); |
|
705 | - $files = array_reverse($files); |
|
706 | - } else { |
|
707 | - $files = array($source); |
|
708 | - } |
|
709 | - |
|
710 | - if (!is_array($files) || empty($files)) { |
|
711 | - return "500 Internal server error"; |
|
712 | - } |
|
713 | - |
|
714 | - |
|
715 | - foreach ($files as $file) { |
|
716 | - if (is_dir($file)) { |
|
717 | - $file = $this->_slashify($file); |
|
718 | - } |
|
719 | - |
|
720 | - $destfile = str_replace($source, $dest, $file); |
|
721 | - |
|
722 | - if (is_dir($file)) { |
|
723 | - if (!file_exists($destfile)) { |
|
724 | - if (!$this->_is_writable(dirname($destfile))) { |
|
725 | - return "403 Forbidden"; |
|
726 | - } |
|
727 | - if (!mkdir($destfile)) { |
|
728 | - return "409 Conflict"; |
|
729 | - } |
|
730 | - } else if (!is_dir($destfile)) { |
|
731 | - return "409 Conflict"; |
|
732 | - } |
|
733 | - } else { |
|
734 | - |
|
735 | - if (!copy($file, $destfile)) { |
|
736 | - return "409 Conflict"; |
|
737 | - } |
|
738 | - } |
|
739 | - } |
|
740 | - |
|
741 | - $query = "INSERT INTO {$this->db_prefix}properties |
|
701 | + mysql_query($query); |
|
702 | + } else { |
|
703 | + if (is_dir($source) && $options["depth"] == "infinity") { // no find for depth="0" |
|
704 | + $files = System::find($source); |
|
705 | + $files = array_reverse($files); |
|
706 | + } else { |
|
707 | + $files = array($source); |
|
708 | + } |
|
709 | + |
|
710 | + if (!is_array($files) || empty($files)) { |
|
711 | + return "500 Internal server error"; |
|
712 | + } |
|
713 | + |
|
714 | + |
|
715 | + foreach ($files as $file) { |
|
716 | + if (is_dir($file)) { |
|
717 | + $file = $this->_slashify($file); |
|
718 | + } |
|
719 | + |
|
720 | + $destfile = str_replace($source, $dest, $file); |
|
721 | + |
|
722 | + if (is_dir($file)) { |
|
723 | + if (!file_exists($destfile)) { |
|
724 | + if (!$this->_is_writable(dirname($destfile))) { |
|
725 | + return "403 Forbidden"; |
|
726 | + } |
|
727 | + if (!mkdir($destfile)) { |
|
728 | + return "409 Conflict"; |
|
729 | + } |
|
730 | + } else if (!is_dir($destfile)) { |
|
731 | + return "409 Conflict"; |
|
732 | + } |
|
733 | + } else { |
|
734 | + |
|
735 | + if (!copy($file, $destfile)) { |
|
736 | + return "409 Conflict"; |
|
737 | + } |
|
738 | + } |
|
739 | + } |
|
740 | + |
|
741 | + $query = "INSERT INTO {$this->db_prefix}properties |
|
742 | 742 | SELECT * |
743 | 743 | FROM {$this->db_prefix}properties |
744 | 744 | WHERE path = '".$options['path']."'"; |
745 | - } |
|
746 | - |
|
747 | - return ($new && !$existing_col) ? "201 Created" : "204 No Content"; |
|
748 | - } |
|
749 | - |
|
750 | - /** |
|
751 | - * PROPPATCH method handler |
|
752 | - * |
|
753 | - * @param array general parameter passing array |
|
754 | - * @return bool true on success |
|
755 | - */ |
|
756 | - function PROPPATCH(&$options) |
|
757 | - { |
|
758 | - global $prefs, $tab; |
|
759 | - |
|
760 | - $msg = ""; |
|
761 | - $path = $options["path"]; |
|
762 | - $dir = dirname($path)."/"; |
|
763 | - $base = basename($path); |
|
764 | - |
|
765 | - foreach ($options["props"] as $key => $prop) { |
|
766 | - if ($prop["ns"] == "DAV:") { |
|
767 | - $options["props"][$key]['status'] = "403 Forbidden"; |
|
768 | - } else { |
|
769 | - if (isset($prop["val"])) { |
|
770 | - $query = "REPLACE INTO {$this->db_prefix}properties |
|
745 | + } |
|
746 | + |
|
747 | + return ($new && !$existing_col) ? "201 Created" : "204 No Content"; |
|
748 | + } |
|
749 | + |
|
750 | + /** |
|
751 | + * PROPPATCH method handler |
|
752 | + * |
|
753 | + * @param array general parameter passing array |
|
754 | + * @return bool true on success |
|
755 | + */ |
|
756 | + function PROPPATCH(&$options) |
|
757 | + { |
|
758 | + global $prefs, $tab; |
|
759 | + |
|
760 | + $msg = ""; |
|
761 | + $path = $options["path"]; |
|
762 | + $dir = dirname($path)."/"; |
|
763 | + $base = basename($path); |
|
764 | + |
|
765 | + foreach ($options["props"] as $key => $prop) { |
|
766 | + if ($prop["ns"] == "DAV:") { |
|
767 | + $options["props"][$key]['status'] = "403 Forbidden"; |
|
768 | + } else { |
|
769 | + if (isset($prop["val"])) { |
|
770 | + $query = "REPLACE INTO {$this->db_prefix}properties |
|
771 | 771 | SET path = '$options[path]' |
772 | 772 | , name = '$prop[name]' |
773 | 773 | , ns= '$prop[ns]' |
774 | 774 | , value = '$prop[val]'"; |
775 | - } else { |
|
776 | - $query = "DELETE FROM {$this->db_prefix}properties |
|
775 | + } else { |
|
776 | + $query = "DELETE FROM {$this->db_prefix}properties |
|
777 | 777 | WHERE path = '$options[path]' |
778 | 778 | AND name = '$prop[name]' |
779 | 779 | AND ns = '$prop[ns]'"; |
780 | - } |
|
781 | - mysql_query($query); |
|
782 | - } |
|
783 | - } |
|
784 | - |
|
785 | - return ""; |
|
786 | - } |
|
787 | - |
|
788 | - |
|
789 | - /** |
|
790 | - * LOCK method handler |
|
791 | - * |
|
792 | - * @param array general parameter passing array |
|
793 | - * @return bool true on success |
|
794 | - */ |
|
795 | - function LOCK(&$options) |
|
796 | - { |
|
797 | - // get absolute fs path to requested resource |
|
798 | - $fspath = $this->base . $options["path"]; |
|
799 | - |
|
800 | - // TODO recursive locks on directories not supported yet |
|
801 | - // makes litmus test "32. lock_collection" fail |
|
802 | - if (is_dir($fspath) && !empty($options["depth"])) { |
|
803 | - return "409 Conflict"; |
|
804 | - } |
|
805 | - |
|
806 | - $options["timeout"] = time()+300; // 5min. hardcoded |
|
807 | - |
|
808 | - if (isset($options["update"])) { // Lock Update |
|
809 | - $where = "WHERE path = '$options[path]' AND token = '$options[update]'"; |
|
810 | - |
|
811 | - $query = "SELECT owner, exclusivelock FROM {$this->db_prefix}locks $where"; |
|
812 | - $res = mysql_query($query); |
|
813 | - $row = mysql_fetch_assoc($res); |
|
814 | - mysql_free_result($res); |
|
815 | - |
|
816 | - if (is_array($row)) { |
|
817 | - $query = "UPDATE {$this->db_prefix}locks |
|
780 | + } |
|
781 | + mysql_query($query); |
|
782 | + } |
|
783 | + } |
|
784 | + |
|
785 | + return ""; |
|
786 | + } |
|
787 | + |
|
788 | + |
|
789 | + /** |
|
790 | + * LOCK method handler |
|
791 | + * |
|
792 | + * @param array general parameter passing array |
|
793 | + * @return bool true on success |
|
794 | + */ |
|
795 | + function LOCK(&$options) |
|
796 | + { |
|
797 | + // get absolute fs path to requested resource |
|
798 | + $fspath = $this->base . $options["path"]; |
|
799 | + |
|
800 | + // TODO recursive locks on directories not supported yet |
|
801 | + // makes litmus test "32. lock_collection" fail |
|
802 | + if (is_dir($fspath) && !empty($options["depth"])) { |
|
803 | + return "409 Conflict"; |
|
804 | + } |
|
805 | + |
|
806 | + $options["timeout"] = time()+300; // 5min. hardcoded |
|
807 | + |
|
808 | + if (isset($options["update"])) { // Lock Update |
|
809 | + $where = "WHERE path = '$options[path]' AND token = '$options[update]'"; |
|
810 | + |
|
811 | + $query = "SELECT owner, exclusivelock FROM {$this->db_prefix}locks $where"; |
|
812 | + $res = mysql_query($query); |
|
813 | + $row = mysql_fetch_assoc($res); |
|
814 | + mysql_free_result($res); |
|
815 | + |
|
816 | + if (is_array($row)) { |
|
817 | + $query = "UPDATE {$this->db_prefix}locks |
|
818 | 818 | SET expires = '$options[timeout]' |
819 | 819 | , modified = ".time()." |
820 | 820 | $where"; |
821 | - mysql_query($query); |
|
821 | + mysql_query($query); |
|
822 | 822 | |
823 | - $options['owner'] = $row['owner']; |
|
824 | - $options['scope'] = $row["exclusivelock"] ? "exclusive" : "shared"; |
|
825 | - $options['type'] = $row["exclusivelock"] ? "write" : "read"; |
|
823 | + $options['owner'] = $row['owner']; |
|
824 | + $options['scope'] = $row["exclusivelock"] ? "exclusive" : "shared"; |
|
825 | + $options['type'] = $row["exclusivelock"] ? "write" : "read"; |
|
826 | 826 | |
827 | - return true; |
|
828 | - } else { |
|
829 | - return false; |
|
830 | - } |
|
831 | - } |
|
827 | + return true; |
|
828 | + } else { |
|
829 | + return false; |
|
830 | + } |
|
831 | + } |
|
832 | 832 | |
833 | - $query = "INSERT INTO {$this->db_prefix}locks |
|
833 | + $query = "INSERT INTO {$this->db_prefix}locks |
|
834 | 834 | SET token = '$options[locktoken]' |
835 | 835 | , path = '$options[path]' |
836 | 836 | , created = ".time()." |
@@ -838,76 +838,76 @@ discard block |
||
838 | 838 | , owner = '$options[owner]' |
839 | 839 | , expires = '$options[timeout]' |
840 | 840 | , exclusivelock = " .($options['scope'] === "exclusive" ? "1" : "0") |
841 | - ; |
|
842 | - mysql_query($query); |
|
843 | - |
|
844 | - return mysql_affected_rows() ? "200 OK" : "409 Conflict"; |
|
845 | - } |
|
846 | - |
|
847 | - /** |
|
848 | - * UNLOCK method handler |
|
849 | - * |
|
850 | - * @param array general parameter passing array |
|
851 | - * @return bool true on success |
|
852 | - */ |
|
853 | - function UNLOCK(&$options) |
|
854 | - { |
|
855 | - $query = "DELETE FROM {$this->db_prefix}locks |
|
841 | + ; |
|
842 | + mysql_query($query); |
|
843 | + |
|
844 | + return mysql_affected_rows() ? "200 OK" : "409 Conflict"; |
|
845 | + } |
|
846 | + |
|
847 | + /** |
|
848 | + * UNLOCK method handler |
|
849 | + * |
|
850 | + * @param array general parameter passing array |
|
851 | + * @return bool true on success |
|
852 | + */ |
|
853 | + function UNLOCK(&$options) |
|
854 | + { |
|
855 | + $query = "DELETE FROM {$this->db_prefix}locks |
|
856 | 856 | WHERE path = '$options[path]' |
857 | 857 | AND token = '$options[token]'"; |
858 | - mysql_query($query); |
|
859 | - |
|
860 | - return mysql_affected_rows() ? "204 No Content" : "409 Conflict"; |
|
861 | - } |
|
862 | - |
|
863 | - /** |
|
864 | - * checkLock() helper |
|
865 | - * |
|
866 | - * @param string resource path to check for locks |
|
867 | - * @return bool true on success |
|
868 | - */ |
|
869 | - function checkLock($path) |
|
870 | - { |
|
871 | - $result = false; |
|
872 | - |
|
873 | - $query = "SELECT owner, token, created, modified, expires, exclusivelock |
|
858 | + mysql_query($query); |
|
859 | + |
|
860 | + return mysql_affected_rows() ? "204 No Content" : "409 Conflict"; |
|
861 | + } |
|
862 | + |
|
863 | + /** |
|
864 | + * checkLock() helper |
|
865 | + * |
|
866 | + * @param string resource path to check for locks |
|
867 | + * @return bool true on success |
|
868 | + */ |
|
869 | + function checkLock($path) |
|
870 | + { |
|
871 | + $result = false; |
|
872 | + |
|
873 | + $query = "SELECT owner, token, created, modified, expires, exclusivelock |
|
874 | 874 | FROM {$this->db_prefix}locks |
875 | 875 | WHERE path = '$path' |
876 | 876 | "; |
877 | - $res = mysql_query($query); |
|
878 | - |
|
879 | - if ($res) { |
|
880 | - $row = mysql_fetch_array($res); |
|
881 | - mysql_free_result($res); |
|
882 | - |
|
883 | - if ($row) { |
|
884 | - $result = array( "type" => "write", |
|
885 | - "scope" => $row["exclusivelock"] ? "exclusive" : "shared", |
|
886 | - "depth" => 0, |
|
887 | - "owner" => $row['owner'], |
|
888 | - "token" => $row['token'], |
|
889 | - "created" => $row['created'], |
|
890 | - "modified" => $row['modified'], |
|
891 | - "expires" => $row['expires'] |
|
892 | - ); |
|
893 | - } |
|
894 | - } |
|
895 | - |
|
896 | - return $result; |
|
897 | - } |
|
898 | - |
|
899 | - |
|
900 | - /** |
|
901 | - * create database tables for property and lock storage |
|
902 | - * |
|
903 | - * @param void |
|
904 | - * @return bool true on success |
|
905 | - */ |
|
906 | - function create_database() |
|
907 | - { |
|
908 | - // TODO |
|
909 | - return false; |
|
910 | - } |
|
877 | + $res = mysql_query($query); |
|
878 | + |
|
879 | + if ($res) { |
|
880 | + $row = mysql_fetch_array($res); |
|
881 | + mysql_free_result($res); |
|
882 | + |
|
883 | + if ($row) { |
|
884 | + $result = array( "type" => "write", |
|
885 | + "scope" => $row["exclusivelock"] ? "exclusive" : "shared", |
|
886 | + "depth" => 0, |
|
887 | + "owner" => $row['owner'], |
|
888 | + "token" => $row['token'], |
|
889 | + "created" => $row['created'], |
|
890 | + "modified" => $row['modified'], |
|
891 | + "expires" => $row['expires'] |
|
892 | + ); |
|
893 | + } |
|
894 | + } |
|
895 | + |
|
896 | + return $result; |
|
897 | + } |
|
898 | + |
|
899 | + |
|
900 | + /** |
|
901 | + * create database tables for property and lock storage |
|
902 | + * |
|
903 | + * @param void |
|
904 | + * @return bool true on success |
|
905 | + */ |
|
906 | + function create_database() |
|
907 | + { |
|
908 | + // TODO |
|
909 | + return false; |
|
910 | + } |
|
911 | 911 | } |
912 | 912 | |
913 | 913 |
@@ -255,20 +255,20 @@ |
||
255 | 255 | */ |
256 | 256 | static public function parse_digest($txt) |
257 | 257 | { |
258 | - // protect against missing data |
|
259 | - $needed_parts = array('nonce'=>1, 'nc'=>1, 'cnonce'=>1, 'qop'=>1, 'username'=>1, 'uri'=>1, 'response'=>1); |
|
260 | - $data = array(); |
|
261 | - $keys = implode('|', array_keys($needed_parts)); |
|
258 | + // protect against missing data |
|
259 | + $needed_parts = array('nonce'=>1, 'nc'=>1, 'cnonce'=>1, 'qop'=>1, 'username'=>1, 'uri'=>1, 'response'=>1); |
|
260 | + $data = array(); |
|
261 | + $keys = implode('|', array_keys($needed_parts)); |
|
262 | 262 | |
263 | 263 | $matches = null; |
264 | - preg_match_all('@(' . $keys . ')=(?:([\'"])([^\2]+?)\2|([^\s,]+))@', $txt, $matches, PREG_SET_ORDER); |
|
264 | + preg_match_all('@(' . $keys . ')=(?:([\'"])([^\2]+?)\2|([^\s,]+))@', $txt, $matches, PREG_SET_ORDER); |
|
265 | 265 | |
266 | - foreach ($matches as $m) |
|
267 | - { |
|
268 | - $data[$m[1]] = $m[3] ? $m[3] : $m[4]; |
|
269 | - unset($needed_parts[$m[1]]); |
|
270 | - } |
|
271 | - //error_log(__METHOD__."('$txt') returning ".array2string($needed_parts ? false : $data)); |
|
272 | - return $needed_parts ? false : $data; |
|
266 | + foreach ($matches as $m) |
|
267 | + { |
|
268 | + $data[$m[1]] = $m[3] ? $m[3] : $m[4]; |
|
269 | + unset($needed_parts[$m[1]]); |
|
270 | + } |
|
271 | + //error_log(__METHOD__."('$txt') returning ".array2string($needed_parts ? false : $data)); |
|
272 | + return $needed_parts ? false : $data; |
|
273 | 273 | } |
274 | 274 | } |
@@ -224,13 +224,13 @@ |
||
224 | 224 | } |
225 | 225 | |
226 | 226 | /** |
227 | - * Ajax callback to receive an incoming file |
|
228 | - * |
|
229 | - * The incoming file is automatically placed into the appropriate VFS location. |
|
230 | - * If the entry is not yet created, the file information is stored into the widget's value. |
|
231 | - * When the form is submitted, the information for all files uploaded is available in the returned |
|
232 | - * $content array and the application should deal with the file. |
|
233 | - */ |
|
227 | + * Ajax callback to receive an incoming file |
|
228 | + * |
|
229 | + * The incoming file is automatically placed into the appropriate VFS location. |
|
230 | + * If the entry is not yet created, the file information is stored into the widget's value. |
|
231 | + * When the form is submitted, the information for all files uploaded is available in the returned |
|
232 | + * $content array and the application should deal with the file. |
|
233 | + */ |
|
234 | 234 | public static function store_file($path, $file) |
235 | 235 | { |
236 | 236 | $name = $_REQUEST['widget_id']; |
@@ -238,10 +238,10 @@ |
||
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
241 | - * Delete a directory RECURSIVELY |
|
242 | - * @param string $dir - directory path |
|
243 | - * @link http://php.net/manual/en/function.rmdir.php |
|
244 | - */ |
|
241 | + * Delete a directory RECURSIVELY |
|
242 | + * @param string $dir - directory path |
|
243 | + * @link http://php.net/manual/en/function.rmdir.php |
|
244 | + */ |
|
245 | 245 | private static function rrmdir($dir) |
246 | 246 | { |
247 | 247 | if (is_dir($dir)) |
@@ -33,7 +33,7 @@ |
||
33 | 33 | * while it uses select-account for owner in historylog (containing all users). |
34 | 34 | * |
35 | 35 | * @param string $cname |
36 | - */ |
|
36 | + */ |
|
37 | 37 | public function beforeSendToClient($cname) |
38 | 38 | { |
39 | 39 | $form_name = self::form_name($cname, $this->id); |