Sosumi - Find my iPhone

Unter anderem auch ein iphone 5 mit 7.0.4. Zum 5S kann ich nichts sagen weil im Fuhrpark nicht vorhanden.

ok, dann liegt der Fehler bei mir. Kannst Du mir zur Sicherheit Deine aktuelle Sosumi Klasse mal posten?

Nu gerne. Nachdem der Thread aber mittlerweile doch etwas unübersichtlich geworden ist kann ich Dir nicht sagen ob meine Klasse zu Deinem Skript passt.

Versuch macht kluch:


<?PHP
	// https://twitter.com/#!/marcoarment/status/59089853433921537
	//date_default_timezone_set('America/Los_Angeles');


    // Sosumi - a PHP client for Apple's Find My iPhone web service
    //
    // June 20, 2010
    // Tyler Hall <tylerhall@gmail.com>
    // http://github.com/tylerhall/sosumi/tree/master
    //
    // Usage:
    // $ssm = new Sosumi('username', 'password');
    // $location_info = $ssm->locate(<device number>);
    // $ssm->sendMessage('Your Message', true, <device number>, 'Important Message');
    //

    class Sosumi
    {
		public $devices;
		public $debug;
		private $username;
		private $password;
		private $partition;
		private $startdate;

        public function __construct($mobile_me_username, $mobile_me_password, $debug = false)
        {
            $this->devices  = array();
            $this->debug    = $debug;
            $this->username = $mobile_me_username;
            $this->password = $mobile_me_password;
				$this->startdate = time();
            $this->getPartition();
            $this->updateDevices();
        }

        private function getPartition()
        {
            $this->iflog('Getting partition...');
            $post = '{"clientContext":{"appName":"FindMyiPhone","appVersion":"1.4","buildVersion":"145","deviceUDID":"0000000000000000000000000000000000000000","inactiveTime":2147483647,"osVersion":"4.2.1","personID":0,"productType":"iPad1,1"}}';
            $response = $this->curlPost("/fmipservice/device/{$this->username}/initClient", $post, array(), true);
            preg_match('/MMe-Host:(.*?)$/msi', $response, $matches);
            $test = $this->partition = trim($matches[1]);
            //print_r($test);
        }

        public function locate($device_id, $max_wait = 30)
        {
            $start = $this->startdate;

			do
				{
				// Alle gefundenen Devices nach der device_num durchsuchen
				// Index device_no zurückgeben (0, 1, ..)
				$found = false;
				foreach($this->devices as $device_num => $device) {
				   if ($device->id == $device_id) { $found = true; break; }
				   }

				// Gefunden, dann nach timestamp entscheiden, ob aktuell genug
				if ($found)
					if ($this->devices[$device_num]->locationTimestamp > $start)
					   break;

				// Timer abgelaufen, false zurueckgeben
				if((time() - $start) > $max_wait)
					return false;

				// Warten und nochmal suchen
				sleep(5);
				$this->updateDevices();

			} while (true);

				// Hier gefunden
            $loc = array(
                        "latitude"  => $this->devices[$device_num]->latitude,
                        "longitude" => $this->devices[$device_num]->longitude,
                        "accuracy"  => $this->devices[$device_num]->horizontalAccuracy,
                        "timestamp" => $this->devices[$device_num]->locationTimestamp,
                        "name"      => $this->devices[$device_num]->name,
                        "charging"  => $this->devices[$device_num]->chargingStatus,
                        "battlevel" => $this->devices[$device_num]->batteryLevel,
                        "status"	   => $this->devices[$device_num]->deviceStatus
                        );
            return $loc;
        }

        public function sendMessage($msg, $alarm = false, $device_num = 0, $subject = 'Important Message')
        {
            $post = sprintf('{"clientContext":{"appName":"FindMyiPhone","appVersion":"1.4","buildVersion":"145","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->iflog('Sending message...');
            $this->curlPost("/fmipservice/device/{$this->username}/sendMessage", $post);
            $this->iflog('Message sent');
        }

        public function remoteLock($passcode, $device_num = 0)
        {
            $post = sprintf('{"clientContext":{"appName":"FindMyiPhone","appVersion":"1.4","buildVersion":"145","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->iflog('Sending remote lock...');
            $this->curlPost("/fmipservice/device/{$this->username}/remoteLock", $post);
            $this->iflog('Remote lock sent');
        }

        // This hasn't been tested (for obvious reasons). Please let me know if it does/doesn't work...
        public function remoteWipe($device_num = 0)
        {
            $post = sprintf('{"clientContext":{"appName":"FindMyiPhone","appVersion":"1.4","buildVersion":"145","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->iflog('Sending remote wipe...');
            $this->curlPost("/fmipservice/device/{$this->username}/remoteWipe", $post);
            $this->iflog('Remote wipe sent');
        }

        private function updateDevices()
        {
            $this->iflog('updateDevices...');
            $post = '{"clientContext":{"appName":"FindMyiPhone","appVersion":"1.4","buildVersion":"145","deviceUDID":"0000000000000000000000000000000000000000","inactiveTime":2147483647,"osVersion":"4.2.1","personID":0,"productType":"iPad1,1"}}';
            $json_str = $this->curlPost("/fmipservice/device/{$this->username}/initClient", $post);
            $this->iflog('updateDevices Returned: ' . $json_str);
            $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();
            $this->iflog('Parsing ' . count($json->content) . ' devices ...');
            foreach($json->content as $json_device)
            {
                $device = new SosumiDevice();
                if(isset($json_device->location) && is_object($json_device->location))
                {
                  $device->located            = true;
						$device->locationTimestamp  = $json_device->location->timeStamp / 1000;
						$device->locationType       = $json_device->location->positionType;
						$device->horizontalAccuracy = $json_device->location->horizontalAccuracy;
						$device->locationFinished   = $json_device->location->locationFinished;
						$device->longitude          = $json_device->location->longitude;
						$device->latitude           = $json_device->location->latitude;
                }
					else
						$device->located        = false;

                $device->isLocating     = $json_device->isLocating;
                $device->deviceModel    = $json_device->deviceModel;
                $device->deviceStatus   = $json_device->deviceStatus;
                $device->id             = $json_device->id;
                $device->name           = $json_device->name;
                $device->deviceClass    = $json_device->deviceClass;
					 //Ursprünglich im Originalskript beinhaltet:
					 //$device->chargingStatus = $json_device->a;
                //$device->batteryLevel   = $json_device->b;
					 //Neu eingebaut am 19.5.2012 von Forenmitglied fischeor
					 $device->chargingStatus = $json_device->batteryStatus;
					 $device->batteryLevel   = $json_device->batteryLevel;
                $this->devices[]        = $device;
                //print_r($json_device);
            }
				return;
        }

        public function listDevices()
        {
            $this->iflog('listDevices...');
            $post = '{"clientContext":{"appName":"FindMyiPhone","appVersion":"1.4","buildVersion":"145","deviceUDID":"0000000000000000000000000000000000000000","inactiveTime":2147483647,"osVersion":"4.2.1","personID":0,"productType":"iPad1,1"}}';
            $json_str = $this->curlPost("/fmipservice/device/{$this->username}/initClient", $post);
            $this->iflog('listDevices Returned: ' . $json_str);
            $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'");

				$list = array();
            foreach($json->content as $json_device)
            {
					$device = array(
                "id"             => $json_device->id,
                "name"           => $json_device->name,
                "deviceClass"    => $json_device->deviceClass,
                "deviceModel"    => $json_device->deviceModel,
                "deviceStatus"   => $json_device->deviceStatus,
                "chargingStatus" => $json_device->batteryStatus,
                "batteryLevel"   => $json_device->batteryLevel,);
                $list[] = $device;
            }
				return $list;
        }

        private function curlPost($url, $post_vars = '', $headers = array(), $return_headers = false)
        {
            if(isset($this->partition))
                $url = 'https://' . $this->partition . $url;
            else
                $url = 'https://fmipmobile.icloud.com' . $url;

            $this->iflog("URL: $url");
            $this->iflog("POST DATA: $post_vars");

            $headers[] = 'Content-Type: application/json; charset=utf-8';
            $headers[] = 'X-Apple-Find-Api-Ver: 2.0';
            $headers[] = 'X-Apple-Authscheme: UserIdGuest';
            $headers[] = 'X-Apple-Realm-Support: 1.0';
            $headers[] = 'User-agent: Find iPhone/1.4 MeKit (iPad: iPhone OS/5.0.1)';
            $headers[] = 'X-Client-Name: iPad';
            $headers[] = 'X-Client-UUID: 0cf3dc501ff812adb0b202baed4f37274b210853';
            $headers[] = 'Accept-Language: en-us';
            $headers[] = "Connection: keep-alive";

            $ch = curl_init($url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_USERPWD, $this->username . ':' . $this->password);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
            curl_setopt($ch, CURLOPT_AUTOREFERER, true);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            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);

            if($return_headers)
                curl_setopt($ch, CURLOPT_HEADER, true);
				//print_r(curl_exec($ch));
            return curl_exec($ch);
        }

        private function iflog($str)
        {
            if($this->debug === true)
                echo $str . "
";
        }
    }

    class SosumiDevice
    {
        public $isLocating;
        public $locationTimestamp;
        public $locationType;
        public $horizontalAccuracy;
        public $locationFinished;
        public $longitude;
        public $latitude;
        public $deviceModel;
        public $deviceStatus;
        public $id;
        public $name;
        public $deviceClass;

        // These values only recently appeared in Apple's JSON response.
        // Their final names will probably change to something other than
        // 'a' and 'b'.
        public $chargingStatus; // location->a
        public $batteryLevel; // location->b
    }

?>

Hallo,

ich bin immer wieder begeistert, was alles mit IP-Symcon möglich ist. :slight_smile:

Auf der Suche nach einer iPhone-Ortung bin ich auf Eure Beiträge gestoßen.
Nur leider steige ich hier nicht so ganz durch.
Kann mir vielleicht BITTE einer von Euch helfen?

Wo bekomme ich die aktuellen Classen und Scripte?
Gibt es eine kurze Anleitung?

zum Hintergrund:
Es gibt mehrere IOS Geräte bei uns und ich möchte Sie gerne über das IP-Symcon auf einer Karte
(z.B. GoogleMaps) sichtbar machen.

Für eine kurze Antwort wäre ich sehr dankbar.

Gruß

Olli

Naja,

die aktuelle Klasse ist ja einen weiter oben gepostet.
Dann gibt es verschiedene Versionen, wie sich user hier im Forum die Daten anzeigen lassen, ich stütze mich auf meine MySQL DB:


<?

   include("func_distance.ips.php");           // Function zur Berechnung
	include("class_Sosumi.ips.php");
	include("IPSInstaller.ips.php"); //nur wenn IPSInstaller von Brownson läuft
	$loc_lat_home = 5x.xxxxxxxxx;                      // Latitude Zuhause
	$loc_lon_home = 9.xxxxxxxxxxx; / LON

if($IPS_SENDER == "TimerEvent" || $IPS_SENDER == "Execute"){

$parent_id = IPS_GetParent($_IPS['SELF']);
IPS_SetPosition($_IPS['SELF'], 999);
IPS_SetHidden($_IPS['SELF'], true);

$ssm = new Sosumi('AppleName', 'ApplePW', true);

$loc = $ssm->locate();
print_r($loc);
$target = ($loc['name']);



//Entfernung
$diff = distance($loc_lat_home, $loc_lon_home, $loc['latitude'], $loc['longitude']);
$timer = CreateTimer_CyclicByMinutes("Timer_".$target, $_IPS['SELF'], 15);
 $home = "abwesend"; //abwesend




if ($diff > 10){
	$minute = 10;
	IPS_SetEventCyclic($timer, 0, 0, 0, 2, 2 , $minute);
}
	elseif ($diff > 5){
		$minute = 5;
		IPS_SetEventCyclic($timer, 0, 0, 0, 2, 2 , $minute);
}
	elseif ($diff > 1){
		$minute = 3;
		IPS_SetEventCyclic($timer, 0, 0, 0, 2, 2 , $minute);
} 	else {
		$minute = 2;
		IPS_SetEventCyclic($timer, 0, 0, 0, 2, 2 , $minute);
		$home = "zuhause";
}

//jetzt alles in die DB
 $db = mysql_connect('IP_des_mysql', 'mysqluser', 'mysqlpw');
	     mysql_select_db('locate_iphone', $db) or die(mysql_error());
   	  $dt = date('Y-m-d H:i:s');
        $lat = mysql_real_escape_string($loc['latitude'], $db);
        $lng = mysql_real_escape_string($loc['longitude'], $db);
        $acc = mysql_real_escape_string($loc['accuracy'], $db);
        $tmstmp = mysql_real_escape_string($loc['timestamp'], $db);
        //$excpt = mysql_real_escape_string ($loc['exception'], $db);
        $name = mysql_real_escape_string ($loc['name'], $db);
        $chrg = mysql_real_escape_string ($loc['chargingStatus'], $db);
        $batt = mysql_real_escape_string ($loc['batteryLevel'], $db);
        //$stat  = mysql_real_escape_string ($loc['status'], $db);
        $dist = mysql_real_escape_string($diff, $db);
		  $cycle = mysql_real_escape_string($diff, $db);
        $query = "INSERT INTO iphone_table (`latitude`, `longitude`, `timestamp`, `accuracy`,  `name`, `charging`, `battlevel`, `distance_from_home`, `Abfragezyklus`, `home_status`) VALUES ('$lat','$lng', '$tmstmp', '$acc', '$name', '$chrg', '$batt', '$diff', '$minute', '$home')";
        mysql_query($query, $db) or die(mysql_error());
        
}

?>

Für jedes iDevice brauchst Du einen Namen und ein Skript, die Separierung erfolgt per AppleID Name.
Dann ff Variable anlegen:

Dann das folgende Skript anpassen (Credentials, Variablen IDs) und als Aktionsskript der Variable Gerät hinterlegen:


<?
// SQL Datenbank Zugriffsdaten
$MySQLHost="IP_mysql";
$username="usermysql";
$password="passmysql";
//Sonst nur Variablen anpassen


// Hilfs-Integervariable mit Profil anlegen
if($IPS_SENDER == "WebFront"){
   SetValue($IPS_VARIABLE, $IPS_VALUE);
   $name = GetValueFormatted(48458 /*[Anwesenheit
ew Sosumi\Variablen\Gerät]*/);
}

if(isset($IPS_VALUE)) {
 // NIX
	} else {
   	 if($IPS_SENDER == "RunScript" || $IPS_SENDER == "TimerEvent") {
      	 $name = GetValueFormatted(48458 /*[Anwesenheit
ew Sosumi\Variablen\Gerät]*/);
       }
    else {
     SetValueString(52945 /*[Anwesenheit
ew Sosumi\Variablen\Karte]*/, "<center>Bitte Gerät auswählen!</center>");
    return;
     }
}

// Connect zur Datenbank
$link = mysql_connect($MySQLHost, $username, $password) or die(mysql_error());
mysql_select_db("locate_iphone") or die(mysql_error());
$select = "SELECT `latitude`, `longitude`, `timestamp`, `accuracy`, `exception`, `name`, `charging`, `battlevel`, `status`, `distance_from_home`, `Abfragezyklus`, `home_status` FROM iphone_table where (name = '".$name."') ORDER BY id DESC LIMIT 1";
$query = mysql_query($select);
$num_rows = mysql_num_rows($query);
$row = mysql_fetch_array($query);
// Connect zur Datenbank trennen
mysql_close($link);

if ($num_rows == 0) {
     SetValueString(52945 /*[Anwesenheit
ew Sosumi\Variablen\Karte]*/, "<center>Keine Daten vorhanden!</center>");
     return;
}

if ($row['charging'] == "NotCharging"){
	$quelle = "Akku";
	}
	else
	{
	$quelle = "Ladegerät";
	}



$devicename=$row['name'];
SetValueString(52945 /*[Anwesenheit
ew Sosumi\Variablen\Karte]*/, "<iframe src=\"user/iphone/map.php?lat=".$row['latitude']."&lng=".$row['longitude']."&devicename=".$devicename."&accuracy=".round($row['accuracy'])."&date=".$row['timestamp']."\" border=\"0\" frameborder=\"0\" style=\"top:0pt; bottom:0pt; left:0pt; right:0pt; width:100%; height:400px;\"/></iframe>");
Setvaluestring (21138 /*[Anwesenheit
ew Sosumi\Variablen\Lezter Kontakt]*/, $row['timestamp']);
Setvalue (16121 /*[Anwesenheit
ew Sosumi\Variablen\Genauigkeit]*/,$row['accuracy']);
Setvaluestring (26532 /*[Anwesenheit
ew Sosumi\Variablen\Spannungsquelle]*/, $quelle);
Setvalue (48416 /*[Anwesenheit
ew Sosumi\Variablen\Akku]*/,round($row['battlevel']*100));
Setvaluestring (10689 /*[Anwesenheit
ew Sosumi\Variablen\Entfernung Haus]*/,$row['distance_from_home']);
Setvaluestring (19926 /*[Anwesenheit
ew Sosumi\Variablen\Abfragezyklus]*/,$row['Abfragezyklus']);
Setvaluestring (51225 /*[Anwesenheit
ew Sosumi\Variablen\Zuhause]*/,$row['home_status']);

?>

Dann noch für jeden iPhone name (Spelling wie im iPhone) einen Assoziation für die Geräte Variable anlegen, siehe Bild.

Das ist dann die Variable, die Du im Webfront schaltest und das anzuzeigende Gerät auswählst.

Super, danke…

Ich werde mir das sofort ansehen.
Irgendwie hat die eMail-Benachrichtigung bei Antworten hier im Forum nicht geklappt :frowning:
Deswegen erst jetzt meine Antwort.

Gruß

Olli

Hallo Oli,
mittlerweile gibt es ja noch eine bessere Möglichkeit mit Geofency. Die braucht auch keinen Akku und eine IPS getriggerte Abfrage entfällt.

Moin.

Sagt mal, läuft das bei euch noch?

Hab grad das Problem, daß die Scripte zwar ausgeführt werden und auch kein Fehler gemeldet wird, aber die Variablen nicht mehr aktualisiert werden.

Hat sich da was geändert?

Problem ist erste Mal am 27.6. aufgetreten und danach hat er nicht mehr aktualisiert.

Find da keinen Fehler…

Danke und Gruß
Dirk

Ja also bei mir läuft es noch… aktualisiert wird und auch richtig… aber was bei mir nicht mehr geht ist die Anzeige der Googlemaps mit Position in der HTMLBOX im Ifront… bleibt leer, dafür im Webfront wird es sauber und richtig angezeigt. Ist aber mit aktuellem Beta-Stadium weiss nicht was du nutzt.

Moin,

seit heute Nacht erhalte ich nach jedem Scriptdurchlauf von Apple eine Mail in der mir mitgeteilt wird, das ein ein neuer Computer die „Mein iPhone suchen“-Funktion benutzt hat. Sehr nervig, ist wohl die Reaktion von Apple auf den „iCloud-Leak“ mit Promi-Fotos.

Habt Ihr das Problem auch? Und vielleicht sogar eine Lösung?

Hab ich auch… Eine Loesung noch nicht…

Hatte schon Angst, dass ich auch gehackt wurde.
Aber kristallisierte sich raus, dass es an SOSUMI liegt.
Momentan leider keine Idee, wie sich das abschalten ließe.

Kann ich (leider) bestätigen. Der Spuk fing gegen 2:00 nachts an. Lösung - derzeit noch keine.
Auffällig ist, dass er nur über ein iPad meckert, nicht über iPhones.

Ich werde heute abend mal prüfen ob alle iCloud-Einstellungen auf den iPads noch passen bzw. diese neu einrichten.

Hat nichts mit dem Device (iPad) zu tun.
Ich ab nur iPhones. Bei mir kommt auch die Meldung eines iPads. Ich denke Sosumi gibt sich beim anmelden bei „Find my iPhone“ als iPad aus.

Bekommst Du die EMail pro Gerät oder einmal pauschal für den gesamten Bestand?

Die E-Mail kommt pro Apple ID , die abgefragt wird.

Jop… Die halbe Family von mir dachte Sie wären gehackt und erhalten die Mails… Keiner mochte mich so sehr als ich das erklärte:-)

https://github.com/tylerhall/sosumi/issues/37

Gibt es schon was neues, um es wieder zum laufen zu bekommen ?

Seit heute App-spezifische Passwörter. Einzurichten unter „Meine Apple-ID“.
Jedoch gibts mit dem generierten Passwort von Apple bei mir in der Susomi-Klasse dann eine „undefined offset“ Exception