1: <?php
2: /**
3: * This code is licensed under AGPLv3 license or Afterlogic Software License
4: * if commercial version of the product was purchased.
5: * For full statements of the licenses see LICENSE-AFTERLOGIC and LICENSE-AGPL3 files.
6: */
7:
8: namespace Aurora\Modules\Autodiscover;
9:
10: /**
11: * @license https://www.gnu.org/licenses/agpl-3.0.html AGPL-3.0
12: * @license https://afterlogic.com/products/common-licensing Afterlogic Software License
13: * @copyright Copyright (c) 2023, Afterlogic Corp.
14: *
15: * @package Modules
16: */
17: class Module extends \Aurora\System\Module\AbstractModule
18: {
19: /**
20: * Initializes Mail Module.
21: *
22: * @ignore
23: */
24: public function init()
25: {
26: $this->AddEntries(
27: array(
28: 'autodiscover' => 'EntryAutodiscover'
29: )
30: );
31: }
32:
33: public function GetAutodiscover($Email)
34: {
35: return '';
36: }
37:
38: public function EntryAutodiscover()
39: {
40: $sInput = \file_get_contents('php://input');
41:
42: \Aurora\System\Api::Log('#autodiscover:');
43: \Aurora\System\Api::LogObject($sInput);
44:
45: $aMatches = array();
46: $aEmailAddress = array();
47: \preg_match("/\<AcceptableResponseSchema\>(.*?)\<\/AcceptableResponseSchema\>/i", $sInput, $aMatches);
48: \preg_match("/\<EMailAddress\>(.*?)\<\/EMailAddress\>/", $sInput, $aEmailAddress);
49: if (!empty($aMatches[1]) && !empty($aEmailAddress[1])) {
50: $sAutodiscover = $this->Decorator()->GetAutodiscover($aEmailAddress[1]);
51:
52: $sResult = \implode("\n", array(
53: '<Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006">',
54: ' <Response xmlns="'.$aMatches[1].'">',
55: $sAutodiscover,
56: ' </Response>',
57: '</Autodiscover>'));
58: }
59:
60: if (empty($sResult)) {
61: $usec = $sec = 0;
62: list($usec, $sec) = \explode(' ', \microtime());
63: $sResult = \implode("\n", array('<Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006">',
64: (
65: empty($aMatches[1]) ?
66: ' <Response>' :
67: ' <Response xmlns="'.$aMatches[1].'">'
68: ),
69: ' <Error Time="'.\gmdate('H:i:s', $sec).\substr($usec, 0, \strlen($usec) - 2).'" Id="2477272013">',
70: ' <ErrorCode>600</ErrorCode>',
71: ' <Message>Invalid Request</Message>',
72: ' <DebugData />',
73: ' </Error>',
74: ' </Response>',
75: '</Autodiscover>'));
76: }
77:
78: \header('Content-Type: text/xml');
79: $sResult = '<'.'?xml version="1.0" encoding="utf-8"?'.'>'."\n".$sResult;
80:
81: echo $sResult;
82:
83: \Aurora\System\Api::Log('');
84: \Aurora\System\Api::Log($sResult);
85: }
86: }
87: