Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix spacing

throw exception if there is an error during authentication or obtaiing the json
remove some left over code from the screen scrapping version that were causing php notices
  • Loading branch information...
commit 8733d5e2579f13e60d4197de5854753d3aca68c0 1 parent aefa1cb
@ablyler ablyler authored committed
Showing with 46 additions and 47 deletions.
  1. +46 −47 class.sosumi.php
View
93 class.sosumi.php
@@ -11,15 +11,15 @@
// $ssm->sendMessage(<device number>, 'Your Subject', 'Your Message');
//
- class Sosumi
- {
- public $devices;
+ class Sosumi
+ {
+ public $devices;
private $username;
private $password;
- public function __construct($mobile_me_username, $mobile_me_password)
- {
- $this->devices = array();
+ public function __construct($mobile_me_username, $mobile_me_password)
+ {
+ $this->devices = array();
$this->username = $mobile_me_username;
$this->password = $mobile_me_password;
@@ -27,6 +27,12 @@ public function __construct($mobile_me_username, $mobile_me_password)
$json_str = $this->curlPost("https://fmipmobile.me.com/fmipservice/device/$mobile_me_username/initClient", $post);
$json = json_decode($json_str);
+ if (is_null($json))
+ throw new Exception("Error parsing json string");
+
+ if (isset($json->error))
+ throw new Exception("Error from web service: '$json->error'");
+
$this->devices = array();
foreach($json->content as $json_device)
{
@@ -45,71 +51,64 @@ public function __construct($mobile_me_username, $mobile_me_password)
$device->deviceClass = $json_device->deviceClass;
$this->devices[] = $device;
}
- }
+ }
- public function locate($device_num = 0)
- {
+ public function locate($device_num = 0)
+ {
$loc = array("latitude" => $this->devices[$device_num]->latitude,
- "longitude" => $this->devices[$device_num]->longitude,
- "accuracy" => $this->devices[$device_num]->horizontalAccuracy);
+ "longitude" => $this->devices[$device_num]->longitude,
+ "accuracy" => $this->devices[$device_num]->horizontalAccuracy,
+ "timestamp" => $this->devices[$device_num]->locationTimestamp,
+ );
return $loc;
- }
+ }
- public function sendMessage($device_num = 0, $subject = 'Important Message', $msg, $alarm = false)
- {
+ public function sendMessage($device_num = 0, $subject = 'Important Message', $msg, $alarm = false)
+ {
$post = sprintf('{"clientContext":{"appName":"FindMyiPhone","appVersion":"1.0","buildVersion":"57","deviceUDID":"0000000000000000000000000000000000000000","inactiveTime":5911,"osVersion":"3.2","productType":"iPad1,1","selectedDevice":"%s","shouldLocate":false},"device":"%s","serverContext":{"callbackIntervalInMS":3000,"clientId":"0000000000000000000000000000000000000000","deviceLoadStatus":"203","hasDevices":true,"lastSessionExtensionTime":null,"maxDeviceLoadTime":60000,"maxLocatingTime":90000,"preferredLanguage":"en","prefsUpdateTime":1276872996660,"sessionLifespan":900000,"timezone":{"currentOffset":-25200000,"previousOffset":-28800000,"previousTransition":1268560799999,"tzCurrentName":"Pacific Daylight Time","tzName":"America/Los_Angeles"},"validRegion":true},"sound":%s,"subject":"%s","text":"%s"}',
$this->devices[$device_num]->id, $this->devices[$device_num]->id,
$alarm ? 'true' : 'false', $subject, $msg);
$this->curlPost("https://fmipmobile.me.com/fmipservice/device/$mobile_me_username/sendMessage", $post);
- }
+ }
- public function remoteLock($device_num = 0, $passcode)
- {
+ public function remoteLock($device_num = 0, $passcode)
+ {
$post = sprintf('{"clientContext":{"appName":"FindMyiPhone","appVersion":"1.0","buildVersion":"57","deviceUDID":"0000000000000000000000000000000000000000","inactiveTime":5911,"osVersion":"3.2","productType":"iPad1,1","selectedDevice":"%s","shouldLocate":false},"device":"%s","oldPasscode":"","passcode":"%s","serverContext":{"callbackIntervalInMS":3000,"clientId":"0000000000000000000000000000000000000000","deviceLoadStatus":"203","hasDevices":true,"lastSessionExtensionTime":null,"maxDeviceLoadTime":60000,"maxLocatingTime":90000,"preferredLanguage":"en","prefsUpdateTime":1276872996660,"sessionLifespan":900000,"timezone":{"currentOffset":-25200000,"previousOffset":-28800000,"previousTransition":1268560799999,"tzCurrentName":"Pacific Daylight Time","tzName":"America/Los_Angeles"},"validRegion":true}}',
$this->devices[$device_num]->id, $this->devices[$device_num]->id, $passcode);
$this->curlPost("https://fmipmobile.me.com/fmipservice/device/$mobile_me_username/remoteLock", $post);
- }
+ }
- public function remoteWipe()
- {
- // Remotely wiping a device is an exercise best
- // left to the reader.
- }
+ public function remoteWipe()
+ {
+ // Remotely wiping a device is an exercise best
+ // left to the reader.
+ }
- private function curlPost($url, $post_vars = null, $headers = null)
- {
- if(is_null($post_vars))
- $post_vars = '';
-
- if(!is_array($headers))
- $headers = array();
+ private function curlPost($url, $post_vars = '', $headers = array())
+ {
$headers[] = 'Authorization: Basic ' . base64_encode($this->username . ':' . $this->password);
$headers[] = 'X-Apple-Realm-Support: 1.0';
$headers[] = 'Content-Type: application/json; charset=utf-8';
$headers[] = 'X-Client-Name: Steve\'s iPad';
$headers[] = 'X-Client-Uuid: 0cf3dc491ff812adb0b202baed4f94873b210853';
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_COOKIEFILE, $this->tmpFile);
- curl_setopt($ch, CURLOPT_COOKIEJAR, $this->tmpFile);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($ch, CURLOPT_AUTOREFERER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_USERAGENT, "Find iPhone/1.0 (iPad: iPhone OS/3.2");
- if(!is_null($referer)) curl_setopt($ch, CURLOPT_REFERER, $referer);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $post_vars);
- if(!is_null($headers)) curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
-
- if($return_headers) curl_setopt($ch, CURLOPT_HEADER, true);
- // curl_setopt($ch, CURLOPT_VERBOSE, true);
+ $ch = curl_init($url);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
+ curl_setopt($ch, CURLOPT_AUTOREFERER, true);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+ curl_setopt($ch, CURLOPT_USERAGENT, "Find iPhone/1.0 (iPad: iPhone OS/3.2");
+ curl_setopt($ch, CURLOPT_POST, true);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $post_vars);
+ if(!is_null($headers)) curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
+
+ // curl_setopt($ch, CURLOPT_VERBOSE, true);
return curl_exec($ch);
- }
- }
+ }
+ }
class Device
{
Please sign in to comment.
Something went wrong with that request. Please try again.