This file is indexed.

/usr/share/z-push/lib/webservice/webservicedevice.php is in z-push-common 2.3.8-2ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
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
226
227
228
229
230
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<?php
/***********************************************
* File      :   webservicedevice.php
* Project   :   Z-Push
* Descr     :   Device remote administration tasks
*               used over webservice e.g. by the
*               Mobile Device Management Plugin for Kopano.
*
* Created   :   23.12.2011
*
* Copyright 2007 - 2016 Zarafa Deutschland GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
* Consult LICENSE file for details
************************************************/

class WebserviceDevice {

    /**
     * Returns a list of all known devices of the Request::GetGETUser().
     *
     * @access public
     * @return array
     */
    public function ListDevicesDetails() {
        $user = Request::GetGETUser();
        $devices = ZPushAdmin::ListDevices($user);
        $output = array();

        ZLog::Write(LOGLEVEL_INFO, sprintf("WebserviceDevice::ListDevicesDetails(): found %d devices of user '%s'", count($devices), $user));
        ZPush::GetTopCollector()->AnnounceInformation(sprintf("Retrieved details of %d devices", count($devices)), true);

        foreach ($devices as $devid)
            $output[] = ZPushAdmin::GetDeviceDetails($devid, $user);

        return $output;
    }

    /**
     * Returns the details of a given deviceid of the Request::GetGETUser().
     *
     * @param boolean   $withHierarchyCache (opt) includes the HierarchyCache - default: false
     *
     * @access public
     * @return ASDevice object
     */
    public function GetDeviceDetails($deviceId, $withHierarchyCache = false) {
        $user = Request::GetGETUser();
        $deviceId = preg_replace("/[^A-Za-z0-9]/", "", $deviceId);
        ZLog::Write(LOGLEVEL_INFO, sprintf("WebserviceDevice::GetDeviceDetails('%s'): getting device details from state of user '%s'", $deviceId, $user));

        ZPush::GetTopCollector()->AnnounceInformation(sprintf("Retrieved details of device '%s'", $deviceId), true);
        return ZPushAdmin::GetDeviceDetails($deviceId, $user, $withHierarchyCache);
    }

    /**
     * Remove all state data for a device of the Request::GetGETUser().
     *
     * @param string    $deviceId       the device id
     *
     * @access public
     * @return boolean
     * @throws SoapFault
     */
    public function RemoveDevice($deviceId) {
        $deviceId = preg_replace("/[^A-Za-z0-9]/", "", $deviceId);
        ZLog::Write(LOGLEVEL_INFO, sprintf("WebserviceDevice::RemoveDevice('%s'): remove device state data of user '%s'", $deviceId, Request::GetGETUser()));

        if (! ZPushAdmin::RemoveDevice(Request::GetGETUser(), $deviceId)) {
            ZPush::GetTopCollector()->AnnounceInformation(ZLog::GetLastMessage(LOGLEVEL_ERROR), true);
            throw new SoapFault("ERROR", ZLog::GetLastMessage(LOGLEVEL_ERROR));
        }

        ZPush::GetTopCollector()->AnnounceInformation(sprintf("Removed device id '%s'", $deviceId), true);
        return true;
    }

    /**
     * Marks a device of the Request::GetGETUser() to be remotely wiped.
     *
     * @param string    $deviceId       the device id
     *
     * @access public
     * @return boolean
     * @throws SoapFault
     */
    public function WipeDevice($deviceId) {
        $deviceId = preg_replace("/[^A-Za-z0-9]/", "", $deviceId);
        ZLog::Write(LOGLEVEL_INFO, sprintf("WebserviceDevice::WipeDevice('%s'): mark device of user '%s' for remote wipe", $deviceId, Request::GetGETUser()));

        if (! ZPushAdmin::WipeDevice(Request::GetAuthUser(), Request::GetGETUser(), $deviceId)) {
            ZPush::GetTopCollector()->AnnounceInformation(ZLog::GetLastMessage(LOGLEVEL_ERROR), true);
            throw new SoapFault("ERROR", ZLog::GetLastMessage(LOGLEVEL_ERROR));
        }

        ZPush::GetTopCollector()->AnnounceInformation(sprintf("Wipe requested - device id '%s'", $deviceId), true);
        return true;
    }

