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\Ios;
9:
10: use Aurora\System\Application;
11:
12: /**
13: * Allows to configure iOS device automatically for syncing mails, contacts and calendars using iOS profile.
14: *
15: * @license https://www.gnu.org/licenses/agpl-3.0.html AGPL-3.0
16: * @license https://afterlogic.com/products/common-licensing Afterlogic Software License
17: * @copyright Copyright (c) 2023, Afterlogic Corp.
18: *
19: * @property Settings $oModuleSettings
20: *
21: * @package Modules
22: */
23: class Module extends \Aurora\System\Module\AbstractModule
24: {
25: /**
26: * @return Module
27: */
28: public static function getInstance()
29: {
30: return parent::getInstance();
31: }
32:
33: /**
34: * @return Module
35: */
36: public static function Decorator()
37: {
38: return parent::Decorator();
39: }
40:
41: /**
42: * @return Settings
43: */
44: public function getModuleSettings()
45: {
46: return $this->oModuleSettings;
47: }
48:
49: /***** private functions *****/
50: /**
51: * Initializes IOS Module.
52: *
53: * @ignore
54: */
55: public function init()
56: {
57: $this->AddEntries(
58: array(
59: 'ios' => 'EntryIos',
60: 'ios-error' => 'EntryIosError',
61: 'profile' => 'EntryProfile'
62: )
63: );
64: }
65: /***** private functions *****/
66:
67: /***** public functions *****/
68: /**
69: *
70: * @return array
71: */
72: public function GetSettings()
73: {
74: \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous);
75:
76: return array(
77: 'AllowIosProfile' => $this->oModuleSettings->AllowIosProfile,
78: 'SyncIosAfterLogin' => $this->oModuleSettings->SyncIosAfterLogin
79: );
80: }
81:
82: /**
83: * @ignore
84: * @return string
85: */
86: public function EntryIos()
87: {
88: $sResult = \file_get_contents($this->GetPath() . '/templates/Ios.html');
89:
90: $oApiIntegrator = \Aurora\System\Managers\Integrator::getInstance();
91: $iUserId = \Aurora\System\Api::getAuthenticatedUserId();
92: if (0 < $iUserId) {
93: $sResult = strtr($sResult, array(
94: '{{IOS/HELLO}}' => $this->i18N('HELLO'),
95: '{{IOS/DESC_P1}}' => $this->i18N('DESC_P1'),
96: '{{IOS/DESC_P2}}' => $this->i18N('DESC_P2'),
97: '{{IOS/DESC_P3}}' => $this->i18N('DESC_P3'),
98: '{{IOS/DESC_P4}}' => $this->i18N('DESC_P4'),
99: '{{IOS/DESC_P5}}' => $this->i18N('DESC_P5'),
100: '{{IOS/DESC_P6}}' => $this->i18N('DESC_P6'),
101: '{{IOS/DESC_P7}}' => $this->i18N('DESC_P7'),
102: '{{IOS/DESC_BUTTON_YES}}' => $this->i18N('DESC_BUTTON_YES'),
103: '{{IOS/DESC_BUTTON_SKIP}}' => $this->i18N('DESC_BUTTON_SKIP'),
104: '{{IOS/DESC_BUTTON_OPEN}}' => $this->i18N('DESC_BUTTON_OPEN'),
105: '{{AppVersion}}' => Application::GetVersion(),
106: '{{IntegratorLinks}}' => $oApiIntegrator->buildHeadersLink()
107: ));
108: \Aurora\Modules\CoreWebclient\Module::Decorator()->SetHtmlOutputHeaders();
109: } else {
110: \Aurora\System\Api::Location('./');
111: }
112:
113: return $sResult;
114: }
115:
116: /**
117: * @ignore
118: * @return string
119: */
120: public function EntryIosError()
121: {
122: $sResult = \file_get_contents($this->GetPath() . '/templates/Ios-error.html');
123:
124: $oApiIntegrator = \Aurora\System\Managers\Integrator::getInstance();
125: $iUserId = \Aurora\System\Api::getAuthenticatedUserId();
126: if (0 < $iUserId) {
127: $sResult = strtr($sResult, array(
128: '{{IOS/ERROR_TITLE}}' => $this->i18N('ERROR_TITLE'),
129: '{{IOS/ERROR_DESC}}' => $this->i18N('ERROR_DESC'),
130: '{{IOS/DESC_BUTTON_OPEN}}' => $this->i18N('DESC_BUTTON_OPEN'),
131: '{{AppVersion}}' => Application::GetVersion(),
132: '{{IntegratorLinks}}' => $oApiIntegrator->buildHeadersLink()
133: ));
134: \Aurora\Modules\CoreWebclient\Module::Decorator()->SetHtmlOutputHeaders();
135: } else {
136: \Aurora\System\Api::Location('./');
137: }
138:
139: return $sResult;
140: }
141:
142: /**
143: * @ignore
144: */
145: public function EntryProfile()
146: {
147: $oIosManager = new Manager($this);
148:
149: $oUser = \Aurora\System\Api::getAuthenticatedUser();
150:
151: $mResultProfile = false;
152: if (!$oUser) {
153: \Aurora\System\Api::Log('Ios profile error: user is not authorized!');
154: } else {
155: $mResultProfile = $oIosManager->generateXMLProfile($oUser);
156: }
157:
158: if (!$mResultProfile) {
159: \Aurora\System\Api::Location('./?ios-error');
160: } else {
161: \header('Content-type: application/x-apple-aspen-config; chatset=utf-8');
162: \header('Content-Disposition: attachment; filename="afterlogic.mobileconfig"');
163: echo $mResultProfile;
164: }
165: }
166: /***** public functions *****/
167: }
168: