inital release
This commit is contained in:
commit
3a10ed38cc
8 changed files with 258 additions and 0 deletions
8
.env.example
Normal file
8
.env.example
Normal file
|
@ -0,0 +1,8 @@
|
|||
ICLOUD_EMAIL=your_email@example.com
|
||||
ICLOUD_PASSWORD=your_password
|
||||
ICLOUD_2FA_CODE=your_2fa_code
|
||||
DB_ROOT_PASSWORD=your_db_root_password
|
||||
DB_HOST=mariadb
|
||||
DB_USER=your_db_user
|
||||
DB_PASSWORD=your_db_password
|
||||
DB_NAME=wo_ist
|
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
.env
|
||||
keyring_data/
|
||||
mariadb_data/
|
18
Dockerfile
Normal file
18
Dockerfile
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Basis-Image
|
||||
FROM python:3.11-slim
|
||||
|
||||
# Git installieren
|
||||
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Arbeitsverzeichnis erstellen
|
||||
WORKDIR /app
|
||||
|
||||
# Abhängigkeiten kopieren und installieren
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Skript kopieren
|
||||
COPY script.py .
|
||||
|
||||
# Container-Einstiegspunkt
|
||||
CMD ["python", "script.py"]
|
80
README.md
Normal file
80
README.md
Normal file
|
@ -0,0 +1,80 @@
|
|||
# iCloud Device Tracker
|
||||
|
||||
Dieses Projekt ermöglicht das Tracking von Geräten, Personen und Objekten über die Apple "Wo ist?"-Funktion und speichert die Standortdaten in einer MariaDB-Datenbank.
|
||||
|
||||
## Inhaltsverzeichnis
|
||||
|
||||
- [Installation](#installation)
|
||||
- [Verwendung](#verwendung)
|
||||
- [Umgebungsvariablen](#umgebungsvariablen)
|
||||
- [Docker-Setup](#docker-setup)
|
||||
- [Technologien](#technologien)
|
||||
- [Lizenz](#lizenz)
|
||||
|
||||
## Installation
|
||||
|
||||
1. **Repository klonen**:
|
||||
|
||||
```bash
|
||||
git clone https://github.com/dein-benutzername/icloud-device-tracker.git
|
||||
cd icloud-device-tracker
|
||||
```
|
||||
|
||||
2. **.env Datei erstellen**:
|
||||
|
||||
Erstelle eine `.env`-Datei im Stammverzeichnis und füge die folgenden Umgebungsvariablen hinzu:
|
||||
|
||||
```env
|
||||
ICLOUD_EMAIL=your_email@example.com
|
||||
ICLOUD_PASSWORD=your_password
|
||||
ICLOUD_2FA_CODE=your_2fa_code
|
||||
DB_HOST=mariadb
|
||||
DB_USER=your_db_user
|
||||
DB_PASSWORD=your_db_password
|
||||
DB_NAME=wo_ist
|
||||
```
|
||||
|
||||
3. **Docker-Container bauen und starten**:
|
||||
|
||||
```bash
|
||||
docker-compose up --build
|
||||
```
|
||||
|
||||
## Verwendung
|
||||
|
||||
- Starte das Projekt mit dem Befehl `docker-compose up --build`.
|
||||
- Die Standortdaten werden in der Konsole angezeigt und in der MariaDB-Datenbank gespeichert.
|
||||
|
||||
## Umgebungsvariablen
|
||||
|
||||
- **ICLOUD_EMAIL**: Deine iCloud-E-Mail-Adresse.
|
||||
- **ICLOUD_PASSWORD**: Dein iCloud-Passwort.
|
||||
- **ICLOUD_2FA_CODE**: Zwei-Faktor-Authentifizierungscode für iCloud.
|
||||
- **DB_HOST**: Hostname des MariaDB-Dienstes.
|
||||
- **DB_USER**: Benutzername für die MariaDB-Datenbank.
|
||||
- **DB_PASSWORD**: Passwort für die MariaDB-Datenbank.
|
||||
- **DB_NAME**: Name der MariaDB-Datenbank.
|
||||
|
||||
## Docker-Setup
|
||||
|
||||
- **`Dockerfile`**: Enthält die Anweisungen zum Erstellen des Docker-Images.
|
||||
- **`docker-compose.yml`**: Definiert die Dienste, Volumes und Umgebungsvariablen.
|
||||
- **`requirements.txt`**: Listet alle Python-Abhängigkeiten auf, einschließlich `pyicloud`, `mysql-connector-python` und `keyrings.alt`.
|
||||
|
||||
## Technologien
|
||||
|
||||
- **Python**: Backend-Programmiersprache.
|
||||
- **MariaDB**: Relationale Datenbank zur Speicherung von Standortdaten.
|
||||
- **Docker**: Containerisierungstechnologie zur Verwaltung der Anwendungsumgebung.
|
||||
- **ICloud**: Schnittstelle zur Apple "Wo ist?"-Funktion.
|
||||
|
||||
## Lizenz
|
||||
|
||||
Dieses Projekt ist unter der MIT-Lizenz lizenziert.
|
||||
|
||||
---
|
||||
|
||||
### Hinweise
|
||||
|
||||
- Stelle sicher, dass du alle erforderlichen Berechtigungen hast, um auf iCloud-Daten zuzugreifen.
|
||||
- Die Verwendung von `keyrings.alt` speichert Passwörter im Klartext. In Produktionsumgebungen sollten sicherere Alternativen verwendet werden.
|
44
docker-compose.yml
Normal file
44
docker-compose.yml
Normal file
|
@ -0,0 +1,44 @@
|
|||
version: '3.8'
|
||||
|
||||
services:
|
||||
mariadb:
|
||||
image: mariadb:latest
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
|
||||
MYSQL_DATABASE: ${DB_NAME}
|
||||
MYSQL_USER: ${DB_USER}
|
||||
MYSQL_PASSWORD: ${DB_PASSWORD}
|
||||
volumes:
|
||||
- ./mariadb_data:/var/lib/mysql
|
||||
#ports:
|
||||
# - "3306:3306"
|
||||
restart: always
|
||||
networks:
|
||||
default:
|
||||
dns:
|
||||
ipv4_address: 172.28.0.40
|
||||
|
||||
app:
|
||||
build: .
|
||||
environment:
|
||||
ICLOUD_EMAIL: ${ICLOUD_EMAIL}
|
||||
ICLOUD_PASSWORD: ${ICLOUD_PASSWORD}
|
||||
ICLOUD_2FA_CODE: ${ICLOUD_2FA_CODE}
|
||||
DB_HOST: ${DB_HOST}
|
||||
DB_USER: ${DB_USER}
|
||||
DB_PASSWORD: ${DB_PASSWORD}
|
||||
DB_NAME: ${DB_NAME}
|
||||
depends_on:
|
||||
- mariadb
|
||||
volumes:
|
||||
- ./keyring_data:/root/.local/share/python_keyring # Persistenter Speicher für den Keyring
|
||||
#restart: always
|
||||
networks:
|
||||
default:
|
||||
dns:
|
||||
ipv4_address: 172.28.0.41
|
||||
|
||||
networks:
|
||||
dns:
|
||||
name: dns
|
||||
external: true
|
5
keyrings.alt
Normal file
5
keyrings.alt
Normal file
|
@ -0,0 +1,5 @@
|
|||
import keyring
|
||||
from keyrings.alt.file import PlaintextKeyring
|
||||
|
||||
# Keyring auf Dateisystem setzen
|
||||
keyring.set_keyring(PlaintextKeyring())
|
3
requirements.txt
Normal file
3
requirements.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
pyicloud
|
||||
mysql-connector-python
|
||||
keyrings.alt
|
97
script.py
Normal file
97
script.py
Normal file
|
@ -0,0 +1,97 @@
|
|||
import os
|
||||
import time
|
||||
import logging
|
||||
import keyring
|
||||
from keyrings.alt.file import PlaintextKeyring
|
||||
from pyicloud import PyiCloudService
|
||||
import mysql.connector
|
||||
from mysql.connector import Error
|
||||
from datetime import datetime
|
||||
|
||||
# Logging konfigurieren
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
|
||||
# Keyring auf Dateisystem setzen
|
||||
keyring.set_keyring(PlaintextKeyring())
|
||||
|
||||
# Datenbankverbindung prüfen
|
||||
def connect_to_database():
|
||||
while True:
|
||||
try:
|
||||
db = mysql.connector.connect(
|
||||
host=os.getenv('DB_HOST'),
|
||||
user=os.getenv('DB_USER'),
|
||||
password=os.getenv('DB_PASSWORD'),
|
||||
database=os.getenv('DB_NAME')
|
||||
)
|
||||
if db.is_connected():
|
||||
logging.info("Erfolgreich mit der Datenbank verbunden.")
|
||||
return db
|
||||
except Error as e:
|
||||
logging.error(f"Fehler beim Verbinden zur Datenbank: {e}")
|
||||
logging.info("Erneuter Verbindungsversuch in 5 Sekunden...")
|
||||
time.sleep(5)
|
||||
|
||||
# iCloud-Verbindung herstellen
|
||||
icloud = PyiCloudService(
|
||||
os.getenv('ICLOUD_EMAIL'),
|
||||
os.getenv('ICLOUD_PASSWORD'),
|
||||
cookie_directory='/root/.local/share/python_keyring'
|
||||
)
|
||||
|
||||
# Zwei-Faktor-Authentifizierung
|
||||
if icloud.requires_2fa:
|
||||
code = os.getenv('ICLOUD_2FA_CODE')
|
||||
if not code:
|
||||
logging.error("Zwei-Faktor-Authentifizierung erforderlich. Kein Code gefunden.")
|
||||
sys.exit(1)
|
||||
|
||||
result = icloud.validate_2fa_code(code)
|
||||
if not result:
|
||||
logging.error("Ungültiger Zwei-Faktor-Code.")
|
||||
sys.exit(1)
|
||||
logging.info("Zwei-Faktor-Authentifizierung erfolgreich.")
|
||||
|
||||
if icloud.requires_2fa and not icloud.is_trusted_session:
|
||||
logging.error("Vertrauenswürdige Sitzung erforderlich.")
|
||||
sys.exit(1)
|
||||
|
||||
# Datenbankverbindung herstellen
|
||||
db = connect_to_database()
|
||||
cursor = db.cursor()
|
||||
|
||||
# Tabelle erstellen, falls sie nicht existiert
|
||||
cursor.execute("""
|
||||
CREATE TABLE IF NOT EXISTS device_locations (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
device_name VARCHAR(255),
|
||||
latitude DOUBLE,
|
||||
longitude DOUBLE,
|
||||
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
""")
|
||||
|
||||
# Standortdaten abrufen
|
||||
devices = icloud.devices
|
||||
|
||||
for device in devices:
|
||||
location = device.location()
|
||||
if location:
|
||||
device_name = device['name']
|
||||
latitude = location['latitude']
|
||||
longitude = location['longitude']
|
||||
timestamp = datetime.fromtimestamp(location['timeStamp'] / 1000)
|
||||
|
||||
# Koordinaten in der Konsole ausgeben
|
||||
logging.info(f"Gerät: {device_name}, Latitude: {latitude}, Longitude: {longitude}, Zeit: {timestamp}")
|
||||
|
||||
# Daten in die Datenbank einfügen
|
||||
cursor.execute("""
|
||||
INSERT INTO device_locations (device_name, latitude, longitude, timestamp)
|
||||
VALUES (%s, %s, %s, %s)
|
||||
""", (device_name, latitude, longitude, timestamp))
|
||||
|
||||
# Änderungen speichern und Verbindung schließen
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
Loading…
Reference in a new issue