    /**
     * Marks a device of the Request::GetGETUser() for resynchronization.
     *
     * @param string    $deviceId       the device id
     *
     * @access public
     * @return boolean
     * @throws SoapFault
     */
    public function ResyncDevice($deviceId) {
        $deviceId = preg_replace("/[^A-Za-z0-9]/", "", $deviceId);
        ZLog::Write(LOGLEVEL_INFO, sprintf("WebserviceDevice::ResyncDevice('%s'): mark device of user '%s' for resynchronization", $deviceId, Request::GetGETUser()));

        if (! ZPushAdmin::ResyncDevice(Request::GetGETUser(), $deviceId)) {
            ZPush::GetTopCollector()->AnnounceInformation(ZLog::GetLastMessage(LOGLEVEL_ERROR), true);
            throw new SoapFault("ERROR", ZLog::GetLastMessage(LOGLEVEL_ERROR));
        }

        ZPush::GetTopCollector()->AnnounceInformation(sprintf("Resync requested - device id '%s'", $deviceId), true);
        return true;
    }

    /**
     * Marks a folder of a device of the Request::GetGETUser() for resynchronization.
     *
     * @param string    $deviceId       the device id
     * @param string    $folderId       the folder id
     *
     * @access public
     * @return boolean
     * @throws SoapFault
     */
    public function ResyncFolder($deviceId, $folderId) {
        $deviceId = preg_replace("/[^A-Za-z0-9]/", "", $deviceId);
        $folderId = preg_replace("/[^A-Za-z0-9]/", "", $folderId);
        ZLog::Write(LOGLEVEL_INFO, sprintf("WebserviceDevice::ResyncFolder('%s','%s'): mark folder of a device of user '%s' for resynchronization", $deviceId, $folderId, Request::GetGETUser()));

        if (! ZPushAdmin::ResyncFolder(Request::GetGETUser(), $deviceId, $folderId)) {
            ZPush::GetTopCollector()->AnnounceInformation(ZLog::GetLastMessage(LOGLEVEL_ERROR), true);
            throw new SoapFault("ERROR", ZLog::GetLastMessage(LOGLEVEL_ERROR));
        }

        ZPush::GetTopCollector()->AnnounceInformation(sprintf("Folder resync requested - device id '%s', folder id '%s", $deviceId, $folderId), true);
        return true;
    }

    /**
     * Returns a list of all additional folders of the given device and the Request::GetGETUser().
     *
     * @param string    $deviceId       device id that should be listed.
     *
     * @access public
     * @return array
     */
    public function AdditionalFolderList($deviceId) {
        $user = Request::GetGETUser();
        $deviceId = preg_replace("/[^A-Za-z0-9]/", "", $deviceId);
        $folders = ZPushAdmin::AdditionalFolderList($user, $deviceId);
        ZLog::Write(LOGLEVEL_INFO, sprintf("WebserviceDevice::AdditionalFolderList(): found %d folders for device '%s' of user '%s'", count($folders), $deviceId, $user));
        // retrieve the permission flags from the backend and convert associative array into stdClass object for PHP7 support
        $folderObjects = array();
        $backend = ZPush::GetBackend();
        foreach($folders as $folder) {
            $folderObject = new stdClass();
            $folderObject->store = $folder['store'];
            $folderObject->folderid = $folder['folderid'];
            $folderObject->parentid = $folder['parentid'];
            $folderObject->syncfolderid = $folder['syncfolderid'];
            $folderObject->name = $folder['name'];
            $folderObject->type = $folder['type'];
            $folderObject->origin = $folder['origin'];
            $folderObject->flags = $folder['flags'];
            $folderObject->readable = $backend->Setup($folder['store'], true, $folder['folderid'], true);
            $folderObject->writeable = $backend->Setup($folder['store'], true, $folder['folderid']);
            $folderObjects[] = $folderObject;
        }
        ZPush::GetTopCollector()->AnnounceInformation(sprintf("Retrieved details of %d folders", count($folderObjects)), true);
        return $folderObjects;
    }

