-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotification.php
More file actions
65 lines (51 loc) · 2.06 KB
/
Notification.php
File metadata and controls
65 lines (51 loc) · 2.06 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
<?php
require_once 'api/config.php';
$licenseKey = $_GET['License'] ?? $_GET['license'] ?? '';
if (empty($licenseKey)) {
sendResponse(['success' => false, 'error' => 'License key is required'], 400);
}
$licenseKey = strtoupper(trim($licenseKey));
try {
$pdo = getDBConnection();
$stmt = $pdo->prepare("SELECT * FROM licenses WHERE license_key = ?");
$stmt->execute([$licenseKey]);
$license = $stmt->fetch();
if (!$license) {
sendResponse(['success' => false, 'error' => 'Invalid license key'], 401);
}
if (empty($license['machine_code'])) {
sendResponse(['success' => false, 'error' => 'License not activated'], 403);
}
$today = new DateTime('today');
$expirationDate = new DateTime($license['expiration_date']);
$isExpired = $today > $expirationDate;
$daysRemaining = $isExpired ? 0 : (int)$today->diff($expirationDate)->days;
$notifPath = __DIR__ . '/json/Notification.json';
if (!file_exists($notifPath)) {
sendResponse(['success' => false, 'error' => 'Notification config not found'], 500);
}
$notifData = json_decode(file_get_contents($notifPath), true);
$descriptions = [];
foreach ($notifData['notifications'] as $key => $value) {
if (trim($value) !== '') {
$descriptions[] = $value;
}
}
sendResponse([
'success' => true,
'license' => [
'license_key' => $license['license_key'],
'software' => $license['software'],
'expiration_date'=> $license['expiration_date'],
'days_remaining' => $daysRemaining,
'status' => $isExpired ? 'expired' : 'active',
],
'notifications' => $descriptions,
'version' => $notifData['version'],
], 200);
} catch (PDOException $e) {
sendResponse(['success' => false, 'error' => 'Database error'], 500);
} catch (Exception $e) {
sendResponse(['success' => false, 'error' => $e->getMessage()], 500);
}
?>