WebOrbiton
v3.0.0.0

FlatlyPage

52 lines · 1.4 KB
  1. <?php
  2. /*
  3. * FlatlyPage CMS - automatic updates, run by a cron job.
  4. *
  5. * php /path/to/site/cron-update.php
  6. *
  7. * or, when the host can only call a URL:
  8. *
  9. * https://example.com/cron-update?token=SECRET
  10. *
  11. * It does nothing unless both the updater and automatic updates are turned on in Admin > Updater,
  12. * where the exact command, URL and token are shown.
  13. */
  14. ​
  15. $isCli = PHP_SAPI === 'cli';
  16. if ($isCli) {
  17. // config.php expects a web request; without these it would guess the site path from the file system.
  18. $_SERVER['HTTP_HOST'] ??= 'localhost';
  19. $_SERVER['SERVER_PORT'] ??= 80;
  20. $_SERVER['SCRIPT_NAME'] = '/cron-update.php';
  21. }
  22. ​
  23. require_once __DIR__ . '/config.php';
  24. require_once __DIR__ . '/admin/updater-lib.php';
  25. ​
  26. if (!$isCli) {
  27. header('Content-Type: text/plain; charset=utf-8');
  28. header('Cache-Control: no-store');
  29. header('X-Robots-Tag: noindex, nofollow');
  30. ​
  31. $token = (string) ($_GET['token'] ?? $_POST['token'] ?? '');
  32. if (!Updater::enabled() || !Updater::autoUpdate() || $token === '' || !hash_equals(Updater::cronToken(), $token)) {
  33. http_response_code(403);
  34. exit("Forbidden.\n");
  35. }
  36. session_write_close();
  37. }
  38. ​
  39. ignore_user_abort(true);
  40. @set_time_limit(600);
  41. ​
  42. $result = Updater::runAutomatic();
  43. ​
  44. if (!$isCli) {
  45. http_response_code($result['ok'] ? 200 : 500);
  46. }
  47. echo '[' . date('c') . '] ' . $result['message'] . "\n";
  48. ​
  49. if ($isCli) {
  50. exit($result['ok'] ? 0 : 1);
  51. }
  52. ​