    /**
     * Adds an additional folder to the given device and the Request::GetGETUser().
     *
     * @param string    $deviceId       device id the folder should be added to.
     * @param string    $add_store      the store where this folder is located, e.g. "SYSTEM" (for public folder) or an username/email address.
     * @param string    $add_folderid   the folder id of the additional folder.
     * @param string    $add_name       the name of the additional folder (has to be unique for all folders on the device).
     * @param string    $add_type       AS foldertype of SYNC_FOLDER_TYPE_USER_*
     * @param int       $add_flags      Additional flags, like DeviceManager::FLD_FLAGS_SENDASOWNER
     *
     * @access public
     * @return boolean
     */
    public function AdditionalFolderAdd($deviceId, $add_store, $add_folderid, $add_name, $add_type, $add_flags) {
        $user = Request::GetGETUser();
        $deviceId = preg_replace("/[^A-Za-z0-9]/", "", $deviceId);
        $add_folderid = preg_replace("/[^A-Za-z0-9]/", "", $add_folderid);
        $add_type = preg_replace("/[^0-9]/", "", $add_type);
        $add_flags = preg_replace("/[^0-9]/", "", $add_flags);

        $status = ZPushAdmin::AdditionalFolderAdd($user, $deviceId, $add_store, $add_folderid, $add_name, $add_type, $add_flags);
        if (!$status) {
            ZPush::GetTopCollector()->AnnounceInformation(ZLog::GetLastMessage(LOGLEVEL_ERROR), true);
            throw new SoapFault("ERROR", ZLog::GetLastMessage(LOGLEVEL_ERROR));
        }
        ZLog::Write(LOGLEVEL_INFO, sprintf("WebserviceDevice::AdditionalFolderAdd(): added folder for device '%s' of user '%s': %s", $deviceId, $user, Utils::PrintAsString($status)));
        ZPush::GetTopCollector()->AnnounceInformation("Added additional folder", true);

        return $status;
    }

    /**
     * Updates the name of an additional folder to the given device and the Request::GetGETUser().
     *
     * @param string    $deviceId       device id of where the folder should be updated.
     * @param string    $add_folderid   the folder id of the additional folder.
     * @param string    $add_name       the name of the additional folder (has to be unique for all folders on the device).
     * @param int       $add_flags      Additional flags, like DeviceManager::FLD_FLAGS_SENDASOWNER
     *
     * @access public
     * @return boolean
     */
    public function AdditionalFolderEdit($deviceId, $add_folderid, $add_name, $add_flags) {
        $user = Request::GetGETUser();
        $deviceId = preg_replace("/[^A-Za-z0-9]/", "", $deviceId);
        $add_folderid = preg_replace("/[^A-Za-z0-9]/", "", $add_folderid);
        $add_flags = preg_replace("/[^0-9]/", "", $add_flags);

        $status = ZPushAdmin::AdditionalFolderEdit($user, $deviceId, $add_folderid, $add_name, $add_flags);
        if (!$status) {
            ZPush::GetTopCollector()->AnnounceInformation(ZLog::GetLastMessage(LOGLEVEL_ERROR), true);
            throw new SoapFault("ERROR", ZLog::GetLastMessage(LOGLEVEL_ERROR));
        }
        ZLog::Write(LOGLEVEL_INFO, sprintf("WebserviceDevice::AdditionalFolderEdit(): edited folder for device '%s' of user '%s': %s", $deviceId, $user, Utils::PrintAsString($status)));
        ZPush::GetTopCollector()->AnnounceInformation("Edited additional folder", true);

        return $status;
    }

