[7589] | 1 | <?php |
---|
| 2 | /*********************************************** |
---|
| 3 | * File : webservicedevice.php |
---|
| 4 | * Project : Z-Push |
---|
| 5 | * Descr : Device remote administration tasks |
---|
| 6 | * used over webservice e.g. by the |
---|
| 7 | * Mobile Device Management Plugin for Zarafa. |
---|
| 8 | * |
---|
| 9 | * Created : 23.12.2011 |
---|
| 10 | * |
---|
| 11 | * Copyright 2007 - 2012 Zarafa Deutschland GmbH |
---|
| 12 | * |
---|
| 13 | * This program is free software: you can redistribute it and/or modify |
---|
| 14 | * it under the terms of the GNU Affero General Public License, version 3, |
---|
| 15 | * as published by the Free Software Foundation with the following additional |
---|
| 16 | * term according to sec. 7: |
---|
| 17 | * |
---|
| 18 | * According to sec. 7 of the GNU Affero General Public License, version 3, |
---|
| 19 | * the terms of the AGPL are supplemented with the following terms: |
---|
| 20 | * |
---|
| 21 | * "Zarafa" is a registered trademark of Zarafa B.V. |
---|
| 22 | * "Z-Push" is a registered trademark of Zarafa Deutschland GmbH |
---|
| 23 | * The licensing of the Program under the AGPL does not imply a trademark license. |
---|
| 24 | * Therefore any rights, title and interest in our trademarks remain entirely with us. |
---|
| 25 | * |
---|
| 26 | * However, if you propagate an unmodified version of the Program you are |
---|
| 27 | * allowed to use the term "Z-Push" to indicate that you distribute the Program. |
---|
| 28 | * Furthermore you may use our trademarks where it is necessary to indicate |
---|
| 29 | * the intended purpose of a product or service provided you use it in accordance |
---|
| 30 | * with honest practices in industrial or commercial matters. |
---|
| 31 | * If you want to propagate modified versions of the Program under the name "Z-Push", |
---|
| 32 | * you may only do so if you have a written permission by Zarafa Deutschland GmbH |
---|
| 33 | * (to acquire a permission please contact Zarafa at trademark@zarafa.com). |
---|
| 34 | * |
---|
| 35 | * This program is distributed in the hope that it will be useful, |
---|
| 36 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 37 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 38 | * GNU Affero General Public License for more details. |
---|
| 39 | * |
---|
| 40 | * You should have received a copy of the GNU Affero General Public License |
---|
| 41 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
| 42 | * |
---|
| 43 | * Consult LICENSE file for details |
---|
| 44 | ************************************************/ |
---|
| 45 | include ('lib/utils/zpushadmin.php'); |
---|
| 46 | |
---|
| 47 | class WebserviceDevice { |
---|
| 48 | |
---|
| 49 | /** |
---|
| 50 | * Returns a list of all known devices of the Request::GetGETUser() |
---|
| 51 | * |
---|
| 52 | * @access public |
---|
| 53 | * @return array |
---|
| 54 | */ |
---|
| 55 | public function ListDevicesDetails() { |
---|
| 56 | $user = Request::GetGETUser(); |
---|
| 57 | $devices = ZPushAdmin::ListDevices($user); |
---|
| 58 | $output = array(); |
---|
| 59 | |
---|
| 60 | ZLog::Write(LOGLEVEL_INFO, sprintf("WebserviceDevice::ListDevicesDetails(): found %d devices of user '%s'", count($devices), $user)); |
---|
| 61 | ZPush::GetTopCollector()->AnnounceInformation(sprintf("Retrieved details of %d devices", count($devices)), true); |
---|
| 62 | |
---|
| 63 | foreach ($devices as $devid) |
---|
| 64 | $output[] = ZPushAdmin::GetDeviceDetails($devid, $user); |
---|
| 65 | |
---|
| 66 | return $output; |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | /** |
---|
| 70 | * Remove all state data for a device of the Request::GetGETUser() |
---|
| 71 | * |
---|
| 72 | * @param string $deviceId the device id |
---|
| 73 | * |
---|
| 74 | * @access public |
---|
| 75 | * @return boolean |
---|
| 76 | * @throws SoapFault |
---|
| 77 | */ |
---|
| 78 | public function RemoveDevice($deviceId) { |
---|
| 79 | $deviceId = preg_replace("/[^A-Za-z0-9]/", "", $deviceId); |
---|
| 80 | ZLog::Write(LOGLEVEL_INFO, sprintf("WebserviceDevice::RemoveDevice('%s'): remove device state data of user '%s'", $deviceId, Request::GetGETUser())); |
---|
| 81 | |
---|
| 82 | if (! ZPushAdmin::RemoveDevice(Request::GetGETUser(), $deviceId)) { |
---|
| 83 | ZPush::GetTopCollector()->AnnounceInformation(ZLog::GetLastMessage(LOGLEVEL_ERROR), true); |
---|
| 84 | throw new SoapFault("ERROR", ZLog::GetLastMessage(LOGLEVEL_ERROR)); |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | ZPush::GetTopCollector()->AnnounceInformation(sprintf("Removed device id '%s'", $deviceId), true); |
---|
| 88 | return true; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | /** |
---|
| 92 | * Marks a device of the Request::GetGETUser() to be remotely wiped |
---|
| 93 | * |
---|
| 94 | * @param string $deviceId the device id |
---|
| 95 | * |
---|
| 96 | * @access public |
---|
| 97 | * @return boolean |
---|
| 98 | * @throws SoapFault |
---|
| 99 | */ |
---|
| 100 | public function WipeDevice($deviceId) { |
---|
| 101 | $deviceId = preg_replace("/[^A-Za-z0-9]/", "", $deviceId); |
---|
| 102 | ZLog::Write(LOGLEVEL_INFO, sprintf("WebserviceDevice::WipeDevice('%s'): mark device of user '%s' for remote wipe", $deviceId, Request::GetGETUser())); |
---|
| 103 | |
---|
| 104 | if (! ZPushAdmin::WipeDevice(Request::GetAuthUser(), Request::GetGETUser(), $deviceId)) { |
---|
| 105 | ZPush::GetTopCollector()->AnnounceInformation(ZLog::GetLastMessage(LOGLEVEL_ERROR), true); |
---|
| 106 | throw new SoapFault("ERROR", ZLog::GetLastMessage(LOGLEVEL_ERROR)); |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | ZPush::GetTopCollector()->AnnounceInformation(sprintf("Wipe requested - device id '%s'", $deviceId), true); |
---|
| 110 | return true; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | /** |
---|
| 114 | * Marks a a device of the Request::GetGETUser() for resynchronization |
---|
| 115 | * |
---|
| 116 | * @param string $deviceId the device id |
---|
| 117 | * |
---|
| 118 | * @access public |
---|
| 119 | * @return boolean |
---|
| 120 | * @throws SoapFault |
---|
| 121 | */ |
---|
| 122 | public function ResyncDevice($deviceId) { |
---|
| 123 | $deviceId = preg_replace("/[^A-Za-z0-9]/", "", $deviceId); |
---|
| 124 | ZLog::Write(LOGLEVEL_INFO, sprintf("WebserviceDevice::ResyncDevice('%s'): mark device of user '%s' for resynchronization", $deviceId, Request::GetGETUser())); |
---|
| 125 | |
---|
| 126 | if (! ZPushAdmin::ResyncDevice(Request::GetGETUser(), $deviceId)) { |
---|
| 127 | ZPush::GetTopCollector()->AnnounceInformation(ZLog::GetLastMessage(LOGLEVEL_ERROR), true); |
---|
| 128 | throw new SoapFault("ERROR", ZLog::GetLastMessage(LOGLEVEL_ERROR)); |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | ZPush::GetTopCollector()->AnnounceInformation(sprintf("Resync requested - device id '%s'", $deviceId), true); |
---|
| 132 | return true; |
---|
| 133 | } |
---|
| 134 | } |
---|
| 135 | ?> |
---|