v3.0.0.0
FlatlyPage
- <?php
- /*
- * FlatlyPage CMS - automatic updates, run by a cron job.
- *
- * php /path/to/site/cron-update.php
- *
- * or, when the host can only call a URL:
- *
- * https://example.com/cron-update?token=SECRET
- *
- * It does nothing unless both the updater and automatic updates are turned on in Admin > Updater,
- * where the exact command, URL and token are shown.
- */
-
- $isCli = PHP_SAPI === 'cli';
- if ($isCli) {
- // config.php expects a web request; without these it would guess the site path from the file system.
- $_SERVER['HTTP_HOST'] ??= 'localhost';
- $_SERVER['SERVER_PORT'] ??= 80;
- $_SERVER['SCRIPT_NAME'] = '/cron-update.php';
- }
-
- require_once __DIR__ . '/config.php';
- require_once __DIR__ . '/admin/updater-lib.php';
-
- if (!$isCli) {
- header('Content-Type: text/plain; charset=utf-8');
- header('Cache-Control: no-store');
- header('X-Robots-Tag: noindex, nofollow');
-
- $token = (string) ($_GET['token'] ?? $_POST['token'] ?? '');
- if (!Updater::enabled() || !Updater::autoUpdate() || $token === '' || !hash_equals(Updater::cronToken(), $token)) {
- http_response_code(403);
- exit("Forbidden.\n");
- }
- session_write_close();
- }
-
- ignore_user_abort(true);
- @set_time_limit(600);
-
- $result = Updater::runAutomatic();
-
- if (!$isCli) {
- http_response_code($result['ok'] ? 200 : 500);
- }
- echo '[' . date('c') . '] ' . $result['message'] . "\n";
-
- if ($isCli) {
- exit($result['ok'] ? 0 : 1);
- }
-