proxy.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. // proxy.php — server-side proxy restricted to the Tasmanian LIST ArcGIS service.
  3. // Originally used by plan-view.html for planning data lookups; the main app now uses
  4. // classes/list_lookup.php instead. This file is kept for legacy/diagnostic use only.
  5. header("Access-Control-Allow-Origin: https://modulosdesign.com.au");
  6. header("Content-Type: application/json");
  7. $ALLOWED_HOSTS = [
  8. 'services.thelist.tas.gov.au',
  9. 'thelistsrv.thelist.tas.gov.au',
  10. ];
  11. $url = $_GET['url'] ?? '';
  12. if (!$url) {
  13. http_response_code(400);
  14. echo json_encode(['error' => 'Missing url parameter']);
  15. exit;
  16. }
  17. $parsed = parse_url($url);
  18. $host = strtolower($parsed['host'] ?? '');
  19. if (!in_array($host, $ALLOWED_HOSTS, true)) {
  20. http_response_code(403);
  21. echo json_encode(['error' => 'Host not permitted: ' . htmlspecialchars($host, ENT_QUOTES, 'UTF-8')]);
  22. exit;
  23. }
  24. // Only allow HTTPS to prevent downgrade to plain HTTP
  25. if (($parsed['scheme'] ?? '') !== 'https') {
  26. http_response_code(403);
  27. echo json_encode(['error' => 'Only HTTPS URLs are permitted']);
  28. exit;
  29. }
  30. $response = file_get_contents($url);
  31. if ($response === false) {
  32. http_response_code(502);
  33. echo json_encode(['error' => 'Upstream request failed']);
  34. exit;
  35. }
  36. echo $response;