1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only |
4
|
|
|
* SPDX-FileCopyrightText: Copyright 2007-2016 Zarafa Deutschland GmbH |
5
|
|
|
* SPDX-FileCopyrightText: Copyright 2020-2022 grommunio GmbH |
6
|
|
|
* |
7
|
|
|
* Provides the SETTINGS command |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
class Settings extends RequestProcessor { |
11
|
|
|
/** |
12
|
|
|
* Handles the Settings command. |
13
|
|
|
* |
14
|
|
|
* @param int $commandCode |
15
|
|
|
* |
16
|
|
|
* @return bool |
17
|
|
|
*/ |
18
|
|
|
public function Handle($commandCode) { |
19
|
|
|
if (!self::$decoder->getElementStartTag(SYNC_SETTINGS_SETTINGS)) { |
20
|
|
|
return false; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
// save the request parameters |
24
|
|
|
$request = []; |
|
|
|
|
25
|
|
|
|
26
|
|
|
// Loop through properties. Possible are: |
27
|
|
|
// - Out of office |
28
|
|
|
// - DevicePassword |
29
|
|
|
// - DeviceInformation |
30
|
|
|
// - UserInformation |
31
|
|
|
// Each of them should only be once per request. Each property must be processed in order. |
32
|
|
|
WBXMLDecoder::ResetInWhile("settingsMain"); |
33
|
|
|
while (WBXMLDecoder::InWhile("settingsMain")) { |
34
|
|
|
$propertyName = ""; |
35
|
|
|
if (self::$decoder->getElementStartTag(SYNC_SETTINGS_OOF)) { |
36
|
|
|
$propertyName = SYNC_SETTINGS_OOF; |
37
|
|
|
} |
38
|
|
|
if (self::$decoder->getElementStartTag(SYNC_SETTINGS_DEVICEPW)) { |
39
|
|
|
$propertyName = SYNC_SETTINGS_DEVICEPW; |
40
|
|
|
} |
41
|
|
|
if (self::$decoder->getElementStartTag(SYNC_SETTINGS_DEVICEINFORMATION)) { |
42
|
|
|
$propertyName = SYNC_SETTINGS_DEVICEINFORMATION; |
43
|
|
|
} |
44
|
|
|
if (self::$decoder->getElementStartTag(SYNC_SETTINGS_USERINFORMATION)) { |
45
|
|
|
$propertyName = SYNC_SETTINGS_USERINFORMATION; |
46
|
|
|
} |
47
|
|
|
if (self::$decoder->getElementStartTag(SYNC_SETTINGS_RIGHTSMANAGEMENTINFORMATION)) { |
48
|
|
|
$propertyName = SYNC_SETTINGS_RIGHTSMANAGEMENTINFORMATION; |
49
|
|
|
} |
50
|
|
|
// TODO - check if it is necessary |
51
|
|
|
// no property name available - break |
52
|
|
|
if (!$propertyName) { |
53
|
|
|
break; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
// the property name is followed by either get or set |
57
|
|
|
if (self::$decoder->getElementStartTag(SYNC_SETTINGS_GET)) { |
58
|
|
|
// get is available for OOF (AS 12), user information (AS 12) and rights management (AS 14.1) |
59
|
|
|
switch ($propertyName) { |
60
|
|
|
case SYNC_SETTINGS_OOF: |
61
|
|
|
$oofGet = new SyncOOF(); |
62
|
|
|
$oofGet->Decode(self::$decoder); |
63
|
|
|
if (!self::$decoder->getElementEndTag()) { |
64
|
|
|
return false; |
65
|
|
|
} // SYNC_SETTINGS_GET |
66
|
|
|
break; |
67
|
|
|
|
68
|
|
|
case SYNC_SETTINGS_USERINFORMATION: |
69
|
|
|
$userInformation = new SyncUserInformation(); |
70
|
|
|
break; |
71
|
|
|
|
72
|
|
|
case SYNC_SETTINGS_RIGHTSMANAGEMENTINFORMATION: |
73
|
|
|
$rmTemplates = new SyncRightsManagementTemplates(); |
74
|
|
|
break; |
75
|
|
|
|
76
|
|
|
default: |
77
|
|
|
// TODO: a special status code needed? |
78
|
|
|
SLog::Write(LOGLEVEL_WARN, sprintf("This property ('%s') is not allowed to use get in request", $propertyName)); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
elseif (self::$decoder->getElementStartTag(SYNC_SETTINGS_SET)) { |
82
|
|
|
// set is available for OOF, device password and device information |
83
|
|
|
switch ($propertyName) { |
84
|
|
|
case SYNC_SETTINGS_OOF: |
85
|
|
|
$oofSet = new SyncOOF(); |
86
|
|
|
$oofSet->Decode(self::$decoder); |
87
|
|
|
// TODO check - do it after while(1) finished? |
88
|
|
|
break; |
89
|
|
|
|
90
|
|
|
case SYNC_SETTINGS_DEVICEPW: |
91
|
|
|
// TODO device password |
92
|
|
|
$devicepassword = new SyncDevicePassword(); |
93
|
|
|
$devicepassword->Decode(self::$decoder); |
94
|
|
|
break; |
95
|
|
|
|
96
|
|
|
case SYNC_SETTINGS_DEVICEINFORMATION: |
97
|
|
|
$deviceinformation = new SyncDeviceInformation(); |
98
|
|
|
$deviceinformation->Decode(self::$decoder); |
99
|
|
|
$deviceinformation->Status = SYNC_SETTINGSSTATUS_SUCCESS; |
100
|
|
|
self::$deviceManager->SaveDeviceInformation($deviceinformation); |
101
|
|
|
break; |
102
|
|
|
|
103
|
|
|
default: |
104
|
|
|
// TODO: a special status code needed? |
105
|
|
|
SLog::Write(LOGLEVEL_WARN, sprintf("This property ('%s') is not allowed to use set in request", $propertyName)); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
if (!self::$decoder->getElementEndTag()) { |
109
|
|
|
return false; |
110
|
|
|
} // SYNC_SETTINGS_SET |
111
|
|
|
} |
112
|
|
|
else { |
113
|
|
|
SLog::Write(LOGLEVEL_WARN, sprintf("Neither get nor set found for property '%s'", $propertyName)); |
114
|
|
|
|
115
|
|
|
return false; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
if (!self::$decoder->getElementEndTag()) { |
119
|
|
|
return false; |
120
|
|
|
} // SYNC_SETTINGS_OOF or SYNC_SETTINGS_DEVICEPW or SYNC_SETTINGS_DEVICEINFORMATION or SYNC_SETTINGS_USERINFORMATION |
121
|
|
|
|
122
|
|
|
// break if it reached the endtag |
123
|
|
|
$e = self::$decoder->peek(); |
124
|
|
|
if ($e[EN_TYPE] == EN_TYPE_ENDTAG) { |
125
|
|
|
self::$decoder->getElementEndTag(); // SYNC_SETTINGS_SETTINGS |
126
|
|
|
|
127
|
|
|
break; |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
$status = SYNC_SETTINGSSTATUS_SUCCESS; |
132
|
|
|
|
133
|
|
|
// TODO put it in try catch block |
134
|
|
|
// TODO implement Settings in the backend |
135
|
|
|
// TODO save device information in device manager |
136
|
|
|
// TODO status handling |
137
|
|
|
// $data = self::$backend->Settings($request); |
138
|
|
|
|
139
|
|
|
self::$encoder->startWBXML(); |
140
|
|
|
self::$encoder->startTag(SYNC_SETTINGS_SETTINGS); |
141
|
|
|
|
142
|
|
|
self::$encoder->startTag(SYNC_SETTINGS_STATUS); |
143
|
|
|
self::$encoder->content($status); |
144
|
|
|
self::$encoder->endTag(); // SYNC_SETTINGS_STATUS |
145
|
|
|
|
146
|
|
|
// get oof settings |
147
|
|
|
if (isset($oofGet)) { |
148
|
|
|
$oofGet = self::$backend->Settings($oofGet); |
149
|
|
|
self::$encoder->startTag(SYNC_SETTINGS_OOF); |
150
|
|
|
self::$encoder->startTag(SYNC_SETTINGS_STATUS); |
151
|
|
|
self::$encoder->content($oofGet->Status); |
152
|
|
|
self::$encoder->endTag(); // SYNC_SETTINGS_STATUS |
153
|
|
|
|
154
|
|
|
self::$encoder->startTag(SYNC_SETTINGS_GET); |
155
|
|
|
$oofGet->Encode(self::$encoder); |
156
|
|
|
self::$encoder->endTag(); // SYNC_SETTINGS_GET |
157
|
|
|
self::$encoder->endTag(); // SYNC_SETTINGS_OOF |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
// get user information |
161
|
|
|
// TODO none email address found |
162
|
|
|
if (isset($userInformation)) { |
163
|
|
|
self::$backend->Settings($userInformation); |
164
|
|
|
self::$encoder->startTag(SYNC_SETTINGS_USERINFORMATION); |
165
|
|
|
self::$encoder->startTag(SYNC_SETTINGS_STATUS); |
166
|
|
|
self::$encoder->content($userInformation->Status); |
167
|
|
|
self::$encoder->endTag(); // SYNC_SETTINGS_STATUS |
168
|
|
|
|
169
|
|
|
self::$encoder->startTag(SYNC_SETTINGS_GET); |
170
|
|
|
$userInformation->Encode(self::$encoder); |
171
|
|
|
self::$encoder->endTag(); // SYNC_SETTINGS_GET |
172
|
|
|
self::$encoder->endTag(); // SYNC_SETTINGS_USERINFORMATION |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
// get rights management templates |
176
|
|
|
if (isset($rmTemplates)) { |
177
|
|
|
self::$backend->Settings($rmTemplates); |
178
|
|
|
self::$encoder->startTag(SYNC_SETTINGS_RIGHTSMANAGEMENTINFORMATION); |
179
|
|
|
self::$encoder->startTag(SYNC_SETTINGS_STATUS); |
180
|
|
|
self::$encoder->content($rmTemplates->Status); |
181
|
|
|
self::$encoder->endTag(); // SYNC_SETTINGS_STATUS |
182
|
|
|
|
183
|
|
|
self::$encoder->startTag(SYNC_SETTINGS_GET); |
184
|
|
|
$rmTemplates->Encode(self::$encoder); |
185
|
|
|
self::$encoder->endTag(); // SYNC_SETTINGS_GET |
186
|
|
|
self::$encoder->endTag(); // SYNC_SETTINGS_RIGHTSMANAGEMENTINFORMATION |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
// set out of office |
190
|
|
|
if (isset($oofSet)) { |
191
|
|
|
$oofSet = self::$backend->Settings($oofSet); |
192
|
|
|
self::$encoder->startTag(SYNC_SETTINGS_OOF); |
193
|
|
|
self::$encoder->startTag(SYNC_SETTINGS_STATUS); |
194
|
|
|
self::$encoder->content($oofSet->Status); |
195
|
|
|
self::$encoder->endTag(); // SYNC_SETTINGS_STATUS |
196
|
|
|
self::$encoder->endTag(); // SYNC_SETTINGS_OOF |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
// set device passwort |
200
|
|
|
if (isset($devicepassword)) { |
201
|
|
|
self::$encoder->startTag(SYNC_SETTINGS_DEVICEPW); |
202
|
|
|
self::$encoder->startTag(SYNC_SETTINGS_SET); |
203
|
|
|
self::$encoder->startTag(SYNC_SETTINGS_STATUS); |
204
|
|
|
self::$encoder->content($devicepassword->Status); |
205
|
|
|
self::$encoder->endTag(); // SYNC_SETTINGS_STATUS |
206
|
|
|
self::$encoder->endTag(); // SYNC_SETTINGS_SET |
207
|
|
|
self::$encoder->endTag(); // SYNC_SETTINGS_DEVICEPW |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
// set device information |
211
|
|
|
if (isset($deviceinformation)) { |
212
|
|
|
self::$encoder->startTag(SYNC_SETTINGS_DEVICEINFORMATION); |
213
|
|
|
self::$encoder->startTag(SYNC_SETTINGS_STATUS); |
214
|
|
|
self::$encoder->content($deviceinformation->Status); |
215
|
|
|
self::$encoder->endTag(); // SYNC_SETTINGS_STATUS |
216
|
|
|
self::$encoder->endTag(); // SYNC_SETTINGS_DEVICEINFORMATION |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
self::$encoder->endTag(); // SYNC_SETTINGS_SETTINGS |
220
|
|
|
|
221
|
|
|
return true; |
222
|
|
|
} |
223
|
|
|
} |
224
|
|
|
|