isat.php 747 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. error_reporting(0);
  3. header('HTTP/1.1 404 Not Found');
  4. header('Access-Control-Allow-Origin: *');
  5. header('Cache-Control: private, no-cache, no-store, max-age=0');
  6. //
  7. // { Example API for IsAT }
  8. //
  9. define('JSON_FILE', './attd.json');
  10. //
  11. //
  12. if (!file_exists(JSON_FILE))
  13. {
  14. die('File Not Found');
  15. }
  16. elseif ($_SERVER['REQUEST_METHOD'] != 'POST')
  17. {
  18. echo ('OK');
  19. exit;
  20. }
  21. header('Content-Type: application/json');
  22. $got = @json_decode(file_get_contents(JSON_FILE) , true);
  23. if (!is_array($got))
  24. {
  25. die('File Error');
  26. }
  27. $fqdn = htmlspecialchars($_POST['f']);
  28. if (!preg_match("/^([a-z0-9]{1})([a-z0-9.-]{0,254})\.([a-z]{2,50})$/", $fqdn))
  29. {
  30. echo ('[false,false]');
  31. exit;
  32. }
  33. echo (isset($got[$fqdn]) ? '[true,true]' : '[true,false]');