Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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?
Expand Down Expand Up @@ -35,8 +35,8 @@ Whats the simplest piece of code to get up and running

```php
<?php
include ("class.findmyiphone.php");
$fmi = new FindMyiPhone("icloud_username", "icloud_password");
require_once __DIR__ . '/vendor/autoload.php';
$fmi = new FindMyiPhone\Client("icloud_username", "icloud_password");
$fmi->printDevices();
?>
```
28 changes: 28 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
"role": "Development"
},
{
"name": "Joost Faassen",
"email": "[email protected]",
"role": "Packaging for Composer"
}
],
"require": {
"php": ">=5.3.0"
},
"autoload": {
"psr-4": {
"FindMyiPhone\\": "src/"
}
},
"license": "Apache-2.0"
}
40 changes: 0 additions & 40 deletions example.php

This file was deleted.

42 changes: 42 additions & 0 deletions examples/example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?PHP

use FindMyiPhone\Client;

// This will prevent any errors that occur from potentially displaying your username/password
error_reporting(0);

// This should properly display device names that contain special characters
header("Content-type: text/html; charset=utf-8");

// Autoload the FindMyiPhone classes
require_once __DIR__ . '/../vendor/autoload.php';

// This is where we log in to iCloud
try {
$fmi = new Client("username_goes_here", "password_goes_here");
} catch (Exception $e) {
print "Error: ".$e->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 <B>".$device->ID."</B> is located at <I>".$location->latitude.", ".$location->longitude."</I>";

// 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;
}
}
?>
54 changes: 20 additions & 34 deletions class.findmyiphone.php → src/Client.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?PHP
<?php

/*
Copyright (C) Alan Beebe ([email protected]).
Expand All @@ -17,8 +17,12 @@
v1.0 - January 2, 2015

*/

class FindMyiPhone {

namespace FindMyiPhone;

use Exception;

class Client {

private $client = array(
"app-version" => "4.0",
Expand Down Expand Up @@ -180,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();
Expand All @@ -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"];
Expand Down Expand Up @@ -237,14 +241,16 @@ 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) {
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);
}
Expand All @@ -258,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) {
Expand Down Expand Up @@ -294,26 +303,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;
}
34 changes: 34 additions & 0 deletions src/Device.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/*
Copyright (C) Alan Beebe ([email protected]).

Licensed under the Apache License, Version 2.0 (the "License");

you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

v1.0 - January 2, 2015

*/

namespace FindMyiPhone;

class Device {
public $ID;
public $batteryLevel;
public $batteryStatus;
public $class;
public $displayName;
public $location;
public $model;
public $modelDisplayName;
public $name;
public $API;
}
29 changes: 29 additions & 0 deletions src/Location.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/*
Copyright (C) Alan Beebe ([email protected]).

Licensed under the Apache License, Version 2.0 (the "License");

you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

v1.0 - January 2, 2015

*/

namespace FindMyiPhone;

class Location {
public $timestamp;
public $horizontalAccuracy;
public $positionType;
public $longitude;
public $latitude;
}