    /**
     * Removes an additional folder from the given device and the Request::GetGETUser().
     *
     * @param string    $deviceId       device id of where the folder should be removed.
     * @param string    $add_folderid   the folder id of the additional folder.
     *
     * @access public
     * @return boolean
     */
    public function AdditionalFolderRemove($deviceId, $add_folderid) {
        $user = Request::GetGETUser();
        $deviceId = preg_replace("/[^A-Za-z0-9]/", "", $deviceId);
        $add_folderid = preg_replace("/[^A-Za-z0-9]/", "", $add_folderid);

        $status = ZPushAdmin::AdditionalFolderRemove($user, $deviceId, $add_folderid);
        if (!$status) {
            ZPush::GetTopCollector()->AnnounceInformation(ZLog::GetLastMessage(LOGLEVEL_ERROR), true);
            throw new SoapFault("ERROR", ZLog::GetLastMessage(LOGLEVEL_ERROR));
        }
        ZLog::Write(LOGLEVEL_INFO, sprintf("WebserviceDevice::AdditionalFolderRemove(): removed folder for device '%s' of user '%s': %s", $deviceId, $user, Utils::PrintAsString($status)));
        ZPush::GetTopCollector()->AnnounceInformation("Removed additional folder", true);

        return $status;
    }

    /**
     * Sets a list of additional folders of one store to the given device and the Request::GetGETUser().
     * If there are additional folders for this store, that are not in the list they will be removed.
     *
     * @param string    $deviceId       device id the folder should be added to.
     * @param string    $set_store      the store where this folder is located, e.g. "SYSTEM" (for public folder) or an username/email address.
     * @param array     $set_folders    a list of folders to be set for this user. Other existing additional folders (that are not in this list)
     *                                  will be removed. The list is an array containing folders, where each folder is an array with the following keys:
     *                                  'folderid'  (string) the folder id of the additional folder.
     *                                  'parentid'  (string) the folderid of the parent folder. If no parent folder is set or the parent folder is not defined, '0' (main folder) is used.
     *                                  'name'      (string) the name of the additional folder (has to be unique for all folders on the device).
     *                                  'type'      (string) AS foldertype of SYNC_FOLDER_TYPE_USER_*
     *                                  'flags'     (int)    Additional flags, like DeviceManager::FLD_FLAGS_SENDASOWNER
     *
     * @access public
     * @return boolean
     */
    public function AdditionalFolderSetList($deviceId, $set_store, $set_folders) {
        $user = Request::GetGETUser();
        $deviceId = preg_replace("/[^A-Za-z0-9]/", "", $deviceId);
        array_walk($set_folders, function(&$folder) {
            if (!isset($folder['folderid']))    $folder['folderid'] = "";
            if (!isset($folder['parentid']))    $folder['parentid'] = "0";
            if (!isset($folder['type']))        $folder['type'] = SYNC_FOLDER_TYPE_USER_MAIL;
            if (!isset($folder['flags']))       $folder['flags'] = 0;

            $folder['folderid'] = preg_replace("/[^A-Za-z0-9]/", "", $folder['folderid']);
            $folder['parentid'] = preg_replace("/[^A-Za-z0-9]/", "", $folder['parentid']);
            $folder['type'] = preg_replace("/[^0-9]/", "", $folder['type']);
            $folder['flags'] = preg_replace("/[^0-9]/", "", $folder['flags']);
        });

        $status = ZPushAdmin::AdditionalFolderSetList($user, $deviceId, $set_store, $set_folders);
        if (!$status) {
            ZPush::GetTopCollector()->AnnounceInformation(ZLog::GetLastMessage(LOGLEVEL_ERROR), true);
            throw new SoapFault("ERROR", ZLog::GetLastMessage(LOGLEVEL_ERROR));
        }
        ZLog::Write(LOGLEVEL_INFO, sprintf("WebserviceDevice::AdditionalFolderSetList(): set '%d' folders for device '%s' of user '%s': %s", count($set_folders), $deviceId, $user, Utils::PrintAsString($status)));
        ZPush::GetTopCollector()->AnnounceInformation("Set additional folders", true);

        return $status;
    }
}