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