Back to index

d-push  2.0
webservicedevice.php
Go to the documentation of this file.
00001 <?php
00002 /***********************************************
00003 * File      :   webservicedevice.php
00004 * Project   :   Z-Push
00005 * Descr     :   Device remote administration tasks
00006 *               used over webservice e.g. by the
00007 *               Mobile Device Management Plugin for Zarafa.
00008 *
00009 * Created   :   23.12.2011
00010 *
00011 * Copyright 2007 - 2011 Zarafa Deutschland GmbH
00012 *
00013 * This program is free software: you can redistribute it and/or modify
00014 * it under the terms of the GNU Affero General Public License, version 3,
00015 * as published by the Free Software Foundation with the following additional
00016 * term according to sec. 7:
00017 *
00018 * According to sec. 7 of the GNU Affero General Public License, version 3,
00019 * the terms of the AGPL are supplemented with the following terms:
00020 *
00021 * "Zarafa" is a registered trademark of Zarafa B.V.
00022 * "Z-Push" is a registered trademark of Zarafa Deutschland GmbH
00023 * The licensing of the Program under the AGPL does not imply a trademark license.
00024 * Therefore any rights, title and interest in our trademarks remain entirely with us.
00025 *
00026 * However, if you propagate an unmodified version of the Program you are
00027 * allowed to use the term "Z-Push" to indicate that you distribute the Program.
00028 * Furthermore you may use our trademarks where it is necessary to indicate
00029 * the intended purpose of a product or service provided you use it in accordance
00030 * with honest practices in industrial or commercial matters.
00031 * If you want to propagate modified versions of the Program under the name "Z-Push",
00032 * you may only do so if you have a written permission by Zarafa Deutschland GmbH
00033 * (to acquire a permission please contact Zarafa at trademark@zarafa.com).
00034 *
00035 * This program is distributed in the hope that it will be useful,
00036 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00037 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00038 * GNU Affero General Public License for more details.
00039 *
00040 * You should have received a copy of the GNU Affero General Public License
00041 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00042 *
00043 * Consult LICENSE file for details
00044 ************************************************/
00045 include ('lib/utils/zpushadmin.php');
00046 
00047 class WebserviceDevice {
00048 
00055     public function ListDevicesDetails() {
00056         $user = Request::GetGETUser();
00057         $devices = ZPushAdmin::ListDevices($user);
00058         $output = array();
00059 
00060         ZLog::Write(LOGLEVEL_INFO, sprintf("WebserviceDevice::ListDevicesDetails(): found %d devices of user '%s'", count($devices), $user));
00061         ZPush::GetTopCollector()->AnnounceInformation(sprintf("Retrieved details of %d devices", count($devices)), true);
00062 
00063         foreach ($devices as $devid)
00064             $output[] = ZPushAdmin::GetDeviceDetails($devid, $user);
00065 
00066         return $output;
00067     }
00068 
00078     public function RemoveDevice($deviceId) {
00079         $deviceId = preg_replace("/[^A-Za-z0-9]/", "", $deviceId);
00080         ZLog::Write(LOGLEVEL_INFO, sprintf("WebserviceDevice::RemoveDevice('%s'): remove device state data of user '%s'", $deviceId, Request::GetGETUser()));
00081 
00082         if (! ZPushAdmin::RemoveDevice(Request::GetGETUser(), $deviceId)) {
00083             ZPush::GetTopCollector()->AnnounceInformation(ZLog::GetLastMessage(LOGLEVEL_ERROR), true);
00084             throw new SoapFault("ERROR", ZLog::GetLastMessage(LOGLEVEL_ERROR));
00085         }
00086 
00087         ZPush::GetTopCollector()->AnnounceInformation(sprintf("Removed device id '%s'", $deviceId), true);
00088         return true;
00089     }
00090 
00100     public function WipeDevice($deviceId) {
00101         $deviceId = preg_replace("/[^A-Za-z0-9]/", "", $deviceId);
00102         ZLog::Write(LOGLEVEL_INFO, sprintf("WebserviceDevice::WipeDevice('%s'): mark device of user '%s' for remote wipe", $deviceId, Request::GetGETUser()));
00103 
00104         if (! ZPushAdmin::WipeDevice(Request::GetAuthUser(), Request::GetGETUser(), $deviceId)) {
00105             ZPush::GetTopCollector()->AnnounceInformation(ZLog::GetLastMessage(LOGLEVEL_ERROR), true);
00106             throw new SoapFault("ERROR", ZLog::GetLastMessage(LOGLEVEL_ERROR));
00107         }
00108 
00109         ZPush::GetTopCollector()->AnnounceInformation(sprintf("Wipe requested - device id '%s'", $deviceId), true);
00110         return true;
00111     }
00112 
00122     public function ResyncDevice($deviceId) {
00123         $deviceId = preg_replace("/[^A-Za-z0-9]/", "", $deviceId);
00124         ZLog::Write(LOGLEVEL_INFO, sprintf("WebserviceDevice::ResyncDevice('%s'): mark device of user '%s' for resynchronization", $deviceId, Request::GetGETUser()));
00125 
00126         if (! ZPushAdmin::ResyncDevice(Request::GetGETUser(), $deviceId)) {
00127             ZPush::GetTopCollector()->AnnounceInformation(ZLog::GetLastMessage(LOGLEVEL_ERROR), true);
00128             throw new SoapFault("ERROR", ZLog::GetLastMessage(LOGLEVEL_ERROR));
00129         }
00130 
00131         ZPush::GetTopCollector()->AnnounceInformation(sprintf("Resync requested - device id '%s'", $deviceId), true);
00132         return true;
00133     }
00134 }
00135 ?>