FindMyiPhone (PHP Klasse) - Sound abspielen, Nachricht anzeigen, Location, ...

Abend Daniel!

Doch, es liegt am letzten IPS Update :slight_smile: Da wurden die Trennzeichen geändert :wink:

Um beim Beispiel von Seite 1 zu bleiben…so sieht es dann, wenn man „,“ als Trennzeichen hat:

<?
require ('findmyiphone.ips.php');

$FindMyiPhone = new FindMyiPhone('BENUTZERNAME', 'PASSWORT');  // iCloud Benutzer/Passwort eingeben
//print_r($FindMyiPhone->devices);  // Devices mit allen Infos auflisten

$longitude = $FindMyiPhone->devices[1]->location->longitude;
$longitude = str_replace(",", ".", $longitude);
$latitude = $FindMyiPhone->devices[1]->location->latitude;
$latitude = str_replace(",", ".", $latitude);

echo "Longitude = ".$longitude;
echo "Latitude = ".$latitude;

?>

…hättest du aber auch selbst hinbekommen können :wink: „str_replace“ ist ja jetzt nicht so schwer :wink:

Grüße,
Chris

Das liegt an der Umstellung auf die Ips vier, steht auch in den Änderungen, dass in der neuen PHP Version, das anders jetzt ist

Ola Chris,

mit php habe ich es nicht so! bin gelernter Elektriker und komme eigentlich nicht aus der Programmierung, dennoch arbeite ich heutzutage in diesem Bereich. :D:cool:
Deine Info warf mir den Fehler:


Fatal error:  Call to undefined function strreplace() in /var/lib/symcon/scripts/23281.ips.php on line 35

Google meinte daraufhin:


$location_longitude_punkt = str_replace(",", ".", $location_longitude);
$location_latitude_punkt = str_replace(",", ".", $location_latitude);

…und das funzte dann. :smiley:

Aber dennoch habe ich hier noch eine Idee für den ein oder anderen.
Habe mir eine String Variable erstellt. Und die beschreibe ich jedes mal wenn dieses Script ausgeführt wird.
Was ich damit meine, sollte klar sein, auch das man sich seine eigenen Orte noch eintragen muss.


// Anzeige Standort iPhone ausgwerdet
$location_longitude_2 = round($location_longitude, 2);
$location_latitude_2 = round($location_latitude, 2);
if ($location_longitude_2 == 08.15 AND $location_latitude_2 == 08.15)
	{ SetValueString(56697 /*[Apple\DK\Infos\Ort ausgewerted]*/, "Zuhause"); }
else
	{ SetValueString(56697 /*[Apple\DK\Infos\Ort ausgewerted]*/, "Ort nicht definiert."); }

PS @ Chris - alleine das raussuchen von „round“ hat mich über eine Stunde gekostet… :p:D

Ups :smiley: Ich sollte nicht nebenbei ein fieses Problem versuchen zu lösen und dann auch noch hier ein Skript posten :rolleyes: :smiley:

Aber hast Google ja gefunden :wink:

Dann noch 2 Tipps für dich:
> Thread mit viiielen Code-Beispielen aus denen man fast alles basteln kann:
IP-Symcon - Wie kann ich… 2.0

> Befasse dich ein wenig mit den Grundlagen von PHP, denn nur dann hast du auf Dauer Spaß mit IPS! Ohne PHP Grundkenntnisse ist IPS mehr Fluch als Segen! Also investiere die Zeit und du wirst sehen > es lohnt sich! :slight_smile:

Grüße,
Chris

Huhu,

habe seit heute bei Ausführung von „findmyiphone.ips.php“ diese hier:


Notice:  Undefined index: X-Apple-MMe-Host in /var/lib/symcon/scripts/findmyiphone.ips.php on line 92
Notice:  Undefined index: X-Apple-MMe-Scope in /var/lib/symcon/scripts/findmyiphone.ips.php on line 93
Notice:  Trying to get property of non-object in /var/lib/symcon/scripts/findmyiphone.ips.php on line 109
Warning:  Invalid argument supplied for foreach() in /var/lib/symcon/scripts/findmyiphone.ips.php on line 109
Notice:  Undefined offset: 0 in /var/lib/symcon/scripts/23281.ips.php on line 7

