localUpdater.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /**
  3. * Serves the current client script (timekeeperLocal.php) for the students'
  4. * machines to download:
  5. *
  6. * wget -O .timekeeper.php "https://overlord.pfip.au/e107_plugins/timekeeper/localUpdater.php"
  7. *
  8. * Changes from the current repo version:
  9. * - ob_clean() raised a notice when no output buffer was active; if
  10. * display_errors was on, that text was prepended to the download and
  11. * pushed the "#!/bin/php" line off line 1 (so the script could no longer
  12. * be run directly). It only cleans a buffer that exists now
  13. * - the file is found next to this script, not relative to the working directory
  14. * - a missing file now answers 404 instead of an empty 200
  15. * - Cache-Control: no-store, so clients always get the newest version
  16. */
  17. $file = __DIR__ . '/timekeeperLocal.php';
  18. if (!is_file($file)) {
  19. http_response_code(404);
  20. exit;
  21. }
  22. while (ob_get_level() > 0) {
  23. ob_end_clean();
  24. }
  25. header('Content-Description: File Transfer');
  26. header('Content-Type: application/octet-stream');
  27. header('Content-Disposition: attachment; filename=' . basename($file));
  28. header('Content-Transfer-Encoding: binary');
  29. header('Expires: 0');
  30. header('Cache-Control: no-store, must-revalidate');
  31. header('Pragma: no-cache');
  32. header('Content-Length: ' . filesize($file));
  33. readfile($file);
  34. exit;