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