Hat jemand hier eine Idee?

Bei mir passiert seit gestern das gleiche. Habe aber leider keine Ahnung warum. :confused:

Kann ich nicht bestätigen. Läuft bei mir ganz normal. Glaube daher nicht, dass Apple etwas verändert hat.

Habe ich aktuell auch, es könnte was mit der neuen zweifach Authentifizierung zu tun haben, wer sie noch nicht aktiviert hat das Problem nicht aber nur ne Vermutung konnte es noch nicht genau anschauen.

Gesendet von iPhone mit Tapatalk

Nachdem mein Login auf iCloud.com mich nach einer PIN fragt welche an meine Apple-Geräte verschickt worden ist gehe ich mal davon aus, dass die zweifach Authentifizierung bei mir aktiv ist. :slight_smile: Die iPhone-Suche funktioniert bei mir trotzdem.

:-)) alles klaro, dann müssen wir dann jeweils bei uns suchen was anderes fällt mir auf Anhieb nicht ein;-)

Gesendet von iPhone mit Tapatalk

Es scheint sich wohl doch bei Apple etwas geändert zu haben. Siehe hier:
Updated class for more simple API url by beinnlora · Pull Request #5 · albeebe/PHP-FindMyiPhone · GitHub

Ist zwar eine andere Klasse, aber vllt schon mal eine Hilfe. Ich hab’s zwar bei mir noch nicht ans Laufen gebracht, aber vielleicht ist das trotzdem schon mal ein guter Anhaltspunkt woran es liegt. Komisch nur, dass das Problem nicht alle betrifft.

Es gabe hier in dem Thread wenn ich mich recht entsinne unterschiedliche Versionen der Sosumi-Klasse. :rolleyes:

Ich denke, ich habe die Lösung gefunden. Zumindest funktioniert es bei mir wieder mit den folgenden Änderungen:

In der Funktion init_client() die beiden Zeilen die host und scope zuweisen löschen. Stattdessen folgende Zeile einfügen:

$this->scope = $this->username;

Damit geht’s bei mir wieder. :slight_smile:

Wer nur copy&paste machen will, hier der komplette Code:


 <?php

/**
 * FindMyiPhone - A PHP class for interacting with iCloud's Find My iPhone.
 * Copyright (c) 2013 Neal <neal@ineal.me>
 */

class FindMyiPhone {

    private $username;
    private $password;

    public $devices = array();

    private $email_updates = false;

    private $host = 'fmipmobile.icloud.com';
    private $scope;

    private $client_context = array(
        'appName' => 'FindMyiPhone',
        'appVersion' => '3.0',
        'buildVersion' => '376',
        'clientTimestamp' => 0,
        'deviceUDID' => null,
        'inactiveTime' => 1,
        'osVersion' => '7.0.3',
        'productType' => 'iPhone6,1'
    );

    private $server_context = array(
        'callbackIntervalInMS' => 10000,
        'classicUser' => false,
        'clientId' => null,
        'cloudUser' => true,
        'deviceLoadStatus' => '200',
        'enableMapStats' => false,
        'isHSA' => false,
        'lastSessionExtensionTime' => null,
        'macCount' => 0,
        'maxDeviceLoadTime' => 60000,
        'maxLocatingTime' => 90000,
        'preferredLanguage' => 'en-us',
        'prefsUpdateTime' => 0,
        'sessionLifespan' => 900000,
        'timezone' => null,
        'trackInfoCacheDurationInSecs' => 86400,
        'validRegion' => true
    );


    /**
     * Constructor
     * Checks requred extensions, sets username/password and gets url host for the user.
     * @param $username - iCloud Apple ID
     * @param $password - iCloud Password
     */
    public function __construct($username, $password) {
        if (!extension_loaded('curl')) {
            throw new FindMyiPhoneException('PHP extension cURL is not loaded.');
        }

        $this->username = $username;
        $this->password = $password;

        $this->init_client();
    }


