-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevicebrand.php
More file actions
107 lines (86 loc) · 3.01 KB
/
devicebrand.php
File metadata and controls
107 lines (86 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
require_once 'api/config.php';
$licenseKey = $_GET['License'] ?? $_GET['license'] ?? '';
if (empty($licenseKey)) {
sendError('License key is required', 400);
}
try {
$pdo = getDBConnection();
$stmt = $pdo->prepare("SELECT * FROM licenses WHERE license_key = ?");
$stmt->execute([$licenseKey]);
$license = $stmt->fetch();
if (!$license) {
sendError('Invalid license key', 401);
}
if (empty($license['machine_code'])) {
sendError('License not activated', 403);
}
$today = new DateTime();
$expirationDate = new DateTime($license['expiration_date']);
if ($today > $expirationDate) {
sendError('License has expired', 403);
}
$dbPath = __DIR__ . '/json/phonedb.db';
if (!file_exists($dbPath)) {
sendError('Device database not found', 404);
}
$phoneDb = new PDO('sqlite:' . $dbPath);
$phoneDb->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$totalStmt = $phoneDb->query("SELECT COUNT(*) as total FROM devices WHERE success = 1");
$totalDevices = $totalStmt->fetch(PDO::FETCH_ASSOC)['total'];
$brandsStmt = $phoneDb->query("
SELECT brand, COUNT(*) as count
FROM devices
WHERE success = 1
GROUP BY brand
ORDER BY brand
");
$brandsData = $brandsStmt->fetchAll(PDO::FETCH_ASSOC);
$result = [
'success' => true,
'license_info' => [
'license_key' => $license['license_key'],
'software' => $license['software'],
'expiration_date' => $license['expiration_date'],
'status' => 'active'
],
'statistics' => [
'total_devices' => $totalDevices,
'total_brands' => count($brandsData)
],
'brands' => [],
'models_by_brand' => []
];
foreach ($brandsData as $brandInfo) {
$brandName = $brandInfo['brand'];
$result['brands'][] = $brandName;
$devicesStmt = $phoneDb->prepare("
SELECT id, name, data
FROM devices
WHERE brand = ? AND success = 1
ORDER BY name
");
$devicesStmt->execute([$brandName]);
$devices = $devicesStmt->fetchAll(PDO::FETCH_ASSOC);
$models = [];
foreach ($devices as $device) {
$deviceData = json_decode($device['data'], true);
$specs = $deviceData['specs'] ?? [];
$models[] = [
'model' => $specs['model'] ?? $device['name'],
'codename' => $specs['codename'] ?? null
];
}
$result['models_by_brand'][$brandName] = [
'brand' => ucfirst($brandName),
'total_models' => count($models),
'models' => $models
];
}
sendSuccess($result);
} catch (PDOException $e) {
sendError('Database error: ' . $e->getMessage(), 500);
} catch (Exception $e) {
sendError('Error: ' . $e->getMessage(), 500);
}
?>