[7589] | 1 | #!/usr/bin/php |
---|
| 2 | <?php |
---|
| 3 | /*********************************************** |
---|
| 4 | * File : z-push-admin.php |
---|
| 5 | * Project : Z-Push |
---|
| 6 | * Descr : This is a small command line |
---|
| 7 | * client to see and modify the |
---|
| 8 | * wipe status of Zarafa users. |
---|
| 9 | * |
---|
| 10 | * Created : 14.05.2010 |
---|
| 11 | * |
---|
| 12 | * Copyright 2007 - 2012 Zarafa Deutschland GmbH |
---|
| 13 | * |
---|
| 14 | * This program is free software: you can redistribute it and/or modify |
---|
| 15 | * it under the terms of the GNU Affero General Public License, version 3, |
---|
| 16 | * as published by the Free Software Foundation with the following additional |
---|
| 17 | * term according to sec. 7: |
---|
| 18 | * |
---|
| 19 | * According to sec. 7 of the GNU Affero General Public License, version 3, |
---|
| 20 | * the terms of the AGPL are supplemented with the following terms: |
---|
| 21 | * |
---|
| 22 | * "Zarafa" is a registered trademark of Zarafa B.V. |
---|
| 23 | * "Z-Push" is a registered trademark of Zarafa Deutschland GmbH |
---|
| 24 | * The licensing of the Program under the AGPL does not imply a trademark license. |
---|
| 25 | * Therefore any rights, title and interest in our trademarks remain entirely with us. |
---|
| 26 | * |
---|
| 27 | * However, if you propagate an unmodified version of the Program you are |
---|
| 28 | * allowed to use the term "Z-Push" to indicate that you distribute the Program. |
---|
| 29 | * Furthermore you may use our trademarks where it is necessary to indicate |
---|
| 30 | * the intended purpose of a product or service provided you use it in accordance |
---|
| 31 | * with honest practices in industrial or commercial matters. |
---|
| 32 | * If you want to propagate modified versions of the Program under the name "Z-Push", |
---|
| 33 | * you may only do so if you have a written permission by Zarafa Deutschland GmbH |
---|
| 34 | * (to acquire a permission please contact Zarafa at trademark@zarafa.com). |
---|
| 35 | * |
---|
| 36 | * This program is distributed in the hope that it will be useful, |
---|
| 37 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 38 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 39 | * GNU Affero General Public License for more details. |
---|
| 40 | * |
---|
| 41 | * You should have received a copy of the GNU Affero General Public License |
---|
| 42 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
| 43 | * |
---|
| 44 | * Consult LICENSE file for details |
---|
| 45 | ************************************************/ |
---|
| 46 | |
---|
| 47 | include('lib/core/zpushdefs.php'); |
---|
| 48 | include('lib/core/zpush.php'); |
---|
| 49 | include('lib/core/stateobject.php'); |
---|
| 50 | include('lib/core/syncparameters.php'); |
---|
| 51 | include('lib/core/bodypreference.php'); |
---|
| 52 | include('lib/core/contentparameters.php'); |
---|
| 53 | include('lib/core/synccollections.php'); |
---|
| 54 | include('lib/core/zlog.php'); |
---|
| 55 | include('lib/core/statemanager.php'); |
---|
| 56 | include('lib/core/streamer.php'); |
---|
| 57 | include('lib/core/asdevice.php'); |
---|
| 58 | include('lib/core/interprocessdata.php'); |
---|
| 59 | include('lib/core/loopdetection.php'); |
---|
| 60 | include('lib/exceptions/exceptions.php'); |
---|
| 61 | include('lib/utils/utils.php'); |
---|
| 62 | include('lib/utils/zpushadmin.php'); |
---|
| 63 | include('lib/request/request.php'); |
---|
| 64 | include('lib/request/requestprocessor.php'); |
---|
| 65 | include('lib/interface/ibackend.php'); |
---|
| 66 | include('lib/interface/ichanges.php'); |
---|
| 67 | include('lib/interface/iexportchanges.php'); |
---|
| 68 | include('lib/interface/iimportchanges.php'); |
---|
| 69 | include('lib/interface/isearchprovider.php'); |
---|
| 70 | include('lib/interface/istatemachine.php'); |
---|
| 71 | include('lib/syncobjects/syncobject.php'); |
---|
| 72 | include('lib/syncobjects/syncbasebody.php'); |
---|
| 73 | include('lib/syncobjects/syncbaseattachment.php'); |
---|
| 74 | include('lib/syncobjects/syncmailflags.php'); |
---|
| 75 | include('lib/syncobjects/syncrecurrence.php'); |
---|
| 76 | include('lib/syncobjects/syncappointment.php'); |
---|
| 77 | include('lib/syncobjects/syncappointmentexception.php'); |
---|
| 78 | include('lib/syncobjects/syncattachment.php'); |
---|
| 79 | include('lib/syncobjects/syncattendee.php'); |
---|
| 80 | include('lib/syncobjects/syncmeetingrequestrecurrence.php'); |
---|
| 81 | include('lib/syncobjects/syncmeetingrequest.php'); |
---|
| 82 | include('lib/syncobjects/syncmail.php'); |
---|
| 83 | include('lib/syncobjects/syncnote.php'); |
---|
| 84 | include('lib/syncobjects/synccontact.php'); |
---|
| 85 | include('lib/syncobjects/syncfolder.php'); |
---|
| 86 | include('lib/syncobjects/syncprovisioning.php'); |
---|
| 87 | include('lib/syncobjects/synctaskrecurrence.php'); |
---|
| 88 | include('lib/syncobjects/synctask.php'); |
---|
| 89 | include('lib/syncobjects/syncoofmessage.php'); |
---|
| 90 | include('lib/syncobjects/syncoof.php'); |
---|
| 91 | include('lib/syncobjects/syncuserinformation.php'); |
---|
| 92 | include('lib/syncobjects/syncdeviceinformation.php'); |
---|
| 93 | include('lib/syncobjects/syncdevicepassword.php'); |
---|
| 94 | include('lib/syncobjects/syncitemoperationsattachment.php'); |
---|
| 95 | include('config.php'); |
---|
| 96 | include('version.php'); |
---|
| 97 | |
---|
| 98 | /** |
---|
| 99 | * //TODO resync of single folders of a users device |
---|
| 100 | */ |
---|
| 101 | |
---|
| 102 | /************************************************ |
---|
| 103 | * MAIN |
---|
| 104 | */ |
---|
| 105 | define('BASE_PATH_CLI', dirname(__FILE__) ."/"); |
---|
| 106 | set_include_path(get_include_path() . PATH_SEPARATOR . BASE_PATH_CLI); |
---|
| 107 | try { |
---|
| 108 | ZPush::CheckConfig(); |
---|
| 109 | ZPushAdminCLI::CheckEnv(); |
---|
| 110 | ZPushAdminCLI::CheckOptions(); |
---|
| 111 | |
---|
| 112 | if (! ZPushAdminCLI::SureWhatToDo()) { |
---|
| 113 | // show error message if available |
---|
| 114 | if (ZPushAdminCLI::GetErrorMessage()) |
---|
| 115 | echo "ERROR: ". ZPushAdminCLI::GetErrorMessage() . "\n"; |
---|
| 116 | |
---|
| 117 | echo ZPushAdminCLI::UsageInstructions(); |
---|
| 118 | exit(1); |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | ZPushAdminCLI::RunCommand(); |
---|
| 122 | } |
---|
| 123 | catch (ZPushException $zpe) { |
---|
| 124 | die(get_class($zpe) . ": ". $zpe->getMessage() . "\n"); |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | |
---|
| 128 | /************************************************ |
---|
| 129 | * Z-Push-Admin CLI |
---|
| 130 | */ |
---|
| 131 | class ZPushAdminCLI { |
---|
| 132 | const COMMAND_SHOWALLDEVICES = 1; |
---|
| 133 | const COMMAND_SHOWDEVICESOFUSER = 2; |
---|
| 134 | const COMMAND_SHOWUSERSOFDEVICE = 3; |
---|
| 135 | const COMMAND_WIPEDEVICE = 4; |
---|
| 136 | const COMMAND_REMOVEDEVICE = 5; |
---|
| 137 | const COMMAND_RESYNCDEVICE = 6; |
---|
| 138 | const COMMAND_CLEARLOOP = 7; |
---|
| 139 | const COMMAND_SHOWLASTSYNC = 8; |
---|
| 140 | |
---|
| 141 | static private $command; |
---|
| 142 | static private $user = false; |
---|
| 143 | static private $device = false; |
---|
| 144 | static private $errormessage; |
---|
| 145 | |
---|
| 146 | /** |
---|
| 147 | * Returns usage instructions |
---|
| 148 | * |
---|
| 149 | * @return string |
---|
| 150 | * @access public |
---|
| 151 | */ |
---|
| 152 | static public function UsageInstructions() { |
---|
| 153 | return "Usage:\n\tz-push-admin.php -a ACTION [options]\n\n" . |
---|
| 154 | "Parameters:\n\t-a list/wipe/remove/resync/clearloop\n\t[-u] username\n\t[-d] deviceid\n\n" . |
---|
| 155 | "Actions:\n" . |
---|
| 156 | "\tlist\t\t\t\t Lists all devices and synchronized users\n" . |
---|
| 157 | "\tlist -u USER\t\t\t Lists all devices of user USER\n" . |
---|
| 158 | "\tlist -d DEVICE\t\t\t Lists all users of device DEVICE\n" . |
---|
| 159 | "\tlastsync\t\t\t Lists all devices and synchronized users and the last synchronization time\n" . |
---|
| 160 | "\twipe -u USER\t\t\t Remote wipes all devices of user USER\n" . |
---|
| 161 | "\twipe -d DEVICE\t\t\t Remote wipes device DEVICE\n" . |
---|
| 162 | "\twipe -u USER -d DEVICE\t\t Remote wipes device DEVICE of user USER\n" . |
---|
| 163 | "\tremove -u USER\t\t\t Removes all state data of all devices of user USER\n" . |
---|
| 164 | "\tremove -d DEVICE\t\t Removes all state data of all users synchronized on device DEVICE\n" . |
---|
| 165 | "\tremove -u USER -d DEVICE\t Removes all related state data of device DEVICE of user USER\n" . |
---|
| 166 | "\tresync -u USER -d DEVICE\t Resynchronizes all data of device DEVICE of user USER\n" . |
---|
| 167 | "\tclearloop\t\t\t Clears system wide loop detection data\n" . |
---|
| 168 | "\tclearloop -d DEVICE -u USER\t Clears all loop detection data of a device DEVICE and an optional user USER\n" . |
---|
| 169 | "\n"; |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | /** |
---|
| 173 | * Checks the environment |
---|
| 174 | * |
---|
| 175 | * @return |
---|
| 176 | * @access public |
---|
| 177 | */ |
---|
| 178 | static public function CheckEnv() { |
---|
| 179 | if (!isset($_SERVER["TERM"]) || !isset($_SERVER["LOGNAME"])) |
---|
| 180 | self::$errormessage = "This script should not be called in a browser."; |
---|
| 181 | |
---|
| 182 | if (!function_exists("getopt")) |
---|
| 183 | self::$errormessage = "PHP Function getopt not found. Please check your PHP version and settings."; |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | /** |
---|
| 187 | * Checks the options from the command line |
---|
| 188 | * |
---|
| 189 | * @return |
---|
| 190 | * @access public |
---|
| 191 | */ |
---|
| 192 | static public function CheckOptions() { |
---|
| 193 | if (self::$errormessage) |
---|
| 194 | return; |
---|
| 195 | |
---|
| 196 | $options = getopt("u:d:a:"); |
---|
| 197 | |
---|
| 198 | // get 'user' |
---|
| 199 | if (isset($options['u']) && !empty($options['u'])) |
---|
| 200 | self::$user = strtolower(trim($options['u'])); |
---|
| 201 | else if (isset($options['user']) && !empty($options['user'])) |
---|
| 202 | self::$user = strtolower(trim($options['user'])); |
---|
| 203 | |
---|
| 204 | // get 'device' |
---|
| 205 | if (isset($options['d']) && !empty($options['d'])) |
---|
| 206 | self::$device = trim($options['d']); |
---|
| 207 | else if (isset($options['device']) && !empty($options['device'])) |
---|
| 208 | self::$device = trim($options['device']); |
---|
| 209 | |
---|
| 210 | // get 'action' |
---|
| 211 | $action = false; |
---|
| 212 | if (isset($options['a']) && !empty($options['a'])) |
---|
| 213 | $action = strtolower(trim($options['a'])); |
---|
| 214 | elseif (isset($options['action']) && !empty($options['action'])) |
---|
| 215 | $action = strtolower(trim($options['action'])); |
---|
| 216 | |
---|
| 217 | // get a command for the requested action |
---|
| 218 | switch ($action) { |
---|
| 219 | // list data |
---|
| 220 | case "list": |
---|
| 221 | if (self::$user === false && self::$device === false) |
---|
| 222 | self::$command = self::COMMAND_SHOWALLDEVICES; |
---|
| 223 | |
---|
| 224 | if (self::$user !== false) |
---|
| 225 | self::$command = self::COMMAND_SHOWDEVICESOFUSER; |
---|
| 226 | |
---|
| 227 | if (self::$device !== false) |
---|
| 228 | self::$command = self::COMMAND_SHOWUSERSOFDEVICE; |
---|
| 229 | break; |
---|
| 230 | |
---|
| 231 | // list data |
---|
| 232 | case "lastsync": |
---|
| 233 | self::$command = self::COMMAND_SHOWLASTSYNC; |
---|
| 234 | break; |
---|
| 235 | |
---|
| 236 | // remove wipe device |
---|
| 237 | case "wipe": |
---|
| 238 | if (self::$user === false && self::$device === false) |
---|
| 239 | self::$errormessage = "Not possible to execute remote wipe. Device, user or both must be specified."; |
---|
| 240 | else |
---|
| 241 | self::$command = self::COMMAND_WIPEDEVICE; |
---|
| 242 | break; |
---|
| 243 | |
---|
| 244 | // remove device data of user |
---|
| 245 | case "remove": |
---|
| 246 | if (self::$user === false && self::$device === false) |
---|
| 247 | self::$errormessage = "Not possible to remove data. Device, user or both must be specified."; |
---|
| 248 | else |
---|
| 249 | self::$command = self::COMMAND_REMOVEDEVICE; |
---|
| 250 | break; |
---|
| 251 | |
---|
| 252 | // resync a device |
---|
| 253 | case "resync": |
---|
| 254 | case "re-sync": |
---|
| 255 | case "sync": |
---|
| 256 | case "resynchronize": |
---|
| 257 | case "re-synchronize": |
---|
| 258 | case "synchronize": |
---|
| 259 | if (self::$user === false || self::$device === false) |
---|
| 260 | self::$errormessage = "Not possible to resynchronize device. Device and user must be specified."; |
---|
| 261 | else |
---|
| 262 | self::$command = self::COMMAND_RESYNCDEVICE; |
---|
| 263 | break; |
---|
| 264 | |
---|
| 265 | // clear loop detection data |
---|
| 266 | case "clearloop": |
---|
| 267 | case "clearloopdetection": |
---|
| 268 | self::$command = self::COMMAND_CLEARLOOP; |
---|
| 269 | break; |
---|
| 270 | |
---|
| 271 | |
---|
| 272 | default: |
---|
| 273 | self::UsageInstructions(); |
---|
| 274 | } |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | /** |
---|
| 278 | * Indicates if the options from the command line |
---|
| 279 | * could be processed correctly |
---|
| 280 | * |
---|
| 281 | * @return boolean |
---|
| 282 | * @access public |
---|
| 283 | */ |
---|
| 284 | static public function SureWhatToDo() { |
---|
| 285 | return isset(self::$command); |
---|
| 286 | } |
---|
| 287 | |
---|
| 288 | /** |
---|
| 289 | * Returns a errormessage of things which could have gone wrong |
---|
| 290 | * |
---|
| 291 | * @return string |
---|
| 292 | * @access public |
---|
| 293 | */ |
---|
| 294 | static public function GetErrorMessage() { |
---|
| 295 | return (isset(self::$errormessage))?self::$errormessage:""; |
---|
| 296 | } |
---|
| 297 | |
---|
| 298 | /** |
---|
| 299 | * Runs a command requested from an action of the command line |
---|
| 300 | * |
---|
| 301 | * @return |
---|
| 302 | * @access public |
---|
| 303 | */ |
---|
| 304 | static public function RunCommand() { |
---|
| 305 | echo "\n"; |
---|
| 306 | switch(self::$command) { |
---|
| 307 | case self::COMMAND_SHOWALLDEVICES: |
---|
| 308 | self::CommandShowDevices(); |
---|
| 309 | break; |
---|
| 310 | |
---|
| 311 | case self::COMMAND_SHOWDEVICESOFUSER: |
---|
| 312 | self::CommandShowDevices(); |
---|
| 313 | break; |
---|
| 314 | |
---|
| 315 | case self::COMMAND_SHOWUSERSOFDEVICE: |
---|
| 316 | self::CommandDeviceUsers(); |
---|
| 317 | break; |
---|
| 318 | |
---|
| 319 | case self::COMMAND_SHOWLASTSYNC: |
---|
| 320 | self::CommandShowLastSync(); |
---|
| 321 | break; |
---|
| 322 | |
---|
| 323 | case self::COMMAND_WIPEDEVICE: |
---|
| 324 | if (self::$device) |
---|
| 325 | echo sprintf("Are you sure you want to REMOTE WIPE device '%s' [y/N]: ", self::$device); |
---|
| 326 | else |
---|
| 327 | echo sprintf("Are you sure you want to REMOTE WIPE all devices of user '%s' [y/N]: ", self::$user); |
---|
| 328 | |
---|
| 329 | $confirm = strtolower(trim(fgets(STDIN))); |
---|
| 330 | if ( $confirm === 'y' || $confirm === 'yes') |
---|
| 331 | self::CommandWipeDevice(); |
---|
| 332 | else |
---|
| 333 | echo "Aborted!\n"; |
---|
| 334 | break; |
---|
| 335 | |
---|
| 336 | case self::COMMAND_REMOVEDEVICE: |
---|
| 337 | self::CommandRemoveDevice(); |
---|
| 338 | break; |
---|
| 339 | |
---|
| 340 | case self::COMMAND_RESYNCDEVICE: |
---|
| 341 | if (self::$device == false) { |
---|
| 342 | echo sprintf("Are you sure you want to re-synchronize all devices of user '%s' [y/N]: ", self::$user); |
---|
| 343 | $confirm = strtolower(trim(fgets(STDIN))); |
---|
| 344 | if ( !($confirm === 'y' || $confirm === 'yes')) |
---|
| 345 | echo "Aborted!\n"; |
---|
| 346 | exit(1); |
---|
| 347 | } |
---|
| 348 | self::CommandResyncDevices(); |
---|
| 349 | break; |
---|
| 350 | |
---|
| 351 | case self::COMMAND_CLEARLOOP: |
---|
| 352 | self::CommandClearLoopDetectionData(); |
---|
| 353 | break; |
---|
| 354 | } |
---|
| 355 | echo "\n"; |
---|
| 356 | } |
---|
| 357 | |
---|
| 358 | /** |
---|
| 359 | * Command "Show all devices" and "Show devices of user" |
---|
| 360 | * Prints the device id of/and connected users |
---|
| 361 | * |
---|
| 362 | * @return |
---|
| 363 | * @access public |
---|
| 364 | */ |
---|
| 365 | static public function CommandShowDevices() { |
---|
| 366 | $devicelist = ZPushAdmin::ListDevices(self::$user); |
---|
| 367 | if (empty($devicelist)) |
---|
| 368 | echo "\tno devices found\n"; |
---|
| 369 | else { |
---|
| 370 | if (self::$user === false) { |
---|
| 371 | echo "All synchronized devices\n\n"; |
---|
| 372 | echo str_pad("Device id", 36). "Synchronized users\n"; |
---|
| 373 | echo "-----------------------------------------------------\n"; |
---|
| 374 | } |
---|
| 375 | else |
---|
| 376 | echo "Synchronized devices of user: ". self::$user. "\n"; |
---|
| 377 | } |
---|
| 378 | |
---|
| 379 | foreach ($devicelist as $deviceId) { |
---|
| 380 | if (self::$user === false) { |
---|
| 381 | echo str_pad($deviceId, 36) . implode (",", ZPushAdmin::ListUsers($deviceId)) ."\n"; |
---|
| 382 | } |
---|
| 383 | else |
---|
| 384 | self::printDeviceData($deviceId, self::$user); |
---|
| 385 | } |
---|
| 386 | } |
---|
| 387 | |
---|
| 388 | /** |
---|
| 389 | * Command "Show all devices and users with last sync time" |
---|
| 390 | * Prints the device id of/and connected users |
---|
| 391 | * |
---|
| 392 | * @return |
---|
| 393 | * @access public |
---|
| 394 | */ |
---|
| 395 | static public function CommandShowLastSync() { |
---|
| 396 | $devicelist = ZPushAdmin::ListDevices(false); |
---|
| 397 | if (empty($devicelist)) |
---|
| 398 | echo "\tno devices found\n"; |
---|
| 399 | else { |
---|
| 400 | echo "All known devices and users and their last synchronization time\n\n"; |
---|
| 401 | echo str_pad("Device id", 36). str_pad("Synchronized user", 30)."Last sync time\n"; |
---|
| 402 | echo "-----------------------------------------------------------------------------------------------------\n"; |
---|
| 403 | } |
---|
| 404 | |
---|
| 405 | foreach ($devicelist as $deviceId) { |
---|
| 406 | $users = ZPushAdmin::ListUsers($deviceId); |
---|
| 407 | foreach ($users as $user) { |
---|
| 408 | $device = ZPushAdmin::GetDeviceDetails($deviceId, $user); |
---|
| 409 | echo str_pad($deviceId, 36) . str_pad($user, 30). ($device->GetLastSyncTime() ? strftime("%Y-%m-%d %H:%M", $device->GetLastSyncTime()) : "never") . "\n"; |
---|
| 410 | } |
---|
| 411 | } |
---|
| 412 | } |
---|
| 413 | |
---|
| 414 | /** |
---|
| 415 | * Command "Show users of device" |
---|
| 416 | * Prints informations about all users which use a device |
---|
| 417 | * |
---|
| 418 | * @return |
---|
| 419 | * @access public |
---|
| 420 | */ |
---|
| 421 | static public function CommandDeviceUsers() { |
---|
| 422 | $users = ZPushAdmin::ListUsers(self::$device); |
---|
| 423 | |
---|
| 424 | if (empty($users)) |
---|
| 425 | echo "\tno user data synchronized to device\n"; |
---|
| 426 | |
---|
| 427 | foreach ($users as $user) { |
---|
| 428 | echo "Synchronized by user: ". $user. "\n"; |
---|
| 429 | self::printDeviceData(self::$device, $user); |
---|
| 430 | } |
---|
| 431 | } |
---|
| 432 | |
---|
| 433 | /** |
---|
| 434 | * Command "Wipe device" |
---|
| 435 | * Marks a device of that user to be remotely wiped |
---|
| 436 | * |
---|
| 437 | * @return |
---|
| 438 | * @access public |
---|
| 439 | */ |
---|
| 440 | static public function CommandWipeDevice() { |
---|
| 441 | $stat = ZPushAdmin::WipeDevice($_SERVER["LOGNAME"], self::$user, self::$device); |
---|
| 442 | |
---|
| 443 | if (self::$user !== false && self::$device !== false) { |
---|
| 444 | echo sprintf("Mark device '%s' of user '%s' to be wiped: %s", self::$device, self::$user, ($stat)?'OK':ZLog::GetLastMessage(LOGLEVEL_ERROR)). "\n"; |
---|
| 445 | |
---|
| 446 | if ($stat) { |
---|
| 447 | echo "Updated information about this device:\n"; |
---|
| 448 | self::printDeviceData(self::$device, self::$user); |
---|
| 449 | } |
---|
| 450 | } |
---|
| 451 | elseif (self::$user !== false) { |
---|
| 452 | echo sprintf("Mark devices of user '%s' to be wiped: %s", self::$user, ($stat)?'OK':ZLog::GetLastMessage(LOGLEVEL_ERROR)). "\n"; |
---|
| 453 | self::CommandShowDevices(); |
---|
| 454 | } |
---|
| 455 | } |
---|
| 456 | |
---|
| 457 | /** |
---|
| 458 | * Command "Remove device" |
---|
| 459 | * Remove a device of that user from the device list |
---|
| 460 | * |
---|
| 461 | * @return |
---|
| 462 | * @access public |
---|
| 463 | */ |
---|
| 464 | static public function CommandRemoveDevice() { |
---|
| 465 | $stat = ZPushAdmin::RemoveDevice(self::$user, self::$device); |
---|
| 466 | if (self::$user === false) |
---|
| 467 | echo sprintf("State data of device '%s' removed: %s", self::$device, ($stat)?'OK':ZLog::GetLastMessage(LOGLEVEL_ERROR)). "\n"; |
---|
| 468 | elseif (self::$device === false) |
---|
| 469 | echo sprintf("State data of all devices of user '%s' removed: %s", self::$user, ($stat)?'OK':ZLog::GetLastMessage(LOGLEVEL_ERROR)). "\n"; |
---|
| 470 | else |
---|
| 471 | echo sprintf("State data of device '%s' of user '%s' removed: %s", self::$device, self::$user, ($stat)?'OK':ZLog::GetLastMessage(LOGLEVEL_ERROR)). "\n"; |
---|
| 472 | } |
---|
| 473 | |
---|
| 474 | /** |
---|
| 475 | * Command "Resync device(s)" |
---|
| 476 | * Resyncs one or all devices of that user |
---|
| 477 | * |
---|
| 478 | * @return |
---|
| 479 | * @access public |
---|
| 480 | */ |
---|
| 481 | static public function CommandResyncDevices() { |
---|
| 482 | $stat = ZPushAdmin::ResyncDevice(self::$user, self::$device); |
---|
| 483 | echo sprintf("Resync of device '%s' of user '%s': %s", self::$device, self::$user, ($stat)?'Requested':ZLog::GetLastMessage(LOGLEVEL_ERROR)). "\n"; |
---|
| 484 | } |
---|
| 485 | |
---|
| 486 | static public function CommandClearLoopDetectionData() { |
---|
| 487 | $stat = false; |
---|
| 488 | $stat = ZPushAdmin::ClearLoopDetectionData(self::$user, self::$device); |
---|
| 489 | if (self::$user === false && self::$device === false) |
---|
| 490 | echo sprintf("System wide loop detection data removed: %s", ($stat)?'OK':ZLog::GetLastMessage(LOGLEVEL_ERROR)). "\n"; |
---|
| 491 | elseif (self::$user === false) |
---|
| 492 | echo sprintf("Loop detection data of device '%s' removed: %s", self::$device, ($stat)?'OK':ZLog::GetLastMessage(LOGLEVEL_ERROR)). "\n"; |
---|
| 493 | elseif (self::$device === false && self::$user !== false) |
---|
| 494 | echo sprintf("Error: %s", ($stat)?'OK':ZLog::GetLastMessage(LOGLEVEL_WARN)). "\n"; |
---|
| 495 | else |
---|
| 496 | echo sprintf("Loop detection data of device '%s' of user '%s' removed: %s", self::$device, self::$user, ($stat)?'OK':ZLog::GetLastMessage(LOGLEVEL_ERROR)). "\n"; |
---|
| 497 | } |
---|
| 498 | |
---|
| 499 | /** |
---|
| 500 | * Prints detailed informations about a device |
---|
| 501 | * |
---|
| 502 | * @param string $deviceId the id of the device |
---|
| 503 | * |
---|
| 504 | * @return |
---|
| 505 | * @access private |
---|
| 506 | */ |
---|
| 507 | static private function printDeviceData($deviceId, $user) { |
---|
| 508 | $device = ZPushAdmin::GetDeviceDetails($deviceId, $user); |
---|
| 509 | |
---|
| 510 | if (! $device instanceof ASDevice) |
---|
| 511 | return false; |
---|
| 512 | |
---|
| 513 | // Gather some statistics about synchronized folders |
---|
| 514 | $folders = $device->GetAllFolderIds(); |
---|
| 515 | $synchedFolders = 0; |
---|
| 516 | $synchedFolderTypes = array(); |
---|
| 517 | foreach ($folders as $folderid) { |
---|
| 518 | if ($device->GetFolderUUID($folderid)) { |
---|
| 519 | $synchedFolders++; |
---|
| 520 | $type = $device->GetFolderType($folderid); |
---|
| 521 | switch($type) { |
---|
| 522 | case SYNC_FOLDER_TYPE_APPOINTMENT: |
---|
| 523 | case SYNC_FOLDER_TYPE_USER_APPOINTMENT: |
---|
| 524 | $gentype = "Calendars"; |
---|
| 525 | break; |
---|
| 526 | case SYNC_FOLDER_TYPE_CONTACT: |
---|
| 527 | case SYNC_FOLDER_TYPE_USER_CONTACT: |
---|
| 528 | $gentype = "Contacts"; |
---|
| 529 | break; |
---|
| 530 | case SYNC_FOLDER_TYPE_TASK: |
---|
| 531 | case SYNC_FOLDER_TYPE_USER_TASK: |
---|
| 532 | $gentype = "Tasks"; |
---|
| 533 | break; |
---|
| 534 | case SYNC_FOLDER_TYPE_NOTE: |
---|
| 535 | case SYNC_FOLDER_TYPE_USER_NOTE: |
---|
| 536 | $gentype = "Notes"; |
---|
| 537 | break; |
---|
| 538 | default: |
---|
| 539 | $gentype = "Emails"; |
---|
| 540 | break; |
---|
| 541 | } |
---|
| 542 | if (!isset($synchedFolderTypes[$gentype])) |
---|
| 543 | $synchedFolderTypes[$gentype] = 0; |
---|
| 544 | $synchedFolderTypes[$gentype]++; |
---|
| 545 | } |
---|
| 546 | } |
---|
| 547 | $folderinfo = ""; |
---|
| 548 | foreach ($synchedFolderTypes as $gentype=>$count) { |
---|
| 549 | $folderinfo .= $gentype; |
---|
| 550 | if ($count>1) $folderinfo .= "($count)"; |
---|
| 551 | $folderinfo .= " "; |
---|
| 552 | } |
---|
| 553 | if (!$folderinfo) $folderinfo = "None available"; |
---|
| 554 | |
---|
| 555 | echo "-----------------------------------------------------\n"; |
---|
| 556 | echo "DeviceId:\t\t$deviceId\n"; |
---|
| 557 | echo "Device type:\t\t". ($device->GetDeviceType() !== ASDevice::UNDEFINED ? $device->GetDeviceType() : "unknown") ."\n"; |
---|
| 558 | echo "UserAgent:\t\t".($device->GetDeviceUserAgent()!== ASDevice::UNDEFINED ? $device->GetDeviceUserAgent() : "unknown") ."\n"; |
---|
| 559 | // TODO implement $device->GetDeviceUserAgentHistory() |
---|
| 560 | |
---|
| 561 | // device information transmitted during Settings command |
---|
| 562 | if ($device->GetDeviceModel()) |
---|
| 563 | echo "Device Model:\t\t". $device->GetDeviceModel(). "\n"; |
---|
| 564 | if ($device->GetDeviceIMEI()) |
---|
| 565 | echo "Device IMEI:\t\t". $device->GetDeviceIMEI(). "\n"; |
---|
| 566 | if ($device->GetDeviceFriendlyName()) |
---|
| 567 | echo "Device friendly name:\t". $device->GetDeviceFriendlyName(). "\n"; |
---|
| 568 | if ($device->GetDeviceOS()) |
---|
| 569 | echo "Device OS:\t\t". $device->GetDeviceOS(). "\n"; |
---|
| 570 | if ($device->GetDeviceOSLanguage()) |
---|
| 571 | echo "Device OS Language:\t". $device->GetDeviceOSLanguage(). "\n"; |
---|
| 572 | if ($device->GetDevicePhoneNumber()) |
---|
| 573 | echo "Device Phone nr:\t". $device->GetDevicePhoneNumber(). "\n"; |
---|
| 574 | if ($device->GetDeviceMobileOperator()) |
---|
| 575 | echo "Device Operator:\t\t". $device->GetDeviceMobileOperator(). "\n"; |
---|
| 576 | if ($device->GetDeviceEnableOutboundSMS()) |
---|
| 577 | echo "Device Outbound SMS:\t". $device->GetDeviceEnableOutboundSMS(). "\n"; |
---|
| 578 | |
---|
| 579 | echo "ActiveSync version:\t".($device->GetASVersion() ? $device->GetASVersion() : "unknown") ."\n"; |
---|
| 580 | echo "First sync:\t\t". strftime("%Y-%m-%d %H:%M", $device->GetFirstSyncTime()) ."\n"; |
---|
| 581 | echo "Last sync:\t\t". ($device->GetLastSyncTime() ? strftime("%Y-%m-%d %H:%M", $device->GetLastSyncTime()) : "never")."\n"; |
---|
| 582 | echo "Total folders:\t\t". count($folders). "\n"; |
---|
| 583 | echo "Synchronized folders:\t". $synchedFolders . "\n"; |
---|
| 584 | echo "Synchronized data:\t$folderinfo\n"; |
---|
| 585 | echo "Status:\t\t\t"; |
---|
| 586 | switch ($device->GetWipeStatus()) { |
---|
| 587 | case SYNC_PROVISION_RWSTATUS_OK: |
---|
| 588 | echo "OK\n"; |
---|
| 589 | break; |
---|
| 590 | case SYNC_PROVISION_RWSTATUS_PENDING: |
---|
| 591 | echo "Pending wipe\n"; |
---|
| 592 | break; |
---|
| 593 | case SYNC_PROVISION_RWSTATUS_REQUESTED: |
---|
| 594 | echo "Wipe requested on device\n"; |
---|
| 595 | break; |
---|
| 596 | case SYNC_PROVISION_RWSTATUS_WIPED: |
---|
| 597 | echo "Wiped\n"; |
---|
| 598 | break; |
---|
| 599 | default: |
---|
| 600 | echo "Not available\n"; |
---|
| 601 | break; |
---|
| 602 | } |
---|
| 603 | |
---|
| 604 | echo "WipeRequest on:\t\t". ($device->GetWipeRequestedOn() ? strftime("%Y-%m-%d %H:%M", $device->GetWipeRequestedOn()) : "not set")."\n"; |
---|
| 605 | echo "WipeRequest by:\t\t". ($device->GetWipeRequestedBy() ? $device->GetWipeRequestedBy() : "not set")."\n"; |
---|
| 606 | echo "Wiped on:\t\t". ($device->GetWipeActionOn() ? strftime("%Y-%m-%d %H:%M", $device->GetWipeActionOn()) : "not set")."\n"; |
---|
| 607 | |
---|
| 608 | echo "Attention needed:\t"; |
---|
| 609 | |
---|
| 610 | if ($device->GetDeviceError()) |
---|
| 611 | echo $device->GetDeviceError() ."\n"; |
---|
| 612 | else if (!isset($device->ignoredmessages) || empty($device->ignoredmessages)) { |
---|
| 613 | echo "No errors known\n"; |
---|
| 614 | } |
---|
| 615 | else { |
---|
| 616 | printf("%d messages need attention because they could not be synchronized\n", count($device->ignoredmessages)); |
---|
| 617 | foreach ($device->ignoredmessages as $im) { |
---|
| 618 | $info = ""; |
---|
| 619 | if (isset($im->asobject->subject)) |
---|
| 620 | $info .= sprintf("Subject: '%s'", $im->asobject->subject); |
---|
| 621 | if (isset($im->asobject->fileas)) |
---|
| 622 | $info .= sprintf("FileAs: '%s'", $im->asobject->fileas); |
---|
| 623 | if (isset($im->asobject->from)) |
---|
| 624 | $info .= sprintf(" - From: '%s'", $im->asobject->from); |
---|
| 625 | if (isset($im->asobject->starttime)) |
---|
| 626 | $info .= sprintf(" - On: '%s'", strftime("%Y-%m-%d %H:%M", $im->asobject->starttime)); |
---|
| 627 | $reason = $im->reasonstring; |
---|
| 628 | if ($im->reasoncode == 2) |
---|
| 629 | $reason = "Message was causing loop"; |
---|
| 630 | printf("\tBroken object:\t'%s' ignored on '%s'\n", $im->asclass, strftime("%Y-%m-%d %H:%M", $im->timestamp)); |
---|
| 631 | printf("\tInformation:\t%s\n", $info); |
---|
| 632 | printf("\tReason: \t%s (%s)\n", $reason, $im->reasoncode); |
---|
| 633 | printf("\tItem/Parent id: %s/%s\n", $im->id, $im->folderid); |
---|
| 634 | echo "\n"; |
---|
| 635 | } |
---|
| 636 | } |
---|
| 637 | |
---|
| 638 | } |
---|
| 639 | } |
---|
| 640 | |
---|
| 641 | |
---|
| 642 | ?> |
---|