    /**
     * Set email updates
     * If false, requests will request to not send email to the user. (doesn't work on all requests)
     * True by default. (optional to set)
     * $param $email_updates - bool
     */
    public function set_email_updates($email_updates) {
        $this->email_updates = (bool) $email_updates;
    }


    /**
     * Init Client
     *
     */
    private function init_client() {
        $post_data = json_encode(array(
            'clientContext' => $this->client_context
        ));

        $headers = $this->parse_curl_headers($this->make_request('initClient', $post_data, true));

        #$this->host = $headers['X-Apple-MMe-Host'];
        #$this->scope = $headers['X-Apple-MMe-Scope'];
        $this->scope = $this->username;

        $this->refresh_client();
    }


    /**
     * Refresh Client
     *
     */
    public function refresh_client() {
        $post_data = json_encode(array(
            'clientContext' => $this->client_context,
            'serverContext' => $this->server_context
        ));

        foreach (json_decode($this->make_request('refreshClient', $post_data))->content as $id => $device) {
            $this->devices[$id] = $device;
        }
    }


    /**
     * Play Sound
     *
     */
    public function play_sound($device_id, $subject = 'Find My iPhone Alert') {
        if(!is_string($device_id)) throw new FindMyiPhoneException('Expected $device_id to be a string');
        if(!is_string($subject)) throw new FindMyiPhoneException('Expected $subject to be a string');

        $post_data = json_encode(array(
            'clientContext' => $this->client_context,
            'serverContext' => $this->server_context,
            'device' => $device_id,
            'subject' => $subject
        ));

        return json_decode($this->make_request('playSound', $post_data))->content[0]->snd;
    }


    /**
     * Send Message
     *
     */
    public function send_message($device_id, $text, $sound = false, $subject = 'Important Message') {
        if(!is_string($device_id)) throw new FindMyiPhoneException('Expected $device_id to be a string');
        if(!is_string($text)) throw new FindMyiPhoneException('Expected $text to be a string');
        if(!is_bool($sound)) throw new FindMyiPhoneException('Expected $sound to be a bool');
        if(!is_string($subject)) throw new FindMyiPhoneException('Expected $subject to be a string');

        $post_data = json_encode(array(
            'clientContext' => $this->client_context,
            'serverContext' => $this->server_context,
            'device' => $device_id,
            'emailUpdates' => $this->email_updates,
            'sound' => $sound,
            'subject' => $subject,
            'text' => $text,
            'userText' => true
        ));

        return json_decode($this->make_request('sendMessage', $post_data))->content[0]->msg;
    }


    /**
     * Lock Device
     *
     */
    public function lost_device($device_id, $passcode, $owner_phone_number = '911', $sound = true, $text = 'This iPhone has been lost. Please call me.') {
        if(!is_string($device_id)) throw new FindMyiPhoneException('Expected $device_id to be a string');
        if(!is_string($passcode)) throw new FindMyiPhoneException('Expected $passcode to be a string');
        if(strlen($passcode) !== 4) throw new FindMyiPhoneException('Expected $passcode to be 4 characters long');
        if(!is_string($owner_phone_number)) throw new FindMyiPhoneException('Expected $owner_phone_number to be a string');
        if(!is_bool($sound)) throw new FindMyiPhoneException('Expected $sound to be a bool');
        if(!is_string($text)) throw new FindMyiPhoneException('Expected $text to be a string');

        $post_data = json_encode(array(
            'clientContext' => $this->client_context,
            'serverContext' => $this->server_context,
            'device' => $device_id,
            'emailUpdates' => $this->email_updates,
            'lostModeEnabled' => true,
            'ownerNbr' => $owner_phone_number,
            'passcode' => $passcode,
            'sound' => $sound,
            'text' => $text,
            'trackingEnabled' => true,
            'userText' => true
        ));

        return json_decode($this->make_request('lostDevice', $post_data))->content[0]->lostDevice;
    }


