1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | namespace Aurora\Modules\Dav; |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: | |
19: | class Module extends \Aurora\System\Module\AbstractModule |
20: | { |
21: | public $oManager = null; |
22: | |
23: | public function getManager() |
24: | { |
25: | if ($this->oManager === null) { |
26: | $this->oManager = new Manager($this); |
27: | } |
28: | |
29: | return $this->oManager; |
30: | } |
31: | |
32: | public function GetModuleManager() |
33: | { |
34: | return parent::GetModuleManager(); |
35: | } |
36: | |
37: | |
38: | |
39: | |
40: | |
41: | |
42: | |
43: | public function init() |
44: | { |
45: | $this->AddEntry('dav', 'EntryDav'); |
46: | |
47: | $this->subscribeEvent('Calendar::GetCalendars::after', array($this, 'onAfterGetCalendars')); |
48: | $this->subscribeEvent('MobileSync::GetInfo', array($this, 'onGetMobileSyncInfo')); |
49: | } |
50: | |
51: | |
52: | |
53: | |
54: | |
55: | |
56: | |
57: | public function onAfterGetCalendars(&$aArgs, &$mResult) |
58: | { |
59: | if (isset($mResult) && $mResult !== false) { |
60: | $mResult['ServerUrl'] = $this->GetServerUrl(); |
61: | } |
62: | } |
63: | |
64: | |
65: | |
66: | |
67: | |
68: | |
69: | |
70: | public function onGetMobileSyncInfo($aArgs, &$mResult) |
71: | { |
72: | $mResult['EnableDav'] = true; |
73: | $mResult['Dav']['Login'] = $this->GetLogin(); |
74: | $mResult['Dav']['Server'] = $this->GetServerUrl(); |
75: | $mResult['Dav']['PrincipalUrl'] = $this->GetPrincipalUrl(); |
76: | } |
77: | |
78: | |
79: | |
80: | |
81: | |
82: | |
83: | |
84: | |
85: | public function onAfterCreateTables($aArgs, &$mResult) |
86: | { |
87: | |
88: | |
89: | |
90: | |
91: | } |
92: | |
93: | |
94: | |
95: | |
96: | |
97: | |
98: | |
99: | |
100: | public function EntryDav() |
101: | { |
102: | set_error_handler(function ($errno, $errstr, $errfile, $errline) { |
103: | throw new \ErrorException($errstr, 0, $errno, $errfile, $errline); |
104: | }); |
105: | |
106: | @set_time_limit(3000); |
107: | |
108: | $sRequestUri = empty($_SERVER['REQUEST_URI']) ? '' : \trim($_SERVER['REQUEST_URI']); |
109: | |
110: | $oServer = \Afterlogic\DAV\Server::getInstance(); |
111: | $oServer->setBaseUri($sRequestUri); |
112: | |
113: | \Afterlogic\DAV\Server::getInstance()->exec(); |
114: | } |
115: | |
116: | |
117: | |
118: | |
119: | |
120: | |
121: | public function GetDavClient() |
122: | { |
123: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
124: | |
125: | return $this->getManager()->GetDAVClient(\Aurora\System\Api::getAuthenticatedUserId()); |
126: | } |
127: | |
128: | |
129: | |
130: | |
131: | |
132: | |
133: | |
134: | public function GetVCardObject($Data) |
135: | { |
136: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
137: | |
138: | return $this->getManager()->getVCardObject($Data); |
139: | } |
140: | |
141: | |
142: | |
143: | |
144: | |
145: | |
146: | |
147: | |
148: | |
149: | |
150: | |
151: | |
152: | |
153: | |
154: | |
155: | |
156: | |
157: | |
158: | |
159: | |
160: | |
161: | |
162: | |
163: | |
164: | |
165: | |
166: | |
167: | |
168: | |
169: | |
170: | |
171: | |
172: | |
173: | |
174: | |
175: | |
176: | |
177: | |
178: | |
179: | |
180: | |
181: | |
182: | |
183: | |
184: | |
185: | |
186: | |
187: | |
188: | |
189: | |
190: | |
191: | |
192: | |
193: | |
194: | |
195: | |
196: | public function GetSettings() |
197: | { |
198: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous); |
199: | |
200: | return array( |
201: | 'ExternalHostNameOfDAVServer' => $this->GetServerUrl() |
202: | ); |
203: | } |
204: | |
205: | |
206: | |
207: | |
208: | |
209: | |
210: | |
211: | |
212: | |
213: | |
214: | |
215: | |
216: | |
217: | |
218: | |
219: | |
220: | |
221: | |
222: | |
223: | |
224: | |
225: | |
226: | |
227: | |
228: | |
229: | |
230: | |
231: | |
232: | |
233: | |
234: | |
235: | |
236: | |
237: | |
238: | |
239: | |
240: | |
241: | |
242: | |
243: | |
244: | |
245: | |
246: | |
247: | |
248: | |
249: | |
250: | |
251: | |
252: | |
253: | |
254: | |
255: | |
256: | |
257: | |
258: | public function UpdateSettings($ExternalHostNameOfDAVServer) |
259: | { |
260: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::TenantAdmin); |
261: | |
262: | if (!empty($ExternalHostNameOfDAVServer)) { |
263: | $this->setConfig('ExternalHostNameOfDAVServer', $ExternalHostNameOfDAVServer); |
264: | $this->saveModuleConfig(); |
265: | return true; |
266: | } |
267: | |
268: | return false; |
269: | } |
270: | |
271: | |
272: | |
273: | |
274: | |
275: | |
276: | |
277: | |
278: | |
279: | |
280: | |
281: | |
282: | |
283: | |
284: | |
285: | |
286: | |
287: | |
288: | |
289: | |
290: | |
291: | |
292: | |
293: | |
294: | |
295: | |
296: | |
297: | |
298: | |
299: | |
300: | |
301: | |
302: | |
303: | |
304: | |
305: | |
306: | |
307: | |
308: | |
309: | |
310: | |
311: | |
312: | public function GetServerUrl() |
313: | { |
314: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous); |
315: | |
316: | return $this->getManager()->getServerUrl(); |
317: | } |
318: | |
319: | |
320: | |
321: | |
322: | |
323: | |
324: | |
325: | |
326: | |
327: | |
328: | |
329: | |
330: | |
331: | |
332: | |
333: | |
334: | |
335: | |
336: | |
337: | |
338: | |
339: | |
340: | |
341: | |
342: | |
343: | |
344: | |
345: | |
346: | |
347: | |
348: | |
349: | |
350: | |
351: | |
352: | |
353: | |
354: | |
355: | |
356: | |
357: | |
358: | |
359: | |
360: | public function GetServerHost() |
361: | { |
362: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous); |
363: | |
364: | return $this->getManager()->getServerHost(); |
365: | } |
366: | |
367: | |
368: | |
369: | |
370: | |
371: | |
372: | |
373: | |
374: | |
375: | |
376: | |
377: | |
378: | |
379: | |
380: | |
381: | |
382: | |
383: | |
384: | |
385: | |
386: | |
387: | |
388: | |
389: | |
390: | |
391: | |
392: | |
393: | |
394: | |
395: | |
396: | |
397: | |
398: | |
399: | |
400: | |
401: | |
402: | |
403: | |
404: | |
405: | |
406: | |
407: | |
408: | public function GetServerPort() |
409: | { |
410: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous); |
411: | |
412: | return $this->getManager()->getServerPort(); |
413: | } |
414: | |
415: | |
416: | |
417: | |
418: | |
419: | |
420: | public function GetPrincipalUrl() |
421: | { |
422: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
423: | $mResult = null; |
424: | |
425: | $oUser = \Aurora\System\Api::getAuthenticatedUser(); |
426: | if ($oUser) { |
427: | $mResult = $this->getManager()->getPrincipalUrl($oUser->PublicId); |
428: | } |
429: | return $mResult; |
430: | } |
431: | |
432: | |
433: | |
434: | |
435: | |
436: | |
437: | public function IsSsl() |
438: | { |
439: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
440: | |
441: | return $this->getManager()->isSsl(); |
442: | } |
443: | |
444: | |
445: | |
446: | |
447: | |
448: | |
449: | public function GetLogin() |
450: | { |
451: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
452: | $mResult = null; |
453: | $oEntity = \Aurora\Modules\Core\Models\User::find(\Aurora\System\Api::getAuthenticatedUserId()); |
454: | if (!empty($oEntity)) { |
455: | $mResult = $oEntity->PublicId; |
456: | } |
457: | |
458: | return $mResult; |
459: | } |
460: | |
461: | |
462: | |
463: | |
464: | |
465: | |
466: | public function IsMobileSyncEnabled() |
467: | { |
468: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
469: | |
470: | return $this->getManager()->isMobileSyncEnabled(); |
471: | } |
472: | |
473: | |
474: | |
475: | |
476: | |
477: | |
478: | |
479: | public function SetMobileSyncEnable($MobileSyncEnable) |
480: | { |
481: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
482: | |
483: | $oMobileSyncModule = \Aurora\System\Api::GetModule('MobileSync'); |
484: | $oMobileSyncModule->setConfig('Disabled', !$MobileSyncEnable); |
485: | return $oMobileSyncModule->saveModuleConfig(); |
486: | } |
487: | |
488: | |
489: | |
490: | |
491: | |
492: | |
493: | public function TestConnection() |
494: | { |
495: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
496: | |
497: | return $this->getManager()->testConnection( |
498: | \Aurora\System\Api::getAuthenticatedUserId() |
499: | ); |
500: | } |
501: | |
502: | |
503: | |
504: | |
505: | |
506: | |
507: | public function DeletePrincipal() |
508: | { |
509: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
510: | |
511: | return $this->getManager()->deletePrincipal( |
512: | \Aurora\System\Api::getAuthenticatedUserId() |
513: | ); |
514: | } |
515: | |
516: | |
517: | |
518: | |
519: | |
520: | |
521: | public function GetPublicUser() |
522: | { |
523: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
524: | |
525: | return \Afterlogic\DAV\Constants::DAV_PUBLIC_PRINCIPAL; |
526: | } |
527: | |
528: | |
529: | |
530: | |
531: | public function Login($Login, $Password) |
532: | { |
533: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous); |
534: | |
535: | $oTenant = \Aurora\System\Api::getTenantByWebDomain(); |
536: | |
537: | if (!$this->getConfig('UseFullEmailForLogin', true)) { |
538: | $Login = $Login . '@' . $this->getConfig('DomainForLoginWithoutEmail', ''); |
539: | } |
540: | |
541: | $mResult = \Aurora\Modules\Core\Module::Decorator()->Login($Login, $Password, '', false); |
542: | |
543: | if (is_array($mResult) && isset($mResult['AuthToken'])) { |
544: | $sAuthToken = $mResult['AuthToken']; |
545: | |
546: | |
547: | $oUser = \Aurora\System\Api::getAuthenticatedUser($sAuthToken); |
548: | |
549: | return array( |
550: | 'AuthToken' => $sAuthToken |
551: | ); |
552: | } |
553: | |
554: | \Aurora\System\Api::LogEvent('login-failed: ' . $Login, self::GetName()); |
555: | if (!is_writable(\Aurora\System\Api::DataPath())) { |
556: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::SystemNotConfigured); |
557: | } |
558: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::AuthError); |
559: | } |
560: | |
561: | } |
562: | |