-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcron.php
More file actions
48 lines (38 loc) · 1.29 KB
/
cron.php
File metadata and controls
48 lines (38 loc) · 1.29 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
<?php
/**
* Aufruf: /cron.php?secret=… oder via X-Cron-Secret Header.
*/
declare(strict_types=1);
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/config/database.php';
use Config\Database;
use Scheduler\WeatherCron;
$config = require __DIR__ . '/config/config.php';
$timezone = $config['app']['timezone'] ?? 'Europe/Vaduz';
setlocale(LC_TIME, 'de_DE.UTF-8');
date_default_timezone_set($timezone);
$cronSecret = $_GET['secret'] ?? $_SERVER['HTTP_X_CRON_SECRET'] ?? null;
$configSecret = getenv('CRON_SECRET') ?: null;
if (!$configSecret) {
http_response_code(503);
header('Content-Type: application/json');
echo json_encode(['success' => false, 'error' => 'CRON_SECRET is not configured']);
exit;
}
if ($cronSecret !== $configSecret) {
http_response_code(403);
header('Content-Type: application/json');
echo json_encode(['success' => false, 'error' => 'Unauthorized']);
exit;
}
try {
Database::getInstance();
$cron = new WeatherCron();
$result = $cron->run();
header('Content-Type: application/json');
echo json_encode($result, JSON_PRETTY_PRINT);
} catch (Exception $e) {
http_response_code(500);
header('Content-Type: application/json');
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}