    /**
     * Notify When Found
     *
     */
    public function notify_when_found($device_id, $notify = true) {
        if(!is_string($device_id)) throw new FindMyiPhoneException('Expected $device_id to be a string');
        if(!is_string($notify)) throw new FindMyiPhoneException('Expected $notify to be a boolean');

        $post_data = json_encode(array(
            'clientContext' => $this->client_context,
            'serverContext' => $this->server_context,
            'device' => $device_id,
            'lostModeEnabled' => $notify
        ));

        return json_decode($this->make_request('saveLocFoundPref', $post_data))->content[0]->locFoundEnabled;
    }


    /**
     * Lock and Message
     *
     */
    public function lock_and_message($device_id, $passcode, $text, $sound = true, $title = 'Find My iPhone Alert') {
        if(!is_string($device_id)) throw new FindMyiPhoneException('Expected $device_id to be a string');
        if(!is_string($passcode)) throw new FindMyiPhoneException('Expected $passcode to be a string');
        if(strlen($passcode) !== 4) throw new FindMyiPhoneException('Expected $passcode to be 4 characters long');
        if(!is_string($text)) throw new FindMyiPhoneException('Expected $text to be a string');
        if(!is_bool($sound)) throw new FindMyiPhoneException('Expected $sound to be a bool');
        if(!is_string($title)) throw new FindMyiPhoneException('Expected $title to be a string');

        $post_data = json_encode(array(
            'clientContext' => $this->client_context,
            'serverContext' => $this->server_context,
            'device' => $device_id,
            'emailUpdates' => $this->email_updates,
            'passcode' => $passcode,
            'sound' => $sound,
            'text' => $text,
            'title' => $title,
            'userText' => true
        ));

        return json_decode($this->make_request('lockAndMessage', $post_data))->content[0]->remoteLock;
    }


    /**
     * Remote Lock
     *
     */
    public function remote_lock($device_id, $passcode) {
        if(!is_string($device_id)) throw new FindMyiPhoneException('Expected $device_id to be a string');
        if(!is_string($passcode)) throw new FindMyiPhoneException('Expected $passcode to be a string');
        if(strlen($passcode) !== 4) throw new FindMyiPhoneException('Expected $passcode to be 4 characters long');

        $post_data = json_encode(array(
            'clientContext' => $this->client_context,
            'serverContext' => $this->server_context,
            'device' => $device_id,
            'emailUpdates' => $this->email_updates,
            'passcode' => $passcode
        ));

        return json_decode($this->make_request('remoteLock', $post_data))->content[0]->remoteLock;
    }


    /**
     * Remote Wipe
     *
     */
    public function remote_wipe($device_id, $passcode, $text) {
        if(!is_string($device_id)) throw new FindMyiPhoneException('Expected $device_id to be a string');
        if(!is_string($passcode)) throw new FindMyiPhoneException('Expected $passcode to be a string');
        if(strlen($passcode) !== 4) throw new FindMyiPhoneException('Expected $passcode to be 4 characters long');
        if(!is_string($text)) throw new FindMyiPhoneException('Expected $text to be a string');

        $post_data = json_encode(array(
            'clientContext' => $this->client_context,
            'serverContext' => $this->server_context,
            'device' => $device_id,
            'passcode' => $passcode,
            'text' => $text,
            'emailUpdates' => $this->email_updates
        ));

        return json_decode($this->make_request('remoteWipe', $post_data))->content[0]->remoteWipe;
    }


    /**
     * Locate Device
     *
     */
    public function locate_device($device, $timeout = 120) {
        if(!is_integer($device)) throw new FindMyiPhoneException('Expected $device to be an integer');
        if(!isset($this->devices[$device])) $this->refresh_client();

        $start = time();
        while (!$this->devices[$device]->location->locationFinished) {
            if ((time() - $start) > intval($timeout)) {
                throw new FindMyiPhoneException('Failed to locate device! Request timed out.');
            }
            sleep(5);
            $this->refresh_client();
        }

        return $this->devices[$device]->location;
    }


