From e426bd9c055c1534751a4355e88a481c5c613452 Mon Sep 17 00:00:00 2001 From: "j.faassen" Date: Thu, 2 Feb 2017 19:24:39 +0100 Subject: [PATCH 1/5] Packaging for composer / packagist --- .editorconfig | 13 ++++++++ .gitignore | 35 ++++++++++++++++++++ README.md | 6 ++-- composer.json | 28 ++++++++++++++++ example.php | 40 ---------------------- examples/example.php | 42 ++++++++++++++++++++++++ class.findmyiphone.php => src/Client.php | 37 +++++---------------- src/Device.php | 34 +++++++++++++++++++ src/Location.php | 29 ++++++++++++++++ 9 files changed, 193 insertions(+), 71 deletions(-) create mode 100644 .editorconfig create mode 100644 .gitignore create mode 100644 composer.json delete mode 100644 example.php create mode 100755 examples/example.php rename class.findmyiphone.php => src/Client.php (95%) create mode 100644 src/Device.php create mode 100644 src/Location.php diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..7187366 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +root = true + +[*] +indent_style = space +indent_size = 2 + +[*.php] +charset = utf-8 +end_of_line = lf +indent_style = tab +indent_size = 1 +insert_final_newline = true +trim_trailing_whitespace = true diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..850dc9a --- /dev/null +++ b/.gitignore @@ -0,0 +1,35 @@ +# autotune +autotune.jso + +# Managed by package managers +/vendor/ + +# Composer +/composer.phar +composer.lock + +# Mac +.DS_Store + +# Project +*.sublime-* +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio + +*.iml + +## Directory-based project format: +.idea/ +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties + +test/nginx/*.conf +!test/nginx/.gitkeep + +/.settings +.buildpath +.project +.tags +.tags1 +npm-debug.log diff --git a/README.md b/README.md index 69fc54f..abfe659 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ PHP-FindMyiPhone ================ -PHP class to locate, play sounds, and lock iOS devices +PHP package to locate, play sounds, and lock iOS devices What is the purpose? @@ -35,8 +35,8 @@ Whats the simplest piece of code to get up and running ```php printDevices(); ?> ``` diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..b0ec041 --- /dev/null +++ b/composer.json @@ -0,0 +1,28 @@ +{ + "name": "albeebe/findmyiphone", + "description": "Find My iPhone client library for PHP", + "homepage": "http://www.github.com/albeebe/PHP-FindMyiPhone", + "keywords": ["php", "iphone", "ios", "icloud", "findmyiphone"], + "type": "library", + "authors": [ + { + "name": "Al Beebe", + "email": "alan.beebe@gmail.com", + "role": "Development" + }, + { + "name": "Joost Faassen", + "email": "j.faassen@linkorb.com", + "role": "Packaging for Composer" + } + ], + "require": { + "php": ">=5.3.0" + }, + "autoload": { + "psr-4": { + "FindMyiPhone\\": "src/" + } + }, + "license": "Apache-2.0" +} diff --git a/example.php b/example.php deleted file mode 100644 index 8f38cfa..0000000 --- a/example.php +++ /dev/null @@ -1,40 +0,0 @@ -getMessage(); - exit; - } - - // This will print out all the devices on your account so you can grab the device IDs - $fmi->printDevices(); - - // Find a device that is reporting its location and attempt to get its current location - foreach ($fmi->devices as $device) { - if ($device->location->timestamp != "") { - // Locate the device - $location = $fmi->locate($device->ID); - - print "Device ".$device->ID." is located at ".$location->latitude.", ".$location->longitude.""; - - // Play a sound on the device - $fmi->playSound($device->ID, "You've been located!"); - - // Lock the device - //$fmi->lostMode($device->ID, "You got locked out", "555-555-5555"); - - break; - } - } -?> diff --git a/examples/example.php b/examples/example.php new file mode 100755 index 0000000..7d8fe37 --- /dev/null +++ b/examples/example.php @@ -0,0 +1,42 @@ +getMessage(); + exit; +} + +// This will print out all the devices on your account so you can grab the device IDs +$fmi->printDevices(); + +// Find a device that is reporting its location and attempt to get its current location +foreach ($fmi->devices as $device) { + if ($device->location->timestamp != "") { + // Locate the device + $location = $fmi->locate($device->ID); + + print "Device ".$device->ID." is located at ".$location->latitude.", ".$location->longitude.""; + + // Play a sound on the device + $fmi->playSound($device->ID, "You've been located!"); + + // Lock the device + //$fmi->lostMode($device->ID, "You got locked out", "555-555-5555"); + + break; + } +} +?> diff --git a/class.findmyiphone.php b/src/Client.php similarity index 95% rename from class.findmyiphone.php rename to src/Client.php index 8b12fc2..580046d 100644 --- a/class.findmyiphone.php +++ b/src/Client.php @@ -1,4 +1,4 @@ - "4.0", @@ -194,14 +198,14 @@ private function getDevices() { * This method takes the raw device details from the API and converts it to a FindMyiPhoneDevice object */ private function generateDevice($deviceDetails) { - $device = new FindMyiPhoneDevice(); + $device = new Device(); $device->API = $deviceDetails; $device->ID = $device->API["id"]; $device->batteryLevel = $device->API["batteryLevel"]; $device->batteryStatus = $device->API["batteryStatus"]; $device->class = $device->API["deviceClass"]; $device->displayName = $device->API["deviceDisplayName"]; - $device->location = new FindMyiPhoneLocation(); + $device->location = new Location(); $device->location->timestamp = $device->API["location"]["timeStamp"]; $device->location->horizontalAccuracy = $device->API["location"]["horizontalAccuracy"]; $device->location->positionType = $device->API["location"]["positionType"]; @@ -294,26 +298,3 @@ private function curlPOST($url, $body, $authentication = "") { return array($headers, json_decode($responseBody, true)); } } - - -class FindMyiPhoneDevice { - public $ID; - public $batteryLevel; - public $batteryStatus; - public $class; - public $displayName; - public $location; - public $model; - public $modelDisplayName; - public $name; - public $API; -} - - -class FindMyiPhoneLocation { - public $timestamp; - public $horizontalAccuracy; - public $positionType; - public $longitude; - public $latitude; -} diff --git a/src/Device.php b/src/Device.php new file mode 100644 index 0000000..eaf09e0 --- /dev/null +++ b/src/Device.php @@ -0,0 +1,34 @@ + Date: Thu, 2 Feb 2017 21:46:31 +0100 Subject: [PATCH 2/5] Make getDevices public --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 580046d..e236179 100644 --- a/src/Client.php +++ b/src/Client.php @@ -184,7 +184,7 @@ private function authenticate() { * This is where all the devices are downloaded and processed * Example: print_r($fmi->devices) */ - private function getDevices() { + public function getDevices() { $url = "https://fmipmobile.icloud.com/fmipservice/device/".$this->username."/initClient"; list($headers, $body) = $this->curlPOST($url, "", $this->username.":".$this->password); $this->devices = array(); From 0af97d10de6f91ae67ab71d100ef2832ac5d9282 Mon Sep 17 00:00:00 2001 From: "j.faassen" Date: Thu, 2 Feb 2017 21:46:56 +0100 Subject: [PATCH 3/5] Pre-apply PR#9 --- src/Client.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index e236179..5aafc88 100644 --- a/src/Client.php +++ b/src/Client.php @@ -241,7 +241,9 @@ private function curlPOST($url, $body, $authentication = "") { curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $body); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_VERBOSE, 1); + if ($this->debug) { + curl_setopt($ch, CURLOPT_VERBOSE, 1); + } curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_USERAGENT, $this->client["user-agent"]); if (strlen($authentication) > 0) { From 0bf44b43823cc5a111a757e3e7b02f0af8ae0d6d Mon Sep 17 00:00:00 2001 From: "j.faassen" Date: Thu, 2 Feb 2017 21:49:01 +0100 Subject: [PATCH 4/5] Fix PHP notices --- src/Client.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Client.php b/src/Client.php index 5aafc88..684e7e1 100644 --- a/src/Client.php +++ b/src/Client.php @@ -264,9 +264,12 @@ private function curlPOST($url, $body, $authentication = "") { if ($i === 0) $headers['http_code'] = $info["http_code"]; else { - list ($key, $value) = explode(': ', $line); - if (strlen($key) > 0) - $headers[$key] = $value; + $part = explode(': ', $line); + if (count($part)>1) { + list ($key, $value) = explode(': ', $line); + if (strlen($key) > 0) + $headers[$key] = $value; + } } } if ($this->debug) { From e5c4640fb906fc0c3709c0bceb1aa9023ff4fb4d Mon Sep 17 00:00:00 2001 From: "j.faassen" Date: Thu, 2 Feb 2017 21:53:38 +0100 Subject: [PATCH 5/5] Removed since $request is undefined --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 684e7e1..f90b1b8 100644 --- a/src/Client.php +++ b/src/Client.php @@ -250,7 +250,7 @@ private function curlPOST($url, $body, $authentication = "") { curl_setopt($ch, CURLOPT_USERPWD, $authentication); } $arrHeaders = array(); - $arrHeaders["Content-Length"] = strlen($request); + //$arrHeaders["Content-Length"] = strlen($request); foreach ($this->client["headers"] as $key=>$value) { array_push($arrHeaders, $key.": ".$value); }