    /**
     * Make request to the Find My iPhone server.
     * @param $method - the method
     * @param $post_data - the POST data
     * @param $return_headers - also return headers when true
     * @param $headers - optional headers to send
     * @return HTTP response
     */
    private function make_request($method, $post_data, $return_headers = false, $headers = array()) {
        if(!is_string($method)) throw new FindMyiPhoneException('Expected $method to be a string');
        if(!$this->is_json($post_data)) throw new FindMyiPhoneException('Expected $post_data to be json');
        if(!is_array($headers)) throw new FindMyiPhoneException('Expected $headers to be an array');
        if(!is_bool($return_headers)) throw new FindMyiPhoneException('Expected $return_headers to be a bool');
        if(!isset($this->scope)) $this->scope = $this->username;

        array_push($headers, 'Accept-Language: en-us');
        array_push($headers, 'Content-Type: application/json; charset=utf-8');
        array_push($headers, 'X-Apple-Realm-Support: 1.0');
        array_push($headers, 'X-Apple-Find-Api-Ver: 3.0');
        array_push($headers, 'X-Apple-Authscheme: UserIdGuest');

        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_TIMEOUT => 9,
            CURLOPT_CONNECTTIMEOUT => 5,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_AUTOREFERER => true,
            CURLOPT_VERBOSE => false,
            CURLOPT_POST => true,
            CURLOPT_POSTFIELDS => $post_data,
            CURLOPT_HTTPHEADER => $headers,
            CURLOPT_HEADER => $return_headers,
            CURLOPT_URL => sprintf("https://%s/fmipservice/device/%s/%s", $this->host, $this->scope, $method),
            CURLOPT_USERPWD => $this->username . ':' . $this->password,
            CURLOPT_USERAGENT => 'FindMyiPhone/376 CFNetwork/672.0.8 Darwin/14.0.0'
        ));

        $http_result = curl_exec($curl);
        curl_close($curl);

        return $http_result;
    }


    /**
     * Parse cURL headers
     * @param $response - cURL response including the headers
     * @return array of headers
     */
    private function parse_curl_headers($response) {
        $headers = array();
        foreach (explode("
", substr($response, 0, strpos($response, "

"))) as $i => $line) {
            if ($i === 0) {
                $headers['http_code'] = $line;
            } else {
                list($key, $value) = explode(': ', $line);
                $headers[$key] = $value;
            }
        }
        return $headers;
    }

    /**
     * Finds whether a variable is json.
     */
    private function is_json($var) {
        json_decode($var);
        return (json_last_error() == JSON_ERROR_NONE);
    }
}

class FindMyiPhoneException extends Exception {}

?> 

Genau das ist die Lösung jop, geht auch bei mir wieder. Was neues, dass Apple mal was „vereinfacht“.

Ein DICKES Danke an dich! :cool:

…hole diesen Thread noch mal wieder hoch…:smiley:

In einer alten Version lief das bei mir auch mal, war jetzt durch Zufall wieder darauf gestossen…

Mein kurzer Test war nicht (mehr) erfolgreich. Die Code-Quelle ist auch sei Jahren nicht mehr aktualisiert worden, etwas Neuers konnte ich auch nicht finden.
Hat jemand dieses oder etwas Alternaives noch am Laufen?

Joachim

Funktioniert hier noch wie ne eins… :rolleyes:

Hallo Daniel,

magst Du hier bitte mal Deine Klasse (hier gab es wohl ein paar Änderungen?) bzw. einen beispielhaften Aufruf einstellen?:slight_smile:

Joachim

Hallo,

ich habe den Standort meines Iphone abgefragt und in eine String Variable als iframe geschrieben.
Auf dem Laptop bleibt der Bildschirm schwarz, auf dem IPAD bekomme ich eine GoogleMap mit Standort.

An was kann das liegen?

Gruß

Oliver

…vielleicht helfen ein paar mehr Details?

Joachim